Skip to content

Commit

Permalink
chore: migrate UHK 80 features
Browse files Browse the repository at this point in the history
chore: migrate UHK 80 features
  • Loading branch information
ert78gb authored Dec 5, 2024
2 parents 173a828 + 7944d8a commit f47d3dd
Show file tree
Hide file tree
Showing 594 changed files with 35,048 additions and 1,492 deletions.
65 changes: 41 additions & 24 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
---
Language: Cpp
BasedOnStyle: WebKit
AllowShortFunctionsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBraces: Custom
Cpp11BracedListStyle: true
Language: Cpp
BasedOnStyle: Microsoft
ColumnLimit: 100
IndentWidth: 4
IndentPPDirectives: BeforeHash
PPIndentWidth: 4
ContinuationIndentWidth: 4

ReflowComments: false

PointerAlignment: Right
ReflowComments: false
SortIncludes: false
TabWidth: 4
...
DerivePointerAlignment: false

BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterStruct: false
AfterUnion: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterExternBlock: false
AfterCaseLabel: false
AfterControlStatement: Never
BeforeElse: false
BeforeCatch: false
BeforeLambdaBody: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
AlignAfterOpenBracket: DontAlign

# c++ specific
ConstructorInitializerIndentWidth: 4
IndentRequiresClause: true
IndentExternBlock: NoIndent
PackConstructorInitializers: NextLine
AlwaysBreakTemplateDeclarations: Yes
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: Inline
ShortNamespaceLines: 1
FixNamespaceComments: true
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ steps:
- git submodule init
- git submodule update --recursive

- name: Generate versions.h
- name: Generate versions.c
image: node:16
commands:
- npm install --prefix scripts
- scripts/generate-versions-h.js
- scripts/generate-versions.mjs

- name: Build (Ubuntu Linux)
image: abcminiuser/docker-ci-arm-toolchain:latest
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI

on:
push:
branches:
- master*
pull_request:
branches:
- master*

jobs:
release:
runs-on: ubuntu-22.04
timeout-minutes: 25

steps:
- uses: actions/checkout@v4
with:
path: firmware-uhk80
submodules: recursive

- name: Install build dependencies
run: sudo apt-get install -y gcc-arm-none-eabi

- name: Install west
run: pip3 install --user -U west

- name: Install python dependencies of scripts
run: |
cd firmware-uhk80/scripts
pip install -r requirements.txt
- name: Setup Zephyr project
uses: zephyrproject-rtos/action-zephyr-setup@v1
with:
app-path: firmware-uhk80
toolchains: arm-zephyr-eabi
sdk-version: 0.16.8

- name: Git user setup
run: |
git config --global user.email "git-patch@uhk.com"
git config --global user.name "Git Patch"
- name: West patch
run: west patch

- name: West config
run: west config --local build.cmake-args -- "-Wno-dev"

- name: Use Node.js (.nvmrc)
uses: actions/setup-node@v4
with:
node-version-file: firmware-uhk80/scripts/.nvmrc

- name: Install node dependencies in scripts folder
run: |
cd firmware-uhk80/scripts
npm install
- name: Create firmware tarball
run: |
cd firmware-uhk80
scripts/make-release.mjs --allowSha
- name: Upload firmware artifacts
uses: actions/upload-artifact@v4
with:
name: firmware
path: firmware-uhk80/scripts/uhk-firmware-*.tar.gz
compression-level: 0
retention-days: 10
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ package-lock.json
node_modules
build_make
.cache
samples
build
CMakeCache.txt
build.ninja
.vscode/settings.json
scripts/__pycache__
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "lib/SDK_2.8.0_MKL17Z32xxx4"]
path = lib/SDK_2.8.0_MKL17Z32xxx4
url = https://github.com/UltimateHackingKeyboard/SDK_2.8.0_MKL17Z32xxx4.git
[submodule "lib/c2usb"]
path = lib/c2usb
url = https://github.com/IntergatedCircuits/c2usb.git
21 changes: 17 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
{
"version": 4,
"configurations": [
{
"name": "UHK 60 v1",
"defines": [
"DEVICE_ID=DEVICE_ID_UHK60V1"
]
],
"configurationProvider": "nordic-semiconductor.nrf-connect"
},
{
"name": "UHK 60 v2",
"defines": [
"DEVICE_ID=DEVICE_ID_UHK60V2"
]
},
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++20",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "nordic-semiconductor.nrf-connect"
}
]
}
],
"version": 4
}
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:2.6.1}",
"nrf-connect.topdir": "${nrf-connect.sdk:2.4.1}",
"nrf-connect.applications": [
"${workspaceFolder}/device"
],
"nrf-connect.boardRoots": [
"${workspaceFolder}/"
],
"files.associations": {
"*.h": "c",
"*.c": "c",
"bitset": "cpp",
"span": "cpp",
"array": "cpp",
"string": "cpp",
"string_view": "cpp",
"compare": "c",
"system_error": "c"
}
}
29 changes: 15 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,31 @@ Header files are composed of sections. The order of sections is fixed. Every hea
// Includes:
#include "fsl_gpio.h"
...
#include "fsl_gpio.h"
...
// Macros:
#define LED_DRIVER_SDB_PORT PORTA
...
#define LED_DRIVER_SDB_PORT PORTA
...
// Typedefs:
typedef enum {
KeystrokeType_Basic,
KeystrokeType_Media,
KeystrokeType_System,
} keystroke_type_t;
typedef enum {
KeystrokeType_Basic,
KeystrokeType_Media,
KeystrokeType_System,
} keystroke_type_t;
// Variables:
extern led_driver_state_t LedDriverState;
...
extern led_driver_state_t LedDriverState;
...
// Functions:
void LedDriver_WriteBuffer(uint8_t i2cAddress, uint8_t buffer[], uint8_t size);
...
void LedDriver_WriteBuffer(uint8_t i2cAddress, uint8_t buffer[], uint8_t size);
...
#endif
```
Expand All @@ -154,4 +154,5 @@ The build process must not yield any warnings, and the build must pass [on on th

## Clang format

There is a `.clang-format` present, which allows you to format your `.c` files simply by `clang-format -i <your source file>`. (It does **not** ensure the required header file structure though!)
There is a `.clang-format` present, which allows you to format your source files simply by `clang-format -i <your source file>`.
(It does **not** ensure the required header file structure though!)
92 changes: 83 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,79 @@ If you want to use the latest firmware version for your UHK, then instead of goi

If you're one of the brave few who wants to hack the firmware then read on.

1. Make sure to clone this repo with:
### Fetching the codebase

`git clone --recursive git@github.com:UltimateHackingKeyboard/firmware.git`
Note that these commands will create a [west workspace](https://docs.zephyrproject.org/latest/develop/west/workspaces.html#t2-star-topology-application-is-the-manifest-repository) in your current directory.

Then, depending whether you want a full IDE experience or just minimal tools for building and flashing firmware, read *IDE setup* or *Minimal development setup* (if you prefer a text editor + command line).
```bash
git clone --recurse-submodules git@github.com:UltimateHackingKeyboard/firmware-uhk80.git
west init -l firmware-uhk80
west update
west patch
west config --local build.cmake-args -- "-Wno-dev"
cd firmware-uhk80/scripts
npm i
./generate-versions.mjs
```

### IDE setup
Then, depending whether you want a full IDE experience or just minimal tools for building and flashing firmware, read *VS Code setup* or *Minimal development setup* (if you prefer a text editor + command line).

### VS Code setup

- Install [nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/installation/install_ncs.html) including VS Code extensions.
- In VS Code, click nRF connect icon in the left pane, then `Applications -> Create new build configuration` and select the relevant CMake preset. Now hit Build. This executes cmake steps.
- Now you can rebuild or flash using the Build and Flash actions.

### Minimal development setup

- Install commandline stuff from [nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/installation/install_ncs.html)
- You can use `./build.sh` script that basically just packs the following snippets, but should be more up to date:

- e.g. `./build.sh uhk-80-left build make flash`, which will perform the three actions below

- If the `build.sh` doesn't suit you, then launch the nrfutil shell:
```
nrfutil toolchain-manager launch --shell --ncs-version v2.6.1
```
- In the shell, you can build (e.g.) uhk-80-left as follows:
- full build including cmake steps, as extracted from VS Code:
```
export DEVICE=uhk-80-left
export PWD=`pwd`
west build --build-dir $PWD/device/build/$DEVICE $PWD/device --pristine --board $DEVICE --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DCONF_FILE=$PWD/device/prj.conf -DOVERLAY_CONFIG=$PWD/device/prj.conf.overlays/$DEVICE.prj.conf -DBOARD_ROOT=$PWD
```
- quick rebuild:
```
export DEVICE=uhk-80-left
export PWD=`pwd`
west build --build-dir $PWD/device/build/$DEVICE $PWD/device
```
- flash:
```
export DEVICE=uhk-80-left
export PWD=`pwd`
west flash -d $PWD/device/build/$DEVICE
```
In case of problems, please refer to scripts/make-release.mjs
### Recommended tweaks
You may find this `.git/hooks/post-checkout` git hook useful:
```bash
#!/bin/bash
# Update the submodule in lib/c2usb to the commit recorded in the checked-out commit
git submodule update --init --recursive lib/c2usb
# Refresh versions.c, so that Agent always shows what commit you are on (although it doesn't indicate unstaged changes)
scripts/generate-versions.mjs
```

### Old IDE setup

2. Download and install MCUXpresso IDE for [Linux](https://ultimatehackingkeyboard.com/mcuxpressoide/mcuxpressoide-11.2.0_4120.x86_64.deb.bin), [Mac](https://ultimatehackingkeyboard.com/mcuxpressoide/MCUXpressoIDE_11.2.0_4120.pkg), or [Windows](https://ultimatehackingkeyboard.com/mcuxpressoide/MCUXpressoIDE_11.2.0_4120.exe).

Expand All @@ -39,7 +105,7 @@ Then, depending whether you want a full IDE experience or just minimal tools for

Going forward, it's easier to flash the firmware of your choice by using the downwards toolbar icon which is located rightwards of the *green play + toolbox icon*.

### Minimal development setup
### Old Minimal development setup

1. Install the ARM cross-compiler, cross-assembler and stdlib implementation. Eg. on Arch Linux the packages `arm-none-eabi-binutils`, `arm-none-eabi-gcc`, `arm-none-eabi-newlib`.

Expand All @@ -55,10 +121,18 @@ Going forward, it's easier to flash the firmware of your choice by using the dow

### Releasing

6. To build a full firmware tarball:
1. Run `npm install` in `scripts`.
2. Run `scripts/make-release.js`. (Or `scripts/make-release.js --allowSha` for development purposes.)
3. Now, the created tarball `scripts/uhk-firmware-VERSION.tar.gz` can be flashed with UHK Agent.
To build a full firmware tarball:

1. Run `npm install` in `scripts`.
2. Run `scripts/make-release.mjs`. (Or `scripts/make-release.mjs --allowSha` for development purposes.)
3. Now, the created tarball `scripts/uhk-firmware-VERSION.tar.gz` can be flashed with UHK Agent.

If `make-release.mjs` fails with a build error, it'll probably succeed in Nordic's shell environment.

1. Install [nRF Util](https://www.nordicsemi.com/Products/Development-tools/nRF-Util).
2. Install the nRF Connect Toolchain Manager with `nrfutil install toolchain-manager`
3. Enter the Toolchain Manager shell with `nrfutil toolchain-manager launch --shell`
4. Within the shell, run `make-release.mjs` according to the above.

## Contributing

Expand Down
Loading

0 comments on commit f47d3dd

Please sign in to comment.