summaryrefslogtreecommitdiff
path: root/src/drivers/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-08-08 20:25:42 +1000
committerjacqueline <me@jacqueline.id.au>2023-08-08 20:25:42 +1000
commite1181fbe59a835ea9c93d6e067e9757e8c522d3c (patch)
tree2fd61bb93713de8c2205b7b6d0a8c84c49832e93 /src/drivers/include
parentc3f40a8cc37114365ef3ec6f2888df64e5206b39 (diff)
parent592f231627843bc44ebaaa4506aec26da1f56499 (diff)
downloadtangara-fw-e1181fbe59a835ea9c93d6e067e9757e8c522d3c.tar.gz
Merge branch 'main' into opus
Diffstat (limited to 'src/drivers/include')
-rw-r--r--src/drivers/include/bluetooth.hpp108
-rw-r--r--src/drivers/include/i2s_dac.hpp6
-rw-r--r--src/drivers/include/nvs.hpp27
3 files changed, 137 insertions, 4 deletions
diff --git a/src/drivers/include/bluetooth.hpp b/src/drivers/include/bluetooth.hpp
new file mode 100644
index 00000000..2b5e6a8d
--- /dev/null
+++ b/src/drivers/include/bluetooth.hpp
@@ -0,0 +1,108 @@
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include <freertos/FreeRTOS.h>
+#include <freertos/stream_buffer.h>
+#include "esp_a2dp_api.h"
+#include "esp_avrc_api.h"
+#include "esp_gap_bt_api.h"
+#include "tinyfsm.hpp"
+#include "tinyfsm/include/tinyfsm.hpp"
+
+namespace drivers {
+
+/*
+ * A handle used to interact with the bluetooth state machine.
+ */
+class Bluetooth {
+ public:
+ Bluetooth();
+
+ auto Enable() -> bool;
+ auto Disable() -> void;
+
+ auto SetSource(StreamBufferHandle_t) -> void;
+};
+
+namespace bluetooth {
+
+namespace events {
+struct Enable : public tinyfsm::Event {};
+struct Disable : public tinyfsm::Event {};
+
+namespace internal {
+struct Gap : public tinyfsm::Event {
+ esp_bt_gap_cb_event_t type;
+ esp_bt_gap_cb_param_t* param;
+};
+struct A2dp : public tinyfsm::Event {
+ esp_a2d_cb_event_t type;
+ esp_a2d_cb_param_t* param;
+};
+struct Avrc : public tinyfsm::Event {
+ esp_avrc_ct_cb_event_t type;
+ esp_avrc_ct_cb_param_t* param;
+};
+} // namespace internal
+} // namespace events
+
+class BluetoothState : public tinyfsm::Fsm<BluetoothState> {
+ public:
+ virtual ~BluetoothState(){};
+
+ virtual void entry() {}
+ virtual void exit() {}
+
+ virtual void react(const events::Enable& ev){};
+ virtual void react(const events::Disable& ev) = 0;
+
+ virtual void react(const events::internal::Gap& ev) = 0;
+ virtual void react(const events::internal::A2dp& ev) = 0;
+ virtual void react(const events::internal::Avrc& ev){};
+};
+
+class Disabled : public BluetoothState {
+ void entry() override;
+
+ void react(const events::Enable& ev) override;
+ void react(const events::Disable& ev) override{};
+
+ void react(const events::internal::Gap& ev) override {}
+ void react(const events::internal::A2dp& ev) override {}
+};
+
+class Scanning : public BluetoothState {
+ void entry() override;
+ void exit() override;
+
+ void react(const events::Disable& ev) override;
+
+ void react(const events::internal::Gap& ev) override;
+ void react(const events::internal::A2dp& ev) override;
+};
+
+class Connecting : public BluetoothState {
+ void entry() override;
+ void exit() override;
+
+ void react(const events::Disable& ev) override;
+ void react(const events::internal::Gap& ev) override;
+ void react(const events::internal::A2dp& ev) override;
+};
+
+class Connected : public BluetoothState {
+ void entry() override;
+ void exit() override;
+
+ void react(const events::Disable& ev) override;
+ void react(const events::internal::Gap& ev) override;
+ void react(const events::internal::A2dp& ev) override;
+ void react(const events::internal::Avrc& ev) override;
+};
+
+} // namespace bluetooth
+
+} // namespace drivers
diff --git a/src/drivers/include/i2s_dac.hpp b/src/drivers/include/i2s_dac.hpp
index 06c0dc16..889ba68c 100644
--- a/src/drivers/include/i2s_dac.hpp
+++ b/src/drivers/include/i2s_dac.hpp
@@ -51,14 +51,12 @@ class I2SDac {
BPS_32 = I2S_DATA_BIT_WIDTH_32BIT,
};
enum SampleRate {
- SAMPLE_RATE_11_025 = 11025,
- SAMPLE_RATE_16 = 16000,
- SAMPLE_RATE_22_05 = 22050,
+ SAMPLE_RATE_8 = 8000,
SAMPLE_RATE_32 = 32000,
SAMPLE_RATE_44_1 = 44100,
SAMPLE_RATE_48 = 48000,
+ SAMPLE_RATE_88_2 = 88200,
SAMPLE_RATE_96 = 96000,
- SAMPLE_RATE_192 = 192000,
};
auto Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate) -> void;
diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp
new file mode 100644
index 00000000..be783583
--- /dev/null
+++ b/src/drivers/include/nvs.hpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include "esp_err.h"
+#include "nvs.h"
+
+namespace drivers {
+
+class NvsStorage {
+ public:
+ static auto Open() -> NvsStorage*;
+
+ auto SchemaVersion() -> uint8_t;
+
+ explicit NvsStorage(nvs_handle_t);
+ ~NvsStorage();
+
+ private:
+ nvs_handle_t handle_;
+};
+
+} // namespace drivers \ No newline at end of file