From 112a43679f988a4d4c40ecfbece6d78168c5938e Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 28 Sep 2022 15:34:00 +1000 Subject: [PATCH] iterate on gpio expander bit flipping --- main/gay-ipod-fw.cpp | 12 ++++++------ main/gpio-expander.cpp | 4 ++-- main/gpio-expander.h | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/main/gay-ipod-fw.cpp b/main/gay-ipod-fw.cpp index 5d8e677c..025b68cd 100644 --- a/main/gay-ipod-fw.cpp +++ b/main/gay-ipod-fw.cpp @@ -12,7 +12,7 @@ #define I2C_SDA_IO (GPIO_NUM_0) #define I2C_SCL_IO (GPIO_NUM_4) -#define I2C_CLOCK_HZ (400000) +#define I2C_CLOCK_HZ (100000) #define SPI_SDI_IO (GPIO_NUM_19) #define SPI_SDO_IO (GPIO_NUM_23) @@ -38,7 +38,7 @@ esp_err_t init_i2c(void) { .master = { .clk_speed = I2C_CLOCK_HZ, }, - // TODO: check flags + // No requirements for the clock. .clk_flags = 0, }; @@ -46,7 +46,6 @@ esp_err_t init_i2c(void) { ESP_ERROR_CHECK(i2c_driver_install(port, config.mode, 0, 0, 0)); // TODO: INT line - // TODO: add devices to the bus (DAC and GPIO expander) return ESP_OK; } @@ -84,10 +83,11 @@ extern "C" void app_main(void) { ESP_LOGI(TAG, "Initialising peripherals"); init_i2c(); - init_spi(); + //init_spi(); + ESP_LOGI(TAG, "Setting default GPIO state"); gay_ipod::GpioExpander expander; - expander.Write(); + ESP_ERROR_CHECK(expander.Write()); - while (1) {} + ESP_LOGI(TAG, "Idling."); } diff --git a/main/gpio-expander.cpp b/main/gpio-expander.cpp index 2ed9c11f..36132356 100644 --- a/main/gpio-expander.cpp +++ b/main/gpio-expander.cpp @@ -38,8 +38,8 @@ esp_err_t GpioExpander::Read() { // it because that would indicate some really very badly wrong more generally. i2c_master_start(handle); i2c_master_write_byte(handle, (PCA8575_ADDRESS << 1 | I2C_MASTER_READ), true); - i2c_master_read_byte(handle, &input_a_, I2C_MASTER_ACK); - i2c_master_read_byte(handle, &input_b_, I2C_MASTER_LAST_NACK); + i2c_master_read_byte(handle, &port_a_, I2C_MASTER_ACK); + i2c_master_read_byte(handle, &port_b_, I2C_MASTER_LAST_NACK); i2c_master_stop(handle); esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_0, handle, PCA8575_TIMEOUT); diff --git a/main/gpio-expander.h b/main/gpio-expander.h index 26668f46..a4983705 100644 --- a/main/gpio-expander.h +++ b/main/gpio-expander.h @@ -33,10 +33,10 @@ class GpioExpander { GpioExpander& operator=(const GpioExpander&) = delete; private: - // All power switches low, both CS pins high, active-low PWR_OK high. - uint8_t port_a_ = 0b00001011; - // DAC mute output low, everything eelse is input and so held high. - uint8_t port_b_ = 0b10111111; + // All power switches high, PWR_OK low (input), both CS pins high. + uint8_t port_a_ = uint8_t{0b00001000}; + // DAC mute output low, everything else is input and so low. + uint8_t port_b_ = uint8_t{0b11111111}; uint8_t input_a_ = 0; uint8_t input_b_ = 0;