From 50d692783f802fbf961baf8e91b23842e9be314b Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Fri, 2 Apr 2021 03:27:13 -0500 Subject: [PATCH] [Ajazz AK33 Rev1] Clean up unused files and fix caps lock indicator LED --- keyboards/ajazz/ak33/rev1/config.h | 7 +- keyboards/ajazz/ak33/rev1/config_led.h | 6 +- .../ajazz/ak33/rev1/keymaps/default/keymap.c | 13 +- keyboards/ajazz/ak33/rev1/led_matrix.c | 6 +- keyboards/ajazz/ak33/rev1/matrix_2.c | 377 ------------------ keyboards/ajazz/ak33/rev1/matrix_base.c | 255 ------------ 6 files changed, 11 insertions(+), 653 deletions(-) delete mode 100644 keyboards/ajazz/ak33/rev1/matrix_2.c delete mode 100644 keyboards/ajazz/ak33/rev1/matrix_base.c diff --git a/keyboards/ajazz/ak33/rev1/config.h b/keyboards/ajazz/ak33/rev1/config.h index 99e9d687fa9b..f595153efa8d 100644 --- a/keyboards/ajazz/ak33/rev1/config.h +++ b/keyboards/ajazz/ak33/rev1/config.h @@ -45,15 +45,10 @@ #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, A14, A15, B0, B1, B2, B3, B4, B10, B11 } #define MATRIX_ROW_PINS { D15, D14, D13, D12, D11, D10 } -#define LED_PIN_ON_STATE 0 -//#define LED_NUM_LOCK_PIN D5 -#define LED_CAPS_LOCK_PIN D6 -//#define LED_SCROLL_LOCK_PIN D7 - /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ #define DEBOUNCE 5 /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ //#define LOCKING_SUPPORT_ENABLE /* Locking resynchronize hack */ -//#define LOCKING_RESYNC_ENABLE \ No newline at end of file +//#define LOCKING_RESYNC_ENABLE diff --git a/keyboards/ajazz/ak33/rev1/config_led.h b/keyboards/ajazz/ak33/rev1/config_led.h index bc904da2d27b..3ea64084f875 100644 --- a/keyboards/ajazz/ak33/rev1/config_led.h +++ b/keyboards/ajazz/ak33/rev1/config_led.h @@ -24,9 +24,11 @@ along with this program. If not, see . #define LED_MATRIX_ROW_CHANNELS 3 #define LED_MATRIX_ROWS_HW (LED_MATRIX_ROWS * LED_MATRIX_ROW_CHANNELS) #define LED_MATRIX_ROW_PINS { C0, C1, C3, C4, C14, C15, C5, C6, C7, C8, C9, C10, D0, D1, B6, B7, D2, D3 } -//#define LED_MATRIX_ROW_PINS { P2.0, P2.1, P2.3, P2.4, P2.14, P2.15, P2.5, P2.6, P2.7, P2.8, P2.9, P2.10, P3.0, P3.1, P1.6, P1.7, P3.2, P3.3 } #define LED_MATRIX_COLS 17 #define LED_MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, A14, A15, B0, B1, B2, B3, B4, B10, B11 } -#define DRIVER_LED_TOTAL (6*17) \ No newline at end of file +#define DRIVER_LED_TOTAL (6*17) + +#define LED_CAPS_LOCK_PIN D6 +#define LED_PIN_ON_STATE 0 diff --git a/keyboards/ajazz/ak33/rev1/keymaps/default/keymap.c b/keyboards/ajazz/ak33/rev1/keymaps/default/keymap.c index 9423d5fc7494..fccc3cbdfe75 100644 --- a/keyboards/ajazz/ak33/rev1/keymaps/default/keymap.c +++ b/keyboards/ajazz/ak33/rev1/keymaps/default/keymap.c @@ -149,17 +149,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { } }; -// Taken from 'g_led_config' in config_led.c -#define CAPS_LOCK_LED_ID 34 - -void rgb_matrix_indicators_user(void) { - if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) { - rgb_matrix_set_color(CAPS_LOCK_LED_ID, 0xFF, 0x00, 0x00); - } else { - rgb_matrix_set_color(CAPS_LOCK_LED_ID, 0x00, 0x00, 0x00); - } -} - bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case BASE: @@ -177,4 +166,4 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { break; } return true; -} \ No newline at end of file +} diff --git a/keyboards/ajazz/ak33/rev1/led_matrix.c b/keyboards/ajazz/ak33/rev1/led_matrix.c index 7bfdd99bde80..048f7480f71e 100644 --- a/keyboards/ajazz/ak33/rev1/led_matrix.c +++ b/keyboards/ajazz/ak33/rev1/led_matrix.c @@ -62,4 +62,8 @@ const rgb_matrix_driver_t rgb_matrix_driver = { .flush = flush, .set_color = set_color, .set_color_all = set_color_all, -}; \ No newline at end of file +}; + +void led_set(uint8_t usb_led) { + writePin(LED_CAPS_LOCK_PIN, !IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)); +} diff --git a/keyboards/ajazz/ak33/rev1/matrix_2.c b/keyboards/ajazz/ak33/rev1/matrix_2.c deleted file mode 100644 index 590d233166dd..000000000000 --- a/keyboards/ajazz/ak33/rev1/matrix_2.c +++ /dev/null @@ -1,377 +0,0 @@ -#include -/* - * Copyright 2011 Jun Wako - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Ported to QMK by Stephen Peery - */ - -#include -#include -#include -#include "ch.h" -#include "hal.h" - -#include "wait.h" -#include "util.h" -#include "matrix.h" -#include "debounce.h" -#include "quantum.h" -#include "color.h" - -static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -static const pin_t led_row_pins[LED_MATRIX_ROWS_HW] = LED_MATRIX_ROW_PINS; -static uint16_t row_ofsts[LED_MATRIX_ROWS]; - -matrix_row_t raw_matrix[MATRIX_ROWS]; //raw values -matrix_row_t last_matrix[MATRIX_ROWS] = {0}; // raw values -matrix_row_t matrix[MATRIX_ROWS]; //debounced values - -static bool matrix_changed = false; -static uint8_t current_row = 0; - -extern volatile LED_TYPE led_state[DRIVER_LED_TOTAL]; - -__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } - -__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); } - -__attribute__((weak)) void matrix_init_user(void) {} - -__attribute__((weak)) void matrix_scan_user(void) {} - -__WEAK inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } - -__WEAK void matrix_print(void) {} - - -_Noreturn void color_loop(void); - -static void select_col (uint8_t col) -{ - setPinInput(col_pins[col]); - writePinHigh(col_pins[col]); -} - -static void unselect_col (uint8_t col) -{ - setPinOutput(col_pins[col]); - writePinLow(col_pins[col]); -} - -static void select_row (uint8_t row) -{ - setPinOutput(row_pins[row]); - writePinLow(row_pins[row]); -} - -static void unselect_row (uint8_t row) -{ - setPinInputHigh(row_pins[row]); -} - -static void unselect_rows (void) -{ - for (uint8_t x = 0; x < MATRIX_ROWS; x++) - { - unselect_row(x); - } -} - -static void init_pins(void) { - - // Unselect ROWs - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInput(row_pins[x]); - writePinHigh(row_pins[x]); - } - - // Unselect COLs - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinOutput(col_pins[x]); - writePinHigh(col_pins[x]); - } - - for (uint8_t x = 0; x < LED_MATRIX_ROWS_HW; x++) { - setPinOutput(led_row_pins[x]); - writePinHigh(led_row_pins[x]); - } -} - -static bool read_cols_on_row (matrix_row_t current_matrix[], uint8_t current_row) -{ - // Store last value of row prior to reading - matrix_row_t last_row_value = current_matrix[current_row]; - - // Clear data in matrix row - current_matrix[current_row] = 0; - - // Select row and wait for row selecton to stabilize - select_row(current_row); - wait_us(30); - - // For each col... - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) - { - // Set pin to input - select_col(col_index); - - // Select the col pin to read (active low) - uint8_t pin_state = readPin(col_pins[col_index]); - - // Set pin to output - unselect_col(col_index); - - // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - - // Unselect row - unselect_row(current_row); - - return last_row_value != current_matrix[current_row]; -} - -void matrix_init (void) -{ - // initialize key pins - init_pins(); - - // initialize matrix state: all keys off - for (uint8_t i = 0; i < MATRIX_ROWS; i++) - { - raw_matrix[i] = 0; - matrix[i] = 0; - } - - debounce_init(MATRIX_ROWS); - - color_loop(); - - matrix_init_quantum(); -} - -#if 1 -uint8_t matrix_scan(void) { - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { - // Determine if the matrix changed state - if ((last_matrix[row_index] != raw_matrix[row_index])) { - matrix_changed = true; - last_matrix[row_index] = raw_matrix[row_index]; - } - } - } - - debounce(raw_matrix, matrix, MATRIX_ROWS, matrix_changed); - - matrix_scan_quantum(); - - return matrix_changed; -} - -#else -uint8_t matrix_scan (void) -{ - bool changed = false; - - volatile uint32_t col_index = 1; - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - } - - while (1) - { - for (uint32_t x = 0; x < sizeof(col_pins) / sizeof(col_pins[0]); x++) - { - setPinOutput(col_pins[x]); - writePinLow(col_pins[x]); - - // writePinHigh(col_pins[x]); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - } - - // for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - // { - //// On - //// setPinInput(led_row_pins[y]); - // setPinOutput(led_row_pins[y]); - // writePinHigh(led_row_pins[y]); - // } - - chThdSleepMilliseconds(1); - setPinInput(col_pins[x]); - - // setPinInput(col_pins[col_index]); - } - } - - chThdSleepMilliseconds(5000); - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - // Off - // setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); - } - - // for (uint8_t x = 0; x < MATRIX_COLS; x++) - while (1) - { - for (uint32_t x = 0; x < sizeof(col_pins) / col_pins[0]; x++) - { - setPinOutput(col_pins[x]); - writePinLow(col_pins[x]); - - // setPinInput(col_pins[col_index]); - } - - // Turn COL On -// writePinHigh(col_pins[col_index]); -// chThdSleepMilliseconds(10); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - chThdSleepMilliseconds(100); - - // Off - // setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); - } - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - } - - // Turn COL Off - // setPinInput(col_pins[col_index]); - - // writePinHigh(col_pins[col_index]); - chThdSleepMilliseconds(10); - } - - //// Set row, read cols - // for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) - // { - // changed |= read_cols_on_row(raw_matrix, current_row); - // } - - // debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - - // matrix_scan_quantum(); - - return (uint8_t) changed; -} - -#endif - -_Noreturn void color_loop (void) -{ -// volatile uint32_t col_index = 1; -// uint32_t pins[] = { C0, C1, C3, C4, C14, C15, C5, C6, C7, C8, C9, C10, D0, D1, D2, D3, D4, D5 }; -// setPinInputHigh(C2); -// -// uint8_t y = 0; -// -// for (uint32_t i = 0; i < sizeof(pins); i++) -// { -// // On -// // setPinInput(pins[y]); -// setPinOutput(pins[i]); -// writePinLow(pins[i]); -// chThdSleepMilliseconds(200); -// } -// -// while (y < sizeof(pins)) -// { -// setPinOutput(pins[y]); -// do -// { -// writePinHigh(pins[y]); -// chThdSleepMilliseconds(1000); -// writePinLow(pins[y]); -// chThdSleepMilliseconds(1000); -// } while(readPin(C2)); -// y++; -// } - - for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); - chThdSleepMilliseconds(200); - } -// -// for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) -// { -// // On -// // setPinInput(led_row_pins[y]); -//// setPinOutput(led_row_pins[y]); -// writePinHigh(led_row_pins[y]); -// chThdSleepMilliseconds(1000); -// writePinLow(led_row_pins[y]); -// chThdSleepMilliseconds(1000); -// } - -// while (1); - - while (1) - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) - { - // Turn COL On - setPinOutput(col_pins[col_index]); - writePinLow(col_pins[col_index]); - chThdSleepMilliseconds(10); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - chThdSleepMilliseconds(500); -// } -// -// ; -// -// chThdSleepMilliseconds(100); -// -// for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y+=3) -// { - // Off - // setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); -// chThdSleepMilliseconds(1000); - } - - // Turn COL Off - setPinInput(col_pins[col_index]); - writePinHigh(col_pins[col_index]); - chThdSleepMilliseconds(10); - } -} \ No newline at end of file diff --git a/keyboards/ajazz/ak33/rev1/matrix_base.c b/keyboards/ajazz/ak33/rev1/matrix_base.c deleted file mode 100644 index 3c17faf2df63..000000000000 --- a/keyboards/ajazz/ak33/rev1/matrix_base.c +++ /dev/null @@ -1,255 +0,0 @@ -/* -Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#include -#include -#include "util.h" -#include "matrix.h" -#include "debounce.h" -#include "quantum.h" - -#ifdef DIRECT_PINS -static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) -static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -static const pin_t led_row_pins[LED_MATRIX_ROWS_HW] = LED_MATRIX_ROW_PINS; -#endif - -/* matrix state(1:on, 0:off) */ -extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values -extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values - -// matrix code - -#ifdef DIRECT_PINS - -static void init_pins(void) { - for (int row = 0; row < MATRIX_ROWS; row++) { - for (int col = 0; col < MATRIX_COLS; col++) { - pin_t pin = direct_pins[row][col]; - if (pin != NO_PIN) { - setPinInputHigh(pin); - } - } - } -} - -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - // Start with a clear matrix row - matrix_row_t current_row_value = 0; - - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - pin_t pin = direct_pins[current_row][col_index]; - if (pin != NO_PIN) { - current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - } - - // If the row has changed, store the row and return the changed flag. - if (current_matrix[current_row] != current_row_value) { - current_matrix[current_row] = current_row_value; - return true; - } - return false; -} - -#elif defined(DIODE_DIRECTION) -# if (DIODE_DIRECTION == COL2ROW) - -static void select_row(uint8_t row) { - setPinOutput(row_pins[row]); - writePinLow(row_pins[row]); -} - -static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); } - -static void unselect_rows(void) { - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); - } -} - -static void init_pins(void) { - unselect_rows(); - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); - } -} - -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - // Start with a clear matrix row - matrix_row_t current_row_value = 0; - - // Select row and wait for row selecton to stabilize - select_row(current_row); - matrix_io_delay(); - - // For each col... - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - // Select the col pin to read (active low) - uint8_t pin_state = readPin(col_pins[col_index]); - - // Populate the matrix row with the state of the col pin - current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - - // Unselect row - unselect_row(current_row); - - // If the row has changed, store the row and return the changed flag. - if (current_matrix[current_row] != current_row_value) { - current_matrix[current_row] = current_row_value; - return true; - } - return false; -} - -# elif (DIODE_DIRECTION == ROW2COL) - -static void select_col(uint8_t col) { - setPinOutput(col_pins[col]); - writePinLow(col_pins[col]); -} - -static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } - -static void unselect_cols(void) { - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); - } -} - -static void init_pins(void) { - unselect_cols(); - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); - } -} - -static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { - bool matrix_changed = false; - - // Select col and wait for col selecton to stabilize - select_col(current_col); - matrix_io_delay(); - - // For each row... - for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { - // Store last value of row prior to reading - matrix_row_t last_row_value = current_matrix[row_index]; - matrix_row_t current_row_value = last_row_value; - - // Check row pin state - if (readPin(row_pins[row_index]) == 0) { - // Pin LO, set col bit - current_row_value |= (MATRIX_ROW_SHIFTER << current_col); - } else { - // Pin HI, clear col bit - current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); - } - - // Determine if the matrix changed state - if ((last_row_value != current_row_value)) { - matrix_changed |= true; - current_matrix[row_index] = current_row_value; - } - } - - // Unselect col - unselect_col(current_col); - - return matrix_changed; -} - -# else -# error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! -# endif -#else -# error DIODE_DIRECTION is not defined! -#endif - -void matrix_init(void) { - // initialize key pins - init_pins(); - - // initialize matrix state: all keys off - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - raw_matrix[i] = 0; - matrix[i] = 0; - } - - debounce_init(MATRIX_ROWS); - - { - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) - { - // Turn COL On - setPinOutput(col_pins[col_index]); - writePinLow(col_pins[col_index]); -// chThdSleepMilliseconds(10); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y+=3) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - chThdSleepMilliseconds(5); -// } -// -// ; -// -// chThdSleepMilliseconds(100); -// -// for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y+=3) -// { - // Off - // setPinOutput(led_row_pins[y]); -// writePinLow(led_row_pins[y]); -// chThdSleepMilliseconds(1000); - } - - // Turn COL Off - setPinInput(col_pins[col_index]); - writePinHigh(col_pins[col_index]); -// chThdSleepMilliseconds(10); - } - } - - matrix_init_quantum(); -} - -uint8_t matrix_scan(void) { - bool changed = false; - -#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) - // Set row, read cols - for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { - changed |= read_cols_on_row(raw_matrix, current_row); - } -#elif (DIODE_DIRECTION == ROW2COL) - // Set col, read rows - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - changed |= read_rows_on_col(raw_matrix, current_col); - } -#endif - - debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - - matrix_scan_quantum(); - return (uint8_t)changed; -} \ No newline at end of file