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.
WS281X.h@46:2374900f8845, 2016-12-20 (annotated)
- Committer:
- mutech
- Date:
- Tue Dec 20 03:22:01 2016 +0000
- Revision:
- 46:2374900f8845
- Parent:
- 32:64c391617f6c
WS2811/WS2812 support Library;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mutech | 24:f93a61e727a3 | 1 | /* WS281X.h (for LPC82X/STM32F0x/STM32F446/STM32F746xx) |
mutech | 0:dff187a80020 | 2 | * mbed Microcontroller Library |
mutech | 46:2374900f8845 | 3 | * Copyright (c) 2016 muetch, t.kuroki |
mutech | 46:2374900f8845 | 4 | * Allrights reserved. |
mutech | 27:bc79f444883b | 5 | * |
mutech | 27:bc79f444883b | 6 | * Rev 0.97 2016-09-07 |
mutech | 28:b452e097da53 | 7 | * Rev 0.98 2016-09-08 |
mutech | 0:dff187a80020 | 8 | */ |
mutech | 0:dff187a80020 | 9 | |
mutech | 0:dff187a80020 | 10 | #pragma once |
mutech | 0:dff187a80020 | 11 | |
mutech | 0:dff187a80020 | 12 | #ifndef WS281X_H |
mutech | 0:dff187a80020 | 13 | #define WS281X_H |
mutech | 0:dff187a80020 | 14 | |
mutech | 46:2374900f8845 | 15 | //#include "mbed.h" |
mutech | 46:2374900f8845 | 16 | #include "PixelBuffer.h" |
mutech | 0:dff187a80020 | 17 | |
mutech | 0:dff187a80020 | 18 | //---------------------------------------------------------------------------- |
mutech | 0:dff187a80020 | 19 | /** |
mutech | 24:f93a61e727a3 | 20 | * WS281X |
mutech | 24:f93a61e727a3 | 21 | */ |
mutech | 46:2374900f8845 | 22 | class WS281X : public RGBPixels |
mutech | 0:dff187a80020 | 23 | { |
mutech | 0:dff187a80020 | 24 | public: |
mutech | 0:dff187a80020 | 25 | /** |
mutech | 0:dff187a80020 | 26 | Order of r, g and b bytes |
mutech | 0:dff187a80020 | 27 | */ |
mutech | 0:dff187a80020 | 28 | enum RGBOrder |
mutech | 0:dff187a80020 | 29 | { |
mutech | 46:2374900f8845 | 30 | RGB = 0, RBG, GRB, GBR, BRG, BGR |
mutech | 0:dff187a80020 | 31 | }; |
mutech | 0:dff187a80020 | 32 | |
mutech | 0:dff187a80020 | 33 | /** |
mutech | 0:dff187a80020 | 34 | * Initializes the addressable led bus |
mutech | 0:dff187a80020 | 35 | * |
mutech | 46:2374900f8845 | 36 | * @param txPin - The output pin on wich the addressable leds are connected |
mutech | 0:dff187a80020 | 37 | * @param pinMode - The output pin mode PullUp, PullDown, PullNone, OpenDrain |
mutech | 20:28fe0d0d081b | 38 | * @param maxPixels - Number of the addressable leds |
mutech | 0:dff187a80020 | 39 | * @param RGBOrder - The order in wich the r, g and b bytes are expected |
mutech | 0:dff187a80020 | 40 | */ |
mutech | 46:2374900f8845 | 41 | WS281X(PinName txPin, PinMode pinMode = PullNone, int maxPixels = MAX_PIXELS, RGBOrder rgbOrder = WS281X::RGB); |
mutech | 46:2374900f8845 | 42 | WS281X(PinName txPin, PinMode pinMode = PullNone, RGBColor *buffer = 0, int maxPixels = 0, RGBOrder rgbOrder = WS281X::RGB); |
mutech | 27:bc79f444883b | 43 | |
mutech | 46:2374900f8845 | 44 | RGBOrder rgbOrder() { return _rgb_order; } |
mutech | 46:2374900f8845 | 45 | RGBOrder rgbOrder(RGBOrder order); |
mutech | 28:b452e097da53 | 46 | |
mutech | 0:dff187a80020 | 47 | void show(); |
mutech | 8:0617f524d67d | 48 | void show(const RGBColor color); |
mutech | 0:dff187a80020 | 49 | |
mutech | 2:cc8e091fd975 | 50 | RGBColor operator[](int index) const |
mutech | 0:dff187a80020 | 51 | { |
mutech | 46:2374900f8845 | 52 | if (_pixels && (uint16_t)index < _num_pixels) |
mutech | 0:dff187a80020 | 53 | return _pixels[index]; |
mutech | 46:2374900f8845 | 54 | return _dummy_pixel; |
mutech | 0:dff187a80020 | 55 | } |
mutech | 0:dff187a80020 | 56 | |
mutech | 2:cc8e091fd975 | 57 | RGBColor& operator[](int index) |
mutech | 0:dff187a80020 | 58 | { |
mutech | 46:2374900f8845 | 59 | if (_pixels && (uint16_t)index < _num_pixels) |
mutech | 0:dff187a80020 | 60 | return _pixels[index]; |
mutech | 46:2374900f8845 | 61 | return _dummy_pixel; |
mutech | 0:dff187a80020 | 62 | } |
mutech | 0:dff187a80020 | 63 | |
mutech | 27:bc79f444883b | 64 | operator RGBColor*() const { return _pixels; } |
mutech | 27:bc79f444883b | 65 | |
mutech | 0:dff187a80020 | 66 | protected: |
mutech | 0:dff187a80020 | 67 | |
mutech | 0:dff187a80020 | 68 | private: |
mutech | 46:2374900f8845 | 69 | PinName _txPin; |
mutech | 24:f93a61e727a3 | 70 | gpio_t _gpio; |
mutech | 46:2374900f8845 | 71 | RGBOrder _rgb_order; |
mutech | 0:dff187a80020 | 72 | int _1st, _2nd, _3rd; |
mutech | 0:dff187a80020 | 73 | |
mutech | 0:dff187a80020 | 74 | #if defined(TARGET_NXP) |
mutech | 0:dff187a80020 | 75 | typedef uint32_t regsize_t; |
mutech | 0:dff187a80020 | 76 | #elif defined(TARGET_STM32F0) || defined(TARGET_STM32F1) |
mutech | 0:dff187a80020 | 77 | typedef uint32_t regsize_t; |
mutech | 0:dff187a80020 | 78 | #elif defined(TARGET_STM) |
mutech | 0:dff187a80020 | 79 | typedef uint16_t regsize_t; |
mutech | 0:dff187a80020 | 80 | #else |
mutech | 0:dff187a80020 | 81 | #error "not supported CPU!!" |
mutech | 0:dff187a80020 | 82 | #endif |
mutech | 0:dff187a80020 | 83 | #if defined(TARGET_STM) |
mutech | 0:dff187a80020 | 84 | void pin_mode_ex(PinName pin, PinMode mode); |
mutech | 0:dff187a80020 | 85 | #endif |
mutech | 46:2374900f8845 | 86 | void pin_init(PinName txPin, PinMode pinMode); |
mutech | 0:dff187a80020 | 87 | void writeByte(__IO regsize_t *reg_set, __IO regsize_t *reg_clr, regsize_t *mask, uint8_t value); |
mutech | 0:dff187a80020 | 88 | }; |
mutech | 0:dff187a80020 | 89 | |
mutech | 0:dff187a80020 | 90 | //---------------------------------------------------------------------------- |
mutech | 0:dff187a80020 | 91 | #endif // end of WS281X_H |