diff --git a/CLC-qthing/SiliconTorch/CyanBus.cpp b/CLC-qthing/SiliconTorch/CyanBus.cpp index 85b3a8d3b39be379fd9a062953852409c44b0521..4b768dc84c756e2dec01b2ea5d600deeca9e52b5 100644 --- a/CLC-qthing/SiliconTorch/CyanBus.cpp +++ b/CLC-qthing/SiliconTorch/CyanBus.cpp @@ -1,8 +1,8 @@ #include "CyanBus.hpp" // C++ system level -// #include <cstdlib> // TODO: is this for memcpy? #include <cstring> // memset +#include <cstdlib> // TODO: is this for memcpy? #include <cinttypes> #include <functional> @@ -28,9 +28,7 @@ namespace SiliconTorch { namespace CyanBus { - // This leads to ~54 P/s @ 2 MBaud at 100% load - const uint32_t MTU = 4096; - + // CyanBus envelope header const uint8_t* const HEADER = (const uint8_t*)"fxCyan"; @@ -88,6 +86,9 @@ namespace SiliconTorch { readerTaskHandle = new SiliconTorch::Util::LambdaTask([&](){ readerTask(); }); + + packetQ = xQueueCreate(3, sizeof(CyanData)); + callbackTaskHandle = new SiliconTorch::Util::LambdaTask([&](){ callbackTask(); }); } void CyanBus::readerTask() { @@ -121,10 +122,8 @@ namespace SiliconTorch { - enum FSM { - SearchHeader, ReadPayload - }; - + enum FSM { SearchHeader, ReadLength, ReadPayload, CheckCRC }; + FSM fsm = SearchHeader; uart_event_t event; @@ -181,6 +180,9 @@ namespace SiliconTorch { delete buffer; } + void CyanBus::callbackTask() { + ESP_LOGW(TAG, "TODO: implement callback task!"); + } void CyanBus::setBaudRate(uint32_t baudRate) { uart_set_baudrate((uart_port_t)uartChannel, baudRate); diff --git a/CLC-qthing/SiliconTorch/CyanBus.hpp b/CLC-qthing/SiliconTorch/CyanBus.hpp index ee561e7ab4b4431f36edf8cfe5d08f7ca65eb5b0..130ab90f39ed81f1bbaf098e2740952ed90041a0 100644 --- a/CLC-qthing/SiliconTorch/CyanBus.hpp +++ b/CLC-qthing/SiliconTorch/CyanBus.hpp @@ -18,11 +18,20 @@ namespace SiliconTorch { namespace CyanBus { // CyanBus payload MTU - extern const uint32_t MTU; + // This leads to ~54 P/s @ 2 MBaud at 100% load + constexpr uint32_t MTU = 4096; // CyanBus envelope header extern const uint8_t* const HEADER; + + typedef struct { + bool crc; + uint16_t length; + uint8_t payload[MTU]; + } CyanData; + + class CyanBus { public: CyanBus(uint8_t tx, uint8_t rx, uint8_t de, uint8_t re, uint32_t baudRate = 115200, uint8_t uartChannel = 1); @@ -33,6 +42,7 @@ namespace SiliconTorch { private: QueueHandle_t uartEvQ; + QueueHandle_t packetQ; uint8_t uartChannel; uint8_t tx, rx, de, re; @@ -50,8 +60,10 @@ namespace SiliconTorch { void readerTask(); + void callbackTask(); - SiliconTorch::Util::LambdaTask* readerTaskHandle = NULL; + SiliconTorch::Util::LambdaTask* readerTaskHandle = NULL; + SiliconTorch::Util::LambdaTask* callbackTaskHandle = NULL; }; } diff --git a/CLC-qthing/device_main.cpp b/CLC-qthing/device_main.cpp index 6a46045eeffe91de36da586fca5a641ff864479c..082d19840c1151692c85f49f0bec431274e65ef0 100644 --- a/CLC-qthing/device_main.cpp +++ b/CLC-qthing/device_main.cpp @@ -16,9 +16,11 @@ qthing::Config cfg; CyanLight::CyanLightControl* ctrl; - void device_main() { + // Needed for packet parsing, animation rendering and stuff + qthing::power_managment_max_power(); + SiliconTorch::CyanBus::CyanBus cyanBus(13, 14, 12, 15); // Pinout of CyanStripe