reform

MNT Reform: Open Source Portable Computer
Log (Feed) | Files | Refs (Tags) | README

commit 064b49c2c34076cfa2f5ffe99a26559471b9d934
parent 2f1af3ea19955365e72344fd6b733baf24afdcee
Author: Johannes Schauer Marin Rodrigues <josch@mister-muffin.de>
Date:   Tue,  6 Jun 2023 06:58:31 +0200

allow setting preprocessor variables from the outside

 - one no longer has to edit files to build different variants of the
   firmwares
 - set SOURCE_DATE_EPOCH to the date of the latest git commit for
   reproducibility
 - allow setting KBD_VARIANT_* from the outside
 - KBD_VARIANT_3_US and KBD_VARIANT_2_US set KBD_VARIANT_QWERTY_US
 - rename KBD_VARIANT_STANDALONE to KBD_MODE_STANDALONE
 - allow setting KBD_VARIANT_STANDALONE from the outside
 - build KBD_VARIANT_2 and KBD_VARIANT_3 with and without KBD_MODE_STANDALONE
   in the gitlab CI
 - allow setting KBD_FW_VERSION from the outside
 - set KBD_FW_REV to R2 for all variants and to R3 for KBD_VARIANT_3
 - rename REFORM_MBREV_R3 to REFORM_MBREV_20_R3
 - rename REFORM_MBREV_25_R1 to REFORM_MBREV_25_R2
 - allow setting REFORM_MOTHERBOARD_REV from the outside
 - pick FW_STRING2 depending on REFORM_MOTHERBOARD_REV
 - allow setting FW_STRING3 from the outside
 - build firmware on CI with git tag name in the version or commit hash

Diffstat:
M.gitlab-ci.yml | 47++++++++++++++++++++++++++++++++++++++++++-----
Mreform2-keyboard-fw/README.md | 17+++++++++++++----
Mreform2-keyboard-fw/constants.h | 29+++++++++++++++++++++++------
Mreform2-keyboard-fw/keyboard.c | 2+-
Mreform2-keyboard-fw/menu.c | 2+-
Mreform2-keyboard-fw/remote.c | 6+++---
Mreform2-lpc-fw/Makefile | 1+
Mreform2-lpc-fw/src/boards/reform2/board_reform2.c | 40+++++++++++++++++++++++++++++-----------
8 files changed, 113 insertions(+), 31 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml @@ -3,15 +3,52 @@ image: debian:unstable-slim build: artifacts: paths: - - reform2-keyboard-fw/keyboard.hex + - reform2-keyboard-fw/keyboard-2.hex + - reform2-keyboard-fw/keyboard-2-standalone.hex + - reform2-keyboard-fw/keyboard-2_US.hex + - reform2-keyboard-fw/keyboard-2_US-standalone.hex + - reform2-keyboard-fw/keyboard-3.hex + - reform2-keyboard-fw/keyboard-3-standalone.hex + - reform2-keyboard-fw/keyboard-3_US.hex + - reform2-keyboard-fw/keyboard-3_US-standalone.hex - reform2-trackball-fw/Mouse.hex - reform2-trackpad-fw/Mouse.hex - - reform2-lpc-fw/bin/firmware.bin + - reform2-lpc-fw/firmware-20_R3.bin + - reform2-lpc-fw/firmware-25_R2.bin script: | + set -x apt update - apt-get --no-install-recommends -y install build-essential avr-libc gcc-avr gcc-arm-none-eabi libnewlib-arm-none-eabi - make -C reform2-keyboard-fw + apt-get --no-install-recommends -y install git build-essential avr-libc gcc-avr gcc-arm-none-eabi libnewlib-arm-none-eabi + # use the timestamp of the latest git commit to set reproducible S_D_E + if [ -z ${SOURCE_DATE_EPOCH:+x} ] && git -C . rev-parse 2>/dev/null; then + SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) + fi + export SOURCE_DATE_EPOCH + # check if the current commit is tagged or otherwise use the git hash + if git describe >/dev/null 2>&1 && [ "$(git describe --abbrev=0)" = "$(git describe)" ]; then + VERSION="$(git describe --abbrev=0 | tr -d -)" + else + VERSION="g$(git rev-parse --short=7 HEAD)" + fi + for variant in 2 2_US 3 3_US; do + make -C reform2-keyboard-fw REFORM_KBD_OPTIONS="-DKBD_VARIANT_$variant -DKBD_FW_VERSION=\\\"$VERSION\\\"" + mv reform2-keyboard-fw/keyboard.hex reform2-keyboard-fw/keyboard-$variant.hex + make -C reform2-keyboard-fw clean + make -C reform2-keyboard-fw REFORM_KBD_OPTIONS="-DKBD_VARIANT_$variant -DKBD_MODE_STANDALONE -DKBD_FW_VERSION=\\\"$VERSION\\\"" + mv reform2-keyboard-fw/keyboard.hex reform2-keyboard-fw/keyboard-$variant-standalone.hex + make -C reform2-keyboard-fw clean + done make -C reform2-trackball-fw make -C reform2-trackpad-fw make -C reform2-lpc-fw lpcrc - make -C reform2-lpc-fw + for rev in 20_R3 25_R2; do + make -C reform2-lpc-fw REFORM_LPC_OPTIONS="-DREFORM_MOTHERBOARD_REV=REFORM_MBREV_$rev -DFW_STRING3=\\\"$VERSION\\\"" + mv reform2-lpc-fw/bin/firmware.bin reform2-lpc-fw/firmware-$rev.bin + make -C reform2-lpc-fw clean + done + md5sum reform2-keyboard-fw/keyboard-*.hex reform2-lpc-fw/firmware-*.bin + # assure that the latest git tag is reflected in the code + if git describe >/dev/null 2>&1; then + grep --quiet "# define KBD_FW_VERSION \"$(git describe --always --tags --abbrev=0 | tr -d -)\"" reform2-keyboard-fw/constants.h + grep --quiet "# define FW_STRING3 \"$(git describe --always --tags --abbrev=0 | tr -d -)\"" reform2-lpc-fw/src/boards/reform2/board_reform2.c + fi diff --git a/reform2-keyboard-fw/README.md b/reform2-keyboard-fw/README.md @@ -39,11 +39,20 @@ To change the keyboard layout, adjust the `matrix` arrays in `keyboard.c`. ## Building -*Important*: Adjust the variant settings in `constants.h` do match your keyboard or laptop model. -I.e., if you are targeting the Standalone Keyboard, uncomment the `#define KBD_VARIANT_STANDALONE`. +Build the firmware by running `make`. The firmware can then be found in +keyboard.hex. To build for the different layouts of the MNT Reform keyboards 2 +or 3, define the `KBD_VARIANT_2` or `KBD_VARIANT_3` preprocessor variables, +respectively, using the `REFORM_KBD_OPTIONS` argument to `make`. -To build, type: -`make` + make REFORM_KBD_OPTIONS=-DKBD_VARIANT_2 # default for keyboard 2.0 + make REFORM_KBD_OPTIONS=-DKBD_VARIANT_3 # keyboard 3.0 layout + +Without any options, `KBD_VARIANT_2` is the default. To build for the +standalone keyboard for, define `KBD_MODE_STANDALONE` using +`REFORM_KBD_OPTIONS` like this: + + make REFORM_KBD_OPTIONS="-DKBD_VARIANT_2 -DKBD_MODE_STANDALONE" + make REFORM_KBD_OPTIONS="-DKBD_VARIANT_3 -DKBD_MODE_STANDALONE" To flash, put your keyboard into [flashing mode](https://mntre.com/reform2/handbook/parts.html#keyboard-firmware) and run: `sudo ./flash.sh` diff --git a/reform2-keyboard-fw/constants.h b/reform2-keyboard-fw/constants.h @@ -7,12 +7,29 @@ #ifndef _CONSTANTS_H_ #define _CONSTANTS_H_ -#define KBD_FW_REV "R1 20230315" -#define KBD_VARIANT_QWERTY_US -//#define KBD_VARIANT_STANDALONE -//#define KBD_VARIANT_NEO2 -//#define KBD_VARIANT_V -//#define KBD_VARIANT_3 +// KBD_VARIANT_*_US sets KBD_VARIANT_QWERTY_US +#if defined KBD_VARIANT_2_US || defined KBD_VARIANT_3_US +# define KBD_VARIANT_QWERTY_US +#endif +// KBD_VARIANT_3_US sets KBD_VARIANT_3 +#ifdef KBD_VARIANT_3_US +# define KBD_VARIANT_3 +#endif +// KBD_VARIANT_2_US sets KBD_VARIANT_2 (which does nothing right now as it's +// the default) +#ifdef KBD_VARIANT_2_US +# define KBD_VARIANT_2 +#endif +// allow overriding KBD_FW_VERSION by not touching it if it's already set +#ifndef KBD_FW_VERSION +# define KBD_FW_VERSION "20230315" +#endif +// set KBD_FW_REV according to variant 2 or 3 +#ifdef KBD_VARIANT_3 +# define KBD_FW_REV "R3 " KBD_FW_VERSION +#else +# define KBD_FW_REV "R2 " KBD_FW_VERSION +#endif #define KBD_COLS 14 #define KBD_ROWS 6 diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c @@ -290,7 +290,7 @@ int main(void) HID_Device_USBTask(&MediaControl_HID_Interface); USB_USBTask(); counter++; -#ifndef KBD_VARIANT_STANDALONE +#ifndef KBD_MODE_STANDALONE if (counter>=100000) { remote_check_for_low_battery(); counter = 0; diff --git a/reform2-keyboard-fw/menu.c b/reform2-keyboard-fw/menu.c @@ -17,7 +17,7 @@ int current_menu_y = 0; int current_scroll_y = 0; int current_menu_page = 0; -#ifdef KBD_VARIANT_STANDALONE +#ifdef KBD_MODE_STANDALONE #define MENU_NUM_ITEMS 5 const MenuItem menu_items[] = { { "Exit Menu ESC", KEY_ESCAPE }, diff --git a/reform2-keyboard-fw/remote.c b/reform2-keyboard-fw/remote.c @@ -76,7 +76,7 @@ int remote_try_wakeup(void) { int ok = 0; char buf[64]; -#ifdef KBD_VARIANT_STANDALONE +#ifdef KBD_MODE_STANDALONE // there's no remote return 0; #endif @@ -114,7 +114,7 @@ int remote_try_wakeup(void) { int remote_try_command(char* cmd, int print_response) { int ok = 0; -#ifdef KBD_VARIANT_STANDALONE +#ifdef KBD_MODE_STANDALONE // there's no remote return 0; #endif @@ -308,7 +308,7 @@ int remote_get_status(void) { gfx_on(); gfx_flush(); -#ifndef KBD_VARIANT_STANDALONE +#ifndef KBD_MODE_STANDALONE int ok = remote_try_command("s", 1); return ok; #endif diff --git a/reform2-lpc-fw/Makefile b/reform2-lpc-fw/Makefile @@ -354,6 +354,7 @@ endif # GCFLAGS += --specs=nano.specs # For use with the LPCXpresso toolchain # GCFLAGS += -D__REDLIB__ -D__CODE_RED +GCFLAGS += $(REFORM_LPC_OPTIONS) # Assembler Options ASFLAGS = -c diff --git a/reform2-lpc-fw/src/boards/reform2/board_reform2.c b/reform2-lpc-fw/src/boards/reform2/board_reform2.c @@ -34,15 +34,33 @@ #define REFORM_MBREV_D4 4 #define REFORM_MBREV_R1 11 #define REFORM_MBREV_R2 12 // stock R2 -#define REFORM_MBREV_R3 13 // R2 with "NTC instead of RNG/SS" fix -#define REFORM_MBREV_25_R1 25 // motherboard 2.5 +#define REFORM_MBREV_20_R3 13 // R2 with "NTC instead of RNG/SS" fix +#define REFORM_MBREV_25_R2 25 // motherboard 2.5 // don't forget to set this to the correct rev for your motherboard! -#define REFORM_MOTHERBOARD_REV REFORM_MBREV_R3 +#ifndef REFORM_MOTHERBOARD_REV +# define REFORM_MOTHERBOARD_REV REFORM_MBREV_20_R3 +#endif //#define REF2_DEBUG 1 #define FW_STRING1 "MREF2LPC" -#define FW_STRING2 "R4" -#define FW_STRING3 "20230208" +#if REFORM_MOTHERBOARD_REV == 2 +# define FW_STRING2 "D2" +#elif REFORM_MOTHERBOARD_REV == 3 +# define FW_STRING2 "D3" +#elif REFORM_MOTHERBOARD_REV == 4 +# define FW_STRING2 "D4" +#elif REFORM_MOTHERBOARD_REV == 11 +# define FW_STRING2 "R1" +#elif REFORM_MOTHERBOARD_REV == 12 +# define FW_STRING2 "R2" +#elif REFORM_MOTHERBOARD_REV == 13 +# define FW_STRING2 "R3" +#elif REFORM_MOTHERBOARD_REV == 25 +# define FW_STRING2 "25_R2" +#endif +#ifndef FW_STRING3 +# define FW_STRING3 "20230208" +#endif #define FW_REV FW_STRING1 FW_STRING2 FW_STRING3 #define POWERSAVE_SLEEP_SECONDS 1 @@ -194,7 +212,7 @@ uint8_t spir[64]; bool som_is_powered = false; bool imx_uart_enabled = false; -#if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_R3) +#if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_20_R3) #define OVERVOLTAGE_START_VALUE 3.8 #define OVERVOLTAGE_STOP_VALUE 3.6 #else @@ -205,7 +223,7 @@ bool imx_uart_enabled = false; #define UNDERVOLTAGE_CRITICAL_VALUE 2.3 #define MISSING_VALUE_HI 4.5 #define MISSING_VALUE_LO 0.4 -#if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_R3) +#if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_20_R3) #define FULLY_CHARGED_VOLTAGE 3.4 #define FULLY_CHARGED_CURRENT -0.3 #else @@ -447,7 +465,7 @@ void turn_som_power_on(void) { LPC_GPIO->CLR[1] = (1 << 31); // USB 5v off (R1+) LPC_GPIO->CLR[0] = (1 << 7); // AUX 3v3 off (R1+) - if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_R1 && REFORM_MOTHERBOARD_REV < REFORM_MBREV_25_R1) { + if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_R1 && REFORM_MOTHERBOARD_REV < REFORM_MBREV_25_R2) { LPC_GPIO->CLR[1] = (1 << 16); // 3v3 on LPC_GPIO->CLR[1] = (1 << 15); // 5v on } else { @@ -468,7 +486,7 @@ void turn_som_power_on(void) { void turn_som_power_off(void) { LPC_GPIO->CLR[1] = (1 << 28); // hold in reset - if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_R1 && REFORM_MOTHERBOARD_REV < REFORM_MBREV_25_R1) { + if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_R1 && REFORM_MOTHERBOARD_REV < REFORM_MBREV_25_R2) { LPC_GPIO->SET[1] = (1 << 16); // 3v3 off LPC_GPIO->SET[1] = (1 << 15); // 5v off } else { @@ -585,7 +603,7 @@ void boardInit(void) imx_uart_enabled = false; // motherboard 2.5 introduces INA233 instead of INA260 - if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_25_R1) { + if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_25_R2) { ina233_calibrate(); } @@ -1141,7 +1159,7 @@ int main(void) // charge current 2: ~0.2A - if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_25_R1) { + if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_25_R2) { measure_and_accumulate_current_v25(); } else { measure_and_accumulate_current();