From 8babfaa5cf1d2636b3bce8320c9c2ab353e2153f Mon Sep 17 00:00:00 2001 From: scilor Date: Sat, 13 Jun 2020 16:03:12 +0200 Subject: [PATCH 01/10] Watchdog code cleaning --- Hackiebox.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/Hackiebox.cpp b/Hackiebox.cpp index 0ceaaf2..bc50968 100755 --- a/Hackiebox.cpp +++ b/Hackiebox.cpp @@ -83,37 +83,20 @@ void watchdog_handler() { } bool Hackiebox::watchdog_start() { watchdog_feed(); - // Enable the peripherals used by this example. - MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK); - // Unlock to be able to configure the registers + MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK); MAP_WatchdogUnlock(WDT_BASE); - - //if (fpAppWDTCB != NULL) { - MAP_IntPrioritySet(INT_WDT, INT_PRIORITY_LVL_1); - MAP_WatchdogIntRegister(WDT_BASE, watchdog_handler); - //} - - - // Set the watchdog timer reload value + MAP_IntPrioritySet(INT_WDT, INT_PRIORITY_LVL_1); + MAP_WatchdogIntRegister(WDT_BASE, watchdog_handler); MAP_WatchdogReloadSet(WDT_BASE, 80000000*15); //15s - - // Start the timer. Once the timer is started, it cannot be disable. MAP_WatchdogEnable(WDT_BASE); return MAP_WatchdogRunning(WDT_BASE); } void Hackiebox::watchdog_stop() { - // Unlock to be able to configure the registers MAP_WatchdogUnlock(WDT_BASE); - - // Disable stalling of the watchdog timer during debug events MAP_WatchdogStallDisable(WDT_BASE); - - // Clear the interrupt MAP_WatchdogIntClear(WDT_BASE); - - // Unregister the interrupt MAP_WatchdogIntUnregister(WDT_BASE); } From c54e8152d4ae4286ec45087a1fdc1b9715faffa6 Mon Sep 17 00:00:00 2001 From: scilor Date: Mon, 15 Jun 2020 17:33:15 +0200 Subject: [PATCH 02/10] DAC Stub --- BoxDAC.cpp | 9 +++++++++ BoxDAC.h | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 BoxDAC.cpp create mode 100644 BoxDAC.h diff --git a/BoxDAC.cpp b/BoxDAC.cpp new file mode 100644 index 0000000..27ea84c --- /dev/null +++ b/BoxDAC.cpp @@ -0,0 +1,9 @@ +#include "BoxDAC.h" + +void BoxDAC::begin() { + +} + +void BoxDAC::loop() { + +} \ No newline at end of file diff --git a/BoxDAC.h b/BoxDAC.h new file mode 100644 index 0000000..759facd --- /dev/null +++ b/BoxDAC.h @@ -0,0 +1,15 @@ +#ifndef BoxDAC_h +#define BoxDAC_h + +#include "BaseHeader.h" + +class BoxDAC { + public: + void + begin(), + loop(); + //private: + +} + +#endif \ No newline at end of file From 89e1c8cb4e4d68482be2d03c7628d6a1c18365a5 Mon Sep 17 00:00:00 2001 From: scilor Date: Mon, 15 Jun 2020 19:04:40 +0200 Subject: [PATCH 03/10] DAC Stub --- BoxDAC.cpp | 17 +++++++++++++++++ BoxDAC.h | 14 ++++++++++++++ Hackiebox.cpp | 2 ++ Hackiebox.h | 4 +++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 BoxDAC.cpp create mode 100644 BoxDAC.h diff --git a/BoxDAC.cpp b/BoxDAC.cpp new file mode 100644 index 0000000..f619afd --- /dev/null +++ b/BoxDAC.cpp @@ -0,0 +1,17 @@ +#include "BoxDAC.h" + +void BoxDAC::begin() { + Log.info("Initialize DAC..."); + //RESET + pinMode(62, OUTPUT); + digitalWrite(62, HIGH); + delayMicroseconds(1); //Be sure + + + + Log.info("...initialized"); +} + +void BoxDAC::loop() { + +} \ No newline at end of file diff --git a/BoxDAC.h b/BoxDAC.h new file mode 100644 index 0000000..27dbc64 --- /dev/null +++ b/BoxDAC.h @@ -0,0 +1,14 @@ +#ifndef BoxDAC_h +#define BoxDAC_h + +#include "BaseHeader.h" +#include + +class BoxDAC : public EnhancedThread { + public: + void + begin(), + loop(); +}; + +#endif \ No newline at end of file diff --git a/Hackiebox.cpp b/Hackiebox.cpp index bc50968..281dfb6 100755 --- a/Hackiebox.cpp +++ b/Hackiebox.cpp @@ -27,6 +27,7 @@ void Hackiebox::setup() { boxEars.begin(); boxAccel.begin(); boxRFID.begin(); + boxDAC.begin(); boxWiFi = WrapperWiFi(config->wifi.ssid, config->wifi.password); boxWiFi.begin(); @@ -46,6 +47,7 @@ void Hackiebox::setup() { Log.info("Config: %s", Config.getAsJson().c_str()); boxAccel.onRun(ThreadCallbackHandler([&]() { boxAccel.loop(); })); + boxDAC.onRun(ThreadCallbackHandler([&]() { boxDAC.loop(); })); boxRFID.onRun(ThreadCallbackHandler([&]() { boxRFID.loop(); })); boxPower.onRun(ThreadCallbackHandler([&]() { boxPower.loop(); })); boxLEDs.onRun(ThreadCallbackHandler([&]() { boxLEDs.loop(); })); diff --git a/Hackiebox.h b/Hackiebox.h index 14e9cea..c912b4f 100644 --- a/Hackiebox.h +++ b/Hackiebox.h @@ -13,6 +13,7 @@ #include "BoxAccelerometer.h" #include "BoxBattery.h" #include "BoxButtonEars.h" +#include "BoxDAC.h" #include "BoxEvents.h" #include "BoxLEDs.h" #include "BoxPower.h" @@ -42,7 +43,8 @@ class Hackiebox { BoxAccelerometer boxAccel; BoxBattery boxBattery; - BoxButtonEars boxEars; + BoxButtonEars boxEars; + BoxDAC boxDAC; BoxLEDs boxLEDs; BoxPower boxPower; BoxRFID boxRFID; From 0e9f3dad2a95eafc9fb9f8fad2db4c9cdd56b262 Mon Sep 17 00:00:00 2001 From: scilor Date: Mon, 15 Jun 2020 20:40:16 +0200 Subject: [PATCH 04/10] start implementing the dac --- BoxDAC.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- BoxDAC.h | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) diff --git a/BoxDAC.cpp b/BoxDAC.cpp index f619afd..533bc98 100644 --- a/BoxDAC.cpp +++ b/BoxDAC.cpp @@ -1,5 +1,7 @@ #include "BoxDAC.h" +#include + void BoxDAC::begin() { Log.info("Initialize DAC..."); //RESET @@ -7,11 +9,77 @@ void BoxDAC::begin() { digitalWrite(62, HIGH); delayMicroseconds(1); //Be sure - + Wire.begin(); + + //Extracted from logic analyzer capture of box + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::SOFTWARE_RESET, 0x01); //Self-clearing software reset for control register + send(ADDR_P0_SERIAL::CLOCKGEN_MUX, 0x07); + send(ADDR_P0_SERIAL::PLL_J_VAL, 0x20); + send(ADDR_P0_SERIAL::PLL_D_VAL_MSB, 0x00); + send(ADDR_P0_SERIAL::PLL_D_VAL_LSB, 0x00); + send(ADDR_P0_SERIAL::PLL_P_R_VAL, 0x96); + send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x84); + send(ADDR_P0_SERIAL::DAC_MDAC_VAL, 0x86); + send(ADDR_P0_SERIAL::DAC_DOSR_VAL_MSB, 0x01); + send(ADDR_P0_SERIAL::DAC_DOSR_VAL_LSB, 0x00); + send(ADDR_P0_SERIAL::CODEC_INT_CTRL1, 0x00); + send(ADDR_P0_SERIAL::DAC_PROC_BLOCK_SEL, 0x19); + + send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL); + send(ADDR_P1_DAC_OUT::HP_OUT_POP_REM_SET, 0x4E); + send(ADDR_P1_DAC_OUT::OUT_PGA_RAMP_DOWN_PER_CTRL, 0x70); + send(ADDR_P1_DAC_OUT::DAC_LR_OUT_MIX_ROUTING, 0x44); + send(ADDR_P1_DAC_OUT::MICBIAS, 0x0B); + send(ADDR_P1_DAC_OUT::HP_CTRL, 0xE0); + + send(ADDR::PAGE_CONTROL, PAGE::MCLK_DIVIDER); + send(ADDR_P3_MCLK::TIMER_CLK_MCLK_DIV, 0x01); + + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(0x43, 0x8C); + send(0x30, 0x80); + send(0x33, 0x14); +/* + //send(0x2E); + //read 0x31 addr + send(0x00, 0x00) + send(0x00, 0x00)*/ + + //Testing custom code + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x0C); //mute DACs + //f 30 26 xxx1xxx1 # wait for DAC gain flag to be set + send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x02); //power down NDAC divider + send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, + send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x84); //power up NDAC divider + send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x00); //unmute DACs + + Log.info("...initialized"); } void BoxDAC::loop() { -} \ No newline at end of file +} + +void BoxDAC::send(uint8_t target_register, uint8_t data) { + //0x30 - 8bit / 0x18 - 7bit + Wire.write(0x00); + Wire.write(target_register); + Wire.write(data); +} +void BoxDAC::send(ADDR target_register, PAGE data) { + send((uint8_t)target_register, (uint8_t)data); +} +void BoxDAC::send(ADDR_P0_SERIAL target_register, uint8_t data) { + send((uint8_t)target_register, data); +} +void BoxDAC::send(ADDR_P1_DAC_OUT target_register, uint8_t data) { + send((uint8_t)target_register, data); +} +void BoxDAC::send(ADDR_P3_MCLK target_register, uint8_t data) { + send((uint8_t)target_register, data); +} + diff --git a/BoxDAC.h b/BoxDAC.h index 27dbc64..329c272 100644 --- a/BoxDAC.h +++ b/BoxDAC.h @@ -9,6 +9,53 @@ class BoxDAC : public EnhancedThread { void begin(), loop(); + + private: + enum class PAGE { + SERIAL_IO = 0x00, + DAC_OUT_VOL = 0x01, + MCLK_DIVIDER = 0x03, + DAC_FILTER_DRC_COE_1A = 0x08, + DAC_FILTER_DRC_COE_2A = 0x09, + DAC_FILTER_DRC_COE_1B = 0x0C, + DAC_FILTER_DRC_COE_2B = 0x0D, + }; + enum class ADDR { + PAGE_CONTROL = 0x00, + }; + enum class ADDR_P0_SERIAL { + SOFTWARE_RESET = 0x01, + CLOCKGEN_MUX = 0x04, + PLL_P_R_VAL = 0x05, + PLL_J_VAL = 0x06, + PLL_D_VAL_MSB = 0x07, + PLL_D_VAL_LSB = 0x08, + DAC_NDAC_VAL = 0x0B, + DAC_MDAC_VAL = 0x0C, + DAC_DOSR_VAL_MSB = 0x0D, + DAC_DOSR_VAL_LSB = 0x0E, + CODEC_INT_CTRL1 = 0x1B, + DAC_PROC_BLOCK_SEL = 0x3C, + DAC_VOL_CTRL = 0x40, + BEEP_L_GEN = 0x47, + BEEP_R_GEN = 0x48, + }; + enum class ADDR_P1_DAC_OUT { + HP_OUT_POP_REM_SET = 0x21, + OUT_PGA_RAMP_DOWN_PER_CTRL = 0x22, + DAC_LR_OUT_MIX_ROUTING = 0x23, + HP_CTRL = 0x2C, + MICBIAS = 0x2E, + }; + enum class ADDR_P3_MCLK { + TIMER_CLK_MCLK_DIV = 0x10, + }; + + void send(uint8_t target_register, uint8_t data); + void send(ADDR target_register, PAGE data); + void send(ADDR_P0_SERIAL target_register, uint8_t data); + void send(ADDR_P1_DAC_OUT target_register, uint8_t data); + void send(ADDR_P3_MCLK target_register, uint8_t data); }; #endif \ No newline at end of file From e2ad5a5a71f00f386ddb665ef50b4502744b01c6 Mon Sep 17 00:00:00 2001 From: scilor Date: Mon, 15 Jun 2020 20:46:39 +0200 Subject: [PATCH 05/10] start implementing the dac --- BoxDAC.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- BoxDAC.h | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) diff --git a/BoxDAC.cpp b/BoxDAC.cpp index f619afd..533bc98 100644 --- a/BoxDAC.cpp +++ b/BoxDAC.cpp @@ -1,5 +1,7 @@ #include "BoxDAC.h" +#include + void BoxDAC::begin() { Log.info("Initialize DAC..."); //RESET @@ -7,11 +9,77 @@ void BoxDAC::begin() { digitalWrite(62, HIGH); delayMicroseconds(1); //Be sure - + Wire.begin(); + + //Extracted from logic analyzer capture of box + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::SOFTWARE_RESET, 0x01); //Self-clearing software reset for control register + send(ADDR_P0_SERIAL::CLOCKGEN_MUX, 0x07); + send(ADDR_P0_SERIAL::PLL_J_VAL, 0x20); + send(ADDR_P0_SERIAL::PLL_D_VAL_MSB, 0x00); + send(ADDR_P0_SERIAL::PLL_D_VAL_LSB, 0x00); + send(ADDR_P0_SERIAL::PLL_P_R_VAL, 0x96); + send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x84); + send(ADDR_P0_SERIAL::DAC_MDAC_VAL, 0x86); + send(ADDR_P0_SERIAL::DAC_DOSR_VAL_MSB, 0x01); + send(ADDR_P0_SERIAL::DAC_DOSR_VAL_LSB, 0x00); + send(ADDR_P0_SERIAL::CODEC_INT_CTRL1, 0x00); + send(ADDR_P0_SERIAL::DAC_PROC_BLOCK_SEL, 0x19); + + send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL); + send(ADDR_P1_DAC_OUT::HP_OUT_POP_REM_SET, 0x4E); + send(ADDR_P1_DAC_OUT::OUT_PGA_RAMP_DOWN_PER_CTRL, 0x70); + send(ADDR_P1_DAC_OUT::DAC_LR_OUT_MIX_ROUTING, 0x44); + send(ADDR_P1_DAC_OUT::MICBIAS, 0x0B); + send(ADDR_P1_DAC_OUT::HP_CTRL, 0xE0); + + send(ADDR::PAGE_CONTROL, PAGE::MCLK_DIVIDER); + send(ADDR_P3_MCLK::TIMER_CLK_MCLK_DIV, 0x01); + + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(0x43, 0x8C); + send(0x30, 0x80); + send(0x33, 0x14); +/* + //send(0x2E); + //read 0x31 addr + send(0x00, 0x00) + send(0x00, 0x00)*/ + + //Testing custom code + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x0C); //mute DACs + //f 30 26 xxx1xxx1 # wait for DAC gain flag to be set + send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x02); //power down NDAC divider + send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, + send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x84); //power up NDAC divider + send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x00); //unmute DACs + + Log.info("...initialized"); } void BoxDAC::loop() { -} \ No newline at end of file +} + +void BoxDAC::send(uint8_t target_register, uint8_t data) { + //0x30 - 8bit / 0x18 - 7bit + Wire.write(0x00); + Wire.write(target_register); + Wire.write(data); +} +void BoxDAC::send(ADDR target_register, PAGE data) { + send((uint8_t)target_register, (uint8_t)data); +} +void BoxDAC::send(ADDR_P0_SERIAL target_register, uint8_t data) { + send((uint8_t)target_register, data); +} +void BoxDAC::send(ADDR_P1_DAC_OUT target_register, uint8_t data) { + send((uint8_t)target_register, data); +} +void BoxDAC::send(ADDR_P3_MCLK target_register, uint8_t data) { + send((uint8_t)target_register, data); +} + diff --git a/BoxDAC.h b/BoxDAC.h index 27dbc64..329c272 100644 --- a/BoxDAC.h +++ b/BoxDAC.h @@ -9,6 +9,53 @@ class BoxDAC : public EnhancedThread { void begin(), loop(); + + private: + enum class PAGE { + SERIAL_IO = 0x00, + DAC_OUT_VOL = 0x01, + MCLK_DIVIDER = 0x03, + DAC_FILTER_DRC_COE_1A = 0x08, + DAC_FILTER_DRC_COE_2A = 0x09, + DAC_FILTER_DRC_COE_1B = 0x0C, + DAC_FILTER_DRC_COE_2B = 0x0D, + }; + enum class ADDR { + PAGE_CONTROL = 0x00, + }; + enum class ADDR_P0_SERIAL { + SOFTWARE_RESET = 0x01, + CLOCKGEN_MUX = 0x04, + PLL_P_R_VAL = 0x05, + PLL_J_VAL = 0x06, + PLL_D_VAL_MSB = 0x07, + PLL_D_VAL_LSB = 0x08, + DAC_NDAC_VAL = 0x0B, + DAC_MDAC_VAL = 0x0C, + DAC_DOSR_VAL_MSB = 0x0D, + DAC_DOSR_VAL_LSB = 0x0E, + CODEC_INT_CTRL1 = 0x1B, + DAC_PROC_BLOCK_SEL = 0x3C, + DAC_VOL_CTRL = 0x40, + BEEP_L_GEN = 0x47, + BEEP_R_GEN = 0x48, + }; + enum class ADDR_P1_DAC_OUT { + HP_OUT_POP_REM_SET = 0x21, + OUT_PGA_RAMP_DOWN_PER_CTRL = 0x22, + DAC_LR_OUT_MIX_ROUTING = 0x23, + HP_CTRL = 0x2C, + MICBIAS = 0x2E, + }; + enum class ADDR_P3_MCLK { + TIMER_CLK_MCLK_DIV = 0x10, + }; + + void send(uint8_t target_register, uint8_t data); + void send(ADDR target_register, PAGE data); + void send(ADDR_P0_SERIAL target_register, uint8_t data); + void send(ADDR_P1_DAC_OUT target_register, uint8_t data); + void send(ADDR_P3_MCLK target_register, uint8_t data); }; #endif \ No newline at end of file From 28c0629bf615108ad957c4c5d88ab62e09a7aac1 Mon Sep 17 00:00:00 2001 From: scilor Date: Mon, 15 Jun 2020 22:03:33 +0200 Subject: [PATCH 06/10] fixed i2c, some experiment (not working!) --- BoxDAC.cpp | 48 ++++++++++++++++++++++++++++++++---------------- BoxDAC.h | 12 +++++++----- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/BoxDAC.cpp b/BoxDAC.cpp index 400c6db..612811f 100644 --- a/BoxDAC.cpp +++ b/BoxDAC.cpp @@ -13,6 +13,7 @@ void BoxDAC::begin() { //Extracted from logic analyzer capture of box send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); send(ADDR_P0_SERIAL::SOFTWARE_RESET, 0x01); //Self-clearing software reset for control register + send(ADDR_P0_SERIAL::CLOCKGEN_MUX, 0x07); send(ADDR_P0_SERIAL::PLL_J_VAL, 0x20); send(ADDR_P0_SERIAL::PLL_D_VAL_MSB, 0x00); @@ -39,18 +40,21 @@ void BoxDAC::begin() { send(0x43, 0x8C); send(0x30, 0x80); send(0x33, 0x14); -/* + //send(0x2E); //read 0x31 addr - send(0x00, 0x00) - send(0x00, 0x00)*/ //Testing custom code send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x0C); //mute DACs //f 30 26 xxx1xxx1 # wait for DAC gain flag to be set send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x02); //power down NDAC divider - send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, + for (uint32_t i = 0; i<10; i++) { + send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, + delay(50); + send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, + delay(100); + } send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x84); //power up NDAC divider send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x00); //unmute DACs @@ -62,21 +66,33 @@ void BoxDAC::begin() { void BoxDAC::loop() { } -void BoxDAC::send(uint8_t target_register, uint8_t data) { +bool BoxDAC::send_raw(uint8_t data) { + delay(1); + if (!Wire.write(data)) { + Log.error("Could not write into I2C Buffer"); + return false; + } + return true; +} +bool BoxDAC::send(uint8_t target_register, uint8_t data) { //0x30 - 8bit / 0x18 - 7bit - Wire.write(0x00); - Wire.write(target_register); - Wire.write(data); + Wire.beginTransmission(0x18); + if (!send_raw(target_register)) return false; + if (!send_raw(data)) return false; + + uint8_t result = Wire.endTransmission(false); + if (!result) return true; + Log.error("Could not send I2C buffer, error=%i", result); } -void BoxDAC::send(ADDR target_register, PAGE data) { - send((uint8_t)target_register, (uint8_t)data); +bool BoxDAC::send(ADDR target_register, PAGE data) { + return send((uint8_t)target_register, (uint8_t)data); } -void BoxDAC::send(ADDR_P0_SERIAL target_register, uint8_t data) { - send((uint8_t)target_register, data); +bool BoxDAC::send(ADDR_P0_SERIAL target_register, uint8_t data) { + return send((uint8_t)target_register, data); } -void BoxDAC::send(ADDR_P1_DAC_OUT target_register, uint8_t data) { - send((uint8_t)target_register, data); +bool BoxDAC::send(ADDR_P1_DAC_OUT target_register, uint8_t data) { + return send((uint8_t)target_register, data); } -void BoxDAC::send(ADDR_P3_MCLK target_register, uint8_t data) { - send((uint8_t)target_register, data); +bool BoxDAC::send(ADDR_P3_MCLK target_register, uint8_t data) { + return send((uint8_t)target_register, data); } \ No newline at end of file diff --git a/BoxDAC.h b/BoxDAC.h index 329c272..40a78f6 100644 --- a/BoxDAC.h +++ b/BoxDAC.h @@ -51,11 +51,13 @@ class BoxDAC : public EnhancedThread { TIMER_CLK_MCLK_DIV = 0x10, }; - void send(uint8_t target_register, uint8_t data); - void send(ADDR target_register, PAGE data); - void send(ADDR_P0_SERIAL target_register, uint8_t data); - void send(ADDR_P1_DAC_OUT target_register, uint8_t data); - void send(ADDR_P3_MCLK target_register, uint8_t data); + bool + send_raw(uint8_t data), + send(uint8_t target_register, uint8_t data), + send(ADDR target_register, PAGE data), + send(ADDR_P0_SERIAL target_register, uint8_t data), + send(ADDR_P1_DAC_OUT target_register, uint8_t data), + send(ADDR_P3_MCLK target_register, uint8_t data); }; #endif \ No newline at end of file From f874829c9265981c163744dcda1c0a70061e4d82 Mon Sep 17 00:00:00 2001 From: scilor Date: Mon, 15 Jun 2020 22:26:38 +0200 Subject: [PATCH 07/10] Speaker is on, but still no real sound --- BoxDAC.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/BoxDAC.cpp b/BoxDAC.cpp index 612811f..2322bf4 100644 --- a/BoxDAC.cpp +++ b/BoxDAC.cpp @@ -42,12 +42,29 @@ void BoxDAC::begin() { send(0x33, 0x14); //send(0x2E); - //read 0x31 addr + //read 0x31 addr*/ //Testing custom code + send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL); + send(0x28,0x06); + send(0x29,0x06); + send(0x2A,0x1C); + + send(0x20, 0x86); + send(0x24, 0x92); + send(0x25, 0x92); + send(0x26, 0x92); + + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(0x3F, 0xD4); + send(0x41, 0xD4); + send(0x42, 0xD4); + + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x0C); //mute DACs //f 30 26 xxx1xxx1 # wait for DAC gain flag to be set + delay(1000); send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x02); //power down NDAC divider for (uint32_t i = 0; i<10; i++) { send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, @@ -67,7 +84,6 @@ void BoxDAC::loop() { } bool BoxDAC::send_raw(uint8_t data) { - delay(1); if (!Wire.write(data)) { Log.error("Could not write into I2C Buffer"); return false; From 1f5872ebd5e24e30c7a3762e5fdb9b9962fed8c1 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 16 Jun 2020 17:27:07 +0200 Subject: [PATCH 08/10] more commands implemented. replicated box behaviour --- BoxDAC.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++---------- BoxDAC.h | 17 ++++++++- 2 files changed, 101 insertions(+), 21 deletions(-) diff --git a/BoxDAC.cpp b/BoxDAC.cpp index 2322bf4..6b3f32d 100644 --- a/BoxDAC.cpp +++ b/BoxDAC.cpp @@ -10,10 +10,10 @@ void BoxDAC::begin() { Wire.begin(); + //Extracted from logic analyzer capture of box send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); send(ADDR_P0_SERIAL::SOFTWARE_RESET, 0x01); //Self-clearing software reset for control register - send(ADDR_P0_SERIAL::CLOCKGEN_MUX, 0x07); send(ADDR_P0_SERIAL::PLL_J_VAL, 0x20); send(ADDR_P0_SERIAL::PLL_D_VAL_MSB, 0x00); @@ -31,45 +31,110 @@ void BoxDAC::begin() { send(ADDR_P1_DAC_OUT::OUT_PGA_RAMP_DOWN_PER_CTRL, 0x70); send(ADDR_P1_DAC_OUT::DAC_LR_OUT_MIX_ROUTING, 0x44); send(ADDR_P1_DAC_OUT::MICBIAS, 0x0B); - send(ADDR_P1_DAC_OUT::HP_CTRL, 0xE0); + send(ADDR_P1_DAC_OUT::HP_DRIVER_CTRL, 0xE0); send(ADDR::PAGE_CONTROL, PAGE::MCLK_DIVIDER); send(ADDR_P3_MCLK::TIMER_CLK_MCLK_DIV, 0x01); send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); - send(0x43, 0x8C); - send(0x30, 0x80); - send(0x33, 0x14); - - //send(0x2E); - //read 0x31 addr*/ + send(ADDR_P0_SERIAL::HEADSET_DETECT, 0x8C); + send(ADDR_P0_SERIAL::INT1_CTRL_REG, 0x80); + send(ADDR_P0_SERIAL::GPIO1_INOUT_CTRL, 0x14); + //send(0x2E); Excel 161 + //read 0x18 addr - //Testing custom code send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL); - send(0x28,0x06); - send(0x29,0x06); - send(0x2A,0x1C); + send(ADDR_P1_DAC_OUT::L_VOL_TO_HPL, 0x7F); + send(ADDR_P1_DAC_OUT::R_VOL_TO_HPR, 0x7F); + send(ADDR_P1_DAC_OUT::L_VOL_TO_SPK, 0x7F); + send(ADDR_P1_DAC_OUT::HPL_DRIVER, 0x00); + send(ADDR_P1_DAC_OUT::HPR_DRIVER, 0x00); + send(ADDR_P1_DAC_OUT::SPK_DRIVER, 0x00); + send(ADDR_P1_DAC_OUT::HP_DRIVERS, 0x00); + send(ADDR_P1_DAC_OUT::SPK_AMP, 0x00); + send(ADDR_P1_DAC_OUT::HPL_DRIVER, 0x06); + send(ADDR_P1_DAC_OUT::HPR_DRIVER, 0x06); + send(ADDR_P1_DAC_OUT::HP_DRIVERS, 0xC2); + send(ADDR_P1_DAC_OUT::L_VOL_TO_HPL, 0x92); + send(ADDR_P1_DAC_OUT::R_VOL_TO_HPR, 0x92); + + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::DAC_DATA_PATH_SETUP, 0xD5); + send(ADDR_P0_SERIAL::DAC_VOL_L_CTRL, 0xDC); + send(ADDR_P0_SERIAL::DAC_VOL_R_CTRL, 0xDC); + //Excel 219 + // Extract END + - send(0x20, 0x86); - send(0x24, 0x92); - send(0x25, 0x92); - send(0x26, 0x92); + //Testing custom code, recommened Initialization code by chip doc + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::SOFTWARE_RESET, 0x01); //Self-clearing software reset for control register + send(ADDR_P0_SERIAL::CLOCKGEN_MUX, 0x03); + send(ADDR_P0_SERIAL::PLL_J_VAL, 0x08); + send(ADDR_P0_SERIAL::PLL_D_VAL_MSB, 0x00); //30 07 00 00 + send(ADDR_P0_SERIAL::PLL_D_VAL_LSB, 0x00); + send(ADDR_P0_SERIAL::PLL_P_R_VAL, 0x91); + send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x88); + send(ADDR_P0_SERIAL::DAC_MDAC_VAL, 0x82); + send(ADDR_P0_SERIAL::DAC_DOSR_VAL_MSB, 0x00); //30 0D 00 80 + send(ADDR_P0_SERIAL::DAC_DOSR_VAL_LSB, 0x80); + + send(ADDR_P0_SERIAL::CODEC_INT_CTRL1, 0x00); + send(ADDR_P0_SERIAL::DAC_PROC_BLOCK_SEL, 0x0B); + send(0x00, 0x08);//TODO! + send(0x01, 0x04);//TODO! send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); - send(0x3F, 0xD4); - send(0x41, 0xD4); - send(0x42, 0xD4); + send(ADDR_P0_SERIAL::VOL_MICDET_SAR_ADC, 0x00); + send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL); + send(ADDR_P1_DAC_OUT::HP_DRIVERS, 0x04); + send(ADDR_P1_DAC_OUT::HP_OUT_POP_REM_SET, 0x4E); + send(ADDR_P1_DAC_OUT::DAC_LR_OUT_MIX_ROUTING, 0x44); + send(ADDR_P1_DAC_OUT::HPL_DRIVER, 0x06); + send(ADDR_P1_DAC_OUT::HPR_DRIVER, 0x06); + send(ADDR_P1_DAC_OUT::SPK_DRIVER, 0x1C); + send(ADDR_P1_DAC_OUT::HP_DRIVERS, 0xC2); + send(ADDR_P1_DAC_OUT::SPK_AMP, 0x86); + send(ADDR_P1_DAC_OUT::L_VOL_TO_HPL, 0x92); + send(ADDR_P1_DAC_OUT::R_VOL_TO_HPR, 0x92); + send(ADDR_P1_DAC_OUT::L_VOL_TO_SPK, 0x92); + + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::DAC_DATA_PATH_SETUP, 0xD4); + send(ADDR_P0_SERIAL::DAC_VOL_L_CTRL, 0xD4); + send(ADDR_P0_SERIAL::DAC_VOL_R_CTRL, 0xD4); + send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x00); + + + /* + send(ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL); + send(ADDR_P1_DAC_OUT::HPL_DRIVER, 0x06); + send(ADDR_P1_DAC_OUT::HPR_DRIVER, 0x06); + send(ADDR_P1_DAC_OUT::SPK_DRIVER, 0x1C); + send(ADDR_P1_DAC_OUT::SPK_AMP, 0x86); + send(ADDR_P1_DAC_OUT::L_VOL_TO_HPL, 0x92); + send(ADDR_P1_DAC_OUT::R_VOL_TO_HPR, 0x92); + send(ADDR_P1_DAC_OUT::L_VOL_TO_SPK, 0x92); + + send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); + send(ADDR_P0_SERIAL::DAC_DATA_PATH_SETUP, 0xD4); + send(ADDR_P0_SERIAL::DAC_VOL_L_CTRL, 0xD4); + send(ADDR_P0_SERIAL::DAC_VOL_R_CTRL, 0xD4); + */ + //recommened cdoe for beep by chip doc send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x0C); //mute DACs //f 30 26 xxx1xxx1 # wait for DAC gain flag to be set - delay(1000); + delay(500); send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x02); //power down NDAC divider for (uint32_t i = 0; i<10; i++) { send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, + send(ADDR_P0_SERIAL::BEEP_R_GEN, 0x00); delay(50); send(ADDR_P0_SERIAL::BEEP_L_GEN, 0x80); //enable beep generator with left channel volume = 0dB, + send(ADDR_P0_SERIAL::BEEP_R_GEN, 0x00); delay(100); } send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x84); //power up NDAC divider diff --git a/BoxDAC.h b/BoxDAC.h index 40a78f6..5e1e45a 100644 --- a/BoxDAC.h +++ b/BoxDAC.h @@ -35,16 +35,31 @@ class BoxDAC : public EnhancedThread { DAC_DOSR_VAL_MSB = 0x0D, DAC_DOSR_VAL_LSB = 0x0E, CODEC_INT_CTRL1 = 0x1B, + INT1_CTRL_REG = 0x30, + GPIO1_INOUT_CTRL = 0x33, DAC_PROC_BLOCK_SEL = 0x3C, + DAC_DATA_PATH_SETUP = 0x3F, DAC_VOL_CTRL = 0x40, + DAC_VOL_L_CTRL = 0x41, + DAC_VOL_R_CTRL = 0x42, + HEADSET_DETECT = 0x43, BEEP_L_GEN = 0x47, BEEP_R_GEN = 0x48, + VOL_MICDET_SAR_ADC = 0x74, }; enum class ADDR_P1_DAC_OUT { + HP_DRIVERS = 0x1F, + SPK_AMP = 0x20, HP_OUT_POP_REM_SET = 0x21, OUT_PGA_RAMP_DOWN_PER_CTRL = 0x22, DAC_LR_OUT_MIX_ROUTING = 0x23, - HP_CTRL = 0x2C, + L_VOL_TO_HPL = 0x24, + R_VOL_TO_HPR = 0x25, + L_VOL_TO_SPK = 0x26, + HPL_DRIVER = 0x28, + HPR_DRIVER = 0x29, + SPK_DRIVER = 0x2A, + HP_DRIVER_CTRL = 0x2C, MICBIAS = 0x2E, }; enum class ADDR_P3_MCLK { From 0ebcaa12f1583fa2235503fc58c7977c50e67279 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 16 Jun 2020 20:23:44 +0200 Subject: [PATCH 09/10] Enlarge storage space for config (otherwise long passwords may corrupt it when reading the json file) --- BoxConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BoxConfig.h b/BoxConfig.h index ab6bcaa..ca4d2f3 100644 --- a/BoxConfig.h +++ b/BoxConfig.h @@ -5,7 +5,7 @@ #include "ConfigStructures.h" #include "BoxSD.h" -#define BOXCONFIG_JSON_SIZE 382 //Size from https://arduinojson.org/v6/assistant/ +#define BOXCONFIG_JSON_SIZE 447 //Size from https://arduinojson.org/v6/assistant/ class BoxConfig { public: From e3f1ecd379226e120916452df39f5bd4f130dec4 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 16 Jun 2020 20:41:01 +0200 Subject: [PATCH 10/10] Credits to bluenazgul --- web/hackiebox.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/hackiebox.html b/web/hackiebox.html index 7ab1c6d..8ddcae0 100644 --- a/web/hackiebox.html +++ b/web/hackiebox.html @@ -335,6 +335,11 @@

Credits

Creating the cc3200tool + + bluenazgul + Testing + + Telegram Toniebox Hacking Community THX2YOU