blob: fef917fd26bac5633f00eb45a5c5c49954ab4452 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/* 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"
/* 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();
}
}
|