Skip to content
Snippets Groups Projects
Commit aff63ed2 authored by fxk8y's avatar fxk8y :spider:
Browse files

Moar dev advancement

parent 7d5020ea
No related branches found
No related tags found
No related merge requests found
#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);
......
......@@ -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;
};
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment