Thomas Buck 8 mesi fa
parent
commit
db196340c9
6 ha cambiato i file con 106 aggiunte e 4 eliminazioni
  1. 35
    0
      debug.sh
  2. 45
    0
      flash.sh
  3. 1
    1
      src/buttons.c
  4. 6
    2
      src/led.c
  5. 17
    1
      src/main.c
  6. 2
    0
      src/sequence.c

+ 35
- 0
debug.sh Vedi File

@@ -0,0 +1,35 @@
1
+#!/bin/bash
2
+
3
+# ----------------------------------------------------------------------------
4
+# Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
5
+#
6
+# This program is free software: you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License as published by
8
+# the Free Software Foundation, either version 3 of the License, or
9
+# (at your option) any later version.
10
+#
11
+# This program is distributed in the hope that it will be useful,
12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+# GNU General Public License for more details.
15
+#
16
+# See <http://www.gnu.org/licenses/>.
17
+# ----------------------------------------------------------------------------
18
+
19
+set -euo pipefail
20
+
21
+SERIAL=/dev/serial/by-id/usb-Raspberry_Pi_Pico_*
22
+
23
+echo -n Waiting for serial port to appear
24
+until [ -e $SERIAL ]
25
+do
26
+    echo -n .
27
+    sleep 1
28
+done
29
+echo
30
+
31
+echo Opening picocom terminal
32
+echo "[C-a] [C-x] to exit"
33
+echo
34
+
35
+picocom -q --omap crcrlf --imap lfcrlf $SERIAL

+ 45
- 0
flash.sh Vedi File

@@ -0,0 +1,45 @@
1
+#!/bin/bash
2
+
3
+# ----------------------------------------------------------------------------
4
+# Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
5
+#
6
+# This program is free software: you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License as published by
8
+# the Free Software Foundation, either version 3 of the License, or
9
+# (at your option) any later version.
10
+#
11
+# This program is distributed in the hope that it will be useful,
12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+# GNU General Public License for more details.
15
+#
16
+# See <http://www.gnu.org/licenses/>.
17
+# ----------------------------------------------------------------------------
18
+
19
+set -euo pipefail
20
+
21
+SERIAL=/dev/serial/by-id/usb-Raspberry_Pi_Pico_*
22
+DISK=/dev/disk/by-label/RPI-RP2
23
+MOUNT=/mnt/tmp
24
+
25
+if [ ! -e $DISK ]
26
+then
27
+    echo Resetting Raspberry Pi Pico
28
+    echo -n -e "\\x18" > $SERIAL
29
+fi
30
+
31
+echo -n Waiting for disk to appear
32
+until [ -e $DISK ]
33
+do
34
+    echo -n .
35
+    sleep 1
36
+done
37
+echo
38
+
39
+echo Mounting bootloader disk
40
+sudo mount $DISK $MOUNT
41
+
42
+echo Copying binary
43
+sudo cp $1 $MOUNT
44
+
45
+echo Done

+ 1
- 1
src/buttons.c Vedi File

@@ -66,7 +66,7 @@ void buttons_run(void) {
66 66
 
67 67
         if ((now - buttons[i].last_time) > DEBOUNCE_DELAY_MS) {
68 68
             if (state != buttons[i].current_state) {
69
-                printf("btn %d now %s\n", i, state ? "pressed" : "released");
69
+                //printf("btn %d now %s\n", i, state ? "pressed" : "released");
70 70
 
71 71
                 buttons[i].current_state = state;
72 72
                 if (callback) {

+ 6
- 2
src/led.c Vedi File

@@ -16,6 +16,8 @@
16 16
  * See <http://www.gnu.org/licenses/>.
17 17
  */
18 18
 
19
+#include <stdio.h>
20
+#include <inttypes.h>
19 21
 #include "pico/stdlib.h"
20 22
 
21 23
 #include "sequence.h"
@@ -42,10 +44,12 @@ void led_init(void) {
42 44
 
43 45
 void led_set(uint32_t i, bool v) {
44 46
     i %= LED_COUNT;
45
-    gpio_put(i, v);
47
+    gpio_put(led_gpio_num[i], v);
48
+    //printf("led %"PRIu32" now %d\n", i, v);
46 49
 }
47 50
 
48 51
 void ch_set(uint32_t i, bool v) {
49 52
     i %= NUM_CHANNELS;
50
-    gpio_put(i, v);
53
+    gpio_put(ch_gpio_num[i], v);
54
+    //printf("ch %"PRIu32" now %d\n", i, v);
51 55
 }

+ 17
- 1
src/main.c Vedi File

@@ -18,6 +18,7 @@
18 18
 
19 19
 #include <stdio.h>
20 20
 #include "pico/stdlib.h"
21
+#include "pico/bootrom.h"
21 22
 #include "hardware/watchdog.h"
22 23
 
23 24
 #include "adc.h"
@@ -32,8 +33,16 @@
32 33
 
33 34
 #define WATCHDOG_PERIOD_MS 100
34 35
 
36
+static void reset_to_bootloader(void) {
37
+#ifdef PICO_DEFAULT_LED_PIN
38
+    reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
39
+#else // ! PICO_DEFAULT_LED_PIN
40
+    reset_usb_boot(0, 0);
41
+#endif // PICO_DEFAULT_LED_PIN
42
+}
43
+
35 44
 int main(void) {
36
-    watchdog_enable(WATCHDOG_PERIOD_MS, 1);
45
+    //watchdog_enable(WATCHDOG_PERIOD_MS, 1);
37 46
     stdio_init_all();
38 47
     bat_init();
39 48
     buttons_init();
@@ -59,6 +68,13 @@ int main(void) {
59 68
             ui_encoder(epos - last_epos);
60 69
             last_epos = epos;
61 70
         }
71
+
72
+        int c = getchar_timeout_us(0);
73
+        if (c == 0x18) {
74
+            reset_to_bootloader();
75
+        } else if (c != PICO_ERROR_TIMEOUT) {
76
+            printf("%c", c);
77
+        }
62 78
     }
63 79
 
64 80
     return 0;

+ 2
- 0
src/sequence.c Vedi File

@@ -172,6 +172,7 @@ void sequence_handle_button_drummachine(enum buttons btn) {
172 172
 }
173 173
 
174 174
 void sequence_run(void) {
175
+    /*
175 176
     uint32_t now = to_ms_since_boot(get_absolute_time());
176 177
 
177 178
     if ((last_t + ms_per_beat) >= now) {
@@ -190,4 +191,5 @@ void sequence_run(void) {
190 191
         last_t = now;
191 192
         last_i = i;
192 193
     }
194
+    */
193 195
 }

Loading…
Annulla
Salva