Update pinouts for R3

custom
jacqueline 2 years ago
parent 53ad4fc3f2
commit a0ae39befe
  1. 4
      src/drivers/battery.cpp
  2. 4
      src/drivers/dac.cpp
  3. 20
      src/drivers/display.cpp
  4. 4
      src/drivers/i2c.cpp
  5. 70
      src/drivers/include/gpio_expander.hpp
  6. 12
      src/main/main.cpp

@ -13,8 +13,8 @@ static const adc_unit_t kAdcUnit = ADC_UNIT_1;
// Max battery voltage should be a little over 2V due to our divider, so we need // Max battery voltage should be a little over 2V due to our divider, so we need
// the max attenuation to properly handle the full range. // the max attenuation to properly handle the full range.
static const adc_atten_t kAdcAttenuation = ADC_ATTEN_DB_11; static const adc_atten_t kAdcAttenuation = ADC_ATTEN_DB_11;
// Corresponds to GPIO 34. // Corresponds to SENSOR_VP.
static const adc_channel_t kAdcChannel = ADC_CHANNEL_6; static const adc_channel_t kAdcChannel = ADC_CHANNEL_0;
Battery::Battery() { Battery::Battery() {
adc_oneshot_unit_init_cfg_t unit_config = { adc_oneshot_unit_init_cfg_t unit_config = {

@ -105,14 +105,14 @@ AudioDac::AudioDac(GpioExpander* gpio, i2s_chan_handle_t i2s_handle)
clock_config_(I2S_STD_CLK_DEFAULT_CONFIG(44100)), clock_config_(I2S_STD_CLK_DEFAULT_CONFIG(44100)),
slot_config_(I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, slot_config_(I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT,
I2S_SLOT_MODE_STEREO)) { I2S_SLOT_MODE_STEREO)) {
gpio_->set_pin(GpioExpander::AUDIO_POWER_ENABLE, true); gpio_->set_pin(GpioExpander::AMP_EN, true);
gpio_->Write(); gpio_->Write();
} }
AudioDac::~AudioDac() { AudioDac::~AudioDac() {
i2s_channel_disable(i2s_handle_); i2s_channel_disable(i2s_handle_);
i2s_del_channel(i2s_handle_); i2s_del_channel(i2s_handle_);
gpio_->set_pin(GpioExpander::AUDIO_POWER_ENABLE, false); gpio_->set_pin(GpioExpander::AMP_EN, false);
gpio_->Write(); gpio_->Write();
} }

@ -28,6 +28,9 @@ static const uint8_t kDisplayWidth = 128 + 2;
static const uint8_t kDisplayHeight = 160 + 1; static const uint8_t kDisplayHeight = 160 + 1;
static const uint8_t kTransactionQueueSize = 10; static const uint8_t kTransactionQueueSize = 10;
static const gpio_num_t kDisplayDr = GPIO_NUM_33;
static const gpio_num_t kDisplayLedEn = GPIO_NUM_32;
/* /*
* The size of each of our two display buffers. This is fundamentally a balance * The size of each of our two display buffers. This is fundamentally a balance
* between performance and memory usage. LVGL docs recommend a buffer 1/10th the * between performance and memory usage. LVGL docs recommend a buffer 1/10th the
@ -59,10 +62,13 @@ extern "C" void FlushDataCallback(lv_disp_drv_t* disp_drv,
auto Display::create(GpioExpander* expander, auto Display::create(GpioExpander* expander,
const displays::InitialisationData& init_data) const displays::InitialisationData& init_data)
-> std::unique_ptr<Display> { -> std::unique_ptr<Display> {
// First, turn on the LED backlight. ESP_LOGI(kTag, "Init I/O pins");
expander->set_pin(GpioExpander::DISPLAY_LED, 1); gpio_set_direction(kDisplayDr, GPIO_MODE_OUTPUT);
expander->set_pin(GpioExpander::DISPLAY_POWER_ENABLE, 1); gpio_set_level(kDisplayDr, 0);
expander->Write();
// TODO: use pwm for the backlight.
gpio_set_direction(kDisplayLedEn, GPIO_MODE_OUTPUT);
gpio_set_level(kDisplayLedEn, 1);
// Next, init the SPI device // Next, init the SPI device
spi_device_interface_config_t spi_cfg = { spi_device_interface_config_t spi_cfg = {
@ -122,7 +128,7 @@ Display::~Display() {}
void Display::SendInitialisationSequence(const uint8_t* data) { void Display::SendInitialisationSequence(const uint8_t* data) {
// Reset the display manually to get it into a predictable state. // Reset the display manually to get it into a predictable state.
gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); gpio_->set_pin(GpioExpander::DISPLAY_RESET, true);
gpio_->Write(); gpio_->Write();
vTaskDelay(pdMS_TO_TICKS(10)); vTaskDelay(pdMS_TO_TICKS(10));
gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); gpio_->set_pin(GpioExpander::DISPLAY_RESET, false);
@ -201,9 +207,7 @@ void Display::SendTransaction(TransactionType type,
transaction.tx_buffer = data; transaction.tx_buffer = data;
} }
// TODO(jacqueline): Move this to an on-board GPIO for speed. gpio_set_level(kDisplayDr, type);
gpio_->set_pin(GpioExpander::DISPLAY_DR, type);
gpio_->Write();
// TODO(jacqueline): Handle these errors. // TODO(jacqueline): Handle these errors.
esp_err_t ret = spi_device_polling_transmit(handle_, &transaction); esp_err_t ret = spi_device_polling_transmit(handle_, &transaction);

@ -9,8 +9,8 @@
namespace drivers { namespace drivers {
static const i2c_port_t kI2CPort = I2C_NUM_0; static const i2c_port_t kI2CPort = I2C_NUM_0;
static const gpio_num_t kI2CSdaPin = GPIO_NUM_2; static const gpio_num_t kI2CSdaPin = GPIO_NUM_4;
static const gpio_num_t kI2CSclPin = GPIO_NUM_4; static const gpio_num_t kI2CSclPin = GPIO_NUM_2;
static const uint32_t kI2CClkSpeed = 400'000; static const uint32_t kI2CClkSpeed = 400'000;
static constexpr int kCmdLinkSize = I2C_LINK_RECOMMENDED_SIZE(12); static constexpr int kCmdLinkSize = I2C_LINK_RECOMMENDED_SIZE(12);

@ -35,28 +35,28 @@ class GpioExpander {
static const uint8_t kPca8575Timeout = pdMS_TO_TICKS(100); static const uint8_t kPca8575Timeout = pdMS_TO_TICKS(100);
// Port A: // Port A:
// 0 - audio power enable // 0 - sd card mux switch
// 1 - usb interface power enable (active low) // 1 - sd card mux enable (active low)
// 2 - display power enable // 2 - key up
// 3 - touchpad power enable // 3 - key down
// 4 - sd card power enable // 4 - key lock
// 5 - sd mux switch // 5 - display reset
// 6 - LDO enable // 6 - NC
// 7 - charge power ok (active low) // 7 - sd card power
// All power switches low, sd mux pointing away from us, inputs high. // Default to SD card off, inputs high.
static const uint8_t kPortADefault = 0b11000010; static const uint8_t kPortADefault = 0b00011110;
// Port B: // Port B:
// 0 - 3.5mm jack detect (active low) // 0 - trs output enable
// 1 - unused // 1 - 3.5mm jack detect (active low)
// 2 - trackpad int // 2 - NC
// 3 - display reset (active low) // 3 - NC
// 4 - lock switch // 4 - NC
// 5 - touchpad interupt // 5 - NC
// 6 - display DR // 6 - NC
// 7 - display LED // 7 - NC
// Inputs all high, all others low. // Default input high, trs output low
static const uint8_t kPortBDefault = 0b00111101; static const uint8_t kPortBDefault = 0b00000010;
/* /*
* Convenience mehod for packing the port a and b bytes into a single 16 bit * 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. */ /* Maps each pin of the expander to its number in a `pack`ed uint16. */
enum Pin { enum Pin {
// Port A // Port A
AUDIO_POWER_ENABLE = 0, SD_MUX_SWITCH = 0,
USB_INTERFACE_POWER_ENABLE = 1, SD_MUX_EN_ACTIVE_LOW = 1,
DISPLAY_POWER_ENABLE = 2, KEY_UP = 2,
TOUCHPAD_POWER_ENABLE = 3, KEY_DOWN = 3,
SD_CARD_POWER_ENABLE = 4, KEY_LOCK = 4,
SD_MUX_SWITCH = 5, DISPLAY_RESET = 5,
LDO_ENABLE = 6, // UNUSED = 6,
CHARGE_POWER_OK = 7, // Active-low input SD_CARD_POWER_ENABLE = 7,
// Port B // Port B
PHONE_DETECT = 8, // Active-high input AMP_EN = 8,
// UNUSED = 9, PHONE_DETECT = 9,
TOUCHPAD_INT = 10, // UNUSED = 10,
DISPLAY_RESET = 11, // UNUSED = 11,
// UNUSED = 12, // UNUSED = 12,
// UNUSED = 13, // UNUSED = 13,
DISPLAY_DR = 14, // UNUSED = 14,
DISPLAY_LED = 15, // UNUSED = 15,
}; };
/* Nicer value names for use with the SD_MUX_SWITCH pin. */ /* Nicer value names for use with the SD_MUX_SWITCH pin. */
enum SdController { enum SdController {
SD_MUX_ESP = 1, SD_MUX_ESP = 1,
SD_MUX_USB = 0, SD_MUX_SAMD = 0,
}; };
/** /**

@ -102,12 +102,10 @@ extern "C" void app_main(void) {
ESP_LOGI(TAG, "Enable power rails for development"); ESP_LOGI(TAG, "Enable power rails for development");
expander->with([&](auto& gpio) { expander->with([&](auto& gpio) {
gpio.set_pin(drivers::GpioExpander::AUDIO_POWER_ENABLE, 1); gpio.set_pin(drivers::GpioExpander::SD_MUX_EN_ACTIVE_LOW, 0);
gpio.set_pin(drivers::GpioExpander::DISPLAY_LED, 0);
gpio.set_pin(drivers::GpioExpander::USB_INTERFACE_POWER_ENABLE, 0);
gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 1);
gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH, gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH,
drivers::GpioExpander::SD_MUX_ESP); drivers::GpioExpander::SD_MUX_ESP);
gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 1);
}); });
ESP_LOGI(TAG, "Init battery measurement"); ESP_LOGI(TAG, "Init battery measurement");
@ -123,6 +121,7 @@ extern "C" void app_main(void) {
storage = std::move(storage_res.value()); storage = std::move(storage_res.value());
} }
/*
ESP_LOGI(TAG, "Init touch wheel"); ESP_LOGI(TAG, "Init touch wheel");
auto touchwheel_res = drivers::TouchWheel::create(expander); auto touchwheel_res = drivers::TouchWheel::create(expander);
std::shared_ptr<drivers::TouchWheel> touchwheel; std::shared_ptr<drivers::TouchWheel> touchwheel;
@ -131,6 +130,7 @@ extern "C" void app_main(void) {
} else { } else {
touchwheel = std::move(touchwheel_res.value()); touchwheel = std::move(touchwheel_res.value());
} }
*/
LvglArgs* lvglArgs = (LvglArgs*)calloc(1, sizeof(LvglArgs)); LvglArgs* lvglArgs = (LvglArgs*)calloc(1, sizeof(LvglArgs));
lvglArgs->gpio_expander = expander; lvglArgs->gpio_expander = expander;
@ -157,8 +157,8 @@ extern "C" void app_main(void) {
console.Launch(); console.Launch();
while (1) { while (1) {
touchwheel->Update(); //touchwheel->Update();
ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position); //ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position);
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
} }
} }

Loading…
Cancel
Save