Jesus Christ / Mbed 2 deprecated ws2811_Izebel

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SimpleWS2811.cpp Source File

SimpleWS2811.cpp

00001 #include "ws2811BitBang.h"
00002 
00003 static inline void send0(DigitalOut& ws2811Data){
00004     ws2811Data=1;
00005     WAIT0H();
00006     ws2811Data=0;
00007     WAIT0L();
00008 }
00009 static inline void send1(DigitalOut& ws2811Data){
00010     ws2811Data=1;
00011     WAIT1H();
00012     ws2811Data=0;
00013     WAIT1L();
00014 }
00015 
00016 static inline void sendByte(uint8_t b, DigitalOut& ws2811Data){
00017     for(int i=0;i<8;i++){
00018         if(b & (uint8_t)0x80){
00019             send1(ws2811Data);
00020         }else{
00021             send0(ws2811Data);
00022         }
00023         b = b << 1;
00024     }
00025 }
00026 
00027 static inline void sendLED(uint8_t red, uint8_t green, uint8_t blue,DigitalOut& ws2811Data){
00028     sendByte(red,ws2811Data);
00029     sendByte(green,ws2811Data);
00030     sendByte(blue,ws2811Data);
00031 }
00032 
00033 static inline void sendLED(uint8_t *p,DigitalOut& ws2811Data){
00034     sendLED(*p,*(p+1), *(p+2),ws2811Data);
00035 }
00036 
00037 void sendBuffer(uint8_t* rgbBuf,size_t len,DigitalOut& ws2812Data){
00038     __disable_irq();
00039     for(size_t i=0;i<len;i++){
00040         sendLED(rgbBuf+3*i,ws2812Data);
00041     }
00042     __enable_irq();
00043 }