updated teensy stuff for dox's PCB
parent
50998376c5
commit
1af2423364
|
@ -136,12 +136,13 @@ uint8_t teensy_init(void) {
|
|||
teensypin_write_all_unused(PORT, SET); // set internal pull-up enabled
|
||||
|
||||
// rows
|
||||
teensypin_write_all_row(DDR, CLEAR); // set as input (hi-Z)
|
||||
teensypin_write_all_row(PORT, CLEAR); // set internal pull-up disabled
|
||||
teensypin_write_all_row(DDR, CLEAR); // set as input
|
||||
teensypin_write_all_row(PORT, SET); // set internal pull-up enabled
|
||||
|
||||
// columns
|
||||
teensypin_write_all_column(DDR, CLEAR); // set as input
|
||||
teensypin_write_all_column(PORT, SET); // set internal pull-up enabled
|
||||
teensypin_write_all_column(DDR, CLEAR); // set as input (hi-Z)
|
||||
teensypin_write_all_column(PORT, CLEAR); // set internal pull-up
|
||||
// disabled
|
||||
|
||||
return 0; // success
|
||||
}
|
||||
|
@ -152,40 +153,43 @@ uint8_t teensy_init(void) {
|
|||
#if KB_ROWS != 12 || KB_COLUMNS != 7
|
||||
#error "Expecting different keyboard dimensions"
|
||||
#endif
|
||||
static inline void _update_columns(
|
||||
bool matrix[KB_ROWS][KB_COLUMNS], uint8_t row ) {
|
||||
matrix[row][0] = ! teensypin_read(COLUMN_0);
|
||||
matrix[row][1] = ! teensypin_read(COLUMN_1);
|
||||
matrix[row][2] = ! teensypin_read(COLUMN_2);
|
||||
matrix[row][3] = ! teensypin_read(COLUMN_3);
|
||||
matrix[row][4] = ! teensypin_read(COLUMN_4);
|
||||
matrix[row][5] = ! teensypin_read(COLUMN_5);
|
||||
matrix[row][6] = ! teensypin_read(COLUMN_6);
|
||||
static inline void _update_rows(
|
||||
bool matrix[KB_ROWS][KB_COLUMNS], uint8_t column ) {
|
||||
matrix[0][column] = ! teensypin_read(ROW_0);
|
||||
matrix[1][column] = ! teensypin_read(ROW_1);
|
||||
matrix[2][column] = ! teensypin_read(ROW_2);
|
||||
matrix[3][column] = ! teensypin_read(ROW_3);
|
||||
matrix[4][column] = ! teensypin_read(ROW_4);
|
||||
matrix[5][column] = ! teensypin_read(ROW_5);
|
||||
}
|
||||
uint8_t teensy_update_matrix(bool matrix[KB_ROWS][KB_COLUMNS]) {
|
||||
teensypin_write(DDR, SET, ROW_0); // set row low (set as output)
|
||||
_update_columns(matrix, 0); // read col 0..6 and update matrix
|
||||
teensypin_write(DDR, CLEAR, ROW_0); // set row hi-Z (set as input)
|
||||
teensypin_write(DDR, SET, COLUMN_0); // set col low (set as output)
|
||||
_update_rows(matrix, 0); // read row 0..5 & update matrix
|
||||
teensypin_write(DDR, CLEAR, COLUMN_0); // set col hi-Z (set as input)
|
||||
|
||||
teensypin_write(DDR, SET, ROW_1);
|
||||
_update_columns(matrix, 1);
|
||||
teensypin_write(DDR, CLEAR, ROW_1);
|
||||
teensypin_write(DDR, SET, COLUMN_1);
|
||||
_update_rows(matrix, 1);
|
||||
teensypin_write(DDR, CLEAR, COLUMN_1);
|
||||
|
||||
teensypin_write(DDR, SET, ROW_2);
|
||||
_update_columns(matrix, 2);
|
||||
teensypin_write(DDR, CLEAR, ROW_2);
|
||||
teensypin_write(DDR, SET, COLUMN_2);
|
||||
_update_rows(matrix, 2);
|
||||
teensypin_write(DDR, CLEAR, COLUMN_2);
|
||||
|
||||
teensypin_write(DDR, SET, ROW_3);
|
||||
_update_columns(matrix, 3);
|
||||
teensypin_write(DDR, CLEAR, ROW_3);
|
||||
teensypin_write(DDR, SET, COLUMN_3);
|
||||
_update_rows(matrix, 3);
|
||||
teensypin_write(DDR, CLEAR, COLUMN_3);
|
||||
|
||||
teensypin_write(DDR, SET, ROW_4);
|
||||
_update_columns(matrix, 4);
|
||||
teensypin_write(DDR, CLEAR, ROW_4);
|
||||
teensypin_write(DDR, SET, COLUMN_4);
|
||||
_update_rows(matrix, 4);
|
||||
teensypin_write(DDR, CLEAR, COLUMN_4);
|
||||
|
||||
teensypin_write(DDR, SET, ROW_5);
|
||||
_update_columns(matrix, 5);
|
||||
teensypin_write(DDR, CLEAR, ROW_5);
|
||||
teensypin_write(DDR, SET, COLUMN_5);
|
||||
_update_rows(matrix, 5);
|
||||
teensypin_write(DDR, CLEAR, COLUMN_5);
|
||||
|
||||
teensypin_write(DDR, SET, COLUMN_6);
|
||||
_update_rows(matrix, 6);
|
||||
teensypin_write(DDR, CLEAR, COLUMN_6);
|
||||
|
||||
return 0; // success
|
||||
}
|
||||
|
|
|
@ -16,14 +16,16 @@
|
|||
#include "matrix.h"
|
||||
|
||||
// LED control
|
||||
#define kb_led1_on() (DDRB |= (1<<5))
|
||||
#define kb_led1_off() (DDRB &= ~(1<<5))
|
||||
#define kb_led1_set(n) (OCR1A = (uint8_t)(n))
|
||||
#define kb_led1_set_percent(n) (OCR1A = (uint8_t)((n) * 0xFF))
|
||||
#define kb_led2_on() (DDRB |= (1<<6))
|
||||
#define kb_led2_off() (DDRB &= ~(1<<6))
|
||||
#define kb_led2_set(n) (OCR1B = (uint8_t)(n))
|
||||
#define kb_led2_set_percent(n) (OCR1B = (uint8_t)((n) * 0xFF))
|
||||
#define kb_led1_on() (DDRB |= (1<<6))
|
||||
#define kb_led1_off() (DDRB &= ~(1<<6))
|
||||
#define kb_led1_set(n) (OCR1B = (uint8_t)(n))
|
||||
#define kb_led1_set_percent(n) (OCR1B = (uint8_t)((n) * 0xFF))
|
||||
//
|
||||
#define kb_led2_on() (DDRB |= (1<<5))
|
||||
#define kb_led2_off() (DDRB &= ~(1<<5))
|
||||
#define kb_led2_set(n) (OCR1A = (uint8_t)(n))
|
||||
#define kb_led2_set_percent(n) (OCR1A = (uint8_t)((n) * 0xFF))
|
||||
//
|
||||
#define kb_led3_on() (DDRB |= (1<<7))
|
||||
#define kb_led3_off() (DDRB &= ~(1<<7))
|
||||
#define kb_led3_set(n) (OCR1C = (uint8_t)(n))
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
PB3 o o o + PF5 row3
|
||||
(OC1C) LED3 PB7 + PE6 AREF + PF6 row4
|
||||
(SCL) I2C PD0 + + PF7 row5
|
||||
(SDA) I2C PD1 + + PB6 LED2 (OC1B)
|
||||
column3 PD2 + + PB5 LED1 (OC1A)
|
||||
(SDA) I2C PD1 + + PB6 LED1 (OC1B)
|
||||
column3 PD2 + + PB5 LED2 (OC1A)
|
||||
column4 PD3 + + PB4 column0
|
||||
column1 PC6 + + PD7 column5
|
||||
column2 PC7 +-o-o-o-o-o-+ PD6 onboardLED
|
||||
|
@ -70,10 +70,11 @@
|
|||
* PD6 (the onboard LED) already has a defined level (low), so there's no
|
||||
reason to set internal pull-up enabled on it. If we do, it will source
|
||||
current to the LED, which is fine, but unnecessary.
|
||||
* We want the row pins 'hi-Z' initially (set as input with pull-up
|
||||
disabled), and the column pins set as input with internal pull-up
|
||||
enabled. We'll cycle through driving the row pins low (setting them as
|
||||
output) and checking the column pins in the update function.
|
||||
* We want the columns to be hi-Z when that column's not being scanned,
|
||||
drive low when it is, and the rows to be input with pull-up enabled.
|
||||
We'll cycle through driving the columns low and scanning all rows.
|
||||
* To set a pin hi-Z on this board, set it as input with pull-up
|
||||
disabled.
|
||||
* Switching the row pins between hi-Z and drive low (treating them as
|
||||
if they were open drain) seems just as good as, and a little safer
|
||||
than, driving them high when the row's not active.
|
||||
|
|
Loading…
Reference in New Issue