is31fl3731.h (6089B)
1 /* Copyright 2017 Jason Williams 2 * Copyright 2018 Jack Humbert 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 IS31FL3731_REG_COMMAND 0xFD 26 #define IS31FL3731_COMMAND_FRAME_1 0x00 27 #define IS31FL3731_COMMAND_FRAME_2 0x01 28 #define IS31FL3731_COMMAND_FRAME_3 0x02 29 #define IS31FL3731_COMMAND_FRAME_4 0x03 30 #define IS31FL3731_COMMAND_FRAME_5 0x04 31 #define IS31FL3731_COMMAND_FRAME_6 0x05 32 #define IS31FL3731_COMMAND_FRAME_7 0x06 33 #define IS31FL3731_COMMAND_FRAME_8 0x07 34 #define IS31FL3731_COMMAND_FUNCTION 0x0B 35 36 #define IS31FL3731_FRAME_REG_LED_CONTROL 0x00 37 #define IS31FL3731_FRAME_REG_BLINK_CONTROL 0x12 38 #define IS31FL3731_FRAME_REG_PWM 0x24 39 40 #define IS31FL3731_FUNCTION_REG_CONFIG 0x00 41 #define IS31FL3731_CONFIG_MODE_PICTURE 0x00 42 #define IS31FL3731_CONFIG_MODE_AUTO_PLAY 0x08 43 #define IS31FL3731_CONFIG_MODE_AUDIO_PLAY 0x18 44 45 #define IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY 0x01 46 #define IS31FL3731_FUNCTION_REG_AUDIO_SYNC 0x06 47 #define IS31FL3731_FUNCTION_REG_SHUTDOWN 0x0A 48 49 // Not defined in the datasheet -- See AN for IC 50 #define IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION 0xC2 51 #define IS31FL3731_GHOST_IMAGE_PREVENTION_GEN 0x10 52 53 #define IS31FL3731_I2C_ADDRESS_GND 0x74 54 #define IS31FL3731_I2C_ADDRESS_SCL 0x75 55 #define IS31FL3731_I2C_ADDRESS_SDA 0x76 56 #define IS31FL3731_I2C_ADDRESS_VCC 0x77 57 58 #if defined(RGB_MATRIX_IS31FL3731) 59 # define IS31FL3731_LED_COUNT RGB_MATRIX_LED_COUNT 60 #endif 61 62 #if defined(IS31FL3731_I2C_ADDRESS_4) 63 # define IS31FL3731_DRIVER_COUNT 4 64 #elif defined(IS31FL3731_I2C_ADDRESS_3) 65 # define IS31FL3731_DRIVER_COUNT 3 66 #elif defined(IS31FL3731_I2C_ADDRESS_2) 67 # define IS31FL3731_DRIVER_COUNT 2 68 #elif defined(IS31FL3731_I2C_ADDRESS_1) 69 # define IS31FL3731_DRIVER_COUNT 1 70 #endif 71 72 typedef struct is31fl3731_led_t { 73 uint8_t driver : 2; 74 uint8_t r; 75 uint8_t g; 76 uint8_t b; 77 } PACKED is31fl3731_led_t; 78 79 extern const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT]; 80 81 void is31fl3731_init_drivers(void); 82 void is31fl3731_init(uint8_t index); 83 void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data); 84 void is31fl3731_select_page(uint8_t index, uint8_t page); 85 86 void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); 87 void is31fl3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue); 88 89 void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue); 90 91 // This should not be called from an interrupt 92 // (eg. from a timer interrupt). 93 // Call this while idle (in between matrix scans). 94 // If the buffer is dirty, it will update the driver with the buffer. 95 void is31fl3731_update_pwm_buffers(uint8_t index); 96 void is31fl3731_update_led_control_registers(uint8_t index); 97 98 void is31fl3731_flush(void); 99 100 #define C1_1 0x00 101 #define C1_2 0x01 102 #define C1_3 0x02 103 #define C1_4 0x03 104 #define C1_5 0x04 105 #define C1_6 0x05 106 #define C1_7 0x06 107 #define C1_8 0x07 108 109 #define C1_9 0x08 110 #define C1_10 0x09 111 #define C1_11 0x0A 112 #define C1_12 0x0B 113 #define C1_13 0x0C 114 #define C1_14 0x0D 115 #define C1_15 0x0E 116 #define C1_16 0x0F 117 118 #define C2_1 0x10 119 #define C2_2 0x11 120 #define C2_3 0x12 121 #define C2_4 0x13 122 #define C2_5 0x14 123 #define C2_6 0x15 124 #define C2_7 0x16 125 #define C2_8 0x17 126 127 #define C2_9 0x18 128 #define C2_10 0x19 129 #define C2_11 0x1A 130 #define C2_12 0x1B 131 #define C2_13 0x1C 132 #define C2_14 0x1D 133 #define C2_15 0x1E 134 #define C2_16 0x1F 135 136 #define C3_1 0x20 137 #define C3_2 0x21 138 #define C3_3 0x22 139 #define C3_4 0x23 140 #define C3_5 0x24 141 #define C3_6 0x25 142 #define C3_7 0x26 143 #define C3_8 0x27 144 145 #define C3_9 0x28 146 #define C3_10 0x29 147 #define C3_11 0x2A 148 #define C3_12 0x2B 149 #define C3_13 0x2C 150 #define C3_14 0x2D 151 #define C3_15 0x2E 152 #define C3_16 0x2F 153 154 #define C4_1 0x30 155 #define C4_2 0x31 156 #define C4_3 0x32 157 #define C4_4 0x33 158 #define C4_5 0x34 159 #define C4_6 0x35 160 #define C4_7 0x36 161 #define C4_8 0x37 162 163 #define C4_9 0x38 164 #define C4_10 0x39 165 #define C4_11 0x3A 166 #define C4_12 0x3B 167 #define C4_13 0x3C 168 #define C4_14 0x3D 169 #define C4_15 0x3E 170 #define C4_16 0x3F 171 172 #define C5_1 0x40 173 #define C5_2 0x41 174 #define C5_3 0x42 175 #define C5_4 0x43 176 #define C5_5 0x44 177 #define C5_6 0x45 178 #define C5_7 0x46 179 #define C5_8 0x47 180 181 #define C5_9 0x48 182 #define C5_10 0x49 183 #define C5_11 0x4A 184 #define C5_12 0x4B 185 #define C5_13 0x4C 186 #define C5_14 0x4D 187 #define C5_15 0x4E 188 #define C5_16 0x4F 189 190 #define C6_1 0x50 191 #define C6_2 0x51 192 #define C6_3 0x52 193 #define C6_4 0x53 194 #define C6_5 0x54 195 #define C6_6 0x55 196 #define C6_7 0x56 197 #define C6_8 0x57 198 199 #define C6_9 0x58 200 #define C6_10 0x59 201 #define C6_11 0x5A 202 #define C6_12 0x5B 203 #define C6_13 0x5C 204 #define C6_14 0x5D 205 #define C6_15 0x5E 206 #define C6_16 0x5F 207 208 #define C7_1 0x60 209 #define C7_2 0x61 210 #define C7_3 0x62 211 #define C7_4 0x63 212 #define C7_5 0x64 213 #define C7_6 0x65 214 #define C7_7 0x66 215 #define C7_8 0x67 216 217 #define C7_9 0x68 218 #define C7_10 0x69 219 #define C7_11 0x6A 220 #define C7_12 0x6B 221 #define C7_13 0x6C 222 #define C7_14 0x6D 223 #define C7_15 0x6E 224 #define C7_16 0x6F 225 226 #define C8_1 0x70 227 #define C8_2 0x71 228 #define C8_3 0x72 229 #define C8_4 0x73 230 #define C8_5 0x74 231 #define C8_6 0x75 232 #define C8_7 0x76 233 #define C8_8 0x77 234 235 #define C8_9 0x78 236 #define C8_10 0x79 237 #define C8_11 0x7A 238 #define C8_12 0x7B 239 #define C8_13 0x7C 240 #define C8_14 0x7D 241 #define C8_15 0x7E 242 #define C8_16 0x7F 243 244 #define C9_1 0x80 245 #define C9_2 0x81 246 #define C9_3 0x82 247 #define C9_4 0x83 248 #define C9_5 0x84 249 #define C9_6 0x85 250 #define C9_7 0x86 251 #define C9_8 0x87 252 253 #define C9_9 0x88 254 #define C9_10 0x89 255 #define C9_11 0x8A 256 #define C9_12 0x8B 257 #define C9_13 0x8C 258 #define C9_14 0x8D 259 #define C9_15 0x8E 260 #define C9_16 0x8F