Skip to content

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

Closed
wants to merge 15 commits into from

Conversation

robert-hh
Copy link
Contributor

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.

@robert-hh robert-hh changed the title wm8960: Driver for the WM8960 codec. drivers: Driver for the WM8960 codec. Feb 18, 2022
0x0050, 0x0050, 0x0050, 0x0000, 0x0000, 0x0000, 0x0000,
0x0040, 0x0000, 0x0000, 0x0050, 0x0050, 0x0000, 0x0002,
0x0037, 0x004d, 0x0080, 0x0008, 0x0031, 0x0026, 0x00e9
]
Copy link
Member

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.

Copy link
Contributor Author

@robert-hh robert-hh Feb 18, 2022

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.

@dpgeorge
Copy link
Member

Including the driver into the MicroPython repository allows to put it by
default into the frozen bytecode of MIMXRT_1xxx_DEV boards.

This driver could also maybe go in micropython-lib, and freezing it in firmware would still be possible.

@robert-hh
Copy link
Contributor Author

robert-hh commented Feb 18, 2022

This driver could also maybe go in micropython-lib, and freezing it in firmware would still be possible.

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.

@robert-hh robert-hh force-pushed the mimxrt_codec branch 2 times, most recently from d038028 to f081086 Compare February 19, 2022 10:05
@robert-hh
Copy link
Contributor Author

@dpgeorge

This driver could also maybe go in micropython-lib, and freezing it in firmware would still be possible.

The code changes you suggested are done. About the maybe: should I read the as a strong suggestion? Then, does $(MPY_LIB_DIR) point in the firmware images build system to the micropython-lib directory?

@robert-hh robert-hh force-pushed the mimxrt_codec branch 2 times, most recently from 6c08954 to 63c474f Compare February 25, 2022 08:52
@robert-hh robert-hh force-pushed the mimxrt_codec branch 5 times, most recently from 510f8bf to f7bb912 Compare March 13, 2022 15:18
@dpgeorge
Copy link
Member

About the maybe: should I read the as a strong suggestion? Then, does $(MPY_LIB_DIR) point in the firmware images build system to the micropython-lib directory?

It would be good to put this in micropython-lib, but it's not ready yet to take such drivers, in particular it's not worked out how to make the documentation work (we may need to have separate docs for micropython-lib...).

So for now let's keep this driver in this repo. There is anyway already the lsm6dsox driver, among others.

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.
@dpgeorge
Copy link
Member

dpgeorge commented Apr 4, 2022

Squashed and merged in 56b331a, with some reformatting of the docs.

@dpgeorge dpgeorge closed this Apr 4, 2022
@robert-hh robert-hh deleted the mimxrt_codec branch April 4, 2022 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants