From 955a8ce303a9f8fd6a34009934e3d7aaeff3ec17 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 1 Aug 2023 12:13:48 +1000 Subject: Basic nvs init + bluetooth in the build --- src/drivers/include/bluetooth.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/drivers/include/bluetooth.hpp (limited to 'src/drivers/include/bluetooth.hpp') diff --git a/src/drivers/include/bluetooth.hpp b/src/drivers/include/bluetooth.hpp new file mode 100644 index 00000000..f3a4b2ac --- /dev/null +++ b/src/drivers/include/bluetooth.hpp @@ -0,0 +1,19 @@ + +#pragma once + +#include + +namespace drivers { + +class Bluetooth { + public: + static auto Enable() -> Bluetooth*; + Bluetooth(); + ~Bluetooth(); + + struct Device {}; + auto Scan() -> std::vector; + private: + }; + +} -- cgit v1.2.3 From 3511852f39cd5023ec8e6d0b94cc69f34e9201ed Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 3 Aug 2023 15:32:28 +1000 Subject: Add very limited resampling (it's slow as shit) --- src/drivers/include/bluetooth.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/drivers/include/bluetooth.hpp') diff --git a/src/drivers/include/bluetooth.hpp b/src/drivers/include/bluetooth.hpp index f3a4b2ac..22b58c8b 100644 --- a/src/drivers/include/bluetooth.hpp +++ b/src/drivers/include/bluetooth.hpp @@ -6,14 +6,15 @@ namespace drivers { class Bluetooth { - public: - static auto Enable() -> Bluetooth*; - Bluetooth(); - ~Bluetooth(); + public: + static auto Enable() -> Bluetooth*; + Bluetooth(); + ~Bluetooth(); - struct Device {}; - auto Scan() -> std::vector; - private: - }; + struct Device {}; + auto Scan() -> std::vector; -} + private: +}; + +} // namespace drivers -- cgit v1.2.3 From 520ec6d98a761e1d96b5bea299819c096ce08ac3 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 8 Aug 2023 17:04:34 +1000 Subject: Add skeleton of bluetooth FSM --- src/drivers/include/bluetooth.hpp | 98 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) (limited to 'src/drivers/include/bluetooth.hpp') diff --git a/src/drivers/include/bluetooth.hpp b/src/drivers/include/bluetooth.hpp index 22b58c8b..2b5e6a8d 100644 --- a/src/drivers/include/bluetooth.hpp +++ b/src/drivers/include/bluetooth.hpp @@ -1,20 +1,108 @@ #pragma once +#include #include +#include +#include +#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: - static auto Enable() -> Bluetooth*; Bluetooth(); - ~Bluetooth(); - struct Device {}; - auto Scan() -> std::vector; + 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 { + 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; - private: + 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 -- cgit v1.2.3