From 0fce4fcc06a600aac6b0cb6fc1ef1ebb91bcdf27 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 8 Mar 2023 12:47:56 +1100 Subject: update to faceplate bodge --- src/drivers/include/gpio_expander.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp index a6e96d87..d03c26b0 100644 --- a/src/drivers/include/gpio_expander.hpp +++ b/src/drivers/include/gpio_expander.hpp @@ -49,8 +49,8 @@ class GpioExpander { // Port B: // 0 - 3.5mm jack detect (active low) // 1 - unused - // 2 - volume up - // 3 - volume down + // 2 - trackpad int + // 3 - display reset (active low) // 4 - lock switch // 5 - touchpad interupt // 6 - display DR @@ -111,10 +111,10 @@ class GpioExpander { // Port B PHONE_DETECT = 8, // Active-high input // UNUSED = 9, - VOL_UP = 10, - VOL_DOWN = 11, - LOCK = 12, - TOUCHPAD_INT = 13, + TOUCHPAD_INT = 10, + DISPLAY_RESET = 11, + // UNUSED = 12, + // UNUSED = 13, DISPLAY_DR = 14, DISPLAY_LED = 15, }; -- cgit v1.2.3 From b9a75cd55a11fd404a1977539acb64a6705f3809 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 10 Mar 2023 12:26:32 +1100 Subject: LDO up at boot --- src/drivers/include/gpio_expander.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp index d03c26b0..cb087df9 100644 --- a/src/drivers/include/gpio_expander.hpp +++ b/src/drivers/include/gpio_expander.hpp @@ -44,7 +44,7 @@ class GpioExpander { // 6 - LDO enable // 7 - charge power ok (active low) // All power switches low, sd mux pointing away from us, inputs high. - static const uint8_t kPortADefault = 0b10000010; + static const uint8_t kPortADefault = 0b11000010; // Port B: // 0 - 3.5mm jack detect (active low) -- cgit v1.2.3 From 78ec09c494faadf9e7d06dc7d3e04531c3a34ff7 Mon Sep 17 00:00:00 2001 From: ailurux Date: Mon, 13 Mar 2023 15:14:32 +1100 Subject: Touchwheel test --- src/drivers/include/i2c.hpp | 2 +- src/drivers/include/touchwheel.hpp | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/drivers/include/touchwheel.hpp (limited to 'src/drivers/include') diff --git a/src/drivers/include/i2c.hpp b/src/drivers/include/i2c.hpp index dbdd8a11..811c9333 100644 --- a/src/drivers/include/i2c.hpp +++ b/src/drivers/include/i2c.hpp @@ -35,7 +35,7 @@ class I2CTransaction { * ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode. * ESP_ERR_TIMEOUT Operation timeout because the bus is busy. */ - esp_err_t Execute(); + esp_err_t Execute(uint8_t port = I2C_NUM_0); /* * Enqueues a start condition. May also be used for repeated start diff --git a/src/drivers/include/touchwheel.hpp b/src/drivers/include/touchwheel.hpp new file mode 100644 index 00000000..14215acd --- /dev/null +++ b/src/drivers/include/touchwheel.hpp @@ -0,0 +1,60 @@ +#pragma once + + +#include +#include + +#include "esp_err.h" +#include "result.hpp" + +#include "gpio_expander.hpp" + +namespace drivers { + +struct TouchWheelData { + bool is_touched = false; + uint8_t wheel_position = -1; +}; + +class TouchWheel { + public: + enum Error { + FAILED_TO_BOOT, + FAILED_TO_CONFIGURE, + }; + static auto create(GpioExpander* expander) + -> cpp::result, Error>; + + TouchWheel(GpioExpander* gpio); + ~TouchWheel(); + + // Not copyable or movable. + TouchWheel(const TouchWheel&) = delete; + TouchWheel& operator=(const TouchWheel&) = delete; + + auto Update() -> void; + auto GetTouchWheelData() const -> TouchWheelData; + + private: + GpioExpander* gpio_; + TouchWheelData data_; + + enum Register { + FIRMWARE_VERSION = 0x1, + DETECTION_STATUS = 0x2, + KEY_STATUS_A = 0x3, + KEY_STATUS_B = 0x4, + SLIDER_POSITION = 0x5, + CALIBRATE = 0x6, + RESET = 0x7, + LOW_POWER = 0x8, + SLIDER_OPTIONS = 0x14, + }; + + + void WriteRegister(uint8_t reg, uint8_t val); + void ReadRegister(uint8_t reg, uint8_t* data, uint8_t count); + +}; + +} // namespace drivers -- cgit v1.2.3 From a0ae39befe11c2a5a78ee5877cd5dd9cda90e27c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 30 Mar 2023 09:31:08 +1100 Subject: Update pinouts for R3 --- src/drivers/include/gpio_expander.hpp | 70 +++++++++++++++++------------------ 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp index cb087df9..86998e7e 100644 --- a/src/drivers/include/gpio_expander.hpp +++ b/src/drivers/include/gpio_expander.hpp @@ -35,28 +35,28 @@ class GpioExpander { static const uint8_t kPca8575Timeout = pdMS_TO_TICKS(100); // Port A: - // 0 - audio power enable - // 1 - usb interface power enable (active low) - // 2 - display power enable - // 3 - touchpad power enable - // 4 - sd card power enable - // 5 - sd mux switch - // 6 - LDO enable - // 7 - charge power ok (active low) - // All power switches low, sd mux pointing away from us, inputs high. - static const uint8_t kPortADefault = 0b11000010; + // 0 - sd card mux switch + // 1 - sd card mux enable (active low) + // 2 - key up + // 3 - key down + // 4 - key lock + // 5 - display reset + // 6 - NC + // 7 - sd card power + // Default to SD card off, inputs high. + static const uint8_t kPortADefault = 0b00011110; // Port B: - // 0 - 3.5mm jack detect (active low) - // 1 - unused - // 2 - trackpad int - // 3 - display reset (active low) - // 4 - lock switch - // 5 - touchpad interupt - // 6 - display DR - // 7 - display LED - // Inputs all high, all others low. - static const uint8_t kPortBDefault = 0b00111101; + // 0 - trs output enable + // 1 - 3.5mm jack detect (active low) + // 2 - NC + // 3 - NC + // 4 - NC + // 5 - NC + // 6 - NC + // 7 - NC + // Default input high, trs output low + static const uint8_t kPortBDefault = 0b00000010; /* * Convenience mehod for packing the port a and b bytes into a single 16 bit @@ -99,30 +99,30 @@ class GpioExpander { /* Maps each pin of the expander to its number in a `pack`ed uint16. */ enum Pin { // Port A - AUDIO_POWER_ENABLE = 0, - USB_INTERFACE_POWER_ENABLE = 1, - DISPLAY_POWER_ENABLE = 2, - TOUCHPAD_POWER_ENABLE = 3, - SD_CARD_POWER_ENABLE = 4, - SD_MUX_SWITCH = 5, - LDO_ENABLE = 6, - CHARGE_POWER_OK = 7, // Active-low input + SD_MUX_SWITCH = 0, + SD_MUX_EN_ACTIVE_LOW = 1, + KEY_UP = 2, + KEY_DOWN = 3, + KEY_LOCK = 4, + DISPLAY_RESET = 5, + // UNUSED = 6, + SD_CARD_POWER_ENABLE = 7, // Port B - PHONE_DETECT = 8, // Active-high input - // UNUSED = 9, - TOUCHPAD_INT = 10, - DISPLAY_RESET = 11, + AMP_EN = 8, + PHONE_DETECT = 9, + // UNUSED = 10, + // UNUSED = 11, // UNUSED = 12, // UNUSED = 13, - DISPLAY_DR = 14, - DISPLAY_LED = 15, + // UNUSED = 14, + // UNUSED = 15, }; /* Nicer value names for use with the SD_MUX_SWITCH pin. */ enum SdController { SD_MUX_ESP = 1, - SD_MUX_USB = 0, + SD_MUX_SAMD = 0, }; /** -- cgit v1.2.3 From 9799ab458d8ad870aaec048abf5b1b1d93aa7aff Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 30 Mar 2023 10:15:09 +1100 Subject: fix sd card on for dev + mux pin --- src/drivers/include/gpio_expander.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp index 86998e7e..d53a1982 100644 --- a/src/drivers/include/gpio_expander.hpp +++ b/src/drivers/include/gpio_expander.hpp @@ -42,9 +42,9 @@ class GpioExpander { // 4 - key lock // 5 - display reset // 6 - NC - // 7 - sd card power + // 7 - sd card power (active low) // Default to SD card off, inputs high. - static const uint8_t kPortADefault = 0b00011110; + static const uint8_t kPortADefault = 0b10011110; // Port B: // 0 - trs output enable @@ -121,8 +121,8 @@ class GpioExpander { /* Nicer value names for use with the SD_MUX_SWITCH pin. */ enum SdController { - SD_MUX_ESP = 1, - SD_MUX_SAMD = 0, + SD_MUX_ESP = 0, + SD_MUX_SAMD = 1, }; /** -- cgit v1.2.3 From 1b245316fe282035f094a3656f717d419e8bd526 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 4 Apr 2023 14:48:35 +1000 Subject: fix up touchpad timeouts, make it less chatty --- src/drivers/include/touchwheel.hpp | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/touchwheel.hpp b/src/drivers/include/touchwheel.hpp index 14215acd..3dfa182b 100644 --- a/src/drivers/include/touchwheel.hpp +++ b/src/drivers/include/touchwheel.hpp @@ -1,8 +1,7 @@ #pragma once - -#include #include +#include #include "esp_err.h" #include "result.hpp" @@ -18,14 +17,7 @@ struct TouchWheelData { class TouchWheel { public: - enum Error { - FAILED_TO_BOOT, - FAILED_TO_CONFIGURE, - }; - static auto create(GpioExpander* expander) - -> cpp::result, Error>; - - TouchWheel(GpioExpander* gpio); + TouchWheel(); ~TouchWheel(); // Not copyable or movable. @@ -36,25 +28,22 @@ class TouchWheel { auto GetTouchWheelData() const -> TouchWheelData; private: - GpioExpander* gpio_; TouchWheelData data_; - + enum Register { FIRMWARE_VERSION = 0x1, DETECTION_STATUS = 0x2, - KEY_STATUS_A = 0x3, - KEY_STATUS_B = 0x4, - SLIDER_POSITION = 0x5, - CALIBRATE = 0x6, - RESET = 0x7, - LOW_POWER = 0x8, - SLIDER_OPTIONS = 0x14, + KEY_STATUS_A = 0x3, + KEY_STATUS_B = 0x4, + SLIDER_POSITION = 0x5, + CALIBRATE = 0x6, + RESET = 0x7, + LOW_POWER = 0x8, + SLIDER_OPTIONS = 0x14, }; - void WriteRegister(uint8_t reg, uint8_t val); - void ReadRegister(uint8_t reg, uint8_t* data, uint8_t count); - + uint8_t ReadRegister(uint8_t reg); }; } // namespace drivers -- cgit v1.2.3 From a1cef17c5bb66c453e4a8e83e52a56fe9173346c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 12 Apr 2023 16:37:27 +1000 Subject: Leave the display reset pin alone; we don't need it --- src/drivers/include/gpio_expander.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp index d53a1982..cd3719a0 100644 --- a/src/drivers/include/gpio_expander.hpp +++ b/src/drivers/include/gpio_expander.hpp @@ -44,7 +44,7 @@ class GpioExpander { // 6 - NC // 7 - sd card power (active low) // Default to SD card off, inputs high. - static const uint8_t kPortADefault = 0b10011110; + static const uint8_t kPortADefault = 0b10111110; // Port B: // 0 - trs output enable -- cgit v1.2.3 From a9531c86a433c8b7ae1f77ff0266c27c39eca7f4 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 10 Mar 2023 11:28:33 +1100 Subject: mostly single task pipeline --- src/drivers/include/dac.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index 06808a78..028d46cb 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -71,7 +71,7 @@ class AudioDac { // TODO(jacqueline): worth supporting channels here as well? auto Reconfigure(BitsPerSample bps, SampleRate rate) -> void; - auto WriteData(cpp::span data) -> std::size_t; + auto WriteData(const cpp::span& data) -> std::size_t; auto Stop() -> void; auto LogStatus() -> void; -- cgit v1.2.3 From 7c6fd654f50e6665efa4226c6b927f9762734182 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Sat, 1 Apr 2023 13:22:21 +1100 Subject: New pipeline building, still needs proper control --- src/drivers/include/dac.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index 028d46cb..4a1b2a5b 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -71,7 +71,7 @@ class AudioDac { // TODO(jacqueline): worth supporting channels here as well? auto Reconfigure(BitsPerSample bps, SampleRate rate) -> void; - auto WriteData(const cpp::span& data) -> std::size_t; + auto WriteData(const cpp::span& data) -> void; auto Stop() -> void; auto LogStatus() -> void; -- cgit v1.2.3 From 3836768bb8b95188e6657ab69027d1d9e4b13a77 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 3 Apr 2023 14:06:30 +1000 Subject: new pipeline working(?), but the dac eludes me --- src/drivers/include/dac.hpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index 4a1b2a5b..6849d92c 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -83,6 +83,7 @@ class AudioDac { private: GpioExpander* gpio_; i2s_chan_handle_t i2s_handle_; + bool i2s_active_; i2s_std_clk_config_t clock_config_; i2s_std_slot_config_t slot_config_; @@ -97,9 +98,13 @@ class AudioDac { PAGE_SELECT = 0, RESET = 1, POWER_MODE = 2, + PLL_ENABLE = 4, DE_EMPHASIS = 7, + PLL_CLOCK_SOURCE = 13, DAC_CLOCK_SOURCE = 14, + RESYNC_REQUEST = 19, CLOCK_ERRORS = 37, + INTERPOLATION = 34, I2S_FORMAT = 40, DIGITAL_VOLUME_L = 61, DIGITAL_VOLUME_R = 62, -- cgit v1.2.3 From 40a9734b04c48339cfdf6ed9043aa3f6f0dda62d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 4 Apr 2023 09:46:52 +1000 Subject: Redo pcm registers to include pages --- src/drivers/include/dac.hpp | 117 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 91 insertions(+), 26 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index 6849d92c..6836cf59 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -20,6 +20,91 @@ namespace drivers { +namespace pcm512x { +class Register { + public: + uint8_t page; + uint8_t reg; + + constexpr Register(uint8_t page, uint8_t reg) : page(page), reg(reg) {} +}; + +constexpr Register RESET(0, 1); +constexpr Register POWER(0, 2); +constexpr Register MUTE(0, 3); +constexpr Register PLL_EN(0, 4); +constexpr Register SPI_MISO_FUNCTION(0, 6); +constexpr Register DSP(0, 7); +constexpr Register GPIO_EN(0, 8); +constexpr Register BCLK_LRCLK_CFG(0, 9); +constexpr Register DSP_GPIO_INPUT(0, 10); +constexpr Register MASTER_MODE(0, 12); +constexpr Register PLL_REF(0, 13); +constexpr Register DAC_REF(0, 14); +constexpr Register GPIO_DACIN(0, 16); +constexpr Register GPIO_PLLIN(0, 18); +constexpr Register SYNCHRONIZE(0, 19); +constexpr Register PLL_COEFF_0(0, 20); +constexpr Register PLL_COEFF_1(0, 21); +constexpr Register PLL_COEFF_2(0, 22); +constexpr Register PLL_COEFF_3(0, 23); +constexpr Register PLL_COEFF_4(0, 24); +constexpr Register DSP_CLKDIV(0, 27); +constexpr Register DAC_CLKDIV(0, 28); +constexpr Register NCP_CLKDIV(0, 29); +constexpr Register OSR_CLKDIV(0, 30); +constexpr Register MASTER_CLKDIV_1(0, 32); +constexpr Register MASTER_CLKDIV_2(0, 33); +constexpr Register FS_SPEED_MODE(0, 34); +constexpr Register IDAC_1(0, 35); +constexpr Register IDAC_2(0, 36); +constexpr Register ERROR_DETECT(0, 37); +constexpr Register I2S_1(0, 40); +constexpr Register I2S_2(0, 41); +constexpr Register DAC_ROUTING(0, 42); +constexpr Register DSP_PROGRAM(0, 43); +constexpr Register CLKDET(0, 44); +constexpr Register AUTO_MUTE(0, 59); +constexpr Register DIGITAL_VOLUME_1(0, 60); +constexpr Register DIGITAL_VOLUME_2(0, 61); +constexpr Register DIGITAL_VOLUME_3(0, 62); +constexpr Register DIGITAL_MUTE_1(0, 63); +constexpr Register DIGITAL_MUTE_2(0, 64); +constexpr Register DIGITAL_MUTE_3(0, 65); +constexpr Register GPIO_OUTPUT_1(0, 80); +constexpr Register GPIO_OUTPUT_2(0, 81); +constexpr Register GPIO_OUTPUT_3(0, 82); +constexpr Register GPIO_OUTPUT_4(0, 83); +constexpr Register GPIO_OUTPUT_5(0, 84); +constexpr Register GPIO_OUTPUT_6(0, 85); +constexpr Register GPIO_CONTROL_1(0, 86); +constexpr Register GPIO_CONTROL_2(0, 87); +constexpr Register OVERFLOW(0, 90); +constexpr Register RATE_DET_1(0, 91); +constexpr Register RATE_DET_2(0, 92); +constexpr Register RATE_DET_3(0, 93); +constexpr Register RATE_DET_4(0, 94); +constexpr Register CLOCK_STATUS(0, 95); +constexpr Register ANALOG_MUTE_DET(0, 108); +constexpr Register POWER_STATE(0, 118); +constexpr Register GPIN(0, 119); +constexpr Register DIGITAL_MUTE_DET(0, 120); + +constexpr Register OUTPUT_AMPLITUDE(1, 1); +constexpr Register ANALOG_GAIN_CTRL(1, 2); +constexpr Register UNDERVOLTAGE_PROT(1, 5); +constexpr Register ANALOG_MUTE_CTRL(1, 6); +constexpr Register ANALOG_GAIN_BOOST(1, 7); +constexpr Register VCOM_CTRL_1(1, 8); +constexpr Register VCOM_CTRL_2(1, 9); + +constexpr Register CRAM_CTRL(44, 1); + +constexpr Register FLEX_A(253, 63); +constexpr Register FLEX_B(253, 64); + +} // namespace pcm512x + /** * Interface for a PCM5122PWR DAC, configured over I2C. */ @@ -84,6 +169,7 @@ class AudioDac { GpioExpander* gpio_; i2s_chan_handle_t i2s_handle_; bool i2s_active_; + std::optional active_page_; i2s_std_clk_config_t clock_config_; i2s_std_slot_config_t slot_config_; @@ -94,33 +180,12 @@ class AudioDac { */ bool WaitForPowerState(std::function predicate); - enum Register { - PAGE_SELECT = 0, - RESET = 1, - POWER_MODE = 2, - PLL_ENABLE = 4, - DE_EMPHASIS = 7, - PLL_CLOCK_SOURCE = 13, - DAC_CLOCK_SOURCE = 14, - RESYNC_REQUEST = 19, - CLOCK_ERRORS = 37, - INTERPOLATION = 34, - I2S_FORMAT = 40, - DIGITAL_VOLUME_L = 61, - DIGITAL_VOLUME_R = 62, - - SAMPLE_RATE_DETECTION = 91, - BCK_DETECTION = 93, - CLOCK_ERROR_STATE = 94, - CLOCK_STATUS = 95, - AUTO_MUTE_STATE = 108, - SOFT_MUTE_STATE = 114, - SAMPLE_RATE_STATE = 115, - DSP_BOOT_POWER_STATE = 118, - }; + void WriteRegister(pcm512x::Register r, uint8_t val); + uint8_t ReadRegister(pcm512x::Register r); - void WriteRegister(Register reg, uint8_t val); - uint8_t ReadRegister(Register reg); + void SelectPage(uint8_t page); + void WriteRegisterRaw(uint8_t reg, uint8_t val); + uint8_t ReadRegisterRaw(uint8_t reg); }; } // namespace drivers -- cgit v1.2.3 From 7a54ff0df9c18b662e5bdc11ac2e26ff052cfa4d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 4 Apr 2023 14:12:01 +1000 Subject: WIP track down new pipeline memory issues --- src/drivers/include/dac.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index 6836cf59..b84f9bdb 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -26,7 +26,7 @@ class Register { uint8_t page; uint8_t reg; - constexpr Register(uint8_t page, uint8_t reg) : page(page), reg(reg) {} + constexpr Register(uint8_t p, uint8_t r) : page(p), reg(r) {} }; constexpr Register RESET(0, 1); -- cgit v1.2.3 From 4c77950e702a329f3136456a932efbea36e03d42 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 19 Apr 2023 16:45:50 +1000 Subject: Pipeline working and outputting correctly, but noisy --- src/drivers/include/dac.hpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index b84f9bdb..f2ee9b49 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -12,6 +12,7 @@ #include "esp_err.h" #include "freertos/FreeRTOS.h" #include "freertos/portmacro.h" +#include "freertos/stream_buffer.h" #include "result.hpp" #include "span.hpp" @@ -157,6 +158,7 @@ class AudioDac { auto Reconfigure(BitsPerSample bps, SampleRate rate) -> void; auto WriteData(const cpp::span& data) -> void; + auto SetSource(StreamBufferHandle_t *buffer) -> void; auto Stop() -> void; auto LogStatus() -> void; -- cgit v1.2.3 From 731b2cfa77a063e98da8fa26acc1e7ed1de8c169 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 20 Apr 2023 11:25:43 +1000 Subject: working isr-based sink, but still grainy --- src/drivers/include/dac.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index f2ee9b49..d27ed915 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -158,7 +158,7 @@ class AudioDac { auto Reconfigure(BitsPerSample bps, SampleRate rate) -> void; auto WriteData(const cpp::span& data) -> void; - auto SetSource(StreamBufferHandle_t *buffer) -> void; + auto SetSource(StreamBufferHandle_t buffer) -> void; auto Stop() -> void; auto LogStatus() -> void; -- cgit v1.2.3 From 2d95b637272f15ba2d74abc2371d708a08407d91 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 20 Apr 2023 14:47:32 +1000 Subject: Working without big distortion :) --- src/drivers/include/dac.hpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index d27ed915..acdd1743 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -150,8 +150,14 @@ class AudioDac { BPS_32 = I2S_DATA_BIT_WIDTH_32BIT, }; enum SampleRate { + SAMPLE_RATE_11_025 = 11025, + SAMPLE_RATE_16 = 16000, + SAMPLE_RATE_22_05 = 22050, + SAMPLE_RATE_32 = 32000, SAMPLE_RATE_44_1 = 44100, SAMPLE_RATE_48 = 48000, + SAMPLE_RATE_96 = 96000, + SAMPLE_RATE_192 = 192000, }; // TODO(jacqueline): worth supporting channels here as well? -- cgit v1.2.3 From 7083459cf3c62c32d0c039a4665e702d70a27bba Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 21 Apr 2023 15:27:57 +1000 Subject: wrap driver instance ownership + di in a class --- src/drivers/include/dac.hpp | 3 +-- src/drivers/include/display.hpp | 3 +-- src/drivers/include/storage.hpp | 7 +++---- 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index acdd1743..4952c992 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -117,8 +117,7 @@ class AudioDac { FAILED_TO_INSTALL_I2S, }; - static auto create(GpioExpander* expander) - -> cpp::result, Error>; + static auto create(GpioExpander* expander) -> cpp::result; AudioDac(GpioExpander* gpio, i2s_chan_handle_t i2s_handle); ~AudioDac(); diff --git a/src/drivers/include/display.hpp b/src/drivers/include/display.hpp index 8157c3a5..9e4a0224 100644 --- a/src/drivers/include/display.hpp +++ b/src/drivers/include/display.hpp @@ -23,8 +23,7 @@ class Display { * us back any kind of signal to tell us we're actually using them correctly. */ static auto create(GpioExpander* expander, - const displays::InitialisationData& init_data) - -> std::unique_ptr; + const displays::InitialisationData& init_data) -> Display*; Display(GpioExpander* gpio, spi_device_handle_t handle); ~Display(); diff --git a/src/drivers/include/storage.hpp b/src/drivers/include/storage.hpp index 64ce4782..c19ec935 100644 --- a/src/drivers/include/storage.hpp +++ b/src/drivers/include/storage.hpp @@ -25,14 +25,13 @@ class SdStorage { FAILED_TO_MOUNT, }; - static auto create(GpioExpander* gpio) - -> cpp::result, Error>; + static auto create(GpioExpander* gpio) -> cpp::result; SdStorage(GpioExpander* gpio, esp_err_t (*do_transaction)(sdspi_dev_handle_t, sdmmc_command_t*), sdspi_dev_handle_t handle_, - std::unique_ptr& host_, - std::unique_ptr& card_, + std::unique_ptr host_, + std::unique_ptr card_, FATFS* fs_); ~SdStorage(); -- cgit v1.2.3 From 464a4bf527b9da30985a6576f702429621a849a6 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 21 Apr 2023 18:42:49 +1000 Subject: Add a RAII-friendly DI wrapper for driver instances --- src/drivers/include/driver_cache.hpp | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/drivers/include/driver_cache.hpp (limited to 'src/drivers/include') diff --git a/src/drivers/include/driver_cache.hpp b/src/drivers/include/driver_cache.hpp new file mode 100644 index 00000000..c56ebc3f --- /dev/null +++ b/src/drivers/include/driver_cache.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include +#include + +#include "dac.hpp" +#include "display.hpp" +#include "gpio_expander.hpp" +#include "storage.hpp" +#include "touchwheel.hpp" + +namespace drivers { + +class DriverCache { + private: + std::unique_ptr gpios_; + std::weak_ptr dac_; + std::weak_ptr display_; + std::weak_ptr storage_; + std::weak_ptr touchwheel_; + // TODO(jacqueline): Haptics, samd + + std::mutex mutex_; + + template + auto Acquire(std::weak_ptr ptr, F factory) -> std::shared_ptr { + std::shared_ptr acquired = ptr.lock(); + if (acquired) { + return acquired; + } + + std::lock_guard lock(mutex_); + + acquired = ptr.lock(); + if (acquired) { + return acquired; + } + acquired.reset(factory()); + ptr = acquired; + return acquired; + } + + public: + DriverCache(); + ~DriverCache(); + + auto AcquireGpios() -> GpioExpander*; + auto AcquireDac() -> std::shared_ptr; + auto AcquireDisplay() -> std::shared_ptr; + auto AcquireStorage() -> std::shared_ptr; + auto AcquireTouchWheel() -> std::shared_ptr; +}; + +} // namespace drivers -- cgit v1.2.3