Skip to content

Commit

Permalink
Improve USB serial support
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 6, 2024
1 parent d5789b5 commit 24b7338
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
22 changes: 12 additions & 10 deletions examples/rpi_pico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,22 @@ function(add_example name)
)
if(ZENOH_USB_UART)
pico_enable_stdio_uart(${name} 1)
pico_enable_stdio_usb(${name} 0)
else()
pico_enable_stdio_uart(${name} 0)
pico_enable_stdio_usb(${name} 1)
endif()
pico_add_extra_outputs(${name})
endfunction()

add_example(z_get)
#add_example(z_get)
add_example(z_pub)
add_example(z_pub_st)
add_example(z_pub_thr)
add_example(z_pull)
add_example(z_put)
add_example(z_queryable)
add_example(z_scout)
add_example(z_sub)
add_example(z_sub_st)
add_example(z_sub_thr)
#add_example(z_pub_st)
#add_example(z_pub_thr)
#add_example(z_pull)
#add_example(z_put)
#add_example(z_queryable)
#add_example(z_scout)
#add_example(z_sub)
#add_example(z_sub_st)
#add_example(z_sub_thr)
2 changes: 1 addition & 1 deletion examples/rpi_pico/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void print_ip_address() {

void main_task(void *params) {
(void)params;
vTaskDelay(pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(3000));
#if WIFI_SUPPORT_ENABLED
if (cyw43_arch_init()) {
printf("Failed to initialise\n");
Expand Down
10 changes: 9 additions & 1 deletion src/system/rpi_pico/usb_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
//

#include "zenoh-pico/system/platform.h"
#include "zenoh-pico/utils/logging.h"

#if Z_FEATURE_LINK_SERIAL == 1 && Z_FEATURE_LINK_SERIAL_USB == 1

#include "pico/unique_id.h"
#include "tusb.h"

// ===== USB descriptors =====
// Copied from
// https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c
//
#ifndef USBD_VID
#define USBD_VID (0x2E8A) // Raspberry Pi
#endif
Expand Down Expand Up @@ -180,14 +184,18 @@ static void *_z_usb_uart_task_proc(void *) {
_z_mutex_unlock(&_z_usb_uart_mutex);
z_sleep_ms(1);
}
return NULL;
}

void _z_usb_uart_init() {
tud_init(BOARD_TUD_RHPORT);
_z_mutex_init(&_z_usb_uart_mutex);
_z_usb_uart_task_run = true;
_z_task_init(&_z_usb_uart_task, NULL, &_z_usb_uart_task_proc, NULL);
z_sleep_s(10);
_Z_DEBUG("whating for host...");
while (!tud_cdc_connected()) {
z_sleep_ms(100);
}
}

void _z_usb_uart_deinit() {
Expand Down

0 comments on commit 24b7338

Please sign in to comment.