diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-18 11:18:02 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-18 11:18:02 -0600 |
commit | 4469398272d78adb81968178276180f16cc8e647 (patch) | |
tree | c360226922c543a5d2fd985ca1e078bb8a603f72 /main.c | |
parent | 05ce08877ff420ca9fc77599dd947ff610d02cb0 (diff) |
fixes for arm?
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 60 |
1 files changed, 20 insertions, 40 deletions
@@ -4,66 +4,46 @@ * SPDX-Licence-Identifier: AGPL-3.0-or-later */ +/* newlib */ +#include <string.h> /* for strlen() */ + /* pico-sdk */ -#include <stdio.h> #include "pico/stdlib.h" -/* TinyUSB */ -#include "bsp/board_api.h" -#include "tusb.h" - /* local */ #include "coroutine.h" +#include "usb_common.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) { +COROUTINE hello_world_cr(void *_chan) { const char *msg = "Hello world!\n"; - hello_world_stack_t *stack = _stack; - + usb_keyboard_chan_t *chan = _chan; cr_begin(); - for (;;) { - cr_chan_req(stack->chan, NULL, msg[stack->i]); - stack->i = (stack->i + 1) % strlen(msg); + + for (size_t i = 0;; i = (i+1) % strlen(msg)) { + cr_chan_req(chan, NULL, msg[i]); } + cr_end(); } int main() { - /* pico-sdk initialization */ + /* initialization */ stdio_uart_init(); - gpio_init(PICO_DEFAULT_LED_PIN); - gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); + //gpio_init(PICO_DEFAULT_LED_PIN); + //gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); + usb_common_earlyinit(); usb_keyboard_init(); - - /* TinyUSB initialization */ - board_init(); - tud_init(BOARD_TUD_RHPORT); - if (board_init_after_tusb) - board_init_after_tusb(); - - /* coroutine initialization */ + usb_common_lateinit(); coroutine_init(); + /* set up coroutines */ + coroutine_add(usb_common_cr, NULL); 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); + coroutine_add(usb_keyboard_cr, &keyboard_chan); + coroutine_add(hello_world_cr, &keyboard_chan); /* Event loop. */ - for (;;) { - tud_task(); - coroutine_task(); - } + coroutine_main(); } |