esp-idf-lib
esp-idf-lib copied to clipboard
max7219: add buffering
I am requesting a driver for MAX7219
.
Add one parameter to max7219_draw_image_8x8.
esp_err_t max7219_draw_image_8x8(max7219_t *dev, uint8_t pos, const void *image, bool flag)
If flag = true, immediately issue an SPI to the device.
for (uint8_t c = 0; c < CASCADE_SIZE; c ++)
max7219_draw_image_8x8(&dev, c * 8, (uint8_t *)symbols + c * 8 + offs, true);
When CASCADE_SIZE is 4, such data is output to SPI.
[0x01 0xff]
[0x01 0xff 0x00 0x00]
[0x01 0xff 0x00 0x00 0x00 0x00]
[0x01 0xff 0x00 0x00 0x00 0x00 0x00 0x00]
The bottom row of the four Matrix LEDs turns ON.
If flag = false, data is saved in the [INTERNAL buffer] and SPI is not issued to the device. [INTERNAL buffer] is uint8_t buffer[CASCADE_SIZE*8] like this:
typedef struct
{
spi_device_interface_config_t spi_cfg;
spi_device_handle_t spi_dev;
uint8_t digits; //!< Accessible digits in 7seg. Up to cascade_size * 8
uint8_t cascade_size; //!< Up to `MAX7219_MAX_CASCADE_SIZE` MAX721xx cascaded
bool mirrored; //!< true for horizontally mirrored displays
bool bcd;
uint8_t internal_buffer[64];
} max7219_t;
When max7219_flash is executed, SPI is issued to the device based on the data in the [INTERNAL buffer].
for (uint8_t c = 0; c < CASCADE_SIZE; c ++)
max7219_draw_image_8x8(&dev, c * 8, (uint8_t *)symbols + c * 8 + offs, false);
max7219_flash(&dev);
When CASCADE_SIZE is 4, such data is output to SPI.
[0x01 0xff 0x01 0xff 0x01 0xff 0x01 0xff]
The bottom row of the four Matrix LEDs turns ON.
It can be displayed at high speed.
I tried the same approach in the Arduino environment. It's 23 times faster.
https://github.com/nopnop2002/Arduino-MatrixControl
Thank you.
Good idea, but implementing it will break compatibility. I will think about it.
How about hiding the flag variable inside the structure like this?
typedef struct
{
spi_device_interface_config_t spi_cfg;
spi_device_handle_t spi_dev;
uint8_t digits; //!< Accessible digits in 7seg. Up to cascade_size * 8
uint8_t cascade_size; //!< Up to `MAX7219_MAX_CASCADE_SIZE` MAX721xx cascaded
bool mirrored; //!< true for horizontally mirrored displays
bool bcd;
bool flag; //Whether to buffer the SPI output
uint8_t internal_buffer[64];
} max7219_t;