keyboard fw polishing for release

This commit is contained in:
Lukas F. Hartmann 2024-04-17 15:52:24 +02:00
parent ee09e6db60
commit 43c2f24563
No known key found for this signature in database
GPG Key ID: 376511EB67AD7BAF
13 changed files with 584 additions and 498 deletions

View File

@ -30,7 +30,7 @@ target_include_directories(${PROJECT} PUBLIC
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
family_configure_device_example(${PROJECT} noos)
target_link_libraries(${PROJECT} PRIVATE pico_stdlib pico_multicore tinyusb_device tinyusb_board hardware_pwm hardware_i2c hardware_pio)
target_link_libraries(${PROJECT} PRIVATE pico_stdlib pico_multicore tinyusb_device tinyusb_board hardware_pwm hardware_i2c hardware_pio hardware_watchdog)
target_compile_definitions(${PROJECT} PUBLIC PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1)

View File

@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include "reform2kbdbitmapfont.xbm"
int main(int argc, char** argv) {
FILE* f = 0;
if (argc>1) f = fopen(argv[1],"w");
int pitch = 192;
if (f) {
// expand bits to bytes
unsigned char* expanded = malloc(sizeof(reform2kbdbitmapfont_bits)*8);
for (int i=0; i<sizeof(reform2kbdbitmapfont_bits); i++) {
if (i%24==0) printf("\n");
for (int j=0; j<8; j++) {
expanded[i*8+j] = (reform2kbdbitmapfont_bits[i]&(1<<j)) ? 1 : 0;
if (expanded[i*8+j]) {
printf("#");
} else {
printf(".");
}
}
}
printf("\n");
fprintf(f, "const unsigned char font[] = {\n");
for (int c=0; c<0x100; c++) {
int y = c/32;
int x = c%32;
for (int j=0; j<6; j++) {
unsigned char bt = 0;
for (int i=0; i<8; i++) {
bt |= expanded[(y*8+i)*pitch + x*6 + j]<<(i);
}
fprintf(f, "0x%02x, ", bt);
}
fprintf(f, "\n");
}
fprintf(f, "\n};\n");
fclose(f);
free(expanded);
} else {
printf("error: couldn't open output file.\n");
return 1;
}
return 0;
}

View File

@ -1,259 +1,259 @@
const unsigned char font[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5f, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x07, 0x00,
0x24, 0x7e, 0x24, 0x7e, 0x24, 0x00,
0x26, 0x49, 0x7f, 0x49, 0x32, 0x00,
0x00, 0x22, 0x10, 0x08, 0x44, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x03, 0x00, 0x00,
0x00, 0x3e, 0x41, 0x41, 0x00, 0x00,
0x00, 0x41, 0x41, 0x3e, 0x00, 0x00,
0x2a, 0x1c, 0x3e, 0x1c, 0x2a, 0x00,
0x08, 0x08, 0x3e, 0x08, 0x08, 0x00,
0x00, 0x00, 0x40, 0x30, 0x00, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00,
0x08, 0x04, 0x02, 0x7f, 0x00, 0x00,
0x42, 0x61, 0x51, 0x49, 0x46, 0x00,
0x22, 0x41, 0x49, 0x49, 0x36, 0x00,
0x18, 0x14, 0x12, 0x7f, 0x10, 0x00,
0x2f, 0x49, 0x49, 0x49, 0x31, 0x00,
0x3e, 0x49, 0x49, 0x49, 0x31, 0x00,
0x41, 0x21, 0x11, 0x09, 0x07, 0x00,
0x36, 0x49, 0x49, 0x49, 0x36, 0x00,
0x26, 0x49, 0x49, 0x49, 0x3e, 0x00,
0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x34, 0x00, 0x00,
0x08, 0x14, 0x22, 0x41, 0x00, 0x00,
0x14, 0x14, 0x14, 0x14, 0x14, 0x00,
0x00, 0x41, 0x22, 0x14, 0x08, 0x00,
0x02, 0x01, 0x51, 0x09, 0x06, 0x00,
0x3e, 0x41, 0x4d, 0x51, 0x4e, 0x00,
0x7e, 0x09, 0x09, 0x09, 0x7e, 0x00,
0x7f, 0x49, 0x49, 0x49, 0x36, 0x00,
0x3e, 0x41, 0x41, 0x41, 0x41, 0x00,
0x7f, 0x41, 0x41, 0x41, 0x3e, 0x00,
0x7f, 0x49, 0x49, 0x49, 0x41, 0x00,
0x7f, 0x09, 0x09, 0x09, 0x01, 0x00,
0x3e, 0x41, 0x49, 0x49, 0x79, 0x00,
0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00,
0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
0x31, 0x41, 0x41, 0x41, 0x3f, 0x00,
0x7f, 0x08, 0x14, 0x22, 0x41, 0x00,
0x7f, 0x40, 0x40, 0x40, 0x40, 0x00,
0x7f, 0x02, 0x04, 0x02, 0x7f, 0x00,
0x7f, 0x02, 0x04, 0x08, 0x7f, 0x00,
0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00,
0x7f, 0x09, 0x09, 0x09, 0x06, 0x00,
0x3e, 0x41, 0x51, 0x21, 0x5e, 0x00,
0x7f, 0x09, 0x09, 0x09, 0x76, 0x00,
0x26, 0x49, 0x49, 0x49, 0x32, 0x00,
0x01, 0x01, 0x7f, 0x01, 0x01, 0x00,
0x3f, 0x40, 0x40, 0x40, 0x3f, 0x00,
0x1f, 0x20, 0x40, 0x20, 0x1f, 0x00,
0x7f, 0x20, 0x10, 0x20, 0x7f, 0x00,
0x63, 0x14, 0x08, 0x14, 0x63, 0x00,
0x03, 0x04, 0x78, 0x04, 0x03, 0x00,
0x61, 0x51, 0x49, 0x45, 0x43, 0x00,
0x00, 0x7f, 0x41, 0x41, 0x00, 0x00,
0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
0x00, 0x41, 0x41, 0x7f, 0x00, 0x00,
0x08, 0x04, 0x02, 0x04, 0x08, 0x00,
0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x38, 0x44, 0x44, 0x48, 0x7c, 0x00,
0x7f, 0x44, 0x44, 0x44, 0x38, 0x00,
0x38, 0x44, 0x44, 0x44, 0x44, 0x00,
0x38, 0x44, 0x44, 0x44, 0x7f, 0x00,
0x38, 0x54, 0x54, 0x54, 0x48, 0x00,
0x04, 0x7e, 0x05, 0x05, 0x05, 0x00,
0x08, 0x54, 0x54, 0x54, 0x38, 0x00,
0x7f, 0x08, 0x04, 0x04, 0x78, 0x00,
0x00, 0x00, 0x7a, 0x00, 0x00, 0x00,
0x20, 0x40, 0x40, 0x40, 0x3a, 0x00,
0x7f, 0x08, 0x14, 0x22, 0x40, 0x00,
0x3f, 0x40, 0x40, 0x40, 0x40, 0x00,
0x7c, 0x04, 0x08, 0x04, 0x78, 0x00,
0x7c, 0x04, 0x04, 0x04, 0x78, 0x00,
0x38, 0x44, 0x44, 0x44, 0x38, 0x00,
0x7c, 0x24, 0x24, 0x24, 0x18, 0x00,
0x18, 0x24, 0x24, 0x24, 0x7c, 0x00,
0x7c, 0x08, 0x04, 0x04, 0x04, 0x00,
0x48, 0x54, 0x54, 0x54, 0x24, 0x00,
0x04, 0x3e, 0x44, 0x44, 0x44, 0x00,
0x3c, 0x40, 0x40, 0x40, 0x3c, 0x00,
0x1c, 0x20, 0x40, 0x20, 0x1c, 0x00,
0x3c, 0x40, 0x20, 0x40, 0x3c, 0x00,
0x44, 0x28, 0x10, 0x28, 0x44, 0x00,
0x4c, 0x50, 0x50, 0x20, 0x1c, 0x00,
0x44, 0x64, 0x54, 0x4c, 0x44, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3c, 0x7e, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x5a,
0x5a, 0x42, 0x42, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x42, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0,
0xc0, 0x80, 0x00, 0xff, 0xfe, 0xfc,
0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00,
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0,
0xc0, 0x80, 0x00, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0x3f, 0x3f, 0x3f, 0x07, 0x0f,
0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff,
0xff, 0x07, 0x0f, 0x1f, 0x3f, 0x7f,
0xff, 0xff, 0xff, 0xff, 0x07, 0x0f,
0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff,
0xff, 0x00, 0x00, 0x00, 0xf0, 0xf0,
0x30, 0xb0, 0xb0, 0x70, 0xf0, 0x30,
0xb0, 0xb0, 0xb0, 0xf0, 0x70, 0xb0,
0xb0, 0xb0, 0xf0, 0x70, 0xb0, 0xb0,
0xb0, 0x70, 0xf0, 0x30, 0xb0, 0xb0,
0x70, 0xf0, 0x30, 0x70, 0xf0, 0xf0,
0xf0, 0x70, 0x30, 0xf0, 0xf0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03,
0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x03, 0x07, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03,
0x07, 0x00, 0x00, 0x00, 0x7f, 0x7f,
0x60, 0x7d, 0x7d, 0x62, 0x7f, 0x60,
0x6d, 0x6d, 0x6d, 0x7f, 0x60, 0x7d,
0x7d, 0x7f, 0x7f, 0x70, 0x6f, 0x6f,
0x6f, 0x70, 0x7f, 0x60, 0x7d, 0x7d,
0x62, 0x7f, 0x60, 0x7f, 0x7e, 0x7d,
0x7e, 0x7f, 0x60, 0x7f, 0x7f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5f, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x07, 0x00,
0x24, 0x7e, 0x24, 0x7e, 0x24, 0x00,
0x26, 0x49, 0x7f, 0x49, 0x32, 0x00,
0x00, 0x22, 0x10, 0x08, 0x44, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x03, 0x00, 0x00,
0x00, 0x3e, 0x41, 0x41, 0x00, 0x00,
0x00, 0x41, 0x41, 0x3e, 0x00, 0x00,
0x2a, 0x1c, 0x3e, 0x1c, 0x2a, 0x00,
0x08, 0x08, 0x3e, 0x08, 0x08, 0x00,
0x00, 0x00, 0x40, 0x30, 0x00, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00,
0x08, 0x04, 0x02, 0x7f, 0x00, 0x00,
0x42, 0x61, 0x51, 0x49, 0x46, 0x00,
0x22, 0x41, 0x49, 0x49, 0x36, 0x00,
0x18, 0x14, 0x12, 0x7f, 0x10, 0x00,
0x2f, 0x49, 0x49, 0x49, 0x31, 0x00,
0x3e, 0x49, 0x49, 0x49, 0x31, 0x00,
0x41, 0x21, 0x11, 0x09, 0x07, 0x00,
0x36, 0x49, 0x49, 0x49, 0x36, 0x00,
0x26, 0x49, 0x49, 0x49, 0x3e, 0x00,
0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x34, 0x00, 0x00,
0x08, 0x14, 0x22, 0x41, 0x00, 0x00,
0x14, 0x14, 0x14, 0x14, 0x14, 0x00,
0x00, 0x41, 0x22, 0x14, 0x08, 0x00,
0x02, 0x01, 0x51, 0x09, 0x06, 0x00,
0x3e, 0x41, 0x4d, 0x51, 0x4e, 0x00,
0x7e, 0x09, 0x09, 0x09, 0x7e, 0x00,
0x7f, 0x49, 0x49, 0x49, 0x36, 0x00,
0x3e, 0x41, 0x41, 0x41, 0x41, 0x00,
0x7f, 0x41, 0x41, 0x41, 0x3e, 0x00,
0x7f, 0x49, 0x49, 0x49, 0x41, 0x00,
0x7f, 0x09, 0x09, 0x09, 0x01, 0x00,
0x3e, 0x41, 0x49, 0x49, 0x79, 0x00,
0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00,
0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
0x31, 0x41, 0x41, 0x41, 0x3f, 0x00,
0x7f, 0x08, 0x14, 0x22, 0x41, 0x00,
0x7f, 0x40, 0x40, 0x40, 0x40, 0x00,
0x7f, 0x02, 0x04, 0x02, 0x7f, 0x00,
0x7f, 0x02, 0x04, 0x08, 0x7f, 0x00,
0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00,
0x7f, 0x09, 0x09, 0x09, 0x06, 0x00,
0x3e, 0x41, 0x51, 0x21, 0x5e, 0x00,
0x7f, 0x09, 0x09, 0x09, 0x76, 0x00,
0x26, 0x49, 0x49, 0x49, 0x32, 0x00,
0x01, 0x01, 0x7f, 0x01, 0x01, 0x00,
0x3f, 0x40, 0x40, 0x40, 0x3f, 0x00,
0x1f, 0x20, 0x40, 0x20, 0x1f, 0x00,
0x7f, 0x20, 0x10, 0x20, 0x7f, 0x00,
0x63, 0x14, 0x08, 0x14, 0x63, 0x00,
0x03, 0x04, 0x78, 0x04, 0x03, 0x00,
0x61, 0x51, 0x49, 0x45, 0x43, 0x00,
0x00, 0x7f, 0x41, 0x41, 0x00, 0x00,
0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
0x00, 0x41, 0x41, 0x7f, 0x00, 0x00,
0x08, 0x04, 0x02, 0x04, 0x08, 0x00,
0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x38, 0x44, 0x44, 0x48, 0x7c, 0x00,
0x7f, 0x44, 0x44, 0x44, 0x38, 0x00,
0x38, 0x44, 0x44, 0x44, 0x44, 0x00,
0x38, 0x44, 0x44, 0x44, 0x7f, 0x00,
0x38, 0x54, 0x54, 0x54, 0x48, 0x00,
0x04, 0x7e, 0x05, 0x05, 0x05, 0x00,
0x08, 0x54, 0x54, 0x54, 0x38, 0x00,
0x7f, 0x08, 0x04, 0x04, 0x78, 0x00,
0x00, 0x00, 0x7a, 0x00, 0x00, 0x00,
0x20, 0x40, 0x40, 0x40, 0x3a, 0x00,
0x7f, 0x08, 0x14, 0x22, 0x40, 0x00,
0x3f, 0x40, 0x40, 0x40, 0x40, 0x00,
0x7c, 0x04, 0x08, 0x04, 0x78, 0x00,
0x7c, 0x04, 0x04, 0x04, 0x78, 0x00,
0x38, 0x44, 0x44, 0x44, 0x38, 0x00,
0x7c, 0x24, 0x24, 0x24, 0x18, 0x00,
0x18, 0x24, 0x24, 0x24, 0x7c, 0x00,
0x7c, 0x08, 0x04, 0x04, 0x04, 0x00,
0x48, 0x54, 0x54, 0x54, 0x24, 0x00,
0x04, 0x3e, 0x44, 0x44, 0x44, 0x00,
0x3c, 0x40, 0x40, 0x40, 0x3c, 0x00,
0x1c, 0x20, 0x40, 0x20, 0x1c, 0x00,
0x3c, 0x40, 0x20, 0x40, 0x3c, 0x00,
0x44, 0x28, 0x10, 0x28, 0x44, 0x00,
0x4c, 0x50, 0x50, 0x20, 0x1c, 0x00,
0x44, 0x64, 0x54, 0x4c, 0x44, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3c, 0x7e, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x5a,
0x5a, 0x42, 0x42, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x42, 0x42, 0x7e,
0x3c, 0x7e, 0x42, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x42, 0x7e,
0x11, 0x2b, 0x15, 0x09, 0x11, 0x3f,
0x08, 0x1c, 0x3e, 0x08, 0x08, 0x0f,
0x00, 0x00, 0x08, 0x78, 0xf0, 0xe0,
0xc0, 0xc0, 0xc0, 0xe0, 0xf0, 0x78,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0,
0xc0, 0x80, 0x00, 0xff, 0xfe, 0xfc,
0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00,
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0,
0xc0, 0x80, 0x00, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x0e, 0x0f, 0x0e,
0x7f, 0xfe, 0xff, 0xff, 0xff, 0xfe,
0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
0xf8, 0xf8, 0xf0, 0xe0, 0x60, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0x3f, 0x3f, 0x3f, 0x07, 0x0f,
0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff,
0xff, 0x07, 0x0f, 0x1f, 0x3f, 0x7f,
0xff, 0xff, 0xff, 0xff, 0x07, 0x0f,
0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff,
0xff, 0x00, 0x00, 0x00, 0xf0, 0xf0,
0x30, 0xb0, 0xb0, 0x70, 0xf0, 0x30,
0xb0, 0xb0, 0xb0, 0xf0, 0x70, 0xb0,
0xb0, 0xb0, 0xf0, 0x70, 0xb0, 0xb0,
0xb0, 0x70, 0xf0, 0x30, 0xb0, 0xb0,
0x70, 0xf0, 0x30, 0x70, 0xf0, 0xf0,
0xf0, 0x70, 0x30, 0xf0, 0xf0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xff, 0x3f, 0xff, 0xff,
0x1f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x07, 0x03, 0x01, 0x3f, 0xff, 0xff,
0x7f, 0xff, 0xff, 0x1f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03,
0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x03, 0x07, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03,
0x07, 0x00, 0x00, 0x00, 0x7f, 0x7f,
0x60, 0x7d, 0x7d, 0x62, 0x7f, 0x60,
0x6d, 0x6d, 0x6d, 0x7f, 0x60, 0x7d,
0x7d, 0x7f, 0x7f, 0x70, 0x6f, 0x6f,
0x6f, 0x70, 0x7f, 0x60, 0x7d, 0x7d,
0x62, 0x7f, 0x60, 0x7f, 0x7e, 0x7d,
0x7e, 0x7f, 0x60, 0x7f, 0x7f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x06, 0x13, 0x18, 0x0f, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x0c, 0x07, 0x09,
0x0c, 0x07, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@ -1,15 +1,16 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
#ifndef _KEYBOARD_H_
#define _KEYBOARD_H_
#define PREF_HID_FW_REV "PREFHID20240412"
#define PREF_HID_FW_REV "PREFHID20240416"
void reset_keyboard_state(void);
int get_usb_power_state(void);
void led_set(uint32_t rgb);
void led_task(uint32_t rgb);

View File

@ -1,7 +1,10 @@
/*
SPDX-License-Identifier: MIT
Copyright (c) 2019 Ha Thach (tinyusb.org)
Copyright (c) 2021-2024 MNT Research GmbH (mntre.com)
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
TinyUSB callbacks/code based on code
Copyright 2019 Ha Thach (tinyusb.org)
*/
#include <stdlib.h>
@ -78,7 +81,9 @@ int process_keyboard(uint8_t* resulting_scancodes);
#define STOP_BITS 1
#define PARITY UART_PARITY_NONE
/*------------- MAIN -------------*/
// can be used as a global clock, incrementing around every ~10ms
static int hid_task_counter = 0;
int main(void)
{
board_init();
@ -184,14 +189,22 @@ int main(void)
// Device callbacks
//--------------------------------------------------------------------+
static int usb_power_state = 0;
// Invoked when device is mounted
void tud_mount_cb(void)
{
usb_power_state = 1;
}
// Invoked when device is unmounted
void tud_umount_cb(void)
{
usb_power_state = 0;
}
int get_usb_power_state(void) {
return usb_power_state;
}
// Invoked when usb bus is suspended
@ -199,12 +212,14 @@ void tud_umount_cb(void)
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
void tud_suspend_cb(bool remote_wakeup_en)
{
usb_power_state = 0;
(void) remote_wakeup_en;
}
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
usb_power_state = 1;
}
// RGB LEDS
@ -250,28 +265,22 @@ bool tud_hid_trackball_report(uint8_t report_id,
uint8_t matrix_debounce[KBD_COLS*KBD_ROWS];
uint8_t matrix_state[KBD_COLS*KBD_ROWS];
int active_meta_mode = 0;
uint8_t last_meta_key = 0;
int active_menu_mode = 0;
uint8_t last_menu_key = 0;
uint32_t hyper_enter_long_press_start_ms = 0;
uint8_t* active_matrix = matrix;
bool media_toggle = 0;
bool fn_key = 0; // Am I holding FN?
bool circle = 0; // Am I holding circle?
bool hyper_key = 0; // Am I holding HYPER?
// enter the menu
void enter_meta_mode(void) {
active_meta_mode = 1;
void enter_menu_mode(void) {
active_menu_mode = 1;
reset_and_render_menu();
if (!remote_get_power_state()) {
led_set_brightness(10);
}
}
void exit_meta_mode(void) {
active_meta_mode = 0;
if (!remote_get_power_state()) {
led_set_brightness(0);
}
void exit_menu_mode(void) {
active_menu_mode = 0;
}
void reset_keyboard_state(void) {
@ -279,7 +288,7 @@ void reset_keyboard_state(void) {
matrix_debounce[i] = 0;
matrix_state[i] = 0;
}
last_meta_key = 0;
last_menu_key = 0;
reset_menu();
}
@ -356,38 +365,54 @@ int process_keyboard(uint8_t* resulting_scancodes) {
total_pressed++;
// hyper + enter? open OLED menu
if (keycode == KEY_ENTER && fn_key) {
if (!active_meta_mode && !last_meta_key) {
enter_meta_mode();
if (keycode == KEY_ENTER && hyper_key) {
if (!last_menu_key) {
if (!active_menu_mode) {
enter_menu_mode();
}
uint32_t now_ms = board_millis();
if (!now_ms) now_ms++;
if (!hyper_enter_long_press_start_ms) {
hyper_enter_long_press_start_ms = now_ms;
// edge case
}
if (now_ms - hyper_enter_long_press_start_ms > 1000) {
// turn on computer after 2 seconds of holding hyper + enter
execute_menu_function(KEY_1);
exit_menu_mode();
last_menu_key = KEY_1;
hyper_enter_long_press_start_ms = 0;
}
}
} else if (keycode == KEY_F12) {
remote_wake_som();
} else if (keycode == KEY_COMPOSE) {
fn_key = 1;
hyper_key = 1;
active_matrix = matrix_fn;
} else {
if (active_meta_mode) {
if (active_menu_mode) {
// not holding the same key?
if (last_meta_key != keycode) {
// hyper/circle/menu functions
int stay_meta = execute_meta_function(keycode);
if (last_menu_key != keycode) {
// hyper/menu functions
int stay_menu = execute_menu_function(keycode);
// don't repeat action while key is held down
last_meta_key = keycode;
last_menu_key = keycode;
// exit meta mode
if (!stay_meta) {
exit_meta_mode();
// exit menu mode
if (!stay_menu) {
exit_menu_mode();
}
// after wake-up from sleep mode, skip further keymap processing
if (stay_meta == 2) {
if (stay_menu == 2) {
reset_keyboard_state();
enter_meta_mode();
enter_menu_mode();
return 0;
}
}
} else if (!last_meta_key) {
// not meta mode, regular key: report keypress via USB
} else if (!last_menu_key) {
// not menu mode, regular key: report keypress via USB
// 6 keys is the limit in the HID descriptor
if (used_key_codes < MAX_SCANCODES && resulting_scancodes && y < 5) {
resulting_scancodes[used_key_codes++] = keycode;
@ -397,15 +422,26 @@ int process_keyboard(uint8_t* resulting_scancodes) {
} else {
// key not pressed
if (keycode == KEY_COMPOSE) {
fn_key = 0;
hyper_key = 0;
active_matrix = matrix;
hyper_enter_long_press_start_ms = 0;
} else if (keycode == KEY_ENTER) {
hyper_enter_long_press_start_ms = 0;
}
}
}
}
// if no more keys are held down, allow a new meta command
if (total_pressed<1) last_meta_key = 0;
// if no more keys are held down, allow a new menu command
if (total_pressed<1) last_menu_key = 0;
// if device is off and user is pressing random keys,
// show a hint for turning on the device
if (!get_usb_power_state() && !remote_get_power_state()) {
if (total_pressed>0 && !active_menu_mode && !hyper_key && !last_menu_key) {
execute_menu_function(KEY_H);
}
}
return used_key_codes;
}
@ -445,7 +481,7 @@ static int poll_trackball()
tb_nx = (int8_t)buf[0];
tb_ny = (int8_t)buf[1];
// HACK hue/value wheel
// backlight hue/value wheel
if (matrix_state[KBD_COLS*4+0]) {
if (tb_ny) {
// shift held? saturation
@ -572,8 +608,6 @@ void led_bitmap(uint8_t row, const uint8_t* row_rgb) {
}
int hid_task_counter = 0;
// Every 10ms, we will sent 1 report for each HID profile (keyboard, mouse etc ..)
// tud_hid_report_complete_cb() is used to send the next report after previous one is complete
void hid_task(void)
@ -588,11 +622,15 @@ void hid_task(void)
}
start_ms += interval_ms;
if (tud_suspended()) {
usb_power_state = 0;
} else {
usb_power_state = 1;
}
// allow trackball backlight control even if there's no USB yet
if (hid_task_counter%10 == 0) {
if (tud_suspended() && remote_get_power_state()) {
poll_trackball();
}
if (!usb_power_state && remote_get_power_state()) {
poll_trackball();
}
// Remote wakeup
@ -609,6 +647,19 @@ void hid_task(void)
hid_task_counter++;
if (hid_task_counter%100 == 0) {
refresh_menu_page();
// power state debugging
/*if (usb_power_state) {
gfx_poke_cstr(0,0,"[usb on]");
} else {
gfx_poke_cstr(0,0,"[usb off]");
}
if (remote_get_power_state()) {
gfx_poke_cstr(10,0,"[pwr on]");
} else {
gfx_poke_cstr(10,0,"[pwr off]");
}*/
gfx_flush();
}
}
@ -618,61 +669,61 @@ int led_hue = 127;
typedef struct RgbColor
{
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char r;
unsigned char g;
unsigned char b;
} RgbColor;
typedef struct HsvColor
{
unsigned char h;
unsigned char s;
unsigned char v;
unsigned char h;
unsigned char s;
unsigned char v;
} HsvColor;
RgbColor HsvToRgb(HsvColor hsv)
{
RgbColor rgb;
unsigned char region, remainder, p, q, t;
RgbColor rgb;
unsigned char region, remainder, p, q, t;
if (hsv.s == 0)
if (hsv.s == 0)
{
rgb.r = hsv.v;
rgb.g = hsv.v;
rgb.b = hsv.v;
return rgb;
rgb.r = hsv.v;
rgb.g = hsv.v;
rgb.b = hsv.v;
return rgb;
}
region = hsv.h / 43;
remainder = (unsigned char)((hsv.h - (region * 43)) * 6);
region = hsv.h / 43;
remainder = (unsigned char)((hsv.h - (region * 43)) * 6);
p = (unsigned char)((hsv.v * (255 - hsv.s)) >> 8);
q = (unsigned char)((hsv.v * (255 - ((hsv.s * remainder) >> 8))) >> 8);
t = (unsigned char)((hsv.v * (255 - ((hsv.s * (255 - remainder)) >> 8))) >> 8);
p = (unsigned char)((hsv.v * (255 - hsv.s)) >> 8);
q = (unsigned char)((hsv.v * (255 - ((hsv.s * remainder) >> 8))) >> 8);
t = (unsigned char)((hsv.v * (255 - ((hsv.s * (255 - remainder)) >> 8))) >> 8);
switch (region)
switch (region)
{
case 0:
rgb.r = hsv.v; rgb.g = t; rgb.b = p;
break;
case 1:
rgb.r = q; rgb.g = hsv.v; rgb.b = p;
break;
case 2:
rgb.r = p; rgb.g = hsv.v; rgb.b = t;
break;
case 3:
rgb.r = p; rgb.g = q; rgb.b = hsv.v;
break;
case 4:
rgb.r = t; rgb.g = p; rgb.b = hsv.v;
break;
default:
rgb.r = hsv.v; rgb.g = p; rgb.b = q;
break;
case 0:
rgb.r = hsv.v; rgb.g = t; rgb.b = p;
break;
case 1:
rgb.r = q; rgb.g = hsv.v; rgb.b = p;
break;
case 2:
rgb.r = p; rgb.g = hsv.v; rgb.b = t;
break;
case 3:
rgb.r = p; rgb.g = q; rgb.b = hsv.v;
break;
case 4:
rgb.r = t; rgb.g = p; rgb.b = hsv.v;
break;
default:
rgb.r = hsv.v; rgb.g = p; rgb.b = q;
break;
}
return rgb;
return rgb;
}
void led_set(uint32_t rgb) {
@ -775,30 +826,19 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
(void) instance;
(void) buffer;
//char repinfo[64];
//sprintf(repinfo, "Rep: %d/%d ", report_type, report_id);
//gfx_poke_str(1, 1, repinfo);
//sprintf(repinfo, "Len: %d ", bufsize);
//gfx_poke_str(1, 2, repinfo);
/*if (buffer) {
sprintf(repinfo, "%02x %02x %02x %02x %02x %02x", buffer[0], buffer[1], buffer[2],
buffer[3], buffer[4], buffer[5]);
gfx_poke_str(0, 0, repinfo);
}
gfx_flush();*/
//return;
if (bufsize < 5) return;
// FIXME
if (report_type == 2) {
// Big Reform style
if (report_id == 'x') {
const char* cmd = (const char*)buffer;
// uncomment for debugging
/*char repinfo[64];
sprintf(repinfo, "cm: %c%c%c%c 4: %d sz: %d", cmd[0],cmd[1],cmd[2],cmd[3], cmd[4], bufsize);
gfx_poke_str(0, 0, repinfo);
gfx_flush();*/
if (cmd == strnstr(cmd, CMD_TEXT_FRAME, 4)) {
gfx_clear();
gfx_on();
@ -819,11 +859,9 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
gfx_flush();
}
else if (cmd == strnstr(cmd, CMD_POWER_OFF, 4)) {
//reset_menu();
//anim_goodbye();
reset_menu();
remote_turn_off_som();
//keyboard_power_off();
//reset_keyboard_state();
reset_keyboard_state();
}
else if (cmd == strnstr(cmd, CMD_OLED_CLEAR, 4)) {
gfx_clear();
@ -841,8 +879,7 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
led_task(pixel_grb);
}
else if (cmd == strnstr(cmd, CMD_LOGO, 4)) {
// FIXME
//anim_hello();
anim_hello();
}
else if (cmd == strnstr(cmd, CMD_OLED_BRITE, 4)) {
uint8_t val = (uint8_t)atoi((const char*)&buffer[4]);
@ -875,3 +912,12 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
}
}*/
}
// TODO
// from https://github.com/raspberrypi/pico-sdk/issues/1118
// Support for default BOOTSEL reset by changing baud rate
/*void tud_cdc_line_coding_cb(__unused uint8_t itf, cdc_line_coding_t const* p_line_coding) {
if (p_line_coding->bit_rate == 110) {
reset_usb_boot(gpio_mask, 0);
}
}*/

View File

@ -1,7 +1,7 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
#include "usb_hid_keys.h"
@ -159,28 +159,3 @@ uint8_t matrix_fn[KBD_MATRIX_SZ] = {
KEY_PAGEDOWN,
KEY_END
};
// Second layer (toggled by HYPER+CIRCLE)
/*uint8_t matrix_fn_toggled[KBD_MATRIX_SZ] = {
// Custom top row
KEY_ESCAPE,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
HID_KEYBOARD_SC_MEDIA_BACKWARD,
HID_KEYBOARD_SC_MEDIA_PLAY,
HID_KEYBOARD_SC_MEDIA_FORWARD,
HID_KEYBOARD_SC_MEDIA_MUTE,
HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN,
HID_KEYBOARD_SC_MEDIA_VOLUME_UP,
KEY_CIRCLE,
MATRIX_DEFAULT_ROW_2,
MATRIX_DEFAULT_ROW_3,
MATRIX_DEFAULT_ROW_4,
MATRIX_DEFAULT_ROW_5,
MATRIX_DEFAULT_ROW_6
};*/

View File

@ -1,18 +1,17 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
//#include "backlight.h"
//#include "keyboard.h"
#include "menu.h"
#include "oled.h"
#include "remote.h"
#include "usb_hid_keys.h"
#include "keyboard.h"
#include "pico/stdlib.h"
//#include "scancodes.h"
#include "pico/bootrom.h"
#include "hardware/watchdog.h"
int current_menu_y = 0;
int current_scroll_y = 0;
@ -20,32 +19,30 @@ int current_menu_page = 0;
int8_t logo_timeout_ticks = 0;
#ifdef KBD_MODE_STANDALONE
#define MENU_NUM_ITEMS 5
const MenuItem menu_items[] = {
{ "Exit Menu ESC", KEY_ESC },
{ "Key Backlight- F1", KEY_F1 },
{ "Key Backlight+ F2", KEY_F2 },
{ "System Status s", KEY_S },
{ "USB Flashing Mode x", KEY_X },
};
// TODO
#else
#define MENU_NUM_ITEMS 7
const MenuItem menu_items[] = {
{ "Exit Menu ESC", KEY_ESC },
{ "Power On 1", KEY_1 },
{ "Power Off 0", KEY_0 },
{ "Reset r", KEY_R },
{ "Battery Status b", KEY_B },
{ "Wake SPC", KEY_SPACE },
{ "System Status s", KEY_S },
// Only needed for debugging.
// The keyboard will go to sleep when turning off
// main system power.
{ "KBD Power-Off p", KEY_P },
{ "Reset Keyboard r", KEY_R },
};
#endif
void rp2040_reset() {
watchdog_enable(1, 1);
while(1);
}
void rp2040_reset_to_bootloader() {
reset_usb_boot(0, 0);
while(1);
}
void reset_menu() {
current_scroll_y = 0;
current_menu_y = 0;
@ -66,6 +63,7 @@ void render_menu(int y) {
gfx_poke_cstr(0,(uint8_t)(i-y),menu_items[i].title);
}
gfx_on();
gfx_contrast(0xff);
gfx_flush();
}
@ -78,41 +76,57 @@ void refresh_menu_page() {
}
}
int execute_menu_function(int y) {
int execute_menu_row_function(int y) {
current_menu_page = MENU_PAGE_NONE;
if (y>=0 && y<MENU_NUM_ITEMS) {
current_menu_page = MENU_PAGE_OTHER;
return execute_meta_function(menu_items[y].keycode);
return execute_menu_function(menu_items[y].keycode);
}
return execute_meta_function(KEY_ESC);
return execute_menu_function(KEY_ESC);
}
// returns 1 for navigation function (stay in meta mode), 0 for terminal function
int execute_meta_function(int keycode) {
// returns 1 for navigation function (stay in menu mode), 0 for terminal function
int execute_menu_function(int keycode) {
if (keycode == KEY_0) {
// TODO: are you sure?
led_set_brightness(0);
anim_goodbye();
remote_turn_off_som();
//keyboard_power_off();
reset_keyboard_state();
// Directly enter menu again
return 2;
return 0;
}
else if (keycode == KEY_1) {
//kbd_brightness_init();
if (remote_turn_on_som()) {
// initial backlight color
led_set(0x004040);
anim_hello();
}
return 0;
}
else if (keycode == KEY_R) {
// TODO: are you sure?
//remote_reset_som();
// reset the MCU
rp2040_reset();
}
else if (keycode == KEY_T) {
render_tina();
logo_timeout_ticks = 10;
current_menu_page = MENU_PAGE_MNT_LOGO;
return 0;
}
else if (keycode == KEY_SPACE) {
remote_wake_som();
}
else if (keycode == KEY_H) {
// turn-on hint page
gfx_clear();
gfx_poke_cstr(0,1,"Press \x8a + \x8b for menu.");
gfx_poke_cstr(0,2,"Hold to power up.");
gfx_flush();
logo_timeout_ticks = 5;
current_menu_page = MENU_PAGE_MNT_LOGO;
return 0;
}
else if (keycode == KEY_B) {
current_menu_page = MENU_PAGE_BATTERY_STATUS;
remote_get_voltages();
@ -146,20 +160,20 @@ int execute_meta_function(int keycode) {
return 1;
}
else if (keycode == KEY_ENTER) {
return execute_menu_function(current_menu_y);
return execute_menu_row_function(current_menu_y);
}
else if (keycode == KEY_ESC) {
gfx_clear();
gfx_flush();
}
/*else if (keycode == KEY_X) {
else if (keycode == KEY_X) {
gfx_clear();
gfx_poke_str(1, 1, "Entered firmware");
gfx_poke_str(1, 2, "update mode.");
gfx_poke_cstr(1, 1, "Entered firmware");
gfx_poke_cstr(1, 2, "update mode.");
gfx_on();
gfx_flush();
jump_to_bootloader();
}*/
rp2040_reset_to_bootloader();
}
else if (keycode == KEY_L) {
anim_hello();
return 0;
@ -171,11 +185,34 @@ int execute_meta_function(int keycode) {
return 0;
}
void render_tina(void) {
gfx_clear();
gfx_on();
for (uint8_t y=0; y<4; y++) {
gfx_invert_row(y);
}
for (int f=13; f>=0; f--) {
for (uint8_t y=0; y<4; y++) {
for (uint8_t x=0; x<6; x++) {
if (x==6) {
if (x+8+f<21) {
gfx_poke((uint8_t)(x+8+f),y,' ');
}
} else {
if (x+8+f<21) {
gfx_poke((uint8_t)(x+8+f),y,(uint8_t)((4+y)*32+x+12));
}
}
}
}
gfx_flush();
}
}
void anim_hello(void) {
current_menu_page = MENU_PAGE_MNT_LOGO;
logo_timeout_ticks = 10; // ~30sec
logo_timeout_ticks = 10;
gfx_clear();
//kbd_brightness_set(0);
gfx_on();
for (uint8_t y=0; y<3; y++) {
for (uint8_t x=0; x<12; x++) {
@ -184,16 +221,10 @@ void anim_hello(void) {
gfx_flush();
}
for (uint8_t y=0; y<0xff; y++) {
/*if ((y % 32) == 0) {
kbd_brightness_inc();
}*/
gfx_contrast(y);
sleep_ms(0);
}
for (uint8_t y=0; y<0xff; y++) {
/*if ((y % 64) == 0) {
kbd_brightness_dec();
}*/
gfx_contrast(0xff-y);
sleep_ms(0);
}
@ -213,10 +244,5 @@ void anim_goodbye(void) {
}
gfx_flush();
}
//int16_t brt = kbd_brightness_get();
/*while (brt--) {
kbd_brightness_dec();
Delay_MS(64);
}*/
gfx_off();
}

View File

@ -1,7 +1,7 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
#ifndef _MENU_H_
@ -21,8 +21,9 @@ void reset_and_render_menu(void);
void reset_menu(void);
void render_menu(int y);
void refresh_menu_page(void);
int execute_menu_function(int y);
int execute_meta_function(int keycode);
int execute_menu_row_function(int y);
int execute_menu_function(int keycode);
void render_tina(void);
void anim_hello(void);
void anim_goodbye(void);

View File

@ -1,7 +1,7 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
// OLED (SSD1306) rendering code. The OLED is interfaced via I2C.

View File

@ -1,7 +1,7 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
#ifndef _OLED_H_

View File

@ -1,7 +1,7 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
#include <stdlib.h>
@ -48,26 +48,6 @@ void insert_bat_icon(char* str, int x, double v) {
str[x+1] = 4*32+icon+1;
}
int remote_turn_on_som() {
uart_puts(UART_ID, "1p\r\n");
//led_set_brightness(10);
soc_power_on = 1;
return 1;
}
int remote_turn_off_som() {
uart_puts(UART_ID, "0p\r\n");
//led_set_brightness(0);
soc_power_on = 0;
return 1;
}
int remote_wake_som() {
uart_puts(UART_ID, "1w\r\n");
//anim_hello();
return 1;
}
int remote_get_power_state() {
return soc_power_on;
}
@ -85,22 +65,6 @@ void remote_on_uart_rx() {
uint8_t poke_chr = c;
if (c == '\n') {
// TODO hack
/*if (uart_rx_i>6) {
gfx_clear();
//gfx_poke_str(0, 3, uart_rx_line);
// cut off after 4 digits
uart_rx_line[4] = 0;
float percentage = ((float)atoi(uart_rx_line))/(float)10.0;
char batinfo[32];
sprintf(batinfo, " %.1f%%", (double)percentage);
insert_bat_icon(batinfo, 0, percentage);
gfx_poke_str(7, 1, batinfo);
gfx_flush();
}*/
uart_rx_i = 0;
poke_chr=' ';
}
@ -153,6 +117,8 @@ int remote_try_command(const char* cmd, int print_response) {
gfx_flush();
};
uart_print_response = 0;
return ok;
}
@ -240,3 +206,20 @@ int remote_get_voltages(void) {
return ok;
}
int remote_turn_on_som() {
remote_try_command("1p\r", 0);
soc_power_on = 1;
return 1;
}
int remote_turn_off_som() {
remote_try_command("0p\r", 0);
soc_power_on = 0;
return 1;
}
int remote_wake_som() {
remote_try_command("1w\r", 0);
return 1;
}

View File

@ -1,7 +1,7 @@
/*
MNT Reform 2.0 Keyboard Firmware
See keyboard.c for Copyright
SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
MNT Pocket Reform Keyboard/Trackball Controller Firmware for RP2040
Copyright 2021-2024 MNT Research GmbH (mntre.com)
*/
#ifndef _REMOTE_H_