-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: Driver for the WM8960 codec. #8324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
drivers/codec/wm8960.py
Outdated
0x0050, 0x0050, 0x0050, 0x0000, 0x0000, 0x0000, 0x0000, | ||
0x0040, 0x0000, 0x0000, 0x0050, 0x0050, 0x0000, 0x0002, | ||
0x0037, 0x004d, 0x0080, 0x0008, 0x0031, 0x0026, 0x00e9 | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, better to make this a tuple, then it has a chance to be optimised by the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm writing back into that table. So a tuple is not feasible. I could use an array, but that had to be initialized with the above values, since these are the power-on defaults in the WM8960 registers.
This driver could also maybe go in |
I considered that. But it would rely on the assumption, that micropython-lib exists and is at a fixed relative position to the micropython tree. |
d038028
to
f081086
Compare
The code changes you suggested are done. About the |
6c08954
to
63c474f
Compare
510f8bf
to
f7bb912
Compare
It would be good to put this in So for now let's keep this driver in this repo. There is anyway already the |
This codec is assembled for the MIMXRT1xxx_DEV boards and available for WM8960 breakout boards as well. The driver itself has been tested as working with the MIMXRT boards and a Sparkfun WM6890 breakout board. It implements the initialization, basic methods and some enhanced methods like 3D, ALC or Soft Mute.
Following the suggestions of @dpgeorge: - create a Regs class, which encapsulates accesses to the hardeware and holds the register cache. - Change WM8960 register accesses into looking like array accesses. - Combine modifications of the same register into one operation. - Put assignments to L/R registers with the same value into one line. Black had to be told to leave the code untouched, because it shifted the whole WM8960 class.
This array is initialized by a tuple with the power-on values.
Which also made a few register shift definitions obsolete.
- remove unneded statement in set_volume() - masked additional bits in get_volume() - rewrote a line in __setitem__() - shortened register access in three functions.
The prefix drop seems to change about every line of code. So it looks like a larger change than it is, but the code looks better.
- Normalize volume setting to the range 0-100. - Use a table to simplify the code. - Reformat the documentation. - Add a default value for i2c_address. - Some reformatting made by black.
According to the suggestion of @dpgeorge. Fix a few omissions of the previous commits as well.
Still there is a warning about the wm8960.rst document not contained in any doc tree. What would be the best place?
Silencing the warning about a missing toctree entry.
For some reason, this is required for one of my boards, and does not hurt on the other ones.
Squashed and merged in 56b331a, with some reformatting of the docs. |
This PR adds to the SAI support of PR #8322. It is a driver for the MW8960 codec,
whis is assembled for the MIMXRT1xxx_DEV boards and is available
at breakout boards as well. The driver is required to get any sound out of
the WM8960 codec.
Including the driver into the MicroPython repository allows to put it by
default into the frozen bytecode of MIMXRT_1xxx_DEV boards.
The driver itself has been tested as working with the MIMXRT boards
and a Sparkfun WM8960 breakout board. It implements the initialization,
basic methods and some enhanced methods like 3D, ALC or Soft Mute.