Skip to content

Commit

Permalink
Move selection of UART interface and baudrate to picoprobe_config.h (r…
Browse files Browse the repository at this point in the history
…aspberrypi#7)

Co-authored-by: Liam Fraser <[email protected]>
  • Loading branch information
lurch and liamfraser authored Feb 3, 2021
1 parent 0fe6a09 commit c29510f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/cdc_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions src/picoprobe_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,6 +44,4 @@
#define PICOPROBE_LED PICO_DEFAULT_LED_PIN
#endif

#endif

#endif

0 comments on commit c29510f

Please sign in to comment.