добавлена проверка - не превышает ли номер вывода из аргумента функции общее кол-во выводов

This commit is contained in:
klassents committed 2025-02-21 15:43:13 +07:00
1 parent 5b2e2eb1d5
commit fbaa4b931a
11 files changed
+171 -96

No files matched your search

+56 -47
View File
@@ -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) {
@@ -228,6 +228,18 @@ void SoftwareSerial::begin(long speed)
// delays are empirical values here
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
// if pins exceeds the total number of pins, return with zero delays - it blocks further library work
if ((_transmitPin >= pinCommonQty()))
{
ErrorMsgHandler("SoftwareSerial.begin(): Tx pin number exceeds the total number of pins");
return;
}
if ((_receivePin >= pinCommonQty()))
{
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin number exceeds the total number of pins");
return;
}
// limit speed
if (speed > MAX_SOFT_SERIAL_SPEED) speed = MAX_SOFT_SERIAL_SPEED;
if (speed < MIN_SOFT_SERIAL_SPEED) speed = MIN_SOFT_SERIAL_SPEED;