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.

121 lines
3.5 KiB

  1. /*
  2. Copyright 2016 flabbergast <s3+flabbergast@sdfeu.org>
  3. Copyright 2017 jpetermans <tibcmhhm@gmail.com>
  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. 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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef _LED_CONTROLLER_H_
  16. #define _LED_CONTROLLER_H_
  17. /* =========================
  18. * communication functions
  19. * ========================= */
  20. msg_t is31_write_data(uint8_t page, uint8_t *buffer, uint8_t size);
  21. msg_t is31_write_register(uint8_t page, uint8_t reg, uint8_t data);
  22. msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result);
  23. /* ============================
  24. * init functions/definitions
  25. * ============================*/
  26. void led_controller_init(void);
  27. #define CAPS_LOCK_LED_ADDRESS 46 //pin matrix location
  28. #define NUM_LOCK_LED_ADDRESS 85
  29. /* =============================
  30. * IS31 chip related definitions
  31. * ============================= */
  32. #define IS31_ADDR_DEFAULT 0x74
  33. #define IS31_REG_CONFIG 0x00
  34. // bits in reg
  35. #define IS31_REG_CONFIG_PICTUREMODE 0x00
  36. #define IS31_REG_CONFIG_AUTOPLAYMODE 0x08
  37. #define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18
  38. // D2:D0 bits are starting frame for autoplay mode
  39. #define IS31_REG_PICTDISP 0x01 // D2:D0 frame select for picture mode
  40. #define IS31_REG_AUTOPLAYCTRL1 0x02
  41. // D6:D4 number of loops (000=infty)
  42. // D2:D0 number of frames to be used
  43. #define IS31_REG_AUTOPLAYCTRL2 0x03 // D5:D0 delay time (*11ms)
  44. #define IS31_REG_DISPLAYOPT 0x05
  45. #define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames
  46. #define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x08
  47. // D2:D0 bits blink period time (*0.27s)
  48. #define IS31_REG_AUDIOSYNC 0x06
  49. #define IS31_REG_AUDIOSYNC_ENABLE 0x1
  50. #define IS31_REG_FRAMESTATE 0x07
  51. #define IS31_REG_BREATHCTRL1 0x08
  52. // D6:D4 fade out time (26ms*2^i)
  53. // D2:D0 fade in time (26ms*2^i)
  54. #define IS31_REG_BREATHCTRL2 0x09
  55. #define IS31_REG_BREATHCTRL2_ENABLE 0x10
  56. // D2:D0 extinguish time (3.5ms*2^i)
  57. #define IS31_REG_SHUTDOWN 0x0A
  58. #define IS31_REG_SHUTDOWN_OFF 0x1
  59. #define IS31_REG_SHUTDOWN_ON 0x0
  60. #define IS31_REG_AGCCTRL 0x0B
  61. #define IS31_REG_ADCRATE 0x0C
  62. #define IS31_COMMANDREGISTER 0xFD
  63. #define IS31_FUNCTIONREG 0x0B // helpfully called 'page nine'
  64. #define IS31_TIMEOUT 10000 // needs to be long enough to write a whole page
  65. /* ========================================
  66. * LED Thread related items
  67. * ========================================*/
  68. extern mailbox_t led_mailbox;
  69. void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action);
  70. void set_lock_leds (uint8_t led_addr, uint8_t led_action, uint8_t page);
  71. void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte);
  72. void write_led_page (uint8_t page, uint8_t *led_array, uint8_t led_count);
  73. // constants for signaling the LED controller thread
  74. enum led_msg_t {
  75. KEY_LIGHT,
  76. SET_FULL_ROW,
  77. OFF_LED,
  78. ON_LED,
  79. TOGGLE_LED,
  80. BLINK_OFF_LED,
  81. BLINK_ON_LED,
  82. BLINK_TOGGLE_LED,
  83. TOGGLE_ALL,
  84. TOGGLE_BACKLIGHT,
  85. DISPLAY_PAGE,
  86. RESET_PAGE,
  87. TOGGLE_NUM_LOCK,
  88. TOGGLE_CAPS_LOCK,
  89. TOGGLE_BREATH,
  90. STEP_BRIGHTNESS
  91. };
  92. #endif /* _LED_CONTROLLER_H_ */