summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-07 13:19:45 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-07 13:19:45 +1000
commit1f903accd95361735c841c87fdc6494ad3331b40 (patch)
tree5b69bd0548c06a93852a576fa90a170fa303a15e /src/drivers
parent2a568846bd8f1c9e23e86e7570557eed6f18cf9f (diff)
downloadtangara-fw-1f903accd95361735c841c87fdc6494ad3331b40.tar.gz
Flesh out audio state machine for playback
Also fix mono playback
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/display.cpp7
-rw-r--r--src/drivers/i2s_dac.cpp16
-rw-r--r--src/drivers/include/display.hpp4
-rw-r--r--src/drivers/include/i2s_dac.hpp6
4 files changed, 24 insertions, 9 deletions
diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp
index dd4cecb8..3c0df978 100644
--- a/src/drivers/display.cpp
+++ b/src/drivers/display.cpp
@@ -126,7 +126,7 @@ auto Display::Create(GpioExpander* expander,
ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0));
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));
- ledc_fade_func_install(0);
+ // ledc_fade_func_install(0);
// Next, init the SPI device
spi_device_interface_config_t spi_cfg = {
@@ -194,8 +194,9 @@ auto Display::SetDisplayOn(bool enabled) -> void {
display_on_ = enabled;
int new_duty = display_on_ ? brightness_ : 0;
- ledc_set_fade_with_time(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, new_duty, 250);
- ledc_fade_start(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT);
+ // ledc_set_fade_with_time(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, new_duty,
+ // 250); ledc_fade_start(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0,
+ // LEDC_FADE_NO_WAIT);
}
void Display::SendInitialisationSequence(const uint8_t* data) {
diff --git a/src/drivers/i2s_dac.cpp b/src/drivers/i2s_dac.cpp
index 68e92970..dbbb58f1 100644
--- a/src/drivers/i2s_dac.cpp
+++ b/src/drivers/i2s_dac.cpp
@@ -116,24 +116,30 @@ auto I2SDac::Stop() -> void {
i2s_active_ = false;
}
-auto I2SDac::Reconfigure(BitsPerSample bps, SampleRate rate) -> void {
+auto I2SDac::Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate)
+ -> void {
if (i2s_active_) {
i2s_channel_disable(i2s_handle_);
}
- uint8_t bps_bits = 0;
+ switch (ch) {
+ case CHANNELS_MONO:
+ slot_config_.slot_mode = I2S_SLOT_MODE_MONO;
+ break;
+ case CHANNELS_STEREO:
+ slot_config_.slot_mode = I2S_SLOT_MODE_STEREO;
+ break;
+ }
+
switch (bps) {
case BPS_16:
slot_config_.data_bit_width = I2S_DATA_BIT_WIDTH_16BIT;
- bps_bits = 0;
break;
case BPS_24:
slot_config_.data_bit_width = I2S_DATA_BIT_WIDTH_24BIT;
- bps_bits = 0b10;
break;
case BPS_32:
slot_config_.data_bit_width = I2S_DATA_BIT_WIDTH_32BIT;
- bps_bits = 0b11;
break;
}
ESP_ERROR_CHECK(i2s_channel_reconfig_std_slot(i2s_handle_, &slot_config_));
diff --git a/src/drivers/include/display.hpp b/src/drivers/include/display.hpp
index b394dd9e..4b63e1c4 100644
--- a/src/drivers/include/display.hpp
+++ b/src/drivers/include/display.hpp
@@ -43,6 +43,10 @@ class Display {
const lv_area_t* area,
lv_color_t* color_map);
+ // Not copyable or movable.
+ Display(const Display&) = delete;
+ Display& operator=(const Display&) = delete;
+
private:
GpioExpander* gpio_;
spi_device_handle_t handle_;
diff --git a/src/drivers/include/i2s_dac.hpp b/src/drivers/include/i2s_dac.hpp
index 42c094b1..388d09fa 100644
--- a/src/drivers/include/i2s_dac.hpp
+++ b/src/drivers/include/i2s_dac.hpp
@@ -40,6 +40,10 @@ class I2SDac {
auto Start() -> void;
auto Stop() -> void;
+ enum Channels {
+ CHANNELS_MONO,
+ CHANNELS_STEREO,
+ };
enum BitsPerSample {
BPS_16 = I2S_DATA_BIT_WIDTH_16BIT,
BPS_24 = I2S_DATA_BIT_WIDTH_24BIT,
@@ -56,7 +60,7 @@ class I2SDac {
SAMPLE_RATE_192 = 192000,
};
- auto Reconfigure(BitsPerSample bps, SampleRate rate) -> void;
+ auto Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate) -> void;
auto WriteData(const cpp::span<const std::byte>& data) -> void;
auto SetSource(StreamBufferHandle_t buffer) -> void;