13 #ifndef _HARDWARESERIAL_H_ 14 #define _HARDWARESERIAL_H_ 16 #include "../Wiring/WiringFrameworkDependencies.h" 17 #include "../Wiring/Stream.h" 18 #include "../SmingCore/Delegate.h" 19 #include "../Services/CommandProcessing/CommandProcessingIncludes.h" 24 #define NUMBER_UARTS 2 26 #define SERIAL_SIGNAL_DELEGATE 0 27 #define SERIAL_SIGNAL_COMMAND 1 28 #define SERIAL_QUEUE_LEN 10 48 SERIAL_5N1 = UART_5N1,
49 SERIAL_6N1 = UART_6N1,
50 SERIAL_7N1 = UART_7N1,
51 SERIAL_8N1 = UART_8N1,
52 SERIAL_5N2 = UART_5N2,
53 SERIAL_6N2 = UART_6N2,
54 SERIAL_7N2 = UART_7N2,
55 SERIAL_8N2 = UART_8N2,
56 SERIAL_5E1 = UART_5E1,
57 SERIAL_6E1 = UART_6E1,
58 SERIAL_7E1 = UART_7E1,
59 SERIAL_8E1 = UART_8E1,
60 SERIAL_5E2 = UART_5E2,
61 SERIAL_6E2 = UART_6E2,
62 SERIAL_7E2 = UART_7E2,
63 SERIAL_8E2 = UART_8E2,
64 SERIAL_5O1 = UART_5O1,
65 SERIAL_6O1 = UART_6O1,
66 SERIAL_7O1 = UART_7O1,
67 SERIAL_8O1 = UART_8O1,
68 SERIAL_5O2 = UART_5O2,
69 SERIAL_6O2 = UART_6O2,
70 SERIAL_7O2 = UART_7O2,
71 SERIAL_8O2 = UART_8O2,
75 SERIAL_FULL = UART_FULL,
76 SERIAL_RX_ONLY = UART_RX_ONLY,
77 SERIAL_TX_ONLY = UART_TX_ONLY
94 void begin(
const uint32_t baud = 9600) {
95 begin(baud, SERIAL_8N1, SERIAL_FULL, 1);
105 void begin(
const uint32_t baud, SerialConfig config)
107 begin(baud, config, SERIAL_FULL, 1);
118 void begin(
const uint32_t baud, SerialConfig config, SerialMode mode)
120 begin(baud, config, mode, 1);
123 void begin(
const uint32_t baud, SerialConfig config, SerialMode mode, uint8_t txPin);
135 size_t setRxBufferSize(
size_t size);
151 void swap(uint8_t tx_pin);
160 void setTx(uint8_t tx_pin);
169 void pins(uint8_t tx, uint8_t rx);
205 size_t write(uint8_t oneChar);
253 operator bool()
const;
259 uart_t* uart =
nullptr;
262 static os_event_t *serialQueue;
269 static void IRAM_ATTR callbackHandler(uart_t *arg);
274 static void delegateTask (os_event_t *inputEvent);
void begin(const uint32_t baud, SerialConfig config)
Initialise and set its configuration.
Definition: HardwareSerial.h:105
int available()
Get quantity characters available from serial input.
StreamDataReceivedDelegate HWSDelegate
Delegate callback handler.
Definition: HardwareSerial.h:43
int readMemoryBlock(char *buf, int max_len)
Read a block of characters from serial port.
bool setCallback(StreamDataReceivedDelegate reqCallback)
Set handler for received data.
Definition: CommandExecutor.h:18
void begin(const uint32_t baud=9600)
Initialise the serial port.
Definition: HardwareSerial.h:94
bool isTxEnabled(void)
Checks if the current UART can transmit(print) information.
virtual size_t write(uint8_t)=0
Writes a single character to output stream.
int read()
Read a character from serial port.
bool isRxEnabled(void)
Checks if the current UART can receive information.
void commandProcessing(bool reqEnable)
Configure serial port for command processing.
void begin(const uint32_t baud, SerialConfig config, SerialMode mode)
Initialise, set its configuration and mode.
Definition: HardwareSerial.h:118
Hardware serial class.
Definition: HardwareSerial.h:81
void systemDebugOutput(bool enabled)
Configure serial port for system debug output and redirect output from debugf.
void resetCallback()
Remove handler for received data.
HardwareSerial Serial
Global instance of serial port UART0.
Hardware serial member data.
Definition: HardwareSerial.h:41
HardwareSerial(const int uartPort)
Create instance of a hardware serial port object.
void flush()
Clear the serial port receive buffer.
int peek()
Read a character from serial port without removing from input buffer.
Delegate< void(Stream &source, char arrivedChar, uint16_t availableCharsCount)> StreamDataReceivedDelegate
Delegate callback type for serial data reception.
Definition: HardwareSerial.h:36
int baudRate(void)
Get the current baud rate.
#define NUMBER_UARTS
Quantity of UARTs available.
Definition: HardwareSerial.h:24
size_t write(uint8_t oneChar)
write a character to serial port