Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for OpenCR board of Turtlebot3 #342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions Adafruit_NeoPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,21 +2353,21 @@ void Adafruit_NeoPixel::show(void) {
XMC_GPIO_PORT_t* XMC_port = mapping_port_pin[ pin ].port;
uint8_t XMC_pin = mapping_port_pin[ pin ].pin;

uint32_t omrhigh = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_HIGH << XMC_pin;
uint32_t omrlow = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_LOW << XMC_pin;
uint32_t omrhigh = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_HIGH << XMC_pin;
uint32_t omrlow = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_LOW << XMC_pin;

#ifdef NEO_KHZ400 // 800 KHz check needed only if 400 KHz support enabled
if(is800KHz) {
#endif
for(;;) {
XMC_port->OMR = omrhigh;
XMC_port->OMR = omrhigh;
asm("nop; nop; nop; nop;");
if(p & bitMask) {
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop;");
XMC_port->OMR = omrlow;
XMC_port->OMR = omrlow;
} else {
XMC_port->OMR = omrlow;
XMC_port->OMR = omrlow;
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop;");
}
Expand Down Expand Up @@ -2697,7 +2697,7 @@ if(is800KHz) {
// ToDo!
}
#endif
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32)
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) || defined(__OPENCR__)
uint8_t *p = pixels, *end = p + numBytes, pix = *p++, mask = 0x80;
uint32_t cyc;
uint32_t saveLoad = SysTick->LOAD, saveVal = SysTick->VAL;
Expand All @@ -2707,14 +2707,24 @@ if(is800KHz) {
uint32_t top = (F_CPU / 800000); // 1.25µs
uint32_t t0 = top - (F_CPU / 2500000); // 0.4µs
uint32_t t1 = top - (F_CPU / 1250000); // 0.8µs

SysTick->LOAD = top - 1; // Config SysTick for NeoPixel bit freq
SysTick->VAL = 0; // Set to start value
for (;;) {
LL_GPIO_SetOutputPin(gpioPort, gpioPin);
#if defined(__OPENCR__)
digitalWrite(pin,HIGH);
#else
LL_GPIO_SetOutputPin(gpioPort, gpioPin);
#endif
cyc = (pix & mask) ? t1 : t0;

while (SysTick->VAL > cyc)
;
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
#if defined(__OPENCR__)
digitalWrite(pin,LOW);
#else
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
#endif
if (!(mask >>= 1)) {
if (p >= end)
break;
Expand All @@ -2727,16 +2737,27 @@ if(is800KHz) {
#if defined(NEO_KHZ400)
} else { // 400 kHz bitstream
uint32_t top = (F_CPU / 400000); // 2.5µs
uint32_t t0 = top - (F_CPU / 2000000); // 0.5µs
uint32_t t1 = top - (F_CPU / 833333); // 1.2µs
SysTick->LOAD = top - 1; // Config SysTick for NeoPixel bit freq
#ifndef __OPENCR__
uint32_t t0 = top - (F_CPU / 2000000); // 0.5µs
uint32_t t1 = top - (F_CPU / 833333); // 1.2µs
#endif
SysTick->LOAD = top -1; // Config SysTick for NeoPixel bit freq
SysTick->VAL = 0; // Set to start value
for (;;) {
LL_GPIO_SetOutputPin(gpioPort, gpioPin);
cyc = (pix & mask) ? t1 : t0;
#if defined(__OPENCR__)
digitalWrite(pin,HIGH);
cyc = (pix & mask) ;
#else
LL_GPIO_SetOutputPin(gpioPort, gpioPin);
cyc = (pix & mask) ? t1 : t0;
#endif
while (SysTick->VAL > cyc)
;
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
#if defined(__OPENCR__)
digitalWrite(pin,LOW);
#else
LL_GPIO_ResetOutputPin(gpioPort, gpioPin);
#endif
if (!(mask >>= 1)) {
if (p >= end)
break;
Expand Down