Browse Source

lcd presence detection

Thomas Buck 2 weeks 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,7 +3,7 @@
3 3
 	url = https://github.com/raspberrypi/pico-sdk
4 4
 [submodule "pico-ssd1306"]
5 5
 	path = pico-ssd1306
6
-	url = https://github.com/daschr/pico-ssd1306
6
+	url = https://github.com/xythobuz/pico-ssd1306
7 7
 [submodule "docs/svg-pan-zoom"]
8 8
 	path = docs/svg-pan-zoom
9 9
 	url = https://github.com/WebSVG/svg-pan-zoom

+ 3
- 0
CMakeLists.txt View File

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

+ 1
- 1
pico-ssd1306

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

+ 29
- 6
src/lcd.c View File

@@ -43,6 +43,7 @@ static const uint gpio_num_v2[2] = { 16, 17 };
43 43
 static ssd1306_t disp = {0};
44 44
 static bool buttons[NUM_BTNS] = {0};
45 45
 static bool changed = true;
46
+static bool found = false;
46 47
 
47 48
 static void lcd_debug_buttons_callback(enum buttons btn, bool v) {
48 49
     buttons[btn] = v;
@@ -50,6 +51,10 @@ static void lcd_debug_buttons_callback(enum buttons btn, bool v) {
50 51
 }
51 52
 
52 53
 void lcd_debug_buttons(void) {
54
+    if (!found) {
55
+        return;
56
+    }
57
+
53 58
     buttons_callback(lcd_debug_buttons_callback);
54 59
 
55 60
     while (1) {
@@ -90,6 +95,10 @@ void lcd_debug_buttons(void) {
90 95
 }
91 96
 
92 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 102
     ssd1306_clear(&disp);
94 103
 
95 104
     for (int y = 0; y < height; y++) {
@@ -114,9 +123,10 @@ void lcd_init(void) {
114 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 130
     } else if (hw_type == HW_V2) {
121 131
         i2c_init(gpio_i2c_v2, 2UL * 1000UL * 1000UL);
122 132
 
@@ -125,13 +135,18 @@ void lcd_init(void) {
125 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 145
 void lcd_draw(const char *mode, const char *val, const char *bat) {
146
+    if (!found) {
147
+        return;
148
+    }
149
+
135 150
     ssd1306_clear(&disp);
136 151
     ssd1306_draw_string(&disp, 0, 0, 2, mode);
137 152
     ssd1306_draw_string(&disp, 0, 20, 4, val);
@@ -140,6 +155,10 @@ void lcd_draw(const char *mode, const char *val, const char *bat) {
140 155
 }
141 156
 
142 157
 void lcd_draw_bye(void) {
158
+    if (!found) {
159
+        return;
160
+    }
161
+
143 162
     ssd1306_clear(&disp);
144 163
     ssd1306_draw_string(&disp, 6, 5, 3, " Boot-");
145 164
     ssd1306_draw_string(&disp, 8, LCD_HEIGHT / 2 + 5, 3, "loader");
@@ -147,6 +166,10 @@ void lcd_draw_bye(void) {
147 166
 }
148 167
 
149 168
 void lcd_draw_version(void) {
169
+    if (!found) {
170
+        return;
171
+    }
172
+
150 173
     ssd1306_clear(&disp);
151 174
 
152 175
     ssd1306_draw_string(&disp, 0, 0, 2,

Loading…
Cancel
Save