summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-01-21 19:02:28 +1100
committerjacqueline <me@jacqueline.id.au>2023-01-21 19:02:28 +1100
commit0560fa7f10e0cbeae07b861bb03419377219aac0 (patch)
tree77cc6c5e65805b5ad340f92c451615787ba020df
parent8ed3d7e31f8b16a24593c01a480b19b14a513b48 (diff)
downloadtangara-fw-0560fa7f10e0cbeae07b861bb03419377219aac0.tar.gz
clang-format
-rw-r--r--src/audio/fatfs_audio_input.cpp6
-rw-r--r--src/drivers/battery.cpp25
-rw-r--r--src/drivers/dac.cpp45
-rw-r--r--src/drivers/include/battery.hpp23
-rw-r--r--src/drivers/include/dac.hpp2
-rw-r--r--src/main/main.cpp2
6 files changed, 55 insertions, 48 deletions
diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp
index f0d4d751..fc623d86 100644
--- a/src/audio/fatfs_audio_input.cpp
+++ b/src/audio/fatfs_audio_input.cpp
@@ -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(&current_file_)) {
f_close(&current_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);
diff --git a/src/drivers/battery.cpp b/src/drivers/battery.cpp
index 29224e2d..00e7796a 100644
--- a/src/drivers/battery.cpp
+++ b/src/drivers/battery.cpp
@@ -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;
}
diff --git a/src/drivers/dac.cpp b/src/drivers/dac.cpp
index 2c7b3e5b..2abb361e 100644
--- a/src/drivers/dac.cpp
+++ b/src/drivers/dac.cpp
@@ -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?
diff --git a/src/drivers/include/battery.hpp b/src/drivers/include/battery.hpp
index dea46d7c..d50bb20f 100644
--- a/src/drivers/include/battery.hpp
+++ b/src/drivers/include/battery.hpp
@@ -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;
- /**
- * 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_;
+ private:
+ adc_oneshot_unit_handle_t adc_handle_;
+ adc_cali_handle_t adc_calibration_handle_;
};
} // namespace drivers
diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp
index 8c49ce17..aec89c72 100644
--- a/src/drivers/include/dac.hpp
+++ b/src/drivers/include/dac.hpp
@@ -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"
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 82a51b8d..f2dd0d1a 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -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);