Merge pull request #15044 from s-hadinger/berry_leds_rmt_fix

Berry leds rmt fix
This commit is contained in:
s-hadinger 2022-03-06 16:53:22 +01:00 committed by GitHub
commit 4ab9e4a361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 2247 additions and 2102 deletions

View File

@ -59,6 +59,7 @@ extern const bcstring be_const_str_INTERNAL_PDM;
extern const bcstring be_const_str_LVG_X3A_X20call_X20to_X20unsupported_X20callback;
extern const bcstring be_const_str_LVG_X3A_X20object_X3A;
extern const bcstring be_const_str_Leds;
extern const bcstring be_const_str_MAX_RMT;
extern const bcstring be_const_str_MD5;
extern const bcstring be_const_str_None;
extern const bcstring be_const_str_OPTION_A;
@ -220,6 +221,7 @@ extern const bcstring be_const_str__persist_X2Ejson;
extern const bcstring be_const_str__ptr;
extern const bcstring be_const_str__read;
extern const bcstring be_const_str__request_from;
extern const bcstring be_const_str__rmt;
extern const bcstring be_const_str__rules;
extern const bcstring be_const_str__settings_def;
extern const bcstring be_const_str__settings_ptr;
@ -258,6 +260,7 @@ extern const bcstring be_const_str_argument_X20must_X20be_X20a_X20list;
extern const bcstring be_const_str_as;
extern const bcstring be_const_str_asin;
extern const bcstring be_const_str_assert;
extern const bcstring be_const_str_assign_rmt;
extern const bcstring be_const_str_asstring;
extern const bcstring be_const_str_atan;
extern const bcstring be_const_str_atan2;
@ -510,6 +513,7 @@ extern const bcstring be_const_str_instance_size;
extern const bcstring be_const_str_int;
extern const bcstring be_const_str_internal_error;
extern const bcstring be_const_str_introspect;
extern const bcstring be_const_str_invalid_X20GPIO_X20number;
extern const bcstring be_const_str_invalidate;
extern const bcstring be_const_str_io_error;
extern const bcstring be_const_str_ip;
@ -595,6 +599,7 @@ extern const bcstring be_const_str_next;
extern const bcstring be_const_str_next_cron;
extern const bcstring be_const_str_nil;
extern const bcstring be_const_str_no_X20GPIO_X20specified_X20for_X20neopixelbus;
extern const bcstring be_const_str_no_X20more_X20RMT_X20channel_X20available;
extern const bcstring be_const_str_now;
extern const bcstring be_const_str_null_cb;
extern const bcstring be_const_str_number;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
# Native commands
# 00 : ctor (leds:int, gpio:int) -> void
# 00 : ctor (leds:int, gpio:int[, type:int, rmt:int]) -> void
# 01 : begin void -> void
# 02 : show void -> void
# 03 : CanShow void -> bool
@ -29,21 +29,17 @@ class Leds : Leds_ntv
# gpio:int (optional) = GPIO for NeoPixel. If not specified, takes the WS2812 gpio
# type:int (optional) = Type of LED, defaults to WS2812 RGB
# rmt:int (optional) = RMT hardware channel to use, leave default unless you have a good reason
def init(leds, gpio, type, rmt) # rmt is optional
def init(leds, gpio_phy, type, rmt) # rmt is optional
self.gamma = true # gamma is enabled by default, it should be disabled explicitly if needed
self.leds = int(leds)
if gpio == nil && gpio.pin(gpio.WS2812) >= 0
gpio = gpio.pin(gpio.WS2812)
end
# if no GPIO, abort
if gpio == nil
if gpio_phy == nil
raise "valuer_error", "no GPIO specified for neopixelbus"
end
# initialize the structure
self.ctor(self.leds, gpio, type, rmt)
self.ctor(self.leds, gpio_phy, type, rmt)
if self._p == nil raise "internal_error", "couldn't not initialize noepixelbus" end
@ -52,17 +48,57 @@ class Leds : Leds_ntv
end
# assign RMT
static def assign_rmt(gpio_phy)
gpio_phy = int(gpio_phy)
if gpio_phy < 0 raise "value_error", "invalid GPIO number" end
import global
var rmt
# if "_rmt" is not initialized, set to an array of GPIO of size MAX_RMT
if !global.contains("_rmt")
rmt = []
global._rmt = rmt
for i:0..gpio.MAX_RMT-1
rmt.push(-1)
end
# if default WS2812 is set, assign RMT0
if gpio.pin_used(gpio.WS2812, 0)
rmt[0] = gpio.pin(gpio.WS2812, 0)
end
end
rmt = global._rmt
# find an already assigned slot or try to assign a new one
var i = 0
var first_free = -1
while i < gpio.MAX_RMT
var elt = rmt[i]
if elt == gpio_phy return i end # already assigned
if elt < 0 && first_free < 0 first_free = i end # found a free slot
i += 1
end
if first_free >= 0
rmt[first_free] = gpio_phy
return first_free
end
# no more slot
raise "internal_error", "no more RMT channel available"
end
def clear()
self.clear_to(0x000000)
self.show()
end
def ctor(leds, gpio, rmt)
if rmt == nil
self.call_native(0, leds, gpio)
else
self.call_native(0, leds, gpio, rmt)
def ctor(leds, gpio_phy, type, rmt)
if type == nil
type = self.WS2812_GRB
end
if rmt == nil
rmt = self.assign_rmt(gpio_phy)
end
self.call_native(0, leds, gpio_phy, type, rmt)
end
def begin()
self.call_native(1)

View File

@ -14,7 +14,6 @@ const be_const_member_t lv_gpio_constants[] = {
{ "ADC_INPUT", (int32_t) GPIO_ADC_INPUT },
{ "ADC_JOY", (int32_t) GPIO_ADC_JOY },
{ "ADC_LIGHT", (int32_t) GPIO_ADC_LIGHT },
{ "ADC_MQ", (int32_t) GPIO_ADC_MQ },
{ "ADC_PH", (int32_t) GPIO_ADC_PH },
{ "ADC_RANGE", (int32_t) GPIO_ADC_RANGE },
{ "ADC_TEMP", (int32_t) GPIO_ADC_TEMP },
@ -39,6 +38,8 @@ const be_const_member_t lv_gpio_constants[] = {
{ "CC1101_GDO0", (int32_t) GPIO_CC1101_GDO0 },
{ "CC1101_GDO2", (int32_t) GPIO_CC1101_GDO2 },
{ "CHANGE", CHANGE },
{ "CM11_RXD", (int32_t) GPIO_CM11_RXD },
{ "CM11_TXD", (int32_t) GPIO_CM11_TXD },
{ "CNTR1", (int32_t) GPIO_CNTR1 },
{ "CNTR1_NP", (int32_t) GPIO_CNTR1_NP },
{ "CSE7761_RX", (int32_t) GPIO_CSE7761_RX },
@ -130,6 +131,7 @@ const be_const_member_t lv_gpio_constants[] = {
{ "MAX7219CLK", (int32_t) GPIO_MAX7219CLK },
{ "MAX7219CS", (int32_t) GPIO_MAX7219CS },
{ "MAX7219DIN", (int32_t) GPIO_MAX7219DIN },
{ "MAX_RMT", MAX_RMT },
{ "MCP2515_CS", (int32_t) GPIO_MCP2515_CS },
{ "MCP39F5_RST", (int32_t) GPIO_MCP39F5_RST },
{ "MCP39F5_RX", (int32_t) GPIO_MCP39F5_RX },

View File

@ -616,7 +616,7 @@ const uint16_t kGpioNiceList[] PROGMEM = {
AGPIO(GPIO_P9813_CLK), // P9813 CLOCK
AGPIO(GPIO_P9813_DAT), // P9813 DATA
#else
AGPIO(GPIO_WS2812) + MAX_RMT,// WS2812 Led string, using RMT on ESP32
AGPIO(GPIO_WS2812) + (MAX_RMT ? MAX_RMT + 1 : 0),// WS2812 Led string, using RMT on ESP32
#endif // NEO_HW_P9813
#endif
#ifdef USE_ARILUX_RF

View File

@ -90,32 +90,23 @@ extern "C" {
int32_t cmd = be_toint(vm, 2);
if (0 == cmd) { // 00 : ctor (leds:int, gpio:int) -> void
if (!(argc >= 4 && be_isint(vm, 3) && be_isint(vm, 4))) {
if (!(argc >= 6 && be_isint(vm, 3) && be_isint(vm, 4) && be_isint(vm, 5) && be_isint(vm, 6))) {
be_raise(vm, "value_error", "bad arguments for neopixelbus:ctor");
}
int32_t leds = be_toint(vm, 3);
int32_t gpio = be_toint(vm, 4);
int32_t rmt = 0;
int32_t neopixel_type = ws2812_grb;
if (argc >= 5 && !(be_isnil(vm, 5))) {
neopixel_type = be_toint(vm, 5);
}
int32_t neopixel_type = be_toint(vm, 5);
int32_t rmt = be_toint(vm, 6);
if (neopixel_type < 1) { neopixel_type = 1; }
if (neopixel_type >= neopixel_type_end) { neopixel_type = neopixel_type_end - 1; }
if (rmt < 0) { rmt = 0; }
if (rmt >= MAX_RMT) { rmt = MAX_RMT - 1; }
// store type in attribute `_t`
be_pushint(vm, neopixel_type);
be_setmember(vm, 1, "_t");
be_pop(vm, 1);
if (PinUsed(GPIO_WS2812)) {
rmt = 1; // if WS2812 is already configured by Tasmota UI, we switch to RMT1
}
if (argc >= 6 && !(be_isnil(vm, 6))) {
rmt = be_toint(vm, 6); // if arg5, then RMT channel is specified
}
if (rmt < 0) { rmt = 0; }
if (rmt >= MAX_RMT) { rmt = MAX_RMT - 1; }
void * strip = nullptr;
switch (neopixel_type) {
case ws2812_grb: strip = new neopixel_ws2812_grb_t(leds, gpio, (NeoBusChannel) rmt);

View File

@ -17,6 +17,8 @@ RISING
FALLING
CHANGE
MAX_RMT
NONE = GPIO_NONE
KEY1 = GPIO_KEY1
KEY1_NP = GPIO_KEY1_NP