Code: Select all
void UARTManager::end()
{
uart_driver_delete(_uart_num);
if(_uart_q)
vQueueDelete(_uart_q);
_uart_q = NULL;
}
void UARTManager::begin(int baud)
{
if(_uart_q)
{
end();
}
uart_config_t uart_config =
{
.baud_rate = baud,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 122, // No idea what this is for, but shouldn't matter if flow ctrl is disabled?
.use_ref_tick = false // ?
};
uart_param_config(_uart_num, &uart_config);
int tx, rx;
if(_uart_num == 0)
{
rx = UART0_RX;
tx = UART0_TX;
}
else if(_uart_num == 1)
{
rx = UART1_RX;
tx = UART1_TX;
}
else if (_uart_num == 2)
{
rx = UART2_RX;
tx = UART2_TX;
} else {
return;
}
uart_set_pin(_uart_num, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
// Arduino default buffer size is 256
int uart_buffer_size = 256;
int uart_queue_size = 10;
int intr_alloc_flags = 0;
// Install UART driver using an event queue here
//uart_driver_install(_uart_num, uart_buffer_size, uart_buffer_size, uart_queue_size, &_uart_q, intr_alloc_flags);
uart_driver_install(_uart_num, uart_buffer_size, 0, uart_queue_size, NULL, intr_alloc_flags);
// Set initialized.
_initialized=true;
}