qmk_firmware

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

frenchdev.h (2692B)


      1 #pragma once
      2 
      3 #include "quantum.h"
      4 #include <stdint.h>
      5 #include <stdbool.h>
      6 #include "i2c_master.h"
      7 #include <util/delay.h>
      8 
      9 // I2C aliases and register addresses (see "mcp23018.md" on tmk repository)
     10 #define I2C_ADDR        (0b0100000<<1)
     11 #define IODIRA          0x00            // i/o direction register
     12 #define IODIRB          0x01
     13 #define GPPUA           0x0C            // GPIO pull-up resistor register
     14 #define GPPUB           0x0D
     15 #define GPIOA           0x12            // general purpose i/o port register (write modifies OLAT)
     16 #define GPIOB           0x13
     17 #define OLATA           0x14            // output latch register
     18 #define OLATB           0x15
     19 
     20 extern uint8_t mcp23018_status;
     21 #define I2C_TIMEOUT 100
     22 
     23 void init_frenchdev(void);
     24 void frenchdev_blink_all_leds(void);
     25 uint8_t init_mcp23018(void);
     26 
     27 #define LED_BRIGHTNESS_LO       15
     28 #define LED_BRIGHTNESS_HI       255
     29 
     30 #define FRENCHDEV_BOARD_LED_PIN D6
     31 #define FRENCHDEV_LED_1_PIN B5
     32 #define FRENCHDEV_LED_2_PIN B6
     33 #define FRENCHDEV_LED_3_PIN B7
     34 
     35 inline void frenchdev_board_led_on(void) {
     36     gpio_set_pin_output(FRENCHDEV_BOARD_LED_PIN);
     37     gpio_write_pin_high(FRENCHDEV_BOARD_LED_PIN);
     38 }
     39 inline void frenchdev_led_1_on(void) {
     40     gpio_set_pin_output(FRENCHDEV_LED_1_PIN);
     41     gpio_write_pin_high(FRENCHDEV_LED_1_PIN);
     42 }
     43 inline void frenchdev_led_2_on(void) {
     44     gpio_set_pin_output(FRENCHDEV_LED_2_PIN);
     45     gpio_write_pin_high(FRENCHDEV_LED_2_PIN);
     46 }
     47 inline void frenchdev_led_3_on(void) {
     48     gpio_set_pin_output(FRENCHDEV_LED_3_PIN);
     49     gpio_write_pin_high(FRENCHDEV_LED_3_PIN);
     50 }
     51 
     52 inline void frenchdev_board_led_off(void) {
     53     gpio_set_pin_input(FRENCHDEV_BOARD_LED_PIN);
     54 }
     55 inline void frenchdev_led_1_off(void) {
     56     gpio_set_pin_input(FRENCHDEV_LED_1_PIN);
     57 }
     58 inline void frenchdev_led_2_off(void) {
     59     gpio_set_pin_input(FRENCHDEV_LED_2_PIN);
     60 }
     61 inline void frenchdev_led_3_off(void) {
     62     gpio_set_pin_input(FRENCHDEV_LED_3_PIN);
     63 }
     64 
     65 inline void frenchdev_led_all_on(void)
     66 {
     67     frenchdev_board_led_on();
     68     frenchdev_led_1_on();
     69     frenchdev_led_2_on();
     70     frenchdev_led_3_on();
     71 }
     72 
     73 inline void frenchdev_led_all_off(void)
     74 {
     75     frenchdev_board_led_off();
     76     frenchdev_led_1_off();
     77     frenchdev_led_2_off();
     78     frenchdev_led_3_off();
     79 }
     80 
     81 inline void frenchdev_led_1_set(uint8_t n)    { OCR1A = n; }
     82 inline void frenchdev_led_2_set(uint8_t n)    { OCR1B = n; }
     83 inline void frenchdev_led_3_set(uint8_t n)    { OCR1C = n; }
     84 inline void frenchdev_led_set(uint8_t led, uint8_t n)  {
     85     (led == 1) ? (OCR1A = n) :
     86     (led == 2) ? (OCR1B = n) :
     87                  (OCR1C = n);
     88 }
     89 
     90 inline void frenchdev_led_all_set(uint8_t n)
     91 {
     92     frenchdev_led_1_set(n);
     93     frenchdev_led_2_set(n);
     94     frenchdev_led_3_set(n);
     95 }