esp32:direct_pin_data_copy
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| esp32:direct_pin_data_copy [2019/09/26 20:47] – created aistis | esp32:direct_pin_data_copy [2019/09/27 07:34] (current) – aistis | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| copy data from input pin to output pin - example ws8212 data stream | copy data from input pin to output pin - example ws8212 data stream | ||
| - | < | + | fast way to copy read/write register values |
| - | void loop() { | + | |
| - | | + | <code cpp> |
| - | | + | void loop() { |
| - | | + | |
| - | // | + | |
| - | // | + | |
| portDISABLE_INTERRUPTS(); | portDISABLE_INTERRUPTS(); | ||
| - | | + | for(;;) { |
| - | // | + | |
| - | gpio_num_t pin = (gpio_num_t)(25 & 0x1F); | + | if (v1) { |
| - | int state=0; | + | GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, |
| - | register int v1 = digitalRead(25); | + | // |
| - | register int p1 = digitalRead(25); | + | |
| - | | + | |
| - | v1 = (GPIO_REG_READ(GPIO_IN_REG) | + | |
| - | if (v1 != p1) | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| } | } | ||
| - | | + | |
| - | if (cnt2 % 1000000 == 0) { | + | GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, |
| + | //cnt3 ++; | ||
| + | } | ||
| + | cnt3 ++; | ||
| + | if (cnt3 % 1000000 == 0) { | ||
| // | // | ||
| portENABLE_INTERRUPTS(); | portENABLE_INTERRUPTS(); | ||
| + | vTaskDelay(10); | ||
| portDISABLE_INTERRUPTS(); | portDISABLE_INTERRUPTS(); | ||
| - | } | + | } |
| } | } | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | speed is like 3.5 times faster | ||
| + | |||
| + | * 07: | ||
| + | * 07: | ||
| + | |||
| + | < | ||
| + | auto t1 = micros(); | ||
| + | int v1; | ||
| + | for (int i=0; | ||
| + | v1 = (GPIO_REG_READ(GPIO_IN_REG) & BIT(25)); | ||
| + | auto t2 = micros(); | ||
| + | auto t3 = micros(); | ||
| + | for (int i=0; | ||
| + | v1 = digitalRead(25); | ||
| + | auto t4 = micros(); | ||
| + | Serial.printf(" | ||
| + | Serial.printf(" | ||
| </ | </ | ||
esp32/direct_pin_data_copy.1569520069.txt.gz · Last modified: by aistis
