добавлена проверка - не превышает ли номер вывода из аргумента функции общее кол-во выводов
This commit is contained in:
1 parent
5b2e2eb1d5
commit
fbaa4b931a
11 files changed
+171
-96
No files matched your search
@@ -19,7 +19,13 @@ NeoPixel::~NeoPixel() {
|
||||
}
|
||||
|
||||
void NeoPixel::begin(void) {
|
||||
if (pin >= 0) {
|
||||
if (pin >= 0)
|
||||
{
|
||||
if (pin >= pinCommonQty())
|
||||
{
|
||||
ErrorMsgHandler("NeoPixel.begin(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW);
|
||||
}
|
||||
@@ -58,59 +64,62 @@ void NeoPixel::updateType(neoPixelType t) {
|
||||
static void __attribute__((noinline, section(".ram_text"))) mik32Show(GPIO_TypeDef* m_port, uint32_t m_pin, uint8_t* pixels, uint32_t numBytes, bool is800KHz) {
|
||||
// not support 400khz
|
||||
if (!is800KHz) return;
|
||||
|
||||
volatile uint32_t* set = &m_port->SET;
|
||||
volatile uint32_t* clr = &m_port->CLEAR;
|
||||
|
||||
uint8_t* ptr = pixels;
|
||||
uint8_t* end = ptr + numBytes;
|
||||
uint8_t p = *ptr++;
|
||||
uint8_t bitMask = 0x80;
|
||||
|
||||
noInterrupts();
|
||||
|
||||
while (1) {
|
||||
if (p & bitMask) { // ONE
|
||||
// High 800ns - 25,6 tick
|
||||
*set = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop; nop; nop; nop;"
|
||||
"nop; nop; nop; nop; nop; nop; nop; nop;"
|
||||
"nop; nop; nop; nop;"
|
||||
);
|
||||
if ((m_port != NULL) && (m_pin != NC))
|
||||
{
|
||||
volatile uint32_t* set = &m_port->SET;
|
||||
volatile uint32_t* clr = &m_port->CLEAR;
|
||||
|
||||
// Low 450ns - 14,4 tick
|
||||
*clr = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop;"
|
||||
);
|
||||
} else { // ZERO
|
||||
// High 400ns - 12,8 tick
|
||||
*set = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop; nop;"
|
||||
);
|
||||
uint8_t* ptr = pixels;
|
||||
uint8_t* end = ptr + numBytes;
|
||||
uint8_t p = *ptr++;
|
||||
uint8_t bitMask = 0x80;
|
||||
|
||||
noInterrupts();
|
||||
|
||||
while (1) {
|
||||
if (p & bitMask) { // ONE
|
||||
// High 800ns - 25,6 tick
|
||||
*set = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop; nop; nop; nop;"
|
||||
"nop; nop; nop; nop; nop; nop; nop; nop;"
|
||||
"nop; nop; nop; nop;"
|
||||
);
|
||||
|
||||
// Low 850ns - 27,2 tick
|
||||
*clr = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop; nop; nop; nop;"
|
||||
"nop; nop; nop;"
|
||||
);
|
||||
}
|
||||
// Low 450ns - 14,4 tick
|
||||
*clr = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop;"
|
||||
);
|
||||
} else { // ZERO
|
||||
// High 400ns - 12,8 tick
|
||||
*set = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop; nop;"
|
||||
);
|
||||
|
||||
if (bitMask >>= 1) {
|
||||
// Move on to the next pixel
|
||||
}
|
||||
else {
|
||||
if (ptr >= end) {
|
||||
break;
|
||||
// Low 850ns - 27,2 tick
|
||||
*clr = m_pin;
|
||||
__asm volatile (
|
||||
"nop; nop; nop; nop; nop; nop; nop; nop;"
|
||||
"nop; nop; nop;"
|
||||
);
|
||||
}
|
||||
|
||||
if (bitMask >>= 1) {
|
||||
// Move on to the next pixel
|
||||
}
|
||||
else {
|
||||
if (ptr >= end) {
|
||||
break;
|
||||
}
|
||||
p = *ptr++;
|
||||
bitMask = 0x80;
|
||||
}
|
||||
p = *ptr++;
|
||||
bitMask = 0x80;
|
||||
}
|
||||
interrupts();
|
||||
}
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void NeoPixel::show(void) {
|
||||
|
||||
Reference in new issue
Block a user