clang-format
This commit is contained in:
@@ -106,7 +106,7 @@ auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, AudioProcessingError> {
|
||||
read_size = file_buffer_.begin() - file_buffer_write_pos_;
|
||||
}
|
||||
|
||||
ESP_LOGI(kTag, "reading up to %d bytes", (int) read_size);
|
||||
ESP_LOGI(kTag, "reading up to %d bytes", (int)read_size);
|
||||
|
||||
UINT bytes_read = 0;
|
||||
FRESULT result =
|
||||
@@ -117,7 +117,7 @@ auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, AudioProcessingError> {
|
||||
return cpp::fail(IO_ERROR);
|
||||
}
|
||||
|
||||
ESP_LOGI(kTag, "actual read size %d bytes", (int) bytes_read);
|
||||
ESP_LOGI(kTag, "actual read size %d bytes", (int)bytes_read);
|
||||
|
||||
if (f_eof(¤t_file_)) {
|
||||
f_close(¤t_file_);
|
||||
@@ -135,7 +135,7 @@ auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, AudioProcessingError> {
|
||||
|
||||
// Now stream data into the output buffer until it's full.
|
||||
while (GetRingBufferDistance() > 0) {
|
||||
ESP_LOGI(kTag, "writing up to %d bytes", (int) GetRingBufferDistance());
|
||||
ESP_LOGI(kTag, "writing up to %d bytes", (int)GetRingBufferDistance());
|
||||
ChunkWriteResult result = chunk_writer_->WriteChunkToStream(
|
||||
[&](cpp::span<std::byte> d) { return SendChunk(d); }, kServiceInterval);
|
||||
|
||||
|
||||
+13
-10
@@ -1,9 +1,9 @@
|
||||
#include "battery.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_adc/adc_cali.h"
|
||||
#include "esp_adc/adc_cali_scheme.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "hal/adc_types.h"
|
||||
|
||||
namespace drivers {
|
||||
@@ -18,24 +18,26 @@ static const adc_channel_t kAdcChannel = ADC_CHANNEL_6;
|
||||
|
||||
Battery::Battery() {
|
||||
adc_oneshot_unit_init_cfg_t unit_config = {
|
||||
.unit_id = kAdcUnit,
|
||||
.unit_id = kAdcUnit,
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_oneshot_new_unit(&unit_config, &adc_handle_));
|
||||
|
||||
adc_oneshot_chan_cfg_t channel_config = {
|
||||
.atten = kAdcAttenuation,
|
||||
.bitwidth = kAdcBitWidth,
|
||||
.atten = kAdcAttenuation,
|
||||
.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
|
||||
// TODO: compile-time assert our scheme is available
|
||||
adc_cali_line_fitting_config_t calibration_config = {
|
||||
.unit_id = kAdcUnit,
|
||||
.atten = kAdcAttenuation,
|
||||
.bitwidth = kAdcBitWidth,
|
||||
.unit_id = kAdcUnit,
|
||||
.atten = kAdcAttenuation,
|
||||
.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() {
|
||||
@@ -48,7 +50,8 @@ auto Battery::Millivolts() -> uint32_t {
|
||||
ESP_ERROR_CHECK(adc_oneshot_read(adc_handle_, kAdcChannel, &raw));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
+24
-21
@@ -28,36 +28,37 @@ static const AudioDac::BitsPerSample kDefaultBps = AudioDac::BPS_16;
|
||||
|
||||
auto AudioDac::create(GpioExpander* expander)
|
||||
-> cpp::result<std::unique_ptr<AudioDac>, Error> {
|
||||
|
||||
// TODO: tune.
|
||||
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);
|
||||
//
|
||||
// First, instantiate the instance so it can do all of its power on
|
||||
// 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
|
||||
// driver.
|
||||
i2s_std_config_t i2s_config = {
|
||||
.clk_cfg = dac->clock_config_,
|
||||
.slot_cfg = dac->slot_config_,
|
||||
.gpio_cfg = {
|
||||
.mclk = GPIO_NUM_0,
|
||||
.bclk = GPIO_NUM_26,
|
||||
.ws = GPIO_NUM_27,
|
||||
.dout = GPIO_NUM_5,
|
||||
.din = I2S_GPIO_UNUSED,
|
||||
.invert_flags = {
|
||||
.mclk_inv = false,
|
||||
.bclk_inv = false,
|
||||
.ws_inv = false,
|
||||
}
|
||||
},
|
||||
.gpio_cfg = {.mclk = GPIO_NUM_0,
|
||||
.bclk = GPIO_NUM_26,
|
||||
.ws = GPIO_NUM_27,
|
||||
.dout = GPIO_NUM_5,
|
||||
.din = I2S_GPIO_UNUSED,
|
||||
.invert_flags =
|
||||
{
|
||||
.mclk_inv = false,
|
||||
.bclk_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);
|
||||
return cpp::fail(Error::FAILED_TO_INSTALL_I2S);
|
||||
}
|
||||
@@ -90,10 +91,12 @@ auto AudioDac::create(GpioExpander* expander)
|
||||
return dac;
|
||||
}
|
||||
|
||||
AudioDac::AudioDac(GpioExpander* gpio, i2s_chan_handle_t i2s_handle) : gpio_(gpio),
|
||||
i2s_handle_(i2s_handle),
|
||||
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)) {
|
||||
AudioDac::AudioDac(GpioExpander* gpio, i2s_chan_handle_t i2s_handle)
|
||||
: gpio_(gpio),
|
||||
i2s_handle_(i2s_handle),
|
||||
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)) {
|
||||
gpio_->set_pin(GpioExpander::AUDIO_POWER_ENABLE, true);
|
||||
gpio_->Write();
|
||||
}
|
||||
@@ -152,7 +155,7 @@ auto AudioDac::Reconfigure(BitsPerSample bps, SampleRate rate) -> bool {
|
||||
// good enough.
|
||||
i2s_channel_disable(i2s_handle_);
|
||||
|
||||
slot_config_.slot_bit_width = (i2s_slot_bit_width_t) bps;
|
||||
slot_config_.slot_bit_width = (i2s_slot_bit_width_t)bps;
|
||||
i2s_channel_reconfig_std_slot(i2s_handle_, &slot_config_);
|
||||
|
||||
// TODO: update mclk multiple as well if needed?
|
||||
|
||||
@@ -2,25 +2,26 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_adc/adc_cali.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_err.h"
|
||||
#include "result.hpp"
|
||||
|
||||
namespace drivers {
|
||||
|
||||
class Battery {
|
||||
public:
|
||||
Battery();
|
||||
~Battery();
|
||||
public:
|
||||
Battery();
|
||||
~Battery();
|
||||
|
||||
/**
|
||||
* Returns the current battery level in millivolts.
|
||||
*/
|
||||
auto Millivolts() -> uint32_t;
|
||||
private:
|
||||
adc_oneshot_unit_handle_t adc_handle_;
|
||||
adc_cali_handle_t adc_calibration_handle_;
|
||||
/**
|
||||
* Returns the current battery level in millivolts.
|
||||
*/
|
||||
auto Millivolts() -> uint32_t;
|
||||
|
||||
private:
|
||||
adc_oneshot_unit_handle_t adc_handle_;
|
||||
adc_cali_handle_t adc_calibration_handle_;
|
||||
};
|
||||
|
||||
} // namespace drivers
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "driver/i2s_std.h"
|
||||
#include "driver/i2s_types.h"
|
||||
#include "esp_err.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "result.hpp"
|
||||
#include "span.hpp"
|
||||
#include "driver/i2s_std.h"
|
||||
|
||||
#include "gpio_expander.hpp"
|
||||
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ extern "C" void app_main(void) {
|
||||
|
||||
ESP_LOGI(TAG, "Init battery measurement");
|
||||
drivers::Battery* battery = new drivers::Battery();
|
||||
ESP_LOGI(TAG, "it's reading %d mV!", (int) battery->Millivolts());
|
||||
ESP_LOGI(TAG, "it's reading %d mV!", (int)battery->Millivolts());
|
||||
|
||||
ESP_LOGI(TAG, "Init SD card");
|
||||
auto storage_res = drivers::SdStorage::create(expander);
|
||||
|
||||
Reference in New Issue
Block a user