SRA Board Components
ESP-IDF component for SRA Board
Classes | Typedefs | Enumerations | Functions
led_matrix.h File Reference
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_log.h"
#include "shift_register.h"
Include dependency graph for led_matrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  led_matrix
 Struct used as a handle for LED matrix. More...
 

Typedefs

typedef uint32_t led_matrix_data_t
 An integer used as a bitarray to represent the LED matrix data type. More...
 
typedef bool led_matrix_data_arr_t[CONFIG_LED_MATRIX_ROWS][CONFIG_LED_MATRIX_COLUMNS]
 An array of booleans used to represent the LED matrix data instead of the uint32_t. More...
 

Enumerations

enum  led_matrix_output_mode_t { LED_MATRIX_OUTPUT_SEQ , LED_MATRIX_OUTPUT_PAR }
 Enum used for the output mode of the LED matrix. More...
 

Functions

led_matrix led_matrix_init (void)
 Enables and configures the LED Matrix and corresponding shift registers. More...
 
led_matrix_data_t bool_to_uint32 (const led_matrix_data_arr_t input_arr)
 Converts a boolean array of size CONFIG_LED_MATRIX_ROWSxCONFIG_LED_MATRIX_COLUMNS to a 32-bit unsigned integer. More...
 
esp_err_t led_matrix_set_bit (led_matrix *matrix, const uint8_t led_number, const uint8_t led_value)
 Sets a single bit of the "data" field of the passed in matrix. More...
 
esp_err_t led_matrix_set_data (led_matrix *matrix, const led_matrix_data_t data)
 Sets all the bits of the "data" field of the passed in matrix using led_matrix_set_bit(). More...
 
esp_err_t led_matrix_set_data_raw (led_matrix *matrix, const led_matrix_data_t data)
 Sets all the bits of the "data" field. More...
 
esp_err_t led_matrix_write (const led_matrix *matrix, const led_matrix_output_mode_t mode)
 Performs the write from the led_matrix structure to the actual LEDs on board. More...
 
esp_err_t led_matrix_display_string (led_matrix *matrix, const char *message, double wait_ms)
 Displays the entered string character by character on the LED Matrix with a delay of "wait_ms" ms between characters. More...
 
esp_err_t led_matrix_cleanup (led_matrix matrix)
 Performs cleanup on the LED Matrix contents. More...
 

Typedef Documentation

◆ led_matrix_data_arr_t

typedef bool led_matrix_data_arr_t[CONFIG_LED_MATRIX_ROWS][CONFIG_LED_MATRIX_COLUMNS]

An array of booleans used to represent the LED matrix data instead of the uint32_t.

Note
Valid when the SRA Board is in its upright orientation (text and logo upright).

◆ led_matrix_data_t

typedef uint32_t led_matrix_data_t

An integer used as a bitarray to represent the LED matrix data type.

Enumeration Type Documentation

◆ led_matrix_output_mode_t

Enum used for the output mode of the LED matrix.

Enumerator
LED_MATRIX_OUTPUT_SEQ 
LED_MATRIX_OUTPUT_PAR 

Function Documentation

◆ bool_to_uint32()

led_matrix_data_t bool_to_uint32 ( const led_matrix_data_arr_t  input_arr)

Converts a boolean array of size CONFIG_LED_MATRIX_ROWSxCONFIG_LED_MATRIX_COLUMNS to a 32-bit unsigned integer.

Parameters
input_arrBoolean input array of dimensions (CONFIG_LED_MATRIX_ROWS, CONFIG_LED_MATRIX_COLUMNS)
Returns
A 32-bit value representing the LED states, where each bit corresponds to one physical LED as defined by led_matrix_map.

◆ led_matrix_cleanup()

esp_err_t led_matrix_cleanup ( led_matrix  matrix)

Performs cleanup on the LED Matrix contents.

Parameters
matrixThe handle to represent and use the matrix of LEDs
Returns
Returns an error if there is an error while cleaning up the shift register, else returns ESP_OK

◆ led_matrix_display_string()

esp_err_t led_matrix_display_string ( led_matrix matrix,
const char *  message,
double  wait_ms 
)

Displays the entered string character by character on the LED Matrix with a delay of "wait_ms" ms between characters.

Parameters
matrixThe handle to represent and use the matrix of LEDs.
messageThe message to be displayed on the screen.
wait_msThe time to wait between two characters (in ms)
Returns
Returns an error if a NULL matrix or message is passed, else returns ESP_OK

◆ led_matrix_init()

led_matrix led_matrix_init ( void  )

Enables and configures the LED Matrix and corresponding shift registers.

Parameters
matrixThe handle to represent and use the matrix of LEDs.
Returns
Returns an error if the could not allocate enough memory or if shift register configuration failed, else returns ESP_OK

◆ led_matrix_set_bit()

esp_err_t led_matrix_set_bit ( led_matrix matrix,
const uint8_t  led_number,
const uint8_t  led_value 
)

Sets a single bit of the "data" field of the passed in matrix.

Parameters
matrixThe handle to represent and use the matrix of LEDs.
led_numberThe logical index of the pin (varies from [0, led_matrix_rows * led_matrix_columns - 1])
led_valueThe value to set the LED (can be 0 - LOW or 1 - HIGH)
Returns
Returns an error if a NULL matrix is passed or if the led number exceeds (led_matrix_rows * led_matrix_columns - 1), else returns ESP_OK

◆ led_matrix_set_data()

esp_err_t led_matrix_set_data ( led_matrix matrix,
const led_matrix_data_t  data 
)

Sets all the bits of the "data" field of the passed in matrix using led_matrix_set_bit().

Parameters
matrixThe handle to represent and use the matrix of LEDs.
dataThe data to write to the LED matrix.
Returns
Returns an error if a NULL matrix is passed, else returns ESP_OK

◆ led_matrix_set_data_raw()

esp_err_t led_matrix_set_data_raw ( led_matrix matrix,
const led_matrix_data_t  data 
)

Sets all the bits of the "data" field.

Parameters
matrixThe handle to represent and use the matrix of LEDs.
dataThe bitfield used to set the values of the LED matrix.
Returns
Returns an error if a NULL matrix is passed, else returns ESP_OK

◆ led_matrix_write()

esp_err_t led_matrix_write ( const led_matrix matrix,
const led_matrix_output_mode_t  mode 
)

Performs the write from the led_matrix structure to the actual LEDs on board.

Parameters
matrixThe handle to represent and use the matrix of LEDs.
modeThe way in which to display the values from the shift register.
Returns
Returns an error if a NULL matrix is passed, else returns ESP_OK