diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-02-19 17:22:42 +0100 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-02-19 17:22:42 +0100 |
| commit | f0b62a2b0eef5d6a825d6ca19a8c50f019e2628f (patch) | |
| tree | c15ce4b0fa684efe999d698b9569de5c5266559f | |
| parent | 710b5d8aff2de490c5531e5cbc9092d51fb39958 (diff) | |
Save space by only supporting 800khz neopixels.
| -rw-r--r-- | atmel-samd/common-hal/neopixel_write/__init__.c | 61 | ||||
| -rw-r--r-- | esp8266/common-hal/neopixel_write/__init__.c | 4 | ||||
| -rw-r--r-- | esp8266/espneopixel.c | 19 | ||||
| -rw-r--r-- | esp8266/espneopixel.h | 2 | ||||
| -rw-r--r-- | shared-bindings/neopixel_write/__init__.c | 10 | ||||
| -rw-r--r-- | shared-bindings/neopixel_write/__init__.h | 2 |
6 files changed, 28 insertions, 70 deletions
diff --git a/atmel-samd/common-hal/neopixel_write/__init__.c b/atmel-samd/common-hal/neopixel_write/__init__.c index bb396162d..ff0e99cd8 100644 --- a/atmel-samd/common-hal/neopixel_write/__init__.c +++ b/atmel-samd/common-hal/neopixel_write/__init__.c @@ -30,7 +30,7 @@ #include "asf/common2/services/delay/delay.h" -void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes, bool is800KHz) { +void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) { // This is adapted directly from the Adafruit NeoPixel library SAMD21G18A code: // https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.cpp uint8_t *ptr, *end, p, bitMask; @@ -54,53 +54,22 @@ void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* digitalinout, volatile uint32_t *set = &(port->OUTSET.reg), *clr = &(port->OUTCLR.reg); - if(is800KHz) { - for(;;) { - *set = pinMask; + for(;;) { + *set = pinMask; + asm("nop; nop;"); + if(p & bitMask) { + asm("nop; nop; nop; nop; nop; nop; nop;"); + *clr = pinMask; + } else { + *clr = pinMask; asm("nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop;"); - *clr = pinMask; - } else { - *clr = pinMask; - asm("nop; nop;"); - } - if((bitMask >>= 1) != 0) { - asm("nop; nop; nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } } - } else { // 400 KHz bitstream - for(;;) { - *set = pinMask; - - asm("nop; nop; nop; nop; nop; nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop;"); - *clr = pinMask; - } else { - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop;"); - } - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - if(bitMask >>= 1) { - asm("nop; nop; nop; nop; nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } + if((bitMask >>= 1) != 0) { + asm("nop; nop; nop; nop; nop;"); + } else { + if(ptr >= end) break; + p = *ptr++; + bitMask = 0x80; } } diff --git a/esp8266/common-hal/neopixel_write/__init__.c b/esp8266/common-hal/neopixel_write/__init__.c index efc161256..daaeead43 100644 --- a/esp8266/common-hal/neopixel_write/__init__.c +++ b/esp8266/common-hal/neopixel_write/__init__.c @@ -28,6 +28,6 @@ #include "espneopixel.h" -void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes, bool is800KHz) { - esp_neopixel_write(digitalinout->pin->gpio_number, pixels, numBytes, is800KHz); +void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) { + esp_neopixel_write(digitalinout->pin->gpio_number, pixels, numBytes); } diff --git a/esp8266/espneopixel.c b/esp8266/espneopixel.c index 6c7659186..f3827283d 100644 --- a/esp8266/espneopixel.c +++ b/esp8266/espneopixel.c @@ -16,7 +16,7 @@ #define NEO_KHZ400 (1) -void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) { +void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes) { uint8_t *p, *end, pix, mask; uint32_t t, time0, time1, period, c, startTime, pinMask; @@ -30,19 +30,10 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32 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 + + time0 = fcpu / 2857143; // 0.35us + time1 = fcpu / 1250000; // 0.8us + period = fcpu / 800000; // 1.25us per bit uint32_t irq_state = mp_hal_quiet_timing_enter(); for(t = time0;; t = time0) { diff --git a/esp8266/espneopixel.h b/esp8266/espneopixel.h index 4b20afda5..733c1ce87 100644 --- a/esp8266/espneopixel.h +++ b/esp8266/espneopixel.h @@ -1 +1 @@ -void esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz); +void esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes); diff --git a/shared-bindings/neopixel_write/__init__.c b/shared-bindings/neopixel_write/__init__.c index 73fd803c5..8a75e7419 100644 --- a/shared-bindings/neopixel_write/__init__.c +++ b/shared-bindings/neopixel_write/__init__.c @@ -40,7 +40,7 @@ //| :platform: SAMD21 //| //| The `neopixel_write` module contains a helper method to write out bytes in -//| the neopixel protocol. +//| the 800khz neopixel protocol. //| .. method:: neopixel_write.neopixel_write(digitalinout, buf, is800KHz) //| @@ -48,19 +48,17 @@ //| //| :param ~nativeio.DigitalInOut gpio: the DigitalInOut to output with //| :param bytearray buf: The bytes to clock out. No assumption is made about color order -//| :param bool is800KHz: True if the pixels are 800KHz, otherwise 400KHz is assumed. //| -STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf, mp_obj_t is800k) { +STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) { // Convert parameters into expected types. const nativeio_digitalinout_obj_t *digitalinout = MP_OBJ_TO_PTR(digitalinout_obj); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); // Call platform's neopixel write function with provided buffer and options. - common_hal_neopixel_write(digitalinout, (uint8_t*)bufinfo.buf, bufinfo.len, - mp_obj_is_true(is800k)); + common_hal_neopixel_write(digitalinout, (uint8_t*)bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(neopixel_write_neopixel_write_obj, neopixel_write_neopixel_write_); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(neopixel_write_neopixel_write_obj, neopixel_write_neopixel_write_); STATIC const mp_rom_map_elem_t neopixel_write_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write) }, diff --git a/shared-bindings/neopixel_write/__init__.h b/shared-bindings/neopixel_write/__init__.h index fdf3c38f6..87f85ee01 100644 --- a/shared-bindings/neopixel_write/__init__.h +++ b/shared-bindings/neopixel_write/__init__.h @@ -32,6 +32,6 @@ #include "common-hal/nativeio/types.h" -extern void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* gpio, uint8_t *pixels, uint32_t numBytes, bool is800KHz); +extern void common_hal_neopixel_write(const nativeio_digitalinout_obj_t* gpio, uint8_t *pixels, uint32_t numBytes); #endif |
