Ver código fonte

more bootloader stuff

Thomas Buck 11 meses atrás
pai
commit
a4b5c89957
6 arquivos alterados com 91 adições e 43 exclusões
  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 Ver arquivo

@@ -25,6 +25,8 @@ execute_process(COMMAND make
25 25
 )
26 26
 
27 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 30
 set(MAKE_FS_DATA_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/pico-sdk/lib/lwip/src/apps/http/makefsdata/makefsdata)
29 31
 execute_process(
30 32
     COMMAND perl ${MAKE_FS_DATA_SCRIPT}
@@ -209,6 +211,8 @@ set(PICOWOTA_ADDITIONAL_SOURCES
209 211
     ${CMAKE_CURRENT_SOURCE_DIR}/src/text.c
210 212
     ${CMAKE_CURRENT_SOURCE_DIR}/src/ota_shim.c
211 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 217
     ${CMAKE_CURRENT_SOURCE_DIR}/st7789/src/driver_st7789.c
214 218
 

+ 1
- 1
include/config.h Ver arquivo

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

+ 3
- 1
include/log.h Ver arquivo

@@ -48,8 +48,10 @@ void debug_log_va(bool log, const char *format, va_list args);
48 48
 void log_dump_to_usb(void);
49 49
 void log_dump_to_uart(void);
50 50
 void log_dump_to_disk(void);
51
-void log_dump_to_lcd(void);
52 51
 
53 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 57
 #endif // __LOG_H__

+ 1
- 1
picowota

@@ -1 +1 @@
1
-Subproject commit 4abdeee20f2dd8f813f322b61ce1afee7b502d12
1
+Subproject commit dd98bf620976a2df113cf03eeb2483a9e68c1d7d

+ 2
- 31
src/log.c Ver arquivo

@@ -24,8 +24,6 @@
24 24
 
25 25
 #include "config.h"
26 26
 #include "main.h"
27
-#include "lcd.h"
28
-#include "textbox.h"
29 27
 #include "usb_cdc.h"
30 28
 #include "serial.h"
31 29
 #include "ring.h"
@@ -36,7 +34,6 @@ static struct ring_buffer log = RB_INIT(log_buff, sizeof(log_buff), 1);
36 34
 
37 35
 static uint8_t line_buff[256] = {0};
38 36
 static volatile bool got_input = false;
39
-static int16_t lcd_off = 0;
40 37
 
41 38
 #ifndef PICOWOTA
42 39
 static FIL log_file_fat;
@@ -46,34 +43,8 @@ static void add_to_log(const void *buff, size_t len) {
46 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 50
 #ifndef PICOWOTA

+ 80
- 9
src/ota_shim.c Ver arquivo

@@ -19,18 +19,90 @@
19 19
 #include "pico/cyw43_arch.h"
20 20
 
21 21
 #include "config.h"
22
+#include "buttons.h"
22 23
 #include "lcd.h"
23 24
 #include "log.h"
25
+#include "lcd.h"
26
+#include "textbox.h"
24 27
 #include "mem.h"
28
+#include "util.h"
25 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 101
 int picowota_network_init(void) {
28
-    debug("mem_load");
102
+    buttons_init();
103
+    buttons_callback(ota_buttons);
29 104
     mem_load();
30
-
31
-    debug("lcd_init");
32 105
     lcd_init();
33
-
34 106
     lcd_set_backlight(mem_data()->backlight);
35 107
     log_dump_to_lcd();
36 108
 
@@ -51,27 +123,26 @@ int picowota_network_init(void) {
51 123
 
52 124
     const char *prev = NULL;
53 125
     while (!wifi_ready()) {
54
-        cyw43_arch_poll();
55
-        wifi_run();
56
-
57 126
         const char *state = wifi_state();
58 127
         if (state != prev) {
59 128
             prev = state;
60 129
             debug("new state: %s", state);
61 130
         }
62 131
 
63
-        log_dump_to_lcd();
132
+        picowota_poll();
64 133
 
65 134
         // TODO open AP when timed out?
66 135
     }
67 136
 
68 137
     debug("wifi ready");
69
-    log_dump_to_lcd();
138
+    picowota_poll();
70 139
 
71 140
     return 0;
72 141
 }
73 142
 
74 143
 void picowota_network_deinit(void) {
75 144
     debug("wifi_deinit");
145
+    log_dump_to_lcd();
146
+
76 147
     wifi_deinit();
77 148
 }

Carregando…
Cancelar
Salvar