-
Notifications
You must be signed in to change notification settings - Fork 99
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
Add support for WM8978 i2c dac #89
Conversation
Thanks but that PR made me think that it was time to refactor a bit the DAC "framework" as I see all drivers doing the same thing over and over. I'm a bit obsessed by minimizing code (I really hate duplication) and I like to do these things early enough so that it does not come un-manageable a year or two later (that's how you end up with spaghetti code). Anyway, I put together some common function and re-wrote the TAX5xxx, AC101 and I2S to support that, as examples. I think that will make your driver much smaller. Let me know if this is a complicated change and I'll help. Also, the use of the JSON should really be reserved for dac_external. Built-in driver should write directly by register. I can add a buffer write if needed, otherwise you can create a table with a loop. I would suggest that you write your own adac_write_byte/word function that uses the original adac_write_byte/word and writes the shadow registers and then add an adac_read_byte/word that simply read in the shadow registers. |
No problem, will have a look this weekend. My latest headache is trying to get a CS-less SPI 240x240 ST7789 display working. (probably the same one that schmurtz was using - I seem to always pick the challenging parts!). I've tested with other code, but I'm not getting anything with the same IO config here. Its possible I missing something on the LMS setup. What is the expected operation, for example should I see a splash screen regardless? |
Yes, you should see a splashscreen at boot no matter what. It's strange b/c ST7789 works well, I have one on one of my test systems. Did you connect RST or pull it up? It's very important. Did you alos make sure that backlight is activated? |
Here is a proposal - you need to tweak a few things still (like the WM address) and verify that it works ... If you could give it a go, then I'd release this weekend a new FW version |
I'll test tonight. Initially, it looks like this will work for basic functionality. |
|
Well candidly it's a bit clunky. I did that as I had no other option for dac_external, but when a chip is supported internally, I'd rather do full/proper support built-in. Now, the next step if we want real external configuration is to add this JavaScript option. I'm not ready to do that for now, but that would give you the real possibility to use chip-specific features. The good thing is that now that I've created the adac_core features, we can make these usable from JS so that's a step in the right direction :-) |
This does work. `/*
*/ #include <freertos/FreeRTOS.h> #define WM8978 0x1A // for TTGO TAudio static const char TAG[] = "WM8978"; static void speaker(bool active) { } static esp_err_t i2c_write_shadow(uint8_t reg, uint16_t val); const struct adac_s dac_wm8978 = { "WM8978", init, adac_deinit, power, speaker, headset, volume }; // initiation table for non-readbale 9-bit i2c registers /****************************************************************************************
/****************************************************************************************
/****************************************************************************************
/****************************************************************************************
|
Could you update your PR? If you thing the WM8978 address can change, one thing we can do is leave the address configurable
and set WM8978 as a "static int WM8978" vs a define |
OK. Not sure if that worked (bit if a novice on github) but hopefully you have what need here. |
Per discussions on squeezebox thread, the WM8978 DAC uses a 9bit I2C format and does not support I2C read (needs simulating). It also requires an external MCLK signal, that is supplied by the ESP32 system clock.
This code adds a new driver based on the existing external format.
I included a default dac_controlset to make it simple for beginners. (dac_config is "model=WM8978,bck=33,ws=25,do=26,sda=19,scl=18,i2c=26" for the TTGO TAudio/ESP-SNOW board.)
I also added JSON support for headset and speaker on/off, but had to disable as the jack-handler is currently on chip only and none of the external GPIO is exposed to allow the ESP to monitor.
I uploaded a quick (demo video) that includes full LED control too!. I'm going to do a separate draft pull request. (a). as I want to clean up the code, and (b). I'll need some help/advise on the best way to properly implement it (I'm thinking it should be integrated into the standard display module as an additional screen)