added a new LEDstrip module based on the espressif component

This commit is contained in:
Matthias Mitscherlich
2024-03-20 16:57:08 +01:00
parent 4b26e6080f
commit ac8505a157
10 changed files with 1118 additions and 1201 deletions
+103
View File
@@ -0,0 +1,103 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file prgm_ledstrip.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_PLATFORM_INC_PRGM_LEDSTRIP_H_
#define MAIN_PLATFORM_INC_PRGM_LEDSTRIP_H_
/**
* prgm_ledstrip implementation
* \defgroup prgm_ledstrip
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <stdint.h>
// ProjectIncludes
// All include files that are provided by the project
#include "FunctionStatus.h"
#include "led_strip.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class prgm_ledstrip
{
// -----------------------------------------------------------------------------------------------------------------
// Public Section
// -----------------------------------------------------------------------------------------------------------------
public:
struct pixel
{
uint32_t index;
uint8_t red;
uint8_t green;
uint8_t blue;
};
// Class Constructor
prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio);
FunctionStatus setPixel(struct pixel& pixel);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
// -----------------------------------------------------------------------------------------------------------------
protected:
// -----------------------------------------------------------------------------------------------------------------
// Private Section
// -----------------------------------------------------------------------------------------------------------------
private:
uint32_t numberOfLEDs;
uint32_t gpio;
led_strip_handle_t led_strip;
led_strip_config_t strip_config;
led_strip_rmt_config_t rmt_config;
};
/** @} */
#endif /* MAIN_PLATFORM_INC_PRGM_LEDSTRIP_H_ */
+83
View File
@@ -0,0 +1,83 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file prgm_ledstrip.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <cstring>
#include <prgm_ledstrip.h>
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
prgm_ledstrip::prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio) : numberOfLEDs(numberOfLEDs), gpio(gpio)
{
/* LED strip initialization with the GPIO and pixels number*/
memset(&strip_config, 0, sizeof(strip_config));
strip_config.strip_gpio_num = 8; // The GPIO that connected to the LED strip's data line
strip_config.max_leds = 2; // The number of LEDs in the strip,
strip_config.led_pixel_format = LED_PIXEL_FORMAT_GRB; // Pixel format of your LED strip
strip_config.led_model = LED_MODEL_WS2812; // LED strip model
strip_config.flags.invert_out = false; // whether to invert the output signal (useful when your hardware has a level inverter)
memset(&rmt_config, 0, sizeof(rmt_config));
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
rmt_config.rmt_channel = 0;
#else
rmt_config.clk_src = RMT_CLK_SRC_DEFAULT; // different clock source can lead to different power consumption
rmt_config.resolution_hz = 10 * 1000 * 1000; // 10MHz
rmt_config.flags.with_dma = false; // whether to enable the DMA feature
#endif
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
}
FunctionStatus prgm_ledstrip::setPixel(struct pixel& pixel)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, pixel.index, pixel.red, pixel.green, pixel.blue));
ESP_ERROR_CHECK(led_strip_refresh(led_strip));
return returnValue;
}