Skip to content

Commit f447301

Browse files
committed
cores/xmc: Write() with buf and size.
Signed-off-by: MDin <[email protected]>
1 parent 6f40df2 commit f447301

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

cores/xmc/Uart.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
// Constructors ////////////////////////////////////////////////////////////////
66

7-
Uart::Uart(XMC_UART_t *xmc_uart_config){
8-
_XMC_UART_config = xmc_uart_config;
9-
}
7+
Uart::Uart(XMC_UART_t *xmc_uart_config) { _XMC_UART_config = xmc_uart_config; }
8+
109
// Public Methods //////////////////////////////////////////////////////////////
1110

1211
void Uart::begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
@@ -68,6 +67,7 @@ void Uart::begin(unsigned long baud, XMC_UART_MODE_t config) {
6867

6968
XMC_GPIO_Init(_XMC_UART_config->rx.port, _XMC_UART_config->rx.pin,
7069
&(_XMC_UART_config->rx_config));
70+
serial_ready = true;
7171
}
7272

7373
void Uart::end(void) {
@@ -77,6 +77,7 @@ void Uart::end(void) {
7777
NVIC_DisableIRQ(_XMC_UART_config->irq_num);
7878
// Clear any received data after stopping interrupts
7979
_rx_buffer.clear();
80+
serial_ready = false;
8081
}
8182

8283
void Uart::setInterruptPriority(uint32_t priority) {
@@ -108,6 +109,20 @@ size_t Uart::write(const uint8_t uc_data) {
108109
return 1;
109110
}
110111

112+
size_t Uart::write(const uint8_t *buffer, size_t size) {
113+
// Check if the length is valid
114+
if ((size == 0) || (buffer == nullptr)) {
115+
return 0;
116+
}
117+
// For sending, write immediately
118+
for (size_t i = 0; i < size; i++) {
119+
XMC_UART_CH_Transmit(_XMC_UART_config->channel, buffer[i]);
120+
}
121+
return size;
122+
}
123+
124+
Uart::operator bool() { return serial_ready; }
125+
111126
void Uart::IrqHandler(void) {
112127
// Receive data Interrupt handler
113128
uint32_t status = XMC_UART_CH_GetStatusFlag(_XMC_UART_config->channel);

cores/xmc/Uart.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ class Uart : public HardwareSerial {
8484
void flush(void);
8585

8686
size_t write(const uint8_t);
87+
size_t write(const uint8_t *buffer, size_t size);
8788
using Print::write; // pull in write(str) and write(buf, size) from Print
8889

89-
operator bool() { return true; }
90+
operator bool();
9091

9192
void setInterruptPriority(uint32_t priority);
9293
uint32_t getInterruptPriority();

0 commit comments

Comments
 (0)