2017-08-25 17:03:07 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 15:06:53 -06:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-08-25 17:03:07 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-08-31 11:44:43 -05:00
|
|
|
* This module is off by default, but can be enabled to facilitate the display of
|
2018-06-18 22:04:03 -05:00
|
|
|
* extra debug information during code development.
|
2017-08-25 17:03:07 -05:00
|
|
|
*
|
2018-06-18 22:04:03 -05:00
|
|
|
* Just connect up 5V and GND to give it power, then connect up the pins assigned
|
2017-08-31 11:44:43 -05:00
|
|
|
* in Configuration_adv.h. For example, on the Re-ARM you could use:
|
2017-08-25 17:03:07 -05:00
|
|
|
*
|
2017-08-31 11:44:43 -05:00
|
|
|
* #define MAX7219_CLK_PIN 77
|
|
|
|
* #define MAX7219_DIN_PIN 78
|
|
|
|
* #define MAX7219_LOAD_PIN 79
|
|
|
|
*
|
2018-08-21 02:06:18 -05:00
|
|
|
* max7219.init() is called automatically at startup, and then there are a number of
|
2017-08-31 11:44:43 -05:00
|
|
|
* support functions available to control the LEDs in the 8x8 grid.
|
2018-07-19 13:56:47 -05:00
|
|
|
*
|
|
|
|
* If you are using the Max7219 matrix for firmware debug purposes in time sensitive
|
2018-07-25 18:49:32 -05:00
|
|
|
* areas of the code, please be aware that the orientation (rotation) of the display can
|
2018-07-19 13:56:47 -05:00
|
|
|
* affect the speed. The Max7219 can update a single column fairly fast. It is much
|
|
|
|
* faster to do a Max7219_Set_Column() with a rotation of 90 or 270 degrees than to do
|
|
|
|
* a Max7219_Set_Row(). The opposite is true for rotations of 0 or 180 degrees.
|
2017-08-25 17:03:07 -05:00
|
|
|
*/
|
2018-08-18 01:33:13 -05:00
|
|
|
#pragma once
|
2017-08-25 17:03:07 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
#ifndef MAX7219_ROTATE
|
|
|
|
#define MAX7219_ROTATE 0
|
|
|
|
#endif
|
|
|
|
#define _ROT ((MAX7219_ROTATE + 360) % 360)
|
|
|
|
|
2018-09-05 14:18:13 -05:00
|
|
|
#ifndef MAX7219_NUMBER_UNITS
|
|
|
|
#define MAX7219_NUMBER_UNITS 1
|
|
|
|
#endif
|
2018-08-21 02:06:18 -05:00
|
|
|
#define MAX7219_LINES (8 * (MAX7219_NUMBER_UNITS))
|
2018-08-18 01:33:13 -05:00
|
|
|
|
|
|
|
#if _ROT == 0 || _ROT == 180
|
|
|
|
#define MAX7219_Y_LEDS 8
|
2018-08-21 02:06:18 -05:00
|
|
|
#define MAX7219_X_LEDS MAX7219_LINES
|
2018-08-18 01:33:13 -05:00
|
|
|
#elif _ROT == 90 || _ROT == 270
|
|
|
|
#define MAX7219_X_LEDS 8
|
2018-08-21 02:06:18 -05:00
|
|
|
#define MAX7219_Y_LEDS MAX7219_LINES
|
2018-08-18 01:33:13 -05:00
|
|
|
#else
|
|
|
|
#error "MAX7219_ROTATE must be a multiple of +/- 90°."
|
|
|
|
#endif
|
2017-08-25 17:03:07 -05:00
|
|
|
|
2017-09-08 14:47:47 -05:00
|
|
|
//
|
2018-06-18 22:04:03 -05:00
|
|
|
// MAX7219 registers
|
2017-09-08 14:47:47 -05:00
|
|
|
//
|
|
|
|
#define max7219_reg_noop 0x00
|
|
|
|
#define max7219_reg_digit0 0x01
|
|
|
|
#define max7219_reg_digit1 0x02
|
|
|
|
#define max7219_reg_digit2 0x03
|
|
|
|
#define max7219_reg_digit3 0x04
|
|
|
|
#define max7219_reg_digit4 0x05
|
|
|
|
#define max7219_reg_digit5 0x06
|
|
|
|
#define max7219_reg_digit6 0x07
|
|
|
|
#define max7219_reg_digit7 0x08
|
2017-08-25 17:03:07 -05:00
|
|
|
|
2017-09-08 14:47:47 -05:00
|
|
|
#define max7219_reg_decodeMode 0x09
|
2018-06-18 22:04:03 -05:00
|
|
|
#define max7219_reg_intensity 0x0A
|
2017-09-08 14:47:47 -05:00
|
|
|
#define max7219_reg_scanLimit 0x0B
|
|
|
|
#define max7219_reg_shutdown 0x0C
|
2018-06-18 22:04:03 -05:00
|
|
|
#define max7219_reg_displayTest 0x0F
|
2017-08-25 17:03:07 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
class Max7219 {
|
|
|
|
public:
|
2018-08-21 02:06:18 -05:00
|
|
|
static uint8_t led_line[MAX7219_LINES];
|
2018-06-18 22:04:03 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
Max7219() { }
|
2018-06-18 22:04:03 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
static void init();
|
|
|
|
static void register_setup();
|
|
|
|
static void putbyte(uint8_t data);
|
|
|
|
static void pulse_load();
|
2018-06-18 22:04:03 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
// Set a single register (e.g., a whole native row)
|
|
|
|
static void send(const uint8_t reg, const uint8_t data);
|
2018-06-18 22:04:03 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
// Refresh all units
|
2018-11-01 23:14:20 -05:00
|
|
|
static inline void refresh() { for (uint8_t i = 0; i < 8; i++) refresh_line(i); }
|
2018-06-18 22:04:03 -05:00
|
|
|
|
2018-08-21 02:06:18 -05:00
|
|
|
// Update a single native line on all units
|
|
|
|
static void refresh_line(const uint8_t line);
|
2018-07-19 13:56:47 -05:00
|
|
|
|
2018-08-21 02:06:18 -05:00
|
|
|
// Update a single native line on just one unit
|
|
|
|
static void refresh_unit_line(const uint8_t line);
|
2018-06-26 18:51:39 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
// Set a single LED by XY coordinate
|
|
|
|
static void led_set(const uint8_t x, const uint8_t y, const bool on);
|
|
|
|
static void led_on(const uint8_t x, const uint8_t y);
|
|
|
|
static void led_off(const uint8_t x, const uint8_t y);
|
|
|
|
static void led_toggle(const uint8_t x, const uint8_t y);
|
2017-08-25 17:03:07 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
// Set all LEDs in a single column
|
|
|
|
static void set_column(const uint8_t col, const uint32_t val);
|
|
|
|
static void clear_column(const uint8_t col);
|
|
|
|
|
|
|
|
// Set all LEDs in a single row
|
|
|
|
static void set_row(const uint8_t row, const uint32_t val);
|
|
|
|
static void clear_row(const uint8_t row);
|
|
|
|
|
|
|
|
// 16 and 32 bit versions of Row and Column functions
|
|
|
|
// Multiple rows and columns will be used to display the value if
|
|
|
|
// the array of matrix LED's is too narrow to accomplish the goal
|
|
|
|
static void set_rows_16bits(const uint8_t y, uint32_t val);
|
|
|
|
static void set_rows_32bits(const uint8_t y, uint32_t val);
|
|
|
|
static void set_columns_16bits(const uint8_t x, uint32_t val);
|
|
|
|
static void set_columns_32bits(const uint8_t x, uint32_t val);
|
|
|
|
|
|
|
|
// Quickly clear the whole matrix
|
|
|
|
static void clear();
|
|
|
|
|
2018-08-21 02:06:18 -05:00
|
|
|
// Quickly fill the whole matrix
|
|
|
|
static void fill();
|
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
// Apply custom code to update the matrix
|
|
|
|
static void idle_tasks();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void error(const char * const func, const int32_t v1, const int32_t v2=-1);
|
|
|
|
static void noop();
|
|
|
|
static void set(const uint8_t line, const uint8_t bits);
|
|
|
|
static void send_row(const uint8_t row);
|
|
|
|
static void send_column(const uint8_t col);
|
|
|
|
static void mark16(const uint8_t y, const uint8_t v1, const uint8_t v2);
|
|
|
|
static void range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh);
|
|
|
|
static void quantity16(const uint8_t y, const uint8_t ov, const uint8_t nv);
|
2018-07-19 13:56:47 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
#ifdef MAX7219_INIT_TEST
|
|
|
|
#if MAX7219_INIT_TEST == 2
|
|
|
|
static void spiral(const bool on, const uint16_t del);
|
|
|
|
#else
|
|
|
|
static void sweep(const int8_t dir, const uint16_t ms, const bool on);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
};
|
2018-07-19 13:56:47 -05:00
|
|
|
|
2018-08-18 01:33:13 -05:00
|
|
|
extern Max7219 max7219;
|