From de48cc273a072b9898bb82294625576a5e26942d Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 29 Sep 2025 22:33:09 +0100 Subject: [PATCH] Starting to implement the Joystick library here Still need to add debouncing and the logic to detect key presses then I'll finish the thing --- platformio.ini | 2 +- src/main.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/platformio.ini b/platformio.ini index e3950a5..8c57a95 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,10 +12,10 @@ platform = atmelavr board = sparkfun_promicro16 framework = arduino -# upload_port = /dev/ttyACM0 build_flags = -Wl,-Map=${BUILD_DIR}/${PROGNAME}.map extra_scripts = post:check.py max_ram = 2560 max_ram_perc = 80 max_flash = 28672 max_flash_perc = 90 +lib_deps = mheironimus/Joystick@^2.1.1 diff --git a/src/main.cpp b/src/main.cpp index 8d5720d..dc1a722 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,9 +4,41 @@ * them from the getgo */ +// The Matrix +/* + * 1 1 1 R3 F9 F10 F11 F12 + * 1 1 1 R2 F5 F6 F7 F8 + * 1 1 1 M1 F1 F2 F3 F4 + * 1 1 1 m1 R1 r1 r2 r3 + * 1 1 1 M2 T3 T4 T5 T6 + * 1 1 1 m2 t3 t4 t5 t6 + * + * Toggle Switches (On - Off - On): + * T -> up, t -> down. + * From left to right + * + * Toggle Switches (Hold On - Off - Hold On) + * M -> up, m -> down + * From left to right + * + * Puny Rotary Encoders Click: + * R1 - 3 + * From left to right + * + * Chonky Rotary Encoder: + * R0 - 3 + * Positions on the encoder + * + * F keys: + * F1 - F12 + * Count them + * + */ + #include #include "595n.h" #include "165.h" +#include // NOTES - 595N // On the board, the first output pin on the SR595 is Qb @@ -26,7 +58,7 @@ #define IN_P4 0b00000100 #define IN_P5 0b00000010 uint8_t rows[] = {IN_P0, IN_P1, IN_P2, IN_P3, IN_P4, IN_P5}; -size_t num_rows = sizeof(rows) / sizeof(rows[0]); +const size_t NUM_ROWS = 6; // NOTES - 165 #define OUT_PARALLEL_LOAD_IN 10 // PL - pin1 (Async Parallel Load In) @@ -44,31 +76,50 @@ size_t num_rows = sizeof(rows) / sizeof(rows[0]); #define OUT_P3 0b11110111 #define OUT_P4 0b11101111 uint8_t cols[] = {OUT_P0, OUT_P1, OUT_P2, OUT_P3, OUT_P4}; -size_t num_cols = sizeof(cols) / sizeof(cols[0]); +const size_t NUM_COLS = 5; SR595N input = NewSR595N(IN_SERIAL_PIN, IN_LATCH_PIN, IN_CLOCK_PIN); SR165 output = NewSR165(OUT_PARALLEL_LOAD_IN, OUT_CLOCK_ENABLE, OUT_CLOCK_IN, OUT_COMPLEMENTARY_OUT); +#define JOYSTICK_BTN_COUNT 32 +#define JOYSTICK_HAT_COUNT 0 +Joystick_ Joystick( + JOYSTICK_DEFAULT_REPORT_ID, + JOYSTICK_TYPE_JOYSTICK, + JOYSTICK_BTN_COUNT, // Button count + JOYSTICK_HAT_COUNT, // Hat switch count + // no axes since this is just buttons + false, false, false, false, false, + false, false, false, false, false, + false +); + void setup() { Serial.begin(115200); + + Joystick.begin(); + for(int k = 0; k < JOYSTICK_BTN_COUNT; k++) { + Joystick.setButton(k, 0); + } + SR595N_write(&input, 0b00000100); } void loop(void) { - uint8_t scanResults[num_rows]; + uint8_t scanResults[NUM_ROWS]; - for (size_t row = 0; row < num_rows ; row++) { + for (size_t row = 0; row < NUM_ROWS ; row++) { SR595N_write(&input, rows[row]); delayMicroseconds(5); scanResults[row] = SR165_read(&output); } - for(size_t row = 0; row < num_rows; row++) { + Serial.print("\033[2J\033[H"); + for(size_t row = 0; row < NUM_ROWS; row++) { Serial.println(scanResults[row], BIN); } - // Serial.println(SR165_read(&output), BIN); - delay(5); + delay(35); }