is31fl3736.h (6778B)
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(RGB_MATRIX_IS31FL3736) 62 # define IS31FL3736_LED_COUNT RGB_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 r; 78 uint8_t g; 79 uint8_t b; 80 } PACKED is31fl3736_led_t; 81 82 extern const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT]; 83 84 void is31fl3736_init_drivers(void); 85 void is31fl3736_init(uint8_t index); 86 void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data); 87 void is31fl3736_select_page(uint8_t index, uint8_t page); 88 89 void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); 90 void is31fl3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue); 91 92 void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue); 93 94 // This should not be called from an interrupt 95 // (eg. from a timer interrupt). 96 // Call this while idle (in between matrix scans). 97 // If the buffer is dirty, it will update the driver with the buffer. 98 void is31fl3736_update_pwm_buffers(uint8_t index); 99 void is31fl3736_update_led_control_registers(uint8_t index); 100 101 void is31fl3736_flush(void); 102 103 #define IS31FL3736_PDR_0_OHM 0b000 // No pull-down resistor 104 #define IS31FL3736_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor 105 #define IS31FL3736_PDR_1K_OHM 0b010 // 1 kOhm resistor 106 #define IS31FL3736_PDR_2K_OHM 0b011 // 2 kOhm resistor 107 #define IS31FL3736_PDR_4K_OHM 0b100 // 4 kOhm resistor 108 #define IS31FL3736_PDR_8K_OHM 0b101 // 8 kOhm resistor 109 #define IS31FL3736_PDR_16K_OHM 0b110 // 16 kOhm resistor 110 #define IS31FL3736_PDR_32K_OHM 0b111 // 32 kOhm resistor 111 112 #define IS31FL3736_PUR_0_OHM 0b000 // No pull-up resistor 113 #define IS31FL3736_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor 114 #define IS31FL3736_PUR_1K_OHM 0b010 // 1 kOhm resistor 115 #define IS31FL3736_PUR_2K_OHM 0b011 // 2 kOhm resistor 116 #define IS31FL3736_PUR_4K_OHM 0b100 // 4 kOhm resistor 117 #define IS31FL3736_PUR_8K_OHM 0b101 // 8 kOhm resistor 118 #define IS31FL3736_PUR_16K_OHM 0b110 // 16 kOhm resistor 119 #define IS31FL3736_PUR_32K_OHM 0b111 // 32 kOhm resistor 120 121 #define IS31FL3736_PWM_FREQUENCY_8K4_HZ 0b000 122 #define IS31FL3736_PWM_FREQUENCY_4K2_HZ 0b001 123 #define IS31FL3736_PWM_FREQUENCY_26K7_HZ 0b010 124 #define IS31FL3736_PWM_FREQUENCY_2K1_HZ 0b011 125 #define IS31FL3736_PWM_FREQUENCY_1K05_HZ 0b100 126 127 #define SW1_CS1 0x00 128 #define SW1_CS2 0x02 129 #define SW1_CS3 0x04 130 #define SW1_CS4 0x06 131 #define SW1_CS5 0x08 132 #define SW1_CS6 0x0A 133 #define SW1_CS7 0x0C 134 #define SW1_CS8 0x0E 135 136 #define SW2_CS1 0x10 137 #define SW2_CS2 0x12 138 #define SW2_CS3 0x14 139 #define SW2_CS4 0x16 140 #define SW2_CS5 0x18 141 #define SW2_CS6 0x1A 142 #define SW2_CS7 0x1C 143 #define SW2_CS8 0x1E 144 145 #define SW3_CS1 0x20 146 #define SW3_CS2 0x22 147 #define SW3_CS3 0x24 148 #define SW3_CS4 0x26 149 #define SW3_CS5 0x28 150 #define SW3_CS6 0x2A 151 #define SW3_CS7 0x2C 152 #define SW3_CS8 0x2E 153 154 #define SW4_CS1 0x30 155 #define SW4_CS2 0x32 156 #define SW4_CS3 0x34 157 #define SW4_CS4 0x36 158 #define SW4_CS5 0x38 159 #define SW4_CS6 0x3A 160 #define SW4_CS7 0x3C 161 #define SW4_CS8 0x3E 162 163 #define SW5_CS1 0x40 164 #define SW5_CS2 0x42 165 #define SW5_CS3 0x44 166 #define SW5_CS4 0x46 167 #define SW5_CS5 0x48 168 #define SW5_CS6 0x4A 169 #define SW5_CS7 0x4C 170 #define SW5_CS8 0x4E 171 172 #define SW6_CS1 0x50 173 #define SW6_CS2 0x52 174 #define SW6_CS3 0x54 175 #define SW6_CS4 0x56 176 #define SW6_CS5 0x58 177 #define SW6_CS6 0x5A 178 #define SW6_CS7 0x5C 179 #define SW6_CS8 0x5E 180 181 #define SW7_CS1 0x60 182 #define SW7_CS2 0x62 183 #define SW7_CS3 0x64 184 #define SW7_CS4 0x66 185 #define SW7_CS5 0x68 186 #define SW7_CS6 0x6A 187 #define SW7_CS7 0x6C 188 #define SW7_CS8 0x6E 189 190 #define SW8_CS1 0x70 191 #define SW8_CS2 0x72 192 #define SW8_CS3 0x74 193 #define SW8_CS4 0x76 194 #define SW8_CS5 0x78 195 #define SW8_CS6 0x7A 196 #define SW8_CS7 0x7C 197 #define SW8_CS8 0x7E 198 199 #define SW9_CS1 0x80 200 #define SW9_CS2 0x82 201 #define SW9_CS3 0x84 202 #define SW9_CS4 0x86 203 #define SW9_CS5 0x88 204 #define SW9_CS6 0x8A 205 #define SW9_CS7 0x8C 206 #define SW9_CS8 0x8E 207 208 #define SW10_CS1 0x90 209 #define SW10_CS2 0x92 210 #define SW10_CS3 0x94 211 #define SW10_CS4 0x96 212 #define SW10_CS5 0x98 213 #define SW10_CS6 0x9A 214 #define SW10_CS7 0x9C 215 #define SW10_CS8 0x9E 216 217 #define SW11_CS1 0xA0 218 #define SW11_CS2 0xA2 219 #define SW11_CS3 0xA4 220 #define SW11_CS4 0xA6 221 #define SW11_CS5 0xA8 222 #define SW11_CS6 0xAA 223 #define SW11_CS7 0xAC 224 #define SW11_CS8 0xAE 225 226 #define SW12_CS1 0xB0 227 #define SW12_CS2 0xB2 228 #define SW12_CS3 0xB4 229 #define SW12_CS4 0xB6 230 #define SW12_CS5 0xB8 231 #define SW12_CS6 0xBA 232 #define SW12_CS7 0xBC 233 #define SW12_CS8 0xBE