Move selection of UART interface and baudrate to picoprobe_config.h (#7)

Co-authored-by: Liam Fraser <liam@raspberrypi.com>
This commit is contained in:
Andrew Scheller 2021-02-03 09:22:09 +00:00 committed by GitHub
parent 0fe6a09d8b
commit c29510f567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -7,7 +7,7 @@
void cdc_uart_init(void) {
gpio_set_function(PICOPROBE_UART_TX, GPIO_FUNC_UART);
gpio_set_function(PICOPROBE_UART_RX, GPIO_FUNC_UART);
uart_init(uart1, 115200);
uart_init(PICOPROBE_UART_INTERFACE, PICOPROBE_UART_BAUDRATE);
}
#define MAX_UART_PKT 64
@ -17,8 +17,8 @@ void cdc_task(void) {
// Consume uart fifo regardless even if not connected
uint rx_len = 0;
while(uart_is_readable(uart1) && (rx_len < MAX_UART_PKT)) {
rx_buf[rx_len++] = uart_getc(uart1);
while(uart_is_readable(PICOPROBE_UART_INTERFACE) && (rx_len < MAX_UART_PKT)) {
rx_buf[rx_len++] = uart_getc(PICOPROBE_UART_INTERFACE);
}
if (tud_cdc_connected()) {
@ -33,12 +33,12 @@ void cdc_task(void) {
if (tud_cdc_available()) {
// Is there any data from the host for us to tx
uint tx_len = tud_cdc_read(tx_buf, sizeof(tx_buf));
uart_write_blocking(uart1, tx_buf, tx_len);
uart_write_blocking(PICOPROBE_UART_INTERFACE, tx_buf, tx_len);
}
}
}
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* line_coding) {
picoprobe_info("New baud rate %d\n", line_coding->bit_rate);
uart_init(uart1, line_coding->bit_rate);
}
uart_init(PICOPROBE_UART_INTERFACE, line_coding->bit_rate);
}

View File

@ -30,6 +30,8 @@
// UART config
#define PICOPROBE_UART_TX 4
#define PICOPROBE_UART_RX 5
#define PICOPROBE_UART_INTERFACE uart1
#define PICOPROBE_UART_BAUDRATE 115200
// LED config
#ifndef PICOPROBE_LED
@ -42,6 +44,4 @@
#define PICOPROBE_LED PICO_DEFAULT_LED_PIN
#endif
#endif
#endif