leds working on both sides
This commit is contained in:
parent
e0f94480d1
commit
beaf774a81
8 changed files with 300 additions and 7 deletions
|
@ -52,7 +52,7 @@ void i2c_init(void)
|
|||
palSetPadMode(GPIOB, 7, PAL_MODE_INPUT);
|
||||
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
|
||||
palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP);
|
||||
palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP);
|
||||
|
||||
|
@ -81,6 +81,10 @@ uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t ti
|
|||
return i2cMasterReceiveTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, MS2ST(timeout));
|
||||
}
|
||||
|
||||
uint8_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length) {
|
||||
return i2cMasterTransmitTimeout(&I2C_DRIVER, address/2, tx_body, tx_length, rx_body, rx_length, MS2ST(100));
|
||||
}
|
||||
|
||||
uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
|
||||
{
|
||||
i2c_address = devaddr;
|
||||
|
|
|
@ -76,3 +76,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
//#define NO_ACTION_ONESHOT
|
||||
//#define NO_ACTION_MACRO
|
||||
//#define NO_ACTION_FUNCTION
|
||||
|
||||
#define DRIVER_ADDR_1 0b1110100
|
||||
#define DRIVER_ADDR_2 0b1110111
|
||||
|
||||
#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
|
||||
|
|
|
@ -28,6 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "action.h"
|
||||
#include "keycode.h"
|
||||
#include <string.h>
|
||||
#include "moonlander.h"
|
||||
#include "i2c_master.h"
|
||||
|
||||
/*
|
||||
#define MATRIX_ROW_PINS { B10, B11, B12, B13, B14, B15 } outputs
|
||||
|
@ -35,9 +37,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
||||
/* matrix state(1:on, 0:off) */
|
||||
static matrix_row_t matrix[MATRIX_ROWS];
|
||||
static matrix_row_t matrix_debouncing[MATRIX_COLS];
|
||||
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||
static bool debouncing = false;
|
||||
static uint16_t debouncing_time = 0;
|
||||
static bool debouncing_right = false;
|
||||
static uint16_t debouncing_time_right = 0;
|
||||
|
||||
__attribute__ ((weak))
|
||||
void matrix_init_user(void) {}
|
||||
|
@ -55,6 +59,41 @@ void matrix_scan_kb(void) {
|
|||
matrix_scan_user();
|
||||
}
|
||||
|
||||
bool mcp23018_initd = false;
|
||||
uint8_t mcp23018_tx[3];
|
||||
uint8_t mcp23018_rx[1];
|
||||
|
||||
void mcp23018_init(void) {
|
||||
|
||||
i2c_init();
|
||||
i2c_start(MCP23018_DEFAULT_ADDRESS << 1);
|
||||
|
||||
// #define MCP23_ROW_PINS { GPB5, GBP4, GBP3, GBP2, GBP1, GBP0 } outputs
|
||||
// #define MCP23_COL_PINS { GPA0, GBA1, GBA2, GBA3, GBA4, GBA5, GBA6 } inputs
|
||||
|
||||
mcp23018_tx[0] = 0x00; // IODIRA
|
||||
mcp23018_tx[1] = 0x00; // ?
|
||||
mcp23018_tx[2] = 0b00111111; // A is inputs
|
||||
|
||||
if (MSG_OK != i2c_transmit(MCP23018_DEFAULT_ADDRESS << 1,
|
||||
mcp23018_tx, 3, 100
|
||||
)) {
|
||||
printf("error hori\n");
|
||||
} else {
|
||||
mcp23018_tx[0] = 0x0C; // GPPUA
|
||||
mcp23018_tx[1] = 0x00; // ?
|
||||
mcp23018_tx[2] = 0b00111111; // pull-up As
|
||||
|
||||
if (MSG_OK != i2c_transmit(MCP23018_DEFAULT_ADDRESS << 1,
|
||||
mcp23018_tx, 3, 100
|
||||
)) {
|
||||
printf("error hori\n");
|
||||
} else {
|
||||
mcp23018_initd = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void matrix_init(void) {
|
||||
printf("matrix init\n");
|
||||
//debug_matrix = true;
|
||||
|
@ -79,13 +118,15 @@ void matrix_init(void) {
|
|||
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
|
||||
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
|
||||
|
||||
mcp23018_init();
|
||||
|
||||
matrix_init_quantum();
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void) {
|
||||
|
||||
// actual matrix
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (int row = 0; row < 6; row++) {
|
||||
matrix_row_t data = 0;
|
||||
|
||||
// strobe row
|
||||
|
@ -127,15 +168,66 @@ uint8_t matrix_scan(void) {
|
|||
debouncing = true;
|
||||
debouncing_time = timer_read();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// right side
|
||||
|
||||
if (!mcp23018_initd) {
|
||||
printf("trying to init right\n");
|
||||
mcp23018_init();
|
||||
}
|
||||
|
||||
// #define MCP23_ROW_PINS { GPB5, GBP4, GBP3, GBP2, GBP1, GBP0 } outputs
|
||||
// #define MCP23_COL_PINS { GPA0, GBA1, GBA2, GBA3, GBA4, GBA5, GBA6 } inputs
|
||||
|
||||
// select row
|
||||
|
||||
mcp23018_tx[0] = 0x12; // GPIOA
|
||||
mcp23018_tx[1] = 0xFF & ~(1<<(row)); // activate row
|
||||
|
||||
if (MSG_OK != i2c_transmit(MCP23018_DEFAULT_ADDRESS << 1,
|
||||
mcp23018_tx, 2, 100
|
||||
)) {
|
||||
printf("error hori\n");
|
||||
}
|
||||
|
||||
// read col
|
||||
|
||||
mcp23018_tx[0] = 0x13; // GPIOB
|
||||
|
||||
if (MSG_OK != i2c_transmit_receive(MCP23018_DEFAULT_ADDRESS << 1,
|
||||
mcp23018_tx, 1,
|
||||
mcp23018_rx, 1
|
||||
)) {
|
||||
printf("error vert\n");
|
||||
}
|
||||
|
||||
data = mcp23018_rx[0];
|
||||
|
||||
if (matrix_debouncing[row + 6] != data) {
|
||||
matrix_debouncing[row + 6] = data;
|
||||
debouncing_right = true;
|
||||
debouncing_time_right = timer_read();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCING_DELAY) {
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (int row = 0; row < 6; row++) {
|
||||
matrix[row] = matrix_debouncing[row];
|
||||
}
|
||||
debouncing = false;
|
||||
}
|
||||
|
||||
if (debouncing_right && timer_elapsed(debouncing_time_right) > DEBOUNCING_DELAY) {
|
||||
for (int row = 6; row < 12; row++) {
|
||||
matrix[row] = matrix_debouncing[row];
|
||||
}
|
||||
debouncing_right = false;
|
||||
}
|
||||
|
||||
matrix_scan_quantum();
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -72,3 +72,190 @@ uint32_t layer_state_set_kb(uint32_t state) {
|
|||
|
||||
return state;
|
||||
}
|
||||
|
||||
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}
|
||||
|
||||
{1, C3_2, C1_1, C4_2}, // 1
|
||||
{1, C2_2, C1_2, C4_3},
|
||||
{1, C2_3, C1_3, C3_3},
|
||||
{1, C2_4, C1_4, C3_4},
|
||||
{1, C2_5, C1_5, C3_5},
|
||||
{1, C2_6, C1_6, C3_6},
|
||||
{1, C2_7, C1_7, C3_7},
|
||||
{1, C2_8, C1_8, C3_8},
|
||||
{1, C3_1, C2_1, C4_1},
|
||||
|
||||
{1, C7_8, C6_8, C8_8}, // 10
|
||||
{1, C7_7, C6_7, C9_8},
|
||||
{1, C8_7, C6_6, C9_7},
|
||||
{1, C8_6, C7_6, C9_6},
|
||||
{1, C8_5, C7_5, C9_5},
|
||||
{1, C8_4, C7_4, C9_4},
|
||||
{1, C8_3, C7_3, C9_3},
|
||||
{1, C8_2, C7_2, C9_2},
|
||||
{1, C8_1, C7_1, C9_1},
|
||||
|
||||
{1, C3_10, C1_9, C4_10}, // 19
|
||||
{1, C2_10, C1_10, C4_11},
|
||||
{1, C2_11, C1_11, C3_11},
|
||||
{1, C2_12, C1_12, C3_12},
|
||||
{1, C2_13, C1_13, C3_13},
|
||||
{1, C2_14, C1_14, C3_14},
|
||||
{1, C2_15, C1_15, C3_15},
|
||||
{1, C2_16, C1_16, C3_16},
|
||||
{1, C3_9, C2_9, C4_9},
|
||||
|
||||
{1, C7_16, C6_16, C8_16}, // 28
|
||||
{1, C7_15, C6_15, C9_16},
|
||||
{1, C8_15, C6_14, C9_15},
|
||||
{1, C8_10, C7_10, C9_10},
|
||||
{1, C8_9, C7_9, C9_9},
|
||||
{1, C8_11, C7_11, C9_11},
|
||||
{1, C8_12, C7_12, C9_12},
|
||||
{1, C8_13, C7_13, C9_13},
|
||||
|
||||
};
|
||||
|
||||
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},
|
||||
|
||||
|
||||
|
||||
|
||||
{{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},
|
||||
|
||||
};
|
||||
|
|
|
@ -17,6 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#pragma once
|
||||
|
||||
#define MCP23018_DEFAULT_ADDRESS 0b0100000
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
#define LAYOUT_moonlander( \
|
||||
|
|
|
@ -19,5 +19,5 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
|
|||
NKRO_ENABLE = yes # USB Nkey Rollover
|
||||
CUSTOM_MATRIX = yes # Custom matrix file
|
||||
AUDIO_ENABLE = no
|
||||
RGBLIGHT_ENABLE = no
|
||||
RGB_MATRIX_ENABLE = IS31FL3731
|
||||
# SERIAL_LINK_ENABLE = yes
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
* @brief Enables the I2C subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_I2C FALSE
|
||||
#define HAL_USE_I2C TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
/*
|
||||
* I2C driver system settings.
|
||||
*/
|
||||
#define STM32_I2C_USE_I2C1 FALSE
|
||||
#define STM32_I2C_USE_I2C1 TRUE
|
||||
#define STM32_I2C_USE_I2C2 FALSE
|
||||
#define STM32_I2C_BUSY_TIMEOUT 50
|
||||
#define STM32_I2C_I2C1_IRQ_PRIORITY 10
|
||||
|
|
Loading…
Reference in a new issue