arm lines implemented

This commit is contained in:
Jack Humbert 2018-06-03 18:01:11 -04:00
parent c1f6f1308b
commit 018a0142d2
3 changed files with 129 additions and 60 deletions

View file

@ -18,6 +18,8 @@
#ifndef REV6_CONFIG_H
#define REV6_CONFIG_H
#include "config_common.h"
/* USB Device descriptor parameter */
#undef PRODUCT
#define PRODUCT Planck Light
@ -41,11 +43,10 @@
* 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
*/
#undef MATRIX_ROW_PINS
#undef MATRIX_COL_PINS
#define MATRIX_ROW_PINS { B5, B10, A9, A8 }
#define MATRIX_COL_PINS { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 }
#define MUSIC_MAP
#undef AUDIO_VOICES

View file

@ -25,6 +25,9 @@ static uint8_t encoder_state = 0;
static int8_t encoder_value = 0;
static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };
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) {}
@ -52,29 +55,17 @@ void matrix_init(void) {
encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1);
// actual matrix setup
palSetPadMode(GPIOA, 10, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 15, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 0, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 1, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 5, PAL_MODE_INPUT_PULLDOWN);
palSetPadMode(GPIOB, 10, PAL_MODE_INPUT_PULLDOWN);
palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_PULLDOWN);
palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLDOWN);
for (int i = 0; i < MATRIX_COLS; i++) {
setPadMode(matrix_col_pins[i], 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_COLS * sizeof(matrix_row_t));
matrix_init_quantum();
}
@ -106,49 +97,17 @@ uint8_t matrix_scan(void) {
for (int col = 0; col < MATRIX_COLS; col++) {
matrix_row_t data = 0;
// strobe col { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 }
switch (col) {
case 0: palSetPad(GPIOA, 10); break;
case 1: palSetPad(GPIOB, 2); break;
case 2: palSetPad(GPIOA, 15); break;
case 3: palSetPad(GPIOA, 0); break;
case 4: palSetPad(GPIOA, 1); break;
case 5: palSetPad(GPIOA, 2); break;
case 6: palSetPad(GPIOB, 0); break;
case 7: palSetPad(GPIOB, 1); break;
case 8: palSetPad(GPIOC, 13); break;
case 9: palSetPad(GPIOA, 6); break;
case 10: palSetPad(GPIOA, 7); break;
case 11: palSetPad(GPIOA, 3); break;
}
setPad(matrix_col_pins[col]);
// need wait to settle pin state
wait_us(20);
// read row data { B5, B10, A9, A8 }
data = (
(palReadPad(GPIOB, 5) << 0 ) |
(palReadPad(GPIOB, 10) << 1 ) |
(palReadPad(GPIOA, 9) << 2 ) |
(palReadPad(GPIOA, 8) << 3 )
);
// unstrobe col { B11, B10, B2, B1, A7, B0 }
switch (col) {
case 0: palClearPad(GPIOA, 10); break;
case 1: palClearPad(GPIOB, 2); break;
case 2: palClearPad(GPIOA, 15); break;
case 3: palClearPad(GPIOA, 0); break;
case 4: palClearPad(GPIOA, 1); break;
case 5: palClearPad(GPIOA, 2); break;
case 6: palClearPad(GPIOB, 0); break;
case 7: palClearPad(GPIOB, 1); break;
case 8: palClearPad(GPIOC, 13); break;
case 9: palClearPad(GPIOA, 6); break;
case 10: palClearPad(GPIOA, 7); break;
case 11: palClearPad(GPIOA, 3); break;
for (int row = 0; row < MATRIX_ROWS; row++) {
data |= (readPad(matrix_row_pins[row]) << row);
}
clearPad(matrix_col_pins[col]);
if (matrix_debouncing[col] != data) {
matrix_debouncing[col] = data;
debouncing = true;

View file

@ -23,6 +23,8 @@
#define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
#ifdef __AVR__
#define LINE_TYPE uint8_t
/* I/O pins */
#ifndef F0
#define B0 0x30
@ -74,8 +76,115 @@
#define A6 0x06
#define A7 0x07
#endif
#else
#include "hal.h"
#define LINE_TYPE ioline_t
#define A0 PAL_LINE(GPIOA, 0)
#define A1 PAL_LINE(GPIOA, 1)
#define A2 PAL_LINE(GPIOA, 2)
#define A3 PAL_LINE(GPIOA, 3)
#define A4 PAL_LINE(GPIOA, 4)
#define A5 PAL_LINE(GPIOA, 5)
#define A6 PAL_LINE(GPIOA, 6)
#define A7 PAL_LINE(GPIOA, 7)
#define A8 PAL_LINE(GPIOA, 8)
#define A9 PAL_LINE(GPIOA, 9)
#define A10 PAL_LINE(GPIOA, 10)
#define A11 PAL_LINE(GPIOA, 11)
#define A12 PAL_LINE(GPIOA, 12)
#define A13 PAL_LINE(GPIOA, 13)
#define A14 PAL_LINE(GPIOA, 14)
#define A15 PAL_LINE(GPIOA, 15)
#define B0 PAL_LINE(GPIOB, 0)
#define B1 PAL_LINE(GPIOB, 1)
#define B2 PAL_LINE(GPIOB, 2)
#define B3 PAL_LINE(GPIOB, 3)
#define B4 PAL_LINE(GPIOB, 4)
#define B5 PAL_LINE(GPIOB, 5)
#define B6 PAL_LINE(GPIOB, 6)
#define B7 PAL_LINE(GPIOB, 7)
#define B8 PAL_LINE(GPIOB, 8)
#define B9 PAL_LINE(GPIOB, 9)
#define B10 PAL_LINE(GPIOB, 10)
#define B11 PAL_LINE(GPIOB, 11)
#define B12 PAL_LINE(GPIOB, 12)
#define B13 PAL_LINE(GPIOB, 13)
#define B14 PAL_LINE(GPIOB, 14)
#define B15 PAL_LINE(GPIOB, 15)
#define C0 PAL_LINE(GPIOC, 0)
#define C1 PAL_LINE(GPIOC, 1)
#define C2 PAL_LINE(GPIOC, 2)
#define C3 PAL_LINE(GPIOC, 3)
#define C4 PAL_LINE(GPIOC, 4)
#define C5 PAL_LINE(GPIOC, 5)
#define C6 PAL_LINE(GPIOC, 6)
#define C7 PAL_LINE(GPIOC, 7)
#define C8 PAL_LINE(GPIOC, 8)
#define C9 PAL_LINE(GPIOC, 9)
#define C10 PAL_LINE(GPIOC, 10)
#define C11 PAL_LINE(GPIOC, 11)
#define C12 PAL_LINE(GPIOC, 12)
#define C13 PAL_LINE(GPIOC, 13)
#define C14 PAL_LINE(GPIOC, 14)
#define C15 PAL_LINE(GPIOC, 15)
#define D0 PAL_LINE(GPIOD, 0)
#define D1 PAL_LINE(GPIOD, 1)
#define D2 PAL_LINE(GPIOD, 2)
#define D3 PAL_LINE(GPIOD, 3)
#define D4 PAL_LINE(GPIOD, 4)
#define D5 PAL_LINE(GPIOD, 5)
#define D6 PAL_LINE(GPIOD, 6)
#define D7 PAL_LINE(GPIOD, 7)
#define D8 PAL_LINE(GPIOD, 8)
#define D9 PAL_LINE(GPIOD, 9)
#define D10 PAL_LINE(GPIOD, 10)
#define D11 PAL_LINE(GPIOD, 11)
#define D12 PAL_LINE(GPIOD, 12)
#define D13 PAL_LINE(GPIOD, 13)
#define D14 PAL_LINE(GPIOD, 14)
#define D15 PAL_LINE(GPIOD, 15)
#define E0 PAL_LINE(GPIOE, 0)
#define E1 PAL_LINE(GPIOE, 1)
#define E2 PAL_LINE(GPIOE, 2)
#define E3 PAL_LINE(GPIOE, 3)
#define E4 PAL_LINE(GPIOE, 4)
#define E5 PAL_LINE(GPIOE, 5)
#define E6 PAL_LINE(GPIOE, 6)
#define E7 PAL_LINE(GPIOE, 7)
#define E8 PAL_LINE(GPIOE, 8)
#define E9 PAL_LINE(GPIOE, 9)
#define E10 PAL_LINE(GPIOE, 10)
#define E11 PAL_LINE(GPIOE, 11)
#define E12 PAL_LINE(GPIOE, 12)
#define E13 PAL_LINE(GPIOE, 13)
#define E14 PAL_LINE(GPIOE, 14)
#define E15 PAL_LINE(GPIOE, 15)
#define F0 PAL_LINE(GPIOF, 0)
#define F1 PAL_LINE(GPIOF, 1)
#define F2 PAL_LINE(GPIOF, 2)
#define F3 PAL_LINE(GPIOF, 3)
#define F4 PAL_LINE(GPIOF, 4)
#define F5 PAL_LINE(GPIOF, 5)
#define F6 PAL_LINE(GPIOF, 6)
#define F7 PAL_LINE(GPIOF, 7)
#define F8 PAL_LINE(GPIOF, 8)
#define F9 PAL_LINE(GPIOF, 9)
#define F10 PAL_LINE(GPIOF, 10)
#define F11 PAL_LINE(GPIOF, 11)
#define F12 PAL_LINE(GPIOF, 12)
#define F13 PAL_LINE(GPIOF, 13)
#define F14 PAL_LINE(GPIOF, 14)
#define F15 PAL_LINE(GPIOF, 15)
#define setPadMode(line, mode) palSetPadMode(PAL_PORT(line), PAL_PAD(line), mode)
#define setPad(line) palSetPad(PAL_PORT(line), PAL_PAD(line))
#define clearPad(line) palClearPad(PAL_PORT(line), PAL_PAD(line))
#define readPad(line) palReadPad(PAL_PORT(line), PAL_PAD(line))
#endif
/* USART configuration */
#ifdef BLUETOOTH_ENABLE
# ifdef __AVR_ATmega32U4__