iterate on gpio expander bit flipping

custom
jacqueline 3 years ago
parent 5d8531642c
commit 112a43679f
  1. 12
      main/gay-ipod-fw.cpp
  2. 4
      main/gpio-expander.cpp
  3. 8
      main/gpio-expander.h

@ -12,7 +12,7 @@
#define I2C_SDA_IO (GPIO_NUM_0) #define I2C_SDA_IO (GPIO_NUM_0)
#define I2C_SCL_IO (GPIO_NUM_4) #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_SDI_IO (GPIO_NUM_19)
#define SPI_SDO_IO (GPIO_NUM_23) #define SPI_SDO_IO (GPIO_NUM_23)
@ -38,7 +38,7 @@ esp_err_t init_i2c(void) {
.master = { .master = {
.clk_speed = I2C_CLOCK_HZ, .clk_speed = I2C_CLOCK_HZ,
}, },
// TODO: check flags // No requirements for the clock.
.clk_flags = 0, .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)); ESP_ERROR_CHECK(i2c_driver_install(port, config.mode, 0, 0, 0));
// TODO: INT line // TODO: INT line
// TODO: add devices to the bus (DAC and GPIO expander)
return ESP_OK; return ESP_OK;
} }
@ -84,10 +83,11 @@ extern "C" void app_main(void)
{ {
ESP_LOGI(TAG, "Initialising peripherals"); ESP_LOGI(TAG, "Initialising peripherals");
init_i2c(); init_i2c();
init_spi(); //init_spi();
ESP_LOGI(TAG, "Setting default GPIO state");
gay_ipod::GpioExpander expander; gay_ipod::GpioExpander expander;
expander.Write(); ESP_ERROR_CHECK(expander.Write());
while (1) {} ESP_LOGI(TAG, "Idling.");
} }

@ -38,8 +38,8 @@ esp_err_t GpioExpander::Read() {
// it because that would indicate some really very badly wrong more generally. // it because that would indicate some really very badly wrong more generally.
i2c_master_start(handle); i2c_master_start(handle);
i2c_master_write_byte(handle, (PCA8575_ADDRESS << 1 | I2C_MASTER_READ), true); 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, &port_a_, I2C_MASTER_ACK);
i2c_master_read_byte(handle, &input_b_, I2C_MASTER_LAST_NACK); i2c_master_read_byte(handle, &port_b_, I2C_MASTER_LAST_NACK);
i2c_master_stop(handle); i2c_master_stop(handle);
esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_0, handle, PCA8575_TIMEOUT); esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_0, handle, PCA8575_TIMEOUT);

@ -33,10 +33,10 @@ class GpioExpander {
GpioExpander& operator=(const GpioExpander&) = delete; GpioExpander& operator=(const GpioExpander&) = delete;
private: private:
// All power switches low, both CS pins high, active-low PWR_OK high. // All power switches high, PWR_OK low (input), both CS pins high.
uint8_t port_a_ = 0b00001011; uint8_t port_a_ = uint8_t{0b00001000};
// DAC mute output low, everything eelse is input and so held high. // DAC mute output low, everything else is input and so low.
uint8_t port_b_ = 0b10111111; uint8_t port_b_ = uint8_t{0b11111111};
uint8_t input_a_ = 0; uint8_t input_a_ = 0;
uint8_t input_b_ = 0; uint8_t input_b_ = 0;

Loading…
Cancel
Save