summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--serial-led/CMakeLists.txt2
-rw-r--r--serial-led/serial-led.c8
-rw-r--r--usb-led/CMakeLists.txt6
-rw-r--r--usb-led/usb-led.c16
4 files changed, 17 insertions, 15 deletions
diff --git a/serial-led/CMakeLists.txt b/serial-led/CMakeLists.txt
index 8ebe9a7..db5b776 100644
--- a/serial-led/CMakeLists.txt
+++ b/serial-led/CMakeLists.txt
@@ -33,5 +33,5 @@ add_executable(serial-led
serial-led.c
)
-target_link_libraries(serial-led pico_stdlib)
+target_link_libraries(serial-led pico_stdlib pico_stdio_uart)
pico_add_extra_outputs(serial-led)
diff --git a/serial-led/serial-led.c b/serial-led/serial-led.c
index 8f10f9c..1ade02e 100644
--- a/serial-led/serial-led.c
+++ b/serial-led/serial-led.c
@@ -30,16 +30,18 @@ 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_uart_init_full(uart0, 9600, PICO_DEFAULT_UART_TX_PIN, PICO_DEFAULT_UART_RX_PIN);
+ stdio_set_translate_crlf(&stdio_uart, true);
for(;;) {
int cmd = getchar_timeout_us(100000);
diff --git a/usb-led/CMakeLists.txt b/usb-led/CMakeLists.txt
index 51a197b..e1d36ac 100644
--- a/usb-led/CMakeLists.txt
+++ b/usb-led/CMakeLists.txt
@@ -33,9 +33,5 @@ add_executable(usb-led
usb-led.c
)
-target_link_libraries(usb-led pico_stdlib)
-
-pico_enable_stdio_usb(usb-led 1)
-pico_enable_stdio_uart(usb-led 0)
-
+target_link_libraries(usb-led pico_stdlib pico_stdio_usb)
pico_add_extra_outputs(usb-led)
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);
+ }
}
}
}