Devices

A device is a piece of equipment that can be controlled from a microcontroller, often via a bus. Classes in this category provide access to the specific features of a given device, and may also provide capability interface implementations for those devices that have a capability that is shared with several devices.

MAX7219 and MAX7221 LED display driver ICs

These chips are manufactured by Maxim and are both intended to drive up to 64 LEDs arranged in sets of eight. They can be used to control 8x8 pixel LED matrices and also to control up to eight seven-segment LED displays.

The chips act as SPI slaves so the driver class requires an SPI master implementation which it will use for signalling.

template < class SPI_CHANNEL_TYPE >
class Max72xxDevice

Device driver for the MAX7219 and MAX7221 LED display driver ICs.

These chips provide a convenient way to control up to 64 LEDs by multiplexing an 8x8 matrix. The chips can either produce digits on up to eight 7-segment numeric displays (decode mode) or directly drive an 8x8 pixel matrix (no decode mode).

Public Functions

Max72xxDevice(SPI_CHANNEL_TYPE * spi_channel)

void set_register(uint8_t register_idx, uint8_t value)

Low-level operation to set a register value on the device.

All other operations on this class are implemented in terms of this method. Consult the device datasheet for information on what registers are available.

void set_intensity(uint8_t intensity)

Set the intensity of the LEDs.

Intensity is a value from 0 to 15 that controls the internal PWM of the chip, with higher values resulting in a brighter appearance.

void set_scan_limit(uint8_t limit)

Set how many rows of eight LEDs will be scanned.

The chips can be configured to scan from 1 to 8 rows of eight LEDs. When controlling 7-segment LED displays, this can be set to the number of digits.

Since the chip illuminates one set of eight at a time in quick succession, reducing the scan limit can increase the brightness of the remaining digits, but be warned that this will increase the power dissipated by these digits. Consult the device datasheet for guidance.

void enable_display_test(void)

Enable the display test mode.

In display test mode, all LEDs will be illumated regardless of what is set in the display data registers.

void disable_display_test(void)

Disable the display test mode.

This resumes normal operation after enabling test mode with enable_display_test.

void enable_display(void)

Enable the display.

By default the display is disabled to avoid the risk of garbled, random display during system boot. Call this method to make the display begin to show what’s in the display registers.

void disable_display(void)

Disable the display.

This will turn off all LEDs in the display, but leave the display registers intact.

void write_decode_mode(uint8_t mask)

Configure the Decode Mode register.

Decode Mode may be enabled for each row of eight LEDs individually and controls how the display driver interprets the content of each row’s data register.

When decode mode is enabled the register value will be interpreted as a number and rendered in a form that will cause the corresponding digit to be displayed on a 7-segment numeric display. When decode mode is disabled the register value is taken literally with each bit corresponding to one LED in the row.

The parameter to this method is a bitmask where each bit corresponds to a row, and 1 enables decode mode while 0 disables it. To completely disable decode mode, pass 0x00.

void write_row(uint8_t row, uint8_t pattern)

Write a row to the display.

How the provided pattern is interpreted depends on whether the row has *decode mode* enabled.

Row is the row index to write, from 0 to 7. Be aware that there is no range checking on this parameter so values greater than 7 will corrupt other display registers.

Table Of Contents

Previous topic

Buses

Next topic

Capabilities

This Page