SRA Board Components
ESP-IDF component for SRA Board
led_matrix.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Society of Robotics and Automation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef LED_MATRIX_H
26#define LED_MATRIX_H
27
28#include <string.h>
29#include <stdint.h>
30#include <ctype.h>
31#include <freertos/FreeRTOS.h>
32#include <freertos/task.h>
33#include "esp_log.h"
34
35#include "shift_register.h"
36
40typedef uint32_t led_matrix_data_t;
41
47typedef bool led_matrix_data_arr_t[CONFIG_LED_MATRIX_ROWS][CONFIG_LED_MATRIX_COLUMNS];
48
52typedef struct {
56
60typedef enum {
64
68static const uint8_t led_matrix_rows = CONFIG_LED_MATRIX_ROWS;
69
73static const uint8_t led_matrix_columns = CONFIG_LED_MATRIX_COLUMNS;
74
84static const uint8_t led_matrix_map[CONFIG_LED_MATRIX_ROWS * CONFIG_LED_MATRIX_COLUMNS] = {
85 0, 1, 2, 3, 4, 5,
86 10, 11, 12, 13, 14, 15,
87 20, 21, 22, 23, 8, 9,
88 30, 31, 16, 17, 18, 19,
89 24, 25, 26, 27, 28, 29
90};
91
100
109
119esp_err_t led_matrix_set_bit(led_matrix *matrix, const uint8_t led_number, const uint8_t led_value);
120
129esp_err_t led_matrix_set_data(led_matrix *matrix, const led_matrix_data_t data);
130
139esp_err_t led_matrix_set_data_raw(led_matrix *matrix, const led_matrix_data_t data);
140
149esp_err_t led_matrix_write(const led_matrix *matrix, const led_matrix_output_mode_t mode);
150
160esp_err_t led_matrix_display_string(led_matrix *matrix, const char *message, double wait_ms);
161
169esp_err_t led_matrix_cleanup(led_matrix matrix);
170
171#endif
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.
Definition: led_matrix.h:47
uint32_t led_matrix_data_t
An integer used as a bitarray to represent the LED matrix data type.
Definition: led_matrix.h:40
led_matrix led_matrix_init(void)
Enables and configures the LED Matrix and corresponding shift registers.
Definition: led_matrix.c:31
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.
Definition: led_matrix.c:102
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 bet...
Definition: led_matrix.c:134
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.
Definition: led_matrix.c:56
led_matrix_output_mode_t
Enum used for the output mode of the LED matrix.
Definition: led_matrix.h:60
@ LED_MATRIX_OUTPUT_SEQ
Definition: led_matrix.h:61
@ LED_MATRIX_OUTPUT_PAR
Definition: led_matrix.h:62
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().
Definition: led_matrix.c:85
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.
Definition: led_matrix.c:115
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 unsigne...
Definition: led_matrix.c:41
esp_err_t led_matrix_cleanup(led_matrix matrix)
Performs cleanup on the LED Matrix contents.
Definition: led_matrix.c:167
Struct used as a handle for LED matrix.
Definition: led_matrix.h:52
led_matrix_data_t data
Definition: led_matrix.h:53
shift_register_t config
Definition: led_matrix.h:54
The handle used for representing the shift register.
Definition: shift_register.h:45