You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /* Copyright 2017 Jason Williams
  2. * Copyright 2018 Jack Humbert
  3. * Copyright 2019 Clueboard
  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. #ifndef IS31FL3235A_DRIVER_H
  19. #define IS31FL3235A_DRIVER_H
  20. // This is a 7-bit address, that gets left-shifted and bit 0
  21. // set to 0 for write, 1 for read (as per I2C protocol)
  22. // The address will vary depending on your wiring:
  23. // 0b0111111 AD <-> VCC
  24. // 0b0111110 AD <-> SDA
  25. // 0b0111101 AD <-> SCL
  26. // 0b0111100 AD <-> GND
  27. #ifndef IS31FL3235A_COUNT
  28. #define IS31FL3235A_COUNT 1
  29. #endif
  30. #ifndef IS31FL3235A_DRIVER_ADDR_1
  31. #define IS31FL3235A_DRIVER_ADDR_1 0b0111111
  32. //#define IS31FL3235A_DRIVER_ADDR_1 0x7E
  33. #endif
  34. #ifndef IS31FL3235A_DRIVER_ADDR_2
  35. #define IS31FL3235A_DRIVER_ADDR_2 0b0111110
  36. #endif
  37. #ifndef IS31FL3235A_DRIVER_ADDR_3
  38. #define IS31FL3235A_DRIVER_ADDR_3 0b0111101
  39. #endif
  40. #ifndef IS31FL3235A_DRIVER_ADDR_4
  41. #define IS31FL3235A_DRIVER_ADDR_4 0b0111100
  42. #endif
  43. // This is the max number of LEDs this driver supports per IC
  44. #define IS31FL3235A_LED_MAX 28
  45. #ifndef IS31FL3235A_LED_COUNT
  46. #define IS31FL3235A_LED_COUNT IS31FL3235A_LED_MAX
  47. #endif
  48. // Registers we will need to write to
  49. #define ISSI_REG_SHUTDOWN 0x00 // Control the software shutdown state of the controller
  50. #define ISSI_REG_GLOBAL_CONTROL 0x4A // Write 0 for normal operation, 1 to shutdown all LEDs
  51. #define ISSI_REG_OUTPUT_FREQ 0x4B // Write 0 for 3kHz PWM, 1 for 22kHz
  52. #define ISSI_REG_RESET_REG 0x4F // Write 0 to reset all registers to default value
  53. void IS31FL3235A_init(uint8_t addr);
  54. void IS31FL3235A_write_register(uint8_t addr, uint8_t reg, uint8_t data);
  55. void IS31FL3235A_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
  56. void IS31FL3235A_set_value(int index, uint8_t value);
  57. void IS31FL3235A_set_value_all(uint8_t value);
  58. void IS31FL3235A_set_led_control_register(uint8_t index, bool value);
  59. // This should not be called from an interrupt
  60. // (eg. from a timer interrupt).
  61. // Call this while idle (in between matrix scans).
  62. // If the buffer is dirty, it will update the driver with the buffer.
  63. void IS31FL3235A_update_pwm_buffers(uint8_t addr, uint8_t index);
  64. void IS31FL3235A_update_led_control_registers(uint8_t addr, uint8_t index);
  65. // The address for each LED in the is31fl3235a's Control Register
  66. enum control_register {
  67. CR_OUT1 = 0x2A,
  68. CR_OUT2,
  69. CR_OUT3,
  70. CR_OUT4,
  71. CR_OUT5,
  72. CR_OUT6,
  73. CR_OUT7,
  74. CR_OUT8,
  75. CR_OUT9,
  76. CR_OUT10,
  77. CR_OUT11,
  78. CR_OUT12,
  79. CR_OUT13,
  80. CR_OUT14,
  81. CR_OUT15,
  82. CR_OUT16,
  83. CR_OUT17,
  84. CR_OUT18,
  85. CR_OUT19,
  86. CR_OUT20,
  87. CR_OUT21,
  88. CR_OUT22,
  89. CR_OUT23,
  90. CR_OUT24,
  91. CR_OUT25,
  92. CR_OUT26,
  93. CR_OUT27,
  94. CR_OUT28
  95. };
  96. // The address for each LED in the is31fl3235a's PWM Register
  97. enum pwm_register {
  98. OUT1 = 0x05,
  99. OUT2,
  100. OUT3,
  101. OUT4,
  102. OUT5,
  103. OUT6,
  104. OUT7,
  105. OUT8,
  106. OUT9,
  107. OUT10,
  108. OUT11,
  109. OUT12,
  110. OUT13,
  111. OUT14,
  112. OUT15,
  113. OUT16,
  114. OUT17,
  115. OUT18,
  116. OUT19,
  117. OUT20,
  118. OUT21,
  119. OUT22,
  120. OUT23,
  121. OUT24,
  122. OUT25,
  123. OUT26,
  124. OUT27,
  125. OUT28
  126. };
  127. #endif // IS31FL3235A_DRIVER_H