Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ws2812B.cpp
- Revision:
- 2:2d4f2cc38f87
- Parent:
- 1:2d0f84d78ca2
- Child:
- 3:e09aafc9cabe
--- a/ws2812B.cpp Sat Sep 24 06:24:10 2016 +0000
+++ b/ws2812B.cpp Sun Sep 25 10:01:11 2016 +0000
@@ -1,7 +1,7 @@
//----------------------------------------------------
// SPI を使って WS2812B を点灯するためのクラス
//
-// 2016/09/24, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/09/25, Copyright (c) 2016 MIKAMI, Naoki
//----------------------------------------------------
#include "ws2812B.hpp"
@@ -9,40 +9,15 @@
namespace Mikami
{
WS2812B::WS2812B(PinName pin, bool inv)
- : mySpi_(NULL)
+ : SPI(pin, NC, NC), mySpi_((SPI_TypeDef *)_spi.spi)
{
- SPI mbedSpi_(pin, NC, NC); // MOSI, MISO, SCK
-
- struct spi123{PinName pin; SPI_TypeDef *spi; };
-// ピンと SPI 番号の関係
-#ifdef STM32F401xE
- static const spi123 f4xx[] =
- {{ D4, SPI1}, { D11, SPI1}, {PB_15, SPI2},
- { PC_3, SPI2}, {PC_12, SPI3}, { NC, NULL}};
-#else
- static const spi123 f4xx[] =
- {{ D11, SPI1}, { A4, SPI2}, {PB_15, SPI2},
- { PC_3, SPI2}, { A3, SPI3}, { D4, SPI3},
- {PC_12, SPI3}, { NC, NULL}};
-#endif // STM32F401xE
-
- for (int n=0; n<8; n++)
- {
- if (f4xx[n].pin == pin)
- {
- mySpi_ = f4xx[n].spi;
- break;
- }
- if (f4xx[n].pin == NC) break;
- }
-
- mbedSpi_.format(8, 0);
+ format(8, 0);
// クロックを 23 MHz 以下で最大の値に設定
// F401RE: 21.0 MHz
// F446RE: 22.5 MHz
- mbedSpi_.frequency(23000000);
+ frequency(23000000);
- if (!inv) fp = &WS2812B::SendByteNrm;
+ if (!inv) fp = &WS2812B::SendByteNorm;
else fp = &WS2812B::SendByteInv;
}
@@ -57,15 +32,8 @@
}
}
- void WS2812B::Reset()
- {
- Dummy();
- wait_us(50);
- }
-
void WS2812B::Clear(int k)
{
- Reset();
for (int n=0; n<k; n++) Write(0x000000);
Reset();
}
@@ -77,7 +45,7 @@
SendByte(x2);
}
- void WS2812B::SendByteNrm(uint8_t x)
+ void WS2812B::SendByteNorm(uint8_t x)
{
while ((mySpi_->SR & SPI_SR_TXE) != SPI_SR_TXE) {}
mySpi_->DR = x;