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

Support for GPIO16/D0 #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
38 changes: 32 additions & 6 deletions esp8266.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ void espShow(
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
#endif

#ifdef ESP8266
// compensation for if (pin == ...)
// high 400-410ns low 800-810ns period 1300ns 769kHz
#define COMP_CYCLES 3
#else
#define COMP_CYCLES 0
#endif

#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us
#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us
#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit
Expand All @@ -44,29 +52,47 @@ void espShow(
#ifdef NEO_KHZ400
if(is800KHz) {
#endif
time0 = CYCLES_800_T0H;
time1 = CYCLES_800_T1H;
time0 = CYCLES_800_T0H - COMP_CYCLES;
time1 = CYCLES_800_T1H - COMP_CYCLES;
period = CYCLES_800;
#ifdef NEO_KHZ400
} else { // 400 KHz bitstream
time0 = CYCLES_400_T0H;
time1 = CYCLES_400_T1H;
time0 = CYCLES_400_T0H - COMP_CYCLES;
time1 = CYCLES_400_T1H - COMP_CYCLES;
period = CYCLES_400;
}
#endif

#ifdef ESP8266
uint32_t gpio_clear = 0;
uint32_t gpio_set = 0;
if (pin == 16) {
// reading and writing RTC_GPIO_OUT is too slow inside the loop
gpio_clear = (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe);
gpio_set = gpio_clear | 1;
}
#endif

for(t = time0;; t = time0) {
if(pix & mask) t = time1; // Bit high duration
while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start
#ifdef ESP8266
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
if (pin == 16) {
WRITE_PERI_REG(RTC_GPIO_OUT, gpio_set);
} else {
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
}
#else
gpio_set_level(pin, HIGH);
#endif
startTime = c; // Save start time
while(((c = _getCycleCount()) - startTime) < t); // Wait high duration
#ifdef ESP8266
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
if (pin == 16) {
WRITE_PERI_REG(RTC_GPIO_OUT, gpio_clear);
} else {
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
}
#else
gpio_set_level(pin, LOW);
#endif
Expand Down