/* main.c - Main entry point and event loop for sbc-harness * * Copyright (C) 2024 Luke T. Shumaker * SPDX-Licence-Identifier: AGPL-3.0-or-later */ /* pico-sdk */ #include #include "pico/stdlib.h" /* TinyUSB */ #include "bsp/board_api.h" #include "tusb.h" /* local */ #include "coroutine.h" #include "usb_keyboard.h" typedef struct { usb_keyboard_chan_t *chan; size_t i; } hello_world_stack_t; void hello_world_cr(void *_stack) { const char *msg = "Hello world!\n"; hello_world_stack_t *stack = _stack; cr_begin(); for (;;) { cr_chan_req(stack->chan, NULL, msg[stack->i]); stack->i = (stack->i + 1) % strlen(msg); } cr_end(); } int main() { /* pico-sdk initialization */ stdio_uart_init(); gpio_init(PICO_DEFAULT_LED_PIN); gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); usb_keyboard_init(); /* TinyUSB initialization */ board_init(); tud_init(BOARD_TUD_RHPORT); if (board_init_after_tusb) board_init_after_tusb(); /* coroutine initialization */ coroutine_init(); usb_keyboard_chan_t keyboard_chan; usb_keyboard_init(); usb_keyboard_stack_t usb_keyboard_stack = {0}; usb_keyboard_stack.chan = &keyboard_chan; coroutine_add(usb_keyboard_cr, &usb_keyboard_stack); hello_world_stack_t hello_world_stack = {0}; hello_world_stack.chan = &keyboard_chan; coroutine_add(hello_world_cr, &hello_world_stack); /* Event loop. */ for (;;) { tud_task(); coroutine_task(); } }