Skip to content

Commit

Permalink
DM: make crickit turn off neopix
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm1278 committed May 23, 2018
1 parent dfeb187 commit 1309458
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 96 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SOURCES = $(COMMON_SRC) \
bsp/bsp_sercom.cpp \
bsp/bsp_timer.cpp \
bsp/pinmux.cpp \
bsp/bsp_neopix.cpp \
bsp/adafruit_ptc.cpp \

SOBJECTS = $(patsubst %.S,$(BUILD_PATH)/%.o,$(SSOURCES))
Expand Down
7 changes: 7 additions & 0 deletions boards/crickit/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

#define CONFIG_USB 0ul

//turn off the neopixel
#define BOARD_SPECIFIC_INITS { \
gpio_init(PORTA, 27, 1); \
uint32_t __color = 0; \
neopix_show_800k(27, (uint8_t *)&__color, 4);\
};\

//override default activity led pin
#define PIN_ACTIVITY_LED (32 + 22) //PB22

Expand Down
98 changes: 98 additions & 0 deletions bsp/bsp_neopix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "bsp_neopix.h"

void neopix_show_400k(uint32_t pin, uint8_t *pixels, uint16_t numBytes)
{

uint8_t *ptr, *end, p, bitMask;
uint32_t pinMask;

volatile uint32_t *set = &(PORT->Group[PORTA].OUTSET.reg);
volatile uint32_t *clr = &(PORT->Group[PORTA].OUTCLR.reg);
#ifdef HAS_PORTB
if(pin >= 32) {
set = &(PORT->Group[PORTB].OUTSET.reg);
clr = &(PORT->Group[PORTB].OUTCLR.reg);
pin -= 32;
}
#endif

pinMask = 1ul << pin;
ptr = pixels;
end = ptr + numBytes;
p = *ptr++;
bitMask = 0x80;

for(;;) {
*set = pinMask;
asm("nop; nop; nop; nop; 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; 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;
}
}
}

void neopix_show_800k(uint32_t pin, uint8_t *pixels, uint16_t numBytes)
{
uint8_t *ptr, *end, p, bitMask;
uint32_t pinMask;

pinMask = 1ul << pin;
ptr = pixels;
end = ptr + numBytes;
p = *ptr++;
bitMask = 0x80;

volatile uint32_t *set = &(PORT->Group[PORTA].OUTSET.reg);
volatile uint32_t *clr = &(PORT->Group[PORTA].OUTCLR.reg);
#ifdef HAS_PORTB
if(pin >= 32) {
set = &(PORT->Group[PORTB].OUTSET.reg);
clr = &(PORT->Group[PORTB].OUTCLR.reg);
pin -= 32;
}
#endif

for(;;) {
*set = pinMask;
asm("nop; 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; 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;");
}
if(bitMask >>= 1) {
asm("nop; nop; nop; nop; nop; nop; nop; nop; nop;");
} else {
if(ptr >= end) break;
p = *ptr++;
bitMask = 0x80;
}
}
}
98 changes: 2 additions & 96 deletions bsp/bsp_neopix.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,7 @@

#include "PinMap.h"

static void neopix_show_400k(uint32_t pin, uint8_t *pixels, uint16_t numBytes)
{

uint8_t *ptr, *end, p, bitMask;
uint32_t pinMask;

volatile uint32_t *set = &(PORT->Group[PORTA].OUTSET.reg);
volatile uint32_t *clr = &(PORT->Group[PORTA].OUTCLR.reg);
#ifdef HAS_PORTB
if(pin >= 32) {
set = &(PORT->Group[PORTB].OUTSET.reg);
clr = &(PORT->Group[PORTB].OUTCLR.reg);
pin -= 32;
}
#endif

pinMask = 1ul << pin;
ptr = pixels;
end = ptr + numBytes;
p = *ptr++;
bitMask = 0x80;

for(;;) {
*set = pinMask;
asm("nop; nop; nop; nop; 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; 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;
}
}
}

static void neopix_show_800k(uint32_t pin, uint8_t *pixels, uint16_t numBytes)
{
uint8_t *ptr, *end, p, bitMask;
uint32_t pinMask;

pinMask = 1ul << pin;
ptr = pixels;
end = ptr + numBytes;
p = *ptr++;
bitMask = 0x80;

volatile uint32_t *set = &(PORT->Group[PORTA].OUTSET.reg);
volatile uint32_t *clr = &(PORT->Group[PORTA].OUTCLR.reg);
#ifdef HAS_PORTB
if(pin >= 32) {
set = &(PORT->Group[PORTB].OUTSET.reg);
clr = &(PORT->Group[PORTB].OUTCLR.reg);
pin -= 32;
}
#endif

for(;;) {
*set = pinMask;
asm("nop; 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; 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;");
}
if(bitMask >>= 1) {
asm("nop; nop; nop; nop; nop; nop; nop; nop; nop;");
} else {
if(ptr >= end) break;
p = *ptr++;
bitMask = 0x80;
}
}
}
extern void neopix_show_400k(uint32_t pin, uint8_t *pixels, uint16_t numBytes);
extern void neopix_show_800k(uint32_t pin, uint8_t *pixels, uint16_t numBytes);

#endif
5 changes: 5 additions & 0 deletions source/bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "sam.h"
#include "bsp_gpio.h"
#include "bsp_sercom.h"
#include "bsp_neopix.h"

#include "SeesawConfig.h"
#include "Delegate.h"
Expand Down Expand Up @@ -81,6 +82,10 @@ void BspInit() {
eeprom_init();
#endif

#ifdef BOARD_SPECIFIC_INITS
BOARD_SPECIFIC_INITS
#endif

/*
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCLK_CLKCTRL_ID_EIC_Val));
// Enable EIC
Expand Down

0 comments on commit 1309458

Please sign in to comment.