Skip to content

Commit

Permalink
clean up firmware skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
xythobuz committed Apr 16, 2024
1 parent c62e528 commit 31b7ba3
Show file tree
Hide file tree
Showing 26 changed files with 717 additions and 139 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Check out the [Dispensy documentation](https://drinkrobotics.github.io/dispensy/

## License

This project is licensed under the [CERN Open Hardware Licence Version 2 - Strongly Reciprocal (CERN-OHL-S-2.0+)](https://ohwr.org/cern_ohl_s_v2.txt) or any later version.
This hardware of this project is licensed under the [CERN Open Hardware Licence Version 2 - Strongly Reciprocal (CERN-OHL-S-2.0+)](https://ohwr.org/cern_ohl_s_v2.txt) or any later version.

The docs are built using [mdbook](https://github.com/rust-lang/mdBook), licensed as `MPL-2.0`.
The PCB SVG files in the documentation are displayed using [svg-pan-zoom](https://github.com/bumbu/svg-pan-zoom), licensed as `BSD-2-Clause`.
Expand Down Expand Up @@ -41,7 +41,19 @@ Please also take a look at the `README.md` files in the subfolders of this proje
| source. |
------------------------------------------------------------------------------

This is the SPDX header for this project:
The firmware of this project is licensed as GPLv3.
I initially adapted it from my own [Trackball](https://git.xythobuz.de/thomas/Trackball) and [Volcano Remote](https://git.xythobuz.de/thomas/sb-py) projects.
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.
Some code is adapted from the TinyUSB examples.

SPDX-FileCopyrightText: 2023 - 2024 Thomas Buck <[email protected]>
SPDX-License-Identifier: CERN-OHL-S-2.0+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

See <http://www.gnu.org/licenses/>.
2 changes: 2 additions & 0 deletions firmware/.clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-I/usr/arm-none-eabi/include]
19 changes: 0 additions & 19 deletions firmware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,3 @@ And also start a GDB debugging session.
These commands have also been put in the `flash_swd.sh` and `debug_swd.sh` scripts, respectively.
They require the `build_debug` folder where you checked out and built OpenOCD.
Here are some [general GDB tips](https://beej.us/guide/bggdb/).

## License

The firmware itself is licensed as GPLv3.
I initially adapted it from my own [Trackball](https://git.xythobuz.de/thomas/Trackball) and [Volcano Remote](https://git.xythobuz.de/thomas/sb-py) projects.
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.
Some code is adapted from the TinyUSB examples.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

See <http://www.gnu.org/licenses/>.
2 changes: 1 addition & 1 deletion firmware/include/buttons.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* buttons.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
30 changes: 3 additions & 27 deletions firmware/include/config.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* config.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,38 +20,14 @@
#define __CONFIG_H__

#define APP_VERSION_MAJOR 0
#define APP_VERSION_MINOR 3
#define APP_VERSION_MINOR 1

#define MENU_PREFER_VOLCANO
//#define MENU_PREFER_CRAFTY

#define VOLCANO_AUTO_CONNECT_TIMEOUT_MS 2000
#define VOLCANO_AUTO_CONNECT_WITHIN_MS 10000

#define COUNTRY_CODE CYW43_COUNTRY_GERMANY

#ifdef NDEBUG
// Release build
#define AUTO_MOUNT_MASS_STORAGE
#define AUTO_LOG_ON_MASS_STORAGE
#endif // NDEBUG

#define WATCHDOG_PERIOD_MS 1000
#define FLASH_LOCK_TIMEOUT_MS 500
#define WATCHDOG_PERIOD_MS 10

// ASCII 0x18 = CAN (cancel)
#define ENTER_BOOTLOADER_MAGIC 0x18

//#define DISABLE_CDC_DTR_CHECK
#define DEBOUNCE_DELAY_MS 5

#define SERIAL_WRITES_BLOCK_WHEN_BUFFER_FULL

// TODO needs to be the same as in pack_data.sh
#define DISK_BLOCK_SIZE 512
#define DISK_BLOCK_COUNT (256 + 128) // 384 * 512 = 196608

#define TEST_VOLCANO_AUTO_CONNECT "EA:06:75:A7:D1:15 1"
#define TEST_CRAFTY_AUTO_CONNECT "60:B6:E1:BB:61:36 0"

#endif // __CONFIG_H__
2 changes: 1 addition & 1 deletion firmware/include/console.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* console.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion firmware/include/lcd.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* lipo.h
*
* Copyright (c) 2023 Thomas Buck ([email protected])
* Copyright (c) 2023 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
10 changes: 1 addition & 9 deletions firmware/include/log.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* log.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,17 +26,11 @@

// for output that is stored in the debug log.
// will be re-played from buffer when terminal connects
#ifndef PICOWOTA
#define debug(fmt, ...) debug_log(true, \
"%08" PRIu32 " %s:%d: " fmt "\r\n", \
to_ms_since_boot(get_absolute_time()), \
__func__, __LINE__, \
##__VA_ARGS__)
#else // PICOWOTA
#define debug(fmt, ...) debug_log(true, \
fmt "\r\n", \
##__VA_ARGS__)
#endif // PICOWOTA

// for interactive output. is not stored or re-played.
#define print(fmt, ...) debug_log(false, fmt, ##__VA_ARGS__)
Expand All @@ -47,8 +41,6 @@ void debug_wait_input(const char *format, ...) __attribute__((format(printf, 1,
void debug_log_va(bool log, const char *format, va_list args);

void log_dump_to_usb(void);
void log_dump_to_uart(void);
void log_dump_to_disk(void);

void debug_handle_input(const void *buff, size_t len);

Expand Down
2 changes: 1 addition & 1 deletion firmware/include/main.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* main.h
*
* Copyright (c) 2023 Thomas Buck ([email protected])
* Copyright (c) 2023 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion firmware/include/ring.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ring.h
*
* Copyright (c) 2023 Thomas Buck ([email protected])
* Copyright (c) 2023 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion firmware/include/tusb_config.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Extended from TinyUSB example code.
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* The MIT License (MIT)
*
Expand Down
2 changes: 1 addition & 1 deletion firmware/include/usb.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* usb.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion firmware/include/usb_cdc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* usb_cdc.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion firmware/include/usb_descriptors.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* usb_descriptors.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
7 changes: 1 addition & 6 deletions firmware/include/util.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* util.h
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,11 +19,6 @@
#ifndef __UTIL_H__
#define __UTIL_H__

void heartbeat_init(void);
void heartbeat_run(void);

int32_t convert_two_complement(int32_t b);

bool str_startswith(const char *str, const char *start);

void reset_to_bootloader(void);
Expand Down
4 changes: 1 addition & 3 deletions firmware/src/buttons.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* buttons.c
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,8 +16,6 @@
* See <http://www.gnu.org/licenses/>.
*/

#include "pico/stdlib.h"

#include "config.h"
#include "log.h"
#include "buttons.h"
Expand Down
5 changes: 1 addition & 4 deletions firmware/src/console.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* console.c
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -21,9 +21,6 @@
#include <unistd.h>
#include <stdio.h>

#include "pico/stdlib.h"
#include "hardware/watchdog.h"

#include "config.h"
#include "log.h"
#include "util.h"
Expand Down
4 changes: 1 addition & 3 deletions firmware/src/lcd.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* lcd.c
*
* Copyright (c) 2023 Thomas Buck ([email protected])
* Copyright (c) 2023 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,8 +16,6 @@
* See <http://www.gnu.org/licenses/>.
*/

#include "pico/stdlib.h"

#include "config.h"
#include "log.h"
#include "lcd.h"
Expand Down
5 changes: 1 addition & 4 deletions firmware/src/log.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* log.c
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,9 +17,6 @@
*/

#include <stdio.h>
#include <string.h>

#include "hardware/watchdog.h"

#include "config.h"
#include "main.h"
Expand Down
6 changes: 2 additions & 4 deletions firmware/src/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* main.c
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,11 +16,9 @@
* See <http://www.gnu.org/licenses/>.
*/

#include "pico/stdlib.h"
#include "hardware/watchdog.h"

#include "config.h"
#include "util.h"
#include "console.h"
#include "log.h"
#include "usb.h"
Expand All @@ -31,7 +29,6 @@
void main_loop_hw(void) {
watchdog_update();
usb_run();
heartbeat_run();
}

int main(void) {
Expand All @@ -50,6 +47,7 @@ int main(void) {
}

buttons_init();
lcd_init();

debug("go");

Expand Down
2 changes: 1 addition & 1 deletion firmware/src/ring.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ring.c
*
* Copyright (c) 2023 Thomas Buck ([email protected])
* Copyright (c) 2023 - 2024 Thomas Buck ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
3 changes: 1 addition & 2 deletions firmware/src/usb.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Extended from TinyUSB example code.
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* The MIT License (MIT)
*
Expand Down Expand Up @@ -33,7 +33,6 @@
#include "config.h"
#include "log.h"
#include "usb_descriptors.h"
#include "usb_cdc.h"
#include "usb.h"

void usb_init(void) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/usb_cdc.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Extended from TinyUSB example code.
*
* Copyright (c) 2022 - 2023 Thomas Buck ([email protected])
* Copyright (c) 2022 - 2024 Thomas Buck ([email protected])
*
* The MIT License (MIT)
*
Expand Down
Loading

0 comments on commit 31b7ba3

Please sign in to comment.