fc660c: Add unimap
[tmk_keyboard.git] / keyboard / fc660c / fc660c.h
1 #ifndef FC660C_H
2 #define FC660C_H
3
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <avr/io.h>
7 #include <avr/interrupt.h>
8 #include <util/delay.h>
9 #include "timer.h"
10 #include "unimap.h"
11
12
13 // Timer resolution check
14 #if (1000000/TIMER_RAW_FREQ > 20)
15 # error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB."
16 #endif
17
18
19 /*
20 * Pin configuration for ATMega32U4
21 *
22 * Row: PD4-6, 7(~EN)
23 * Col: PB0-2, 3(Z5 ~EN), 4(Z4 ~EN)
24 * Key: PC6(pull-uped)
25 * Hys: PC7
26 */
27 static inline void KEY_ENABLE(void) { (PORTD &= ~(1<<7)); }
28 static inline void KEY_UNABLE(void) { (PORTD |= (1<<7)); }
29 static inline bool KEY_STATE(void) { return (PINC & (1<<6)); }
30 static inline void KEY_HYS_ON(void) { (PORTC |= (1<<7)); }
31 static inline void KEY_HYS_OFF(void) { (PORTC &= ~(1<<7)); }
32 static inline void KEY_INIT(void)
33 {
34 /* Col */
35 DDRB |= 0x1F;
36 /* Key: input with pull-up */
37 DDRC &= ~(1<<6);
38 PORTC |= (1<<6);
39 /* Hys */
40 DDRC |= (1<<7);
41 /* Row */
42 DDRD |= 0xF0;
43
44 KEY_UNABLE();
45 KEY_HYS_OFF();
46 }
47 static inline void SET_ROW(uint8_t ROW)
48 {
49 // set row with unabling key
50 PORTD = (PORTD & 0x0F) | (1<<7) | ((ROW & 0x07) << 4);
51 }
52 static inline void SET_COL(uint8_t COL)
53 {
54 // |PB3(Z5 ~EN)|PB4(Z4 ~EN)
55 // --------|-----------|-----------
56 // Col:0-7 |high |low
57 // Col:8-F |low |high
58 PORTB = (PORTB & 0xE0) | ((COL & 0x08) ? 1<<4 : 1<<3) | (COL & 0x07);
59 }
60
61
62 #ifdef UNIMAP_ENABLE
63 /* unimap */
64 #define KMAP( \
65 K35,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K2D,K2E,K2A, K49, \
66 K2B,K14,K1A,K08,K15,K17,K1C,K18,K0C,K12,K13,K2F,K30,K31, K4C, \
67 K39,K04,K16,K07,K09,K0A,K0B,K0D,K0E,K0F,K33,K34, K28, \
68 K79,K1D,K1B,K06,K19,K05,K11,K10,K36,K37,K38, K7D,K52, \
69 K78,K7B,K7A, K2C, K7E,K7C,K7F,K50,K51,K4F \
70 ) UNIMAP( \
71 NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \
72 NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \
73 K35,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K2D,K2E,NO, K2A, K49,NO, NO, NO, NO, NO, NO, \
74 K2B,K14,K1A,K08,K15,K17,K1C,K18,K0C,K12,K13,K2F,K30, K31, K4C,NO, NO, NO, NO, NO, NO, \
75 K39,K04,K16,K07,K09,K0A,K0B,K0D,K0E,K0F,K33,K34, NO, K28, NO, NO, NO, NO, \
76 K79,NO, K1D,K1B,K06,K19,K05,K11,K10,K36,K37,K38, NO, K7D, K52, NO, NO, NO, NO, \
77 K78,K7B,K7A,NO, K2C, NO, NO, K7E,K7F,NO, K7C, K50,K51,K4F, NO, NO, NO \
78 )
79 #else
80 /* actionmap */
81 #define KMAP( \
82 K13, K10, K11, K12, K14, K16, K17, K15, K1B, K18, K19, K1A, K1C, K1E, K1F, \
83 K03, K00, K01, K02, K04, K06, K07, K05, K0B, K08, K09, K0A, K0C, K0E, K0F, \
84 K43, K40, K41, K42, K44, K46, K47, K45, K4B, K48, K49, K4A, K4E, \
85 K33, K31, K32, K34, K36, K37, K35, K3B, K38, K39, K3A, K3C, K3D, \
86 K23, K21, K22, K27, K28, K2A, K2C, K2E, K2D, K2F \
87 ) { \
88 { AC_##K00, AC_##K01, AC_##K02, AC_##K03, AC_##K04, AC_##K05, AC_##K06, AC_##K07, \
89 AC_##K08, AC_##K09, AC_##K0A, AC_##K0B, AC_##K0C, AC_NO, AC_##K0E, AC_##K0F }, \
90 { AC_##K10, AC_##K11, AC_##K12, AC_##K13, AC_##K14, AC_##K15, AC_##K16, AC_##K17, \
91 AC_##K18, AC_##K19, AC_##K1A, AC_##K1B, AC_##K1C, AC_NO, AC_##K1E, AC_##K1F }, \
92 { AC_NO, AC_##K21, AC_##K22, AC_##K23, AC_NO, AC_NO, AC_NO, AC_##K27, \
93 AC_##K28, AC_NO, AC_##K2A, AC_NO, AC_##K2C, AC_##K2D, AC_##K2E, AC_##K2F }, \
94 { AC_NO, AC_##K31, AC_##K32, AC_##K33, AC_##K34, AC_##K35, AC_##K36, AC_##K37, \
95 AC_##K38, AC_##K39, AC_##K3A, AC_##K3B, AC_##K3C, AC_##K3D, AC_NO, AC_NO }, \
96 { AC_##K40, AC_##K41, AC_##K42, AC_##K43, AC_##K44, AC_##K45, AC_##K46, AC_##K47, \
97 AC_##K48, AC_##K49, AC_##K4A, AC_##K4B, AC_NO, AC_NO, AC_##K4E, AC_NO }, \
98 { AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, \
99 AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO }, \
100 { AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, \
101 AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO }, \
102 { AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, \
103 AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO } \
104 }
105 #endif
106
107 #endif
Imprint / Impressum