Browse Source

pico w onboard led

Thomas Buck 10 months ago
parent
commit
a9bf35e24b
6 changed files with 25 additions and 14 deletions
  1. 3
    1
      CMakeLists.txt
  2. 1
    3
      README.md
  3. 1
    1
      debug.sh
  4. 1
    1
      flash.sh
  5. 7
    2
      src/main.c
  6. 12
    6
      src/util.c

+ 3
- 1
CMakeLists.txt View File

@@ -74,6 +74,7 @@ target_sources(gadget PUBLIC
74 74
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
75 75
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/fatfs)
76 76
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/st7789/src)
77
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/st7789/interface)
77 78
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/decoder)
78 79
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/fonts)
79 80
 
@@ -98,11 +99,12 @@ target_link_libraries(gadget
98 99
     hardware_spi
99 100
     pico_btstack_ble
100 101
     pico_btstack_cyw43
101
-    pico_cyw43_arch_none
102
+    pico_cyw43_arch_threadsafe_background
102 103
 )
103 104
 
104 105
 target_compile_definitions(gadget PUBLIC
105 106
     RUNNING_AS_CLIENT=1
107
+    CYW43_LWIP=0
106 108
 )
107 109
 
108 110
 # fix for Errata RP2040-E5 (the fix requires use of GPIO 15)

+ 1
- 3
README.md View File

@@ -2,9 +2,7 @@
2 2
 
3 3
 For use with Raspberry Pi Pico W boards with the [Waveshare Pico LCD 1.3](https://www.waveshare.com/wiki/Pico-LCD-1.3) and the [Pimoroni Pico Lipo Shim](https://shop.pimoroni.com/products/pico-lipo-shim).
4 4
 
5
-Adapted from the [tinyusb-cdc-example](https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/src/main.c).
6
-
7
-TODO other examples used
5
+Adapted from the [tinyusb-cdc-example](https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/src/main.c), [standalone client example](https://github.com/raspberrypi/pico-examples/blob/master/pico_w/bt/standalone/client.c) and my [Trackball firmware](https://git.xythobuz.de/thomas/Trackball).
8 6
 
9 7
 ## Quick Start
10 8
 

+ 1
- 1
debug.sh View File

@@ -1,7 +1,7 @@
1 1
 #!/bin/bash
2 2
 set -euo pipefail
3 3
 
4
-SERIAL=/dev/serial/by-id/usb-xythobuz_Trackball_*
4
+SERIAL=/dev/serial/by-id/usb-xythobuz_VolcanoRC_*
5 5
 
6 6
 echo -n Waiting for serial port to appear
7 7
 until [ -e $SERIAL ]

+ 1
- 1
flash.sh View File

@@ -1,7 +1,7 @@
1 1
 #!/bin/bash
2 2
 set -euo pipefail
3 3
 
4
-SERIAL=/dev/serial/by-id/usb-xythobuz_Trackball_*
4
+SERIAL=/dev/serial/by-id/usb-xythobuz_VolcanoRC_*
5 5
 DISK=/dev/disk/by-label/RPI-RP2
6 6
 MOUNT=/mnt/tmp
7 7
 

+ 7
- 2
src/main.c View File

@@ -17,6 +17,7 @@
17 17
  */
18 18
 
19 19
 #include "pico/stdlib.h"
20
+#include "pico/cyw43_arch.h"
20 21
 #include "hardware/watchdog.h"
21 22
 
22 23
 #include "config.h"
@@ -38,11 +39,15 @@ int main(void) {
38 39
         debug("reset by watchdog");
39 40
     }
40 41
 
42
+    if (cyw43_arch_init()) {
43
+        debug("cyw43_arch failed");
44
+    }
45
+
41 46
     debug("fat_disk_init");
42 47
     fat_disk_init();
43 48
 
44
-    // trigger after 500ms
45
-    watchdog_enable(500, 1);
49
+    // trigger after 1000ms
50
+    watchdog_enable(1000, 1);
46 51
 
47 52
     debug("init done");
48 53
 

+ 12
- 6
src/util.c View File

@@ -21,16 +21,16 @@
21 21
 #include "pico/bootrom.h"
22 22
 #include "hardware/watchdog.h"
23 23
 
24
+#ifdef CYW43_WL_GPIO_LED_PIN
25
+#include "pico/cyw43_arch.h"
26
+#endif // CYW43_WL_GPIO_LED_PIN
27
+
24 28
 #include "config.h"
25 29
 #include "log.h"
26 30
 #include "util.h"
27 31
 
28 32
 #define HEARTBEAT_INTERVAL_MS 500
29 33
 
30
-#ifdef PICO_DEFAULT_LED_PIN
31
-static uint32_t last_heartbeat = 0;
32
-#endif // PICO_DEFAULT_LED_PIN
33
-
34 34
 void heartbeat_init(void) {
35 35
 #ifdef PICO_DEFAULT_LED_PIN
36 36
     gpio_init(PICO_DEFAULT_LED_PIN);
@@ -40,13 +40,19 @@ void heartbeat_init(void) {
40 40
 }
41 41
 
42 42
 void heartbeat_run(void) {
43
-#ifdef PICO_DEFAULT_LED_PIN
43
+#if defined(PICO_DEFAULT_LED_PIN) || defined(CYW43_WL_GPIO_LED_PIN)
44
+    static uint32_t last_heartbeat = 0;
44 45
     uint32_t now = to_ms_since_boot(get_absolute_time());
45 46
     if (now >= (last_heartbeat + HEARTBEAT_INTERVAL_MS)) {
46 47
         last_heartbeat = now;
48
+#ifdef PICO_DEFAULT_LED_PIN
47 49
         gpio_xor_mask(1 << PICO_DEFAULT_LED_PIN);
48
-    }
49 50
 #endif // PICO_DEFAULT_LED_PIN
51
+#ifdef CYW43_WL_GPIO_LED_PIN
52
+        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, !cyw43_arch_gpio_get(CYW43_WL_GPIO_LED_PIN));
53
+#endif // CYW43_WL_GPIO_LED_PIN
54
+    }
55
+#endif // defined(PICO_DEFAULT_LED_PIN) || defined(CYW43_WL_GPIO_LED_PIN)
50 56
 }
51 57
 
52 58
 bool str_startswith(const char *str, const char *start) {

Loading…
Cancel
Save