diff --git a/src/internal/Esp32_i2s.c b/src/internal/Esp32_i2s.c index 5a33e73..0c0612b 100644 --- a/src/internal/Esp32_i2s.c +++ b/src/internal/Esp32_i2s.c @@ -104,7 +104,7 @@ bool i2sInitDmaItems(uint8_t bus_num) { } if (I2S[bus_num].dma_items == NULL) { - I2S[bus_num].dma_items = (i2s_dma_item_t*)malloc(I2S[bus_num].dma_count* sizeof(i2s_dma_item_t)); + I2S[bus_num].dma_items = (i2s_dma_item_t*)(malloc(I2S[bus_num].dma_count* sizeof(i2s_dma_item_t))); if (I2S[bus_num].dma_items == NULL) { log_e("MEM ERROR!"); return false; @@ -127,7 +127,7 @@ bool i2sInitDmaItems(uint8_t bus_num) { item->next = &I2S[bus_num].dma_items[i2]; item->free_ptr = NULL; if (I2S[bus_num].dma_buf_len) { - item->buf = (uint8_t*)malloc(I2S[bus_num].dma_buf_len); + item->buf = (uint8_t*)(malloc(I2S[bus_num].dma_buf_len)); if (item->buf == NULL) { log_e("MEM ERROR!"); for(a=0; abus->int_st.out_eof) { - i2s_dma_item_t* item = (i2s_dma_item_t*)dev->bus->out_eof_des_addr; + i2s_dma_item_t* item = (i2s_dma_item_t*)(dev->bus->out_eof_des_addr); item->data = dev->silence_buf; item->blocksize = dev->silence_len; item->datalen = dev->silence_len; diff --git a/src/internal/NeoArmMethod.h b/src/internal/NeoArmMethod.h index 3b83964..9cfce88 100644 --- a/src/internal/NeoArmMethod.h +++ b/src/internal/NeoArmMethod.h @@ -144,6 +144,15 @@ public: static const uint32_t ResetTimeUs = 50; }; +class NeoArmMk20dxSpeedPropsApa106 +{ +public: + static const uint32_t CyclesT0h = (F_CPU / 4000000); + static const uint32_t CyclesT1h = (F_CPU / 913750); + static const uint32_t Cycles = (F_CPU / 584800); + static const uint32_t ResetTimeUs = 50; +}; + template class NeoArmMk20dxSpeedBase { public: @@ -190,9 +199,11 @@ public: typedef NeoArmMethodBase> NeoArmWs2812xMethod; typedef NeoArmMethodBase> NeoArmSk6812Method; +typedef NeoArmMethodBase> NeoArmApa106Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; typedef NeoArmMethodBase> NeoArm400KbpsMethod; + #elif defined(__MKL26Z64__) // Teensy-LC #if F_CPU == 48000000 @@ -308,6 +319,7 @@ public: typedef NeoArmMethodBase NeoArmWs2812xMethod; typedef NeoArmMethodBase NeoArmSk6812Method; typedef NeoArmMethodBase NeoArm800KbpsMethod; +typedef NeoArm800KbpsMethod NeoArmApa106Method #else #error "Teensy-LC: Sorry, only 48 MHz is supported, please set Tools > CPU Speed to 48 MHz" @@ -443,6 +455,7 @@ typedef NeoArmMethodBase> NeoArmSk6812Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; typedef NeoArmMethodBase> NeoArm400KbpsMethod; +typedef NeoArm400KbpsMethod NeoArmApa106Method #elif defined(ARDUINO_STM32_FEATHER) || defined(ARDUINO_ARCH_STM32L4) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32F1)// FEATHER WICED (120MHz) @@ -622,6 +635,7 @@ public: typedef NeoArmMethodBase> NeoArmWs2812xMethod; typedef NeoArmMethodBase> NeoArmSk6812Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; +typedef NeoArm800KbpsMethod NeoArmApa106Method; #else // Other ARM architecture -- Presumed Arduino Due @@ -744,6 +758,7 @@ typedef NeoArmMethodBase> Neo typedef NeoArmMethodBase> NeoArmSk6812Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; typedef NeoArmMethodBase> NeoArm400KbpsMethod; +typedef NeoArm400KbpsMethod NeoArmApa106Method; #endif @@ -754,6 +769,7 @@ typedef NeoArmWs2812xMethod NeoWs2812xMethod; typedef NeoArmSk6812Method NeoSk6812Method; typedef NeoArmSk6812Method NeoLc8812Method; typedef NeoArm800KbpsMethod NeoWs2812Method; +typedef NeoArmApa106Method NeoApa106Method; typedef NeoArmWs2812xMethod Neo800KbpsMethod; #ifdef NeoArm400KbpsMethod // this is needed due to missing 400Kbps for some platforms typedef NeoArm400KbpsMethod Neo400KbpsMethod; diff --git a/src/internal/NeoAvrMethod.h b/src/internal/NeoAvrMethod.h index 7b44ee8..b292cf4 100644 --- a/src/internal/NeoAvrMethod.h +++ b/src/internal/NeoAvrMethod.h @@ -199,12 +199,14 @@ typedef NeoAvrMethodBase NeoAvrSk6812Method; typedef NeoAvrMethodBase NeoAvr800KbpsMethod; typedef NeoAvrMethodBase NeoAvr400KbpsMethod; + // AVR doesn't have alternatives yet, so there is just the default typedef NeoAvrWs2812xMethod NeoWs2813Method; typedef NeoAvrWs2812xMethod NeoWs2812xMethod; typedef NeoAvr800KbpsMethod NeoWs2812Method; typedef NeoAvrSk6812Method NeoSk6812Method; typedef NeoAvrSk6812Method NeoLc8812Method; +typedef NeoAvr400KbpsMethod NeoApa106Method; typedef NeoAvrWs2812xMethod Neo800KbpsMethod; typedef NeoAvr400KbpsMethod Neo400KbpsMethod; diff --git a/src/internal/NeoEsp32I2sMethod.h b/src/internal/NeoEsp32I2sMethod.h index 9e5f5f6..2883e94 100644 --- a/src/internal/NeoEsp32I2sMethod.h +++ b/src/internal/NeoEsp32I2sMethod.h @@ -97,10 +97,10 @@ public: _i2sBufferSize += 4 - alignment; } - _pixels = (uint8_t*)malloc(_pixelsSize); + _pixels = static_cast(malloc(_pixelsSize)); memset(_pixels, 0x00, _pixelsSize); - _i2sBuffer = (uint8_t*)malloc(_i2sBufferSize); + _i2sBuffer = static_cast(malloc(_i2sBufferSize)); memset(_i2sBuffer, 0x00, _i2sBufferSize); } @@ -170,7 +170,7 @@ private: 0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110, }; - uint16_t* pDma = (uint16_t*)_i2sBuffer; + uint16_t* pDma = reinterpret_cast(_i2sBuffer); uint8_t* pPixelsEnd = _pixels + _pixelsSize; for (uint8_t* pPixel = _pixels; pPixel < pPixelsEnd; pPixel++) { @@ -184,11 +184,13 @@ typedef NeoEsp32I2sMethodBase NeoEs typedef NeoEsp32I2sMethodBase NeoEsp32I2s0Sk6812Method; typedef NeoEsp32I2sMethodBase NeoEsp32I2s0800KbpsMethod; typedef NeoEsp32I2sMethodBase NeoEsp32I2s0400KbpsMethod; +typedef NeoEsp32I2s0400KbpsMethod NeoEsp32I2s0Apa106Method; typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Ws2812xMethod; typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Sk6812Method; typedef NeoEsp32I2sMethodBase NeoEsp32I2s1800KbpsMethod; typedef NeoEsp32I2sMethodBase NeoEsp32I2s1400KbpsMethod; +typedef NeoEsp32I2s1400KbpsMethod NeoEsp32I2s1Apa106Method; // I2s Bus 1 method is the default method for Esp32 typedef NeoEsp32I2s1Ws2812xMethod NeoWs2813Method; @@ -196,6 +198,7 @@ typedef NeoEsp32I2s1Ws2812xMethod NeoWs2812xMethod; typedef NeoEsp32I2s1800KbpsMethod NeoWs2812Method; typedef NeoEsp32I2s1Sk6812Method NeoSk6812Method; typedef NeoEsp32I2s1Sk6812Method NeoLc8812Method; +typedef NeoEsp32I2s1Apa106Method NeoApa106Method; typedef NeoEsp32I2s1Ws2812xMethod Neo800KbpsMethod; typedef NeoEsp32I2s1400KbpsMethod Neo400KbpsMethod; diff --git a/src/internal/NeoEsp32RmtMethod.h b/src/internal/NeoEsp32RmtMethod.h index ebbbf25..7e37f0f 100644 --- a/src/internal/NeoEsp32RmtMethod.h +++ b/src/internal/NeoEsp32RmtMethod.h @@ -103,6 +103,14 @@ public: const static uint16_t RmtDurationReset = FromNs(50000); // 50us }; +class NeoEsp32RmtSpeedApa106 : public NeoEsp32RmtSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(400, 1400); + const static uint32_t RmtBit1 = Item32Val(1400, 400); + const static uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + class NeoEsp32RmtChannel0 { public: @@ -159,10 +167,10 @@ public: { _pixelsSize = pixelCount * elementSize; - _pixelsEditing = (uint8_t*)malloc(_pixelsSize); + _pixelsEditing = static_cast(malloc(_pixelsSize)); memset(_pixelsEditing, 0x00, _pixelsSize); - _pixelsSending = (uint8_t*)malloc(_pixelsSize); + _pixelsSending = static_cast(malloc(_pixelsSize)); // no need to initialize it, it gets overwritten on every send } @@ -267,7 +275,7 @@ private: size_t size = 0; size_t num = 0; - uint8_t *psrc = (uint8_t *)src; + const uint8_t* psrc = static_cast(src); rmt_item32_t* pdest = dest; for (;;) @@ -309,41 +317,49 @@ private: typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsMethod; diff --git a/src/internal/NeoEsp8266DmaMethod.h b/src/internal/NeoEsp8266DmaMethod.h index b755ff8..402c9ae 100644 --- a/src/internal/NeoEsp8266DmaMethod.h +++ b/src/internal/NeoEsp8266DmaMethod.h @@ -100,6 +100,15 @@ public: const static uint32_t ResetTimeUs = 50; }; +class NeoEsp8266DmaSpeedApa106 +{ +public: + const static uint32_t I2sClockDivisor = 4; + const static uint32_t I2sBaseClockDivisor = 16; + const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element + const static uint32_t ResetTimeUs = 50; +}; + enum NeoDmaState { NeoDmaState_Idle, @@ -435,6 +444,7 @@ typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaWs2812xM typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaSk6812Method; typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma800KbpsMethod; typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma400KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaApa106Method; // Dma method is the default method for Esp8266 typedef NeoEsp8266DmaWs2812xMethod NeoWs2813Method; @@ -442,6 +452,7 @@ typedef NeoEsp8266DmaWs2812xMethod NeoWs2812xMethod; typedef NeoEsp8266Dma800KbpsMethod NeoWs2812Method; typedef NeoEsp8266DmaSk6812Method NeoSk6812Method; typedef NeoEsp8266DmaSk6812Method NeoLc8812Method; +typedef NeoEsp8266DmaApa106Method NeoApa106Method; typedef NeoEsp8266DmaWs2812xMethod Neo800KbpsMethod; typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod; diff --git a/src/internal/NeoEsp8266UartMethod.h b/src/internal/NeoEsp8266UartMethod.h index 1b2c6c5..d45436b 100644 --- a/src/internal/NeoEsp8266UartMethod.h +++ b/src/internal/NeoEsp8266UartMethod.h @@ -309,6 +309,16 @@ public: static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update }; +// NeoEsp8266UartSpeedApa106 contains the timing constant used to get NeoPixelBus running for Apa106 +// Pulse cycle = 1.71 = 1.368 longer than normal, 0.731 slower, NeoEsp8266UartSpeedApa1066 +class NeoEsp8266UartSpeedApa106 +{ +public: + static const uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element at 400khz speed + static const uint32_t UartBaud = 2339181; // APA106 pulse cycle of 1.71us, 4 serial bytes per NeoByte + static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update +}; + // NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that // implements the methods needed to operate as a NeoPixelBus method. template @@ -376,6 +386,7 @@ private: // uart 0 typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0Ws2812xMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0Apa106Method; typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0800KbpsMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0400KbpsMethod; @@ -386,6 +397,7 @@ typedef NeoEsp8266Uart0Sk6812Method NeoEsp8266Uart0Lc8812Method; // uart 1 typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1Ws2812xMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1Apa106Method; typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1800KbpsMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1400KbpsMethod; @@ -396,6 +408,7 @@ typedef NeoEsp8266Uart1Sk6812Method NeoEsp8266Uart1Lc8812Method; // uart 0 async typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0Ws2812xMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0Apa106Method; typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0800KbpsMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0400KbpsMethod; @@ -406,6 +419,7 @@ typedef NeoEsp8266AsyncUart0Sk6812Method NeoEsp8266AsyncUart0Lc8812Method; // uart 1 async typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1Ws2812xMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1Apa106Method; typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1800KbpsMethod; typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1400KbpsMethod; diff --git a/src/internal/NeoEspBitBangMethod.h b/src/internal/NeoEspBitBangMethod.h index d832df9..77e3434 100644 --- a/src/internal/NeoEspBitBangMethod.h +++ b/src/internal/NeoEspBitBangMethod.h @@ -176,6 +176,7 @@ typedef NeoEspBitBangMethodBase NeoEsp32BitBang400Kbp typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2813Method; typedef NeoEsp32BitBang800KbpsMethod NeoEsp32BitBangWs2812Method; typedef NeoEsp32BitBangSk6812Method NeoEsp32BitBangLc8812Method; +typedef NeoEsp32BitBang400KbpsMethod NeoEsp32BitBangApa106Method; #else @@ -187,6 +188,7 @@ typedef NeoEspBitBangMethodBase NeoEsp8266BitBang400K typedef NeoEsp8266BitBangWs2812xMethod NeoEsp32BitBangWs2813Method; typedef NeoEsp8266BitBang800KbpsMethod NeoEsp32BitBangWs2812Method; typedef NeoEsp8266BitBangSk6812Method NeoEsp32BitBangLc8812Method; +typedef NeoEsp8266BitBang400KbpsMethod NeoEsp32BitBangApa106Method; #endif // ESP bitbang doesn't have defaults and should avoided except for testing