rgb hooked-up
This commit is contained in:
parent
a6afb16c90
commit
7e839c9ba6
@ -16,6 +16,108 @@
|
||||
*/
|
||||
#include "_qmk_handwire.h"
|
||||
|
||||
|
||||
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
|
||||
/* Refer to IS31 manual for these locations
|
||||
* driver
|
||||
* | R location
|
||||
* | | G location
|
||||
* | | | B location
|
||||
* | | | | */
|
||||
{0, C3_2, C1_1, C4_2}, // 1
|
||||
{0, C2_2, C1_2, C4_3},
|
||||
{0, C2_3, C1_3, C3_3},
|
||||
{0, C2_4, C1_4, C3_4},
|
||||
{0, C2_5, C1_5, C3_5},
|
||||
{0, C2_6, C1_6, C3_6},
|
||||
{0, C2_7, C1_7, C3_7},
|
||||
{0, C2_8, C1_8, C3_8},
|
||||
{0, C3_1, C2_1, C4_1},
|
||||
|
||||
{0, C7_8, C6_8, C8_8}, // 10
|
||||
{0, C7_7, C6_7, C9_8},
|
||||
{0, C8_7, C6_6, C9_7},
|
||||
{0, C8_6, C7_6, C9_6},
|
||||
{0, C8_5, C7_5, C9_5},
|
||||
{0, C8_4, C7_4, C9_4},
|
||||
{0, C8_3, C7_3, C9_3},
|
||||
{0, C8_2, C7_2, C9_2},
|
||||
{0, C8_1, C7_1, C9_1},
|
||||
|
||||
{0, C3_10, C1_9, C4_10}, // 19
|
||||
{0, C2_10, C1_10, C4_11},
|
||||
{0, C2_11, C1_11, C3_11},
|
||||
{0, C2_12, C1_12, C3_12},
|
||||
{0, C2_13, C1_13, C3_13},
|
||||
{0, C2_14, C1_14, C3_14},
|
||||
{0, C2_15, C1_15, C3_15},
|
||||
{0, C2_16, C1_16, C3_16},
|
||||
{0, C3_9, C2_9, C4_9},
|
||||
|
||||
{0, C7_16, C6_16, C8_16}, // 28
|
||||
{0, C7_15, C6_15, C9_16},
|
||||
{0, C8_15, C6_14, C9_15},
|
||||
{0, C8_10, C7_10, C9_10},
|
||||
{0, C8_9, C7_9, C9_9},
|
||||
{0, C8_11, C7_11, C9_11},
|
||||
{0, C8_12, C7_12, C9_12},
|
||||
{0, C8_13, C7_13, C9_13},
|
||||
// {0, C8_14, C7_14, C9_4}
|
||||
|
||||
};
|
||||
|
||||
const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
|
||||
|
||||
/*{row | col << 4}
|
||||
| {x=0..224, y=0..64}
|
||||
| | modifier
|
||||
| | | */
|
||||
{{0|(0<<4)}, {20.36*0, 21.33*0}, 1},
|
||||
{{1|(0<<4)}, {20.36*1, 21.33*0}, 0},
|
||||
{{2|(0<<4)}, {20.36*2, 21.33*0}, 0},
|
||||
{{3|(0<<4)}, {20.36*3, 21.33*0}, 0},
|
||||
{{4|(0<<4)}, {20.36*4, 21.33*0}, 0},
|
||||
|
||||
{{0|(1<<4)}, {20.36*5, 21.33*0}, 0},
|
||||
{{1|(1<<4)}, {20.36*6, 21.33*0}, 0},
|
||||
{{2|(1<<4)}, {20.36*7, 21.33*0}, 0},
|
||||
{{3|(1<<4)}, {20.36*8, 21.33*0}, 0},
|
||||
{{4|(1<<4)}, {20.36*9, 21.33*0}, 0},
|
||||
|
||||
{{0|(2<<4)}, {20.36*5, 21.33*0}, 0},
|
||||
{{1|(2<<4)}, {20.36*6, 21.33*0}, 0},
|
||||
{{2|(2<<4)}, {20.36*7, 21.33*0}, 0},
|
||||
{{3|(2<<4)}, {20.36*8, 21.33*0}, 0},
|
||||
{{4|(2<<4)}, {20.36*9, 21.33*0}, 0},
|
||||
|
||||
{{0|(3<<4)}, {20.36*5, 21.33*0}, 0},
|
||||
{{1|(3<<4)}, {20.36*6, 21.33*0}, 0},
|
||||
{{2|(3<<4)}, {20.36*7, 21.33*0}, 0},
|
||||
{{3|(3<<4)}, {20.36*8, 21.33*0}, 0},
|
||||
{{4|(3<<4)}, {20.36*9, 21.33*0}, 0},
|
||||
|
||||
{{0|(4<<4)}, {20.36*5, 21.33*0}, 0},
|
||||
{{1|(4<<4)}, {20.36*6, 21.33*0}, 0},
|
||||
{{2|(4<<4)}, {20.36*7, 21.33*0}, 0},
|
||||
{{3|(4<<4)}, {20.36*8, 21.33*0}, 0},
|
||||
{{4|(4<<4)}, {20.36*9, 21.33*0}, 0},
|
||||
|
||||
{{0|(5<<4)}, {20.36*5, 21.33*0}, 0},
|
||||
{{1|(5<<4)}, {20.36*6, 21.33*0}, 0},
|
||||
{{2|(5<<4)}, {20.36*7, 21.33*0}, 0},
|
||||
{{3|(5<<4)}, {20.36*8, 21.33*0}, 0},
|
||||
|
||||
{{0|(6<<4)}, {20.36*5, 21.33*0}, 0},
|
||||
{{1|(6<<4)}, {20.36*6, 21.33*0}, 0},
|
||||
{{2|(6<<4)}, {20.36*7, 21.33*0}, 0},
|
||||
|
||||
// cluster
|
||||
{{5|(0<<4)}, {20.36*5, 21.33*0}, 0},
|
||||
{{5|(1<<4)}, {20.36*6, 21.33*0}, 0},
|
||||
{{5|(2<<4)}, {20.36*7, 21.33*0}, 0},
|
||||
|
||||
};
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
|
||||
}
|
||||
|
@ -20,21 +20,15 @@
|
||||
#include "quantum.h"
|
||||
|
||||
/*
|
||||
* These are shortcuts to help you work with the various layout options. If your
|
||||
* These are shortcuts to help you work with the various layout options. If your
|
||||
* keymap works with one of the LAYOUT_...() macros you are encouraged to use that
|
||||
* and to contribute your keymap to the corresponding layout in
|
||||
* and to contribute your keymap to the corresponding layout in
|
||||
* `qmk_firmware/layouts/community`.
|
||||
*/
|
||||
|
||||
/* The fully-featured KEYMAP() that has every single key available in the matrix.
|
||||
*/
|
||||
#define KEYMAP(\
|
||||
j00, j01, j02, j03, j04, j05, j06, \
|
||||
j10, j11, j12, j13, j14, j15, j16, \
|
||||
j20, j21, j22, j23, j24, j25, j26, \
|
||||
j30, j31, j32, j33, j34, j35, \
|
||||
j40, j41, j42, j43, j44, \
|
||||
j54, j55, j56, \
|
||||
k00, k01, k02, k03, k04, k05, k06, \
|
||||
k10, k11, k12, k13, k14, k15, k16, \
|
||||
k20, k21, k22, k23, k24, k25, k26, \
|
||||
@ -42,12 +36,6 @@
|
||||
k42, k43, k44, k45, k46, \
|
||||
k50, k51, k52 \
|
||||
) { \
|
||||
{ j00, j01, j02, j03, j04, j05, j06 }, \
|
||||
{ j10, j11, j12, j13, j14, j15, j16 }, \
|
||||
{ j20, j21, j22, j23, j24, j25, j26 }, \
|
||||
{ j30, j31, j32, j33, j34, j35, 0 }, \
|
||||
{ j40, j41, j42, j43, j44, 0, 0 }, \
|
||||
{ 0, 0, 0, 0, j54, j55, j56 }, \
|
||||
{ k00, k01, k02, k03, k04, k05, k06 }, \
|
||||
{ k10, k11, k12, k13, k14, k15, k16 }, \
|
||||
{ k20, k21, k22, k23, k24, k25, k26 }, \
|
||||
@ -56,4 +44,4 @@
|
||||
{ k50, k51, k52, 0, 0, 0, 0 } \
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define DESCRIPTION "Handwire protoboard"
|
||||
|
||||
/* key matrix size */
|
||||
#define MATRIX_ROWS 12
|
||||
#define MATRIX_ROWS 6
|
||||
#define MATRIX_COLS 7
|
||||
|
||||
/*
|
||||
@ -40,11 +40,9 @@
|
||||
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
|
||||
*
|
||||
*/
|
||||
/* Note: These are not used for arm boards. They're here purely as documentation.
|
||||
* #define MATRIX_ROW_PINS { PB0, PB1, PB2, PA15, PA10 }
|
||||
* #define MATRIX_COL_PINS { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 }
|
||||
* #define UNUSED_PINS
|
||||
*/
|
||||
|
||||
#define MATRIX_ROW_PINS { B11, B10, B12, B13, B14, B15 }
|
||||
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6 }
|
||||
|
||||
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
|
||||
#define DEBOUNCE 6
|
||||
@ -130,5 +128,20 @@
|
||||
|
||||
#define NO_USB_STARTUP_CHECK
|
||||
|
||||
// This is a 7-bit address, that gets left-shifted and bit 0
|
||||
// set to 0 for write, 1 for read (as per I2C protocol)
|
||||
// The address will vary depending on your wiring:
|
||||
// 0b1110100 AD <-> GND
|
||||
// 0b1110111 AD <-> VCC
|
||||
// 0b1110101 AD <-> SCL
|
||||
// 0b1110110 AD <-> SDA
|
||||
#define DRIVER_ADDR_1 0b1110100
|
||||
#define DRIVER_ADDR_2 0b1110110
|
||||
|
||||
#define DRIVER_COUNT 2
|
||||
#define DRIVER_1_LED_TOTAL 35
|
||||
#define DRIVER_2_LED_TOTAL 35
|
||||
#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -34,12 +34,12 @@ enum custom_keycodes {
|
||||
|
||||
const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = KEYMAP(
|
||||
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_DEL,
|
||||
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_HOME,
|
||||
KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_END,
|
||||
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_N,
|
||||
KC_NO, KC_LCTL, KC_LALT, KC_LGUI, MO(1),
|
||||
KC_SPC, MO(1), RESET,
|
||||
// KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_DEL,
|
||||
// KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_HOME,
|
||||
// KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_END,
|
||||
// KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_N,
|
||||
// KC_NO, KC_LCTL, KC_LALT, KC_LGUI, MO(1),
|
||||
// KC_SPC, MO(1), RESET,
|
||||
|
||||
KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
|
||||
KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL,
|
||||
|
@ -7,27 +7,23 @@
|
||||
#include "printf.h"
|
||||
#include "backlight.h"
|
||||
#include "matrix.h"
|
||||
#include "action.h"
|
||||
#include "keycode.h"
|
||||
#include <string.h>
|
||||
#include "quantum.h"
|
||||
|
||||
#include "usb_main.h"
|
||||
#include "twi2c.h"
|
||||
|
||||
/* QMK Handwire
|
||||
*
|
||||
* Column pins are input with internal pull-down.
|
||||
* Row pins are output and strobe with high.
|
||||
* Key is high or 1 when it turns on.
|
||||
*
|
||||
* col: { A13, A14, A15, B3, B4, B5, B6 }
|
||||
* row: { B10, B2, B1, B0, A7, A6 }
|
||||
/*
|
||||
* col: { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 }
|
||||
* row: { B5, B10, A9, A8 }
|
||||
*/
|
||||
/* 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 matrix_debouncing[MATRIX_COLS];
|
||||
static bool debouncing = false;
|
||||
static uint16_t debouncing_time = 0;
|
||||
|
||||
static bool master = false;
|
||||
static bool right_hand = false;
|
||||
static LINE_TYPE matrix_col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
|
||||
static LINE_TYPE matrix_row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
|
||||
|
||||
__attribute__ ((weak))
|
||||
void matrix_init_user(void) {}
|
||||
@ -47,126 +43,43 @@ void matrix_scan_kb(void) {
|
||||
|
||||
void matrix_init(void) {
|
||||
printf("matrix init\n");
|
||||
// debug_matrix = true;
|
||||
//debug_matrix = true;
|
||||
|
||||
// C13 is connected to VCC on the right hand
|
||||
palSetPadMode(GPIOC, 13, PAL_MODE_INPUT);
|
||||
wait_us(20);
|
||||
right_hand = palReadPad(GPIOC, 13);
|
||||
|
||||
// if USB is active, this is the master
|
||||
// master = usbGetDriverStateI(&USB_DRIVER) == USB_ACTIVE;
|
||||
master = right_hand;
|
||||
|
||||
if (master) {
|
||||
twi2c_init();
|
||||
} else {
|
||||
twi2c_slave_init();
|
||||
// actual matrix setup
|
||||
for (int i = 0; i < MATRIX_COLS; i++) {
|
||||
setPadMode(matrix_col_pins[i], PAL_MODE_OUTPUT_PUSHPULL);
|
||||
}
|
||||
|
||||
/* Column(sense) */
|
||||
palSetPadMode(GPIOA, 13, PAL_MODE_INPUT_PULLDOWN);
|
||||
palSetPadMode(GPIOA, 14, PAL_MODE_INPUT_PULLDOWN);
|
||||
palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLDOWN);
|
||||
palSetPadMode(GPIOB, 3, PAL_MODE_INPUT_PULLDOWN);
|
||||
palSetPadMode(GPIOB, 4, PAL_MODE_INPUT_PULLDOWN);
|
||||
palSetPadMode(GPIOB, 5, PAL_MODE_INPUT_PULLDOWN);
|
||||
palSetPadMode(GPIOB, 6, PAL_MODE_INPUT_PULLDOWN);
|
||||
|
||||
/* Row(strobe) */
|
||||
palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
for (int i = 0; i < MATRIX_ROWS; i++) {
|
||||
setPadMode(matrix_row_pins[i], PAL_MODE_INPUT_PULLDOWN);
|
||||
}
|
||||
|
||||
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
|
||||
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
|
||||
memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t));
|
||||
|
||||
// palClearPad(GPIOB, 7); // Turn off capslock
|
||||
matrix_init_quantum();
|
||||
}
|
||||
|
||||
matrix_row_t matrix_scan_common(uint8_t row) {
|
||||
matrix_row_t data;
|
||||
|
||||
// strobe row { A6, A7, B0, B1, B2, B10 }
|
||||
switch (row) {
|
||||
case 5: palSetPad(GPIOA, 6); break;
|
||||
case 4: palSetPad(GPIOA, 7); break;
|
||||
case 3: palSetPad(GPIOB, 0); break;
|
||||
case 2: palSetPad(GPIOB, 1); break;
|
||||
case 1: palSetPad(GPIOB, 2); break;
|
||||
case 0: palSetPad(GPIOB, 10); break;
|
||||
}
|
||||
|
||||
// need wait to settle pin state
|
||||
wait_us(20);
|
||||
|
||||
// read col data { B6, B5, B4, B3, A15, A14, A13 }
|
||||
data = (
|
||||
(palReadPad(GPIOB, 6) << 6 ) |
|
||||
(palReadPad(GPIOB, 5) << 5 ) |
|
||||
(palReadPad(GPIOB, 4) << 4 ) |
|
||||
(palReadPad(GPIOB, 3) << 3 ) |
|
||||
(palReadPad(GPIOA, 15) << 2 ) |
|
||||
(palReadPad(GPIOA, 14) << 1 ) |
|
||||
(palReadPad(GPIOA, 13) << 0 )
|
||||
);
|
||||
|
||||
// unstrobe row { A6, A7, B0, B1, B2, B10 }
|
||||
switch (row) {
|
||||
case 5: palClearPad(GPIOA, 6); break;
|
||||
case 4: palClearPad(GPIOA, 7); break;
|
||||
case 3: palClearPad(GPIOB, 0); break;
|
||||
case 2: palClearPad(GPIOB, 1); break;
|
||||
case 1: palClearPad(GPIOB, 2); break;
|
||||
case 0: palClearPad(GPIOB, 10); break;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const uint8_t command[2] = { 0x01, 0x00 };
|
||||
uint8_t other_matrix[MATRIX_ROWS] = { 0 };
|
||||
|
||||
void matrix_scan_master(void) {
|
||||
|
||||
msg_t resp;
|
||||
// resp = twi2c_master_send(slaveI2Caddress/2, command, 2, other_matrix, US2ST(100));
|
||||
resp = i2cMasterTransmitTimeout(&I2C_DRIVER, slaveI2Caddress/2, command, 2, other_matrix, MATRIX_ROWS / 2, MS2ST(100));
|
||||
// resp = i2cMasterReceiveTimeout(&I2C_DRIVER, slaveI2Caddress/2, other_matrix, MATRIX_ROWS / 2, US2ST(100));
|
||||
// printf("%x\n", resp);
|
||||
// if (resp != MSG_OK) {
|
||||
// for (i = 0; i < MATRIX_ROWS / 2; i++) {
|
||||
// resp = i2cMasterReceiveTimeout(&I2C_DRIVER, slaveI2Caddress/2, other_matrix, MATRIX_ROWS / 2, US2ST(100));
|
||||
// }
|
||||
// }
|
||||
|
||||
if (resp == MSG_OK) {
|
||||
uint8_t * matrix_pointer;
|
||||
if (right_hand) {
|
||||
matrix_pointer = matrix;
|
||||
} else {
|
||||
matrix_pointer = matrix + (MATRIX_ROWS / 2);
|
||||
}
|
||||
|
||||
memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void) {
|
||||
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
|
||||
// actual matrix
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
matrix_row_t data = 0;
|
||||
|
||||
if ((right_hand && row >= 6) || (!right_hand && row < 6)) {
|
||||
data = matrix_scan_common(row % 6);
|
||||
setPad(matrix_col_pins[col]);
|
||||
|
||||
// need wait to settle pin state
|
||||
wait_us(20);
|
||||
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
data |= (readPad(matrix_row_pins[row]) << row);
|
||||
}
|
||||
|
||||
if (matrix_debouncing[row] != data) {
|
||||
matrix_debouncing[row] = data;
|
||||
clearPad(matrix_col_pins[col]);
|
||||
|
||||
if (matrix_debouncing[col] != data) {
|
||||
matrix_debouncing[col] = data;
|
||||
debouncing = true;
|
||||
debouncing_time = timer_read();
|
||||
}
|
||||
@ -174,15 +87,14 @@ uint8_t matrix_scan(void) {
|
||||
|
||||
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
matrix[row] = matrix_debouncing[row];
|
||||
matrix[row] = 0;
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col);
|
||||
}
|
||||
}
|
||||
debouncing = false;
|
||||
}
|
||||
|
||||
if (master) {
|
||||
matrix_scan_master();
|
||||
}
|
||||
|
||||
matrix_scan_quantum();
|
||||
|
||||
return 1;
|
||||
@ -196,16 +108,6 @@ matrix_row_t matrix_get_row(uint8_t row) {
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void matrix_copy(matrix_row_t * copy) {
|
||||
uint8_t * matrix_pointer;
|
||||
if (right_hand) {
|
||||
matrix_pointer = matrix + (MATRIX_ROWS / 2);
|
||||
} else {
|
||||
matrix_pointer = matrix;
|
||||
}
|
||||
memcpy(copy, matrix_pointer, MATRIX_ROWS / 2);
|
||||
}
|
||||
|
||||
void matrix_print(void) {
|
||||
printf("\nr/c 01234567\n");
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
|
@ -53,4 +53,4 @@ NKRO_ENABLE = yes # USB Nkey Rollover
|
||||
CUSTOM_MATRIX = yes # Custom matrix file
|
||||
AUDIO_ENABLE = yes
|
||||
# SERIAL_LINK_ENABLE = yes
|
||||
I2C_SLAVE_ENABLE = yes
|
||||
RGB_MATRIX_ENABLE = yes
|
||||
|
Loading…
x
Reference in New Issue
Block a user