summaryrefslogtreecommitdiff
path: root/cmd/sbc_harness/main.c
blob: 31ce30b8c0ebdb0ebdbf3b782212c9fb0f73fa6e (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
/* 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
 */

#include <string.h> /* for strlen() */
#include "pico/stdlib.h"

#include <libcr/coroutine.h>
#include <libusb/usb_common.h>

#include "usb_keyboard.h"

COROUTINE hello_world_cr(void *_chan) {
	const char *msg = "Hello world!\n";
	usb_keyboard_rpc_t *chan = _chan;
	cr_begin();

	for (size_t i = 0;; i = (i+1) % strlen(msg)) {
		int result;
		cr_rpc_req(chan, &result, (uint32_t)msg[i]);
	}

	cr_end();
}

int main() {
	/* initialization */
	stdio_uart_init();
	//gpio_init(PICO_DEFAULT_LED_PIN);
	//gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);

	usb_common_earlyinit();
	usb_keyboard_init();
	usb_common_lateinit();

	/* set up coroutines */
	coroutine_add(usb_common_cr, NULL);
	usb_keyboard_rpc_t keyboard_chan = {0};
	coroutine_add(usb_keyboard_cr, &keyboard_chan);
	coroutine_add(hello_world_cr, &keyboard_chan);

	/* Event loop. */
	coroutine_main();
}