qmk_firmware

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

is31fl3736-mono.h (6673B)


      1 /* Copyright 2018 Jason Williams (Wilba)
      2  * Copyright 2021 Doni Crosby
      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 #pragma once
     19 
     20 #include <stdint.h>
     21 #include <stdbool.h>
     22 #include "progmem.h"
     23 #include "util.h"
     24 
     25 #define IS31FL3736_REG_INTERRUPT_MASK 0xF0
     26 #define IS31FL3736_REG_INTERRUPT_STATUS 0xF1
     27 
     28 #define IS31FL3736_REG_COMMAND 0xFD
     29 
     30 #define IS31FL3736_COMMAND_LED_CONTROL 0x00
     31 #define IS31FL3736_COMMAND_PWM 0x01
     32 #define IS31FL3736_COMMAND_AUTO_BREATH 0x02
     33 #define IS31FL3736_COMMAND_FUNCTION 0x03
     34 
     35 #define IS31FL3736_FUNCTION_REG_CONFIGURATION 0x00
     36 #define IS31FL3736_FUNCTION_REG_GLOBAL_CURRENT 0x01
     37 #define IS31FL3736_FUNCTION_REG_SW_PULLUP 0x0F
     38 #define IS31FL3736_FUNCTION_REG_CS_PULLDOWN 0x10
     39 #define IS31FL3736_FUNCTION_REG_RESET 0x11
     40 
     41 #define IS31FL3736_REG_COMMAND_WRITE_LOCK 0xFE
     42 #define IS31FL3736_COMMAND_WRITE_LOCK_MAGIC 0xC5
     43 
     44 #define IS31FL3736_I2C_ADDRESS_GND_GND 0x50
     45 #define IS31FL3736_I2C_ADDRESS_GND_SCL 0x51
     46 #define IS31FL3736_I2C_ADDRESS_GND_SDA 0x52
     47 #define IS31FL3736_I2C_ADDRESS_GND_VCC 0x53
     48 #define IS31FL3736_I2C_ADDRESS_SCL_GND 0x54
     49 #define IS31FL3736_I2C_ADDRESS_SCL_SCL 0x55
     50 #define IS31FL3736_I2C_ADDRESS_SCL_SDA 0x56
     51 #define IS31FL3736_I2C_ADDRESS_SCL_VCC 0x57
     52 #define IS31FL3736_I2C_ADDRESS_SDA_GND 0x58
     53 #define IS31FL3736_I2C_ADDRESS_SDA_SCL 0x59
     54 #define IS31FL3736_I2C_ADDRESS_SDA_SDA 0x5A
     55 #define IS31FL3736_I2C_ADDRESS_SDA_VCC 0x5B
     56 #define IS31FL3736_I2C_ADDRESS_VCC_GND 0x5C
     57 #define IS31FL3736_I2C_ADDRESS_VCC_SCL 0x5D
     58 #define IS31FL3736_I2C_ADDRESS_VCC_SDA 0x5E
     59 #define IS31FL3736_I2C_ADDRESS_VCC_VCC 0x5F
     60 
     61 #if defined(LED_MATRIX_IS31FL3736)
     62 #    define IS31FL3736_LED_COUNT LED_MATRIX_LED_COUNT
     63 #endif
     64 
     65 #if defined(IS31FL3736_I2C_ADDRESS_4)
     66 #    define IS31FL3736_DRIVER_COUNT 4
     67 #elif defined(IS31FL3736_I2C_ADDRESS_3)
     68 #    define IS31FL3736_DRIVER_COUNT 3
     69 #elif defined(IS31FL3736_I2C_ADDRESS_2)
     70 #    define IS31FL3736_DRIVER_COUNT 2
     71 #elif defined(IS31FL3736_I2C_ADDRESS_1)
     72 #    define IS31FL3736_DRIVER_COUNT 1
     73 #endif
     74 
     75 typedef struct is31fl3736_led_t {
     76     uint8_t driver : 2;
     77     uint8_t v;
     78 } PACKED is31fl3736_led_t;
     79 
     80 extern const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT];
     81 
     82 void is31fl3736_init_drivers(void);
     83 void is31fl3736_init(uint8_t index);
     84 void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data);
     85 void is31fl3736_select_page(uint8_t index, uint8_t page);
     86 
     87 void is31fl3736_set_value(int index, uint8_t value);
     88 void is31fl3736_set_value_all(uint8_t value);
     89 
     90 void is31fl3736_set_led_control_register(uint8_t index, bool value);
     91 
     92 // This should not be called from an interrupt
     93 // (eg. from a timer interrupt).
     94 // Call this while idle (in between matrix scans).
     95 // If the buffer is dirty, it will update the driver with the buffer.
     96 void is31fl3736_update_pwm_buffers(uint8_t index);
     97 void is31fl3736_update_led_control_registers(uint8_t index);
     98 
     99 void is31fl3736_flush(void);
    100 
    101 #define IS31FL3736_PDR_0_OHM 0b000   // No pull-down resistor
    102 #define IS31FL3736_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor
    103 #define IS31FL3736_PDR_1K_OHM 0b010  // 1 kOhm resistor
    104 #define IS31FL3736_PDR_2K_OHM 0b011  // 2 kOhm resistor
    105 #define IS31FL3736_PDR_4K_OHM 0b100  // 4 kOhm resistor
    106 #define IS31FL3736_PDR_8K_OHM 0b101  // 8 kOhm resistor
    107 #define IS31FL3736_PDR_16K_OHM 0b110 // 16 kOhm resistor
    108 #define IS31FL3736_PDR_32K_OHM 0b111 // 32 kOhm resistor
    109 
    110 #define IS31FL3736_PUR_0_OHM 0b000   // No pull-up resistor
    111 #define IS31FL3736_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor
    112 #define IS31FL3736_PUR_1K_OHM 0b010  // 1 kOhm resistor
    113 #define IS31FL3736_PUR_2K_OHM 0b011  // 2 kOhm resistor
    114 #define IS31FL3736_PUR_4K_OHM 0b100  // 4 kOhm resistor
    115 #define IS31FL3736_PUR_8K_OHM 0b101  // 8 kOhm resistor
    116 #define IS31FL3736_PUR_16K_OHM 0b110 // 16 kOhm resistor
    117 #define IS31FL3736_PUR_32K_OHM 0b111 // 32 kOhm resistor
    118 
    119 #define IS31FL3736_PWM_FREQUENCY_8K4_HZ 0b000
    120 #define IS31FL3736_PWM_FREQUENCY_4K2_HZ 0b001
    121 #define IS31FL3736_PWM_FREQUENCY_26K7_HZ 0b010
    122 #define IS31FL3736_PWM_FREQUENCY_2K1_HZ 0b011
    123 #define IS31FL3736_PWM_FREQUENCY_1K05_HZ 0b100
    124 
    125 #define SW1_CS1 0x00
    126 #define SW1_CS2 0x02
    127 #define SW1_CS3 0x04
    128 #define SW1_CS4 0x06
    129 #define SW1_CS5 0x08
    130 #define SW1_CS6 0x0A
    131 #define SW1_CS7 0x0C
    132 #define SW1_CS8 0x0E
    133 
    134 #define SW2_CS1 0x10
    135 #define SW2_CS2 0x12
    136 #define SW2_CS3 0x14
    137 #define SW2_CS4 0x16
    138 #define SW2_CS5 0x18
    139 #define SW2_CS6 0x1A
    140 #define SW2_CS7 0x1C
    141 #define SW2_CS8 0x1E
    142 
    143 #define SW3_CS1 0x20
    144 #define SW3_CS2 0x22
    145 #define SW3_CS3 0x24
    146 #define SW3_CS4 0x26
    147 #define SW3_CS5 0x28
    148 #define SW3_CS6 0x2A
    149 #define SW3_CS7 0x2C
    150 #define SW3_CS8 0x2E
    151 
    152 #define SW4_CS1 0x30
    153 #define SW4_CS2 0x32
    154 #define SW4_CS3 0x34
    155 #define SW4_CS4 0x36
    156 #define SW4_CS5 0x38
    157 #define SW4_CS6 0x3A
    158 #define SW4_CS7 0x3C
    159 #define SW4_CS8 0x3E
    160 
    161 #define SW5_CS1 0x40
    162 #define SW5_CS2 0x42
    163 #define SW5_CS3 0x44
    164 #define SW5_CS4 0x46
    165 #define SW5_CS5 0x48
    166 #define SW5_CS6 0x4A
    167 #define SW5_CS7 0x4C
    168 #define SW5_CS8 0x4E
    169 
    170 #define SW6_CS1 0x50
    171 #define SW6_CS2 0x52
    172 #define SW6_CS3 0x54
    173 #define SW6_CS4 0x56
    174 #define SW6_CS5 0x58
    175 #define SW6_CS6 0x5A
    176 #define SW6_CS7 0x5C
    177 #define SW6_CS8 0x5E
    178 
    179 #define SW7_CS1 0x60
    180 #define SW7_CS2 0x62
    181 #define SW7_CS3 0x64
    182 #define SW7_CS4 0x66
    183 #define SW7_CS5 0x68
    184 #define SW7_CS6 0x6A
    185 #define SW7_CS7 0x6C
    186 #define SW7_CS8 0x6E
    187 
    188 #define SW8_CS1 0x70
    189 #define SW8_CS2 0x72
    190 #define SW8_CS3 0x74
    191 #define SW8_CS4 0x76
    192 #define SW8_CS5 0x78
    193 #define SW8_CS6 0x7A
    194 #define SW8_CS7 0x7C
    195 #define SW8_CS8 0x7E
    196 
    197 #define SW9_CS1 0x80
    198 #define SW9_CS2 0x82
    199 #define SW9_CS3 0x84
    200 #define SW9_CS4 0x86
    201 #define SW9_CS5 0x88
    202 #define SW9_CS6 0x8A
    203 #define SW9_CS7 0x8C
    204 #define SW9_CS8 0x8E
    205 
    206 #define SW10_CS1 0x90
    207 #define SW10_CS2 0x92
    208 #define SW10_CS3 0x94
    209 #define SW10_CS4 0x96
    210 #define SW10_CS5 0x98
    211 #define SW10_CS6 0x9A
    212 #define SW10_CS7 0x9C
    213 #define SW10_CS8 0x9E
    214 
    215 #define SW11_CS1 0xA0
    216 #define SW11_CS2 0xA2
    217 #define SW11_CS3 0xA4
    218 #define SW11_CS4 0xA6
    219 #define SW11_CS5 0xA8
    220 #define SW11_CS6 0xAA
    221 #define SW11_CS7 0xAC
    222 #define SW11_CS8 0xAE
    223 
    224 #define SW12_CS1 0xB0
    225 #define SW12_CS2 0xB2
    226 #define SW12_CS3 0xB4
    227 #define SW12_CS4 0xB6
    228 #define SW12_CS5 0xB8
    229 #define SW12_CS6 0xBA
    230 #define SW12_CS7 0xBC
    231 #define SW12_CS8 0xBE