Skip to content

Commit

Permalink
Change matrix pin usage, LED and keymap of mm60
Browse files Browse the repository at this point in the history
  • Loading branch information
yashikno committed Apr 4, 2013
1 parent cc28679 commit ec1c321
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 63 deletions.
62 changes: 31 additions & 31 deletions keyboard/mm60/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,72 +63,72 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Layer 0: Default Layer
* ,-----------------------------------------------------------.
* |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| `| \|
* |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \|Del|
* |-----------------------------------------------------------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
* |-----------------------------------------------------------|
* |Fn | A| S| D| F| G| H| J| K| L|Fn3| '|Return |
* |Fn2 | A| S| D| F| G| H| J| K| L| ;| '|Return |
* |-----------------------------------------------------------|
* |Shift | Z| X| C| V| B| N| M| ,| .|Fn2|Up |Shift |
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Up |Shift |
* |-----------------------------------------------------------|
* |Ctrl|Gui |Alt | Space |Alt |Left|Down|Righ|
* `-----------------------------------------------------------'
*/
KEYMAP_ANSI(
ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, GRV, BSLS, \
ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,DEL, \
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
FN1, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
FN2, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, UP, RSFT, \
LCTL,LGUI,LALT, SPC, RALT,LEFT,DOWN,RGHT),
LCTL,LGUI,LALT, SPC, MENU,LEFT,DOWN,RGHT),

/* Layer 1: Function
/* Layer 1: Numpad
* ,-----------------------------------------------------------.
* | | F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| | |
* | | | | | | | | 7| 8| 9| | | | | |
* |-----------------------------------------------------------|
* | | | | | | | | | | |Psc|Pus| |Delet|
* | | | | | | | | 4| 5| 6| | | | |
* |-----------------------------------------------------------|
* | | | | | | | | | | | | | |
* | | | | | | | | 1| 2| 3| *| | |
* |-----------------------------------------------------------|
* |Caps Loc| | | | | | | | | | |PgU|Caps L|
* | | | | | | | |Nlk| 0| .| /| | |
* |-----------------------------------------------------------|
* | | | | | |Home|PgDn|End |
* | | | | | | | | |
* `-----------------------------------------------------------'
*/
KEYMAP_ANSI(
TRNS,F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS,TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,PAUS,TRNS,DEL, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,FN2, TRNS,TRNS,TRNS, PGUP,CAPS, \
TRNS,TRNS,TRNS, TRNS, TRNS,HOME,PGDN,END),
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,P7, P8, P9, TRNS,PMNS,PPLS,TRNS,TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,P4, P5, P6, TRNS,TRNS,TRNS,TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,P1, P2, P3, PAST,TRNS, PENT, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,NLCK,P0, PDOT,PSLS, TRNS,TRNS, \
TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),

/* Layer 2: Numpad
/* Layer 2: Function
* ,-----------------------------------------------------------.
* | | | | | | | | 7| 8| 9| | | | | |
* | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ~|Ins|
* |-----------------------------------------------------------|
* | | | | | | | | 4| 5| 6| | | | |
* | | | | | | | | | | |Psc|Pus| |Delet|
* |-----------------------------------------------------------|
* | | | | | | | | 1| 2| 3| | | |
* | | | | | | | | | | | | | |
* |-----------------------------------------------------------|
* | | | | | | | | | | | | | |
* |Caps Loc| | | | | | |Fn1| | | |PgU|Caps L|
* |-----------------------------------------------------------|
* | | | | | | | | |
* | | | | | |Home|PgDn|End |
* `-----------------------------------------------------------'
*/
KEYMAP_ANSI(
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,7, 8, 9, TRNS,TRNS,TRNS,TRNS,TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,4, 5, 6, TRNS,TRNS,TRNS,TRNS, \
NO, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,1, 2, 3, TRNS,TRNS, TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,FN0, TRNS,TRNS,TRNS, TRNS,TRNS, \
TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, FN0, INS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,PAUS,TRNS,DEL, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,FN1, TRNS,TRNS,TRNS, PGUP,CAPS, \
TRNS,TRNS,TRNS, TRNS, TRNS,HOME,PGDN,END),
};

/*
* Fn action definition
*/
static const uint16_t PROGMEM fn_actions[] = {
[0] = ACTION_LAYER_DEFAULT,
[1] = ACTION_LAYER_SET_MOMENTARY(1),
[2] = ACTION_LAYER_SET_TOGGLE(2),
[0] = ACTION_LMOD_KEY(KC_LSFT, KC_GRV),
[1] = ACTION_LAYER_BIT_TOGGLE(1),
[2] = ACTION_LAYER_BIT_MOMENTARY(2),
};


Expand Down
18 changes: 18 additions & 0 deletions keyboard/mm60/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

void led_set(uint8_t usb_led)
{
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
// output low
DDRB |= (1<<6);
PORTB &= ~(1<<6);
} else {
// Hi-Z
DDRB &= ~(1<<6);
PORTB &= ~(1<<6);
}
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
// output low
DDRB |= (1<<5);
PORTB &= ~(1<<5);
} else {
// Hi-Z
DDRB &= ~(1<<5);
PORTB &= ~(1<<5);
}
}
69 changes: 37 additions & 32 deletions keyboard/mm60/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ void matrix_init(void)
debug_keyboard = true;
debug_matrix = true;

// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);

// initialize row and col
unselect_rows();
init_cols();
Expand Down Expand Up @@ -153,73 +157,74 @@ uint8_t matrix_key_count(void)

/* Column pin configuration
* col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
* pin: C6 C5 C4 C3 C2 C1 C0 E1 E0 D7 D5 D4 D3 D2 D1 D0
* pin: D0 D1 D2 D3 D4 D5 D7 E0 E1 C1 C2 C3 C4 C5 C6 --
*/
static void init_cols(void)
{
// Input with pull-up(DDR:0, PORT:1)
DDRC &= ~0b01111111;
PORTC |= 0b01111111;
DDRC &= ~0b01111110;
PORTC |= 0b01111110;
DDRD &= ~0b10111111;
PORTD |= 0b10111111;
DDRE &= ~0b00000011;
PORTE |= 0b00000011;
}

/* Column state(0:off, 1:on) */
static uint16_t read_cols(void)
{
return (PINC&(1<<6) ? 0 : (1<<0)) |
(PINC&(1<<5) ? 0 : (1<<1)) |
(PINC&(1<<4) ? 0 : (1<<2)) |
(PINC&(1<<3) ? 0 : (1<<3)) |
(PINC&(1<<2) ? 0 : (1<<4)) |
(PINC&(1<<1) ? 0 : (1<<5)) |
(PINC&(1<<0) ? 0 : (1<<6)) |
(PINE&(1<<1) ? 0 : (1<<7)) |
(PINE&(1<<0) ? 0 : (1<<8)) |
(PIND&(1<<7) ? 0 : (1<<9)) |
(PIND&(1<<5) ? 0 : (1<<10)) |
(PIND&(1<<4) ? 0 : (1<<11)) |
(PIND&(1<<3) ? 0 : (1<<12)) |
(PIND&(1<<2) ? 0 : (1<<13)) |
(PIND&(1<<1) ? 0 : (1<<14)) |
(PIND&(1<<0) ? 0 : (1<<15));
return (PIND&(1<<0) ? 0 : (1<<0)) |
(PIND&(1<<1) ? 0 : (1<<1)) |
(PIND&(1<<2) ? 0 : (1<<2)) |
(PIND&(1<<3) ? 0 : (1<<3)) |
(PIND&(1<<4) ? 0 : (1<<4)) |
(PIND&(1<<5) ? 0 : (1<<5)) |
(PIND&(1<<7) ? 0 : (1<<6)) |
(PINE&(1<<0) ? 0 : (1<<7)) |
(PINE&(1<<1) ? 0 : (1<<8)) |
(PINC&(1<<1) ? 0 : (1<<9)) |
(PINC&(1<<2) ? 0 : (1<<10)) |
(PINC&(1<<3) ? 0 : (1<<11)) |
(PINC&(1<<4) ? 0 : (1<<12)) |
(PINC&(1<<5) ? 0 : (1<<13)) |
(PINC&(1<<6) ? 0 : (1<<14)) |
((0<<15));
}

/* Row pin configuration
* row: 0 1 2 3 4
* pin: B4 B3 B2 B1 B0
* pin: F4 F3 F2 F1 F0
*/
static void unselect_rows(void)
{
// Hi-Z(DDR:0, PORT:0) to unselect
DDRB &= ~0b00011111;
PORTB &= ~0b00011111;
DDRF &= ~0b00011111;
PORTF &= ~0b00011111;
}

static void select_row(uint8_t row)
{
// Output low(DDR:1, PORT:0) to select
switch (row) {
case 0:
DDRB |= (1<<4);
PORTB &= ~(1<<4);
DDRF |= (1<<4);
PORTF &= ~(1<<4);
break;
case 1:
DDRB |= (1<<3);
PORTB &= ~(1<<3);
DDRF |= (1<<3);
PORTF &= ~(1<<3);
break;
case 2:
DDRB |= (1<<2);
PORTB &= ~(1<<2);
DDRF |= (1<<2);
PORTF &= ~(1<<2);
break;
case 3:
DDRB |= (1<<1);
PORTB &= ~(1<<1);
DDRF |= (1<<1);
PORTF &= ~(1<<1);
break;
case 4:
DDRB |= (1<<0);
PORTB &= ~(1<<0);
DDRF |= (1<<0);
PORTF &= ~(1<<0);
break;
}
}

0 comments on commit ec1c321

Please sign in to comment.