aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ergodox_ez/ergodox_ez.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ergodox_ez/ergodox_ez.c')
-rw-r--r--keyboards/ergodox_ez/ergodox_ez.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c
new file mode 100644
index 000000000..3609f6f81
--- /dev/null
+++ b/keyboards/ergodox_ez/ergodox_ez.c
@@ -0,0 +1,136 @@
1#include QMK_KEYBOARD_H
2#include "i2cmaster.h"
3
4
5extern inline void ergodox_board_led_on(void);
6extern inline void ergodox_right_led_1_on(void);
7extern inline void ergodox_right_led_2_on(void);
8extern inline void ergodox_right_led_3_on(void);
9extern inline void ergodox_right_led_on(uint8_t led);
10
11extern inline void ergodox_board_led_off(void);
12extern inline void ergodox_right_led_1_off(void);
13extern inline void ergodox_right_led_2_off(void);
14extern inline void ergodox_right_led_3_off(void);
15extern inline void ergodox_right_led_off(uint8_t led);
16
17extern inline void ergodox_led_all_on(void);
18extern inline void ergodox_led_all_off(void);
19
20extern inline void ergodox_right_led_1_set(uint8_t n);
21extern inline void ergodox_right_led_2_set(uint8_t n);
22extern inline void ergodox_right_led_3_set(uint8_t n);
23extern inline void ergodox_right_led_set(uint8_t led, uint8_t n);
24
25extern inline void ergodox_led_all_set(uint8_t n);
26
27
28bool i2c_initialized = 0;
29uint8_t mcp23018_status = 0x20;
30
31void matrix_init_kb(void) {
32 // keyboard LEDs (see "PWM on ports OC1(A|B|C)" in "teensy-2-0.md")
33 TCCR1A = 0b10101001; // set and configure fast PWM
34 TCCR1B = 0b00001001; // set and configure fast PWM
35
36 // (tied to Vcc for hardware convenience)
37 DDRB &= ~(1<<4); // set B(4) as input
38 PORTB &= ~(1<<4); // set B(4) internal pull-up disabled
39
40 // unused pins - C7, D4, D5, D7, E6
41 // set as input with internal pull-ip enabled
42 DDRC &= ~(1<<7);
43 DDRD &= ~(1<<5 | 1<<4);
44 DDRE &= ~(1<<6);
45 PORTC |= (1<<7);
46 PORTD |= (1<<5 | 1<<4);
47 PORTE |= (1<<6);
48
49 ergodox_blink_all_leds();
50
51 matrix_init_user();
52}
53
54void ergodox_blink_all_leds(void)
55{
56 ergodox_led_all_off();
57 ergodox_led_all_set(LED_BRIGHTNESS_HI);
58 ergodox_right_led_1_on();
59 _delay_ms(50);
60 ergodox_right_led_2_on();
61 _delay_ms(50);
62 ergodox_right_led_3_on();
63 _delay_ms(50);
64 ergodox_right_led_1_off();
65 _delay_ms(50);
66 ergodox_right_led_2_off();
67 _delay_ms(50);
68 ergodox_right_led_3_off();
69 //ergodox_led_all_on();
70 //_delay_ms(333);
71 ergodox_led_all_off();
72}
73
74uint8_t init_mcp23018(void) {
75 mcp23018_status = 0x20;
76
77 // I2C subsystem
78
79 // uint8_t sreg_prev;
80 // sreg_prev=SREG;
81 // cli();
82 if (i2c_initialized == 0) {
83 i2c_init(); // on pins D(1,0)
84 i2c_initialized = true;
85 _delay_ms(1000);
86 }
87
88 // set pin direction
89 // - unused : input : 1
90 // - input : input : 1
91 // - driving : output : 0
92 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
93 mcp23018_status = i2c_write(IODIRA); if (mcp23018_status) goto out;
94 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
95 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
96 i2c_stop();
97
98 // set pull-up
99 // - unused : on : 1
100 // - input : on : 1
101 // - driving : off : 0
102 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
103 mcp23018_status = i2c_write(GPPUA); if (mcp23018_status) goto out;
104 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
105 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
106
107out:
108 i2c_stop();
109
110 // SREG=sreg_prev;
111
112 return mcp23018_status;
113}
114
115#ifdef ONEHAND_ENABLE
116__attribute__ ((weak))
117// swap-hands action needs a matrix to define the swap
118const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
119 /* Left hand, matrix positions */
120 {{0,13}, {1,13}, {2,13}, {3,13}, {4,13}, {5,13}},
121 {{0,12}, {1,12}, {2,12}, {3,12}, {4,12}, {5,12}},
122 {{0,11}, {1,11}, {2,11}, {3,11}, {4,11}, {5,11}},
123 {{0,10}, {1,10}, {2,10}, {3,10}, {4,10}, {5,10}},
124 {{0,9}, {1,9}, {2,9}, {3,9}, {4,9}, {5,9}},
125 {{0,8}, {1,8}, {2,8}, {3,8}, {4,8}, {5,8}},
126 {{0,7}, {1,7}, {2,7}, {3,7}, {4,7}, {5,7}},
127 /* Right hand, matrix positions */
128 {{0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}},
129 {{0,5}, {1,5}, {2,5}, {3,5}, {4,5}, {5,5}},
130 {{0,4}, {1,4}, {2,4}, {3,4}, {4,4}, {5,4}},
131 {{0,3}, {1,3}, {2,3}, {3,3}, {4,3}, {5,3}},
132 {{0,2}, {1,2}, {2,2}, {3,2}, {4,2}, {5,2}},
133 {{0,1}, {1,1}, {2,1}, {3,1}, {4,1}, {5,1}},
134 {{0,0}, {1,0}, {2,0}, {3,0}, {4,0}, {5,0}},
135};
136#endif