Update keyboards/mectechpad/matrix.c

Co-authored-by: ClownFish <177758267+clownfish-og@users.noreply.github.com>
This commit is contained in:
jacksaxi 2025-06-18 12:28:22 +03:00 committed by GitHub
parent 56c9212345
commit 88c911df4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,61 +1,30 @@
// Copyright 2025 Jack Sachinidhs (@jacksaxi)
// SPDX-License-Identifier: GPL-2.0-or-later
#include QMK_KEYBOARD_H
enum layers {
_LAYER1,
_LAYER2,
_LAYER3,
_LAYER4
};
// Define the pin for the layer change button
#define LAYER_CHANGE_PIN GP13
#define DEBOUNCE_DELAY 10 // Debounce time in milliseconds
#include "quantum.h"
// Initialize LED pins
void matrix_init_kb() {
gpio_set_pin_output(LED_PIN_LAYER_0);
gpio_write_pin_low(LED_PIN_LAYER_0);
gpio_set_pin_output(LED_PIN_LAYER_1);
gpio_write_pin_low(LED_PIN_LAYER_1);
gpio_set_pin_output(LED_PIN_LAYER_2);
gpio_write_pin_low(LED_PIN_LAYER_2);
gpio_set_pin_output(LED_PIN_LAYER_3);
gpio_write_pin_low(LED_PIN_LAYER_3);
}
// Update LEDs based on the current layer
void set_layer_indicator(uint8_t layer) {
writePin(LED_PIN_LAYER1, layer == _LAYER1);
writePin(LED_PIN_LAYER2, layer == _LAYER2);
writePin(LED_PIN_LAYER3, layer == _LAYER3);
writePin(LED_PIN_LAYER4, layer == _LAYER4);
void housekeeping_task_kb(void) {
gpio_write_pin(LED_PIN_LAYER_0, (get_highest_layer(layer_state) == 0));
gpio_write_pin(LED_PIN_LAYER_1, (get_highest_layer(layer_state) == 1));
gpio_write_pin(LED_PIN_LAYER_2, (get_highest_layer(layer_state) == 2));
gpio_write_pin(LED_PIN_LAYER_3, (get_highest_layer(layer_state) == 3));
}
// Initialize pins
void keyboard_post_init_user(void) {
setPinOutput(LED_PIN_LAYER1);
setPinOutput(LED_PIN_LAYER2);
setPinOutput(LED_PIN_LAYER3);
setPinOutput(LED_PIN_LAYER4);
// Initialize the layer change button pin
setPinInputHigh(LAYER_CHANGE_PIN);
set_layer_indicator(_LAYER1);
}
// Cycle through layers based on the layer change button state
void matrix_scan_user(void) {
static bool last_button_state = false;
static uint16_t last_debounce_time = 0;
// Read the current state of the button (active low)
bool current_button_state = !readPin(LAYER_CHANGE_PIN);
// Check if the button state has changed and debounce time has passed
if (current_button_state != last_button_state) {
if (timer_elapsed(last_debounce_time) > DEBOUNCE_DELAY) {
last_debounce_time = timer_read(); // Reset debounce timer
if (current_button_state) {
// Button was just pressed, move to the next layer
uint8_t current_layer = get_highest_layer(layer_state);
uint8_t next_layer = (current_layer + 1) % 4; // Cycle to the next layer
layer_move(next_layer);
set_layer_indicator(next_layer);
}
}
}
// Update the last known button state
last_button_state = current_button_state;
}
// Mask to accommodate the direct pin switch
const matrix_row_t matrix_mask[MATRIX_ROWS] = {
0b111,
0b111,
0b111,
0b001,
};