Browse Source

draw version and repo info on oled

Thomas Buck 1 week ago
parent
commit
6a53e9596b
8 changed files with 87 additions and 3 deletions
  1. 3
    0
      .gitmodules
  2. 3
    0
      README.md
  3. 13
    1
      firmware/CMakeLists.txt
  4. 9
    2
      firmware/include/config.h
  5. 4
    0
      firmware/include/lcd.h
  6. 1
    0
      firmware/pico-ssd1306
  7. 53
    0
      firmware/src/lcd.c
  8. 1
    0
      firmware/src/main.c

+ 3
- 0
.gitmodules View File

@@ -4,3 +4,6 @@
4 4
 [submodule "firmware/pico-sdk"]
5 5
 	path = firmware/pico-sdk
6 6
 	url = https://github.com/raspberrypi/pico-sdk
7
+[submodule "firmware/pico-ssd1306"]
8
+	path = firmware/pico-ssd1306
9
+	url = https://github.com/daschr/pico-ssd1306/

+ 3
- 0
README.md View File

@@ -11,6 +11,7 @@ Check out the [Dispensy documentation](https://drinkrobotics.github.io/dispensy/
11 11
 ## License
12 12
 
13 13
 This hardware of this project is licensed under the [CERN Open Hardware Licence Version 2 - Strongly Reciprocal (CERN-OHL-S-2.0+)](https://ohwr.org/cern_ohl_s_v2.txt) or any later version.
14
+The SSD1306 footprint is from [KiCAD Rookie](https://kicadrookie.blogspot.com/2022/06/ssd1306-i2c-096in-oled-display-kicad_86.html).
14 15
 
15 16
 The docs are built using [mdbook](https://github.com/rust-lang/mdBook), licensed as `MPL-2.0`.
16 17
 The PCB SVG files in the documentation are displayed using [svg-pan-zoom](https://github.com/bumbu/svg-pan-zoom), licensed as `BSD-2-Clause`.
@@ -45,6 +46,8 @@ The firmware of this project is licensed as GPLv3.
45 46
 I initially adapted it from my own [Trackball](https://git.xythobuz.de/thomas/Trackball) and [Volcano Remote](https://git.xythobuz.de/thomas/sb-py) projects.
46 47
 It uses the [Pi Pico SDK](https://github.com/raspberrypi/pico-sdk), licensed as BSD 3-clause, and therefore also [TinyUSB](https://github.com/hathach/tinyusb), licensed under the MIT license.
47 48
 Some code is adapted from the TinyUSB examples.
49
+To control the OLED display, [pico-ssd1306](https://github.com/daschr/pico-ssd1306) is used, licensed under the MIT license.
50
+Repo metadata is embedded into the project using [cmake-git-version-tracking](https://github.com/andrew-hardin/cmake-git-version-tracking), licensed under the MIT license.
48 51
 
49 52
     This program is free software: you can redistribute it and/or modify
50 53
     it under the terms of the GNU General Public License as published by

+ 13
- 1
firmware/CMakeLists.txt View File

@@ -40,9 +40,12 @@ target_sources(dispensy PUBLIC
40 40
     ${CMAKE_CURRENT_LIST_DIR}/src/buttons.c
41 41
     ${CMAKE_CURRENT_LIST_DIR}/src/lcd.c
42 42
     ${CMAKE_CURRENT_LIST_DIR}/src/ring.c
43
+
44
+    ${CMAKE_CURRENT_LIST_DIR}/pico-ssd1306/ssd1306.c
43 45
 )
44 46
 
45 47
 target_include_directories(dispensy PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
48
+target_include_directories(dispensy PUBLIC ${CMAKE_CURRENT_LIST_DIR}/pico-ssd1306)
46 49
 
47 50
 # enable generous warnings
48 51
 target_compile_options(dispensy PUBLIC
@@ -61,6 +64,14 @@ set_source_files_properties(pico-sdk/lib/btstack/src/classic/goep_client.c PROPE
61 64
 set_source_files_properties(pico-sdk/lib/btstack/src/classic/goep_server.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
62 65
 set_source_files_properties(pico-sdk/src/rp2_common/hardware_flash/flash.c PROPERTIES COMPILE_FLAGS -Wno-shadow)
63 66
 
67
+# repo meta data
68
+include(FetchContent)
69
+FetchContent_Declare(cmake_git_version_tracking
70
+    GIT_REPOSITORY https://github.com/andrew-hardin/cmake-git-version-tracking.git
71
+    GIT_TAG 6c0cb87edd029ddfb403a8e24577c144a03605a6
72
+)
73
+FetchContent_MakeAvailable(cmake_git_version_tracking)
74
+
64 75
 # pull in common dependencies
65 76
 target_link_libraries(dispensy
66 77
     pico_stdlib
@@ -69,7 +80,8 @@ target_link_libraries(dispensy
69 80
     tinyusb_board
70 81
     hardware_adc
71 82
     hardware_gpio
72
-    hardware_pwm
83
+    hardware_i2c
84
+    cmake_git_version_tracking
73 85
 )
74 86
 
75 87
 # fix for Errata RP2040-E5 (the fix requires use of GPIO 15)

+ 9
- 2
firmware/include/config.h View File

@@ -19,8 +19,8 @@
19 19
 #ifndef __CONFIG_H__
20 20
 #define __CONFIG_H__
21 21
 
22
-#define APP_VERSION_MAJOR 0
23
-#define APP_VERSION_MINOR 1
22
+#define VERSION_MAJOR 0
23
+#define VERSION_MINOR 1
24 24
 
25 25
 #define WATCHDOG_PERIOD_MS 10
26 26
 
@@ -30,4 +30,11 @@
30 30
 //#define DISABLE_CDC_DTR_CHECK
31 31
 #define DEBOUNCE_DELAY_MS 5
32 32
 
33
+// ----------------------------------------------------------------------------
34
+
35
+#define STR_HELPER(x) #x
36
+#define STR(x) STR_HELPER(x)
37
+
38
+#define VERSION_STR "V" STR(VERSION_MAJOR) "." STR(VERSION_MINOR)
39
+
33 40
 #endif // __CONFIG_H__

+ 4
- 0
firmware/include/lcd.h View File

@@ -22,6 +22,10 @@
22 22
 #define LCD_WIDTH 128
23 23
 #define LCD_HEIGHT 64
24 24
 
25
+#define FONT_HEIGHT 8
26
+#define FONT_WIDTH 5
27
+
25 28
 void lcd_init(void);
29
+void lcd_splash(void);
26 30
 
27 31
 #endif // __LCD_H__

+ 1
- 0
firmware/pico-ssd1306

@@ -0,0 +1 @@
1
+Subproject commit 8467f5b06ebd7bfa7b53e4ebc83dfdc6f396e4eb

+ 53
- 0
firmware/src/lcd.c View File

@@ -16,9 +16,62 @@
16 16
  * See <http://www.gnu.org/licenses/>.
17 17
  */
18 18
 
19
+#include <string.h>
20
+
21
+#include "hardware/i2c.h"
22
+#include "ssd1306.h"
23
+#include "git.h"
24
+
19 25
 #include "config.h"
20 26
 #include "log.h"
21 27
 #include "lcd.h"
22 28
 
29
+#define LCD_I2C_ADDR 0x3C
30
+
31
+static i2c_inst_t *gpio_inst_i2c = i2c1;
32
+static const uint gpio_num_i2c[2] = { 14, 15 };
33
+
34
+static ssd1306_t lcd = {0};
35
+
23 36
 void lcd_init(void) {
37
+    i2c_init(gpio_inst_i2c, 2UL * 1000UL * 1000UL);
38
+
39
+    for (uint i = 0; i < sizeof(gpio_num_i2c) / sizeof(gpio_num_i2c[0]); i++) {
40
+        gpio_set_function(gpio_num_i2c[i], GPIO_FUNC_I2C);
41
+        gpio_pull_up(gpio_num_i2c[i]);
42
+    }
43
+
44
+    ssd1306_init(&lcd, LCD_WIDTH, LCD_HEIGHT, LCD_I2C_ADDR, gpio_inst_i2c);
45
+}
46
+
47
+void lcd_splash(void) {
48
+    ssd1306_clear(&lcd);
49
+
50
+    ssd1306_draw_string(&lcd, 0, 0, 2,
51
+                        "Dispensy");
52
+
53
+    ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1, 1,
54
+                        "Release: " VERSION_STR);
55
+
56
+    ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + FONT_HEIGHT + 1, 1,
57
+                        __DATE__ " " __TIME__);
58
+
59
+    if (git_IsPopulated()) {
60
+        const char *hash = git_CommitSHA1();
61
+        char short_hash[6 + 7 + 1] = {0};
62
+        memcpy(short_hash, "Hash: ", 6);
63
+        memcpy(short_hash + 6, hash, 7);
64
+        ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
65
+                            short_hash);
66
+
67
+        if (git_AnyUncommittedChanges()) {
68
+            ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 3, 1,
69
+                                "Repo has changes!");
70
+        }
71
+    } else {
72
+        ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
73
+                            "No Git Repo");
74
+    }
75
+
76
+    ssd1306_show(&lcd);
24 77
 }

+ 1
- 0
firmware/src/main.c View File

@@ -48,6 +48,7 @@ int main(void) {
48 48
 
49 49
     buttons_init();
50 50
     lcd_init();
51
+    lcd_splash();
51 52
 
52 53
     debug("go");
53 54
 

Loading…
Cancel
Save