2025-01-28 23:26:55 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "BaseSerialInterface.h"
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
class ArduinoSerialInterface : public BaseSerialInterface {
|
|
|
|
|
bool _isEnabled;
|
|
|
|
|
uint8_t _state;
|
2025-01-29 10:12:22 +11:00
|
|
|
uint16_t _frame_len;
|
|
|
|
|
uint16_t rx_len;
|
2025-02-04 22:09:46 +11:00
|
|
|
#ifdef LILYGO_T3S3
|
|
|
|
|
HWCDC* _serial;
|
2025-02-12 18:40:00 +11:00
|
|
|
#elif defined(NRF52_PLATFORM)
|
|
|
|
|
Adafruit_USBD_CDC* _serial;
|
2025-02-04 22:09:46 +11:00
|
|
|
#else
|
2025-01-28 23:26:55 +11:00
|
|
|
HardwareSerial* _serial;
|
2025-02-04 22:09:46 +11:00
|
|
|
#endif
|
2025-01-28 23:26:55 +11:00
|
|
|
uint8_t rx_buf[MAX_FRAME_SIZE];
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ArduinoSerialInterface() { _isEnabled = false; _state = 0; }
|
|
|
|
|
|
2025-02-04 22:09:46 +11:00
|
|
|
#ifdef LILYGO_T3S3
|
|
|
|
|
void begin(HWCDC& serial) { _serial = &serial; }
|
2025-02-12 18:40:00 +11:00
|
|
|
#elif defined(NRF52_PLATFORM)
|
|
|
|
|
void begin(Adafruit_USBD_CDC& serial) { _serial = &serial; }
|
2025-02-04 22:09:46 +11:00
|
|
|
#else
|
2025-01-28 23:26:55 +11:00
|
|
|
void begin(HardwareSerial& serial) { _serial = &serial; }
|
2025-02-04 22:09:46 +11:00
|
|
|
#endif
|
2025-01-28 23:26:55 +11:00
|
|
|
|
|
|
|
|
// BaseSerialInterface methods
|
|
|
|
|
void enable() override;
|
|
|
|
|
void disable() override;
|
|
|
|
|
bool isEnabled() const override { return _isEnabled; }
|
|
|
|
|
|
|
|
|
|
bool isConnected() const override;
|
|
|
|
|
|
|
|
|
|
bool isWriteBusy() const override;
|
|
|
|
|
size_t writeFrame(const uint8_t src[], size_t len) override;
|
|
|
|
|
size_t checkRecvFrame(uint8_t dest[]) override;
|
|
|
|
|
};
|