fc980c: Add initial files
[tmk_keyboard.git] / keyboard / fc980c / fc980c.h
1 #ifndef FC980C_H
2 #define FC980C_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: PD5,6,PB0, PD4(~EN)
23 * Col: PB1-3, 4
24 * Key: PC6(pull-uped)
25 * Hys: PC7
26 */
27 static inline void KEY_ENABLE(void) { (PORTD &= ~(1<<4)); }
28 static inline void KEY_UNABLE(void) { (PORTD |= (1<<4)); }
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 |= 0x70;
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 PORTB = (PORTB & 0xFE) | ((ROW & 0x04) >> 2); // PB0
51 PORTD = (PORTD & 0x9F) | ((ROW & 0x03) << 5); // PD5,6
52 }
53 static inline void SET_COL(uint8_t COL)
54 {
55 // PB4(Lo:Z5, Hi:Z4)
56 // PB1-3
57 PORTB = (PORTB & 0xE1) | ((COL & 0x0F) << 1);
58 }
59
60
61 #ifdef UNIMAP_ENABLE
62 /* unimap */
63 #define KMAP( \
64 K29, K3A,K3B,K3C,K3D,K3E,K3F,K40,K41,K42,K43,K44,K45, K4C,K49,K4B,K4E, \
65 K35,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K2D,K2E,K2A, K53,K54,K55,K56, \
66 K2B,K14,K1A,K08,K15,K17,K1C,K18,K0C,K12,K13,K2F,K30,K31, K5F,K60,K61,K57, \
67 K39,K04,K16,K07,K09,K0A,K0B,K0D,K0E,K0F,K33,K34, K28, K5C,K5D,K5E, \
68 K79, K1D,K1B,K06,K19,K05,K11,K10,K36,K37,K38, K7D, K52, K59,K5A,K5B,K58, \
69 K78,K7B,K7A, K2C, K7E,K7C,K7F, K50,K51,K4F, K62,K63 \
70 ) UNIMAP( \
71 NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \
72 K29, K3A,K3B,K3C,K3D,K3E,K3F,K40,K41,K42,K43,K44,K45, NO, NO, NO, NO, NO, NO, \
73 K35,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K2D,K2E,NO, K2A, K49,NO, K4B, K53,K54,K55,K56, \
74 K2B,K14,K1A,K08,K15,K17,K1C,K18,K0C,K12,K13,K2F,K30, K31, K4C,NO, K4E, K5F,K60,K61,K57, \
75 K39,K04,K16,K07,K09,K0A,K0B,K0D,K0E,K0F,K33,K34, NO, K28, K5C,K5D,K5E,NO, \
76 K79,NO, K1D,K1B,K06,K19,K05,K11,K10,K36,K37,K38, NO, K7D, K52, K59,K5A,K5B,K58, \
77 K78,K7B,K7A,NO, K2C, NO, NO, K7E,K7F,NO, K7C, K50,K51,K4F, K62,K63,NO \
78 )
79 #else
80 /* actionmap */
81 /*
82 #define KMAP( \
83 K13, K10, K11, K12, K14, K16, K17, K15, K1B, K18, K19, K1A, K1C, K1E, K1F, \
84 K03, K00, K01, K02, K04, K06, K07, K05, K0B, K08, K09, K0A, K0C, K0E, K0F, \
85 K43, K40, K41, K42, K44, K46, K47, K45, K4B, K48, K49, K4A, K4E, \
86 K33, K31, K32, K34, K36, K37, K35, K3B, K38, K39, K3A, K3C, K3D, \
87 K23, K21, K22, K27, K28, K2A, K2C, K2E, K2D, K2F \
88 ) { \
89 { AC_##K00, AC_##K01, AC_##K02, AC_##K03, AC_##K04, AC_##K05, AC_##K06, AC_##K07, \
90 AC_##K08, AC_##K09, AC_##K0A, AC_##K0B, AC_##K0C, AC_NO, AC_##K0E, AC_##K0F }, \
91 { AC_##K10, AC_##K11, AC_##K12, AC_##K13, AC_##K14, AC_##K15, AC_##K16, AC_##K17, \
92 AC_##K18, AC_##K19, AC_##K1A, AC_##K1B, AC_##K1C, AC_NO, AC_##K1E, AC_##K1F }, \
93 { AC_NO, AC_##K21, AC_##K22, AC_##K23, AC_NO, AC_NO, AC_NO, AC_##K27, \
94 AC_##K28, AC_NO, AC_##K2A, AC_NO, AC_##K2C, AC_##K2D, AC_##K2E, AC_##K2F }, \
95 { AC_NO, AC_##K31, AC_##K32, AC_##K33, AC_##K34, AC_##K35, AC_##K36, AC_##K37, \
96 AC_##K38, AC_##K39, AC_##K3A, AC_##K3B, AC_##K3C, AC_##K3D, AC_NO, AC_NO }, \
97 { AC_##K40, AC_##K41, AC_##K42, AC_##K43, AC_##K44, AC_##K45, AC_##K46, AC_##K47, \
98 AC_##K48, AC_##K49, AC_##K4A, AC_##K4B, AC_NO, AC_NO, AC_##K4E, 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 AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO, AC_NO } \
105 }
106 */
107 #endif
108
109 #endif
Imprint / Impressum