summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/battery.cpp20
-rw-r--r--src/drivers/dac.cpp6
-rw-r--r--src/drivers/display.cpp2
-rw-r--r--src/drivers/include/battery.hpp3
-rw-r--r--src/drivers/include/dac.hpp1
-rw-r--r--src/drivers/include/display.hpp3
-rw-r--r--src/drivers/include/gpio_expander.hpp2
-rw-r--r--src/drivers/include/i2c.hpp2
8 files changed, 23 insertions, 16 deletions
diff --git a/src/drivers/battery.cpp b/src/drivers/battery.cpp
index b45e20cf..29224e2d 100644
--- a/src/drivers/battery.cpp
+++ b/src/drivers/battery.cpp
@@ -2,17 +2,19 @@
#include <cstdint>
#include "esp_adc/adc_oneshot.h"
+#include "esp_adc/adc_cali.h"
+#include "esp_adc/adc_cali_scheme.h"
#include "hal/adc_types.h"
namespace drivers {
-static const uint8_t kAdcBitWidth = ADC_BITWIDTH_12;
-static const uint8_t kAdcUnit = ADC_UNIT_1;
+static const adc_bitwidth_t kAdcBitWidth = ADC_BITWIDTH_12;
+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 uint8_t kAdcAttenuation = ADC_ATTEN_DB_11;
+static const adc_atten_t kAdcAttenuation = ADC_ATTEN_DB_11;
// Corresponds to GPIO 34.
-static const uint8_t kAdcChannel = ADC_CHANNEL_6;
+static const adc_channel_t kAdcChannel = ADC_CHANNEL_6;
Battery::Battery() {
adc_oneshot_unit_init_cfg_t unit_config = {
@@ -21,8 +23,8 @@ Battery::Battery() {
ESP_ERROR_CHECK(adc_oneshot_new_unit(&unit_config, &adc_handle_));
adc_oneshot_chan_cfg_t channel_config = {
- .bitwidth = kAdcBitWidth,
.atten = kAdcAttenuation,
+ .bitwidth = kAdcBitWidth,
};
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc_handle_, kAdcChannel, &channel_config));
@@ -42,11 +44,11 @@ Battery::~Battery() {
auto Battery::Millivolts() -> uint32_t {
// GPIO 34
- int raw;
- ESP_ERROR_CHECK(adc_oneshot_read(adc_handle, kAdcChannel &raw));
+ int raw = 0;
+ ESP_ERROR_CHECK(adc_oneshot_read(adc_handle_, kAdcChannel, &raw));
- int voltage;
- ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc_calibration_handle, raw, &voltage));
+ int voltage = 0;
+ ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc_calibration_handle_, raw, &voltage));
return voltage;
}
diff --git a/src/drivers/dac.cpp b/src/drivers/dac.cpp
index 23c67e88..78bf94c4 100644
--- a/src/drivers/dac.cpp
+++ b/src/drivers/dac.cpp
@@ -5,6 +5,8 @@
#include "assert.h"
#include "driver/i2c.h"
#include "driver/i2s.h"
+#include "driver/i2s_types.h"
+#include "driver/i2s_types_legacy.h"
#include "esp_err.h"
#include "esp_log.h"
#include "hal/i2c_types.h"
@@ -17,7 +19,7 @@ namespace drivers {
static const char* kTag = "AUDIODAC";
static const uint8_t kPcm5122Address = 0x4C;
-static const uint8_t kPcm5122Timeout = 100 / portTICK_RATE_MS;
+static const uint8_t kPcm5122Timeout = pdMS_TO_TICKS(100);
static const i2s_port_t kI2SPort = I2S_NUM_0;
static const AudioDac::SampleRate kDefaultSampleRate =
@@ -46,7 +48,7 @@ auto AudioDac::create(GpioExpander* expander)
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0,
- .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT,
+ .mclk_multiple = I2S_MCLK_MULTIPLE_512, // TODO: double check
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT,
};
diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp
index 8aaca4a4..83710f45 100644
--- a/src/drivers/display.cpp
+++ b/src/drivers/display.cpp
@@ -122,7 +122,7 @@ auto Display::create(GpioExpander* expander,
ESP_LOGI(kTag, "Registering driver");
display->display_ = lv_disp_drv_register(&display->driver_);
- return std::move(display);
+ return display;
}
Display::Display(GpioExpander* gpio, spi_device_handle_t handle)
diff --git a/src/drivers/include/battery.hpp b/src/drivers/include/battery.hpp
index 9366a5b1..dea46d7c 100644
--- a/src/drivers/include/battery.hpp
+++ b/src/drivers/include/battery.hpp
@@ -3,6 +3,7 @@
#include <cstdint>
#include "esp_adc/adc_oneshot.h"
+#include "esp_adc/adc_cali.h"
#include "esp_err.h"
#include "result.hpp"
@@ -18,7 +19,7 @@ class Battery {
*/
auto Millivolts() -> uint32_t;
private:
- adc_oneshot_handle_t adc_handle_;
+ adc_oneshot_unit_handle_t adc_handle_;
adc_cali_handle_t adc_calibration_handle_;
};
diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp
index dc03624b..2d4e812f 100644
--- a/src/drivers/include/dac.hpp
+++ b/src/drivers/include/dac.hpp
@@ -9,6 +9,7 @@
#include "hal/i2s_types.h"
#include "result.hpp"
#include "span.hpp"
+#include "driver/i2s_types_legacy.h"
#include "gpio_expander.hpp"
diff --git a/src/drivers/include/display.hpp b/src/drivers/include/display.hpp
index 75b2f9a6..5f6d6f58 100644
--- a/src/drivers/include/display.hpp
+++ b/src/drivers/include/display.hpp
@@ -8,6 +8,7 @@
#include "display_init.hpp"
#include "gpio_expander.hpp"
+#include "sys/_stdint.h"
namespace drivers {
@@ -63,7 +64,7 @@ class Display {
void SendTransaction(TransactionType type,
const uint8_t* data,
size_t length,
- uintptr_t flags = 0);
+ uint32_t flags = 0);
};
} // namespace drivers
diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp
index 8875e954..a6e96d87 100644
--- a/src/drivers/include/gpio_expander.hpp
+++ b/src/drivers/include/gpio_expander.hpp
@@ -32,7 +32,7 @@ class GpioExpander {
~GpioExpander();
static const uint8_t kPca8575Address = 0x20;
- static const uint8_t kPca8575Timeout = 100 / portTICK_RATE_MS;
+ static const uint8_t kPca8575Timeout = pdMS_TO_TICKS(100);
// Port A:
// 0 - audio power enable
diff --git a/src/drivers/include/i2c.hpp b/src/drivers/include/i2c.hpp
index 3704509d..dbdd8a11 100644
--- a/src/drivers/include/i2c.hpp
+++ b/src/drivers/include/i2c.hpp
@@ -20,7 +20,7 @@ esp_err_t deinit_i2c(void);
*/
class I2CTransaction {
public:
- static const uint8_t kI2CTimeout = 100 / portTICK_RATE_MS;
+ static const uint8_t kI2CTimeout = pdMS_TO_TICKS(100);
I2CTransaction();
~I2CTransaction();