Refactor 40percentclub/ut47 (#25571)
This commit is contained in:
parent
4a4e4aa083
commit
319da7bfdb
13 changed files with 66 additions and 433 deletions
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
Copyright 2018 Carlos Filoteo
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
/* key matrix size */
|
||||
#define MATRIX_ROWS 4
|
||||
#define MATRIX_COLS 12
|
||||
|
||||
#define MATRIX_ROW_PINS { D1, D0, D4, C6 }
|
||||
#define MATRIX_COL_PINS { D7, E6, B4, B5, B6, B2, B3, B1, F7, F6, F5, F4 }
|
||||
|
||||
/* COL2ROW, ROW2COL*/
|
||||
#define DIODE_DIRECTION COL2ROW
|
||||
|
||||
/* Enable GNAP matrix serial output */
|
||||
#define GNAP_ENABLE
|
||||
|
|
@ -22,6 +22,15 @@
|
|||
"resync": true
|
||||
}
|
||||
},
|
||||
"diode_direction": "COL2ROW",
|
||||
"matrix_pins": {
|
||||
"cols": ["D7", "E6", "B4", "B5", "B6", "B2", "B3", "B1", "F7", "F6", "F5", "F4"],
|
||||
"rows": ["D1", "D0", "D4", "C6"]
|
||||
},
|
||||
"keycodes": [
|
||||
{"key": "LED_TOG"},
|
||||
{"key": "LED_CHG"}
|
||||
],
|
||||
"layouts": {
|
||||
"LAYOUT": {
|
||||
"layout": [
|
||||
|
|
|
|||
|
|
@ -1,31 +1,10 @@
|
|||
/* Copyright 2018 Carlos Filoteo
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Copyright 2018 Carlos Filoteo
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include QMK_KEYBOARD_H
|
||||
#ifdef LED_ENABLE
|
||||
#include "uart.h"
|
||||
#endif
|
||||
|
||||
#define LT3_TAB LT(3, KC_TAB)
|
||||
#define MT_RSFT_ENT MT(MOD_RSFT, KC_ENT)
|
||||
|
||||
enum custom_keycodes {
|
||||
LED_TOG = SAFE_RANGE,
|
||||
LED_CHG
|
||||
};
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
|
||||
/* Base Layer
|
||||
|
|
@ -104,32 +83,3 @@ LAYOUT( /* Tab */
|
|||
_______, _______, _______, _______, _______, _______, _______, MS_LEFT, MS_DOWN, MS_UP, MS_RGHT
|
||||
),
|
||||
};
|
||||
|
||||
//LED keymap functions
|
||||
#ifdef LED_ENABLE
|
||||
void led_chmode(void) {
|
||||
uart_write(0x65);
|
||||
}
|
||||
|
||||
void led_toggle(void) {
|
||||
uart_write(0x64);
|
||||
}
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
if (record->event.pressed) {
|
||||
switch(keycode) {
|
||||
case LED_TOG:
|
||||
#ifdef LED_ENABLE
|
||||
led_toggle();
|
||||
#endif
|
||||
return false;
|
||||
case LED_CHG:
|
||||
#ifdef LED_ENABLE
|
||||
led_chmode();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,23 +1,7 @@
|
|||
/* Copyright 2018 Carlos Filoteo
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Copyright 2018 Carlos Filoteo
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
|
||||
|
||||
// place overrides here
|
||||
#define RGBLIGHT_EFFECT_BREATHING
|
||||
#define RGBLIGHT_EFFECT_RAINBOW_MOOD
|
||||
#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
|
||||
|
|
|
|||
|
|
@ -1,31 +1,10 @@
|
|||
/* Copyright 2018 Carlos Filoteo
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Copyright 2018 Carlos Filoteo
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include QMK_KEYBOARD_H
|
||||
#ifdef LED_ENABLE
|
||||
#include "uart.h"
|
||||
#endif
|
||||
|
||||
#define LT3_TAB LT(3, KC_TAB)
|
||||
#define MT_RSFT_ENT MT(MOD_RSFT, KC_ENT)
|
||||
|
||||
enum custom_keycodes {
|
||||
LED_TOG = SAFE_RANGE,
|
||||
LED_CHG
|
||||
};
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
|
||||
LAYOUT(
|
||||
|
|
@ -56,32 +35,3 @@ LAYOUT( /* Tab */
|
|||
_______, _______, _______, _______, _______, _______, _______, MS_LEFT, MS_DOWN, MS_UP, MS_RGHT
|
||||
),
|
||||
};
|
||||
|
||||
//LED keymap functions
|
||||
#ifdef LED_ENABLE
|
||||
void led_chmode(void) {
|
||||
uart_write(0x65);
|
||||
}
|
||||
|
||||
void led_toggle(void) {
|
||||
uart_write(0x64);
|
||||
}
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
if (record->event.pressed) {
|
||||
switch(keycode) {
|
||||
case LED_TOG:
|
||||
#ifdef LED_ENABLE
|
||||
led_toggle();
|
||||
#endif
|
||||
return false;
|
||||
case LED_CHG:
|
||||
#ifdef LED_ENABLE
|
||||
led_chmode();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
Copyright 2012 Jun Wako <wakojun@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <stdint.h>
|
||||
#include "led.h"
|
||||
|
||||
bool led_update_kb(led_t led_state)
|
||||
{
|
||||
bool res = led_update_user(led_state);
|
||||
if (res) {
|
||||
if (led_state.caps_lock) {
|
||||
// output low
|
||||
gpio_set_pin_output(B0);
|
||||
gpio_write_pin_low(B0);
|
||||
gpio_set_pin_output(D5);
|
||||
gpio_write_pin_low(D5);
|
||||
} else {
|
||||
// Hi-Z
|
||||
gpio_set_pin_input(B0);
|
||||
gpio_set_pin_input(D5);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
44
keyboards/40percentclub/ut47/led_controls.c
Normal file
44
keyboards/40percentclub/ut47/led_controls.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright 2018 Carlos Filoteo
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "uart.h"
|
||||
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if (res) {
|
||||
if (led_state.caps_lock) {
|
||||
// output low
|
||||
gpio_set_pin_output(B0);
|
||||
gpio_write_pin_low(B0);
|
||||
gpio_set_pin_output(D5);
|
||||
gpio_write_pin_low(D5);
|
||||
} else {
|
||||
// Hi-Z
|
||||
gpio_set_pin_input(B0);
|
||||
gpio_set_pin_input(D5);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void keyboard_post_init_kb(void) {
|
||||
uart_init(9600);
|
||||
|
||||
keyboard_post_init_user();
|
||||
}
|
||||
|
||||
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||
if (record->event.pressed) {
|
||||
uart_write((record->event.key.row * 16) + record->event.key.col);
|
||||
|
||||
switch (keycode) {
|
||||
case LED_TOG:
|
||||
uart_write(0x64);
|
||||
return false;
|
||||
case LED_CHG:
|
||||
uart_write(0x65);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return process_record_user(keycode, record);
|
||||
}
|
||||
420
keyboards/40percentclub/ut47/led_controls.ino
Normal file
420
keyboards/40percentclub/ut47/led_controls.ino
Normal file
|
|
@ -0,0 +1,420 @@
|
|||
#include <FastGPIO.h>
|
||||
#include <TimerOne.h>
|
||||
|
||||
int iByte;
|
||||
byte col = 0;
|
||||
byte leds[12][4];
|
||||
byte pass = 1;
|
||||
int fadecount = 1;
|
||||
const int fadelimit = 3000;
|
||||
const int fadelimitshort = 1000;
|
||||
byte mode = 4;
|
||||
byte brightness = 2;
|
||||
boolean changemode = 0;
|
||||
int rain = 0;
|
||||
const int rainlimit = 5000;
|
||||
const int rainfade = 5000;
|
||||
byte rx = 0;
|
||||
byte ry = 0;
|
||||
|
||||
// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
|
||||
int pins[17] = {
|
||||
-1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 14, 15, 18, 19, 20, 21
|
||||
};
|
||||
|
||||
// col[xx] of leds = pin yy on led matrix
|
||||
int cols[12] = {
|
||||
pins[8], pins[7], pins[6], pins[5], pins[9], pins[10], pins[11], pins[12], pins[13], pins[14], pins[15], pins[16]
|
||||
};
|
||||
|
||||
// row[xx] of leds = pin yy on led matrix
|
||||
int rows[4] = {
|
||||
pins[1], pins[2], pins[3], pins[4]
|
||||
};
|
||||
|
||||
|
||||
#define DELAY 0
|
||||
extern byte leds[12][4];
|
||||
|
||||
void setup() {
|
||||
Serial1.begin(9600);
|
||||
setupLeds();
|
||||
for (int s = 0; s < 5; s++) {
|
||||
for ( int r = 1; r < 9; r++) {
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
leds[i][j] = 1;
|
||||
for (int p = 0; p < 25; p++) {
|
||||
}
|
||||
leds[i][j] = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( int r = 9; r > 0; r--) {
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
leds[i][j] = 1;
|
||||
for (int p = 0; p < 25; p++) {
|
||||
}
|
||||
leds[i][j] = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
switch (mode) {
|
||||
case 0:
|
||||
//Blacklight
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
leds[i][j] = brightness;
|
||||
}
|
||||
}
|
||||
checkserial();
|
||||
break;
|
||||
case 1:
|
||||
//Breathing
|
||||
for ( int r = 1; r < 9; r++) {
|
||||
checkserial();
|
||||
if (changemode == 0) {
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
leds[i][j] = 1;
|
||||
for (int p = 0; p < 25; p++) {
|
||||
}
|
||||
leds[i][j] = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for ( int r = 9; r > 0; r--) {
|
||||
checkserial();
|
||||
if (changemode == 0) {
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
leds[i][j] = 1;
|
||||
for (int p = 0; p < 25; p++) {
|
||||
}
|
||||
leds[i][j] = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for ( int r = 1; r < 30; r++) {
|
||||
checkserial();
|
||||
if (changemode == 0) {
|
||||
delayMicroseconds(65000);
|
||||
delayMicroseconds(65000);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
//Random
|
||||
leds[random(12)][random(4)] = random(8);
|
||||
delayMicroseconds(10000);
|
||||
checkserial();
|
||||
break;
|
||||
case 3:
|
||||
//Rain
|
||||
rain++;
|
||||
if (rain > rainlimit) {
|
||||
rain = 0;
|
||||
rx = random(12);
|
||||
ry = random(4);
|
||||
if (leds[rx][ry] == 0) {
|
||||
leds[rx][ry] = 18;
|
||||
}
|
||||
}
|
||||
fadecount++;
|
||||
if (fadecount > rainfade) {
|
||||
fadecount = 1;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (leds[i][j] > 0) {
|
||||
leds[i][j] = leds[i][j] - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
checkserial();
|
||||
break;
|
||||
case 4:
|
||||
//Reactive
|
||||
fadecount++;
|
||||
if (fadecount > fadelimit) {
|
||||
fadecount = 1;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (leds[i][j] > 0) {
|
||||
leds[i][j] = leds[i][j] - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
checkserial();
|
||||
break;
|
||||
case 5:
|
||||
//Reactive Target
|
||||
fadecount++;
|
||||
if (fadecount > fadelimitshort) {
|
||||
fadecount = 1;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (leds[i][j] > 0) {
|
||||
leds[i][j] = leds[i][j] - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
checkserial();
|
||||
break;
|
||||
default:
|
||||
mode = 0;
|
||||
break;
|
||||
}
|
||||
changemode = 0;
|
||||
}
|
||||
|
||||
void checkserial() {
|
||||
if (Serial1.available() > 0) {
|
||||
iByte = Serial1.read();
|
||||
if (iByte == 100) {
|
||||
brightness++;
|
||||
if (brightness > 9) {
|
||||
brightness = 1;
|
||||
}
|
||||
}
|
||||
if (iByte == 101) {
|
||||
mode++;
|
||||
}
|
||||
if (iByte < 100) {
|
||||
if (mode == 4) {
|
||||
byte row = iByte / 16;
|
||||
byte col = iByte % 16;
|
||||
leds[col][row] = 18;
|
||||
}
|
||||
if (mode == 5) {
|
||||
byte row = iByte / 16;
|
||||
byte col = iByte % 16;
|
||||
for (byte i = 0; i < 12; i++) {
|
||||
leds[i][row] = 18;
|
||||
}
|
||||
for (byte p = 0; p < 4; p++) {
|
||||
leds[col][p] = 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setupLeds() {
|
||||
// sets the pins as output
|
||||
FastGPIO::Pin<2>::setOutputLow();
|
||||
FastGPIO::Pin<3>::setOutputLow();
|
||||
FastGPIO::Pin<4>::setOutputLow();
|
||||
FastGPIO::Pin<5>::setOutputLow();
|
||||
FastGPIO::Pin<6>::setOutputLow();
|
||||
FastGPIO::Pin<7>::setOutputLow();
|
||||
FastGPIO::Pin<8>::setOutputLow();
|
||||
FastGPIO::Pin<9>::setOutputLow();
|
||||
FastGPIO::Pin<10>::setOutputLow();
|
||||
FastGPIO::Pin<16>::setOutputLow();
|
||||
FastGPIO::Pin<14>::setOutputLow();
|
||||
FastGPIO::Pin<15>::setOutputLow();
|
||||
FastGPIO::Pin<18>::setOutputLow();
|
||||
FastGPIO::Pin<19>::setOutputLow();
|
||||
FastGPIO::Pin<20>::setOutputLow();
|
||||
FastGPIO::Pin<21>::setOutputLow();
|
||||
|
||||
// set up Cols
|
||||
FastGPIO::Pin<6>::setOutputValueLow();
|
||||
FastGPIO::Pin<7>::setOutputValueLow();
|
||||
FastGPIO::Pin<8>::setOutputValueLow();
|
||||
FastGPIO::Pin<9>::setOutputValueLow();
|
||||
FastGPIO::Pin<10>::setOutputValueLow();
|
||||
FastGPIO::Pin<16>::setOutputValueLow();
|
||||
FastGPIO::Pin<14>::setOutputValueLow();
|
||||
FastGPIO::Pin<15>::setOutputValueLow();
|
||||
FastGPIO::Pin<18>::setOutputValueLow();
|
||||
FastGPIO::Pin<19>::setOutputValueLow();
|
||||
FastGPIO::Pin<20>::setOutputValueLow();
|
||||
FastGPIO::Pin<21>::setOutputValueLow();
|
||||
|
||||
// set up Rows
|
||||
FastGPIO::Pin<2>::setOutputValueLow();
|
||||
FastGPIO::Pin<3>::setOutputValueLow();
|
||||
FastGPIO::Pin<4>::setOutputValueLow();
|
||||
FastGPIO::Pin<5>::setOutputValueLow();
|
||||
|
||||
clearLeds();
|
||||
Timer1.initialize(25);
|
||||
Timer1.attachInterrupt(display);
|
||||
|
||||
}
|
||||
|
||||
void clearLeds() {
|
||||
// Clear display array
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
leds[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onLeds() {
|
||||
// Clear display array
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
leds[i][j] = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Interrupt routine
|
||||
void display() {
|
||||
|
||||
switch (col) { // Turn whole previous column off
|
||||
case 0:
|
||||
FastGPIO::Pin<6>::setOutputValueLow();
|
||||
break;
|
||||
case 1:
|
||||
FastGPIO::Pin<7>::setOutputValueLow();
|
||||
break;
|
||||
case 2:
|
||||
FastGPIO::Pin<8>::setOutputValueLow();
|
||||
break;
|
||||
case 3:
|
||||
FastGPIO::Pin<9>::setOutputValueLow();
|
||||
break;
|
||||
case 4:
|
||||
FastGPIO::Pin<10>::setOutputValueLow();
|
||||
break;
|
||||
case 5:
|
||||
FastGPIO::Pin<16>::setOutputValueLow();
|
||||
break;
|
||||
case 6:
|
||||
FastGPIO::Pin<14>::setOutputValueLow();
|
||||
break;
|
||||
case 7:
|
||||
FastGPIO::Pin<15>::setOutputValueLow();
|
||||
break;
|
||||
case 8:
|
||||
FastGPIO::Pin<18>::setOutputValueLow();
|
||||
break;
|
||||
case 9:
|
||||
FastGPIO::Pin<19>::setOutputValueLow();
|
||||
break;
|
||||
case 10:
|
||||
FastGPIO::Pin<20>::setOutputValueLow();
|
||||
break;
|
||||
case 11:
|
||||
FastGPIO::Pin<21>::setOutputValueLow();
|
||||
break;
|
||||
}
|
||||
|
||||
col++;
|
||||
if (col == 12) {
|
||||
col = 0;
|
||||
pass++;
|
||||
if (pass > 8) {
|
||||
pass = 1;
|
||||
}
|
||||
}
|
||||
for (int row = 0; row < 4; row++) {
|
||||
if (leds[col][row] > pass) {
|
||||
switch (row) { // Turn on this led
|
||||
case 0:
|
||||
FastGPIO::Pin<2>::setOutputValueLow();
|
||||
break;
|
||||
case 1:
|
||||
FastGPIO::Pin<3>::setOutputValueLow();
|
||||
break;
|
||||
case 2:
|
||||
FastGPIO::Pin<4>::setOutputValueLow();
|
||||
break;
|
||||
case 3:
|
||||
FastGPIO::Pin<5>::setOutputValueLow();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (row) { // Turn off this led
|
||||
case 0:
|
||||
FastGPIO::Pin<2>::setOutputValueHigh();
|
||||
break;
|
||||
case 1:
|
||||
FastGPIO::Pin<3>::setOutputValueHigh();
|
||||
break;
|
||||
case 2:
|
||||
FastGPIO::Pin<4>::setOutputValueHigh();
|
||||
break;
|
||||
case 3:
|
||||
FastGPIO::Pin<5>::setOutputValueHigh();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (col) { // Turn column on
|
||||
case 0:
|
||||
FastGPIO::Pin<6>::setOutputValueHigh();
|
||||
break;
|
||||
case 1:
|
||||
FastGPIO::Pin<7>::setOutputValueHigh();
|
||||
break;
|
||||
case 2:
|
||||
FastGPIO::Pin<8>::setOutputValueHigh();
|
||||
break;
|
||||
case 3:
|
||||
FastGPIO::Pin<9>::setOutputValueHigh();
|
||||
break;
|
||||
case 4:
|
||||
FastGPIO::Pin<10>::setOutputValueHigh();
|
||||
break;
|
||||
case 5:
|
||||
FastGPIO::Pin<16>::setOutputValueHigh();
|
||||
break;
|
||||
case 6:
|
||||
FastGPIO::Pin<14>::setOutputValueHigh();
|
||||
break;
|
||||
case 7:
|
||||
FastGPIO::Pin<15>::setOutputValueHigh();
|
||||
break;
|
||||
case 8:
|
||||
FastGPIO::Pin<18>::setOutputValueHigh();
|
||||
break;
|
||||
case 9:
|
||||
FastGPIO::Pin<19>::setOutputValueHigh();
|
||||
break;
|
||||
case 10:
|
||||
FastGPIO::Pin<20>::setOutputValueHigh();
|
||||
break;
|
||||
case 11:
|
||||
FastGPIO::Pin<21>::setOutputValueHigh();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
Copyright 2018 Carlos Filoteo
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* scan matrix
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
#include "util.h"
|
||||
#include "matrix.h"
|
||||
|
||||
#ifndef DEBOUNCE
|
||||
# define DEBOUNCE 5
|
||||
#endif
|
||||
static uint8_t debouncing = DEBOUNCE;
|
||||
|
||||
/* matrix state(1:on, 0:off) */
|
||||
static matrix_row_t matrix[MATRIX_ROWS];
|
||||
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||
|
||||
static matrix_row_t read_cols(void);
|
||||
static void init_cols(void);
|
||||
static void unselect_rows(void);
|
||||
static void select_row(uint8_t row);
|
||||
|
||||
|
||||
inline
|
||||
uint8_t matrix_rows(void)
|
||||
{
|
||||
return MATRIX_ROWS;
|
||||
}
|
||||
|
||||
inline
|
||||
uint8_t matrix_cols(void)
|
||||
{
|
||||
return MATRIX_COLS;
|
||||
}
|
||||
|
||||
void matrix_init(void)
|
||||
{
|
||||
// initialize row and col
|
||||
unselect_rows();
|
||||
init_cols();
|
||||
|
||||
// initialize matrix state: all keys off
|
||||
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||
matrix[i] = 0;
|
||||
matrix_debouncing[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void)
|
||||
{
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
select_row(i);
|
||||
_delay_us(30); // without this wait read unstable value.
|
||||
matrix_row_t cols = read_cols();
|
||||
if (matrix_debouncing[i] != cols) {
|
||||
matrix_debouncing[i] = cols;
|
||||
if (debouncing) {
|
||||
dprintf("bounce!: %02X\n", debouncing);
|
||||
}
|
||||
debouncing = DEBOUNCE;
|
||||
}
|
||||
unselect_rows();
|
||||
}
|
||||
|
||||
if (debouncing) {
|
||||
if (--debouncing) {
|
||||
_delay_ms(1);
|
||||
} else {
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
matrix[i] = matrix_debouncing[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline
|
||||
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||
{
|
||||
return (matrix[row] & ((matrix_row_t)1<<col));
|
||||
}
|
||||
|
||||
inline
|
||||
matrix_row_t matrix_get_row(uint8_t row)
|
||||
{
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void matrix_print(void)
|
||||
{
|
||||
print("\nr/c 0123456789ABCDEF\n");
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
print_hex8(row); print(": ");
|
||||
print_bin_reverse16(matrix_get_row(row));
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* Column pin configuration
|
||||
* col: 0 1 2 3 4 5 6 7 8 9 10 11
|
||||
* pin: D7 E6 B4 B5 B6 B2 B3 B1 F7 F6 F5 F4
|
||||
*/
|
||||
|
||||
static void init_cols(void)
|
||||
{
|
||||
// Input with pull-up(DDR:0, PORT:1)
|
||||
gpio_set_pin_input_high(F4);
|
||||
gpio_set_pin_input_high(F5);
|
||||
gpio_set_pin_input_high(F6);
|
||||
gpio_set_pin_input_high(F7);
|
||||
gpio_set_pin_input_high(E6);
|
||||
gpio_set_pin_input_high(D7);
|
||||
gpio_set_pin_input_high(B1);
|
||||
gpio_set_pin_input_high(B2);
|
||||
gpio_set_pin_input_high(B3);
|
||||
gpio_set_pin_input_high(B4);
|
||||
gpio_set_pin_input_high(B5);
|
||||
gpio_set_pin_input_high(B6);
|
||||
}
|
||||
|
||||
static matrix_row_t read_cols(void)
|
||||
{
|
||||
return (PIND&(1<<7) ? 0 : (1<<0)) |
|
||||
(PINE&(1<<6) ? 0 : (1<<1)) |
|
||||
(PINB&(1<<4) ? 0 : (1<<2)) |
|
||||
(PINB&(1<<5) ? 0 : (1<<3)) |
|
||||
(PINB&(1<<6) ? 0 : (1<<4)) |
|
||||
(PINB&(1<<2) ? 0 : (1<<5)) |
|
||||
(PINB&(1<<3) ? 0 : (1<<6)) |
|
||||
(PINB&(1<<1) ? 0 : (1<<7)) |
|
||||
(PINF&(1<<7) ? 0 : (1<<8)) |
|
||||
(PINF&(1<<6) ? 0 : (1<<9)) |
|
||||
(PINF&(1<<5) ? 0 : (1<<10)) |
|
||||
(PINF&(1<<4) ? 0 : (1<<11));
|
||||
}
|
||||
|
||||
/* Row pin configuration
|
||||
* row: 0 1 2 3
|
||||
* pin: D1 D0 D4 C6
|
||||
*/
|
||||
|
||||
static void unselect_rows(void)
|
||||
{
|
||||
// Hi-Z(DDR:0, PORT:0) to unselect
|
||||
gpio_set_pin_input(C6);
|
||||
gpio_set_pin_input(D0);
|
||||
gpio_set_pin_input(D1);
|
||||
gpio_set_pin_input(D4);
|
||||
}
|
||||
|
||||
static void select_row(uint8_t row)
|
||||
{
|
||||
// Output low(DDR:1, PORT:0) to select
|
||||
switch (row) {
|
||||
case 0:
|
||||
gpio_set_pin_output(D1);
|
||||
gpio_write_pin_low(D1);
|
||||
break;
|
||||
case 1:
|
||||
gpio_set_pin_output(D0);
|
||||
gpio_write_pin_low(D0);
|
||||
break;
|
||||
case 2:
|
||||
gpio_set_pin_output(D4);
|
||||
gpio_write_pin_low(D4);
|
||||
break;
|
||||
case 3:
|
||||
gpio_set_pin_output(C6);
|
||||
gpio_write_pin_low(C6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
ifeq ($(strip $(LED_ENABLE)), yes)
|
||||
OPT_DEFS += -DLED_ENABLE
|
||||
SRC += led.c
|
||||
OPT_DEFS += -DLED_ENABLE
|
||||
SRC += led_controls.c
|
||||
UART_DRIVER_REQUIRED = yes
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
# ut47
|
||||
|
||||

|
||||
===
|
||||
|
||||
Somewhere between ortholinear and standard offset. Created to have all the same functions on a Planck in a keyboard but with a more conventional keyboard row stagger.
|
||||
|
||||
Keyboard Maintainer: [filoxo](https://github.com/filoxo), [network_operations]
|
||||
Hardware Supported: [PCB design](http://www.40percent.club/2016/10/gnap-20-plateless.html), Arduino Pro Micro
|
||||
Hardware Availability: [How to order](http://www.40percent.club/2017/03/ordering-pcb.html)
|
||||
* Keyboard Maintainer: [filoxo](https://github.com/filoxo), [network_operations]
|
||||
* Hardware Supported: [PCB design](http://www.40percent.club/2016/10/gnap-20-plateless.html), Arduino Pro Micro
|
||||
* Hardware Availability: [How to order](http://www.40percent.club/2017/03/ordering-pcb.html)
|
||||
|
||||
### Instructions
|
||||
|
||||
|
|
@ -21,7 +20,7 @@ To enable the UT47 LEDs (dual controller), run this for the main controller:
|
|||
|
||||
Or you can add `LED_ENABLE = yes` to *rules.mk*
|
||||
|
||||
And then flash [LED_controls.ino](LED_controls.ino) to the second controller using [Arduino IDE](https://www.arduino.cc/en/Main/Software) or similar. NOTE: Arduino IDE will require importing additional libraries to compile.
|
||||
And then flash [led_controls.ino](led_controls.ino) to the second controller using [Arduino IDE](https://www.arduino.cc/en/Main/Software) or similar. NOTE: Arduino IDE will require importing additional libraries to compile.
|
||||
|
||||
<small>The reason this is an "opt-in" feature is to prevent sending serial communication over the pin, in case it ends up being used for something else (like RGB underglow).</small>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
CUSTOM_MATRIX = yes
|
||||
SRC += matrix.c
|
||||
UART_DRIVER_REQUIRED = yes
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/* Copyright 2018 Carlos Filoteo
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "quantum.h"
|
||||
#ifdef LED_ENABLE
|
||||
#include "uart.h"
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
uart_init(9600);
|
||||
|
||||
matrix_init_user();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||
// put your per-action keyboard code here
|
||||
// runs for every action, just before processing by the firmware
|
||||
if (record->event.pressed) {
|
||||
#ifdef LED_ENABLE
|
||||
uart_write((record->event.key.row*16)+record->event.key.col);
|
||||
#endif
|
||||
}
|
||||
return process_record_user(keycode, record);
|
||||
}
|
||||
Loading…
Reference in a new issue