MaxMatrix
Drive chained 8x8 LED dot matrix modules with MAX7219.
Loading...
Searching...
No Matches
Wired.h
Go to the documentation of this file.
1// Copyright 2020 Andreas Burnickl
2// SPDX-License-Identifier: GPL-3.0-or-later
3
12
13#ifndef MAXMATRIX_SRC_MATRIX_WIRED_H_
14#define MAXMATRIX_SRC_MATRIX_WIRED_H_
15
16#include "Arduino.h"
17#include "Max7219/Chain.h"
18#include "MaxMatrixAttributes.h"
19#include "MaxMatrixConfig.h"
20#include "Utility/Byte.h"
21#include "Utility/span.h"
22
23namespace max_matrix {
24namespace internal {
25
34class Wired {
35 private:
36 Chain chain_;
37 // The sketch's, BufferSize() of the chain's modules long, which says how
38 // many modules the chain has; MatrixOf brings one.
39 span<Byte> matrix_buffer_;
40 /*
41 * A frame carries one register of every module, so the same column of all
42 * modules goes out in one frame. The buffer therefore keeps which columns of
43 * a module have changed, one bit each, and Send() needs one frame per changed
44 * column: eight at most for a whole picture, however many calls drew it.
45 */
46 Byte changed_columns_{};
47
48 public:
59 Wired(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin,
60 span<Byte> buffer);
61
63 Chain& GetChain() { return chain_; }
64
66 MAXMATRIX_NODISCARD Chain const& GetChain() const { return chain_; }
67
70 return static_cast<uint8_t>(matrix_buffer_.size());
71 }
72
75 // From the columns, a byte, rather than the size of the buffer, which the
76 // Uno would shift as 16 bits.
77 return static_cast<uint8_t>(GetNumberOfColumns() / kColumnNumberOfModule);
78 }
79
87 Byte GetColumn(uint8_t column) { return matrix_buffer_[column]; }
88
102 void StoreBit(uint8_t column, uint8_t bit, bool value);
103
112 void Clear();
113
120 void Send();
121};
122
123} // namespace internal
124} // namespace max_matrix
125
126#endif // MAXMATRIX_SRC_MATRIX_WIRED_H_
A byte of raw data, as a column of dots, which is no number.
Transfer to the chain of MAX7219.
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.
constexpr uint8_t kColumnNumberOfModule
The columns of one module.
Definition MaxMatrixConfig.h:82
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
The chain of MAX7219s: the pins, and the frames sent to them.
Definition Chain.h:115
MAXMATRIX_NODISCARD Chain const & GetChain() const
Returns the chain the matrix sends to.
Definition Wired.h:66
Chain & GetChain()
Returns the chain the matrix sends to.
Definition Wired.h:63
MAXMATRIX_NODISCARD uint8_t GetNumberOfColumns() const
Returns the columns of the chain, eight per module.
Definition Wired.h:69
void StoreBit(uint8_t column, uint8_t bit, bool value)
Sets one bit of the buffer.
void Clear()
Turns every LED off in the buffer, and marks every column as changed.
Byte GetColumn(uint8_t column)
Returns a column of the buffer, unchecked.
Definition Wired.h:87
MAXMATRIX_NODISCARD uint8_t GetNumberOfModules() const
Returns the modules in the chain, one per eight bytes of buffer.
Definition Wired.h:74
Wired(uint8_t data_in_pin, uint8_t chip_select_pin, uint8_t clock_pin, span< Byte > buffer)
Makes the matrix of the chain at these pins, and empties its buffer.
void Send()
Sends what has changed.
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.