MaxMatrix
Drive chained 8x8 LED dot matrix modules with MAX7219.
Loading...
Searching...
No Matches
Panel.h
Go to the documentation of this file.
1// Copyright 2026 Andreas Burnickl
2// SPDX-License-Identifier: GPL-3.0-or-later
3
12
13#ifndef MAXMATRIX_SRC_MATRIX_PANEL_H_
14#define MAXMATRIX_SRC_MATRIX_PANEL_H_
15
16#include "Arduino.h"
17#include "MaxMatrixAttributes.h"
18#include "MaxMatrixConfig.h"
19#include "MaxMatrixError.h"
20#include "Utility/Byte.h"
21#include "Utility/span.h"
22#include "Wired.h"
23
24namespace max_matrix {
25
28enum class MatrixOrientation : uint8_t {
31};
32
33namespace internal {
34
35/* the three properties of a ModuleType, one bit each of its value */
37constexpr uint8_t kModuleTypeDigitsAsRows{0x04};
39constexpr uint8_t kModuleTypeReversedColumns{0x02};
41constexpr uint8_t kModuleTypeReversedRows{0x01};
42
43} // namespace internal
44
76
78enum class ShiftFill : uint8_t {
82};
83
84namespace internal {
85
94class Panel {
95 private:
96 Wired wired_;
98 MatrixOrientation matrix_orientation_{MatrixOrientation::k0};
99
100 /* where a dot lies in the buffer: the buffer column and its bit */
101 struct BufferDot {
102 uint8_t column;
103 uint8_t bit;
104 };
105
106 static Byte ReverseByte(Byte input);
107 MAXMATRIX_NODISCARD BufferDot ConvertDotToBuffer(uint8_t column,
108 uint8_t row) const;
109 Byte GetLine(uint8_t column, uint8_t row, bool vertical);
110 void SetLine(uint8_t column, uint8_t row, bool vertical, Byte value);
111 void SetFarDot(int32_t column, int32_t row, bool value);
112 void FillArea(int32_t left, int32_t top, int32_t right, int32_t bottom,
113 bool value);
114 void ChangeMapping(MatrixOrientation matrix_orientation,
115 ModuleType module_type);
116 Byte GetFill(ShiftFill fill, uint8_t rotated_column, uint8_t kept_column);
117 void ShiftRows(bool up, ShiftFill fill);
118
119 public:
131 Panel(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin,
132 span<Byte> buffer);
133
136 return wired_.GetNumberOfModules();
137 }
138
141 return wired_.GetNumberOfColumns();
142 }
143
145 Wired& GetWired() { return wired_; }
146
148 MAXMATRIX_NODISCARD Wired const& GetWired() const { return wired_; }
149
151 MAXMATRIX_NODISCARD ModuleType GetModuleType() const { return module_type_; }
152
155 return matrix_orientation_;
156 }
157
167
176 MAXMATRIX_NODISCARD Result<Byte> GetColumn(uint8_t module, uint8_t column);
177
188
200 MAXMATRIX_NODISCARD Result<Byte> GetRow(uint8_t module, uint8_t row);
201
210 MAXMATRIX_NODISCARD Result<bool> GetDot(int16_t column, int16_t row);
211
221 void SetColumn(int16_t column, Byte value);
222
232 void SetColumn(uint8_t module, uint8_t column, Byte value);
233
244 void SetRow(int16_t row, span<Byte const> values);
245
255 void SetRow(uint8_t module, uint8_t row, Byte value);
256
269 void SetDot(int16_t column, int16_t row, bool value);
270
283 void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, bool value);
284
297 void DrawRect(int16_t x, int16_t y, int16_t width, int16_t height,
298 bool value);
299
312 void FillRect(int16_t x, int16_t y, int16_t width, int16_t height,
313 bool value);
314
327 void DrawCircle(int16_t x, int16_t y, int16_t radius, bool value);
328
344 void DrawBitmap(int16_t x, int16_t y, uint8_t height,
345 span<uint8_t const> bitmap);
346
358 void DrawColumn(int16_t x, int16_t y, uint8_t height, Byte value);
359
367 void SetModuleType(ModuleType module_type);
368
378 void SetMatrixOrientation(MatrixOrientation matrix_orientation);
379
387
399 Byte ShiftLeft(Byte shifted_in);
400
408
416 Byte ShiftRight(Byte shifted_in);
417
425
433};
434
435} // namespace internal
436} // namespace max_matrix
437
438#endif // MAXMATRIX_SRC_MATRIX_PANEL_H_
A byte of raw data, as a column of dots, which is no number.
The attributes of a later standard, as macros, where the compiler has them.
#define MAXMATRIX_NODISCARD
Marks a function whose result must not be dropped: the compiler warns where it is.
Definition MaxMatrixAttributes.h:37
Configuration of the MaxMatrix library.
Why a call did not do what it was asked.
constexpr uint8_t kModuleTypeReversedColumns
Definition Panel.h:39
constexpr uint8_t kModuleTypeReversedRows
Definition Panel.h:41
ModuleType
How the LEDs of a module are wired to its MAX7219, named as MD_MAX72XX names its hardware types.
Definition Panel.h:57
@ kDr0Cr1Rr0
Definition Panel.h:62
@ kGeneric
Definition Panel.h:70
@ kDr1Cr1Rr0
Definition Panel.h:66
@ kDr1Cr0Rr1
Definition Panel.h:65
@ kDr1Cr1Rr1
Definition Panel.h:67
@ kFc16
Definition Panel.h:71
@ kIcstation
Definition Panel.h:74
@ kDr0Cr0Rr0
Definition Panel.h:58
@ kDr0Cr1Rr1
Definition Panel.h:63
@ kParola
Definition Panel.h:73
@ kDr1Cr0Rr0
Definition Panel.h:64
@ kDr0Cr0Rr1
Definition Panel.h:61
constexpr uint8_t kModuleTypeDigitsAsRows
Definition Panel.h:37
ShiftFill
What comes in at the edge a shift leaves empty.
Definition Panel.h:78
@ kZero
Definition Panel.h:79
@ kRotate
Definition Panel.h:80
@ kKeep
Definition Panel.h:81
MatrixOrientation
How the whole matrix is turned: by 180 degrees for a board mounted upside down.
Definition Panel.h:28
@ k0
Definition Panel.h:29
@ k180
Definition Panel.h:30
The matrix as it is wired.
A byte of raw data: eight dots of a column or a row, or the value of a register of the MAX7219.
Definition Byte.h:45
What a getter of a single value returns: the value, or why there is none.
Definition MaxMatrixError.h:141
What a function that can fail returns when it has no value to return.
Definition MaxMatrixError.h:73
MAXMATRIX_NODISCARD uint8_t GetNumberOfModules() const
Returns the modules of the chain.
Definition Panel.h:135
void SetRow(int16_t row, span< Byte const > values)
Sets a row of the matrix, one byte per module.
void SetMatrixOrientation(MatrixOrientation matrix_orientation)
Sets how the whole matrix is turned.
MAXMATRIX_NODISCARD MatrixOrientation GetMatrixOrientation() const
Returns how the whole matrix is turned.
Definition Panel.h:154
void ShiftLeft(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one column to the left.
void DrawBitmap(int16_t x, int16_t y, uint8_t height, span< uint8_t const > bitmap)
Draws a picture from flash with its top left corner at x, y.
void SetColumn(uint8_t module, uint8_t column, Byte value)
Sets a column of a module.
MAXMATRIX_NODISCARD Result< bool > GetDot(int16_t column, int16_t row)
Returns whether a dot is lit.
MAXMATRIX_NODISCARD Result< Byte > GetRow(uint8_t module, uint8_t row)
Returns a row of a module.
MAXMATRIX_NODISCARD Result< Byte > GetColumn(uint8_t module, uint8_t column)
Returns a column of a module.
void SetModuleType(ModuleType module_type)
Sets how the LEDs of every module are wired.
Byte ShiftLeft(Byte shifted_in)
Shifts the whole picture one column to the left, with a column of the sketch coming in at the right.
MAXMATRIX_NODISCARD Result< Byte > GetColumn(int16_t column)
Returns a column of the matrix.
Panel(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin, span< Byte > buffer)
Makes the panel of the chain at these pins, of modules ModuleType::kDr0Cr0Rr1 in matrix orientation 0...
MAXMATRIX_NODISCARD Status GetRow(int16_t row, span< Byte > values)
Gives a row of the matrix, one byte per module.
void DrawRect(int16_t x, int16_t y, int16_t width, int16_t height, bool value)
Draws the outline of a rectangle.
void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, bool value)
Draws a straight line from one dot to another, both ends included.
void ShiftUp(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one row up.
void FillRect(int16_t x, int16_t y, int16_t width, int16_t height, bool value)
Draws a rectangle with its inside.
Wired & GetWired()
Returns the matrix as it is wired, below this one.
Definition Panel.h:145
void DrawColumn(int16_t x, int16_t y, uint8_t height, Byte value)
Draws one column of a picture, height rows from y on.
void ShiftRight(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one column to the right.
void DrawCircle(int16_t x, int16_t y, int16_t radius, bool value)
Draws the outline of a circle.
void ShiftDown(ShiftFill fill=ShiftFill::kZero)
Shifts the whole picture one row down.
MAXMATRIX_NODISCARD ModuleType GetModuleType() const
Returns how the LEDs of every module are wired.
Definition Panel.h:151
void SetRow(uint8_t module, uint8_t row, Byte value)
Sets a row of a module.
void SetColumn(int16_t column, Byte value)
Sets a column of the matrix.
void SetDot(int16_t column, int16_t row, bool value)
Lights a dot or turns it off.
Byte ShiftRight(Byte shifted_in)
Shifts the whole picture one column to the right, with a column of the sketch coming in at the left.
MAXMATRIX_NODISCARD Wired const & GetWired() const
Returns the matrix as it is wired, below this one.
Definition Panel.h:148
MAXMATRIX_NODISCARD uint8_t GetNumberOfColumns() const
Returns the columns of the panel, eight per module.
Definition Panel.h:140
The matrix as it is wired: the buffer of what the LEDs show, and what of it changed.
Definition Wired.h:34
A view of size() elements that another owns: a font, a bitmap, a text or a buffer.
Definition span.h:64
Elements that lie elsewhere, reached by index within their size, as std::span.