diff options
Diffstat (limited to 'keyboards/meira/meira.c')
| -rw-r--r-- | keyboards/meira/meira.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/keyboards/meira/meira.c b/keyboards/meira/meira.c new file mode 100644 index 000000000..823415920 --- /dev/null +++ b/keyboards/meira/meira.c | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | /* Copyright 2017 REPLACE_WITH_YOUR_NAME | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include "meira.h" | ||
| 17 | #include "issi.h" | ||
| 18 | #include "TWIlib.h" | ||
| 19 | #include "lighting.h" | ||
| 20 | #include "quantum.h" | ||
| 21 | #define BACKLIGHT_BREATHING | ||
| 22 | |||
| 23 | #ifdef AUDIO_ENABLE | ||
| 24 | float tone_startup[][2] = SONG(STARTUP_SOUND); | ||
| 25 | float tone_goodbye[][2] = SONG(GOODBYE_SOUND); | ||
| 26 | #endif | ||
| 27 | |||
| 28 | |||
| 29 | void shutdown_user(void) { | ||
| 30 | #ifdef AUDIO_ENABLE | ||
| 31 | PLAY_NOTE_ARRAY(tone_goodbye, false, 0); | ||
| 32 | _delay_ms(150); | ||
| 33 | stop_all_notes(); | ||
| 34 | #endif | ||
| 35 | } | ||
| 36 | |||
| 37 | |||
| 38 | void matrix_init_kb(void) | ||
| 39 | { | ||
| 40 | debug_enable=true; | ||
| 41 | print("meira matrix_init_kb\n"); | ||
| 42 | #ifdef AUDIO_ENABLE | ||
| 43 | _delay_ms(20); // gets rid of tick | ||
| 44 | PLAY_NOTE_ARRAY(tone_startup, false, 0); | ||
| 45 | #endif | ||
| 46 | |||
| 47 | |||
| 48 | #ifdef ISSI_ENABLE | ||
| 49 | issi_init(); | ||
| 50 | #endif | ||
| 51 | backlight_set(5); | ||
| 52 | #ifdef WATCHDOG_ENABLE | ||
| 53 | // This is done after turning the layer LED red, if we're caught in a loop | ||
| 54 | // we should get a flashing red light | ||
| 55 | wdt_enable(WDTO_500MS); | ||
| 56 | #endif | ||
| 57 | |||
| 58 | |||
| 59 | // put your keyboard start-up code here | ||
| 60 | // runs once when the firmware starts up | ||
| 61 | matrix_init_user(); | ||
| 62 | } | ||
| 63 | |||
| 64 | void matrix_scan_kb(void) | ||
| 65 | { | ||
| 66 | #ifdef WATCHDOG_ENABLE | ||
| 67 | wdt_reset(); | ||
| 68 | #endif | ||
| 69 | #ifdef ISSI_ENABLE | ||
| 70 | // switch/underglow lighting update | ||
| 71 | static uint32_t issi_device = 0; | ||
| 72 | static uint32_t twi_last_ready = 0; | ||
| 73 | if(twi_last_ready > 1000){ | ||
| 74 | // Its been way too long since the last ISSI update, reset the I2C bus and start again | ||
| 75 | xprintf("TWI failed to recover, TWI re-init\n"); | ||
| 76 | twi_last_ready = 0; | ||
| 77 | TWIInit(); | ||
| 78 | force_issi_refresh(); | ||
| 79 | } | ||
| 80 | if(isTWIReady()){ | ||
| 81 | twi_last_ready = 0; | ||
| 82 | // If the i2c bus is available, kick off the issi update, alternate between devices | ||
| 83 | update_issi(issi_device, issi_device); | ||
| 84 | if(issi_device){ | ||
| 85 | issi_device = 0; | ||
| 86 | }else{ | ||
| 87 | issi_device = 3; | ||
| 88 | } | ||
| 89 | }else{ | ||
| 90 | twi_last_ready++; | ||
| 91 | } | ||
| 92 | #endif | ||
| 93 | matrix_scan_user(); | ||
| 94 | } | ||
| 95 | |||
| 96 | bool process_record_kb(uint16_t keycode, keyrecord_t *record) { | ||
| 97 | // Test code that turns on the switch led for the key that is pressed | ||
| 98 | // set_backlight_by_keymap(record->event.key.col, record->event.key.row); | ||
| 99 | if (keycode == RESET) { | ||
| 100 | reset_keyboard_kb(); | ||
| 101 | } else { | ||
| 102 | } | ||
| 103 | return process_record_user(keycode, record); | ||
| 104 | } | ||
| 105 | |||
| 106 | void led_set_kb(uint8_t usb_led) { | ||
| 107 | // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here | ||
| 108 | led_set_user(usb_led); | ||
| 109 | } | ||
| 110 | |||
| 111 | //void action_function(keyrecord_t *event, uint8_t id, uint8_t opt) | ||
| 112 | //{ | ||
| 113 | //#ifdef AUDIO_ENABLE | ||
| 114 | // int8_t sign = 1; | ||
| 115 | //#endif | ||
| 116 | // if(id == LFK_ESC_TILDE){ | ||
| 117 | // // Send ~ on shift-esc | ||
| 118 | // void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key; | ||
| 119 | // uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); | ||
| 120 | // method(shifted ? KC_GRAVE : KC_ESCAPE); | ||
| 121 | // send_keyboard_report(); | ||
| 122 | // }else if(event->event.pressed){ | ||
| 123 | // switch(id){ | ||
| 124 | // case LFK_CLEAR: | ||
| 125 | // // Go back to default layer | ||
| 126 | // layer_clear(); | ||
| 127 | // break; | ||
| 128 | //#ifdef ISSI_ENABLE | ||
| 129 | // case LFK_LED_TEST: | ||
| 130 | // led_test(); | ||
| 131 | // break; | ||
| 132 | //#endif | ||
| 133 | // } | ||
| 134 | // } | ||
| 135 | //} | ||
| 136 | |||
| 137 | void reset_keyboard_kb(){ | ||
| 138 | #ifdef WATCHDOG_ENABLE | ||
| 139 | MCUSR = 0; | ||
| 140 | wdt_disable(); | ||
| 141 | wdt_reset(); | ||
| 142 | #endif | ||
| 143 | xprintf("programming!\n"); | ||
| 144 | reset_keyboard(); | ||
| 145 | } | ||
