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