|
@@ -16,16 +16,11 @@
|
16
|
16
|
* See <http://www.gnu.org/licenses/>.
|
17
|
17
|
*/
|
18
|
18
|
|
19
|
|
-#include <stdio.h>
|
20
|
|
-#include <stdint.h>
|
21
|
|
-#include <string.h>
|
22
|
|
-#include "pico/stdlib.h"
|
23
|
19
|
#include "hardware/i2c.h"
|
24
|
20
|
|
25
|
21
|
#include "ssd1306.h"
|
26
|
22
|
|
27
|
23
|
#include "buttons.h"
|
28
|
|
-#include "logo.h"
|
29
|
24
|
#include "main.h"
|
30
|
25
|
#include "lcd.h"
|
31
|
26
|
|
|
@@ -37,7 +32,7 @@ static const uint gpio_num_v2[2] = { 16, 17 };
|
37
|
32
|
|
38
|
33
|
#define LCD_ADDR 0x3C
|
39
|
34
|
|
40
|
|
-static ssd1306_t disp;
|
|
35
|
+static ssd1306_t disp = {0};
|
41
|
36
|
static bool buttons[NUM_BTNS] = {0};
|
42
|
37
|
static bool changed = true;
|
43
|
38
|
|
|
@@ -48,72 +43,89 @@ static void lcd_debug_buttons_callback(enum buttons btn, bool v) {
|
48
|
43
|
|
49
|
44
|
void lcd_debug_buttons(void) {
|
50
|
45
|
buttons_callback(lcd_debug_buttons_callback);
|
|
46
|
+
|
51
|
47
|
while (1) {
|
52
|
48
|
buttons_run();
|
53
|
49
|
handle_serial_input();
|
|
50
|
+
|
54
|
51
|
if (changed) {
|
55
|
52
|
changed = false;
|
|
53
|
+
|
56
|
54
|
ssd1306_clear(&disp);
|
57
|
55
|
ssd1306_draw_string(&disp, 0, 0, 3, "Buttons");
|
|
56
|
+
|
58
|
57
|
for (uint i = 0; i < NUM_BTNS; i++) {
|
|
58
|
+ if ((hw_type == HW_PROTOTYPE) && (i >= BTN_D) && (i <= BTN_H)) {
|
|
59
|
+ continue;
|
|
60
|
+ }
|
|
61
|
+
|
59
|
62
|
ssd1306_draw_char(&disp,
|
60
|
|
- i * 12, LCD_HEIGHT - 20 - 16 - 1,
|
61
|
|
- 2, '0' + i);
|
|
63
|
+ i * 12, LCD_HEIGHT - 20 - 16 - 1,
|
|
64
|
+ 2, '0' + i);
|
|
65
|
+
|
62
|
66
|
if (buttons[i]) {
|
63
|
67
|
ssd1306_draw_square(&disp,
|
64
|
68
|
i * 12, LCD_HEIGHT - 20 - 1,
|
65
|
69
|
10, 20);
|
66
|
70
|
} else {
|
67
|
71
|
ssd1306_draw_empty_square(&disp,
|
68
|
|
- i * 12, LCD_HEIGHT - 20 - 1,
|
69
|
|
- 10, 20);
|
|
72
|
+ i * 12, LCD_HEIGHT - 20 - 1,
|
|
73
|
+ 10, 20);
|
70
|
74
|
}
|
71
|
75
|
}
|
|
76
|
+
|
72
|
77
|
ssd1306_show(&disp);
|
73
|
78
|
}
|
74
|
79
|
}
|
75
|
80
|
}
|
76
|
81
|
|
|
82
|
+void lcd_draw_bitmap(uint8_t *data, int width, int height, int x_off, int y_off) {
|
|
83
|
+ ssd1306_clear(&disp);
|
|
84
|
+
|
|
85
|
+ for (int y = 0; y < height; y++) {
|
|
86
|
+ for (int x = 0; x < width; x++) {
|
|
87
|
+ const uint pos = y * width + x;
|
|
88
|
+ const uint bit = 7 - (pos % 8);
|
|
89
|
+ if (data[pos / 8] & (1 << bit)) {
|
|
90
|
+ ssd1306_draw_pixel(&disp, x + x_off, y + y_off);
|
|
91
|
+ }
|
|
92
|
+ }
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ ssd1306_show(&disp);
|
|
96
|
+}
|
|
97
|
+
|
77
|
98
|
void lcd_init(void) {
|
78
|
99
|
if (hw_type == HW_PROTOTYPE) {
|
79
|
|
- i2c_init(gpio_i2c_proto, 1000 * 1000);
|
|
100
|
+ i2c_init(gpio_i2c_proto, 2UL * 1000UL * 1000UL);
|
|
101
|
+
|
80
|
102
|
for (uint i = 0; i < sizeof(gpio_num_proto) / sizeof(gpio_num_proto[0]); i++) {
|
81
|
103
|
gpio_set_function(gpio_num_proto[i], GPIO_FUNC_I2C);
|
82
|
104
|
gpio_pull_up(gpio_num_proto[i]);
|
83
|
105
|
}
|
84
|
106
|
|
85
|
|
- disp.external_vcc = false;
|
86
|
|
- ssd1306_init(&disp, LCD_WIDTH, LCD_HEIGHT, LCD_ADDR, gpio_i2c_proto);
|
|
107
|
+ ssd1306_init(&disp,
|
|
108
|
+ LCD_WIDTH, LCD_HEIGHT,
|
|
109
|
+ LCD_ADDR, gpio_i2c_proto);
|
87
|
110
|
} else if (hw_type == HW_V2) {
|
88
|
|
- i2c_init(gpio_i2c_v2, 1000 * 1000);
|
|
111
|
+ i2c_init(gpio_i2c_v2, 2UL * 1000UL * 1000UL);
|
|
112
|
+
|
89
|
113
|
for (uint i = 0; i < sizeof(gpio_num_v2) / sizeof(gpio_num_v2[0]); i++) {
|
90
|
114
|
gpio_set_function(gpio_num_v2[i], GPIO_FUNC_I2C);
|
91
|
115
|
gpio_pull_up(gpio_num_v2[i]);
|
92
|
116
|
}
|
93
|
117
|
|
94
|
|
- disp.external_vcc = false;
|
95
|
|
- ssd1306_init(&disp, LCD_WIDTH, LCD_HEIGHT, LCD_ADDR, gpio_i2c_v2);
|
|
118
|
+ ssd1306_init(&disp,
|
|
119
|
+ LCD_WIDTH, LCD_HEIGHT,
|
|
120
|
+ LCD_ADDR, gpio_i2c_v2);
|
96
|
121
|
}
|
97
|
|
-
|
98
|
|
- // show logo
|
99
|
|
- ssd1306_clear(&disp);
|
100
|
|
- for (uint y = 0; y < LOGO_HEIGHT; y++) {
|
101
|
|
- for (uint x = 0; x < LOGO_WIDTH; x++) {
|
102
|
|
- const uint pos = y * LOGO_WIDTH + x;
|
103
|
|
- const uint bit = 7 - (pos % 8);
|
104
|
|
- if (logo_data[pos / 8] & (1 << bit)) {
|
105
|
|
- ssd1306_draw_pixel(&disp, x, y);
|
106
|
|
- }
|
107
|
|
- }
|
108
|
|
- }
|
109
|
|
- ssd1306_show(&disp);
|
110
|
122
|
}
|
111
|
123
|
|
112
|
124
|
void lcd_draw(const char *mode, const char *val, const char *bat) {
|
113
|
125
|
ssd1306_clear(&disp);
|
114
|
126
|
ssd1306_draw_string(&disp, 0, 0, 2, mode);
|
115
|
127
|
ssd1306_draw_string(&disp, 0, 20, 4, val);
|
116
|
|
- ssd1306_draw_string(&disp, 0, LCD_HEIGHT - 1 - 10, 1, bat);
|
|
128
|
+ ssd1306_draw_string(&disp, 0, LCD_HEIGHT - 8, 1, bat);
|
117
|
129
|
ssd1306_show(&disp);
|
118
|
130
|
}
|
119
|
131
|
|