aw20216s.h (6944B)
1 /* Copyright 2021 Jasper Chan (Gigahawk) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #pragma once 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include "progmem.h" 22 #include "gpio.h" 23 #include "util.h" 24 25 #define AW20216S_ID (0b1010 << 4) 26 #define AW20216S_WRITE 0 27 #define AW20216S_READ 1 28 29 #define AW20216S_PAGE_FUNCTION (0x00 << 1) 30 #define AW20216S_PAGE_PWM (0x01 << 1) 31 #define AW20216S_PAGE_SCALING (0x02 << 1) 32 #define AW20216S_PAGE_PATTERN_CHOICE (0x03 << 1) 33 #define AW20216S_PAGE_PWM_SCALING (0x04 << 1) 34 35 #define AW20216S_FUNCTION_REG_CONFIGURATION 0x00 36 #define AW20216S_CONFIGURATION_SWSEL_1_12 (0b1011 << 4) 37 #define AW20216S_CONFIGURATION_CHIPEN (0b1 << 0) 38 39 #define AW20216S_FUNCTION_REG_GLOBAL_CURRENT 0x01 40 41 #define AW20216S_FUNCTION_REG_RESET 0x2F 42 #define AW20216S_RESET_MAGIC 0xAE 43 44 #define AW20216S_FUNCTION_REG_MIX_FUNCTION 0x46 45 #define AW20216S_MIX_FUNCTION_LPEN (0b1 << 1) 46 47 #if defined(RGB_MATRIX_AW20216S) 48 # define AW20216S_LED_COUNT RGB_MATRIX_LED_COUNT 49 #endif 50 51 #if defined(AW20216S_CS_PIN_2) 52 # define AW20216S_DRIVER_COUNT 2 53 #elif defined(AW20216S_CS_PIN_1) 54 # define AW20216S_DRIVER_COUNT 1 55 #endif 56 57 typedef struct aw20216s_led_t { 58 uint8_t driver : 2; 59 uint8_t r; 60 uint8_t g; 61 uint8_t b; 62 } PACKED aw20216s_led_t; 63 64 extern const aw20216s_led_t PROGMEM g_aw20216s_leds[AW20216S_LED_COUNT]; 65 66 void aw20216s_init_drivers(void); 67 void aw20216s_init(pin_t cs_pin); 68 void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); 69 void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue); 70 void aw20216s_update_pwm_buffers(pin_t cs_pin, uint8_t index); 71 72 void aw20216s_flush(void); 73 74 #define SW1_CS1 0x00 75 #define SW1_CS2 0x01 76 #define SW1_CS3 0x02 77 #define SW1_CS4 0x03 78 #define SW1_CS5 0x04 79 #define SW1_CS6 0x05 80 #define SW1_CS7 0x06 81 #define SW1_CS8 0x07 82 #define SW1_CS9 0x08 83 #define SW1_CS10 0x09 84 #define SW1_CS11 0x0A 85 #define SW1_CS12 0x0B 86 #define SW1_CS13 0x0C 87 #define SW1_CS14 0x0D 88 #define SW1_CS15 0x0E 89 #define SW1_CS16 0x0F 90 #define SW1_CS17 0x10 91 #define SW1_CS18 0x11 92 93 #define SW2_CS1 0x12 94 #define SW2_CS2 0x13 95 #define SW2_CS3 0x14 96 #define SW2_CS4 0x15 97 #define SW2_CS5 0x16 98 #define SW2_CS6 0x17 99 #define SW2_CS7 0x18 100 #define SW2_CS8 0x19 101 #define SW2_CS9 0x1A 102 #define SW2_CS10 0x1B 103 #define SW2_CS11 0x1C 104 #define SW2_CS12 0x1D 105 #define SW2_CS13 0x1E 106 #define SW2_CS14 0x1F 107 #define SW2_CS15 0x20 108 #define SW2_CS16 0x21 109 #define SW2_CS17 0x22 110 #define SW2_CS18 0x23 111 112 #define SW3_CS1 0x24 113 #define SW3_CS2 0x25 114 #define SW3_CS3 0x26 115 #define SW3_CS4 0x27 116 #define SW3_CS5 0x28 117 #define SW3_CS6 0x29 118 #define SW3_CS7 0x2A 119 #define SW3_CS8 0x2B 120 #define SW3_CS9 0x2C 121 #define SW3_CS10 0x2D 122 #define SW3_CS11 0x2E 123 #define SW3_CS12 0x2F 124 #define SW3_CS13 0x30 125 #define SW3_CS14 0x31 126 #define SW3_CS15 0x32 127 #define SW3_CS16 0x33 128 #define SW3_CS17 0x34 129 #define SW3_CS18 0x35 130 131 #define SW4_CS1 0x36 132 #define SW4_CS2 0x37 133 #define SW4_CS3 0x38 134 #define SW4_CS4 0x39 135 #define SW4_CS5 0x3A 136 #define SW4_CS6 0x3B 137 #define SW4_CS7 0x3C 138 #define SW4_CS8 0x3D 139 #define SW4_CS9 0x3E 140 #define SW4_CS10 0x3F 141 #define SW4_CS11 0x40 142 #define SW4_CS12 0x41 143 #define SW4_CS13 0x42 144 #define SW4_CS14 0x43 145 #define SW4_CS15 0x44 146 #define SW4_CS16 0x45 147 #define SW4_CS17 0x46 148 #define SW4_CS18 0x47 149 150 #define SW5_CS1 0x48 151 #define SW5_CS2 0x49 152 #define SW5_CS3 0x4A 153 #define SW5_CS4 0x4B 154 #define SW5_CS5 0x4C 155 #define SW5_CS6 0x4D 156 #define SW5_CS7 0x4E 157 #define SW5_CS8 0x4F 158 #define SW5_CS9 0x50 159 #define SW5_CS10 0x51 160 #define SW5_CS11 0x52 161 #define SW5_CS12 0x53 162 #define SW5_CS13 0x54 163 #define SW5_CS14 0x55 164 #define SW5_CS15 0x56 165 #define SW5_CS16 0x57 166 #define SW5_CS17 0x58 167 #define SW5_CS18 0x59 168 169 #define SW6_CS1 0x5A 170 #define SW6_CS2 0x5B 171 #define SW6_CS3 0x5C 172 #define SW6_CS4 0x5D 173 #define SW6_CS5 0x5E 174 #define SW6_CS6 0x5F 175 #define SW6_CS7 0x60 176 #define SW6_CS8 0x61 177 #define SW6_CS9 0x62 178 #define SW6_CS10 0x63 179 #define SW6_CS11 0x64 180 #define SW6_CS12 0x65 181 #define SW6_CS13 0x66 182 #define SW6_CS14 0x67 183 #define SW6_CS15 0x68 184 #define SW6_CS16 0x69 185 #define SW6_CS17 0x6A 186 #define SW6_CS18 0x6B 187 188 #define SW7_CS1 0x6C 189 #define SW7_CS2 0x6D 190 #define SW7_CS3 0x6E 191 #define SW7_CS4 0x6F 192 #define SW7_CS5 0x70 193 #define SW7_CS6 0x71 194 #define SW7_CS7 0x72 195 #define SW7_CS8 0x73 196 #define SW7_CS9 0x74 197 #define SW7_CS10 0x75 198 #define SW7_CS11 0x76 199 #define SW7_CS12 0x77 200 #define SW7_CS13 0x78 201 #define SW7_CS14 0x79 202 #define SW7_CS15 0x7A 203 #define SW7_CS16 0x7B 204 #define SW7_CS17 0x7C 205 #define SW7_CS18 0x7D 206 207 #define SW8_CS1 0x7E 208 #define SW8_CS2 0x7F 209 #define SW8_CS3 0x80 210 #define SW8_CS4 0x81 211 #define SW8_CS5 0x82 212 #define SW8_CS6 0x83 213 #define SW8_CS7 0x84 214 #define SW8_CS8 0x85 215 #define SW8_CS9 0x86 216 #define SW8_CS10 0x87 217 #define SW8_CS11 0x88 218 #define SW8_CS12 0x89 219 #define SW8_CS13 0x8A 220 #define SW8_CS14 0x8B 221 #define SW8_CS15 0x8C 222 #define SW8_CS16 0x8D 223 #define SW8_CS17 0x8E 224 #define SW8_CS18 0x8F 225 226 #define SW9_CS1 0x90 227 #define SW9_CS2 0x91 228 #define SW9_CS3 0x92 229 #define SW9_CS4 0x93 230 #define SW9_CS5 0x94 231 #define SW9_CS6 0x95 232 #define SW9_CS7 0x96 233 #define SW9_CS8 0x97 234 #define SW9_CS9 0x98 235 #define SW9_CS10 0x99 236 #define SW9_CS11 0x9A 237 #define SW9_CS12 0x9B 238 #define SW9_CS13 0x9C 239 #define SW9_CS14 0x9D 240 #define SW9_CS15 0x9E 241 #define SW9_CS16 0x9F 242 #define SW9_CS17 0xA0 243 #define SW9_CS18 0xA1 244 245 #define SW10_CS1 0xA2 246 #define SW10_CS2 0xA3 247 #define SW10_CS3 0xA4 248 #define SW10_CS4 0xA5 249 #define SW10_CS5 0xA6 250 #define SW10_CS6 0xA7 251 #define SW10_CS7 0xA8 252 #define SW10_CS8 0xA9 253 #define SW10_CS9 0xAA 254 #define SW10_CS10 0xAB 255 #define SW10_CS11 0xAC 256 #define SW10_CS12 0xAD 257 #define SW10_CS13 0xAE 258 #define SW10_CS14 0xAF 259 #define SW10_CS15 0xB0 260 #define SW10_CS16 0xB1 261 #define SW10_CS17 0xB2 262 #define SW10_CS18 0xB3 263 264 #define SW11_CS1 0xB4 265 #define SW11_CS2 0xB5 266 #define SW11_CS3 0xB6 267 #define SW11_CS4 0xB7 268 #define SW11_CS5 0xB8 269 #define SW11_CS6 0xB9 270 #define SW11_CS7 0xBA 271 #define SW11_CS8 0xBB 272 #define SW11_CS9 0xBC 273 #define SW11_CS10 0xBD 274 #define SW11_CS11 0xBE 275 #define SW11_CS12 0xBF 276 #define SW11_CS13 0xC0 277 #define SW11_CS14 0xC1 278 #define SW11_CS15 0xC2 279 #define SW11_CS16 0xC3 280 #define SW11_CS17 0xC4 281 #define SW11_CS18 0xC5 282 283 #define SW12_CS1 0xC6 284 #define SW12_CS2 0xC7 285 #define SW12_CS3 0xC8 286 #define SW12_CS4 0xC9 287 #define SW12_CS5 0xCA 288 #define SW12_CS6 0xCB 289 #define SW12_CS7 0xCC 290 #define SW12_CS8 0xCD 291 #define SW12_CS9 0xCE 292 #define SW12_CS10 0xCF 293 #define SW12_CS11 0xD0 294 #define SW12_CS12 0xD1 295 #define SW12_CS13 0xD2 296 #define SW12_CS14 0xD3 297 #define SW12_CS15 0xD4 298 #define SW12_CS16 0xD5 299 #define SW12_CS17 0xD6 300 #define SW12_CS18 0xD7