Browse Source

lcd presence detection

Thomas Buck 1 month ago
parent
commit
aebf8acc42
4 changed files with 34 additions and 8 deletions
  1. 1
    1
      .gitmodules
  2. 3
    0
      CMakeLists.txt
  3. 1
    1
      pico-ssd1306
  4. 29
    6
      src/lcd.c

+ 1
- 1
.gitmodules View File

3
 	url = https://github.com/raspberrypi/pico-sdk
3
 	url = https://github.com/raspberrypi/pico-sdk
4
 [submodule "pico-ssd1306"]
4
 [submodule "pico-ssd1306"]
5
 	path = pico-ssd1306
5
 	path = pico-ssd1306
6
-	url = https://github.com/daschr/pico-ssd1306
6
+	url = https://github.com/xythobuz/pico-ssd1306
7
 [submodule "docs/svg-pan-zoom"]
7
 [submodule "docs/svg-pan-zoom"]
8
 	path = docs/svg-pan-zoom
8
 	path = docs/svg-pan-zoom
9
 	url = https://github.com/WebSVG/svg-pan-zoom
9
 	url = https://github.com/WebSVG/svg-pan-zoom

+ 3
- 0
CMakeLists.txt View File

62
     -Werror
62
     -Werror
63
     -Wshadow
63
     -Wshadow
64
     -O3
64
     -O3
65
+
66
+    -DSSD1306_DEBUG_PRINT=debug
67
+    -DSSD1306_DEBUG_INCLUDE="log.h"
65
 )
68
 )
66
 
69
 
67
 # suppress some warnings for borked 3rd party files in Pico SDK
70
 # suppress some warnings for borked 3rd party files in Pico SDK

+ 1
- 1
pico-ssd1306

1
-Subproject commit 8467f5b06ebd7bfa7b53e4ebc83dfdc6f396e4eb
1
+Subproject commit 607fe1cc3c84d662f749e9af0355bc15de0fc48e

+ 29
- 6
src/lcd.c View File

43
 static ssd1306_t disp = {0};
43
 static ssd1306_t disp = {0};
44
 static bool buttons[NUM_BTNS] = {0};
44
 static bool buttons[NUM_BTNS] = {0};
45
 static bool changed = true;
45
 static bool changed = true;
46
+static bool found = false;
46
 
47
 
47
 static void lcd_debug_buttons_callback(enum buttons btn, bool v) {
48
 static void lcd_debug_buttons_callback(enum buttons btn, bool v) {
48
     buttons[btn] = v;
49
     buttons[btn] = v;
50
 }
51
 }
51
 
52
 
52
 void lcd_debug_buttons(void) {
53
 void lcd_debug_buttons(void) {
54
+    if (!found) {
55
+        return;
56
+    }
57
+
53
     buttons_callback(lcd_debug_buttons_callback);
58
     buttons_callback(lcd_debug_buttons_callback);
54
 
59
 
55
     while (1) {
60
     while (1) {
90
 }
95
 }
91
 
96
 
92
 void lcd_draw_bitmap(uint8_t *data, int width, int height, int x_off, int y_off) {
97
 void lcd_draw_bitmap(uint8_t *data, int width, int height, int x_off, int y_off) {
98
+    if (!found) {
99
+        return;
100
+    }
101
+
93
     ssd1306_clear(&disp);
102
     ssd1306_clear(&disp);
94
 
103
 
95
     for (int y = 0; y < height; y++) {
104
     for (int y = 0; y < height; y++) {
114
             gpio_pull_up(gpio_num_proto[i]);
123
             gpio_pull_up(gpio_num_proto[i]);
115
         }
124
         }
116
 
125
 
117
-        ssd1306_init(&disp,
118
-                     LCD_WIDTH, LCD_HEIGHT,
119
-                     LCD_ADDR, gpio_i2c_proto);
126
+        bool r = ssd1306_init(&disp,
127
+                              LCD_WIDTH, LCD_HEIGHT,
128
+                              LCD_ADDR, gpio_i2c_proto);
129
+        found = r;
120
     } else if (hw_type == HW_V2) {
130
     } else if (hw_type == HW_V2) {
121
         i2c_init(gpio_i2c_v2, 2UL * 1000UL * 1000UL);
131
         i2c_init(gpio_i2c_v2, 2UL * 1000UL * 1000UL);
122
 
132
 
125
             gpio_pull_up(gpio_num_v2[i]);
135
             gpio_pull_up(gpio_num_v2[i]);
126
         }
136
         }
127
 
137
 
128
-        ssd1306_init(&disp,
129
-                     LCD_WIDTH, LCD_HEIGHT,
130
-                     LCD_ADDR, gpio_i2c_v2);
138
+        bool r = ssd1306_init(&disp,
139
+                              LCD_WIDTH, LCD_HEIGHT,
140
+                              LCD_ADDR, gpio_i2c_v2);
141
+        found = r;
131
     }
142
     }
132
 }
143
 }
133
 
144
 
134
 void lcd_draw(const char *mode, const char *val, const char *bat) {
145
 void lcd_draw(const char *mode, const char *val, const char *bat) {
146
+    if (!found) {
147
+        return;
148
+    }
149
+
135
     ssd1306_clear(&disp);
150
     ssd1306_clear(&disp);
136
     ssd1306_draw_string(&disp, 0, 0, 2, mode);
151
     ssd1306_draw_string(&disp, 0, 0, 2, mode);
137
     ssd1306_draw_string(&disp, 0, 20, 4, val);
152
     ssd1306_draw_string(&disp, 0, 20, 4, val);
140
 }
155
 }
141
 
156
 
142
 void lcd_draw_bye(void) {
157
 void lcd_draw_bye(void) {
158
+    if (!found) {
159
+        return;
160
+    }
161
+
143
     ssd1306_clear(&disp);
162
     ssd1306_clear(&disp);
144
     ssd1306_draw_string(&disp, 6, 5, 3, " Boot-");
163
     ssd1306_draw_string(&disp, 6, 5, 3, " Boot-");
145
     ssd1306_draw_string(&disp, 8, LCD_HEIGHT / 2 + 5, 3, "loader");
164
     ssd1306_draw_string(&disp, 8, LCD_HEIGHT / 2 + 5, 3, "loader");
147
 }
166
 }
148
 
167
 
149
 void lcd_draw_version(void) {
168
 void lcd_draw_version(void) {
169
+    if (!found) {
170
+        return;
171
+    }
172
+
150
     ssd1306_clear(&disp);
173
     ssd1306_clear(&disp);
151
 
174
 
152
     ssd1306_draw_string(&disp, 0, 0, 2,
175
     ssd1306_draw_string(&disp, 0, 0, 2,

Loading…
Cancel
Save