Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit f71f37e

Browse files
committed
esp8266/esp_mphal.h: Add mp_hal_ticks_cpu() for reuse.
1 parent c2070d7 commit f71f37e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

esp8266/esp_mphal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ void mp_hal_init(void);
4747
void mp_hal_rtc_init(void);
4848

4949
uint32_t mp_hal_ticks_us(void);
50+
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
51+
uint32_t ccount;
52+
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
53+
return ccount;
54+
}
55+
5056
void mp_hal_delay_us(uint32_t);
5157
void mp_hal_set_interrupt_char(int c);
5258
uint32_t mp_hal_get_cpu_freq(void);

esp8266/espneopixel.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99
#include "eagle_soc.h"
1010
#include "user_interface.h"
1111
#include "espneopixel.h"
12+
#include "esp_mphal.h"
1213

1314
#define NEO_KHZ400 (1)
1415

15-
static uint32_t _getCycleCount(void) __attribute__((always_inline));
16-
static inline uint32_t _getCycleCount(void) {
17-
uint32_t ccount;
18-
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
19-
return ccount;
20-
}
21-
2216
void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) {
2317

2418
uint8_t *p, *end, pix, mask;
@@ -49,16 +43,16 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32
4943

5044
for(t = time0;; t = time0) {
5145
if(pix & mask) t = time1; // Bit high duration
52-
while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start
46+
while(((c = mp_hal_ticks_cpu()) - startTime) < period); // Wait for bit start
5347
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
5448
startTime = c; // Save start time
55-
while(((c = _getCycleCount()) - startTime) < t); // Wait high duration
49+
while(((c = mp_hal_ticks_cpu()) - startTime) < t); // Wait high duration
5650
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
5751
if(!(mask >>= 1)) { // Next bit/byte
5852
if(p >= end) break;
5953
pix = *p++;
6054
mask = 0x80;
6155
}
6256
}
63-
while((_getCycleCount() - startTime) < period); // Wait for last bit
57+
while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
6458
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy