aboutsummaryrefslogtreecommitdiff
path: root/ports/esp8266/espneopixel.c
diff options
context:
space:
mode:
authorDamien George2020-02-27 15:36:53 +1100
committerDamien George2020-02-28 10:33:03 +1100
commit69661f3343bedf86e514337cff63d96cc42f8859 (patch)
treeaf5dfb380ffdb75dda84828f63cf9d840d992f0f /ports/esp8266/espneopixel.c
parent3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff)
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'ports/esp8266/espneopixel.c')
-rw-r--r--ports/esp8266/espneopixel.c84
1 files changed, 47 insertions, 37 deletions
diff --git a/ports/esp8266/espneopixel.c b/ports/esp8266/espneopixel.c
index 6c7659186..d2166a8b0 100644
--- a/ports/esp8266/espneopixel.c
+++ b/ports/esp8266/espneopixel.c
@@ -18,48 +18,58 @@
void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) {
- uint8_t *p, *end, pix, mask;
- uint32_t t, time0, time1, period, c, startTime, pinMask;
+ uint8_t *p, *end, pix, mask;
+ uint32_t t, time0, time1, period, c, startTime, pinMask;
- pinMask = 1 << pin;
- p = pixels;
- end = p + numBytes;
- pix = *p++;
- mask = 0x80;
- startTime = 0;
+ pinMask = 1 << pin;
+ p = pixels;
+ end = p + numBytes;
+ pix = *p++;
+ mask = 0x80;
+ startTime = 0;
- uint32_t fcpu = system_get_cpu_freq() * 1000000;
+ uint32_t fcpu = system_get_cpu_freq() * 1000000;
-#ifdef NEO_KHZ400
- if(is800KHz) {
-#endif
- time0 = fcpu / 2857143; // 0.35us
- time1 = fcpu / 1250000; // 0.8us
- period = fcpu / 800000; // 1.25us per bit
-#ifdef NEO_KHZ400
- } else { // 400 KHz bitstream
- time0 = fcpu / 2000000; // 0.5uS
- time1 = fcpu / 833333; // 1.2us
- period = fcpu / 400000; // 2.5us per bit
- }
-#endif
+ #ifdef NEO_KHZ400
+ if (is800KHz) {
+ #endif
+ time0 = fcpu / 2857143; // 0.35us
+ time1 = fcpu / 1250000; // 0.8us
+ period = fcpu / 800000; // 1.25us per bit
+ #ifdef NEO_KHZ400
+} else { // 400 KHz bitstream
+ time0 = fcpu / 2000000; // 0.5uS
+ time1 = fcpu / 833333; // 1.2us
+ period = fcpu / 400000; // 2.5us per bit
+}
+ #endif
- uint32_t irq_state = mp_hal_quiet_timing_enter();
- for(t = time0;; t = time0) {
- if(pix & mask) t = time1; // Bit high duration
- while(((c = mp_hal_ticks_cpu()) - startTime) < period); // Wait for bit start
- GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
- startTime = c; // Save start time
- while(((c = mp_hal_ticks_cpu()) - startTime) < t); // Wait high duration
- GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
- if(!(mask >>= 1)) { // Next bit/byte
- if(p >= end) break;
- pix = *p++;
- mask = 0x80;
+ uint32_t irq_state = mp_hal_quiet_timing_enter();
+ for (t = time0;; t = time0) {
+ if (pix & mask) {
+ t = time1; // Bit high duration
+ }
+ while (((c = mp_hal_ticks_cpu()) - startTime) < period) {
+ ; // Wait for bit start
+ }
+ GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
+ startTime = c; // Save start time
+ while (((c = mp_hal_ticks_cpu()) - startTime) < t) {
+ ; // Wait high duration
+ }
+ GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
+ if (!(mask >>= 1)) { // Next bit/byte
+ if (p >= end) {
+ break;
+ }
+ pix = *p++;
+ mask = 0x80;
+ }
+ }
+ while ((mp_hal_ticks_cpu() - startTime) < period) {
+ ; // Wait for last bit
}
- }
- while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
- mp_hal_quiet_timing_exit(irq_state);
+ mp_hal_quiet_timing_exit(irq_state);
}
#endif // MICROPY_ESP8266_NEOPIXEL