WS2812B Liblary this use SPI
Diff: WS2812B.cpp
- Revision:
- 5:62b6ac21c199
- Parent:
- 4:02e88df0ae2d
- Child:
- 6:21a721b31a20
--- a/WS2812B.cpp Mon Jul 01 00:29:17 2019 +0000 +++ b/WS2812B.cpp Wed Jul 17 14:06:08 2019 +0000 @@ -12,25 +12,20 @@ : spi_(pin, NC, NC), mySpi_((SPI_TypeDef *)pinmap_peripheral(pin, PinMap_SPI_MOSI)) { - spi_.format(9, 0); - // クロックを 23 MHz 以下で最大の値に設定 - // F401RE: 21.0 MHz - // F446RE: 22.5 MHz + spi_.format(8, 0); #if defined(STM32F446xx) spi_.frequency(22500000); -#elif defined(STM32F401xE) - spi_.frequency(21000000); #else #error This code is not move this board. #endif if (!inv) fp = &WS2812B::SendByteNorm; else fp = &WS2812B::SendByteInv; + colors = (uint32_t *)calloc(num,sizeof(uint32_t)); if (colors == NULL) printf("can not reserve memory\n"); bufferSize = num; bright = 1.0; - //printf("buffer : %d\r\n",bufferSize); } uint32_t BrightAdjust(uint32_t x,double brightness) @@ -59,13 +54,13 @@ for (int i = 0; i < bufferSize; i++) { uint32_t x = colors[i]; x = BrightAdjust(x,bright); - //printf("%6x\r\n",x); colors_m[i] = 0; colors_m[i] |= ((x >> 8) & 0xFF00); colors_m[i] |= ((x << 8) & 0xFF0000); colors_m[i] |= (x & 0xFF); } static const uint32_t bit23 = 0x800000; + __disable_irq(); for (int i = 0; i < bufferSize; i++) { for (int n=0; n<24; n++) { if ((colors_m[i] & bit23) == bit23) T1HL(); @@ -74,6 +69,7 @@ } } Reset(); + __enable_irq(); free(colors_m); }