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: WS281X.h
- Revision:
- 46:2374900f8845
- Parent:
- 32:64c391617f6c
--- a/WS281X.h Sat Dec 17 00:23:44 2016 +0000 +++ b/WS281X.h Tue Dec 20 03:22:01 2016 +0000 @@ -1,21 +1,7 @@ /* WS281X.h (for LPC82X/STM32F0x/STM32F446/STM32F746xx) * mbed Microcontroller Library - * Copyright (c) 2016 muetch, t.kuroki, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * Copyright (c) 2016 muetch, t.kuroki + * Allrights reserved. * * Rev 0.97 2016-09-07 * Rev 0.98 2016-09-08 @@ -26,19 +12,14 @@ #ifndef WS281X_H #define WS281X_H -#include "mbed.h" -#include "ColorLib.h" - -//---------------------------------------------------------------------------- -#ifndef MAX_PIXELS -#define MAX_PIXELS 170 -#endif +//#include "mbed.h" +#include "PixelBuffer.h" //---------------------------------------------------------------------------- /** * WS281X */ -class WS281X +class WS281X : public RGBPixels { public: /** @@ -46,100 +27,38 @@ */ enum RGBOrder { - RGB = 0, RBG, GRB, GBR, BRG, BGR, - READ_ORDER = -1 + RGB = 0, RBG, GRB, GBR, BRG, BGR }; /** * Initializes the addressable led bus * - * @param wirePin - The output pin on wich the addressable leds are connected + * @param txPin - The output pin on wich the addressable leds are connected * @param pinMode - The output pin mode PullUp, PullDown, PullNone, OpenDrain * @param maxPixels - Number of the addressable leds * @param RGBOrder - The order in wich the r, g and b bytes are expected */ - WS281X(PinName wirePin, PinMode pinMode = PullNone, int maxPixels = MAX_PIXELS, RGBOrder rgbOrder = WS281X::RGB); - WS281X(PinName wirePin, PinMode pinMode = PullNone, RGBColor *buffer = 0, int maxPixels = 0, RGBOrder rgbOrder = WS281X::RGB); - ~WS281X(); - - WS281X::RGBOrder rgbOrder(WS281X::RGBOrder order = READ_ORDER); - MBED_DEPRECATED("don't setRGBOrder any more, rgbOrder() instead") - void setRGBOrder(RGBOrder order = WS281X::RGB) { rgbOrder(order); } - MBED_DEPRECATED("don't getRGBOrder any more, rgbOrder() instead") - RGBOrder getRGBOrder() { return _rgbOrder; } - - void setPixelBuffer(RGBColor *buffer, int maxPixels); - int maxPixels() { return _maxPixels; } - int numPixels(int value = -1); - MBED_DEPRECATED("don't getMaxPixels any more, maxPixels instead") - int getMaxPixels() { return _maxPixels; } - MBED_DEPRECATED("don't setNumPixels any more, numPixels instead") - void setNumPixels(int value) { numPixels(value); } - MBED_DEPRECATED("don't getNumPixels any more, numPixels instead") - int getNumPixels() { return _numPixels; } - - void setPixels(int index, RGBColor *color, int len); - void setPixels(int index, HSVColor *color, int len); - void setPixels(RGBColor *color, int len) { setPixels(0, color, len); } - void setPixels(HSVColor *color, int len) { setPixels(0, color, len); } - MBED_DEPRECATED("don't setColor any more, setPixels instead") - void setColor(int index, RGBColor *color, int len) { setPixels(index, color, len); } - MBED_DEPRECATED("don't setColor any more, setPixels instead") - void setColor(int index, HSVColor *color, int len) { setPixels(index, color, len); } + WS281X(PinName txPin, PinMode pinMode = PullNone, int maxPixels = MAX_PIXELS, RGBOrder rgbOrder = WS281X::RGB); + WS281X(PinName txPin, PinMode pinMode = PullNone, RGBColor *buffer = 0, int maxPixels = 0, RGBOrder rgbOrder = WS281X::RGB); - void fillPixels(int index, const RGBColor color, int len); - void fillPixels(int index, const HSVColor color, int len); - void fillPixels(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); } - void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } - void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } - void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); } - MBED_DEPRECATED("don't fillColor any more, fillPixels instead") - void fillColor(int index, const RGBColor color, int len) { fillPixels(index, color, len); } - MBED_DEPRECATED("don't fillColor any more, fillPixels instead") - void fillColor(int index, const int32_t color, int len) { fillPixels(index, (RGBColor)color, len); } - - void fill(int index, const RGBColor color, int len) { fillPixels(index, color, len); } - void fill(int index, const HSVColor color, int len) { fillPixels(index, color, len); } - void fill(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); } - void fill(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } - void fill(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } - void fill(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); } - - void clear(const RGBColor color) { fillPixels(color); } - void clear(const HSVColor color) { fillPixels(color); } - void clear(const int color = 0) { fillPixels((RGBColor)color); } - - void repeatPixels(int block_size); - void repeatPixels(RGBColor *source, int size); - void repeatPixels(HSVColor *source, int size); - MBED_DEPRECATED("don't repeatBlock any more, repeatPixels instead") - void repeatBlock(int block_size) { repeatPixels(block_size); } - MBED_DEPRECATED("don't repeatBlock any more, repeatPixels instead") - void repeatBlock(RGBColor *source, int size) { repeatPixels(source, size); } - MBED_DEPRECATED("don't repeatBlock any more, repeatPixels instead") - void repeatBlock(HSVColor *source, int size) { repeatPixels(source, size); } - - void makeGradation(int index, RGBColor from, RGBColor to, int len); - void makeGradation(RGBColor from, RGBColor to, int len) { makeGradation(0, from, to, len); } - - void makeRainbow(int index, HSVColor color, int len, int direction); - void makeRainbow(HSVColor color, int len = MAX_PIXELS, int direction = 1) { makeRainbow(0, color, len, direction); } + RGBOrder rgbOrder() { return _rgb_order; } + RGBOrder rgbOrder(RGBOrder order); void show(); void show(const RGBColor color); RGBColor operator[](int index) const { - if (_pixels && (uint16_t)index < _numPixels) + if (_pixels && (uint16_t)index < _num_pixels) return _pixels[index]; - return _dummyPixel; + return _dummy_pixel; } RGBColor& operator[](int index) { - if (_pixels && (uint16_t)index < _numPixels) + if (_pixels && (uint16_t)index < _num_pixels) return _pixels[index]; - return _dummyPixel; + return _dummy_pixel; } operator RGBColor*() const { return _pixels; } @@ -147,17 +66,11 @@ protected: private: - PinName _wirePin; + PinName _txPin; gpio_t _gpio; - RGBOrder _rgbOrder; + RGBOrder _rgb_order; int _1st, _2nd, _3rd; - bool _owned_buffer; - uint16_t _maxPixels; - uint16_t _numPixels; - RGBColor *_pixels; - RGBColor _dummyPixel; - #if defined(TARGET_NXP) typedef uint32_t regsize_t; #elif defined(TARGET_STM32F0) || defined(TARGET_STM32F1) @@ -170,6 +83,7 @@ #if defined(TARGET_STM) void pin_mode_ex(PinName pin, PinMode mode); #endif + void pin_init(PinName txPin, PinMode pinMode); void writeByte(__IO regsize_t *reg_set, __IO regsize_t *reg_clr, regsize_t *mask, uint8_t value); };