summaryrefslogtreecommitdiff
path: root/usb-led/usb-led.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2022-10-06 22:43:54 +0200
committerChristian Pointner <equinox@spreadspace.org>2022-10-06 22:43:54 +0200
commit79d19fafff8d25297bbe8d8c4856ca088afbe7fd (patch)
tree3840eb55741c53824fec9a4e28d568af45bc330b /usb-led/usb-led.c
parentadd program target to makefiles (diff)
make *-led example a little bit more explicitHEADmaster
Diffstat (limited to 'usb-led/usb-led.c')
-rw-r--r--usb-led/usb-led.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/usb-led/usb-led.c b/usb-led/usb-led.c
index 8f10f9c..faa3d1b 100644
--- a/usb-led/usb-led.c
+++ b/usb-led/usb-led.c
@@ -30,21 +30,25 @@ void handle_cmd(uint8_t cmd)
switch(cmd) {
case '0': gpio_put(LED_PIN, 0); break;
case '1': gpio_put(LED_PIN, 1); break;
- default: printf("error\r\n"); return;
+ case 't': gpio_xor_mask(1<<LED_PIN); break;
+ default: printf("error\n"); return;
}
- printf("ok\r\n");
+ printf("ok\n");
}
int main()
{
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
- stdio_init_all();
+ stdio_usb_init();
+ stdio_set_translate_crlf(&stdio_usb, true);
for(;;) {
- int cmd = getchar_timeout_us(100000);
- if(cmd != PICO_ERROR_TIMEOUT) {
- handle_cmd(cmd);
+ if(stdio_usb_connected()) {
+ int cmd = getchar_timeout_us(100000);
+ if(cmd != PICO_ERROR_TIMEOUT) {
+ handle_cmd(cmd);
+ }
}
}
}