42 Commits

Author SHA1 Message Date
  Thomas Buck 965cf087d8 print current value in workflow 3 months ago
  Thomas Buck ca91fdf394 only call disconnect once when aborting workflow 3 months ago
  Thomas Buck 33773f52d6 print workflow step and allow aborting 3 months ago
  Thomas Buck 0c2780e7ae allow going back from workflow selection 3 months ago
  Thomas Buck 5af9bc8780 add simplistic crafty support 3 months ago
  Thomas Buck 01259255e8 clear text box bg. fix ble disconnect and workflow notify. 3 months ago
  Thomas Buck e78ad09f27 add simple volcano_run state 3 months ago
  Thomas Buck f064eb3a5a generalize menu infrastructure to also use it for workflow selection 3 months ago
  Thomas Buck 5063ba3de1 add workflow logic 3 months ago
  Thomas Buck 00498af11e device selection menu 3 months ago
  Thomas Buck 0769496400 only show relevant devices in scan state 3 months ago
  Thomas Buck 00e30acf5d detect known device types and read their serial number 3 months ago
  Thomas Buck 03daa0ec1e test workflow in debug console 3 months ago
  Thomas Buck 722d6e6d8f add commands for heater and pump state 3 months ago
  Thomas Buck c3a43c4f91 proper timeouts for ble write, now working. 3 months ago
  Thomas Buck 46f9c9a5da serial console mostly working, but still losing some bytes when transmitting lots. 3 months ago
  Thomas Buck 3b40fe0f43 option to block on uart buffer overrun 3 months ago
  Thomas Buck e41bd0bfed add generic ring buffer lib, used for log buffer and new uart tx buffer. uart as second console option for nicer debugging. 3 months ago
  Thomas Buck 395ef608e6 implement ble service and characteristic discovery and value write for volcano. still crashing unfortunately. 3 months ago
  Thomas Buck c6da7c81a2 make inclusion of sources optional 3 months ago
  Thomas Buck 2354f36e7a tweak debug disk creation 3 months ago
  Thomas Buck 558224aa67 have the device give out its own source code 3 months ago
  Thomas Buck 17c4cf73ba run state machine for testing periodically. 3 months ago
  Thomas Buck 0d8e77dd69 optional auto connect for volcano console commands. 3 months ago
  Thomas Buck 1b3e3e286b implement ble read 3 months ago
  Thomas Buck 3f60298a6e only redraw battery indicator when needed 3 months ago
  Thomas Buck c376ba1486 ble connect and disconnect 3 months ago
  Thomas Buck 2c330fd03f basic state machine for app logic 3 months ago
  Thomas Buck d2c67b7c92 gap inquiry scan is not needed after all 3 months ago
  Thomas Buck 8e13f7b0d8 more work on ble scan. still not finding target device name, even with gap inquiry. 3 months ago
  Thomas Buck 822302d3e8 support arbitrary blended text colors 3 months ago
  Thomas Buck b7bae8f489 draw battery status on display 3 months ago
  Thomas Buck d7f8847dab optional background fill for text, for splash screen 3 months ago
  Thomas Buck 6a4c2b8e16 first text rendering test 3 months ago
  Thomas Buck 86e238560d lcd working, drawing logo as splash screen 3 months ago
  Thomas Buck 47d270deb2 add ble scanning test 3 months ago
  Thomas Buck 25aa485d8f add lipo shim reading 3 months ago
  Thomas Buck a9bf35e24b pico w onboard led 3 months ago
  Thomas Buck 0b7fcb080b first building but not running state of C Pico SDK version 3 months ago
  Thomas Buck 76436adf41 unfinished py ota 3 months ago
  Thomas Buck 8c9fcb659d modify brightness in menus. nicer battery display. 3 months ago
  Thomas Buck 18b4c98c5e gpl license 3 months ago
93 changed files with 11958 additions and 31 deletions
  1. 7
    0
      .gitignore
  2. 12
    0
      .gitmodules
  3. 145
    0
      CMakeLists.txt
  4. 674
    0
      COPYING
  5. 131
    0
      README.md
  6. 33
    0
      case/case.scad
  7. 245
    0
      case/pico_case.scad
  8. 18
    0
      debug.sh
  9. 31
    0
      debug_swd.sh
  10. 1
    0
      fatfs
  11. 28
    0
      flash.sh
  12. 6
    0
      flash_swd.sh
  13. 61
    0
      include/ble.h
  14. 58
    0
      include/btstack_config.h
  15. 42
    0
      include/buttons.h
  16. 48
    0
      include/config.h
  17. 26
    0
      include/console.h
  18. 38
    0
      include/crafty.h
  19. 27
    0
      include/debug_disk.h
  20. 21
    0
      include/fat_disk.h
  21. 296
    0
      include/ffconf.h
  22. 30
    0
      include/image.h
  23. 44
    0
      include/lcd.h
  24. 26
    0
      include/lipo.h
  25. 48
    0
      include/log.h
  26. 3615
    0
      include/logo.h
  27. 24
    0
      include/main.h
  28. 37
    0
      include/menu.h
  29. 33
    0
      include/models.h
  30. 43
    0
      include/ring.h
  31. 31
    0
      include/serial.h
  32. 33
    0
      include/state.h
  33. 30
    0
      include/state_crafty.h
  34. 26
    0
      include/state_scan.h
  35. 31
    0
      include/state_volcano_run.h
  36. 26
    0
      include/state_volcano_workflow.h
  37. 53
    0
      include/text.h
  38. 125
    0
      include/tusb_config.h
  39. 25
    0
      include/usb.h
  40. 29
    0
      include/usb_cdc.h
  41. 24
    0
      include/usb_descriptors.h
  42. 25
    0
      include/usb_msc.h
  43. 36
    0
      include/util.h
  44. 36
    0
      include/volcano.h
  45. 60
    0
      include/workflow.h
  46. 1
    0
      mcufont
  47. 22
    0
      pack_data.sh
  48. 1
    0
      pico-sdk
  49. 16
    0
      python-test/copy.sh
  50. 48
    2
      python-test/lcd.py
  51. 187
    0
      python-test/ota.py
  52. 17
    1
      python-test/poll.py
  53. 18
    0
      python-test/scan.py
  54. 17
    1
      python-test/state_connect.py
  55. 17
    1
      python-test/state_heat.py
  56. 17
    1
      python-test/state_notify.py
  57. 17
    1
      python-test/state_pump.py
  58. 34
    2
      python-test/state_scan.py
  59. 29
    2
      python-test/state_select.py
  60. 17
    1
      python-test/state_wait_temp.py
  61. 17
    1
      python-test/state_wait_time.py
  62. 59
    17
      python-test/states.py
  63. 17
    1
      python-test/workflows.py
  64. 770
    0
      src/ble.c
  65. 80
    0
      src/buttons.c
  66. 552
    0
      src/console.c
  67. 121
    0
      src/crafty.c
  68. 147
    0
      src/debug_disk.c
  69. 130
    0
      src/fat_disk.c
  70. 152
    0
      src/image.c
  71. 309
    0
      src/lcd.c
  72. 120
    0
      src/lipo.c
  73. 142
    0
      src/log.c
  74. 112
    0
      src/main.c
  75. 105
    0
      src/menu.c
  76. 53
    0
      src/models.c
  77. 92
    0
      src/ring.c
  78. 157
    0
      src/serial.c
  79. 115
    0
      src/state.c
  80. 127
    0
      src/state_crafty.c
  81. 132
    0
      src/state_scan.c
  82. 146
    0
      src/state_volcano_run.c
  83. 78
    0
      src/state_volcano_workflow.c
  84. 192
    0
      src/text.c
  85. 70
    0
      src/usb.c
  86. 115
    0
      src/usb_cdc.c
  87. 229
    0
      src/usb_descriptors.c
  88. 215
    0
      src/usb_msc.c
  89. 109
    0
      src/util.c
  90. 118
    0
      src/volcano.c
  91. 264
    0
      src/workflow.c
  92. 1
    0
      st7789
  93. 16
    0
      web-app/fetch.sh

+ 7
- 0
.gitignore View File

@@ -1,2 +1,9 @@
1 1
 web-app/*.js
2
+web-app/*/*.js
2 3
 __pycache__
4
+build
5
+build_debug
6
+*.stl
7
+*.sl1
8
+*.wow
9
+.directory

+ 12
- 0
.gitmodules View File

@@ -0,0 +1,12 @@
1
+[submodule "pico-sdk"]
2
+	path = pico-sdk
3
+	url = https://github.com/raspberrypi/pico-sdk
4
+[submodule "fatfs"]
5
+	path = fatfs
6
+	url = https://github.com/abbrev/fatfs
7
+[submodule "mcufont"]
8
+	path = mcufont
9
+	url = https://github.com/mcufont/mcufont
10
+[submodule "st7789"]
11
+	path = st7789
12
+	url = https://github.com/hepingood/st7789

+ 145
- 0
CMakeLists.txt View File

@@ -0,0 +1,145 @@
1
+cmake_minimum_required(VERSION 3.13)
2
+
3
+# build MCUFont encoder host tool and convert included example fonts
4
+execute_process(COMMAND make
5
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mcufont/encoder
6
+)
7
+execute_process(COMMAND make
8
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mcufont/fonts
9
+)
10
+
11
+# initialize pico-sdk from submodule
12
+include(pico-sdk/pico_sdk_init.cmake)
13
+
14
+project(gadget C CXX)
15
+set(CMAKE_C_STANDARD 11)
16
+set(CMAKE_CXX_STANDARD 17)
17
+
18
+# initialize the Raspberry Pi Pico SDK
19
+pico_sdk_init()
20
+
21
+# copy FatFS source files to build dir, so we can use our own ffconf.h
22
+configure_file(
23
+    ${CMAKE_CURRENT_SOURCE_DIR}/fatfs/source/ff.c
24
+    ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.c
25
+    COPYONLY
26
+)
27
+configure_file(
28
+    ${CMAKE_CURRENT_SOURCE_DIR}/fatfs/source/ff.h
29
+    ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.h
30
+    COPYONLY
31
+)
32
+configure_file(
33
+    ${CMAKE_CURRENT_SOURCE_DIR}/fatfs/source/diskio.h
34
+    ${CMAKE_CURRENT_BINARY_DIR}/fatfs/diskio.h
35
+    COPYONLY
36
+)
37
+configure_file(
38
+    ${CMAKE_CURRENT_SOURCE_DIR}/fatfs/source/ffunicode.c
39
+    ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ffunicode.c
40
+    COPYONLY
41
+)
42
+
43
+add_executable(gadget)
44
+
45
+target_sources(gadget PUBLIC
46
+    src/main.c
47
+    src/console.c
48
+    src/log.c
49
+    src/util.c
50
+    src/usb.c
51
+    src/usb_cdc.c
52
+    src/usb_descriptors.c
53
+    src/usb_msc.c
54
+    src/fat_disk.c
55
+    src/debug_disk.c
56
+    src/buttons.c
57
+    src/lipo.c
58
+    src/ble.c
59
+    src/lcd.c
60
+    src/text.c
61
+    src/image.c
62
+    src/state.c
63
+    src/volcano.c
64
+    src/serial.c
65
+    src/ring.c
66
+    src/models.c
67
+    src/state_scan.c
68
+    src/workflow.c
69
+    src/menu.c
70
+    src/state_volcano_workflow.c
71
+    src/state_volcano_run.c
72
+    src/crafty.c
73
+    src/state_crafty.c
74
+
75
+    ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.c
76
+    ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ffunicode.c
77
+
78
+    st7789/src/driver_st7789.c
79
+
80
+    mcufont/decoder/mf_encoding.c
81
+    mcufont/decoder/mf_font.c
82
+    mcufont/decoder/mf_justify.c
83
+    mcufont/decoder/mf_kerning.c
84
+    mcufont/decoder/mf_rlefont.c
85
+    mcufont/decoder/mf_bwfont.c
86
+    mcufont/decoder/mf_scaledfont.c
87
+    mcufont/decoder/mf_wordwrap.c
88
+)
89
+
90
+# external dependency include directories
91
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
92
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/fatfs)
93
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/st7789/src)
94
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/st7789/interface)
95
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/decoder)
96
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/fonts)
97
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/build)
98
+
99
+# compress source code and stuff we want to include
100
+add_custom_target(pack bash -c "./pack_data.sh"
101
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
102
+    BYPRODUCTS "build/pack_data.h"
103
+)
104
+add_dependencies(gadget pack)
105
+
106
+# enable generous warnings
107
+target_compile_options(gadget PUBLIC
108
+    -Wall
109
+    -Wextra
110
+    -Werror
111
+)
112
+
113
+# suppress some warnings for borked 3rd party files in Pico SDK
114
+set_source_files_properties(pico-sdk/lib/btstack/src/ble/sm.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
115
+set_source_files_properties(pico-sdk/lib/btstack/src/btstack_hid_parser.c PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized)
116
+set_source_files_properties(pico-sdk/src/rp2_common/pico_cyw43_driver/cyw43_driver.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
117
+set_source_files_properties(pico-sdk/lib/btstack/src/classic/avdtp_util.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
118
+set_source_files_properties(pico-sdk/lib/btstack/src/classic/goep_client.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
119
+set_source_files_properties(pico-sdk/lib/btstack/src/classic/goep_server.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
120
+
121
+# pull in common dependencies
122
+target_link_libraries(gadget
123
+    pico_stdlib
124
+    pico_unique_id
125
+    tinyusb_device
126
+    tinyusb_board
127
+    hardware_spi
128
+    hardware_adc
129
+    hardware_gpio
130
+    hardware_pwm
131
+    pico_btstack_ble
132
+    pico_btstack_cyw43
133
+    pico_cyw43_arch_threadsafe_background
134
+)
135
+
136
+target_compile_definitions(gadget PUBLIC
137
+    RUNNING_AS_CLIENT=1
138
+    CYW43_LWIP=0
139
+)
140
+
141
+# fix for Errata RP2040-E5 (the fix requires use of GPIO 15)
142
+target_compile_definitions(gadget PUBLIC PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1)
143
+
144
+# create map/bin/hex/uf2 file etc.
145
+pico_add_extra_outputs(gadget)

+ 674
- 0
COPYING View File

@@ -0,0 +1,674 @@
1
+                    GNU GENERAL PUBLIC LICENSE
2
+                       Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+                            Preamble
9
+
10
+  The GNU General Public License is a free, copyleft license for
11
+software and other kinds of works.
12
+
13
+  The licenses for most software and other practical works are designed
14
+to take away your freedom to share and change the works.  By contrast,
15
+the GNU General Public License is intended to guarantee your freedom to
16
+share and change all versions of a program--to make sure it remains free
17
+software for all its users.  We, the Free Software Foundation, use the
18
+GNU General Public License for most of our software; it applies also to
19
+any other work released this way by its authors.  You can apply it to
20
+your programs, too.
21
+
22
+  When we speak of free software, we are referring to freedom, not
23
+price.  Our General Public Licenses are designed to make sure that you
24
+have the freedom to distribute copies of free software (and charge for
25
+them if you wish), that you receive source code or can get it if you
26
+want it, that you can change the software or use pieces of it in new
27
+free programs, and that you know you can do these things.
28
+
29
+  To protect your rights, we need to prevent others from denying you
30
+these rights or asking you to surrender the rights.  Therefore, you have
31
+certain responsibilities if you distribute copies of the software, or if
32
+you modify it: responsibilities to respect the freedom of others.
33
+
34
+  For example, if you distribute copies of such a program, whether
35
+gratis or for a fee, you must pass on to the recipients the same
36
+freedoms that you received.  You must make sure that they, too, receive
37
+or can get the source code.  And you must show them these terms so they
38
+know their rights.
39
+
40
+  Developers that use the GNU GPL protect your rights with two steps:
41
+(1) assert copyright on the software, and (2) offer you this License
42
+giving you legal permission to copy, distribute and/or modify it.
43
+
44
+  For the developers' and authors' protection, the GPL clearly explains
45
+that there is no warranty for this free software.  For both users' and
46
+authors' sake, the GPL requires that modified versions be marked as
47
+changed, so that their problems will not be attributed erroneously to
48
+authors of previous versions.
49
+
50
+  Some devices are designed to deny users access to install or run
51
+modified versions of the software inside them, although the manufacturer
52
+can do so.  This is fundamentally incompatible with the aim of
53
+protecting users' freedom to change the software.  The systematic
54
+pattern of such abuse occurs in the area of products for individuals to
55
+use, which is precisely where it is most unacceptable.  Therefore, we
56
+have designed this version of the GPL to prohibit the practice for those
57
+products.  If such problems arise substantially in other domains, we
58
+stand ready to extend this provision to those domains in future versions
59
+of the GPL, as needed to protect the freedom of users.
60
+
61
+  Finally, every program is threatened constantly by software patents.
62
+States should not allow patents to restrict development and use of
63
+software on general-purpose computers, but in those that do, we wish to
64
+avoid the special danger that patents applied to a free program could
65
+make it effectively proprietary.  To prevent this, the GPL assures that
66
+patents cannot be used to render the program non-free.
67
+
68
+  The precise terms and conditions for copying, distribution and
69
+modification follow.
70
+
71
+                       TERMS AND CONDITIONS
72
+
73
+  0. Definitions.
74
+
75
+  "This License" refers to version 3 of the GNU General Public License.
76
+
77
+  "Copyright" also means copyright-like laws that apply to other kinds of
78
+works, such as semiconductor masks.
79
+
80
+  "The Program" refers to any copyrightable work licensed under this
81
+License.  Each licensee is addressed as "you".  "Licensees" and
82
+"recipients" may be individuals or organizations.
83
+
84
+  To "modify" a work means to copy from or adapt all or part of the work
85
+in a fashion requiring copyright permission, other than the making of an
86
+exact copy.  The resulting work is called a "modified version" of the
87
+earlier work or a work "based on" the earlier work.
88
+
89
+  A "covered work" means either the unmodified Program or a work based
90
+on the Program.
91
+
92
+  To "propagate" a work means to do anything with it that, without
93
+permission, would make you directly or secondarily liable for
94
+infringement under applicable copyright law, except executing it on a
95
+computer or modifying a private copy.  Propagation includes copying,
96
+distribution (with or without modification), making available to the
97
+public, and in some countries other activities as well.
98
+
99
+  To "convey" a work means any kind of propagation that enables other
100
+parties to make or receive copies.  Mere interaction with a user through
101
+a computer network, with no transfer of a copy, is not conveying.
102
+
103
+  An interactive user interface displays "Appropriate Legal Notices"
104
+to the extent that it includes a convenient and prominently visible
105
+feature that (1) displays an appropriate copyright notice, and (2)
106
+tells the user that there is no warranty for the work (except to the
107
+extent that warranties are provided), that licensees may convey the
108
+work under this License, and how to view a copy of this License.  If
109
+the interface presents a list of user commands or options, such as a
110
+menu, a prominent item in the list meets this criterion.
111
+
112
+  1. Source Code.
113
+
114
+  The "source code" for a work means the preferred form of the work
115
+for making modifications to it.  "Object code" means any non-source
116
+form of a work.
117
+
118
+  A "Standard Interface" means an interface that either is an official
119
+standard defined by a recognized standards body, or, in the case of
120
+interfaces specified for a particular programming language, one that
121
+is widely used among developers working in that language.
122
+
123
+  The "System Libraries" of an executable work include anything, other
124
+than the work as a whole, that (a) is included in the normal form of
125
+packaging a Major Component, but which is not part of that Major
126
+Component, and (b) serves only to enable use of the work with that
127
+Major Component, or to implement a Standard Interface for which an
128
+implementation is available to the public in source code form.  A
129
+"Major Component", in this context, means a major essential component
130
+(kernel, window system, and so on) of the specific operating system
131
+(if any) on which the executable work runs, or a compiler used to
132
+produce the work, or an object code interpreter used to run it.
133
+
134
+  The "Corresponding Source" for a work in object code form means all
135
+the source code needed to generate, install, and (for an executable
136
+work) run the object code and to modify the work, including scripts to
137
+control those activities.  However, it does not include the work's
138
+System Libraries, or general-purpose tools or generally available free
139
+programs which are used unmodified in performing those activities but
140
+which are not part of the work.  For example, Corresponding Source
141
+includes interface definition files associated with source files for
142
+the work, and the source code for shared libraries and dynamically
143
+linked subprograms that the work is specifically designed to require,
144
+such as by intimate data communication or control flow between those
145
+subprograms and other parts of the work.
146
+
147
+  The Corresponding Source need not include anything that users
148
+can regenerate automatically from other parts of the Corresponding
149
+Source.
150
+
151
+  The Corresponding Source for a work in source code form is that
152
+same work.
153
+
154
+  2. Basic Permissions.
155
+
156
+  All rights granted under this License are granted for the term of
157
+copyright on the Program, and are irrevocable provided the stated
158
+conditions are met.  This License explicitly affirms your unlimited
159
+permission to run the unmodified Program.  The output from running a
160
+covered work is covered by this License only if the output, given its
161
+content, constitutes a covered work.  This License acknowledges your
162
+rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+  You may make, run and propagate covered works that you do not
165
+convey, without conditions so long as your license otherwise remains
166
+in force.  You may convey covered works to others for the sole purpose
167
+of having them make modifications exclusively for you, or provide you
168
+with facilities for running those works, provided that you comply with
169
+the terms of this License in conveying all material for which you do
170
+not control copyright.  Those thus making or running the covered works
171
+for you must do so exclusively on your behalf, under your direction
172
+and control, on terms that prohibit them from making any copies of
173
+your copyrighted material outside their relationship with you.
174
+
175
+  Conveying under any other circumstances is permitted solely under
176
+the conditions stated below.  Sublicensing is not allowed; section 10
177
+makes it unnecessary.
178
+
179
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+  No covered work shall be deemed part of an effective technological
182
+measure under any applicable law fulfilling obligations under article
183
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+similar laws prohibiting or restricting circumvention of such
185
+measures.
186
+
187
+  When you convey a covered work, you waive any legal power to forbid
188
+circumvention of technological measures to the extent such circumvention
189
+is effected by exercising rights under this License with respect to
190
+the covered work, and you disclaim any intention to limit operation or
191
+modification of the work as a means of enforcing, against the work's
192
+users, your or third parties' legal rights to forbid circumvention of
193
+technological measures.
194
+
195
+  4. Conveying Verbatim Copies.
196
+
197
+  You may convey verbatim copies of the Program's source code as you
198
+receive it, in any medium, provided that you conspicuously and
199
+appropriately publish on each copy an appropriate copyright notice;
200
+keep intact all notices stating that this License and any
201
+non-permissive terms added in accord with section 7 apply to the code;
202
+keep intact all notices of the absence of any warranty; and give all
203
+recipients a copy of this License along with the Program.
204
+
205
+  You may charge any price or no price for each copy that you convey,
206
+and you may offer support or warranty protection for a fee.
207
+
208
+  5. Conveying Modified Source Versions.
209
+
210
+  You may convey a work based on the Program, or the modifications to
211
+produce it from the Program, in the form of source code under the
212
+terms of section 4, provided that you also meet all of these conditions:
213
+
214
+    a) The work must carry prominent notices stating that you modified
215
+    it, and giving a relevant date.
216
+
217
+    b) The work must carry prominent notices stating that it is
218
+    released under this License and any conditions added under section
219
+    7.  This requirement modifies the requirement in section 4 to
220
+    "keep intact all notices".
221
+
222
+    c) You must license the entire work, as a whole, under this
223
+    License to anyone who comes into possession of a copy.  This
224
+    License will therefore apply, along with any applicable section 7
225
+    additional terms, to the whole of the work, and all its parts,
226
+    regardless of how they are packaged.  This License gives no
227
+    permission to license the work in any other way, but it does not
228
+    invalidate such permission if you have separately received it.
229
+
230
+    d) If the work has interactive user interfaces, each must display
231
+    Appropriate Legal Notices; however, if the Program has interactive
232
+    interfaces that do not display Appropriate Legal Notices, your
233
+    work need not make them do so.
234
+
235
+  A compilation of a covered work with other separate and independent
236
+works, which are not by their nature extensions of the covered work,
237
+and which are not combined with it such as to form a larger program,
238
+in or on a volume of a storage or distribution medium, is called an
239
+"aggregate" if the compilation and its resulting copyright are not
240
+used to limit the access or legal rights of the compilation's users
241
+beyond what the individual works permit.  Inclusion of a covered work
242
+in an aggregate does not cause this License to apply to the other
243
+parts of the aggregate.
244
+
245
+  6. Conveying Non-Source Forms.
246
+
247
+  You may convey a covered work in object code form under the terms
248
+of sections 4 and 5, provided that you also convey the
249
+machine-readable Corresponding Source under the terms of this License,
250
+in one of these ways:
251
+
252
+    a) Convey the object code in, or embodied in, a physical product
253
+    (including a physical distribution medium), accompanied by the
254
+    Corresponding Source fixed on a durable physical medium
255
+    customarily used for software interchange.
256
+
257
+    b) Convey the object code in, or embodied in, a physical product
258
+    (including a physical distribution medium), accompanied by a
259
+    written offer, valid for at least three years and valid for as
260
+    long as you offer spare parts or customer support for that product
261
+    model, to give anyone who possesses the object code either (1) a
262
+    copy of the Corresponding Source for all the software in the
263
+    product that is covered by this License, on a durable physical
264
+    medium customarily used for software interchange, for a price no
265
+    more than your reasonable cost of physically performing this
266
+    conveying of source, or (2) access to copy the
267
+    Corresponding Source from a network server at no charge.
268
+
269
+    c) Convey individual copies of the object code with a copy of the
270
+    written offer to provide the Corresponding Source.  This
271
+    alternative is allowed only occasionally and noncommercially, and
272
+    only if you received the object code with such an offer, in accord
273
+    with subsection 6b.
274
+
275
+    d) Convey the object code by offering access from a designated
276
+    place (gratis or for a charge), and offer equivalent access to the
277
+    Corresponding Source in the same way through the same place at no
278
+    further charge.  You need not require recipients to copy the
279
+    Corresponding Source along with the object code.  If the place to
280
+    copy the object code is a network server, the Corresponding Source
281
+    may be on a different server (operated by you or a third party)
282
+    that supports equivalent copying facilities, provided you maintain
283
+    clear directions next to the object code saying where to find the
284
+    Corresponding Source.  Regardless of what server hosts the
285
+    Corresponding Source, you remain obligated to ensure that it is
286
+    available for as long as needed to satisfy these requirements.
287
+
288
+    e) Convey the object code using peer-to-peer transmission, provided
289
+    you inform other peers where the object code and Corresponding
290
+    Source of the work are being offered to the general public at no
291
+    charge under subsection 6d.
292
+
293
+  A separable portion of the object code, whose source code is excluded
294
+from the Corresponding Source as a System Library, need not be
295
+included in conveying the object code work.
296
+
297
+  A "User Product" is either (1) a "consumer product", which means any
298
+tangible personal property which is normally used for personal, family,
299
+or household purposes, or (2) anything designed or sold for incorporation
300
+into a dwelling.  In determining whether a product is a consumer product,
301
+doubtful cases shall be resolved in favor of coverage.  For a particular
302
+product received by a particular user, "normally used" refers to a
303
+typical or common use of that class of product, regardless of the status
304
+of the particular user or of the way in which the particular user
305
+actually uses, or expects or is expected to use, the product.  A product
306
+is a consumer product regardless of whether the product has substantial
307
+commercial, industrial or non-consumer uses, unless such uses represent
308
+the only significant mode of use of the product.
309
+
310
+  "Installation Information" for a User Product means any methods,
311
+procedures, authorization keys, or other information required to install
312
+and execute modified versions of a covered work in that User Product from
313
+a modified version of its Corresponding Source.  The information must
314
+suffice to ensure that the continued functioning of the modified object
315
+code is in no case prevented or interfered with solely because
316
+modification has been made.
317
+
318
+  If you convey an object code work under this section in, or with, or
319
+specifically for use in, a User Product, and the conveying occurs as
320
+part of a transaction in which the right of possession and use of the
321
+User Product is transferred to the recipient in perpetuity or for a
322
+fixed term (regardless of how the transaction is characterized), the
323
+Corresponding Source conveyed under this section must be accompanied
324
+by the Installation Information.  But this requirement does not apply
325
+if neither you nor any third party retains the ability to install
326
+modified object code on the User Product (for example, the work has
327
+been installed in ROM).
328
+
329
+  The requirement to provide Installation Information does not include a
330
+requirement to continue to provide support service, warranty, or updates
331
+for a work that has been modified or installed by the recipient, or for
332
+the User Product in which it has been modified or installed.  Access to a
333
+network may be denied when the modification itself materially and
334
+adversely affects the operation of the network or violates the rules and
335
+protocols for communication across the network.
336
+
337
+  Corresponding Source conveyed, and Installation Information provided,
338
+in accord with this section must be in a format that is publicly
339
+documented (and with an implementation available to the public in
340
+source code form), and must require no special password or key for
341
+unpacking, reading or copying.
342
+
343
+  7. Additional Terms.
344
+
345
+  "Additional permissions" are terms that supplement the terms of this
346
+License by making exceptions from one or more of its conditions.
347
+Additional permissions that are applicable to the entire Program shall
348
+be treated as though they were included in this License, to the extent
349
+that they are valid under applicable law.  If additional permissions
350
+apply only to part of the Program, that part may be used separately
351
+under those permissions, but the entire Program remains governed by
352
+this License without regard to the additional permissions.
353
+
354
+  When you convey a copy of a covered work, you may at your option
355
+remove any additional permissions from that copy, or from any part of
356
+it.  (Additional permissions may be written to require their own
357
+removal in certain cases when you modify the work.)  You may place
358
+additional permissions on material, added by you to a covered work,
359
+for which you have or can give appropriate copyright permission.
360
+
361
+  Notwithstanding any other provision of this License, for material you
362
+add to a covered work, you may (if authorized by the copyright holders of
363
+that material) supplement the terms of this License with terms:
364
+
365
+    a) Disclaiming warranty or limiting liability differently from the
366
+    terms of sections 15 and 16 of this License; or
367
+
368
+    b) Requiring preservation of specified reasonable legal notices or
369
+    author attributions in that material or in the Appropriate Legal
370
+    Notices displayed by works containing it; or
371
+
372
+    c) Prohibiting misrepresentation of the origin of that material, or
373
+    requiring that modified versions of such material be marked in
374
+    reasonable ways as different from the original version; or
375
+
376
+    d) Limiting the use for publicity purposes of names of licensors or
377
+    authors of the material; or
378
+
379
+    e) Declining to grant rights under trademark law for use of some
380
+    trade names, trademarks, or service marks; or
381
+
382
+    f) Requiring indemnification of licensors and authors of that
383
+    material by anyone who conveys the material (or modified versions of
384
+    it) with contractual assumptions of liability to the recipient, for
385
+    any liability that these contractual assumptions directly impose on
386
+    those licensors and authors.
387
+
388
+  All other non-permissive additional terms are considered "further
389
+restrictions" within the meaning of section 10.  If the Program as you
390
+received it, or any part of it, contains a notice stating that it is
391
+governed by this License along with a term that is a further
392
+restriction, you may remove that term.  If a license document contains
393
+a further restriction but permits relicensing or conveying under this
394
+License, you may add to a covered work material governed by the terms
395
+of that license document, provided that the further restriction does
396
+not survive such relicensing or conveying.
397
+
398
+  If you add terms to a covered work in accord with this section, you
399
+must place, in the relevant source files, a statement of the
400
+additional terms that apply to those files, or a notice indicating
401
+where to find the applicable terms.
402
+
403
+  Additional terms, permissive or non-permissive, may be stated in the
404
+form of a separately written license, or stated as exceptions;
405
+the above requirements apply either way.
406
+
407
+  8. Termination.
408
+
409
+  You may not propagate or modify a covered work except as expressly
410
+provided under this License.  Any attempt otherwise to propagate or
411
+modify it is void, and will automatically terminate your rights under
412
+this License (including any patent licenses granted under the third
413
+paragraph of section 11).
414
+
415
+  However, if you cease all violation of this License, then your
416
+license from a particular copyright holder is reinstated (a)
417
+provisionally, unless and until the copyright holder explicitly and
418
+finally terminates your license, and (b) permanently, if the copyright
419
+holder fails to notify you of the violation by some reasonable means
420
+prior to 60 days after the cessation.
421
+
422
+  Moreover, your license from a particular copyright holder is
423
+reinstated permanently if the copyright holder notifies you of the
424
+violation by some reasonable means, this is the first time you have
425
+received notice of violation of this License (for any work) from that
426
+copyright holder, and you cure the violation prior to 30 days after
427
+your receipt of the notice.
428
+
429
+  Termination of your rights under this section does not terminate the
430
+licenses of parties who have received copies or rights from you under
431
+this License.  If your rights have been terminated and not permanently
432
+reinstated, you do not qualify to receive new licenses for the same
433
+material under section 10.
434
+
435
+  9. Acceptance Not Required for Having Copies.
436
+
437
+  You are not required to accept this License in order to receive or
438
+run a copy of the Program.  Ancillary propagation of a covered work
439
+occurring solely as a consequence of using peer-to-peer transmission
440
+to receive a copy likewise does not require acceptance.  However,
441
+nothing other than this License grants you permission to propagate or
442
+modify any covered work.  These actions infringe copyright if you do
443
+not accept this License.  Therefore, by modifying or propagating a
444
+covered work, you indicate your acceptance of this License to do so.
445
+
446
+  10. Automatic Licensing of Downstream Recipients.
447
+
448
+  Each time you convey a covered work, the recipient automatically
449
+receives a license from the original licensors, to run, modify and
450
+propagate that work, subject to this License.  You are not responsible
451
+for enforcing compliance by third parties with this License.
452
+
453
+  An "entity transaction" is a transaction transferring control of an
454
+organization, or substantially all assets of one, or subdividing an
455
+organization, or merging organizations.  If propagation of a covered
456
+work results from an entity transaction, each party to that
457
+transaction who receives a copy of the work also receives whatever
458
+licenses to the work the party's predecessor in interest had or could
459
+give under the previous paragraph, plus a right to possession of the
460
+Corresponding Source of the work from the predecessor in interest, if
461
+the predecessor has it or can get it with reasonable efforts.
462
+
463
+  You may not impose any further restrictions on the exercise of the
464
+rights granted or affirmed under this License.  For example, you may
465
+not impose a license fee, royalty, or other charge for exercise of
466
+rights granted under this License, and you may not initiate litigation
467
+(including a cross-claim or counterclaim in a lawsuit) alleging that
468
+any patent claim is infringed by making, using, selling, offering for
469
+sale, or importing the Program or any portion of it.
470
+
471
+  11. Patents.
472
+
473
+  A "contributor" is a copyright holder who authorizes use under this
474
+License of the Program or a work on which the Program is based.  The
475
+work thus licensed is called the contributor's "contributor version".
476
+
477
+  A contributor's "essential patent claims" are all patent claims
478
+owned or controlled by the contributor, whether already acquired or
479
+hereafter acquired, that would be infringed by some manner, permitted
480
+by this License, of making, using, or selling its contributor version,
481
+but do not include claims that would be infringed only as a
482
+consequence of further modification of the contributor version.  For
483
+purposes of this definition, "control" includes the right to grant
484
+patent sublicenses in a manner consistent with the requirements of
485
+this License.
486
+
487
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+patent license under the contributor's essential patent claims, to
489
+make, use, sell, offer for sale, import and otherwise run, modify and
490
+propagate the contents of its contributor version.
491
+
492
+  In the following three paragraphs, a "patent license" is any express
493
+agreement or commitment, however denominated, not to enforce a patent
494
+(such as an express permission to practice a patent or covenant not to
495
+sue for patent infringement).  To "grant" such a patent license to a
496
+party means to make such an agreement or commitment not to enforce a
497
+patent against the party.
498
+
499
+  If you convey a covered work, knowingly relying on a patent license,
500
+and the Corresponding Source of the work is not available for anyone
501
+to copy, free of charge and under the terms of this License, through a
502
+publicly available network server or other readily accessible means,
503
+then you must either (1) cause the Corresponding Source to be so
504
+available, or (2) arrange to deprive yourself of the benefit of the
505
+patent license for this particular work, or (3) arrange, in a manner
506
+consistent with the requirements of this License, to extend the patent
507
+license to downstream recipients.  "Knowingly relying" means you have
508
+actual knowledge that, but for the patent license, your conveying the
509
+covered work in a country, or your recipient's use of the covered work
510
+in a country, would infringe one or more identifiable patents in that
511
+country that you have reason to believe are valid.
512
+
513
+  If, pursuant to or in connection with a single transaction or
514
+arrangement, you convey, or propagate by procuring conveyance of, a
515
+covered work, and grant a patent license to some of the parties
516
+receiving the covered work authorizing them to use, propagate, modify
517
+or convey a specific copy of the covered work, then the patent license
518
+you grant is automatically extended to all recipients of the covered
519
+work and works based on it.
520
+
521
+  A patent license is "discriminatory" if it does not include within
522
+the scope of its coverage, prohibits the exercise of, or is
523
+conditioned on the non-exercise of one or more of the rights that are
524
+specifically granted under this License.  You may not convey a covered
525
+work if you are a party to an arrangement with a third party that is
526
+in the business of distributing software, under which you make payment
527
+to the third party based on the extent of your activity of conveying
528
+the work, and under which the third party grants, to any of the
529
+parties who would receive the covered work from you, a discriminatory
530
+patent license (a) in connection with copies of the covered work
531
+conveyed by you (or copies made from those copies), or (b) primarily
532
+for and in connection with specific products or compilations that
533
+contain the covered work, unless you entered into that arrangement,
534
+or that patent license was granted, prior to 28 March 2007.
535
+
536
+  Nothing in this License shall be construed as excluding or limiting
537
+any implied license or other defenses to infringement that may
538
+otherwise be available to you under applicable patent law.
539
+
540
+  12. No Surrender of Others' Freedom.
541
+
542
+  If conditions are imposed on you (whether by court order, agreement or
543
+otherwise) that contradict the conditions of this License, they do not
544
+excuse you from the conditions of this License.  If you cannot convey a
545
+covered work so as to satisfy simultaneously your obligations under this
546
+License and any other pertinent obligations, then as a consequence you may
547
+not convey it at all.  For example, if you agree to terms that obligate you
548
+to collect a royalty for further conveying from those to whom you convey
549
+the Program, the only way you could satisfy both those terms and this
550
+License would be to refrain entirely from conveying the Program.
551
+
552
+  13. Use with the GNU Affero General Public License.
553
+
554
+  Notwithstanding any other provision of this License, you have
555
+permission to link or combine any covered work with a work licensed
556
+under version 3 of the GNU Affero General Public License into a single
557
+combined work, and to convey the resulting work.  The terms of this
558
+License will continue to apply to the part which is the covered work,
559
+but the special requirements of the GNU Affero General Public License,
560
+section 13, concerning interaction through a network will apply to the
561
+combination as such.
562
+
563
+  14. Revised Versions of this License.
564
+
565
+  The Free Software Foundation may publish revised and/or new versions of
566
+the GNU General Public License from time to time.  Such new versions will
567
+be similar in spirit to the present version, but may differ in detail to
568
+address new problems or concerns.
569
+
570
+  Each version is given a distinguishing version number.  If the
571
+Program specifies that a certain numbered version of the GNU General
572
+Public License "or any later version" applies to it, you have the
573
+option of following the terms and conditions either of that numbered
574
+version or of any later version published by the Free Software
575
+Foundation.  If the Program does not specify a version number of the
576
+GNU General Public License, you may choose any version ever published
577
+by the Free Software Foundation.
578
+
579
+  If the Program specifies that a proxy can decide which future
580
+versions of the GNU General Public License can be used, that proxy's
581
+public statement of acceptance of a version permanently authorizes you
582
+to choose that version for the Program.
583
+
584
+  Later license versions may give you additional or different
585
+permissions.  However, no additional obligations are imposed on any
586
+author or copyright holder as a result of your choosing to follow a
587
+later version.
588
+
589
+  15. Disclaimer of Warranty.
590
+
591
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+  16. Limitation of Liability.
601
+
602
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+SUCH DAMAGES.
611
+
612
+  17. Interpretation of Sections 15 and 16.
613
+
614
+  If the disclaimer of warranty and limitation of liability provided
615
+above cannot be given local legal effect according to their terms,
616
+reviewing courts shall apply local law that most closely approximates
617
+an absolute waiver of all civil liability in connection with the
618
+Program, unless a warranty or assumption of liability accompanies a
619
+copy of the Program in return for a fee.
620
+
621
+                     END OF TERMS AND CONDITIONS
622
+
623
+            How to Apply These Terms to Your New Programs
624
+
625
+  If you develop a new program, and you want it to be of the greatest
626
+possible use to the public, the best way to achieve this is to make it
627
+free software which everyone can redistribute and change under these terms.
628
+
629
+  To do so, attach the following notices to the program.  It is safest
630
+to attach them to the start of each source file to most effectively
631
+state the exclusion of warranty; and each file should have at least
632
+the "copyright" line and a pointer to where the full notice is found.
633
+
634
+    <one line to give the program's name and a brief idea of what it does.>
635
+    Copyright (C) <year>  <name of author>
636
+
637
+    This program is free software: you can redistribute it and/or modify
638
+    it under the terms of the GNU General Public License as published by
639
+    the Free Software Foundation, either version 3 of the License, or
640
+    (at your option) any later version.
641
+
642
+    This program is distributed in the hope that it will be useful,
643
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
645
+    GNU General Public License for more details.
646
+
647
+    You should have received a copy of the GNU General Public License
648
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
649
+
650
+Also add information on how to contact you by electronic and paper mail.
651
+
652
+  If the program does terminal interaction, make it output a short
653
+notice like this when it starts in an interactive mode:
654
+
655
+    <program>  Copyright (C) <year>  <name of author>
656
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+    This is free software, and you are welcome to redistribute it
658
+    under certain conditions; type `show c' for details.
659
+
660
+The hypothetical commands `show w' and `show c' should show the appropriate
661
+parts of the General Public License.  Of course, your program's commands
662
+might be different; for a GUI interface, you would use an "about box".
663
+
664
+  You should also get your employer (if you work as a programmer) or school,
665
+if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+For more information on this, and how to apply and follow the GNU GPL, see
667
+<https://www.gnu.org/licenses/>.
668
+
669
+  The GNU General Public License does not permit incorporating your program
670
+into proprietary programs.  If your program is a subroutine library, you
671
+may consider it more useful to permit linking proprietary applications with
672
+the library.  If this is what you want to do, use the GNU Lesser General
673
+Public License instead of this License.  But first, please read
674
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

+ 131
- 0
README.md View File

@@ -0,0 +1,131 @@
1
+# Pi Pico Volcano Remote Control Gadget
2
+
3
+For use with Raspberry Pi Pico W boards with the [Waveshare Pico LCD 1.3](https://www.waveshare.com/wiki/Pico-LCD-1.3) and the [Pimoroni Pico Lipo Shim](https://shop.pimoroni.com/products/pico-lipo-shim).
4
+
5
+Adapted from the [tinyusb-cdc-example](https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/src/main.c), [adc example](https://github.com/raspberrypi/pico-examples/tree/master/adc/read_vsys), [standalone client example](https://github.com/raspberrypi/pico-examples/blob/master/pico_w/bt/standalone/client.c) and my [Trackball firmware](https://git.xythobuz.de/thomas/Trackball).
6
+
7
+## Quick Start
8
+
9
+When compiling for the first time, check out the required git submodules.
10
+
11
+    git submodule update --init
12
+    cd pico-sdk
13
+    git submodule update --init
14
+
15
+Then do this to build.
16
+
17
+    mkdir build
18
+    cd build
19
+    cmake -DPICO_BOARD=pico_w ..
20
+    make -j4 gadget
21
+
22
+And flash the resulting `gadget.uf2` file to your Pico as usual.
23
+
24
+For convenience you can use the included `flash.sh`, as long as you flashed the binary manually once before.
25
+
26
+    make -j4 gadget
27
+    ../flash.sh gadget.uf2
28
+
29
+This will use the mass storage bootloader to upload a new uf2 image.
30
+
31
+For old-school debugging a serial port will be presented by the firmware.
32
+Open it using eg. `picocom`, or with the included `debug.sh` script.
33
+
34
+For dependencies to compile, on Arch install these.
35
+
36
+    sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib picocom cmake
37
+
38
+## Proper Debugging
39
+
40
+You can also use the SWD interface for proper hardware debugging.
41
+
42
+This follows the instructions from the [RP2040 Getting Started document](https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf) from chapter 5 and 6.
43
+
44
+For ease of reading the disassembly, create a debug build.
45
+
46
+    mkdir build_debug
47
+    cd build_debug
48
+    cmake -DPICO_BOARD=pico_w -DCMAKE_BUILD_TYPE=Debug ..
49
+    make -j4 gadget
50
+
51
+You need a hardware SWD probe.
52
+This can be made from another Pico, see Appendix A in the document linked above.
53
+For this you need to compile the `picoprobe` firmware, like this.
54
+
55
+    git clone https://github.com/raspberrypi/picoprobe.git
56
+    cd picoprobe
57
+
58
+    git submodule update --init
59
+    mkdir build
60
+    cd build
61
+
62
+    PICO_SDK_PATH=../../../pico-sdk cmake ..
63
+    make -j4
64
+
65
+    cd ../.. # back to build_debug directory from before
66
+
67
+And flash the resulting `picoprobe.uf2` to your probe.
68
+Connect `GP2` of the probe to `SWCLK` of the target and `GP3` of the probe to `SWDIO` of the target.
69
+Of course you also need to connect GND between both.
70
+
71
+You need some dependencies, mainly `gdb-multiarch` and the RP2040 fork of `OpenOCD`.
72
+
73
+    sudo apt install gdb-multiarch   # Debian / Ubuntu
74
+    sudo pacman -S arm-none-eabi-gdb # Arch Linux
75
+
76
+    git clone https://github.com/raspberrypi/openocd.git --branch rp2040 --recursive --depth=1
77
+    cd openocd
78
+
79
+    # install udev rules
80
+    sudo cp contrib/60-openocd.rules /etc/udev/rules.d
81
+    sudo udevadm control --reload-rules && sudo udevadm trigger
82
+
83
+    ./bootstrap
84
+    ./configure --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
85
+    make -j4
86
+
87
+    cd .. # back to build_debug directory from before
88
+
89
+Now we can flash a firmware image via OpenOCD.
90
+
91
+    ./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c" -c "program gadget.elf verify reset exit"
92
+
93
+And also start a GDB debugging session.
94
+
95
+    ./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c"
96
+    arm-none-eabi-gdb gadget.elf
97
+    target extended-remote localhost:3333
98
+
99
+    load # program elf into flash
100
+    monitor reset init # put into clean initial state
101
+    continue # start program
102
+
103
+These commands have also been put in the `flash_swd.sh` and `debug_swd.sh` scripts, respectively.
104
+They require the `build_debug` folder where you checked out and built OpenOCD.
105
+Here are some [general GDB tips](https://beej.us/guide/bggdb/).
106
+
107
+## License
108
+
109
+The firmware itself is licensed as GPLv3.
110
+I initially adapted it from my own [Trackball](https://git.xythobuz.de/thomas/Trackball) project.
111
+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.
112
+Some code is adapted from the TinyUSB examples.
113
+And the project uses the [FatFS library](https://github.com/abbrev/fatfs), licensed as BSD 1-clause.
114
+Also included are the [MCUFont library](https://github.com/mcufont/mcufont) and the [st7789 library](https://github.com/hepingood/st7789), both licensed under the MIT license.
115
+It also uses the [BTstack](https://github.com/bluekitchen/btstack/blob/master/LICENSE) included with the Pico SDK, following their [license terms](https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_btstack/LICENSE.RP).
116
+
117
+The case design is also licensed as GPLv3.
118
+It uses a [Pi Pico case model](https://www.printables.com/model/210898-raspberry-pi-pico-case) licensed as CC-BY-NC-SA.
119
+But this is only used for visualization purposes and doesn't influence the 3D model at all.
120
+
121
+    This program is free software: you can redistribute it and/or modify
122
+    it under the terms of the GNU General Public License as published by
123
+    the Free Software Foundation, either version 3 of the License, or
124
+    (at your option) any later version.
125
+
126
+    This program is distributed in the hope that it will be useful,
127
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
128
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
129
+    GNU General Public License for more details.
130
+
131
+    See <http://www.gnu.org/licenses/>.

+ 33
- 0
case/case.scad View File

@@ -0,0 +1,33 @@
1
+// https://www.waveshare.com/wiki/Pico-LCD-1.3
2
+lcd_w = 52.0;
3
+lcd_h = 26.5;
4
+
5
+lcd_d = 1.0; // todo
6
+
7
+// https://www.printables.com/model/210898-raspberry-pi-pico-case
8
+use <pico_case.scad>
9
+p_w = 21;
10
+p_h = 51;
11
+p_t = 1.0;
12
+
13
+pico_header_h = 2.0; // todo
14
+lcd_header_h = 10.0; // todo
15
+
16
+header_h = pico_header_h + lcd_header_h;
17
+
18
+module lcd() {
19
+    color("blue")
20
+    translate([-lcd_h / 2, -lcd_w / 2, 0])
21
+    cube([lcd_h, lcd_w, lcd_d]);
22
+}
23
+
24
+module hw() {
25
+    translate([0, 0, header_h])
26
+    lcd();
27
+    
28
+    translate([p_w / 2, -p_h / 2, 0])
29
+    rotate([0, 180, 0])
30
+    pico();
31
+}
32
+
33
+hw();

+ 245
- 0
case/pico_case.scad View File

@@ -0,0 +1,245 @@
1
+resolution = 20; //[10, 20, 30, 50, 100]
2
+$fn = resolution;
3
+
4
+show_frame = false; // [true, false]
5
+show_pico = true; // [true, false]
6
+show_lid = false; // [true, false]
7
+show_button = false; // [true, false]
8
+
9
+module rounded_plate(w, h, t, d) {
10
+    translate([0, (d/2), 0])
11
+    cube([w, (h-d), t]);
12
+    translate([(d/2), 0, 0])
13
+    cube([(w-d), h, t]);
14
+    translate([(d/2), (d/2), 0])
15
+    cylinder(h=t, d=d);
16
+    translate([w-(d/2), (d/2), 0])
17
+    cylinder(h=t, d=d);
18
+    translate([(d/2), h-(d/2), 0])
19
+    cylinder(h=t, d=d);
20
+    translate([w-(d/2), h-(d/2), 0])
21
+    cylinder(h=t, d=d);
22
+}
23
+
24
+module usb_port() {
25
+    translate([0.3, 0, 0])
26
+    color("grey")
27
+    difference() {
28
+        union() {
29
+            cube([7.4, 6, 2.7]);
30
+            translate([-0.3, 5.4, -0.1])
31
+            cube([8, 0.6, 2.9]);
32
+        }
33
+    }
34
+}
35
+
36
+module switch() {
37
+    color("grey")
38
+    cube([3.5, 4.5, 1]);
39
+    color("white")
40
+    translate([(3.5/2), (4.5/2), 0])
41
+    cylinder(h=1.5, d=3);
42
+}
43
+
44
+p_w = 21;
45
+p_h = 51;
46
+p_t = 1.0;
47
+os = 0.35;
48
+b = 2;
49
+
50
+module pico() {
51
+    translate([((p_w-8)/2), ((p_h+1.3)-6), p_t])
52
+    usb_port();
53
+
54
+    translate([5.25, 36.6, 0.6])
55
+    switch();
56
+
57
+    difference() {
58
+        color("green")
59
+        cube([p_w, p_h, 1]);
60
+
61
+        translate([((p_w/2)-5.7), 2, -0.01])
62
+        cylinder(h=p_t+0.02, d=2.1);
63
+       
64
+        translate([(p_w-((p_w/2)-5.7)), 2, -0.01])
65
+        cylinder(h=p_t+0.02, d=2.1);
66
+
67
+        translate([((p_w/2)-5.7), (p_h-2), -0.01])
68
+        cylinder(h=p_t+0.02, d=2.1);
69
+
70
+        translate([(p_w-((p_w/2)-5.7)), (p_h-2), -0.01])
71
+        cylinder(h=p_t+0.02, d=2.1);
72
+    }
73
+}
74
+
75
+if (show_pico) {
76
+    translate([(os+b), (os+b), 3.4])
77
+    pico();
78
+}
79
+
80
+if (show_frame) {
81
+    union() {
82
+        difference() {
83
+            // Outer frame
84
+            rounded_plate(p_w+(2*(os+b)), p_h+(2*(os+b)), 10, (2*(os+b)));
85
+            
86
+            // Board cut-out
87
+            translate([b, b, -1])
88
+            cube([p_w+(2*os), p_h+(2*os), 12]);
89
+            
90
+            // USB port cut-out
91
+//            translate([b+os+((p_w-10)/2), b+os+((p_h+1)-6), 3.4])
92
+//            cube([10, 8, 4.7]);
93
+            translate([b+os+((p_w-10)/2), b+(2*os)+p_h-1, 8.1])
94
+            rotate([-90, 0, 0])
95
+            rounded_plate(10, 4.7, 4.7, 2);
96
+            
97
+            // Lid release cut-out
98
+            difference() {
99
+                union() {
100
+                    translate([b+os+((p_w-10)/2), -1, 10-1])
101
+                    cube([10, 8, 2]);
102
+                    translate([b+os+((p_w-6)/2), -1, 10-1])
103
+                    rotate([-90, 0, 0])
104
+                    cylinder(h=4, d=2); 
105
+                    translate([b+os+((p_w-6)/2), -1, 10-2])
106
+                    cube([6, 8, 3]);
107
+                    translate([b+os+((p_w+6)/2), -1, 10-1])
108
+                    rotate([-90, 0, 0])
109
+                    cylinder(h=4, d=2); 
110
+                }
111
+                translate([b+os+((p_w+10)/2), -1, 10-1])
112
+                rotate([-90, 0, 0])
113
+                cylinder(h=4, d=2); 
114
+                translate([b+os+((p_w-10)/2), -1, 10-1])
115
+                rotate([-90, 0, 0])
116
+                cylinder(h=4, d=2); 
117
+            }
118
+            
119
+            // Outer frame
120
+            translate([1, 1, 10-1.2])
121
+            rounded_plate(p_w+(2*(os+b))-2, p_h+(2*(os+b))-2, 2, (2*(os+b))-2);
122
+
123
+            // Left top retainer cut-out
124
+            translate([b+os+(p_w/2)-(3.2/2)-7.1, b+p_h+(2*os), 10-3+0.2])
125
+            cube([3.2, 0.7, 1.0]);
126
+
127
+            // Right top retainer cut-out
128
+            translate([b+os+(p_w/2)-(3.2/2)+7.1, b+p_h+(2*os), 10-3+0.2])
129
+            cube([3.2, 0.7, 1.0]);
130
+
131
+            // Left bottom retainer cut-out
132
+            translate([b+os+(p_w/2)-(4/2)-7.1, b+os-0.7, 10-3+0.2])
133
+            cube([4, 0.7, 1.0]);
134
+
135
+            // Right bottom retainer cut-out
136
+            translate([b+os+(p_w/2)-(4/2)+7.1, b+os-0.7, 10-3+0.2])
137
+            cube([4, 0.7, 1.0]);
138
+
139
+            // Left retainer cut-out
140
+            translate([b-0.7, b+os+(p_h/2)-2, 10-3+0.2])
141
+            cube([0.7, 4, 1.0]);
142
+
143
+            // Right retainer cut-out
144
+            translate([b+(2*os)+p_w, b+os+(p_h/2)-2, 10-3+0.2])
145
+            cube([0.7, 4, 1.0]);
146
+        }
147
+        
148
+        // Left support rail
149
+        translate([b+os+(p_w/2)-(3/2)-5.5, 0, 0])
150
+        cube([3, p_h+(2*(os+b)), 3.4]);
151
+       
152
+        // Right support rail
153
+        translate([b+os+(p_w/2)-(3/2)+5.5, 0, 0])
154
+        cube([3, p_h+(2*(os+b)), 3.4]);
155
+
156
+        // Left top retainer
157
+        translate([b+os+(p_w/2)-(2.2/2)-6.1, b+p_h+(2*os)-0.6, 3.4+1+0.5])
158
+        cube([2.2, 0.6, 0.8]);
159
+
160
+        // Right top retainer
161
+        translate([b+os+(p_w/2)-(2.2/2)+6.1, b+p_h+(2*os)-0.6, 3.4+1+0.5])
162
+        cube([2.2, 0.6, 0.8]);
163
+
164
+        // Left bottom retainer
165
+        translate([b+os+(p_w/2)-(3/2)-5.7, b, 3.4+1+0.])
166
+        cube([3, 0.6, 0.8]);
167
+
168
+        // Right bottom retainer
169
+        translate([b+os+(p_w/2)-(3/2)+5.7, b, 3.4+1+0.5])
170
+        cube([3, 0.6, 0.8]);
171
+    }
172
+}
173
+
174
+if (show_lid) {
175
+    difference() {
176
+        union() {
177
+            translate([1+os, 1+os, 10-1.2])
178
+            rounded_plate(p_w+(2*b)-2, p_h+(2*b)-2, 1, (2*b)-2);
179
+            translate([(os+b), (os+b), 10-3])
180
+            rounded_plate(p_w, p_h, 2, (2*b)-3);
181
+            
182
+            // Left top retainer
183
+            translate([b+os+(p_w/2)-(2.2/2)-7.1, b+p_h+os, 10-3+0.4])
184
+            cube([2.2, 0.6, 0.6]);
185
+
186
+            // Right top retainer
187
+            translate([b+os+(p_w/2)-(2.2/2)+7.1, b+p_h+os, 10-3+0.4])
188
+            cube([2.2, 0.6, 0.6]);
189
+
190
+            // Left bottom retainer
191
+            translate([b+os+(p_w/2)-(3/2)-7.1, b+os-0.5, 10-3+0.3])
192
+            cube([3, 0.6, 0.6]);
193
+
194
+            // Right bottom retainer
195
+            translate([b+os+(p_w/2)-(3/2)+7.1, b+os-0.5, 10-3+0.3])
196
+            cube([3, 0.6, 0.6]);
197
+
198
+            // Left retainer
199
+            translate([b+os-0.6, b+os+(p_h/2)-1.5, 10-3+0.3])
200
+            cube([0.6, 3, 0.6]);            
201
+
202
+            // Right retainer
203
+            translate([b+os+p_w, b+os+(p_h/2)-1.5, 10-3+0.3])
204
+            cube([0.6, 3, 0.6]);            
205
+        }
206
+
207
+        // USB port cut-out
208
+        translate([b+os+((p_w-10)/2), b+p_h+(2*os)-2, 10-4.2])
209
+        cube([10, 8, 2.4]);
210
+
211
+        // Lid release cut-out
212
+        translate([b+os+((p_w-10)/2), -1, 10-4.2])
213
+        cube([10, 8, 3]);
214
+        
215
+        // Switch cut-out
216
+        translate([(os+b)+7, (os+b)+38.85, 0])
217
+        cylinder(h=10, d=5);
218
+        
219
+        // Inset
220
+        translate([(os+b)+1, (os+b)+1, 10-4])
221
+        cube([p_w-2, p_h-2, 3]);
222
+    }
223
+    // Switch surround
224
+    translate([(os+b), (os+b)+38.85-6, 10-2])
225
+    cube([p_w, 1, 1]);    
226
+
227
+    translate([(os+b), (os+b)+38.85+5, 10-2])
228
+    cube([p_w, 1, 1]);    
229
+
230
+}
231
+
232
+
233
+if (show_button) {
234
+    color("red")
235
+    union() {
236
+        translate([(os+b)+7, (os+b)+38.85, 7.5])
237
+        cylinder(h=2.3, d=4.4);
238
+        difference() {
239
+            translate([(os+b)+7, (os+b)+38.85, 6.5])
240
+            cylinder(h=2, d=7.6);
241
+            translate([(os+b)+7, (os+b)+38.85, 6.5])
242
+            cylinder(h=1, d=6.6);
243
+        }
244
+    }
245
+}

+ 18
- 0
debug.sh View File

@@ -0,0 +1,18 @@
1
+#!/bin/bash
2
+set -euo pipefail
3
+
4
+SERIAL=/dev/serial/by-id/usb-xythobuz_VolcanoRC_*
5
+
6
+echo -n Waiting for serial port to appear
7
+until [ -e $SERIAL ]
8
+do
9
+    echo -n .
10
+    sleep 1
11
+done
12
+echo
13
+
14
+echo Opening picocom terminal
15
+echo "[C-a] [C-x] to exit"
16
+echo
17
+
18
+picocom -q --omap crcrlf --imap lfcrlf $SERIAL

+ 31
- 0
debug_swd.sh View File

@@ -0,0 +1,31 @@
1
+#!/bin/bash
2
+set -euo pipefail
3
+
4
+cd "$(dirname "$0")"
5
+
6
+echo Starting OpenOCD in background
7
+echo "\n\nstarting new openocd" >> openocd.log
8
+./build_debug/openocd/src/openocd -s build_debug/openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c" >> openocd.log 2>&1 &
9
+OPENOCD_PID=$!
10
+
11
+# give OpenOCD some time to output stuff
12
+sleep 1
13
+
14
+echo -n Waiting for debugger to appear
15
+while ! netstat -tna | grep 'LISTEN\>' | grep -q ':3333\>'; do
16
+    echo -n .
17
+    sleep 1
18
+done
19
+
20
+echo Starting GDB
21
+arm-none-eabi-gdb \
22
+-ex "set history save" \
23
+-ex "show print pretty" \
24
+-ex "target extended-remote localhost:3333" \
25
+-ex "tui new-layout default src 1 status 1 cmd 2" \
26
+-ex "tui layout default" \
27
+-ex "tui enable" \
28
+$1
29
+
30
+echo Killing OpenOCD instance in background
31
+kill $OPENOCD_PID

+ 1
- 0
fatfs

@@ -0,0 +1 @@
1
+Subproject commit b11f08931929e5f2f1fe8a3a2c0bd16d222b5625

+ 28
- 0
flash.sh View File

@@ -0,0 +1,28 @@
1
+#!/bin/bash
2
+set -euo pipefail
3
+
4
+SERIAL=/dev/serial/by-id/usb-xythobuz_VolcanoRC_*
5
+DISK=/dev/disk/by-label/RPI-RP2
6
+MOUNT=/mnt/tmp
7
+
8
+if [ ! -e $DISK ]
9
+then
10
+    echo Resetting Raspberry Pi Pico
11
+    echo -n -e "\\x18" > $SERIAL
12
+fi
13
+
14
+echo -n Waiting for disk to appear
15
+until [ -e $DISK ]
16
+do
17
+    echo -n .
18
+    sleep 1
19
+done
20
+echo
21
+
22
+echo Mounting bootloader disk
23
+sudo mount $DISK $MOUNT
24
+
25
+echo Copying binary
26
+sudo cp $1 $MOUNT
27
+
28
+echo Done

+ 6
- 0
flash_swd.sh View File

@@ -0,0 +1,6 @@
1
+#!/bin/bash
2
+set -euo pipefail
3
+
4
+cd "$(dirname "$0")"
5
+
6
+./build_debug/openocd/src/openocd -s build_debug/openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c" -c "program $1 verify reset exit"

+ 61
- 0
include/ble.h View File

@@ -0,0 +1,61 @@
1
+/*
2
+ * ble.h
3
+ *
4
+ * Copyright (c) 2023 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 __BLE_H__
20
+#define __BLE_H__
21
+
22
+#include "btstack.h"
23
+
24
+#define BLE_MAX_NAME_LENGTH 32
25
+#define BLE_MAX_DATA_LENGTH 26
26
+#define BLE_MAX_SCAN_RESULTS 32
27
+#define BLE_MAX_VALUE_LEN 64
28
+
29
+enum ble_scan_mode {
30
+    BLE_SCAN_OFF    = 0,
31
+    BLE_SCAN_ON     = 1,
32
+    BLE_SCAN_TOGGLE = 2,
33
+};
34
+
35
+struct ble_scan_result {
36
+    bool set;
37
+    uint32_t time;
38
+
39
+    bd_addr_t addr;
40
+    bd_addr_type_t type;
41
+    int8_t rssi;
42
+    char name[BLE_MAX_NAME_LENGTH + 1];
43
+    uint8_t data[BLE_MAX_DATA_LENGTH];
44
+    size_t data_len;
45
+};
46
+
47
+void ble_init(void);
48
+bool ble_is_ready(void);
49
+
50
+void ble_scan(enum ble_scan_mode mode);
51
+int32_t ble_get_scan_results(struct ble_scan_result *buf, uint16_t len);
52
+
53
+void ble_connect(bd_addr_t addr, bd_addr_type_t type);
54
+bool ble_is_connected(void);
55
+void ble_disconnect(void);
56
+
57
+int32_t ble_read(const uint8_t *characteristic, uint8_t *buff, uint16_t buff_len);
58
+int8_t ble_write(const uint8_t *service, const uint8_t *characteristic,
59
+                 uint8_t *buff, uint16_t buff_len);
60
+
61
+#endif // __BLE_H__

+ 58
- 0
include/btstack_config.h View File

@@ -0,0 +1,58 @@
1
+#ifndef _PICO_BTSTACK_BTSTACK_CONFIG_H
2
+#define _PICO_BTSTACK_BTSTACK_CONFIG_H
3
+
4
+#ifndef ENABLE_BLE
5
+#error Please link to pico_btstack_ble
6
+#endif
7
+
8
+// BTstack features that can be enabled
9
+#define ENABLE_LE_PERIPHERAL
10
+#define ENABLE_LOG_INFO
11
+#define ENABLE_LOG_ERROR
12
+#define ENABLE_PRINTF_HEXDUMP
13
+
14
+// for the client
15
+#if RUNNING_AS_CLIENT
16
+#define ENABLE_LE_CENTRAL
17
+#define MAX_NR_GATT_CLIENTS 1
18
+#else
19
+#define MAX_NR_GATT_CLIENTS 0
20
+#endif
21
+
22
+// BTstack configuration. buffers, sizes, ...
23
+#define HCI_OUTGOING_PRE_BUFFER_SIZE 4
24
+#define HCI_ACL_PAYLOAD_SIZE (255 + 4)
25
+#define HCI_ACL_CHUNK_SIZE_ALIGNMENT 4
26
+#define MAX_NR_HCI_CONNECTIONS 1
27
+#define MAX_NR_SM_LOOKUP_ENTRIES 3
28
+#define MAX_NR_WHITELIST_ENTRIES 16
29
+#define MAX_NR_LE_DEVICE_DB_ENTRIES 16
30
+
31
+// Limit number of ACL/SCO Buffer to use by stack to avoid cyw43 shared bus overrun
32
+#define MAX_NR_CONTROLLER_ACL_BUFFERS 3
33
+#define MAX_NR_CONTROLLER_SCO_PACKETS 3
34
+
35
+// Enable and configure HCI Controller to Host Flow Control to avoid cyw43 shared bus overrun
36
+#define ENABLE_HCI_CONTROLLER_TO_HOST_FLOW_CONTROL
37
+#define HCI_HOST_ACL_PACKET_LEN (255+4)
38
+#define HCI_HOST_ACL_PACKET_NUM 3
39
+#define HCI_HOST_SCO_PACKET_LEN 120
40
+#define HCI_HOST_SCO_PACKET_NUM 3
41
+
42
+// Link Key DB and LE Device DB using TLV on top of Flash Sector interface
43
+#define NVM_NUM_DEVICE_DB_ENTRIES 16
44
+#define NVM_NUM_LINK_KEYS 16
45
+
46
+// We don't give btstack a malloc, so use a fixed-size ATT DB.
47
+#define MAX_ATT_DB_SIZE 512
48
+
49
+// BTstack HAL configuration
50
+#define HAVE_EMBEDDED_TIME_MS
51
+// map btstack_assert onto Pico SDK assert()
52
+#define HAVE_ASSERT
53
+// Some USB dongles take longer to respond to HCI reset (e.g. BCM20702A).
54
+#define HCI_RESET_RESEND_TIMEOUT_MS 1000
55
+#define ENABLE_SOFTWARE_AES128
56
+#define ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS
57
+
58
+#endif // _PICO_BTSTACK_BTSTACK_CONFIG_H

+ 42
- 0
include/buttons.h View File

@@ -0,0 +1,42 @@
1
+/*
2
+ * buttons.h
3
+ *
4
+ * Copyright (c) 2022 - 2023 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 __BUTTONS_H__
20
+#define __BUTTONS_H__
21
+
22
+#include <stdbool.h>
23
+
24
+enum buttons {
25
+    BTN_A = 0,
26
+    BTN_B,
27
+    BTN_X,
28
+    BTN_Y,
29
+    BTN_UP,
30
+    BTN_DOWN,
31
+    BTN_LEFT,
32
+    BTN_RIGHT,
33
+    BTN_ENTER,
34
+    NUM_BTNS // count
35
+};
36
+
37
+void buttons_init(void);
38
+void buttons_callback(void (*fp)(enum buttons, bool));
39
+void buttons_run(void);
40
+
41
+#endif // __BUTTONS_H__
42
+

+ 48
- 0
include/config.h View File

@@ -0,0 +1,48 @@
1
+/*
2
+ * config.h
3
+ *
4
+ * Copyright (c) 2022 - 2023 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 MENU_PREFER_VOLCANO
23
+//#define MENU_PREFER_CRAFTY
24
+
25
+#define WATCHDOG_PERIOD_MS 1000
26
+
27
+// ASCII 0x18 = CAN (cancel)
28
+#define ENTER_BOOTLOADER_MAGIC 0x18
29
+
30
+//#define DISABLE_CDC_DTR_CHECK
31
+#define DEBOUNCE_DELAY_MS 5
32
+
33
+#define SERIAL_WRITES_BLOCK_WHEN_BUFFER_FULL
34
+
35
+#define DEBUG_DISK_WRITE_SOURCES
36
+
37
+#define DISK_BLOCK_SIZE 512
38
+
39
+#ifdef DEBUG_DISK_WRITE_SOURCES
40
+#define DISK_BLOCK_COUNT (256 + 128)
41
+#else // DEBUG_DISK_WRITE_SOURCES
42
+#define DISK_BLOCK_COUNT 256
43
+#endif // DEBUG_DISK_WRITE_SOURCES
44
+
45
+//#define TEST_VOLCANO_AUTO_CONNECT "xx:xx:xx:xx:xx:xx 1"
46
+//#define TEST_CRAFTY_AUTO_CONNECT "xx:xx:xx:xx:xx:xx 0"
47
+
48
+#endif // __CONFIG_H__

+ 26
- 0
include/console.h View File

@@ -0,0 +1,26 @@
1
+/*
2
+ * console.h
3
+ *
4
+ * Copyright (c) 2022 - 2023 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 __CONSOLE_H__
20
+#define __CONSOLE_H__
21
+
22
+void cnsl_init(void);
23
+void cnsl_run(void);
24
+void cnsl_handle_input(const uint8_t *buf, size_t len);
25
+
26
+#endif // __CONSOLE_H__

+ 38
- 0
include/crafty.h View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * crafty.h
3
+ *
4
+ * Copyright (c) 2023 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 __CRAFTY_H__
20
+#define __CRAFTY_H__
21
+
22
+#include <stdint.h>
23
+#include <stdbool.h>
24
+
25
+// in 1/10th degrees C, or < 0 on error
26
+int16_t crafty_get_current_temp(void);
27
+int16_t crafty_get_target_temp(void);
28
+
29
+// v in 1/10th degrees C, returns < 0 on error
30
+int8_t crafty_set_target_temp(uint16_t v);
31
+
32
+// returns < 0 on error
33
+int8_t crafty_set_heater_state(bool value);
34
+
35
+// in percent, or < 0 on error
36
+int8_t crafty_get_battery_state(void);
37
+
38
+#endif // __CRAFTY_H__

+ 27
- 0
include/debug_disk.h View File

@@ -0,0 +1,27 @@
1
+/*
2
+ * debug_disk.h
3
+ *
4
+ * Copyright (c) 2022 - 2023 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 __DEBUG_DISK_H__
20
+#define __DEBUG_DISK_H__
21
+
22
+void debug_disk_init(void);
23
+
24
+int debug_disk_mount(void);
25
+int debug_disk_unmount(void);
26
+
27
+#endif // __DEBUG_DISK_H__

+ 21
- 0
include/fat_disk.h View File

@@ -0,0 +1,21 @@
1
+/* 
2
+ * fat_disk.h
3
+ *
4
+ * Copyright (c) 2022 - 2023 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
+void fat_disk_init(void);
20
+
21
+uint8_t *fat_disk_get_sector(uint32_t sector);

+ 296
- 0
include/ffconf.h View File

@@ -0,0 +1,296 @@
1
+/*---------------------------------------------------------------------------/
2
+/  Configurations of FatFs Module
3
+/---------------------------------------------------------------------------*/
4
+
5
+#define FFCONF_DEF	80286	/* Revision ID */
6
+
7
+/*---------------------------------------------------------------------------/
8
+/ Function Configurations
9
+/---------------------------------------------------------------------------*/
10
+
11
+#define FF_FS_READONLY	0
12
+/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
13
+/  Read-only configuration removes writing API functions, f_write(), f_sync(),
14
+/  f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
15
+/  and optional writing functions as well. */
16
+
17
+
18
+#define FF_FS_MINIMIZE	0
19
+/* This option defines minimization level to remove some basic API functions.
20
+/
21
+/   0: Basic functions are fully enabled.
22
+/   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
23
+/      are removed.
24
+/   2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
25
+/   3: f_lseek() function is removed in addition to 2. */
26
+
27
+
28
+#define FF_USE_FIND		0
29
+/* This option switches filtered directory read functions, f_findfirst() and
30
+/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
31
+
32
+
33
+#define FF_USE_MKFS		1
34
+/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
35
+
36
+
37
+#define FF_USE_FASTSEEK	0
38
+/* This option switches fast seek function. (0:Disable or 1:Enable) */
39
+
40
+
41
+#define FF_USE_EXPAND	0
42
+/* This option switches f_expand function. (0:Disable or 1:Enable) */
43
+
44
+
45
+#define FF_USE_CHMOD	0
46
+/* This option switches attribute manipulation functions, f_chmod() and f_utime().
47
+/  (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
48
+
49
+
50
+#define FF_USE_LABEL	1
51
+/* This option switches volume label functions, f_getlabel() and f_setlabel().
52
+/  (0:Disable or 1:Enable) */
53
+
54
+
55
+#define FF_USE_FORWARD	0
56
+/* This option switches f_forward() function. (0:Disable or 1:Enable) */
57
+
58
+
59
+#define FF_USE_STRFUNC	0
60
+#define FF_PRINT_LLI	1
61
+#define FF_PRINT_FLOAT	1
62
+#define FF_STRF_ENCODE	3
63
+/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
64
+/  f_printf().
65
+/
66
+/   0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
67
+/   1: Enable without LF-CRLF conversion.
68
+/   2: Enable with LF-CRLF conversion.
69
+/
70
+/  FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
71
+/  makes f_printf() support floating point argument. These features want C99 or later.
72
+/  When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
73
+/  encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
74
+/  to be read/written via those functions.
75
+/
76
+/   0: ANSI/OEM in current CP
77
+/   1: Unicode in UTF-16LE
78
+/   2: Unicode in UTF-16BE
79
+/   3: Unicode in UTF-8
80
+*/
81
+
82
+
83
+/*---------------------------------------------------------------------------/
84
+/ Locale and Namespace Configurations
85
+/---------------------------------------------------------------------------*/
86
+
87
+#define FF_CODE_PAGE	850
88
+/* This option specifies the OEM code page to be used on the target system.
89
+/  Incorrect code page setting can cause a file open failure.
90
+/
91
+/   437 - U.S.
92
+/   720 - Arabic
93
+/   737 - Greek
94
+/   771 - KBL
95
+/   775 - Baltic
96
+/   850 - Latin 1
97
+/   852 - Latin 2
98
+/   855 - Cyrillic
99
+/   857 - Turkish
100
+/   860 - Portuguese
101
+/   861 - Icelandic
102
+/   862 - Hebrew
103
+/   863 - Canadian French
104
+/   864 - Arabic
105
+/   865 - Nordic
106
+/   866 - Russian
107
+/   869 - Greek 2
108
+/   932 - Japanese (DBCS)
109
+/   936 - Simplified Chinese (DBCS)
110
+/   949 - Korean (DBCS)
111
+/   950 - Traditional Chinese (DBCS)
112
+/     0 - Include all code pages above and configured by f_setcp()
113
+*/
114
+
115
+
116
+#define FF_USE_LFN		3
117
+#define FF_MAX_LFN		255
118
+/* The FF_USE_LFN switches the support for LFN (long file name).
119
+/
120
+/   0: Disable LFN. FF_MAX_LFN has no effect.
121
+/   1: Enable LFN with static  working buffer on the BSS. Always NOT thread-safe.
122
+/   2: Enable LFN with dynamic working buffer on the STACK.
123
+/   3: Enable LFN with dynamic working buffer on the HEAP.
124
+/
125
+/  To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
126
+/  requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
127
+/  additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
128
+/  The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
129
+/  be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
130
+/  specification.
131
+/  When use stack for the working buffer, take care on stack overflow. When use heap
132
+/  memory for the working buffer, memory management functions, ff_memalloc() and
133
+/  ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
134
+
135
+
136
+#define FF_LFN_UNICODE	2
137
+/* This option switches the character encoding on the API when LFN is enabled.
138
+/
139
+/   0: ANSI/OEM in current CP (TCHAR = char)
140
+/   1: Unicode in UTF-16 (TCHAR = WCHAR)
141
+/   2: Unicode in UTF-8 (TCHAR = char)
142
+/   3: Unicode in UTF-32 (TCHAR = DWORD)
143
+/
144
+/  Also behavior of string I/O functions will be affected by this option.
145
+/  When LFN is not enabled, this option has no effect. */
146
+
147
+
148
+#define FF_LFN_BUF		255
149
+#define FF_SFN_BUF		12
150
+/* This set of options defines size of file name members in the FILINFO structure
151
+/  which is used to read out directory items. These values should be suffcient for
152
+/  the file names to read. The maximum possible length of the read file name depends
153
+/  on character encoding. When LFN is not enabled, these options have no effect. */
154
+
155
+
156
+#define FF_FS_RPATH		0
157
+/* This option configures support for relative path.
158
+/
159
+/   0: Disable relative path and remove related functions.
160
+/   1: Enable relative path. f_chdir() and f_chdrive() are available.
161
+/   2: f_getcwd() function is available in addition to 1.
162
+*/
163
+
164
+
165
+/*---------------------------------------------------------------------------/
166
+/ Drive/Volume Configurations
167
+/---------------------------------------------------------------------------*/
168
+
169
+#define FF_VOLUMES		1
170
+/* Number of volumes (logical drives) to be used. (1-10) */
171
+
172
+
173
+#define FF_STR_VOLUME_ID	0
174
+#define FF_VOLUME_STRS		"RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
175
+/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
176
+/  When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
177
+/  number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
178
+/  logical drives. Number of items must not be less than FF_VOLUMES. Valid
179
+/  characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
180
+/  compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
181
+/  not defined, a user defined volume string table is needed as:
182
+/
183
+/  const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
184
+*/
185
+
186
+
187
+#define FF_MULTI_PARTITION	0
188
+/* This option switches support for multiple volumes on the physical drive.
189
+/  By default (0), each logical drive number is bound to the same physical drive
190
+/  number and only an FAT volume found on the physical drive will be mounted.
191
+/  When this function is enabled (1), each logical drive number can be bound to
192
+/  arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
193
+/  function will be available. */
194
+
195
+
196
+#define FF_MIN_SS		512
197
+#define FF_MAX_SS		512
198
+/* This set of options configures the range of sector size to be supported. (512,
199
+/  1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
200
+/  harddisk, but a larger value may be required for on-board flash memory and some
201
+/  type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
202
+/  for variable sector size mode and disk_ioctl() function needs to implement
203
+/  GET_SECTOR_SIZE command. */
204
+
205
+
206
+#define FF_LBA64		0
207
+/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
208
+/  To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
209
+
210
+
211
+#define FF_MIN_GPT		0x10000000
212
+/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
213
+/  f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
214
+
215
+
216
+#define FF_USE_TRIM		0
217
+/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
218
+/  To enable Trim function, also CTRL_TRIM command should be implemented to the
219
+/  disk_ioctl() function. */
220
+
221
+
222
+
223
+/*---------------------------------------------------------------------------/
224
+/ System Configurations
225
+/---------------------------------------------------------------------------*/
226
+
227
+#define FF_FS_TINY		0
228
+/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
229
+/  At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
230
+/  Instead of private sector buffer eliminated from the file object, common sector
231
+/  buffer in the filesystem object (FATFS) is used for the file data transfer. */
232
+
233
+
234
+#define FF_FS_EXFAT		0
235
+/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
236
+/  To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
237
+/  Note that enabling exFAT discards ANSI C (C89) compatibility. */
238
+
239
+
240
+#define FF_FS_NORTC		1
241
+#define FF_NORTC_MON	1
242
+#define FF_NORTC_MDAY	1
243
+#define FF_NORTC_YEAR	2022
244
+/* The option FF_FS_NORTC switches timestamp feature. If the system does not have
245
+/  an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the
246
+/  timestamp feature. Every object modified by FatFs will have a fixed timestamp
247
+/  defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
248
+/  To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
249
+/  added to the project to read current time form real-time clock. FF_NORTC_MON,
250
+/  FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
251
+/  These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
252
+
253
+
254
+#define FF_FS_NOFSINFO	0
255
+/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
256
+/  option, and f_getfree() function at the first time after volume mount will force
257
+/  a full FAT scan. Bit 1 controls the use of last allocated cluster number.
258
+/
259
+/  bit0=0: Use free cluster count in the FSINFO if available.
260
+/  bit0=1: Do not trust free cluster count in the FSINFO.
261
+/  bit1=0: Use last allocated cluster number in the FSINFO if available.
262
+/  bit1=1: Do not trust last allocated cluster number in the FSINFO.
263
+*/
264
+
265
+
266
+#define FF_FS_LOCK		0
267
+/* The option FF_FS_LOCK switches file lock function to control duplicated file open
268
+/  and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
269
+/  is 1.
270
+/
271
+/  0:  Disable file lock function. To avoid volume corruption, application program
272
+/      should avoid illegal open, remove and rename to the open objects.
273
+/  >0: Enable file lock function. The value defines how many files/sub-directories
274
+/      can be opened simultaneously under file lock control. Note that the file
275
+/      lock control is independent of re-entrancy. */
276
+
277
+
278
+#define FF_FS_REENTRANT	0
279
+#define FF_FS_TIMEOUT	1000
280
+/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
281
+/  module itself. Note that regardless of this option, file access to different
282
+/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
283
+/  and f_fdisk() function, are always not re-entrant. Only file/directory access
284
+/  to the same volume is under control of this featuer.
285
+/
286
+/   0: Disable re-entrancy. FF_FS_TIMEOUT have no effect.
287
+/   1: Enable re-entrancy. Also user provided synchronization handlers,
288
+/      ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give()
289
+/      function, must be added to the project. Samples are available in ffsystem.c.
290
+/
291
+/  The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick.
292
+*/
293
+
294
+
295
+
296
+/*--- End of configuration options ---*/

+ 30
- 0
include/image.h View File

@@ -0,0 +1,30 @@
1
+/*
2
+ * image.h
3
+ *
4
+ * Copyright (c) 2023 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 __IMAGE_H__
20
+#define __IMAGE_H__
21
+
22
+#include "pico/stdlib.h"
23
+
24
+void image_draw(const char *data, uint width, uint height);
25
+
26
+void draw_splash(void);
27
+void draw_battery_indicator(void);
28
+void battery_run(void);
29
+
30
+#endif // __IMAGE_H__

+ 44
- 0
include/lcd.h View File

@@ -0,0 +1,44 @@
1
+/*
2
+ * lipo.h
3
+ *
4
+ * Copyright (c) 2023 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 __LCD_H__
20
+#define __LCD_H__
21
+
22
+#include <stdint.h>
23
+
24
+#define RGB_565(r, g, b) ( \
25
+      (((r) >> 3) << 11)   \
26
+    | (((g) >> 2) << 5)    \
27
+    |  ((b) >> 3)          \
28
+)
29
+#define RGB_565_REV(c)            \
30
+    ((c & 0xF800) >> 8) / 255.0f, \
31
+    ((c & 0x07E0) >> 3) / 255.0f, \
32
+    ((c & 0x001F) << 3) / 255.0f
33
+uint32_t from_hsv(float h, float s, float v);
34
+
35
+void lcd_init(void);
36
+
37
+uint16_t lcd_get_backlight(void);
38
+void lcd_set_backlight(uint16_t value);
39
+
40
+void lcd_clear(void);
41
+void lcd_write_point(uint16_t x, uint16_t y, uint32_t color);
42
+void lcd_write_rect(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint32_t color);
43
+
44
+#endif // __LCD_H__

+ 26
- 0
include/lipo.h View File

@@ -0,0 +1,26 @@
1
+/*
2
+ * lipo.h
3
+ *
4
+ * Copyright (c) 2023 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 __LIPO_H__
20
+#define __LIPO_H__
21
+
22
+bool lipo_charging(void);
23
+float lipo_voltage(void);
24
+float lipo_percentage(float voltage);
25
+
26
+#endif // __LIPO_H__

+ 48
- 0
include/log.h View File

@@ -0,0 +1,48 @@
1
+/*
2
+ * log.h
3
+ *
4
+ * Copyright (c) 2022 - 2023 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 __LOG_H__
20
+#define __LOG_H__
21
+
22
+#include <stdarg.h>
23
+#include <stdbool.h>
24
+#include "pico/stdlib.h"
25
+
26
+// for output that is stored in the debug log.
27
+// will be re-played from buffer when terminal connects
28
+#define debug(fmt, ...) debug_log(true, \
29
+        "%08lu %s: " fmt "\r\n", \
30
+        to_ms_since_boot(get_absolute_time()), \
31
+        __func__, \
32
+        ##__VA_ARGS__)
33
+
34
+// for interactive output. is not stored or re-played.
35
+#define print(fmt, ...) debug_log(false, fmt, ##__VA_ARGS__)
36
+#define println(fmt, ...) debug_log(false, fmt "\r\n", ##__VA_ARGS__)
37
+
38
+void debug_log(bool log, const char *format, ...) __attribute__((format(printf, 2, 3)));
39
+void debug_wait_input(const char *format, ...) __attribute__((format(printf, 1, 2)));
40
+void debug_log_va(bool log, const char *format, va_list args);
41
+
42
+void log_dump_to_usb(void);
43
+void log_dump_to_uart(void);
44
+void log_dump_to_disk(void);
45
+
46
+void debug_handle_input(const uint8_t *buff, size_t len);
47
+
48
+#endif // __LOG_H__

+ 3615
- 0
include/logo.h
File diff suppressed because it is too large
View File


+ 24
- 0
include/main.h View File

@@ -0,0 +1,24 @@
1
+/*
2
+ * main.h
3
+ *
4
+ * Copyright (c) 2023 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 __MAIN_H__
20
+#define __MAIN_H__
21
+
22
+void main_loop_hw(void);
23
+
24
+#endif // __MAIN_H__

+ 37
- 0
include/menu.h View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * menu.h
3
+ *
4
+ * Copyright (c) 2023 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 __MENU_H__
20
+#define __MENU_H__
21
+
22
+#define MENU_MAX_LINES 5
23
+#define MENU_MAX_LEN (MENU_MAX_LINES * 32)
24
+
25
+struct menu_state {
26
+    int off;
27
+    int selection;
28
+    int length;
29
+    char *buff;
30
+};
31
+
32
+void menu_init(void (*enter)(int), void (*exit)(void));
33
+void menu_deinit(void);
34
+
35
+void menu_run(void (*cb)(struct menu_state *));
36
+
37
+#endif // __MENU_H__

+ 33
- 0
include/models.h View File

@@ -0,0 +1,33 @@
1
+/*
2
+ * models.h
3
+ *
4
+ * Copyright (c) 2023 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 __MODELS_H__
20
+#define __MODELS_H__
21
+
22
+#include <stdint.h>
23
+
24
+enum known_devices {
25
+    DEV_UNKNOWN = 0,
26
+    DEV_VOLCANO,
27
+    DEV_CRAFTY,
28
+};
29
+
30
+enum known_devices models_filter_name(const char *name);
31
+int8_t models_get_serial(const uint8_t *data, size_t data_len, char *buff, size_t buff_len);
32
+
33
+#endif // __MODELS_H__

+ 43
- 0
include/ring.h View File

@@ -0,0 +1,43 @@
1
+/*
2
+ * ring.h
3
+ *
4
+ * Copyright (c) 2023 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 __RING_BUFFER_H__
20
+#define __RING_BUFFER_H__
21
+
22
+#include <stddef.h>
23
+#include <stdint.h>
24
+#include <stdbool.h>
25
+
26
+struct ring_buffer {
27
+    uint8_t *buffer;
28
+    size_t size;
29
+    size_t head, tail;
30
+    bool full;
31
+};
32
+#define RB_INIT(b, s) { .buffer = b, .size = s, .head = 0, .tail = 0, .full = false }
33
+
34
+void rb_add(struct ring_buffer *rb, const uint8_t *data, size_t length);
35
+#define rb_push(rb, v) rb_add(rb, &v, 1)
36
+size_t rb_len(struct ring_buffer *rb);
37
+#define rb_space(rb) ((rb)->size - rb_len(rb))
38
+void rb_dump(struct ring_buffer *rb, void (*write)(const uint8_t *, size_t));
39
+void rb_move(struct ring_buffer *rb, void (*write)(const uint8_t *, size_t));
40
+uint8_t rb_peek(struct ring_buffer *rb);
41
+uint8_t rb_pop(struct ring_buffer *rb);
42
+
43
+#endif // __RING_BUFFER_H__

+ 31
- 0
include/serial.h View File

@@ -0,0 +1,31 @@
1
+/*
2
+ * serial.h
3
+ *
4
+ * Copyright (c) 2023 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 __SERIAL_H__
20
+#define __SERIAL_H__
21
+
22
+#include <stddef.h>
23
+#include <stdint.h>
24
+#include <stdbool.h>
25
+
26
+void serial_init(void);
27
+void serial_write(const uint8_t *buf, size_t count);
28
+void serial_set_reroute(bool reroute);
29
+void serial_run(void);
30
+
31
+#endif // __SERIAL_H__

+ 33
- 0
include/state.h View File

@@ -0,0 +1,33 @@
1
+/*
2
+ * state.h
3
+ *
4
+ * Copyright (c) 2023 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 __STATE_H__
20
+#define __STATE_H__
21
+
22
+enum system_state {
23
+    STATE_INIT = 0,
24
+    STATE_SCAN,
25
+    STATE_VOLCANO_WORKFLOW,
26
+    STATE_VOLCANO_RUN,
27
+    STATE_CRAFTY,
28
+};
29
+
30
+void state_switch(enum system_state next);
31
+void state_run(void);
32
+
33
+#endif // __STATE_H__

+ 30
- 0
include/state_crafty.h View File

@@ -0,0 +1,30 @@
1
+/*
2
+ * state_crafty.h
3
+ *
4
+ * Copyright (c) 2023 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 __STATE_CRAFTY_H__
20
+#define __STATE_CRAFTY_H__
21
+
22
+#include <ble.h>
23
+
24
+void state_crafty_target(bd_addr_t addr, bd_addr_type_t type);
25
+
26
+void state_crafty_enter(void);
27
+void state_crafty_exit(void);
28
+void state_crafty_run(void);
29
+
30
+#endif // __STATE_CRAFTY_H__

+ 26
- 0
include/state_scan.h View File

@@ -0,0 +1,26 @@
1
+/*
2
+ * state_scan.h
3
+ *
4
+ * Copyright (c) 2023 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