Skip to content

Commit fb4834b

Browse files
committed
cores/xmc: Write function with buf and size.
1 parent c48c443 commit fb4834b

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

cores/xmc/Uart.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void Uart::begin(unsigned long baud, XMC_UART_MODE_t config) {
6868

6969
XMC_GPIO_Init(_XMC_UART_config->rx.port, _XMC_UART_config->rx.pin,
7070
&(_XMC_UART_config->rx_config));
71+
serial_ready = true;
7172
}
7273

7374
void Uart::end(void) {
@@ -77,6 +78,7 @@ void Uart::end(void) {
7778
NVIC_DisableIRQ(_XMC_UART_config->irq_num);
7879
// Clear any received data after stopping interrupts
7980
_rx_buffer.clear();
81+
serial_ready = false;
8082
}
8183

8284
void Uart::setInterruptPriority(uint32_t priority) {
@@ -107,6 +109,24 @@ size_t Uart::write(const uint8_t uc_data) {
107109
XMC_UART_CH_Transmit(_XMC_UART_config->channel, uc_data);
108110
return 1;
109111
}
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+
}
110130

111131
void Uart::IrqHandler(void) {
112132
// Receive data Interrupt handler

cores/xmc/Uart.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,20 @@ 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();
9394

9495
void IrqHandler(void);
9596

9697
private:
97-
RingBuffer _rx_buffer;
98+
static constexpr size_t BUF_LENGTH = 512;
99+
RingBufferN<BUF_LENGTH> _rx_buffer;
100+
bool serial_ready =false;
98101
};
99102
extern Uart Serial;
100103
extern Uart Serial1;

0 commit comments

Comments
 (0)