File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ void Uart::begin(unsigned long baud, XMC_UART_MODE_t config) {
68
68
69
69
XMC_GPIO_Init (_XMC_UART_config->rx .port , _XMC_UART_config->rx .pin ,
70
70
&(_XMC_UART_config->rx_config ));
71
+ serial_ready = true ;
71
72
}
72
73
73
74
void Uart::end (void ) {
@@ -77,6 +78,7 @@ void Uart::end(void) {
77
78
NVIC_DisableIRQ (_XMC_UART_config->irq_num );
78
79
// Clear any received data after stopping interrupts
79
80
_rx_buffer.clear ();
81
+ serial_ready = false ;
80
82
}
81
83
82
84
void Uart::setInterruptPriority (uint32_t priority) {
@@ -107,6 +109,24 @@ size_t Uart::write(const uint8_t uc_data) {
107
109
XMC_UART_CH_Transmit (_XMC_UART_config->channel , uc_data);
108
110
return 1 ;
109
111
}
112
+ size_t Uart::write (const uint8_t * buffer, size_t length) {
113
+ // Check for null pointer or zero length
114
+ if (buffer == nullptr || length == 0 ) {
115
+ return 0 ;
116
+ }
117
+ size_t bytes_sent = 0 ;
118
+ for (size_t i = 0 ; i < length; ++i) {
119
+ // Transmit a single byte using XMC UART transmit function
120
+ XMC_UART_CH_Transmit (_XMC_UART_config->channel , buffer[i]);
121
+ ++bytes_sent; // Increment the count of bytes sent
122
+ }
123
+ // Return the total number of bytes successfully sent
124
+ return bytes_sent;
125
+ }
126
+
127
+ Uart::operator bool () {
128
+ return serial_ready;
129
+ }
110
130
111
131
void Uart::IrqHandler (void ) {
112
132
// Receive data Interrupt handler
Original file line number Diff line number Diff line change @@ -84,17 +84,20 @@ class Uart : public HardwareSerial {
84
84
void flush (void );
85
85
86
86
size_t write (const uint8_t );
87
+ size_t write (const uint8_t *buffer, size_t size);
87
88
using Print::write; // pull in write(str) and write(buf, size) from Print
88
89
89
- operator bool () { return true ; }
90
+ operator bool ();
90
91
91
92
void setInterruptPriority (uint32_t priority);
92
93
uint32_t getInterruptPriority ();
93
94
94
95
void IrqHandler (void );
95
96
96
97
private:
97
- RingBuffer _rx_buffer;
98
+ static constexpr size_t BUF_LENGTH = 512 ;
99
+ RingBufferN<BUF_LENGTH> _rx_buffer;
100
+ bool serial_ready =false ;
98
101
};
99
102
extern Uart Serial;
100
103
extern Uart Serial1;
You can’t perform that action at this time.
0 commit comments