summaryrefslogtreecommitdiff
path: root/src/drivers/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-04-04 09:46:52 +1000
committerjacqueline <me@jacqueline.id.au>2023-04-19 10:29:40 +1000
commit40a9734b04c48339cfdf6ed9043aa3f6f0dda62d (patch)
tree4e4d75a3d7c1cc1ec5d0505595224af077940128 /src/drivers/include
parent3836768bb8b95188e6657ab69027d1d9e4b13a77 (diff)
downloadtangara-fw-40a9734b04c48339cfdf6ed9043aa3f6f0dda62d.tar.gz
Redo pcm registers to include pages
Diffstat (limited to 'src/drivers/include')
-rw-r--r--src/drivers/include/dac.hpp117
1 files changed, 91 insertions, 26 deletions
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<uint8_t> 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<bool(bool, PowerState)> 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