Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neopixel add SPI driver for C2 and some minor updates #19372

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/lib_basic/NeoPixelBus/src/NeoPixelBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ License along with NeoPixel. If not, see
#include "internal/NeoEsp32I2sMethod.h"
#include "internal/NeoEsp32RmtMethod.h"
#else
#include "internal/NeoEsp32RmtMethod_idf5.h"
#if !defined(CONFIG_IDF_TARGET_ESP32C2)
#include "internal/NeoEsp32RmtMethod_idf5.h" // every other SOC
#else //CONFIG_IDF_TARGET_ESP32C2
#include "internal/NeoEsp32SpiMethod_idf5.h" // ESP32C2
#endif //CONFIG_IDF_TARGET_ESP32C2
#endif // ESP_IDF_VERSION_MAJOR
#include "internal/NeoEspBitBangMethod.h"
#include "internal/DotStarEsp32DmaSpiMethod.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/lib_basic/NeoPixelBus/src/internal/Esp32_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// ESP32C3/S3 I2S is not supported yet due to significant changes to interface
#ifndef CONFIG_SOC_RMT_TX_CANDIDATES_PER_GROUP // turn this off with something new from idf5.1
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32C2)

#include <string.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/lib_basic/NeoPixelBus/src/internal/Esp32_i2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#ifndef CONFIG_SOC_RMT_TX_CANDIDATES_PER_GROUP // turn this off with something new from idf5.1
// ESP32C3 I2S is not supported yet due to significant changes to interface
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2)

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ License along with NeoPixel. If not, see
#include "NeoBusChannel.h"
#include "NeoEsp32RmtMethod.h"

#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6)
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2)


// translate NeoPixelBuffer into RMT buffer
Expand Down
2 changes: 1 addition & 1 deletion lib/lib_basic/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ License along with NeoPixel. If not, see

#pragma once

#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6)
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2)

/* General Reference documentation for the APIs used in this implementation
LOW LEVEL: (what is actually used)
Expand Down
35 changes: 14 additions & 21 deletions lib/lib_basic/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Esp32-hal-rmt.c

#include <Arduino.h>

// extern void AddLog(uint32_t loglevel, PGM_P formatP, ...);
extern void AddLog(uint32_t loglevel, PGM_P formatP, ...);

extern "C"
{
Expand All @@ -55,7 +55,7 @@ extern "C"
#include "esp_check.h"
}

#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define RMT_LED_STRIP_RESOLUTION_HZ 40000000 // 40MHz resolution - setting of the "old" driver

typedef struct {
uint32_t resolution; /*!< Encoder resolution, in Hz */
Expand Down Expand Up @@ -124,9 +124,9 @@ static esp_err_t rmt_led_strip_encoder_reset(rmt_encoder_t *encoder)
return ESP_OK;
}

esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder/*, uint32_t bit0, uint32_t bit1*/)
esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder, uint32_t bit0, uint32_t bit1)
{
const char* TAG = "TEST_RMT";
const char* TAG = "TEST_RMT"; //TODO: Remove later
esp_err_t ret = ESP_OK;
rmt_led_strip_encoder_t *led_encoder = NULL;
uint32_t reset_ticks = config->resolution / 1000000 * 50 / 2; // reset code duration defaults to 50us
Expand All @@ -141,16 +141,11 @@ esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rm
led_encoder->base.encode = rmt_encode_led_strip;
led_encoder->base.del = rmt_del_led_strip_encoder;
led_encoder->base.reset = rmt_led_strip_encoder_reset;
// different led strip might have its own timing requirements, following parameter is for WS2812
bytes_encoder_config.bit0.level0 = 1;
bytes_encoder_config.bit0.duration0 = 0.3 * config->resolution / 1000000; // T0H=0.3us
bytes_encoder_config.bit0.level1 = 0;
bytes_encoder_config.bit0.duration1 = 0.9 * config->resolution / 1000000; // T0L=0.9us
bytes_encoder_config.bit1.level0 = 1;
bytes_encoder_config.bit1.duration0 = 0.9 * config->resolution / 1000000; // T0H=0.3us
bytes_encoder_config.bit1.level1 = 0;
bytes_encoder_config.bit1.duration1 = 0.3 * config->resolution / 1000000; // T0L=0.9us
bytes_encoder_config.flags.msb_first = 1; // WS2812 transfer bit order: G7...G0R7...R0B7...B0

bytes_encoder_config.bit0.val = bit0;
bytes_encoder_config.bit1.val = bit1;

bytes_encoder_config.flags.msb_first = 1; // WS2812 transfer bit order: G7...G0R7...R0B7...B0 - TODO: more checks

ESP_GOTO_ON_ERROR(rmt_new_bytes_encoder(&bytes_encoder_config, &led_encoder->bytes_encoder), err, TAG, "create bytes encoder failed");
ESP_GOTO_ON_ERROR(rmt_new_copy_encoder(&copy_encoder_config, &led_encoder->copy_encoder), err, TAG, "create copy encoder failed");
Expand Down Expand Up @@ -226,16 +221,16 @@ class NeoEsp32RmtInvertedSpeedBase : public NeoEsp32RmtSpeed
class NeoEsp32RmtSpeedWs2811 : public NeoEsp32RmtSpeedBase
{
public:
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950);
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950); // TODO: DRAM_ATTR debatable everywhere
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 350);
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
};

class NeoEsp32RmtSpeedWs2812x : public NeoEsp32RmtSpeedBase
{
public:
const uint32_t RmtBit0 = Item32Val(400, 850);
const uint32_t RmtBit1 = Item32Val(800, 450);
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
};

Expand Down Expand Up @@ -530,11 +525,11 @@ template<typename T_SPEED, typename T_CHANNEL> class NeoEsp32RmtMethodBase

_tx_config.loop_count = 0; //no loop

ret += rmt_new_led_strip_encoder(&encoder_config, &_led_encoder);
ret += rmt_new_led_strip_encoder(&encoder_config, &_led_encoder, T_SPEED::RmtBit0, T_SPEED::RmtBit1);

// ESP_LOGI(TAG, "Enable RMT TX channel");
ret += rmt_enable(_channel.RmtChannelNumber);
// AddLog(2,"RMT:initialized with error code: %u on pin: %u",ret, _pin);
AddLog(2,"RMT:initialized with error code: %u on pin: %u",ret, _pin);
}

void Update(bool maintainBufferConsistency)
Expand All @@ -548,9 +543,7 @@ template<typename T_SPEED, typename T_CHANNEL> class NeoEsp32RmtMethodBase
{
// AddLog(2,"__ %u", _sizeData);
// now start the RMT transmit with the editing buffer before we swap
// const uint8_t pixels[3] = {100,100,100};
esp_err_t ret = rmt_transmit(_channel.RmtChannelNumber, _led_encoder, _dataEditing, _sizeData, &_tx_config); // 3 for _sizeData
// esp_err_t ret = rmt_transmit(_channel.RmtChannelNumber, _led_encoder, pixels, 3, &_tx_config);
// AddLog(2,"rmt_transmit: %u", ret);
if (maintainBufferConsistency)
{
Expand Down
Loading