logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

max7219.h (3283B)


  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 <stddef.h>
  30. #include <stdint.h>
  31. #include <stdbool.h>
  32. // Set defaults if they're not set
  33. #ifndef MAX7219_LOAD
  34. # define MAX7219_LOAD B0
  35. #endif
  36. #ifndef MAX7219_CONTROLLERS
  37. # define MAX7219_CONTROLLERS 4
  38. #endif
  39. #ifndef MAX7219_LED_INTENSITY
  40. # define MAX7219_LED_INTENSITY 1
  41. #endif
  42. #ifndef MAX7219_SCROLL_TIME
  43. # define MAX7219_SCROLL_TIME 100
  44. #endif
  45. #ifndef MAX7219_BUFFER_MULTIPLIER
  46. # define MAX7219_BUFFER_MULTIPLIER 24
  47. #endif
  48. #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)
  49. # define MAX7219_QMK_POWERED
  50. #endif
  51. // Configure our MAX7219's
  52. #define MAX_BYTES MAX7219_CONTROLLERS * 2
  53. #define LED_COUNT MAX7219_CONTROLLERS * 64
  54. #define MAX7219_BUFFER_SIZE MAX7219_CONTROLLERS*MAX7219_BUFFER_MULTIPLIER
  55. // Opcodes for the MAX7219
  56. #define OP_DECODEMODE 9
  57. #define OP_INTENSITY 10
  58. #define OP_SCANLIMIT 11
  59. #define OP_SHUTDOWN 12
  60. #define OP_DISPLAYTEST 15
  61. // Datastructures
  62. extern uint8_t max7219_led_a[8][MAX7219_BUFFER_SIZE];
  63. extern bool max7219_led_scrolling;
  64. // Functions
  65. void max7219_write(int device_num, volatile uint8_t opcode, volatile uint8_t data);
  66. void max7219_write_all(void);
  67. void max7219_write_frame(void);
  68. void max7219_clear_display(void);
  69. void max7219_display_test(int device_num, bool enabled);
  70. void max7219_init(void);
  71. void max7219_message_sign(uint8_t message[][6], size_t message_len);
  72. void max7219_message_sign_task(bool loop_message);
  73. void max7219_set_decode_mode(int device_num, int mode);
  74. void max7219_set_intensity(int device_num, int intensity);
  75. void max7219_set_led(int row, int column, bool state);
  76. void max7219_set_all_leds(uint8_t led_matrix[LED_COUNT]);
  77. void max7219_set_scan_limit(int device_num, int limit);
  78. void max7219_shutdown(int device_num, bool is_in_shutdown);