is31fl3729-mono.h (7873B)
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(LED_MATRIX_IS31FL3729) 41 # define IS31FL3729_LED_COUNT LED_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 v; 57 } PACKED is31fl3729_led_t; 58 59 extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT]; 60 61 void is31fl3729_init_drivers(void); 62 void is31fl3729_init(uint8_t index); 63 void is31fl3729_write_register(uint8_t index, uint8_t reg, uint8_t data); 64 65 void is31fl3729_set_value(int index, uint8_t value); 66 void is31fl3729_set_value_all(uint8_t value); 67 68 void is31fl3729_set_scaling_register(uint8_t index, uint8_t value); 69 70 // This should not be called from an interrupt 71 // (eg. from a timer interrupt). 72 // Call this while idle (in between matrix scans). 73 // If the buffer is dirty, it will update the driver with the buffer. 74 void is31fl3729_update_pwm_buffers(uint8_t index); 75 void is31fl3729_update_scaling_registers(uint8_t index); 76 77 void is31fl3729_flush(void); 78 79 #define IS31FL3729_SW_PULLDOWN_0_OHM 0b000 80 #define IS31FL3729_SW_PULLDOWN_0K5_OHM_SW_OFF 0b001 81 #define IS31FL3729_SW_PULLDOWN_1K_OHM_SW_OFF 0b010 82 #define IS31FL3729_SW_PULLDOWN_2K_OHM_SW_OFF 0b011 83 #define IS31FL3729_SW_PULLDOWN_1K_OHM 0b100 84 #define IS31FL3729_SW_PULLDOWN_2K_OHM 0b101 85 #define IS31FL3729_SW_PULLDOWN_4K_OHM 0b110 86 #define IS31FL3729_SW_PULLDOWN_8K_OHM 0b111 87 88 #define IS31FL3729_CS_PULLUP_0_OHM 0b000 89 #define IS31FL3729_CS_PULLUP_0K5_OHM_CS_OFF 0b001 90 #define IS31FL3729_CS_PULLUP_1K_OHM_CS_OFF 0b010 91 #define IS31FL3729_CS_PULLUP_2K_OHM_CS_OFF 0b011 92 #define IS31FL3729_CS_PULLUP_1K_OHM 0b100 93 #define IS31FL3729_CS_PULLUP_2K_OHM 0b101 94 #define IS31FL3729_CS_PULLUP_4K_OHM 0b110 95 #define IS31FL3729_CS_PULLUP_8K_OHM 0b111 96 97 #define IS31FL3729_SPREAD_SPECTRUM_DISABLE 0b0 98 #define IS31FL3729_SPREAD_SPECTRUM_ENABLE 0b1 99 100 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_5_PERCENT 0b00 101 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_15_PERCENT 0b01 102 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_24_PERCENT 0b10 103 #define IS31FL3729_SPREAD_SPECTRUM_RANGE_34_PERCENT 0b11 104 105 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_1980_US 0b00 106 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_1200_US 0b01 107 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_820_US 0b10 108 #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_660_US 0b11 109 110 #define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000 111 #define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001 112 #define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010 113 #define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011 114 #define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100 115 #define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101 116 #define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110 117 #define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111 118 119 #define IS31FL3729_CONFIG_SWS_15_9 0x01 // 15 CS x 9 SW matrix 120 #define IS31FL3729_CONFIG_SWS_16_8 0x11 // 16 CS x 8 SW matrix 121 #define IS31FL3729_CONFIG_SWS_16_7 0x21 // 16 CS x 7 SW matrix 122 #define IS31FL3729_CONFIG_SWS_16_6 0x31 // 16 CS x 6 SW matrix 123 #define IS31FL3729_CONFIG_SWS_16_5 0x41 // 16 CS x 5 SW matrix 124 #define IS31FL3729_CONFIG_SWS_16_4 0x51 // 16 CS x 4 SW matrix 125 #define IS31FL3729_CONFIG_SWS_16_3 0x61 // 16 CS x 3 SW matrix 126 #define IS31FL3729_CONFIG_SWS_16_2 0x71 // 16 CS x 2 SW matrix 127 128 #define SW1_CS1 0x00 129 #define SW1_CS2 0x01 130 #define SW1_CS3 0x02 131 #define SW1_CS4 0x03 132 #define SW1_CS5 0x04 133 #define SW1_CS6 0x05 134 #define SW1_CS7 0x06 135 #define SW1_CS8 0x07 136 #define SW1_CS9 0x08 137 #define SW1_CS10 0x09 138 #define SW1_CS11 0x0A 139 #define SW1_CS12 0x0B 140 #define SW1_CS13 0x0C 141 #define SW1_CS14 0x0D 142 #define SW1_CS15 0x0E 143 #define SW1_CS16 0x0F 144 145 #define SW2_CS1 0x10 146 #define SW2_CS2 0x11 147 #define SW2_CS3 0x12 148 #define SW2_CS4 0x13 149 #define SW2_CS5 0x14 150 #define SW2_CS6 0x15 151 #define SW2_CS7 0x16 152 #define SW2_CS8 0x17 153 #define SW2_CS9 0x18 154 #define SW2_CS10 0x19 155 #define SW2_CS11 0x1A 156 #define SW2_CS12 0x1B 157 #define SW2_CS13 0x1C 158 #define SW2_CS14 0x1D 159 #define SW2_CS15 0x1E 160 #define SW2_CS16 0x1F 161 162 #define SW3_CS1 0x20 163 #define SW3_CS2 0x21 164 #define SW3_CS3 0x22 165 #define SW3_CS4 0x23 166 #define SW3_CS5 0x24 167 #define SW3_CS6 0x25 168 #define SW3_CS7 0x26 169 #define SW3_CS8 0x27 170 #define SW3_CS9 0x28 171 #define SW3_CS10 0x29 172 #define SW3_CS11 0x2A 173 #define SW3_CS12 0x2B 174 #define SW3_CS13 0x2C 175 #define SW3_CS14 0x2D 176 #define SW3_CS15 0x2E 177 #define SW3_CS16 0x2F 178 179 #define SW4_CS1 0x30 180 #define SW4_CS2 0x31 181 #define SW4_CS3 0x32 182 #define SW4_CS4 0x33 183 #define SW4_CS5 0x34 184 #define SW4_CS6 0x35 185 #define SW4_CS7 0x36 186 #define SW4_CS8 0x37 187 #define SW4_CS9 0x38 188 #define SW4_CS10 0x39 189 #define SW4_CS11 0x3A 190 #define SW4_CS12 0x3B 191 #define SW4_CS13 0x3C 192 #define SW4_CS14 0x3D 193 #define SW4_CS15 0x3E 194 #define SW4_CS16 0x3F 195 196 #define SW5_CS1 0x40 197 #define SW5_CS2 0x41 198 #define SW5_CS3 0x42 199 #define SW5_CS4 0x43 200 #define SW5_CS5 0x44 201 #define SW5_CS6 0x45 202 #define SW5_CS7 0x46 203 #define SW5_CS8 0x47 204 #define SW5_CS9 0x48 205 #define SW5_CS10 0x49 206 #define SW5_CS11 0x4A 207 #define SW5_CS12 0x4B 208 #define SW5_CS13 0x4C 209 #define SW5_CS14 0x4D 210 #define SW5_CS15 0x4E 211 #define SW5_CS16 0x4F 212 213 #define SW6_CS1 0x50 214 #define SW6_CS2 0x51 215 #define SW6_CS3 0x52 216 #define SW6_CS4 0x53 217 #define SW6_CS5 0x54 218 #define SW6_CS6 0x55 219 #define SW6_CS7 0x56 220 #define SW6_CS8 0x57 221 #define SW6_CS9 0x58 222 #define SW6_CS10 0x59 223 #define SW6_CS11 0x5A 224 #define SW6_CS12 0x5B 225 #define SW6_CS13 0x5C 226 #define SW6_CS14 0x5D 227 #define SW6_CS15 0x5E 228 #define SW6_CS16 0x5F 229 230 #define SW7_CS1 0x60 231 #define SW7_CS2 0x61 232 #define SW7_CS3 0x62 233 #define SW7_CS4 0x63 234 #define SW7_CS5 0x64 235 #define SW7_CS6 0x65 236 #define SW7_CS7 0x66 237 #define SW7_CS8 0x67 238 #define SW7_CS9 0x68 239 #define SW7_CS10 0x69 240 #define SW7_CS11 0x6A 241 #define SW7_CS12 0x6B 242 #define SW7_CS13 0x6C 243 #define SW7_CS14 0x6D 244 #define SW7_CS15 0x6E 245 #define SW7_CS16 0x6F 246 247 #define SW8_CS1 0x70 248 #define SW8_CS2 0x71 249 #define SW8_CS3 0x72 250 #define SW8_CS4 0x73 251 #define SW8_CS5 0x74 252 #define SW8_CS6 0x75 253 #define SW8_CS7 0x76 254 #define SW8_CS8 0x77 255 #define SW8_CS9 0x78 256 #define SW8_CS10 0x79 257 #define SW8_CS11 0x7A 258 #define SW8_CS12 0x7B 259 #define SW8_CS13 0x7C 260 #define SW8_CS14 0x7D 261 #define SW8_CS15 0x7E 262 #define SW8_CS16 0x7F 263 264 #define SW9_CS1 0x80 265 #define SW9_CS2 0x81 266 #define SW9_CS3 0x82 267 #define SW9_CS4 0x83 268 #define SW9_CS5 0x84 269 #define SW9_CS6 0x85 270 #define SW9_CS7 0x86 271 #define SW9_CS8 0x87 272 #define SW9_CS9 0x88 273 #define SW9_CS10 0x89 274 #define SW9_CS11 0x8A 275 #define SW9_CS12 0x8B 276 #define SW9_CS13 0x8C 277 #define SW9_CS14 0x8D 278 #define SW9_CS15 0x8E