dunno, changes and stuff

This commit is contained in:
2022-07-17 14:47:21 +02:00
parent 331f9f3e6c
commit 07917fe5ba
19 changed files with 1449 additions and 192 deletions

View File

@@ -6,19 +6,22 @@
#include "../../Debug.h"
#include "../../io/GPIO.h"
#include <xtensa/xtruntime.h>
#if ESP8266
#if IS_ESP8266
#include "../../io/fastGPIO.h"
// https://github.com/FastLED/FastLED/tree/master/src/platforms/esp/8266
#include "../../io/GPIO.h"
template <int numLEDs> class WS2812B {
static constexpr const char* NAME = "WS2812B";
#define LED_SET_PIN_TO_OUTPUT GPIO5_OUTPUT_SET
#define LED_SET_PIN_H GPIO5_H
#define LED_SET_PIN_L GPIO5_L
#define LED_SET_PIN_TO_OUTPUT MyGPIO::setOutput(5) //GPIO5_OUTPUT_SET
#define LED_SET_PIN_H MyGPIO::set(5) //GPIO5_H
#define LED_SET_PIN_L MyGPIO::clear(5) //GPIO5_L
//#define NS_PER_TICK ( (1000ul*1000ul*1000ul) / (80ul*1000ul*1000ul) )
@@ -37,7 +40,7 @@
void init() {
LED_SET_PIN_TO_OUTPUT;
debugMod1(NAME, "init with %d leds", numLEDs);
Log::addInfo(NAME, "init with %d leds", numLEDs);
}
/** set the color for the given LED */
@@ -74,12 +77,16 @@
}
/** flush configured changes */
void flush() {
IRAM_ATTR void flush() {
LED_SET_PIN_TO_OUTPUT;
ets_intr_lock();
//LED_SET_PIN_TO_OUTPUT;
//ets_intr_lock();
//taskENTER_CRITICAL();
//taskDISABLE_INTERRUPTS();
//const uint32_t saved = XTOS_DISABLE_ALL_INTERRUPTS;
vPortETSIntrLock();
// process each LED
for (int i = 0; i < numLEDs; ++i) {
@@ -97,19 +104,29 @@
}
ets_intr_unlock();
//ets_intr_unlock();
//taskEXIT_CRITICAL();
//XTOS_RESTORE_INTLEVEL(saved);
vPortETSIntrUnlock();
//taskENABLE_INTERRUPTS();
reset();
}
/** flush configured changes, including global brightness */
void flushBrightness(const uint8_t brightness) {
IRAM_ATTR void flushBrightness(const uint8_t brightness) {
LED_SET_PIN_TO_OUTPUT;
ets_intr_lock();
//LED_SET_PIN_TO_OUTPUT;
//ets_intr_lock();
//taskENTER_CRITICAL();
taskDISABLE_INTERRUPTS();
//const uint32_t saved = XTOS_DISABLE_ALL_INTERRUPTS;
//vPortETSIntrLock();
// process each LED
for (int i = 0; i < numLEDs; ++i) {
@@ -127,122 +144,79 @@
}
ets_intr_unlock();
//ets_intr_unlock();
taskENABLE_INTERRUPTS();
//taskEXIT_CRITICAL();
//XTOS_RESTORE_INTLEVEL(saved);
//vPortETSIntrUnlock();
reset();
}
private:
inline void sendByte(uint8_t b) {
// for (uint8_t i = 0; i < 8; ++i) {
// if (b & 0b10000000) {
// send1();
// } else {
// send0();
// }
// b <<= 1;
// }
if (b & 0b10000000) {send1();} else {send0();}
if (b & 0b01000000) {send1();} else {send0();}
if (b & 0b00100000) {send1();} else {send0();}
if (b & 0b00010000) {send1();} else {send0();}
if (b & 0b00001000) {send1();} else {send0();}
if (b & 0b00000100) {send1();} else {send0();}
if (b & 0b00000010) {send1();} else {send0();}
if (b & 0b00000001) {send1();} else {send0();}
IRAM_ATTR void sendByte(uint8_t b) {
//if (b & 0b10000000) {send1();} else {send0();}
//if (b & 0b01000000) {send1();} else {send0();}
//if (b & 0b00100000) {send1();} else {send0();}
//if (b & 0b00010000) {send1();} else {send0();}
//if (b & 0b00001000) {send1();} else {send0();}
//if (b & 0b00000100) {send1();} else {send0();}
//if (b & 0b00000010) {send1();} else {send0();}
//if (b & 0b00000001) {send1();} else {send0();}
for (uint8_t i = 0; i < 8; ++i) {
if (b & 0b10000000) {send1();} else {send0();}
b <<= 1;
}
}
__attribute__((always_inline)) inline void send1() { // 800ns high, 450ns low
// @80 MHz one instruction = 12.5ns
// @160 MHz one instruction = 6.25ns
__attribute__((always_inline)) void send1() { // 800ns high, 450ns low
LED_SET_PIN_H;
delay800();
delayL();
LED_SET_PIN_L;
delay100();
delayS();
//const uint32_t tmp = soc_get_ccount();
//LED_SET_PIN_H;
//while(soc_get_ccount() - tmp < 144) {}
//LED_SET_PIN_L;
//while(soc_get_ccount() - tmp < 192-24) {}
}
__attribute__((always_inline)) inline void send0() { // 400ns high, 850ns low
__attribute__((always_inline)) void send0() { // 400ns high, 850ns low
LED_SET_PIN_H;
delay100();
delayS();
LED_SET_PIN_L;
delay800();
delayL();
//const uint32_t tmp = soc_get_ccount();
//LED_SET_PIN_H;
//while(soc_get_ccount() - tmp < 48) {}
//LED_SET_PIN_L;
//while(soc_get_ccount() - tmp < 192-24) {}
}
__attribute__((always_inline)) inline void reset() {
LED_SET_PIN_L;
os_delay_us(50);
__attribute__((always_inline)) void reset() {
LED_SET_PIN_L; // low for more than 50 us
//const uint32_t tmp = soc_get_ccount();
//while(soc_get_ccount() - tmp < 9999) {}
//os_delay_us(100);
//LED_SET_PIN_H;
//asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
//LED_SET_PIN_L;
//delayMicroseconds(50);
}
//#pragma GCC optimize 0
__attribute__((always_inline)) inline void delay50() {
asm volatile("nop");
asm volatile("nop");
asm volatile("nop");
asm volatile("nop");
__attribute__((always_inline)) void delayS() {
for(uint8_t i = 0; i < (9*1); ++i) {asm("nop");}
}
// 100 ns delay. @80 MHz one nop = 12,5ns
__attribute__((always_inline)) inline void delay100() {
delay50();
delay50();
__attribute__((always_inline)) void delayL() {
for(uint8_t i = 0; i < (9*2); ++i) {asm("nop");}
}
/*
__attribute__((always_inline)) inline void delay200() {
delay100();
delay100();
}
__attribute__((always_inline)) inline void delay400() {
delay100();
delay100();
delay100();
delay100();
}
__attribute__((always_inline)) inline void delay500() {
delay100();
delay100();
delay100();
delay100();
delay100();
}
__attribute__((always_inline)) inline void delay600() {
delay100();
delay100();
delay100();
delay100();
delay100();
delay100();
}
*/
__attribute__((always_inline)) inline void delay800() {
delay100();
delay100();
delay100();
delay100();
delay100();
delay100();
delay100();
delay100();
}
// #pragma GCC reset_options
// inline void delayNS(const uint16_t ns) {
// const uint16_t ticks = ns / NS_PER_TICK / 2;
// for (uint16_t i = 0; i < ticks; ++i) {asm("nop");}
// }
};
#elif false// ESP32aaa
@@ -452,7 +426,7 @@
};
#elif ESP32
#elif IS_ESP32
#include "../../io/I2S.h"
@@ -474,7 +448,7 @@
}
void init() {
debugMod1(TAG, "init with %d leds", NUM_LEDS);
Log::addInfo(TAG, "init with %d leds", NUM_LEDS);
cfg();
}