]> git.gir.st - tmk_keyboard.git/blob - keyboard/ergodox/ergodox.h
remove experimental return, cleanup slash_question key
[tmk_keyboard.git] / keyboard / ergodox / ergodox.h
1 /*
2 Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18 Copyright (c) 2012, 2013 Ben Blazak <benblazak.dev@gmail.com>
19 Released under The MIT License (see "doc/licenses/MIT.md")
20 Project located at <https://github.com/benblazak/ergodox-firmware>
21
22 Most used files are located at
23 <https://github.com/benblazak/ergodox-firmware/tree/partial-rewrite/firmware/keyboard/ergodox/controller>
24
25 */
26
27 #include <stdint.h>
28 #include <stdbool.h>
29 #include <avr/io.h>
30 #include "i2cmaster.h"
31
32 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
33 #define CPU_16MHz 0x00
34
35 // I2C aliases and register addresses (see "mcp23018.md")
36 #define I2C_ADDR 0b0100000
37 #define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE )
38 #define I2C_ADDR_READ ( (I2C_ADDR<<1) | I2C_READ )
39 #define IODIRA 0x00 // i/o direction register
40 #define IODIRB 0x01
41 #define GPPUA 0x0C // GPIO pull-up resistor register
42 #define GPPUB 0x0D
43 #define GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
44 #define GPIOB 0x13
45 #define OLATA 0x14 // output latch register
46 #define OLATB 0x15
47
48 extern uint8_t mcp23018_status;
49
50 void init_ergodox(void);
51 void ergodox_blink_all_leds(void);
52 uint8_t init_mcp23018(void);
53 uint8_t ergodox_left_leds_update(void);
54
55 #define LED_BRIGHTNESS_LO 31
56 #define LED_BRIGHTNESS_HI 255
57
58 #define LEFT_LED_1_SHIFT 7 // in MCP23018 port B
59 #define LEFT_LED_2_SHIFT 6 // in MCP23018 port B
60 #define LEFT_LED_3_SHIFT 7 // in MCP23018 port A
61
62 extern bool ergodox_left_led_1; // left top
63 extern bool ergodox_left_led_2; // left middle
64 extern bool ergodox_left_led_3; // left bottom
65
66 inline void ergodox_board_led_on(void) { DDRD |= (1<<6); PORTD |= (1<<6); }
67 inline void ergodox_right_led_1_on(void) { DDRB |= (1<<5); PORTB |= (1<<5); }
68 inline void ergodox_right_led_2_on(void) { DDRB |= (1<<6); PORTB |= (1<<6); }
69 inline void ergodox_right_led_3_on(void) { DDRB |= (1<<7); PORTB |= (1<<7); }
70 inline void ergodox_left_led_1_on(void) { ergodox_left_led_1 = 1; }
71 inline void ergodox_left_led_2_on(void) { ergodox_left_led_2 = 1; }
72 inline void ergodox_left_led_3_on(void) { ergodox_left_led_3 = 1; }
73
74 inline void ergodox_board_led_off(void) { DDRD &= ~(1<<6); PORTD &= ~(1<<6); }
75 inline void ergodox_right_led_1_off(void) { DDRB &= ~(1<<5); PORTB &= ~(1<<5); }
76 inline void ergodox_right_led_2_off(void) { DDRB &= ~(1<<6); PORTB &= ~(1<<6); }
77 inline void ergodox_right_led_3_off(void) { DDRB &= ~(1<<7); PORTB &= ~(1<<7); }
78 inline void ergodox_left_led_1_off(void) { ergodox_left_led_1 = 0; }
79 inline void ergodox_left_led_2_off(void) { ergodox_left_led_2 = 0; }
80 inline void ergodox_left_led_3_off(void) { ergodox_left_led_3 = 0; }
81
82 inline void ergodox_led_all_on(void)
83 {
84 ergodox_board_led_on();
85 ergodox_right_led_1_on();
86 ergodox_right_led_2_on();
87 ergodox_right_led_3_on();
88 ergodox_left_led_1_on();
89 ergodox_left_led_2_on();
90 ergodox_left_led_3_on();
91 ergodox_left_leds_update();
92 }
93
94 inline void ergodox_led_all_off(void)
95 {
96 ergodox_board_led_off();
97 ergodox_right_led_1_off();
98 ergodox_right_led_2_off();
99 ergodox_right_led_3_off();
100 ergodox_left_led_1_off();
101 ergodox_left_led_2_off();
102 ergodox_left_led_3_off();
103 ergodox_left_leds_update();
104 }
105
106 inline void ergodox_right_led_1_set(uint8_t n) { OCR1A = n; }
107 inline void ergodox_right_led_2_set(uint8_t n) { OCR1B = n; }
108 inline void ergodox_right_led_3_set(uint8_t n) { OCR1C = n; }
109
110 inline void ergodox_led_all_set(uint8_t n)
111 {
112 ergodox_right_led_1_set(n);
113 ergodox_right_led_2_set(n);
114 ergodox_right_led_3_set(n);
115 }
116
Imprint / Impressum