clang-format

custom
jacqueline 2 years ago
parent 8ed3d7e31f
commit 0560fa7f10
  1. 11
      src/drivers/battery.cpp
  2. 25
      src/drivers/dac.cpp
  3. 3
      src/drivers/include/battery.hpp
  4. 2
      src/drivers/include/dac.hpp

@ -1,9 +1,9 @@
#include "battery.hpp" #include "battery.hpp"
#include <cstdint> #include <cstdint>
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali.h" #include "esp_adc/adc_cali.h"
#include "esp_adc/adc_cali_scheme.h" #include "esp_adc/adc_cali_scheme.h"
#include "esp_adc/adc_oneshot.h"
#include "hal/adc_types.h" #include "hal/adc_types.h"
namespace drivers { namespace drivers {
@ -26,7 +26,8 @@ Battery::Battery() {
.atten = kAdcAttenuation, .atten = kAdcAttenuation,
.bitwidth = kAdcBitWidth, .bitwidth = kAdcBitWidth,
}; };
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc_handle_, kAdcChannel, &channel_config)); ESP_ERROR_CHECK(
adc_oneshot_config_channel(adc_handle_, kAdcChannel, &channel_config));
// calibrate // calibrate
// TODO: compile-time assert our scheme is available // TODO: compile-time assert our scheme is available
@ -35,7 +36,8 @@ Battery::Battery() {
.atten = kAdcAttenuation, .atten = kAdcAttenuation,
.bitwidth = kAdcBitWidth, .bitwidth = kAdcBitWidth,
}; };
ESP_ERROR_CHECK(adc_cali_create_scheme_line_fitting(&calibration_config, &adc_calibration_handle_)); ESP_ERROR_CHECK(adc_cali_create_scheme_line_fitting(
&calibration_config, &adc_calibration_handle_));
} }
Battery::~Battery() { Battery::~Battery() {
@ -48,7 +50,8 @@ auto Battery::Millivolts() -> uint32_t {
ESP_ERROR_CHECK(adc_oneshot_read(adc_handle_, kAdcChannel, &raw)); ESP_ERROR_CHECK(adc_oneshot_read(adc_handle_, kAdcChannel, &raw));
int voltage = 0; int voltage = 0;
ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc_calibration_handle_, raw, &voltage)); ESP_ERROR_CHECK(
adc_cali_raw_to_voltage(adc_calibration_handle_, raw, &voltage));
return voltage; return voltage;
} }

@ -28,36 +28,37 @@ static const AudioDac::BitsPerSample kDefaultBps = AudioDac::BPS_16;
auto AudioDac::create(GpioExpander* expander) auto AudioDac::create(GpioExpander* expander)
-> cpp::result<std::unique_ptr<AudioDac>, Error> { -> cpp::result<std::unique_ptr<AudioDac>, Error> {
// TODO: tune. // TODO: tune.
i2s_chan_handle_t i2s_handle; i2s_chan_handle_t i2s_handle;
i2s_chan_config_t channel_config = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER); i2s_chan_config_t channel_config =
I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
i2s_new_channel(&channel_config, &i2s_handle, NULL); i2s_new_channel(&channel_config, &i2s_handle, NULL);
// //
// First, instantiate the instance so it can do all of its power on // First, instantiate the instance so it can do all of its power on
// configuration. // configuration.
std::unique_ptr<AudioDac> dac = std::make_unique<AudioDac>(expander, i2s_handle); std::unique_ptr<AudioDac> dac =
std::make_unique<AudioDac>(expander, i2s_handle);
// Whilst we wait for the initial boot, we can work on installing the I2S // Whilst we wait for the initial boot, we can work on installing the I2S
// driver. // driver.
i2s_std_config_t i2s_config = { i2s_std_config_t i2s_config = {
.clk_cfg = dac->clock_config_, .clk_cfg = dac->clock_config_,
.slot_cfg = dac->slot_config_, .slot_cfg = dac->slot_config_,
.gpio_cfg = { .gpio_cfg = {.mclk = GPIO_NUM_0,
.mclk = GPIO_NUM_0,
.bclk = GPIO_NUM_26, .bclk = GPIO_NUM_26,
.ws = GPIO_NUM_27, .ws = GPIO_NUM_27,
.dout = GPIO_NUM_5, .dout = GPIO_NUM_5,
.din = I2S_GPIO_UNUSED, .din = I2S_GPIO_UNUSED,
.invert_flags = { .invert_flags =
{
.mclk_inv = false, .mclk_inv = false,
.bclk_inv = false, .bclk_inv = false,
.ws_inv = false, .ws_inv = false,
} }},
},
}; };
if (esp_err_t err = i2s_channel_init_std_mode(i2s_handle, &i2s_config) != ESP_OK) { if (esp_err_t err =
i2s_channel_init_std_mode(i2s_handle, &i2s_config) != ESP_OK) {
ESP_LOGE(kTag, "failed to initialise i2s channel %x", err); ESP_LOGE(kTag, "failed to initialise i2s channel %x", err);
return cpp::fail(Error::FAILED_TO_INSTALL_I2S); return cpp::fail(Error::FAILED_TO_INSTALL_I2S);
} }
@ -90,10 +91,12 @@ auto AudioDac::create(GpioExpander* expander)
return dac; return dac;
} }
AudioDac::AudioDac(GpioExpander* gpio, i2s_chan_handle_t i2s_handle) : gpio_(gpio), AudioDac::AudioDac(GpioExpander* gpio, i2s_chan_handle_t i2s_handle)
: gpio_(gpio),
i2s_handle_(i2s_handle), i2s_handle_(i2s_handle),
clock_config_(I2S_STD_CLK_DEFAULT_CONFIG(48000)), clock_config_(I2S_STD_CLK_DEFAULT_CONFIG(48000)),
slot_config_(I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_STEREO)) { slot_config_(I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT,
I2S_SLOT_MODE_STEREO)) {
gpio_->set_pin(GpioExpander::AUDIO_POWER_ENABLE, true); gpio_->set_pin(GpioExpander::AUDIO_POWER_ENABLE, true);
gpio_->Write(); gpio_->Write();
} }

@ -2,8 +2,8 @@
#include <cstdint> #include <cstdint>
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali.h" #include "esp_adc/adc_cali.h"
#include "esp_adc/adc_oneshot.h"
#include "esp_err.h" #include "esp_err.h"
#include "result.hpp" #include "result.hpp"
@ -18,6 +18,7 @@ class Battery {
* Returns the current battery level in millivolts. * Returns the current battery level in millivolts.
*/ */
auto Millivolts() -> uint32_t; auto Millivolts() -> uint32_t;
private: private:
adc_oneshot_unit_handle_t adc_handle_; adc_oneshot_unit_handle_t adc_handle_;
adc_cali_handle_t adc_calibration_handle_; adc_cali_handle_t adc_calibration_handle_;

@ -6,12 +6,12 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "driver/i2s_std.h"
#include "driver/i2s_types.h" #include "driver/i2s_types.h"
#include "esp_err.h" #include "esp_err.h"
#include "freertos/portmacro.h" #include "freertos/portmacro.h"
#include "result.hpp" #include "result.hpp"
#include "span.hpp" #include "span.hpp"
#include "driver/i2s_std.h"
#include "gpio_expander.hpp" #include "gpio_expander.hpp"

Loading…
Cancel
Save