is31fl3731.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright 2017 Jason Williams
  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. #ifndef IS31FL3731_DRIVER_H
  17. #define IS31FL3731_DRIVER_H
  18. #include <stdint.h>
  19. #include <stdbool.h>
  20. typedef struct Point {
  21. uint8_t x;
  22. uint8_t y;
  23. } __attribute__((packed)) Point;
  24. typedef struct is31_led {
  25. uint8_t driver:2;
  26. uint8_t matrix:1;
  27. uint8_t modifier:1;
  28. uint8_t control_index;
  29. union {
  30. uint8_t raw;
  31. struct {
  32. uint8_t row:4; // 16 max
  33. uint8_t col:4; // 16 max
  34. };
  35. } matrix_co;
  36. Point point;
  37. } __attribute__((packed)) is31_led;
  38. extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
  39. void map_index_to_led( uint8_t index, is31_led *led );
  40. void IS31FL3731_init( uint8_t addr );
  41. void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data );
  42. void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer );
  43. void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
  44. void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
  45. void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue );
  46. // This should not be called from an interrupt
  47. // (eg. from a timer interrupt).
  48. // Call this while idle (in between matrix scans).
  49. // If the buffer is dirty, it will update the driver with the buffer.
  50. void IS31FL3731_update_pwm_buffers( uint8_t addr1, uint8_t addr2 );
  51. void IS31FL3731_update_led_control_registers( uint8_t addr1, uint8_t addr2 );
  52. #endif // IS31FL3731_DRIVER_H