diff --git a/pocket-reform-keyboard-fw/pocket-hid/build.sh b/pocket-reform-keyboard-fw/pocket-hid/build.sh index 907e5ae..4c0836c 100755 --- a/pocket-reform-keyboard-fw/pocket-hid/build.sh +++ b/pocket-reform-keyboard-fw/pocket-hid/build.sh @@ -1,8 +1,14 @@ #!/bin/bash +set -e + +mkdir -p build + +cc test/matrix-valid.c -o build/matrix-valid +build/matrix-valid + export PICO_SDK_PATH=$(pwd)/../../pico-sdk -mkdir -p build cd build cmake -DFAMILY=rp2040 .. diff --git a/pocket-reform-keyboard-fw/pocket-hid/test/matrix-valid.c b/pocket-reform-keyboard-fw/pocket-hid/test/matrix-valid.c new file mode 100644 index 0000000..60e107a --- /dev/null +++ b/pocket-reform-keyboard-fw/pocket-hid/test/matrix-valid.c @@ -0,0 +1,86 @@ +#define KBD_COLS 12 +#define KBD_ROWS 6 +#define KBD_MATRIX_SZ KBD_COLS * KBD_ROWS + 4 + +#include +#include +#include "../src/matrix.h" + +#define WHY_HYPER_RETURN \ + "Hyper+Return is required both to power on and to enter the keyboard menu.\n" + +#define WHY_X \ + "Pressing X in the keyboard menu is required to enter bootloader mode.\n" \ + "(Bootloader mode can be exited by toggling the standby power switch.)\n" + +int main() { + int i; + int hyper_loc = -1; + int x_loc = -1; + int enter_loc_fn = -1; + + // irrelevant because they're both defined with [KBD_MATRIX_SZ], + // but if they were changed not to: + if (sizeof(matrix) != sizeof(matrix_fn)) { + fprintf( + stderr, + "Layer size mismatch! %zu != %zu\n", + sizeof(matrix), + sizeof(matrix_fn) + ); + return 1; + } + + for (i = 0; i < sizeof(matrix); i++) { + if (matrix[i] == KEY_COMPOSE) { + hyper_loc = i; + } else if (matrix[i] == KEY_X) { + x_loc = i; + } + } + if (hyper_loc == -1) { + fprintf( + stderr, + "No hyper key (KEY_COMPOSE) found on base layer (matrix)!\n" + WHY_HYPER_RETURN + ); + return 1; + } + if (x_loc == -1) { + fprintf( + stderr, + "No X key (KEY_X) found on base layer (matrix)!\n" + WHY_X + ); + return 1; + } + if (matrix_fn[hyper_loc] != KEY_COMPOSE) { + for (i = 0; i < sizeof(matrix_fn); i++) { + if (matrix_fn[i] == KEY_COMPOSE) { + fprintf( + stderr, + "Hyper key (KEY_COMPOSE) in different position on layers! %d != %d\n", + hyper_loc, + i + ); + return 1; + } + } + fprintf(stderr, "No hyper key (KEY_COMPOSE) found on hyper layer (matrix_fn)!\n"); + return 1; + } + for (i = 0; i < sizeof(matrix_fn); i++) { + if (matrix_fn[i] == KEY_ENTER) { + enter_loc_fn = i; + } + } + if (enter_loc_fn == -1) { + fprintf( + stderr, + "No return key (KEY_ENTER) found on hyper layer (matrix_fn)!\n" + WHY_HYPER_RETURN + ); + return 1; + } + return 0; +}