is31fl3729.h (7984B)
1 /* Copyright 2024 HorrorTroll <https://github.com/HorrorTroll> 2 * Copyright 2024 Harrison Chan (Xelus) 3 * Copyright 2024 Dimitris Mantzouranis <d3xter93@gmail.com> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #pragma once 20 21 #include <stdint.h> 22 #include <stdbool.h> 23 #include "progmem.h" 24 #include "util.h" 25 26 #define IS31FL3729_REG_PWM 0x01 27 #define IS31FL3729_REG_SCALING 0x90 28 #define IS31FL3729_REG_CONFIGURATION 0xA0 29 #define IS31FL3729_REG_GLOBAL_CURRENT 0xA1 30 #define IS31FL3729_REG_PULLDOWNUP 0xB0 31 #define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1 32 #define IS31FL3729_REG_PWM_FREQUENCY 0xB2 33 #define IS31FL3729_REG_RESET 0xCF 34 35 #define IS31FL3729_I2C_ADDRESS_GND 0x34 36 #define IS31FL3729_I2C_ADDRESS_SCL 0x35 37 #define IS31FL3729_I2C_ADDRESS_SDA 0x36 38 #define IS31FL3729_I2C_ADDRESS_VCC 0x37 39 40 #if defined(RGB_MATRIX_IS31FL3729) 41 # define IS31FL3729_LED_COUNT RGB_MATRIX_LED_COUNT 42 #endif 43 44 #if defined(IS31FL3729_I2C_ADDRESS_4) 45 # define IS31FL3729_DRIVER_COUNT 4 46 #elif defined(IS31FL3729_I2C_ADDRESS_3) 47 # define IS31FL3729_DRIVER_COUNT 3 48 #elif defined(IS31FL3729_I2C_ADDRESS_2) 49 # define IS31FL3729_DRIVER_COUNT 2 50 #elif defined(IS31FL3729_I2C_ADDRESS_1) 51 # define IS31FL3729_DRIVER_COUNT 1 52 #endif 53 54 typedef struct is31fl3729_led_t { 55 uint8_t driver : 2; 56 uint8_t r; 57 uint8_t g; 58 uint8_t b; 59 } PACKED is31fl3729_led_t; 60 61 extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; 62 63 void is31fl3729_init_drivers(void); 64 void is31fl3729_init(uint8_t index); 65 void is31fl3729_write_register(uint8_t index, uint8_t reg, uint8_t data); 66 67 void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); 68 void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue); 69 70 void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue); 71 72 // This should not be called from an interrupt 73 // (eg. from a timer interrupt). 74 // Call this while idle (in between matrix scans). 75 // If the buffer is dirty, it will update the driver with the buffer. 76 void is31fl3729_update_pwm_buffers(uint8_t index); 77 void is31fl3729_update_scaling_registers(uint8_t index); 78 79 void is31fl3729_flush(void); 80 81 #define IS31FL3729_SW_PULLDOWN_0_OHM 0b000 82 #define IS31FL3729_SW_PULLDOWN_0K5_OHM_SW_OFF 0b001 83 #define IS31FL3729_SW_PULLDOWN_1K_OHM_SW_OFF 0b010 84 #define IS31FL3729_SW_PULLDOWN_2K_OHM_SW_OFF 0b011 85 #define IS31FL3729_SW_PULLDOWN_1K_OHM 0b100 86 #define IS31FL3729_SW_PULLDOWN_2K_OHM 0b101 87 #define IS31FL3729_SW_PULLDOWN_4K_OHM 0b110 88 #define IS31FL3729_SW_PULLDOWN_8K_OHM 0b111 89 90 #define IS31FL3729_CS_PULLUP_0_OHM 0b000 91 #define IS31FL3729_CS_PULLUP_0K5_OHM_CS_OFF 0b001 92 #define IS31FL3729_CS_PULLUP_1K_OHM_CS_OFF 0b010 93 #define IS31FL3729_CS_PULLUP_2K_OHM_CS_OFF 0b011 94 #define IS31FL3729_CS_PULLUP_1K_OHM 0b100 95 #define IS31FL3729_CS_PULLUP_2K_OHM 0b101 96 #define IS31FL3729_CS_PULLUP_4K_OHM 0b110 97 #define IS31FL3729_CS_PULLUP_8K_OHM 0b111 98 99 #define IS31FL3729_SPREAD_SPECTRUM_DISABLE 0b0 100 #define IS31FL3729_SPREAD_SPECTRUM_ENABLE 0b1 101 102 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_5_PERCENT 0b00 103 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_15_PERCENT 0b01 104 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_24_PERCENT 0b10 105 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_34_PERCENT 0b11 106 107 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_1980_US 0b00 108 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_1200_US 0b01 109 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_820_US 0b10 110 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_660_US 0b11 111 112 #define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 113 #define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 114 #define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 115 #define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 116 #define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 117 #define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 118 #define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 119 #define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 120 121 #define IS31FL3729_CONFIG_SWS_15_9 0x01 // 15 CS x 9 SW matrix 122 #define IS31FL3729_CONFIG_SWS_16_8 0x11 // 16 CS x 8 SW matrix 123 #define IS31FL3729_CONFIG_SWS_16_7 0x21 // 16 CS x 7 SW matrix 124 #define IS31FL3729_CONFIG_SWS_16_6 0x31 // 16 CS x 6 SW matrix 125 #define IS31FL3729_CONFIG_SWS_16_5 0x41 // 16 CS x 5 SW matrix 126 #define IS31FL3729_CONFIG_SWS_16_4 0x51 // 16 CS x 4 SW matrix 127 #define IS31FL3729_CONFIG_SWS_16_3 0x61 // 16 CS x 3 SW matrix 128 #define IS31FL3729_CONFIG_SWS_16_2 0x71 // 16 CS x 2 SW matrix 129 130 #define SW1_CS1 0x00 131 #define SW1_CS2 0x01 132 #define SW1_CS3 0x02 133 #define SW1_CS4 0x03 134 #define SW1_CS5 0x04 135 #define SW1_CS6 0x05 136 #define SW1_CS7 0x06 137 #define SW1_CS8 0x07 138 #define SW1_CS9 0x08 139 #define SW1_CS10 0x09 140 #define SW1_CS11 0x0A 141 #define SW1_CS12 0x0B 142 #define SW1_CS13 0x0C 143 #define SW1_CS14 0x0D 144 #define SW1_CS15 0x0E 145 #define SW1_CS16 0x0F 146 147 #define SW2_CS1 0x10 148 #define SW2_CS2 0x11 149 #define SW2_CS3 0x12 150 #define SW2_CS4 0x13 151 #define SW2_CS5 0x14 152 #define SW2_CS6 0x15 153 #define SW2_CS7 0x16 154 #define SW2_CS8 0x17 155 #define SW2_CS9 0x18 156 #define SW2_CS10 0x19 157 #define SW2_CS11 0x1A 158 #define SW2_CS12 0x1B 159 #define SW2_CS13 0x1C 160 #define SW2_CS14 0x1D 161 #define SW2_CS15 0x1E 162 #define SW2_CS16 0x1F 163 164 #define SW3_CS1 0x20 165 #define SW3_CS2 0x21 166 #define SW3_CS3 0x22 167 #define SW3_CS4 0x23 168 #define SW3_CS5 0x24 169 #define SW3_CS6 0x25 170 #define SW3_CS7 0x26 171 #define SW3_CS8 0x27 172 #define SW3_CS9 0x28 173 #define SW3_CS10 0x29 174 #define SW3_CS11 0x2A 175 #define SW3_CS12 0x2B 176 #define SW3_CS13 0x2C 177 #define SW3_CS14 0x2D 178 #define SW3_CS15 0x2E 179 #define SW3_CS16 0x2F 180 181 #define SW4_CS1 0x30 182 #define SW4_CS2 0x31 183 #define SW4_CS3 0x32 184 #define SW4_CS4 0x33 185 #define SW4_CS5 0x34 186 #define SW4_CS6 0x35 187 #define SW4_CS7 0x36 188 #define SW4_CS8 0x37 189 #define SW4_CS9 0x38 190 #define SW4_CS10 0x39 191 #define SW4_CS11 0x3A 192 #define SW4_CS12 0x3B 193 #define SW4_CS13 0x3C 194 #define SW4_CS14 0x3D 195 #define SW4_CS15 0x3E 196 #define SW4_CS16 0x3F 197 198 #define SW5_CS1 0x40 199 #define SW5_CS2 0x41 200 #define SW5_CS3 0x42 201 #define SW5_CS4 0x43 202 #define SW5_CS5 0x44 203 #define SW5_CS6 0x45 204 #define SW5_CS7 0x46 205 #define SW5_CS8 0x47 206 #define SW5_CS9 0x48 207 #define SW5_CS10 0x49 208 #define SW5_CS11 0x4A 209 #define SW5_CS12 0x4B 210 #define SW5_CS13 0x4C 211 #define SW5_CS14 0x4D 212 #define SW5_CS15 0x4E 213 #define SW5_CS16 0x4F 214 215 #define SW6_CS1 0x50 216 #define SW6_CS2 0x51 217 #define SW6_CS3 0x52 218 #define SW6_CS4 0x53 219 #define SW6_CS5 0x54 220 #define SW6_CS6 0x55 221 #define SW6_CS7 0x56 222 #define SW6_CS8 0x57 223 #define SW6_CS9 0x58 224 #define SW6_CS10 0x59 225 #define SW6_CS11 0x5A 226 #define SW6_CS12 0x5B 227 #define SW6_CS13 0x5C 228 #define SW6_CS14 0x5D 229 #define SW6_CS15 0x5E 230 #define SW6_CS16 0x5F 231 232 #define SW7_CS1 0x60 233 #define SW7_CS2 0x61 234 #define SW7_CS3 0x62 235 #define SW7_CS4 0x63 236 #define SW7_CS5 0x64 237 #define SW7_CS6 0x65 238 #define SW7_CS7 0x66 239 #define SW7_CS8 0x67 240 #define SW7_CS9 0x68 241 #define SW7_CS10 0x69 242 #define SW7_CS11 0x6A 243 #define SW7_CS12 0x6B 244 #define SW7_CS13 0x6C 245 #define SW7_CS14 0x6D 246 #define SW7_CS15 0x6E 247 #define SW7_CS16 0x6F 248 249 #define SW8_CS1 0x70 250 #define SW8_CS2 0x71 251 #define SW8_CS3 0x72 252 #define SW8_CS4 0x73 253 #define SW8_CS5 0x74 254 #define SW8_CS6 0x75 255 #define SW8_CS7 0x76 256 #define SW8_CS8 0x77 257 #define SW8_CS9 0x78 258 #define SW8_CS10 0x79 259 #define SW8_CS11 0x7A 260 #define SW8_CS12 0x7B 261 #define SW8_CS13 0x7C 262 #define SW8_CS14 0x7D 263 #define SW8_CS15 0x7E 264 #define SW8_CS16 0x7F 265 266 #define SW9_CS1 0x80 267 #define SW9_CS2 0x81 268 #define SW9_CS3 0x82 269 #define SW9_CS4 0x83 270 #define SW9_CS5 0x84 271 #define SW9_CS6 0x85 272 #define SW9_CS7 0x86 273 #define SW9_CS8 0x87 274 #define SW9_CS9 0x88 275 #define SW9_CS10 0x89 276 #define SW9_CS11 0x8A 277 #define SW9_CS12 0x8B 278 #define SW9_CS13 0x8C 279 #define SW9_CS14 0x8D 280 #define SW9_CS15 0x8E