qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

ergodox_ez.h (4899B)


      1 /*
      2 Copyright 2012 Jun Wako <wakojun@gmail.com>
      3 Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com>
      4 Copyright 2015 ZSA Technology Labs Inc (@zsa)
      5 Copyright 2020 Christopher Courtney <drashna@live.com> (@drashna)
      6 
      7 This program is free software: you can redistribute it and/or modify
      8 it under the terms of the GNU General Public License as published by
      9 the Free Software Foundation, either version 2 of the License, or
     10 (at your option) any later version.
     11 
     12 This program is distributed in the hope that it will be useful,
     13 but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 GNU General Public License for more details.
     16 
     17 You should have received a copy of the GNU General Public License
     18 along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 */
     20 
     21 #pragma once
     22 
     23 #include "quantum.h"
     24 #include <stdint.h>
     25 #include <stdbool.h>
     26 #include "i2c_master.h"
     27 
     28 // I2C aliases and register addresses (see "mcp23018.md")
     29 #define I2C_ADDR        (0b0100000<<1)
     30 #define IODIRA          0x00            // i/o direction register
     31 #define IODIRB          0x01
     32 #define GPPUA           0x0C            // GPIO pull-up resistor register
     33 #define GPPUB           0x0D
     34 #define GPIOA           0x12            // general purpose i/o port register (write modifies OLAT)
     35 #define GPIOB           0x13
     36 #define OLATA           0x14            // output latch register
     37 #define OLATB           0x15
     38 
     39 extern i2c_status_t mcp23018_status;
     40 #define ERGODOX_EZ_I2C_TIMEOUT 100
     41 
     42 void init_ergodox(void);
     43 void ergodox_blink_all_leds(void);
     44 uint8_t init_mcp23018(void);
     45 uint8_t ergodox_left_leds_update(void);
     46 
     47 #ifndef LED_BRIGHTNESS_LO
     48 #define LED_BRIGHTNESS_LO       15
     49 #endif
     50 #ifndef LED_BRIGHTNESS_HI
     51 #define LED_BRIGHTNESS_HI       255
     52 #endif
     53 
     54 #define ERGODOX_EZ_BOARD_LED_PIN D6
     55 #define ERGODOX_EZ_RIGHT_LED_1_PIN B5
     56 #define ERGODOX_EZ_RIGHT_LED_2_PIN B6
     57 #define ERGODOX_EZ_RIGHT_LED_3_PIN B7
     58 
     59 inline void ergodox_board_led_on(void) {
     60     gpio_set_pin_output(ERGODOX_EZ_BOARD_LED_PIN);
     61     gpio_write_pin_high(ERGODOX_EZ_BOARD_LED_PIN);
     62 }
     63 inline void ergodox_right_led_1_on(void) {
     64     gpio_set_pin_output(ERGODOX_EZ_RIGHT_LED_1_PIN);
     65     gpio_write_pin_high(ERGODOX_EZ_RIGHT_LED_1_PIN);
     66 }
     67 inline void ergodox_right_led_2_on(void) {
     68     gpio_set_pin_output(ERGODOX_EZ_RIGHT_LED_2_PIN);
     69     gpio_write_pin_high(ERGODOX_EZ_RIGHT_LED_2_PIN);
     70 }
     71 inline void ergodox_right_led_3_on(void) {
     72     gpio_set_pin_output(ERGODOX_EZ_RIGHT_LED_3_PIN);
     73     gpio_write_pin_high(ERGODOX_EZ_RIGHT_LED_3_PIN);
     74 }
     75 
     76 inline void ergodox_board_led_off(void) {
     77     gpio_set_pin_input(ERGODOX_EZ_BOARD_LED_PIN);
     78 }
     79 inline void ergodox_right_led_1_off(void) {
     80     gpio_set_pin_input(ERGODOX_EZ_RIGHT_LED_1_PIN);
     81 }
     82 inline void ergodox_right_led_2_off(void) {
     83     gpio_set_pin_input(ERGODOX_EZ_RIGHT_LED_2_PIN);
     84 }
     85 inline void ergodox_right_led_3_off(void) {
     86     gpio_set_pin_input(ERGODOX_EZ_RIGHT_LED_3_PIN);
     87 }
     88 
     89 #ifdef LEFT_LEDS
     90 bool ergodox_left_led_1;
     91 bool ergodox_left_led_2;
     92 bool ergodox_left_led_3;
     93 
     94 inline void ergodox_left_led_1_on(void)    { ergodox_left_led_1 = 1; }
     95 inline void ergodox_left_led_2_on(void)    { ergodox_left_led_2 = 1; }
     96 inline void ergodox_left_led_3_on(void)    { ergodox_left_led_3 = 1; }
     97 
     98 inline void ergodox_left_led_1_off(void)    { ergodox_left_led_1 = 0; }
     99 inline void ergodox_left_led_2_off(void)    { ergodox_left_led_2 = 0; }
    100 inline void ergodox_left_led_3_off(void)    { ergodox_left_led_3 = 0; }
    101 #endif // LEFT_LEDS
    102 
    103 inline void ergodox_led_all_on(void) {
    104     ergodox_board_led_on();
    105     ergodox_right_led_1_on();
    106     ergodox_right_led_2_on();
    107     ergodox_right_led_3_on();
    108 #ifdef LEFT_LEDS
    109     ergodox_left_led_1_on();
    110     ergodox_left_led_2_on();
    111     ergodox_left_led_3_on();
    112 #endif // LEFT_LEDS
    113 }
    114 
    115 inline void ergodox_led_all_off(void)
    116 {
    117     ergodox_board_led_off();
    118     ergodox_right_led_1_off();
    119     ergodox_right_led_2_off();
    120     ergodox_right_led_3_off();
    121 #ifdef LEFT_LEDS
    122     ergodox_left_led_1_off();
    123     ergodox_left_led_2_off();
    124     ergodox_left_led_3_off();
    125 #endif // LEFT_LEDS
    126 }
    127 
    128 inline void ergodox_right_led_1_set(uint8_t n)    { OCR1A = n; }
    129 inline void ergodox_right_led_2_set(uint8_t n)    { OCR1B = n; }
    130 inline void ergodox_right_led_3_set(uint8_t n)    { OCR1C = n; }
    131 inline void ergodox_right_led_set(uint8_t led, uint8_t n)  {
    132     (led == 1) ? (OCR1A = n) :
    133     (led == 2) ? (OCR1B = n) :
    134                  (OCR1C = n);
    135 }
    136 
    137 inline void ergodox_led_all_set(uint8_t n) {
    138     ergodox_right_led_1_set(n);
    139     ergodox_right_led_2_set(n);
    140     ergodox_right_led_3_set(n);
    141 }
    142 
    143 enum ergodox_ez_keycodes {
    144     LED_LEVEL = QK_KB_0,
    145     TOGGLE_LAYER_COLOR,
    146 };
    147 
    148 #ifndef WEBUSB_ENABLE
    149 #    define WEBUSB_PAIR KC_NO
    150 #endif
    151 
    152 typedef union {
    153   uint32_t raw;
    154   struct {
    155     uint8_t    led_level :3;
    156     bool       disable_layer_led   :1;
    157     bool       rgb_matrix_enable   :1;
    158   };
    159 } keyboard_config_t;
    160 
    161 extern keyboard_config_t keyboard_config;