diff options
Diffstat (limited to 'keyboards/torn/torn.c')
| -rw-r--r-- | keyboards/torn/torn.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/keyboards/torn/torn.c b/keyboards/torn/torn.c new file mode 100644 index 000000000..ef5060e60 --- /dev/null +++ b/keyboards/torn/torn.c | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2020 Richard Titmuss <richard.titmuss@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 | #include "torn.h" | ||
| 18 | #include "i2c_master.h" | ||
| 19 | #include "mcp23018.h" | ||
| 20 | |||
| 21 | static uint8_t led_state[3] = {1, 1, 1}; | ||
| 22 | |||
| 23 | void matrix_init_kb(void) { | ||
| 24 | // put your keyboard start-up code here | ||
| 25 | // runs once when the firmware starts up | ||
| 26 | i2c_init(); | ||
| 27 | |||
| 28 | matrix_init_user(); | ||
| 29 | } | ||
| 30 | |||
| 31 | void matrix_scan_kb(void) { | ||
| 32 | // put your looping keyboard code here | ||
| 33 | // runs every cycle (a lot) | ||
| 34 | if (mcp23018_reset_required()) { | ||
| 35 | msp23018_init(); | ||
| 36 | secondary_encoder_init(); | ||
| 37 | // torn_set_led(2, 1); | ||
| 38 | } | ||
| 39 | |||
| 40 | matrix_scan_user(); | ||
| 41 | secondary_encoder_read(); | ||
| 42 | } | ||
| 43 | |||
| 44 | void torn_set_led(uint8_t led, bool state) { | ||
| 45 | led_state[led] = !state; | ||
| 46 | |||
| 47 | // toggle leds by setting the pin direction | ||
| 48 | uint8_t iodir = 0b11111000 | led_state[0] << 2 | led_state[1] << 1 | led_state[2]; | ||
| 49 | mcp23018_writeReg(IODIRB, &iodir, 1); | ||
| 50 | } | ||
