Browse Source

pico w onboard led

Thomas Buck 1 year 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
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
74
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
75
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/fatfs)
75
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/fatfs)
76
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/st7789/src)
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
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/decoder)
78
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/decoder)
78
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/fonts)
79
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/fonts)
79
 
80
 
98
     hardware_spi
99
     hardware_spi
99
     pico_btstack_ble
100
     pico_btstack_ble
100
     pico_btstack_cyw43
101
     pico_btstack_cyw43
101
-    pico_cyw43_arch_none
102
+    pico_cyw43_arch_threadsafe_background
102
 )
103
 )
103
 
104
 
104
 target_compile_definitions(gadget PUBLIC
105
 target_compile_definitions(gadget PUBLIC
105
     RUNNING_AS_CLIENT=1
106
     RUNNING_AS_CLIENT=1
107
+    CYW43_LWIP=0
106
 )
108
 )
107
 
109
 
108
 # fix for Errata RP2040-E5 (the fix requires use of GPIO 15)
110
 # fix for Errata RP2040-E5 (the fix requires use of GPIO 15)

+ 1
- 3
README.md View File

2
 
2
 
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).
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
 ## Quick Start
7
 ## Quick Start
10
 
8
 

+ 1
- 1
debug.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 set -euo pipefail
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
 echo -n Waiting for serial port to appear
6
 echo -n Waiting for serial port to appear
7
 until [ -e $SERIAL ]
7
 until [ -e $SERIAL ]

+ 1
- 1
flash.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 set -euo pipefail
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
 DISK=/dev/disk/by-label/RPI-RP2
5
 DISK=/dev/disk/by-label/RPI-RP2
6
 MOUNT=/mnt/tmp
6
 MOUNT=/mnt/tmp
7
 
7
 

+ 7
- 2
src/main.c View File

17
  */
17
  */
18
 
18
 
19
 #include "pico/stdlib.h"
19
 #include "pico/stdlib.h"
20
+#include "pico/cyw43_arch.h"
20
 #include "hardware/watchdog.h"
21
 #include "hardware/watchdog.h"
21
 
22
 
22
 #include "config.h"
23
 #include "config.h"
38
         debug("reset by watchdog");
39
         debug("reset by watchdog");
39
     }
40
     }
40
 
41
 
42
+    if (cyw43_arch_init()) {
43
+        debug("cyw43_arch failed");
44
+    }
45
+
41
     debug("fat_disk_init");
46
     debug("fat_disk_init");
42
     fat_disk_init();
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
     debug("init done");
52
     debug("init done");
48
 
53
 

+ 12
- 6
src/util.c View File

21
 #include "pico/bootrom.h"
21
 #include "pico/bootrom.h"
22
 #include "hardware/watchdog.h"
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
 #include "config.h"
28
 #include "config.h"
25
 #include "log.h"
29
 #include "log.h"
26
 #include "util.h"
30
 #include "util.h"
27
 
31
 
28
 #define HEARTBEAT_INTERVAL_MS 500
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
 void heartbeat_init(void) {
34
 void heartbeat_init(void) {
35
 #ifdef PICO_DEFAULT_LED_PIN
35
 #ifdef PICO_DEFAULT_LED_PIN
36
     gpio_init(PICO_DEFAULT_LED_PIN);
36
     gpio_init(PICO_DEFAULT_LED_PIN);
40
 }
40
 }
41
 
41
 
42
 void heartbeat_run(void) {
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
     uint32_t now = to_ms_since_boot(get_absolute_time());
45
     uint32_t now = to_ms_since_boot(get_absolute_time());
45
     if (now >= (last_heartbeat + HEARTBEAT_INTERVAL_MS)) {
46
     if (now >= (last_heartbeat + HEARTBEAT_INTERVAL_MS)) {
46
         last_heartbeat = now;
47
         last_heartbeat = now;
48
+#ifdef PICO_DEFAULT_LED_PIN
47
         gpio_xor_mask(1 << PICO_DEFAULT_LED_PIN);
49
         gpio_xor_mask(1 << PICO_DEFAULT_LED_PIN);
48
-    }
49
 #endif // PICO_DEFAULT_LED_PIN
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
 bool str_startswith(const char *str, const char *start) {
58
 bool str_startswith(const char *str, const char *start) {

Loading…
Cancel
Save