Skip to content

Commit

Permalink
console: Extend for bleuart
Browse files Browse the repository at this point in the history
  • Loading branch information
rymanluk committed Aug 5, 2024
1 parent 1430ea6 commit 53d3410
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions hw/usb/tinyusb/cdc_console/src/cdc_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
static struct os_event rx_receive_event;
static struct os_event tx_flush_event;
static bool connected;
static console_ble_tx_cb console_compat_ble_tx_cb;

static const struct cdc_callbacks console_cdc_callback;

Expand Down Expand Up @@ -65,9 +66,18 @@ console_out_nolock(int c)

cdc_schedule_tx_flush();

if (console_compat_ble_tx_cb) {
console_compat_ble_tx_cb(c);
}
return c;
}

int console_ble_uart_init(console_ble_tx_cb tx_cb)
{
console_compat_ble_tx_cb = tx_cb;
return 0;
}

void
console_rx_restart(void)
{
Expand Down
3 changes: 3 additions & 0 deletions sys/console/full/include/console/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct console_input {
char line[MYNEWT_VAL(CONSOLE_MAX_INPUT_LEN)];
};

//typedef int (*console_ble_tx_cb)(const char *, int);
typedef int (*console_ble_tx_cb)(int c);
typedef void (*console_rx_cb)(void);
typedef int (*console_append_char_cb)(char *line, uint8_t byte);
typedef void (*completion_cb)(char *str, console_append_char_cb cb);
Expand All @@ -55,6 +57,7 @@ void console_deinit(void);
*/
void console_reinit(void);
int console_init(console_rx_cb rx_cb);
int console_ble_uart_init(console_ble_tx_cb tx_cb);
int console_is_init(void);
void console_write(const char *str, int cnt);
#if MYNEWT_VAL(CONSOLE_COMPAT)
Expand Down
12 changes: 12 additions & 0 deletions sys/console/full/src/uart_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct console_ring {
uint8_t *buf;
};

static console_ble_tx_cb console_compat_ble_tx_cb;

static struct uart_dev *uart_dev;
static struct console_ring cr_tx;
static uint8_t cr_tx_buf[MYNEWT_VAL(CONSOLE_UART_TX_BUF_SIZE)];
Expand Down Expand Up @@ -169,6 +171,9 @@ console_out_nolock(int c)
write_char_cb(uart_dev, c);
uart_start_tx(uart_dev);

if (console_compat_ble_tx_cb) {
console_compat_ble_tx_cb(c);
}
return c;
}

Expand Down Expand Up @@ -279,6 +284,12 @@ uart_console_deinit(void)
return 0;
}

int console_ble_uart_init(console_ble_tx_cb tx_cb)
{
console_compat_ble_tx_cb = tx_cb;
return 0;
}

int
uart_console_init(void)
{
Expand Down Expand Up @@ -312,4 +323,5 @@ uart_console_init(void)
}
return 0;
}

#endif /* MYNEWT_VAL(CONSOLE_UART) */

0 comments on commit 53d3410

Please sign in to comment.