Browse Source

more bootloader stuff

Thomas Buck 11 months ago
parent
commit
a4b5c89957
6 changed files with 91 additions and 43 deletions
  1. 4
    0
      CMakeLists.txt
  2. 1
    1
      include/config.h
  3. 3
    1
      include/log.h
  4. 1
    1
      picowota
  5. 2
    31
      src/log.c
  6. 80
    9
      src/ota_shim.c

+ 4
- 0
CMakeLists.txt View File

25
 )
25
 )
26
 
26
 
27
 # build lwip httpd fs
27
 # build lwip httpd fs
28
+# TODO should use C version instead of Perl script, for
29
+# TODO added file compression. but how to compile it?
28
 set(MAKE_FS_DATA_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/pico-sdk/lib/lwip/src/apps/http/makefsdata/makefsdata)
30
 set(MAKE_FS_DATA_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/pico-sdk/lib/lwip/src/apps/http/makefsdata/makefsdata)
29
 execute_process(
31
 execute_process(
30
     COMMAND perl ${MAKE_FS_DATA_SCRIPT}
32
     COMMAND perl ${MAKE_FS_DATA_SCRIPT}
209
     ${CMAKE_CURRENT_SOURCE_DIR}/src/text.c
211
     ${CMAKE_CURRENT_SOURCE_DIR}/src/text.c
210
     ${CMAKE_CURRENT_SOURCE_DIR}/src/ota_shim.c
212
     ${CMAKE_CURRENT_SOURCE_DIR}/src/ota_shim.c
211
     ${CMAKE_CURRENT_SOURCE_DIR}/src/workflow_default.c
213
     ${CMAKE_CURRENT_SOURCE_DIR}/src/workflow_default.c
214
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/buttons.c
215
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/util.c
212
 
216
 
213
     ${CMAKE_CURRENT_SOURCE_DIR}/st7789/src/driver_st7789.c
217
     ${CMAKE_CURRENT_SOURCE_DIR}/st7789/src/driver_st7789.c
214
 
218
 

+ 1
- 1
include/config.h View File

20
 #define __CONFIG_H__
20
 #define __CONFIG_H__
21
 
21
 
22
 #define APP_VERSION_MAJOR 0
22
 #define APP_VERSION_MAJOR 0
23
-#define APP_VERSION_MINOR 1
23
+#define APP_VERSION_MINOR 2
24
 
24
 
25
 #define MENU_PREFER_VOLCANO
25
 #define MENU_PREFER_VOLCANO
26
 //#define MENU_PREFER_CRAFTY
26
 //#define MENU_PREFER_CRAFTY

+ 3
- 1
include/log.h View File

48
 void log_dump_to_usb(void);
48
 void log_dump_to_usb(void);
49
 void log_dump_to_uart(void);
49
 void log_dump_to_uart(void);
50
 void log_dump_to_disk(void);
50
 void log_dump_to_disk(void);
51
-void log_dump_to_lcd(void);
52
 
51
 
53
 void debug_handle_input(const void *buff, size_t len);
52
 void debug_handle_input(const void *buff, size_t len);
54
 
53
 
54
+#include "ring.h"
55
+struct ring_buffer *log_get(void);
56
+
55
 #endif // __LOG_H__
57
 #endif // __LOG_H__

+ 1
- 1
picowota

1
-Subproject commit 4abdeee20f2dd8f813f322b61ce1afee7b502d12
1
+Subproject commit dd98bf620976a2df113cf03eeb2483a9e68c1d7d

+ 2
- 31
src/log.c View File

24
 
24
 
25
 #include "config.h"
25
 #include "config.h"
26
 #include "main.h"
26
 #include "main.h"
27
-#include "lcd.h"
28
-#include "textbox.h"
29
 #include "usb_cdc.h"
27
 #include "usb_cdc.h"
30
 #include "serial.h"
28
 #include "serial.h"
31
 #include "ring.h"
29
 #include "ring.h"
36
 
34
 
37
 static uint8_t line_buff[256] = {0};
35
 static uint8_t line_buff[256] = {0};
38
 static volatile bool got_input = false;
36
 static volatile bool got_input = false;
39
-static int16_t lcd_off = 0;
40
 
37
 
41
 #ifndef PICOWOTA
38
 #ifndef PICOWOTA
42
 static FIL log_file_fat;
39
 static FIL log_file_fat;
46
     rb_add(&log, buff, len);
43
     rb_add(&log, buff, len);
47
 }
44
 }
48
 
45
 
49
-static void lcd_write(const void *buf, size_t len) {
50
-    char tmp[len + 1];
51
-    memcpy(tmp, buf, len);
52
-    tmp[len] = '\0';
53
-    lcd_off = text_box(tmp, false,
54
-                       "fixed_10x20",
55
-                       0, LCD_WIDTH,
56
-                       lcd_off, LCD_HEIGHT - lcd_off,
57
-                       0);
58
-}
59
-
60
-void log_dump_to_lcd(void) {
61
-    static size_t prev_len = 0;
62
-    size_t len = rb_len(&log);
63
-    if (len == prev_len) {
64
-        return;
65
-    }
66
-    prev_len = len;
67
-
68
-    lcd_off = 0;
69
-
70
-    const size_t todo = 120;
71
-    size_t text_off = 0;
72
-    if (len > todo) {
73
-        text_off = len - todo;
74
-    }
75
-
76
-    rb_dump(&log, lcd_write, text_off);
46
+struct ring_buffer *log_get(void) {
47
+    return &log;
77
 }
48
 }
78
 
49
 
79
 #ifndef PICOWOTA
50
 #ifndef PICOWOTA

+ 80
- 9
src/ota_shim.c View File

19
 #include "pico/cyw43_arch.h"
19
 #include "pico/cyw43_arch.h"
20
 
20
 
21
 #include "config.h"
21
 #include "config.h"
22
+#include "buttons.h"
22
 #include "lcd.h"
23
 #include "lcd.h"
23
 #include "log.h"
24
 #include "log.h"
25
+#include "lcd.h"
26
+#include "textbox.h"
24
 #include "mem.h"
27
 #include "mem.h"
28
+#include "util.h"
25
 #include "wifi.h"
29
 #include "wifi.h"
26
 
30
 
31
+static int16_t lcd_off = 0;
32
+static size_t text_window = 120;
33
+static size_t text_off = 0;
34
+static size_t prev_len = 0;
35
+static bool redraw = false;
36
+
37
+static void lcd_write(const void *buf, size_t len) {
38
+    char tmp[len + 1];
39
+    memcpy(tmp, buf, len);
40
+    tmp[len] = '\0';
41
+    lcd_off = text_box(tmp, false,
42
+                       "fixed_10x20",
43
+                       0, LCD_WIDTH,
44
+                       lcd_off, LCD_HEIGHT - lcd_off,
45
+                       0);
46
+}
47
+
48
+static void log_dump_to_lcd(void) {
49
+    // TODO length is not good as indicator.
50
+    // TODO will stop working when log buffer is filled.
51
+    size_t len = rb_len(log_get());
52
+    if (redraw || (len == prev_len)) {
53
+        return;
54
+    }
55
+    prev_len = len;
56
+    redraw = false;
57
+
58
+    lcd_off = 0;
59
+
60
+    text_off = 0;
61
+    if (len > text_window) {
62
+        text_off = len - text_window;
63
+    }
64
+
65
+    rb_dump(log_get(), lcd_write, text_off);
66
+}
67
+
68
+static void ota_buttons(enum buttons btn, bool state) {
69
+    if (state && (btn == BTN_Y)) {
70
+        reset_to_main();
71
+    } else if (state && (btn == BTN_LEFT)) {
72
+        if (text_window > 10) {
73
+            text_window -= 10;
74
+            redraw = true;
75
+        }
76
+    } else if (state && (btn == BTN_RIGHT)) {
77
+        if (text_window < 1000) {
78
+            text_window += 10;
79
+            redraw = true;
80
+        }
81
+    } else if (state && (btn == BTN_UP)) {
82
+        if (text_off > 10) {
83
+            text_off -= 10;
84
+            redraw = true;
85
+        }
86
+    } else if (state && (btn == BTN_DOWN)) {
87
+        if (text_off < (prev_len - 10)) {
88
+            text_off += 10;
89
+            redraw = true;
90
+        }
91
+    }
92
+}
93
+
94
+void picowota_poll(void) {
95
+    buttons_run();
96
+    cyw43_arch_poll();
97
+    wifi_run();
98
+    log_dump_to_lcd();
99
+}
100
+
27
 int picowota_network_init(void) {
101
 int picowota_network_init(void) {
28
-    debug("mem_load");
102
+    buttons_init();
103
+    buttons_callback(ota_buttons);
29
     mem_load();
104
     mem_load();
30
-
31
-    debug("lcd_init");
32
     lcd_init();
105
     lcd_init();
33
-
34
     lcd_set_backlight(mem_data()->backlight);
106
     lcd_set_backlight(mem_data()->backlight);
35
     log_dump_to_lcd();
107
     log_dump_to_lcd();
36
 
108
 
51
 
123
 
52
     const char *prev = NULL;
124
     const char *prev = NULL;
53
     while (!wifi_ready()) {
125
     while (!wifi_ready()) {
54
-        cyw43_arch_poll();
55
-        wifi_run();
56
-
57
         const char *state = wifi_state();
126
         const char *state = wifi_state();
58
         if (state != prev) {
127
         if (state != prev) {
59
             prev = state;
128
             prev = state;
60
             debug("new state: %s", state);
129
             debug("new state: %s", state);
61
         }
130
         }
62
 
131
 
63
-        log_dump_to_lcd();
132
+        picowota_poll();
64
 
133
 
65
         // TODO open AP when timed out?
134
         // TODO open AP when timed out?
66
     }
135
     }
67
 
136
 
68
     debug("wifi ready");
137
     debug("wifi ready");
69
-    log_dump_to_lcd();
138
+    picowota_poll();
70
 
139
 
71
     return 0;
140
     return 0;
72
 }
141
 }
73
 
142
 
74
 void picowota_network_deinit(void) {
143
 void picowota_network_deinit(void) {
75
     debug("wifi_deinit");
144
     debug("wifi_deinit");
145
+    log_dump_to_lcd();
146
+
76
     wifi_deinit();
147
     wifi_deinit();
77
 }
148
 }

Loading…
Cancel
Save