|
@@ -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,
|