Browse Source

add version info to built fw

Thomas Buck 2 weeks ago
parent
commit
494255b7da
9 changed files with 106 additions and 10 deletions
  1. 9
    0
      CMakeLists.txt
  2. 6
    0
      README.md
  3. 0
    2
      include/buttons.h
  4. 41
    0
      include/config.h
  5. 3
    0
      include/lcd.h
  6. 1
    0
      src/buttons.c
  7. 44
    2
      src/lcd.c
  8. 1
    3
      src/main.c
  9. 1
    3
      src/usb_cdc.c

+ 9
- 0
CMakeLists.txt View File

@@ -73,6 +73,14 @@ set_source_files_properties(pico-sdk/lib/btstack/src/classic/goep_client.c PROPE
73 73
 set_source_files_properties(pico-sdk/lib/btstack/src/classic/goep_server.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
74 74
 set_source_files_properties(pico-sdk/src/rp2_common/hardware_flash/flash.c PROPERTIES COMPILE_FLAGS -Wno-shadow)
75 75
 
76
+# repo meta data
77
+include(FetchContent)
78
+FetchContent_Declare(cmake_git_version_tracking
79
+    GIT_REPOSITORY https://github.com/andrew-hardin/cmake-git-version-tracking.git
80
+    GIT_TAG 6c0cb87edd029ddfb403a8e24577c144a03605a6
81
+)
82
+FetchContent_MakeAvailable(cmake_git_version_tracking)
83
+
76 84
 # pull in common dependencies
77 85
 target_link_libraries(drumkit
78 86
     pico_stdlib
@@ -83,6 +91,7 @@ target_link_libraries(drumkit
83 91
     pico_unique_id
84 92
     tinyusb_device
85 93
     tinyusb_board
94
+    cmake_git_version_tracking
86 95
 )
87 96
 
88 97
 # enable usb output, disable uart output

+ 6
- 0
README.md View File

@@ -86,8 +86,14 @@ A copy of the license can be found in `COPYING`.
86 86
 
87 87
 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.
88 88
 
89
+Some code is adapted from the TinyUSB examples.
90
+
91
+To control the OLED display, [pico-ssd1306](https://github.com/daschr/pico-ssd1306) is used, licensed under the MIT license.
92
+
89 93
 The code in `src/encoder.c` is derived from [mathertel/RotaryEncoder](https://github.com/mathertel/RotaryEncoder) and therefore licensed as BSD 3-clause.
90 94
 
95
+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.
96
+
91 97
 The docs are built using [mdbook](https://github.com/rust-lang/mdBook), licensed as `MPL-2.0`.
92 98
 
93 99
 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`.

+ 0
- 2
include/buttons.h View File

@@ -21,8 +21,6 @@
21 21
 
22 22
 #include <stdbool.h>
23 23
 
24
-#define DEBOUNCE_DELAY_MS 50
25
-
26 24
 enum buttons {
27 25
     BTN_A = 0,
28 26
     BTN_B,

+ 41
- 0
include/config.h View File

@@ -0,0 +1,41 @@
1
+/*
2
+ * config.h
3
+ *
4
+ * Copyright (c) 2022 - 2024 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef __CONFIG_H__
20
+#define __CONFIG_H__
21
+
22
+#define VERSION_MAJOR 0
23
+#define VERSION_MINOR 1
24
+
25
+#define WATCHDOG_PERIOD_MS 100
26
+#define LOGO_INIT_MS 1000
27
+
28
+// ASCII 0x18 = CAN (cancel)
29
+#define ENTER_BOOTLOADER_MAGIC 0x18
30
+
31
+//#define DISABLE_CDC_DTR_CHECK
32
+#define DEBOUNCE_DELAY_MS 5
33
+
34
+// ----------------------------------------------------------------------------
35
+
36
+#define STR_HELPER(x) #x
37
+#define STR(x) STR_HELPER(x)
38
+
39
+#define VERSION_STR "V" STR(VERSION_MAJOR) "." STR(VERSION_MINOR)
40
+
41
+#endif // __CONFIG_H__

+ 3
- 0
include/lcd.h View File

@@ -24,6 +24,9 @@
24 24
 #define LCD_WIDTH 128
25 25
 #define LCD_HEIGHT 64
26 26
 
27
+#define FONT_HEIGHT 8
28
+#define FONT_WIDTH 5
29
+
27 30
 void lcd_init(void);
28 31
 void lcd_draw(const char *mode, const char *val, const char *bat);
29 32
 void lcd_draw_bye(void);

+ 1
- 0
src/buttons.c View File

@@ -19,6 +19,7 @@
19 19
 #include <stdio.h>
20 20
 #include "pico/stdlib.h"
21 21
 
22
+#include "config.h"
22 23
 #include "main.h"
23 24
 #include "buttons.h"
24 25
 

+ 44
- 2
src/lcd.c View File

@@ -16,11 +16,16 @@
16 16
  * See <http://www.gnu.org/licenses/>.
17 17
  */
18 18
 
19
+#include <stdio.h>
20
+#include <string.h>
21
+
19 22
 #include "hardware/i2c.h"
20 23
 #include "hardware/watchdog.h"
21 24
 
22 25
 #include "ssd1306.h"
26
+#include "git.h"
23 27
 
28
+#include "config.h"
24 29
 #include "buttons.h"
25 30
 #include "console.h"
26 31
 #include "main.h"
@@ -143,7 +148,44 @@ void lcd_draw_bye(void) {
143 148
 
144 149
 void lcd_draw_version(void) {
145 150
     ssd1306_clear(&disp);
146
-    // TODO
147
-    ssd1306_draw_string(&disp, 0, LCD_HEIGHT / 2 - 4, 1, "TODO");
151
+
152
+    ssd1306_draw_string(&disp, 0, 0, 2,
153
+                        "LARS");
154
+
155
+    ssd1306_draw_string(&disp, 0, FONT_HEIGHT * 2 + 1, 1,
156
+                        "Release: " VERSION_STR);
157
+
158
+    ssd1306_draw_string(&disp, 0, FONT_HEIGHT * 2 + 1 + FONT_HEIGHT + 1, 1,
159
+                        __DATE__ " " __TIME__);
160
+
161
+    if (git_IsPopulated()) {
162
+        const char *hash = git_CommitSHA1();
163
+        char short_hash[6 + 7 + 6 + 1] = {0};
164
+        memcpy(short_hash, "Hash: ", 6);
165
+        memcpy(short_hash + 6, hash, 7);
166
+        if (git_AnyUncommittedChanges()) {
167
+            memcpy(short_hash + 6 + 7, " dirty", 6);
168
+        }
169
+        ssd1306_draw_string(&disp, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
170
+                            short_hash);
171
+    } else {
172
+        ssd1306_draw_string(&disp, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
173
+                            "No Git Repo");
174
+    }
175
+
176
+    char hw_id_str[42] = {0};
177
+    if (hw_type == HW_PROTOTYPE) {
178
+        snprintf(hw_id_str, sizeof(hw_id_str) - 1,
179
+                 "HW Prototype");
180
+    } else if (hw_type == HW_V2) {
181
+        snprintf(hw_id_str, sizeof(hw_id_str) - 1,
182
+                 "HW V2");
183
+    } else {
184
+        snprintf(hw_id_str, sizeof(hw_id_str) - 1,
185
+                 "HW unknown %X", hw_type);
186
+    }
187
+    ssd1306_draw_string(&disp, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 3, 1,
188
+                        hw_id_str);
189
+
148 190
     ssd1306_show(&disp);
149 191
 }

+ 1
- 3
src/main.c View File

@@ -20,6 +20,7 @@
20 20
 #include "pico/bootrom.h"
21 21
 #include "hardware/watchdog.h"
22 22
 
23
+#include "config.h"
23 24
 #include "adc.h"
24 25
 #include "buttons.h"
25 26
 #include "console.h"
@@ -34,9 +35,6 @@
34 35
 #include "usb.h"
35 36
 #include "main.h"
36 37
 
37
-#define WATCHDOG_PERIOD_MS 100
38
-#define LOGO_INIT_MS 1000
39
-
40 38
 static const uint gpio_hw_detect = 21;
41 39
 
42 40
 enum hw_versions hw_type = HW_UNKNOWN;

+ 1
- 3
src/usb_cdc.c View File

@@ -30,15 +30,13 @@
30 30
 #include "bsp/board.h"
31 31
 #include "tusb.h"
32 32
 
33
+#include "config.h"
33 34
 #include "console.h"
34 35
 #include "log.h"
35 36
 #include "main.h"
36 37
 #include "usb_descriptors.h"
37 38
 #include "usb_cdc.h"
38 39
 
39
-#define ENTER_BOOTLOADER_MAGIC 0x18
40
-#define DISABLE_CDC_DTR_CHECK
41
-
42 40
 static bool reroute_cdc_debug = false;
43 41
 
44 42
 void usb_cdc_write(const void *buf, size_t count) {

Loading…
Cancel
Save