diff options
| author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-08-07 16:03:00 +0300 |
|---|---|---|
| committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-08-07 16:03:00 +0300 |
| commit | f71f37e4269b43222d6b1b812e7109e946345b53 (patch) | |
| tree | f73d4d3dbfb639f5c4c97fe04d88d0f739149239 /esp8266 | |
| parent | c2070d771a70df6ebe19d6ca97b363b2b38d69fa (diff) | |
esp8266/esp_mphal.h: Add mp_hal_ticks_cpu() for reuse.
Diffstat (limited to 'esp8266')
| -rw-r--r-- | esp8266/esp_mphal.h | 6 | ||||
| -rw-r--r-- | esp8266/espneopixel.c | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h index 91fee2119..fa52ae53a 100644 --- a/esp8266/esp_mphal.h +++ b/esp8266/esp_mphal.h @@ -47,6 +47,12 @@ void mp_hal_init(void); void mp_hal_rtc_init(void); uint32_t mp_hal_ticks_us(void); +__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) { + uint32_t ccount; + __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); + return ccount; +} + void mp_hal_delay_us(uint32_t); void mp_hal_set_interrupt_char(int c); uint32_t mp_hal_get_cpu_freq(void); diff --git a/esp8266/espneopixel.c b/esp8266/espneopixel.c index 26776f025..0f12f4c82 100644 --- a/esp8266/espneopixel.c +++ b/esp8266/espneopixel.c @@ -9,16 +9,10 @@ #include "eagle_soc.h" #include "user_interface.h" #include "espneopixel.h" +#include "esp_mphal.h" #define NEO_KHZ400 (1) -static uint32_t _getCycleCount(void) __attribute__((always_inline)); -static inline uint32_t _getCycleCount(void) { - uint32_t ccount; - __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); - return ccount; -} - void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) { uint8_t *p, *end, pix, mask; @@ -49,10 +43,10 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32 for(t = time0;; t = time0) { if(pix & mask) t = time1; // Bit high duration - while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start + 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 = _getCycleCount()) - startTime) < t); // Wait high duration + 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; @@ -60,5 +54,5 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32 mask = 0x80; } } - while((_getCycleCount() - startTime) < period); // Wait for last bit + while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit } |
