SBK_MAX72xx library 2.0.5
Low-level driver for controlling multiple MAX7219/MAX7221 LED matrix chips via software SPI.
Loading...
Searching...
No Matches
SBK_MAX72xxHard.h
Go to the documentation of this file.
1
23
24/*
25 * Adapted from the original Ledcontrol.h library by Eberhard Fahle:
26 * <https://github.com/wayoda/LedControl>
27 *
28 * Original library:
29 * LEdControl.h - A library for controlling LEDs with a MAX7219/MAX7221
30 * Copyright (c) 2007 Eberhard Fahle
31 *
32 * All credit for the original library goes to Eberhard Fahle.
33 */
34
35#pragma once
36
37#define SBK_MAX72xx_IS_DEFINED
38
39#include <Arduino.h>
40#include <SPI.h>
41
47{
48public:
59 SBK_MAX72xxHard(uint8_t csPin, uint8_t devsNum = 1);
60
65 void setSPIClock(uint32_t frequency);
66
71 void end();
72
73 ~SBK_MAX72xxHard(); // Destructor
74
87 uint8_t maxRows(uint8_t devIdx = 0) const
88 {
89 (void)devIdx;
90 return _defaultRowBufferSize;
91 }
92
101 uint8_t maxColumns() const { return _defaultColBufferSize; }
102
116 uint8_t maxSegments(uint8_t devIdx = 0) const { return maxRows(devIdx) * maxColumns(); }
117
121 void begin();
122
129 void setShutdown(uint8_t devIdx, bool status);
130
137 void setScanLimit(uint8_t devIdx, uint8_t limit);
138
145 void setBrightness(uint8_t devIdx, uint8_t brightness);
146
152 uint8_t devsNum() const { return _devsNum; }
153
159 void clear(uint8_t devIdx);
160
164 void clear();
165
181 void setLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx, bool state);
182
203 bool getLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx) const;
204
212 void setCol(uint8_t devIdx, uint8_t colIdx, uint8_t value);
213
223 void show();
224
235 void show(uint8_t devIdx);
236
237private:
238 void _spiTransfer(uint8_t targetDevice, uint8_t opcode, uint8_t data);
239 void _writeColToAllDevices(uint8_t targetDevice, uint8_t colIdx, uint8_t data);
240 inline uint8_t _bitMaskRow(uint8_t devIdx, uint8_t rowIdx) const;
241 inline uint8_t _colIndex(uint8_t devIdx, uint8_t colIdx) const;
242
243 const uint8_t _dataPin;
244 const uint8_t _clkPin;
245 const uint8_t _csPin;
246 const uint8_t _devsNum = 1;
247
248 static constexpr uint8_t _defaultRowBufferSize = 8;
249 static constexpr uint8_t _defaultColBufferSize = 8;
250 uint8_t *_buffer; // Internal display buffer
251 bool *_update; // Array to track if data has changed per device
252
253 uint32_t _spiClock = 1000000; // Default 1 MHz
254};
void setLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx, bool state)
Set the state of a specific LED in the device’s internal matrix buffer.
Definition SBK_MAX72xxHard.cpp:126
uint8_t devsNum() const
Return the number of actives driver devices.
Definition SBK_MAX72xxHard.h:152
void clear()
Clear display buffers and hardware for all devices.
Definition SBK_MAX72xxHard.cpp:118
void setShutdown(uint8_t devIdx, bool status)
Enable or disable shutdown mode on a specific device.
Definition SBK_MAX72xxHard.cpp:86
bool getLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx) const
Get the state of a specific LED in the device’s internal matrix buffer.
Definition SBK_MAX72xxHard.cpp:152
void end()
Set SPI clock speed (hardware SPI only).
Definition SBK_MAX72xxHard.cpp:56
void setSPIClock(uint32_t frequency)
Set SPI clock speed (hardware SPI only).
Definition SBK_MAX72xxHard.cpp:51
uint8_t maxSegments(uint8_t devIdx=0) const
Returns the total number of addressable LED segments for this device.
Definition SBK_MAX72xxHard.h:116
uint8_t maxColumns() const
Returns the number of addressable columns (cathode outputs = DIGx).
Definition SBK_MAX72xxHard.h:101
uint8_t maxRows(uint8_t devIdx=0) const
Returns the number of addressable row lines (anode outputs = SEGx).
Definition SBK_MAX72xxHard.h:87
void setScanLimit(uint8_t devIdx, uint8_t limit)
Set the scan limit (number of active digits) for a specific device.
Definition SBK_MAX72xxHard.cpp:91
void begin()
Initialize SPI pins and all MAX72xx chips.
Definition SBK_MAX72xxHard.cpp:68
void setBrightness(uint8_t devIdx, uint8_t brightness)
Set display brightness for a specific device.
Definition SBK_MAX72xxHard.cpp:96
void show()
Push the internal display buffer to all connected devices.
Definition SBK_MAX72xxHard.cpp:172
SBK_MAX72xxHard(uint8_t csPin, uint8_t devsNum=1)
Construct a new hardware SPI SBK_MAX72xxHard driver instance.
Definition SBK_MAX72xxHard.cpp:39
void setCol(uint8_t devIdx, uint8_t colIdx, uint8_t value)
Set the entire col value for a specific device (buffer only).
Definition SBK_MAX72xxHard.cpp:160