diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 45 |
1 files changed, 39 insertions, 6 deletions
@@ -1,3 +1,9 @@ +/* main.c - Main entry point and event loop for sbc-harness + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-Licence-Identifier: AGPL-3.0-or-later + */ + /* pico-sdk */ #include <stdio.h> #include "pico/stdlib.h" @@ -7,8 +13,26 @@ #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(); @@ -23,14 +47,23 @@ int main() { 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(); - usb_keyboard_task(); - if (usb_keyboard_is_flushed()) { - char *msg = "Hello world!\n"; - for (size_t i = 0; i < strlen(msg); i++) - usb_keyboard_send_char(msg[i]); - } + coroutine_task(); } } |