// -------------------------------------------------------------------------------------------------------------------- /// \file ledmatrix.h /// \brief File description // -------------------------------------------------------------------------------------------------------------------- // // vbchaos software design // // -------------------------------------------------------------------------------------------------------------------- /// $Revision: $ /// $Author: $ /// $Date: $ // (c) 2023 vbchaos // -------------------------------------------------------------------------------------------------------------------- #ifndef MAIN_INC_LEDMATRIX_H_ #define MAIN_INC_LEDMATRIX_H_ /** * ledmatrix implementation * \defgroup ledmatrix * \brief {group_description} * \addtogroup {Layer} * * Detailed description * @{ */ // -------------------------------------------------------------------------------------------------------------------- // Include files // -------------------------------------------------------------------------------------------------------------------- // CompilerIncludes // All include files that are provided by the compiler directly #include // ProjectIncludes // All include files that are provided by the project #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" #include "driver/rmt_tx.h" // -------------------------------------------------------------------------------------------------------------------- // Constant and macro definitions // -------------------------------------------------------------------------------------------------------------------- #define LEDMATRIX_RED_INDEX ((uint32_t)1) #define LEDMATRIX_GREEN_INDEX ((uint32_t)0) #define LEDMATRIX_BLUE_INDEX ((uint32_t)2) // -------------------------------------------------------------------------------------------------------------------- // Type definitions. // -------------------------------------------------------------------------------------------------------------------- typedef enum { LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT, LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT } LEDMatrix_Orientation_Row_t; typedef enum { LEDMATRIX_ORIENTATION_COLUM_UP_DOWN, LEDMATRIX_ORIENTATION_COLUM_DOWN_UP } LEDMatrix_Orientation_Colum_t; typedef enum { LEDMATRIX_ORIENTATION_ROW, LEDMATRIX_ORIENTATION_COLUM }LEDMatrix_Orientation_t; typedef struct { LEDMatrix_Orientation_Row_t rowOrientation; LEDMatrix_Orientation_Colum_t columOrientation; LEDMatrix_Orientation_t matrixOrientation; unsigned int width; unsigned int height; // RMT objects for transmission rmt_channel_handle_t* rmtChannel; rmt_encoder_handle_t* rmtEncoder; rmt_transmit_config_t* rmtConfig; } LEDMatrix_Parameters_t; typedef struct { bool on; uint8_t red; uint8_t green; uint8_t blue; } LEDMatrix_Pixel_t; // -------------------------------------------------------------------------------------------------------------------- // Function declarations // -------------------------------------------------------------------------------------------------------------------- class LEDMatrix { public: struct coordinate { int x; int y; }; LEDMatrix(LEDMatrix_Parameters_t* parameters); bool setPixelValue(unsigned int colum, unsigned int row, bool value); void setGlobalColour(uint8_t red, uint8_t green, uint8_t blue); void setPixelColour(unsigned int colum, unsigned int row, uint8_t red, uint8_t green, uint8_t blue); void clear(void); BaseType_t tick(void); protected: unsigned int findPixelIndexFromCoordinates(unsigned int colum, unsigned int row); private: LEDMatrix_Parameters_t parameters; LEDMatrix_Pixel_t* matrix; uint8_t* tx_matrix; unsigned int numberOfPixels; static bool initialized; static TaskHandle_t matrixTaskHandle; static SemaphoreHandle_t taskSemaphore; static void matrixTask(void* parameters); }; inline BaseType_t LEDMatrix::tick(void) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; if (LEDMatrix::initialized) { xSemaphoreGiveFromISR(LEDMatrix::taskSemaphore, &xHigherPriorityTaskWoken); } return xHigherPriorityTaskWoken; } /** @} */ #endif /* MAIN_INC_LEDMATRIX_H_ */