@@ -61,9 +61,13 @@ void UART::WrapperCallback(uart_callback_args_t *p_args) {
61
61
case UART_EVENT_TX_COMPLETE:
62
62
case UART_EVENT_TX_DATA_EMPTY:
63
63
{
64
- // uint8_t to_enqueue = uart_ptr->txBuffer.available() < uart_ptr->uart_ctrl.fifo_depth ? uart_ptr->txBuffer.available() : uart_ptr->uart_ctrl.fifo_depth;
65
- // while (to_enqueue) {
66
- uart_ptr->tx_done = true ;
64
+ if (uart_ptr->txBuffer .available ()){
65
+ static char txc;
66
+ txc = uart_ptr->txBuffer .read_char ();
67
+ R_SCI_UART_Write (&(uart_ptr->uart_ctrl ), (uint8_t *)&txc , 1 );
68
+ } else {
69
+ uart_ptr->tx_done = true ;
70
+ }
67
71
break ;
68
72
}
69
73
case UART_EVENT_RX_CHAR:
@@ -108,27 +112,31 @@ bool UART::setUpUartIrqs(uart_cfg_t &cfg) {
108
112
/* -------------------------------------------------------------------------- */
109
113
size_t UART::write (uint8_t c) {
110
114
/* -------------------------------------------------------------------------- */
111
- if (init_ok) {
112
- tx_done = false ;
113
- R_SCI_UART_Write (&uart_ctrl, &c, 1 );
114
- while (!tx_done) {}
115
- return 1 ;
116
- }
117
- else {
118
- return 0 ;
119
- }
115
+ if (init_ok) {
116
+ while (txBuffer.isFull ()){;}
117
+ txBuffer.store_char (c);
118
+ if (tx_done){
119
+ tx_done = false ;
120
+ txc = txBuffer.read_char (); // clear out the char we just added and send it to start transmission.
121
+ R_SCI_UART_Write (&uart_ctrl, (uint8_t *)&txc , 1 );
122
+ }
123
+ return 1 ;
124
+ }
125
+ else {
126
+ return 0 ;
127
+ }
120
128
}
121
129
122
130
size_t UART::write (uint8_t * c, size_t len) {
123
- if (init_ok) {
124
- tx_done = false ;
125
- R_SCI_UART_Write (&uart_ctrl, c, len );
126
- while (!tx_done) { }
127
- return len;
128
- }
129
- else {
130
- return 0 ;
131
- }
131
+ if (init_ok) {
132
+ for ( int i = 0 ; i<len; i++){
133
+ write (c[i] );
134
+ }
135
+ return len;
136
+ }
137
+ else {
138
+ return 0 ;
139
+ }
132
140
}
133
141
134
142
/* -------------------------------------------------------------------------- */
@@ -328,11 +336,5 @@ void UART::flush() {
328
336
/* -------------------------------------------------------------------------- */
329
337
size_t UART::write_raw (uint8_t * c, size_t len) {
330
338
/* -------------------------------------------------------------------------- */
331
- size_t i = 0 ;
332
- while (i < len) {
333
- uart_ctrl.p_reg ->TDR = *(c+i);
334
- while (uart_ctrl.p_reg ->SSR_b .TEND == 0 ) {}
335
- i++;
336
- }
337
- return len;
339
+ return write (c, len);
338
340
}
0 commit comments