fc980c: Fix for pin config of TMK controller

This commit is contained in:
tmk 2017-07-27 21:43:14 +09:00
parent e3036006e8
commit 3d3bcd8ad6
2 changed files with 15 additions and 19 deletions

View file

@ -51,11 +51,9 @@ void matrix_init(void)
KEY_INIT();
// LEDs on NumLock, CapsLock and ScrollLock(PD7, PB5, PB6)
DDRD |= (1<<7);
PORTD |= (1<<7);
DDRB |= (1<<5) | (1<<6);
PORTB |= (1<<5) | (1<<6);
// LEDs on NumLock, CapsLock and ScrollLock(PB4, PB5, PB6)
DDRB |= (1<<4) | (1<<5) | (1<<6);
PORTB |= (1<<4) | (1<<5) | (1<<6);
// initialize matrix state: all keys off
for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
@ -133,9 +131,9 @@ matrix_row_t matrix_get_row(uint8_t row)
void led_set(uint8_t usb_led)
{
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
PORTD |= (1<<7);
PORTB |= (1<<4);
} else {
PORTD &= ~(1<<7);
PORTB &= ~(1<<4);
}
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
PORTB |= (1<<5);

View file

@ -19,42 +19,40 @@
/*
* Pin configuration for ATMega32U4
*
* Row: PD5,6,PB0, PD4(~EN)
* Col: PB1-3, 4
* Row: PD4-6, PD7(~EN)
* Col: PB0-3
* Key: PC6(pull-uped)
* Hys: PC7
*/
static inline void KEY_ENABLE(void) { (PORTD &= ~(1<<4)); }
static inline void KEY_UNABLE(void) { (PORTD |= (1<<4)); }
static inline void KEY_ENABLE(void) { (PORTD &= ~(1<<7)); }
static inline void KEY_UNABLE(void) { (PORTD |= (1<<7)); }
static inline bool KEY_STATE(void) { return (PINC & (1<<6)); }
static inline void KEY_HYS_ON(void) { (PORTC |= (1<<7)); }
static inline void KEY_HYS_OFF(void) { (PORTC &= ~(1<<7)); }
static inline void KEY_INIT(void)
{
/* Col */
DDRB |= 0x1F;
DDRB |= 0x0F;
/* Key: input with pull-up */
DDRC &= ~(1<<6);
PORTC |= (1<<6);
/* Hys */
DDRC |= (1<<7);
/* Row */
DDRD |= 0x70;
DDRD |= 0xF0;
KEY_UNABLE();
KEY_HYS_OFF();
}
static inline void SET_ROW(uint8_t ROW)
{
// set row with unabling key
PORTB = (PORTB & 0xFE) | ((ROW & 0x04) >> 2); // PB0
PORTD = (PORTD & 0x9F) | ((ROW & 0x03) << 5); // PD5,6
// PD4-6
PORTD = (PORTD & 0x8F) | ((ROW & 0x07) << 4);
}
static inline void SET_COL(uint8_t COL)
{
// PB4(Lo:Z5, Hi:Z4)
// PB1-3
PORTB = (PORTB & 0xE1) | ((COL & 0x0F) << 1);
// PB0-3
PORTB = (PORTB & 0xF0) | (COL & 0x0F);
}