summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-03-30 09:31:08 +1100
committerjacqueline <me@jacqueline.id.au>2023-03-30 09:31:08 +1100
commita0ae39befe11c2a5a78ee5877cd5dd9cda90e27c (patch)
tree21d51e8929d3c6fa9ffa4bf78da0eacb5c0c27a2 /src
parent53ad4fc3f260ea7de56d1bce24e284b48c0e856b (diff)
downloadtangara-fw-a0ae39befe11c2a5a78ee5877cd5dd9cda90e27c.tar.gz
Update pinouts for R3
Diffstat (limited to 'src')
-rw-r--r--src/drivers/battery.cpp4
-rw-r--r--src/drivers/dac.cpp4
-rw-r--r--src/drivers/display.cpp20
-rw-r--r--src/drivers/i2c.cpp4
-rw-r--r--src/drivers/include/gpio_expander.hpp70
-rw-r--r--src/main/main.cpp12
6 files changed, 59 insertions, 55 deletions
diff --git a/src/drivers/battery.cpp b/src/drivers/battery.cpp
index 00e7796a..8d747c07 100644
--- a/src/drivers/battery.cpp
+++ b/src/drivers/battery.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
// the max attenuation to properly handle the full range.
static const adc_atten_t kAdcAttenuation = ADC_ATTEN_DB_11;
-// Corresponds to GPIO 34.
-static const adc_channel_t kAdcChannel = ADC_CHANNEL_6;
+// Corresponds to SENSOR_VP.
+static const adc_channel_t kAdcChannel = ADC_CHANNEL_0;
Battery::Battery() {
adc_oneshot_unit_init_cfg_t unit_config = {
diff --git a/src/drivers/dac.cpp b/src/drivers/dac.cpp
index 1ab562f9..c9af0d99 100644
--- a/src/drivers/dac.cpp
+++ b/src/drivers/dac.cpp
@@ -105,14 +105,14 @@ AudioDac::AudioDac(GpioExpander* gpio, i2s_chan_handle_t i2s_handle)
clock_config_(I2S_STD_CLK_DEFAULT_CONFIG(44100)),
slot_config_(I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT,
I2S_SLOT_MODE_STEREO)) {
- gpio_->set_pin(GpioExpander::AUDIO_POWER_ENABLE, true);
+ gpio_->set_pin(GpioExpander::AMP_EN, true);
gpio_->Write();
}
AudioDac::~AudioDac() {
i2s_channel_disable(i2s_handle_);
i2s_del_channel(i2s_handle_);
- gpio_->set_pin(GpioExpander::AUDIO_POWER_ENABLE, false);
+ gpio_->set_pin(GpioExpander::AMP_EN, false);
gpio_->Write();
}
diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp
index e8ddb65e..d5c17744 100644
--- a/src/drivers/display.cpp
+++ b/src/drivers/display.cpp
@@ -28,6 +28,9 @@ static const uint8_t kDisplayWidth = 128 + 2;
static const uint8_t kDisplayHeight = 160 + 1;
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
* 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,
const displays::InitialisationData& init_data)
-> std::unique_ptr<Display> {
- // First, turn on the LED backlight.
- expander->set_pin(GpioExpander::DISPLAY_LED, 1);
- expander->set_pin(GpioExpander::DISPLAY_POWER_ENABLE, 1);
- expander->Write();
+ ESP_LOGI(kTag, "Init I/O pins");
+ gpio_set_direction(kDisplayDr, GPIO_MODE_OUTPUT);
+ gpio_set_level(kDisplayDr, 0);
+
+ // TODO: use pwm for the backlight.
+ gpio_set_direction(kDisplayLedEn, GPIO_MODE_OUTPUT);
+ gpio_set_level(kDisplayLedEn, 1);
// Next, init the SPI device
spi_device_interface_config_t spi_cfg = {
@@ -122,7 +128,7 @@ Display::~Display() {}
void Display::SendInitialisationSequence(const uint8_t* data) {
// 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();
vTaskDelay(pdMS_TO_TICKS(10));
gpio_->set_pin(GpioExpander::DISPLAY_RESET, false);
@@ -201,9 +207,7 @@ void Display::SendTransaction(TransactionType type,
transaction.tx_buffer = data;
}
- // TODO(jacqueline): Move this to an on-board GPIO for speed.
- gpio_->set_pin(GpioExpander::DISPLAY_DR, type);
- gpio_->Write();
+ gpio_set_level(kDisplayDr, type);
// TODO(jacqueline): Handle these errors.
esp_err_t ret = spi_device_polling_transmit(handle_, &transaction);
diff --git a/src/drivers/i2c.cpp b/src/drivers/i2c.cpp
index a66f54f0..3773055d 100644
--- a/src/drivers/i2c.cpp
+++ b/src/drivers/i2c.cpp
@@ -9,8 +9,8 @@
namespace drivers {
static const i2c_port_t kI2CPort = I2C_NUM_0;
-static const gpio_num_t kI2CSdaPin = GPIO_NUM_2;
-static const gpio_num_t kI2CSclPin = GPIO_NUM_4;
+static const gpio_num_t kI2CSdaPin = GPIO_NUM_4;
+static const gpio_num_t kI2CSclPin = GPIO_NUM_2;
static const uint32_t kI2CClkSpeed = 400'000;
static constexpr int kCmdLinkSize = I2C_LINK_RECOMMENDED_SIZE(12);
diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp
index cb087df9..86998e7e 100644
--- a/src/drivers/include/gpio_expander.hpp
+++ b/src/drivers/include/gpio_expander.hpp
@@ -35,28 +35,28 @@ class GpioExpander {
static const uint8_t kPca8575Timeout = pdMS_TO_TICKS(100);
// Port A:
- // 0 - audio power enable
- // 1 - usb interface power enable (active low)
- // 2 - display power enable
- // 3 - touchpad power enable
- // 4 - sd card power enable
- // 5 - sd mux switch
- // 6 - LDO enable
- // 7 - charge power ok (active low)
- // All power switches low, sd mux pointing away from us, inputs high.
- static const uint8_t kPortADefault = 0b11000010;
+ // 0 - sd card mux switch
+ // 1 - sd card mux enable (active low)
+ // 2 - key up
+ // 3 - key down
+ // 4 - key lock
+ // 5 - display reset
+ // 6 - NC
+ // 7 - sd card power
+ // Default to SD card off, inputs high.
+ static const uint8_t kPortADefault = 0b00011110;
// Port B:
- // 0 - 3.5mm jack detect (active low)
- // 1 - unused
- // 2 - trackpad int
- // 3 - display reset (active low)
- // 4 - lock switch
- // 5 - touchpad interupt
- // 6 - display DR
- // 7 - display LED
- // Inputs all high, all others low.
- static const uint8_t kPortBDefault = 0b00111101;
+ // 0 - trs output enable
+ // 1 - 3.5mm jack detect (active low)
+ // 2 - NC
+ // 3 - NC
+ // 4 - NC
+ // 5 - NC
+ // 6 - NC
+ // 7 - NC
+ // Default input high, trs output low
+ static const uint8_t kPortBDefault = 0b00000010;
/*
* 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. */
enum Pin {
// Port A
- AUDIO_POWER_ENABLE = 0,
- USB_INTERFACE_POWER_ENABLE = 1,
- DISPLAY_POWER_ENABLE = 2,
- TOUCHPAD_POWER_ENABLE = 3,
- SD_CARD_POWER_ENABLE = 4,
- SD_MUX_SWITCH = 5,
- LDO_ENABLE = 6,
- CHARGE_POWER_OK = 7, // Active-low input
+ SD_MUX_SWITCH = 0,
+ SD_MUX_EN_ACTIVE_LOW = 1,
+ KEY_UP = 2,
+ KEY_DOWN = 3,
+ KEY_LOCK = 4,
+ DISPLAY_RESET = 5,
+ // UNUSED = 6,
+ SD_CARD_POWER_ENABLE = 7,
// Port B
- PHONE_DETECT = 8, // Active-high input
- // UNUSED = 9,
- TOUCHPAD_INT = 10,
- DISPLAY_RESET = 11,
+ AMP_EN = 8,
+ PHONE_DETECT = 9,
+ // UNUSED = 10,
+ // UNUSED = 11,
// UNUSED = 12,
// UNUSED = 13,
- DISPLAY_DR = 14,
- DISPLAY_LED = 15,
+ // UNUSED = 14,
+ // UNUSED = 15,
};
/* Nicer value names for use with the SD_MUX_SWITCH pin. */
enum SdController {
SD_MUX_ESP = 1,
- SD_MUX_USB = 0,
+ SD_MUX_SAMD = 0,
};
/**
diff --git a/src/main/main.cpp b/src/main/main.cpp
index bd0a06af..57d88f96 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -102,12 +102,10 @@ extern "C" void app_main(void) {
ESP_LOGI(TAG, "Enable power rails for development");
expander->with([&](auto& gpio) {
- gpio.set_pin(drivers::GpioExpander::AUDIO_POWER_ENABLE, 1);
- 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_EN_ACTIVE_LOW, 0);
gpio.set_pin(drivers::GpioExpander::SD_MUX_SWITCH,
drivers::GpioExpander::SD_MUX_ESP);
+ gpio.set_pin(drivers::GpioExpander::SD_CARD_POWER_ENABLE, 1);
});
ESP_LOGI(TAG, "Init battery measurement");
@@ -123,6 +121,7 @@ extern "C" void app_main(void) {
storage = std::move(storage_res.value());
}
+ /*
ESP_LOGI(TAG, "Init touch wheel");
auto touchwheel_res = drivers::TouchWheel::create(expander);
std::shared_ptr<drivers::TouchWheel> touchwheel;
@@ -131,6 +130,7 @@ extern "C" void app_main(void) {
} else {
touchwheel = std::move(touchwheel_res.value());
}
+ */
LvglArgs* lvglArgs = (LvglArgs*)calloc(1, sizeof(LvglArgs));
lvglArgs->gpio_expander = expander;
@@ -157,8 +157,8 @@ extern "C" void app_main(void) {
console.Launch();
while (1) {
- touchwheel->Update();
- ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position);
+ //touchwheel->Update();
+ //ESP_LOGI(TAG, "Touch wheel pos: %d", touchwheel->GetTouchWheelData().wheel_position);
vTaskDelay(pdMS_TO_TICKS(100));
}
}