Skip to content

Commit

Permalink
Several updates (partially? broken)
Browse files Browse the repository at this point in the history
  * `WARN_UNUSED` in `logging`
  * Remove hacky `load_*` macros, force writing names
  * Migrate some code from C to zig
  * Shorter keycode names
  * Fix `halconf.h` order
  * Better handling of some `NULL` returns
  * Remove `TRACE` logging level
  * Tidy up init/deinit priorities
  * Disable (experimental) use of second core
  * Create `introspection.c` for code that has to be parsed by QMK
  • Loading branch information
elpekenin committed Jul 14, 2024
1 parent da11d07 commit dcb2027
Show file tree
Hide file tree
Showing 47 changed files with 704 additions and 56,024 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ kicad.kicad_prl
__pycache__/
*.py[cod]
*$py.class

TODO.md

.zig-cache
zig-out
6 changes: 6 additions & 0 deletions firmware/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"operation": "pr",
"id": 20032
},
{
// #23679-ish
"operation": "merge",
"repo": "https://github.com/elpekenin/qmk_firmware",
"branch": "rgb_pr"
},
{
"operation": "checkout",
"files": ["drivers/painter/il91874"],
Expand Down
3 changes: 0 additions & 3 deletions firmware/keyboards/elpekenin/access/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ touch_device_t ili9341_touch = &ili9341_touch_driver;
void keyboard_post_init_kb(void) {
debug_enable = true;

logging(UNKNOWN, LOG_TRACE, "-- kb init --");

UNUSED bool ret = true;

#if defined (QUANTUM_PAINTER_ENABLE)
Expand Down Expand Up @@ -109,6 +107,5 @@ void keyboard_post_init_kb(void) {

// *** User ***

logging(UNKNOWN, LOG_TRACE, "-- user code --");
keyboard_post_init_user();
}
2 changes: 1 addition & 1 deletion firmware/keyboards/elpekenin/access/compile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ KM=elpekenin

for SIDE in left right
do
qmk compile -kb $KB -km $KM --compiledb -e MAKECMDGOALS=uf2-split-$SIDE -e TARGET=$SIDE > errors.log 2>&1 || (cat errors.log && exit 1)
qmk compile -kb $KB -km $KM --compiledb -e MAKECMDGOALS=uf2-split-$SIDE -e TARGET=$SIDE > errors.log 2>&1 -e CC=qmk-arm-gcc || (cat errors.log && exit 1)
done
10 changes: 2 additions & 8 deletions firmware/keyboards/elpekenin/access/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@

#pragma once

#include_next <halconf.h>

#undef HAL_USE_PWM
#define HAL_USE_PWM TRUE

#undef HAL_USE_SPI
#define HAL_USE_SPI TRUE

#undef SPI_USE_WAIT
#define SPI_USE_WAIT TRUE

#include_next <halconf.h>
1 change: 1 addition & 0 deletions firmware/keyboards/elpekenin/access/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"matrix": [0, 6]
},
"features": {
"console": true,
"extrakey": true,
"quantum_painter": true,
"rgb_matrix": true,
Expand Down
65 changes: 32 additions & 33 deletions firmware/keyboards/elpekenin/access/keymaps/elpekenin/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,47 @@

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QWERTY] = LAYOUT(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, ES_PLUS,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, TD_NTIL, KC_ENT,
KC_LSFT, TD_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_VOLU,
KC_LCTL, KC_LGUI, TL_UPPR, KC_LALT, TD_SPC, R_SPC, TL_LOWR, KC_LEFT, KC_DOWN, KC_RIGHT
ESC, N1, N2, N3, N4, N5, N6, N7, N8, N9, N0, BSPC,
TAB, Q, W, E, R, T, Y, U, I, O, P, PLUS,
XXXXXXX, A, S, D, F, G, H, J, K, L, TD_NTIL, XXXXXXX,
SFT, TD_Z, X, C, V, B, N, M, COMM, DOT, MINS, GRV,
CTL, GUI, ALT, TL_UPPR, TD_SPC, ENT, TL_LOWR, XXXXXXX, XXXXXXX, KC_VOLU
),

// LOWER
[_FN1] = LAYOUT(
XXXXXXX, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_9, KC_F10, ES_BSLS,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, ES_LBRC, ES_RBRC, PK_CPYR,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_VAI, RGB_MOD,
XXXXXXX, XXXXXXX, _______, XXXXXXX, PK_UCIS, XXXXXXX, _______, RGB_SPD, RGB_VAD, RGB_SPI
XXXXXXX, PIPE, AT, HASH, F4, F5, F6, F7, F8, F9, F10, BSLS,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, LBRC, RBRC, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, LCBR, RCBR, PK_CPYR,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RM_VALU, XXXXXXX,
_______, _______, _______, _______, PK_UCIS, _______, _______, RM_SPDU, RM_VALD, RM_SPDD
),

// UPPER
// Note: Using number row keycodes instead of numpad, so we dont care about numlock
[_FN2] = LAYOUT(
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_7, KC_8, KC_9, XXXXXXX, XXXXXXX, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_4, KC_5, KC_6, XXXXXXX, XXXXXXX, XXXXXXX,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_1, KC_2, KC_3, XXXXXXX, RGB_VAI, XXXXXXX,
XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, KC_0, _______, RGB_SPD, RGB_VAD, RGB_SPI
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, BSLS,
ESC, N1, N2, N3, N4, N5, N6, N7, N8, N9, N0, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, LEFT, DOWN, UP, RIGHT, XXXXXXX, XXXXXXX,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RM_VALU, XXXXXXX,
_______, _______, _______, _______, _______, _______, _______, RM_SPDU, RM_VALD, RM_SPDD
),

[_FN3] = LAYOUT(
XXXXXXX, ES_PIPE, ES_AT, ES_HASH, ES_TILD, ES_EURO, ES_NOT, XXXXXXX, XXXXXXX, XXXXXXX, ES_QUOT, ES_BSLS,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, TD_GRV, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, ES_LCBR, ES_RCBR, XXXXXXX,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, ES_MINS, XXXXXXX, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
),
// [_FN3] = LAYOUT(
// XXXXXXX, PIPE, AT, HASH, TILD, EURO, NOT, XXXXXXX, XXXXXXX, XXXXXXX, QUOT, BSLS,
// XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, TD_GRV, XXXXXXX,
// XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, LCBR, RCBR, XXXXXXX,
// _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, MINS, XXXXXXX, XXXXXXX,
// XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
// ),

// ADJUST
[_RST] = LAYOUT(
QK_BOOT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, PK_LOG, PK_GAME, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, EE_CLR,
QK_BOOT, XXXXXXX, F2, XXXXXXX, F4, PK_LOG, PK_GAME, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, EE_CLR,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
PK_QCLR, AC_TOGG, XXXXXXX, XXXXXXX, PK_SIZE, PK_PCSH, PK_KLOG, PK_CRSH, XXXXXXX, XXXXXXX, XXXXXXX, QK_RBT,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
// XXXXXXX, XXXXXXX, _______, XXXXXXX, DB_TOGG, DB_TOGG, _______, XXXXXXX, XXXXXXX, AC_DICT
XXXXXXX, XXXXXXX, _______, XXXXXXX, DB_TOGG, DB_TOGG, _______, XXXXXXX, XXXXXXX, XXXXXXX
XXXXXXX, XXXXXXX, _______, _______, DB_TOGG, DB_TOGG, _______, XXXXXXX, XXXXXXX, XXXXXXX
),
};

Expand Down Expand Up @@ -84,16 +83,16 @@ static uint32_t read_touch_callback(uint32_t trigger_time, void *cb_arg) {
void keyboard_post_init_keymap(void) {
#if defined(QUANTUM_PAINTER_ENABLE)
# if IS_LEFT_HAND
load_display(il91874);
load_display(il91874, "il91874");
# endif

# if IS_RIGHT_HAND
load_display(ili9163);
load_display(ili9341);
load_display(ili9163, "ili9163");
load_display(ili9341, "ili9341");

set_uptime_device(ili9341);
set_logging_device(ili9341);
set_heap_stats_device(ili9341);
// set_uptime_device(ili9341);
// set_logging_device(ili9341);
// set_heap_stats_device(ili9341);
set_layer_device(ili9341);
# if defined(KEYLOG_ENABLE)
set_keylog_device(ili9341);
Expand All @@ -116,9 +115,9 @@ void build_info_sync_keymap_callback(void) {
#endif
}

#if defined(QUANTUM_PAINTER_ENABLE) && IS_RIGHT_HAND
#if 0 && defined(QUANTUM_PAINTER_ENABLE) && IS_RIGHT_HAND
static void start_animation(void) {
qp_animate(qp_get_device_by_name("ili9163"), 0, 0, qp_get_img_by_name("gfx_pedro"));
qp_animate(qp_get_device_by_name("ili9163"), 0, 0, qp_get_img_by_name(<image>));
}
// somehow fails from PEKE_CORE1_INIT, but not PEKE_POST_INIT
// ... which makes no sense as the actual logic happens on core1 (__real_deferred_exec_task)
Expand Down
75 changes: 75 additions & 0 deletions firmware/users/elpekenin/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const std = @import("std");

const MCU = struct {
name: []const u8,
target: std.Target.Query,
};

const KnownMcus = [_]MCU{
.{
.name = "RP2040",
.target = .{
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m0plus },
.os_tag = .freestanding,
.abi = .eabi,
},
},
};

fn getTarget(mcu: []const u8) std.Target.Query {
inline for (KnownMcus) |known_mcu| {
if (std.mem.eql(u8, mcu, known_mcu.name)) {
return known_mcu.target;
}
}

std.debug.panic("Unknown MCU: {s}", .{mcu});
}

pub fn build(b: *std.Build) !void {
const mcu = b.option([]const u8, "mcu", "MCU to compile for") orelse @panic("Select a MCU");
const target = b.resolveTargetQuery(getTarget(mcu));

const optimize = b.standardOptimizeOption(.{});

// const elpekenin = ".";
// const users = elpekenin ++ "/..";
// const qmk = users ++ "/..";
// const platforms = qmk ++ "/platforms";
// const lib = qmk ++ "/lib";
// const chibios = lib ++ "/chibios/os";

const elpekenin_lib = b.addStaticLibrary(.{
.root_source_file = b.path("src/zig/elpekenin.zig"),
.name = "elpekenin",
.target = target,
.optimize = optimize,
});

elpekenin_lib.is_linking_libc = true;

// // ideally, we would only need these two paths
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = qmk});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = elpekenin ++ "/include"});

// // ... but QMK's includes are a mess
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = chibios ++ "/common/portability/GCC"});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = chibios ++ "/hal/include"});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = chibios ++ "/hal/osal/rt-nil"});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = chibios ++ "/license"});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = chibios ++ "/rt/include"});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = lib ++ "/printf/src/printf"});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = platforms});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = platforms ++ "/chibios"});
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = qmk ++ "/quantum"});

// // ... and my 3rd_party libs too :P
// elpekenin_lib.addSystemIncludePath(.{ .cwd_relative = elpekenin ++ "/3rd_party/backtrace/include"});

// // hack newlib include path too...
// elpekenin_lib.addSystemIncludePath(.{.cwd_relative = "/usr/include/newlib/"});

// generate the .a file
b.installArtifact(elpekenin_lib);
}
5 changes: 2 additions & 3 deletions firmware/users/elpekenin/include/elpekenin/build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ typedef struct PACKED {
enabled_features_t features;
} build_info_t;

PURE build_info_t get_build_info(void);
build_info_t get_build_info(void);

NON_NULL(1) READ_ONLY(1) void set_build_commit(const char *commit);
void set_build_features(enabled_features_t features);
void set_build_info(build_info_t new_build_info);
3 changes: 1 addition & 2 deletions firmware/users/elpekenin/include/elpekenin/crash.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ NON_NULL(1) RETURN_NO_NULL WRITE_ONLY(1) backtrace_t *get_crash_call_stack(uint8
void print_crash_call_stack(void);
void clear_crash_info(void);

const char *get_crash_msg(void);
void set_crash_msg(const char *msg);
void set_crash_info(const char *msg);
95 changes: 95 additions & 0 deletions firmware/users/elpekenin/include/elpekenin/keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,104 @@

#include <quantum/keymap_extras/keymap_spanish.h>

// aliases
#define _______ KC_TRNS
#define R_SPC LT(_FN3, KC_SPC)

#define KC(x) ES_##x /* just so that adapting this code to other languages is easy */

// these do not have ES_*
#define CTL KC_LCTL
#define SFT KC_LSFT
#define GUI KC_LGUI
#define ALT KC_LALT

#define ESC KC_ESC
#define BSPC KC_BSPC
#define TAB KC_TAB
#define SPC KC_SPC
#define ENT KC_ENT
#define DEL KC_DEL

#undef UP
#define UP KC_UP
#define LEFT KC_LEFT
#define DOWN KC_DOWN
#define RIGHT KC_RIGHT

#define F1 KC_F1
#define F2 KC_F2
#define F3 KC_F3
#define F4 KC_F4
#define F5 KC_F5
#define F6 KC_F6
#define F7 KC_F7
#define F8 KC_F8
#define F9 KC_F9
#define F10 KC_F10
#define F11 KC_F11
#define F12 KC_F12

// hacky
#define RABK LSFT(LABK) /* cant use S(), it gets redefined */

#define PIPE KC(PIPE)
#define AT KC(AT)
#define HASH KC(HASH)
#define LABK KC(LABK)
#define PLUS KC(PLUS)
#define COMM KC(COMM)
#define DOT KC(DOT)
#define MINS KC(MINS)
#define GRV KC(GRV)
#define BSLS KC(BSLS)
#define LBRC KC(LBRC)
#define RBRC KC(RBRC)
#define LCBR KC(LCBR)
#define RCBR KC(RCBR)

#define N0 KC(0)
#define N1 KC(1)
#define N2 KC(2)
#define N3 KC(3)
#define N4 KC(4)
#define N5 KC(5)
#define N6 KC(6)
#define N7 KC(7)
#define N8 KC(8)
#define N9 KC(9)

#undef A
#undef C
#undef G
#undef S
#define A KC(A)
#define B KC(B)
#define C KC(C)
#define D KC(D)
#define E KC(E)
#define F KC(F)
#define G KC(G)
#define H KC(H)
#define I KC(I)
#define J KC(J)
#define K KC(K)
#define L KC(L)
#define M KC(M)
#define N KC(N)
#define O KC(O)
#define P KC(P)
#define Q KC(Q)
#define R KC(R)
#define S KC(S)
#define T KC(T)
#define U KC(U)
#define V KC(V)
#define W KC(W)
#define X KC(X)
#define Y KC(Y)
#define Z KC(Z)

// note: these are always defined, but may not do anything based on features enabled
enum userspace_keycodes {
__CUSTOM_KEYCODES_START = QK_USER,
Expand Down
Loading

0 comments on commit dcb2027

Please sign in to comment.