max7219.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2021 Zach White <skullydazed@gmail.com>
  3. * Copyright (c) 2007 Eberhard Fahle
  4. *
  5. * max7219.h - A library for controling Leds with a MAX7219/MAX7221
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use,
  11. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following
  14. * conditions:
  15. *
  16. * This permission notice shall be included in all copies or
  17. * substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  21. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. #pragma once
  29. #include "quantum.h"
  30. #include "spi_master.h"
  31. // Set defaults if they're not set
  32. #ifndef MAX7219_LOAD
  33. # define MAX7219_LOAD B0
  34. #endif
  35. #ifndef MAX7219_CONTROLLERS
  36. # define MAX7219_CONTROLLERS 4
  37. #endif
  38. #ifndef MAX7219_LED_INTENSITY
  39. # define MAX7219_LED_INTENSITY 1
  40. #endif
  41. #ifndef MAX7219_SCROLL_TIME
  42. # define MAX7219_SCROLL_TIME 100
  43. #endif
  44. #ifndef MAX7219_BUFFER_MULTIPLIER
  45. # define MAX7219_BUFFER_MULTIPLIER 24
  46. #endif
  47. #if !defined(MAX7219_LED_TEST) && !defined(MAX7219_LED_ITERATE) && !defined(MAX7219_LED_DANCE) && !defined(MAX7219_LED_FONTTEST) && !defined(MAX7219_LED_CLUEBOARD) && !defined(MAX7219_LED_KONAMI) && !defined(MAX7219_LED_QMK_POWERED) && !defined(MAX7219_DRAWING_TOY_MODE) && !defined(MAX7219_LED_CUSTOM)
  48. # define MAX7219_QMK_POWERED
  49. #endif
  50. // Configure our MAX7219's
  51. #define MAX_BYTES MAX7219_CONTROLLERS * 2
  52. #define LED_COUNT MAX7219_CONTROLLERS * 64
  53. #define MAX7219_BUFFER_SIZE MAX7219_CONTROLLERS*MAX7219_BUFFER_MULTIPLIER
  54. // Opcodes for the MAX7219
  55. #define OP_DECODEMODE 9
  56. #define OP_INTENSITY 10
  57. #define OP_SCANLIMIT 11
  58. #define OP_SHUTDOWN 12
  59. #define OP_DISPLAYTEST 15
  60. // Datastructures
  61. extern uint8_t max7219_led_a[8][MAX7219_BUFFER_SIZE];
  62. extern bool max7219_led_scrolling;
  63. // Functions
  64. void max7219_write(int device_num, volatile uint8_t opcode, volatile uint8_t data);
  65. void max7219_write_all(void);
  66. void max7219_write_frame(void);
  67. void max7219_clear_display(void);
  68. void max7219_display_test(int device_num, bool enabled);
  69. void max7219_init(void);
  70. void max7219_message_sign(uint8_t message[][6], size_t message_len);
  71. void max7219_message_sign_task(bool loop_message);
  72. void max7219_set_decode_mode(int device_num, int mode);
  73. void max7219_set_intensity(int device_num, int intensity);
  74. void max7219_set_led(int row, int column, bool state);
  75. void max7219_set_all_leds(uint8_t led_matrix[LED_COUNT]);
  76. void max7219_set_scan_limit(int device_num, int limit);
  77. void max7219_shutdown(int device_num, bool is_in_shutdown);