Subversion Repositories MK-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
/**
2
 * Marlin 3D Printer Firmware
3
 * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
 *
5
 * Based on Sprinter and grbl.
6
 * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
 
23
/**
24
 * This module is off by default, but can be enabled to facilitate the display of
25
 * extra debug information during code development.
26
 *
27
 * Just connect up 5V and GND to give it power, then connect up the pins assigned
28
 * in Configuration_adv.h. For example, on the Re-ARM you could use:
29
 *
30
 *   #define MAX7219_CLK_PIN   77
31
 *   #define MAX7219_DIN_PIN   78
32
 *   #define MAX7219_LOAD_PIN  79
33
 *
34
 * max7219.init() is called automatically at startup, and then there are a number of
35
 * support functions available to control the LEDs in the 8x8 grid.
36
 *
37
 * If you are using the Max7219 matrix for firmware debug purposes in time sensitive
38
 * areas of the code, please be aware that the orientation (rotation) of the display can
39
 * affect the speed.   The Max7219 can update a single column fairly fast.  It is much
40
 * faster to do a Max7219_Set_Column() with a rotation of 90 or 270 degrees than to do
41
 * a Max7219_Set_Row().    The opposite is true for rotations of 0 or 180 degrees.
42
 */
43
#pragma once
44
 
45
#ifndef MAX7219_ROTATE
46
  #define MAX7219_ROTATE 0
47
#endif
48
#define _ROT ((MAX7219_ROTATE + 360) % 360)
49
 
50
#define MAX7219_LINES (8 * (MAX7219_NUMBER_UNITS))
51
 
52
#if _ROT == 0 || _ROT == 180
53
  #define MAX7219_Y_LEDS          8
54
  #define MAX7219_X_LEDS          MAX7219_LINES
55
#elif _ROT == 90 || _ROT == 270
56
  #define MAX7219_X_LEDS          8
57
  #define MAX7219_Y_LEDS          MAX7219_LINES
58
#else
59
  #error "MAX7219_ROTATE must be a multiple of +/- 90°."
60
#endif
61
 
62
//
63
// MAX7219 registers
64
//
65
#define max7219_reg_noop        0x00
66
#define max7219_reg_digit0      0x01
67
#define max7219_reg_digit1      0x02
68
#define max7219_reg_digit2      0x03
69
#define max7219_reg_digit3      0x04
70
#define max7219_reg_digit4      0x05
71
#define max7219_reg_digit5      0x06
72
#define max7219_reg_digit6      0x07
73
#define max7219_reg_digit7      0x08
74
 
75
#define max7219_reg_decodeMode  0x09
76
#define max7219_reg_intensity   0x0A
77
#define max7219_reg_scanLimit   0x0B
78
#define max7219_reg_shutdown    0x0C
79
#define max7219_reg_displayTest 0x0F
80
 
81
class Max7219 {
82
public:
83
  static uint8_t led_line[MAX7219_LINES];
84
 
85
  Max7219() { }
86
 
87
  static void init();
88
  static void register_setup();
89
  static void putbyte(uint8_t data);
90
  static void pulse_load();
91
 
92
  // Set a single register (e.g., a whole native row)
93
  static void send(const uint8_t reg, const uint8_t data);
94
 
95
  // Refresh all units
96
  inline static void refresh() { for (uint8_t i = 0; i < 8; i++) refresh_line(i); }
97
 
98
  // Update a single native line on all units
99
  static void refresh_line(const uint8_t line);
100
 
101
  // Update a single native line on just one unit
102
  static void refresh_unit_line(const uint8_t line);
103
 
104
  // Set a single LED by XY coordinate
105
  static void led_set(const uint8_t x, const uint8_t y, const bool on);
106
  static void led_on(const uint8_t x, const uint8_t y);
107
  static void led_off(const uint8_t x, const uint8_t y);
108
  static void led_toggle(const uint8_t x, const uint8_t y);
109
 
110
  // Set all LEDs in a single column
111
  static void set_column(const uint8_t col, const uint32_t val);
112
  static void clear_column(const uint8_t col);
113
 
114
  // Set all LEDs in a single row
115
  static void set_row(const uint8_t row, const uint32_t val);
116
  static void clear_row(const uint8_t row);
117
 
118
  // 16 and 32 bit versions of Row and Column functions
119
  // Multiple rows and columns will be used to display the value if
120
  // the array of matrix LED's is too narrow to accomplish the goal
121
  static void set_rows_16bits(const uint8_t y, uint32_t val);
122
  static void set_rows_32bits(const uint8_t y, uint32_t val);
123
  static void set_columns_16bits(const uint8_t x, uint32_t val);
124
  static void set_columns_32bits(const uint8_t x, uint32_t val);
125
 
126
  // Quickly clear the whole matrix
127
  static void clear();
128
 
129
  // Quickly fill the whole matrix
130
  static void fill();
131
 
132
  // Apply custom code to update the matrix
133
  static void idle_tasks();
134
 
135
private:
136
  static void error(const char * const func, const int32_t v1, const int32_t v2=-1);
137
  static void noop();
138
  static void set(const uint8_t line, const uint8_t bits);
139
  static void send_row(const uint8_t row);
140
  static void send_column(const uint8_t col);
141
  static void mark16(const uint8_t y, const uint8_t v1, const uint8_t v2);
142
  static void range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh);
143
  static void quantity16(const uint8_t y, const uint8_t ov, const uint8_t nv);
144
 
145
  #ifdef MAX7219_INIT_TEST
146
  #if MAX7219_INIT_TEST == 2
147
    static void spiral(const bool on, const uint16_t del);
148
  #else
149
    static void sweep(const int8_t dir, const uint16_t ms, const bool on);
150
  #endif
151
  #endif
152
};
153
 
154
extern Max7219 max7219;