/** * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause */ #include #include #include #include #define LED_BLINK_DELAY_MS 1000 void recv_cb(void *args); int main(void) { stdio_init_all(); gpio_init(PICO_DEFAULT_LED_PIN); gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); stdio_set_chars_available_callback(recv_cb, NULL); uint32_t start_ms = 0; bool led_state = false; // main run loop while(true) { if(us_to_ms(time_us_64()) - start_ms > LED_BLINK_DELAY_MS) { gpio_put(PICO_DEFAULT_LED_PIN, led_state); led_state = !led_state; start_ms += LED_BLINK_DELAY_MS; printf("Connected to CDC 1\n"); fflush(stdout); } } } void recv_cb(void *args __attribute__((unused))) { while(true) { int c = stdio_getchar_timeout_us(0); if(c == PICO_ERROR_TIMEOUT) { break; } if(putchar(c) == EOF) { break; } } }