Merge pull request #2740 from arturo182/mimxrt10xx_neopixel
mimxrt10xx: Fix neopixel_write
This commit is contained in:
commit
e8cffcf978
@ -32,7 +32,6 @@
|
|||||||
#include "py/mperrno.h"
|
#include "py/mperrno.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "common-hal/microcontroller/Pin.h"
|
||||||
#include "fsl_gpio.h"
|
|
||||||
|
|
||||||
uint64_t next_start_tick_ms = 0;
|
uint64_t next_start_tick_ms = 0;
|
||||||
uint32_t next_start_tick_us = 1000;
|
uint32_t next_start_tick_us = 1000;
|
||||||
@ -45,7 +44,7 @@ uint32_t next_start_tick_us = 1000;
|
|||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC optimize ("Os")
|
#pragma GCC optimize ("Os")
|
||||||
|
|
||||||
void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels,
|
void PLACE_IN_ITCM(common_hal_neopixel_write)(const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels,
|
||||||
uint32_t numBytes) {
|
uint32_t numBytes) {
|
||||||
uint8_t *p = pixels, *end = p + numBytes, pix = *p++, mask = 0x80;
|
uint8_t *p = pixels, *end = p + numBytes, pix = *p++, mask = 0x80;
|
||||||
uint32_t start = 0;
|
uint32_t start = 0;
|
||||||
@ -54,14 +53,10 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
|
|||||||
//assumes 800_000Hz frequency
|
//assumes 800_000Hz frequency
|
||||||
//Theoretical values here are 800_000 -> 1.25us, 2500000->0.4us, 1250000->0.8us
|
//Theoretical values here are 800_000 -> 1.25us, 2500000->0.4us, 1250000->0.8us
|
||||||
//TODO: try to get dynamic weighting working again
|
//TODO: try to get dynamic weighting working again
|
||||||
#ifdef MIMXRT1011_SERIES
|
const uint32_t sys_freq = SystemCoreClock;
|
||||||
uint32_t sys_freq = CLOCK_GetCoreFreq();
|
const uint32_t interval = (sys_freq / MAGIC_800_INT);
|
||||||
#else
|
const uint32_t t0 = (sys_freq / MAGIC_800_T0H);
|
||||||
uint32_t sys_freq = CLOCK_GetAhbFreq();
|
const uint32_t t1 = (sys_freq / MAGIC_800_T1H);
|
||||||
#endif
|
|
||||||
uint32_t interval = sys_freq/MAGIC_800_INT;
|
|
||||||
uint32_t t0 = (sys_freq/MAGIC_800_T0H);
|
|
||||||
uint32_t t1 = (sys_freq/MAGIC_800_T1H);
|
|
||||||
|
|
||||||
// This must be called while interrupts are on in case we're waiting for a
|
// This must be called while interrupts are on in case we're waiting for a
|
||||||
// future ms tick.
|
// future ms tick.
|
||||||
@ -79,9 +74,9 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
cyc = (pix & mask) ? t1 : t0;
|
cyc = (pix & mask) ? t1 : t0;
|
||||||
start = DWT->CYCCNT;
|
start = DWT->CYCCNT;
|
||||||
GPIO_PinWrite(gpio, pin, 1);
|
gpio->DR |= (1U << pin);
|
||||||
while((DWT->CYCCNT - start) < cyc);
|
while((DWT->CYCCNT - start) < cyc);
|
||||||
GPIO_PinWrite(gpio, pin, 0);
|
gpio->DR &= ~(1U << pin);
|
||||||
while((DWT->CYCCNT - start) < interval);
|
while((DWT->CYCCNT - start) < interval);
|
||||||
if(!(mask >>= 1)) {
|
if(!(mask >>= 1)) {
|
||||||
if(p >= end) break;
|
if(p >= end) break;
|
||||||
|
Loading…
Reference in New Issue
Block a user