Reconsidered input pin and NC pin for SPI. Modified several functions interface and its contents.

Dependents:   WS2812_out_of_specification_demo

Committer:
kenjiArai
Date:
Fri Mar 20 06:46:11 2020 +0000
Revision:
6:583738208b96
Parent:
5:a07522fe36d4
Reconsidered input pin and NC pin for SPI. Modified several functions interface and its contents.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:be22a9d4df5f 1 /* Copyright (c) 2012 cstyles, MIT License
chris 0:be22a9d4df5f 2 *
kenjiArai 6:583738208b96 3 * Permission is hereby granted, free of charge, to any person obtaining a copy
kenjiArai 6:583738208b96 4 * of this software and associated documentation files (the "Software"),
kenjiArai 6:583738208b96 5 * to deal in the Software without restriction, including without limitation
kenjiArai 6:583738208b96 6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
kenjiArai 6:583738208b96 7 * and/or sell copies of the Software, and to permit persons to whom
kenjiArai 6:583738208b96 8 * the Software is furnished to do so, subject to the following conditions:
kenjiArai 6:583738208b96 9 *
kenjiArai 6:583738208b96 10 * The above copyright notice and this permission notice shall be included
kenjiArai 6:583738208b96 11 * in all copies or substantial portions of the Software.
chris 0:be22a9d4df5f 12 *
kenjiArai 6:583738208b96 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
kenjiArai 6:583738208b96 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
kenjiArai 6:583738208b96 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
kenjiArai 6:583738208b96 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
kenjiArai 6:583738208b96 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kenjiArai 6:583738208b96 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
kenjiArai 6:583738208b96 19 * IN THE SOFTWARE.
kenjiArai 6:583738208b96 20 */
kenjiArai 6:583738208b96 21
kenjiArai 6:583738208b96 22 /*
kenjiArai 6:583738208b96 23 Modified by Kenji Arai / JH1PJL
kenjiArai 6:583738208b96 24 March 20th, 2020
kenjiArai 6:583738208b96 25
kenjiArai 6:583738208b96 26 Original & Refrence
kenjiArai 6:583738208b96 27 https://os.mbed.com/users/chris/code/ChrisRGB-Ring/
kenjiArai 6:583738208b96 28 https://os.mbed.com/users/chris/code/WS2812/
kenjiArai 6:583738208b96 29 https://os.mbed.com/users/chris/code/PixelArray/
kenjiArai 6:583738208b96 30
kenjiArai 6:583738208b96 31 https://os.mbed.com/users/bridadan/code/WS2812_Example/
kenjiArai 6:583738208b96 32 https://os.mbed.com/users/bridadan/code/WS2812/
kenjiArai 6:583738208b96 33 https://os.mbed.com/users/chris/code/PixelArray/
kenjiArai 6:583738208b96 34
kenjiArai 6:583738208b96 35 */
kenjiArai 6:583738208b96 36
kenjiArai 6:583738208b96 37 /*
kenjiArai 6:583738208b96 38 !!!!! This library does NOT follow specification value of the timing !!!!
kenjiArai 6:583738208b96 39 https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
kenjiArai 6:583738208b96 40 http://akizukidenshi.com/download/ds/adafruit/WS2812B.pdf
kenjiArai 6:583738208b96 41
kenjiArai 6:583738208b96 42 WS2812 -> Interpretation of control timing (Not Grantee but works)
kenjiArai 6:583738208b96 43 Specification
kenjiArai 6:583738208b96 44 T0H 200 to 500ns
kenjiArai 6:583738208b96 45 T1H 550 to 850ns
kenjiArai 6:583738208b96 46 T0L 650 to 950ns
kenjiArai 6:583738208b96 47 T1L 450 to 750ns
kenjiArai 6:583738208b96 48 Reset 50us
kenjiArai 6:583738208b96 49 Interpretation
kenjiArai 6:583738208b96 50 T0H same as above
kenjiArai 6:583738208b96 51 T1H same as above
kenjiArai 6:583738208b96 52 T0L less than 10us
kenjiArai 6:583738208b96 53 T1L Less than 10us
kenjiArai 6:583738208b96 54 Reset over 50uS
kenjiArai 6:583738208b96 55
kenjiArai 6:583738208b96 56 Please refer following web page
kenjiArai 6:583738208b96 57 https://wp.josh.com/2014/05/13/
kenjiArai 6:583738208b96 58 ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
chris 0:be22a9d4df5f 59 */
chris 0:be22a9d4df5f 60
chris 0:be22a9d4df5f 61 #ifndef WS2812_H
chris 0:be22a9d4df5f 62 #define WS2812_H
chris 0:be22a9d4df5f 63
chris 0:be22a9d4df5f 64 #include "mbed.h"
chris 0:be22a9d4df5f 65
kenjiArai 6:583738208b96 66 #if \
kenjiArai 6:583738208b96 67 defined(TARGET_NUCLEO_F042K6)\
kenjiArai 6:583738208b96 68 || defined(TARGET_NUCLEO_F334R8)\
kenjiArai 6:583738208b96 69 || defined(TARGET_NUCLEO_F401RE)\
kenjiArai 6:583738208b96 70 || defined(TARGET_NUCLEO_F411RE)\
kenjiArai 6:583738208b96 71 || defined(TARGET_NUCLEO_F446RE)\
kenjiArai 6:583738208b96 72 || defined(TARGET_NUCLEO_L053R8)\
kenjiArai 6:583738208b96 73 || defined(TARGET_NUCLEO_L073RZ)\
kenjiArai 6:583738208b96 74 || defined(TARGET_NUCLEO_L152RE)\
kenjiArai 6:583738208b96 75 || defined(TARGET_NUCLEO_L476RG)
kenjiArai 6:583738208b96 76 # define WS1 0x0f
kenjiArai 6:583738208b96 77 # define WS0 0x0c
kenjiArai 6:583738208b96 78 # define SPICLK 8000000
kenjiArai 6:583738208b96 79 # define SPIBPF 4
kenjiArai 6:583738208b96 80 #elif \
kenjiArai 6:583738208b96 81 defined(TARGET_RZ_A1H)\
kenjiArai 6:583738208b96 82 || defined(TARGET_GR_LYCHEE)\
kenjiArai 6:583738208b96 83 || defined(TARGET_GR_MANGO)
kenjiArai 6:583738208b96 84 # define WS1 0x0f
kenjiArai 6:583738208b96 85 # define WS0 0x0c
kenjiArai 6:583738208b96 86 # define SPICLK 5000000
kenjiArai 6:583738208b96 87 # define SPIBPF 8
kenjiArai 6:583738208b96 88 #endif
chris 1:c278c3d136bb 89
chris 0:be22a9d4df5f 90 //!Library for the WS2812 RGB LED with integrated controller
chris 0:be22a9d4df5f 91 /*!
chris 0:be22a9d4df5f 92 The WS2812 is controller that is built into a range of LEDs
chris 0:be22a9d4df5f 93 */
chris 0:be22a9d4df5f 94 class WS2812
chris 0:be22a9d4df5f 95 {
chris 0:be22a9d4df5f 96 public:
kenjiArai 6:583738208b96 97 enum BrightnessControl {OFF, GLOBAL, PER_PIXEL};
kenjiArai 6:583738208b96 98
chris 4:b230e85fc5e7 99 //!Creates an instance of the class.
chris 4:b230e85fc5e7 100 /*!
kenjiArai 6:583738208b96 101 Connect WS2812 using SPI MOSI pin(Only use) and MISO&SCLK(NC)
chris 4:b230e85fc5e7 102 */
kenjiArai 6:583738208b96 103 WS2812(PinName mosi, PinName miso, PinName sclk, int size);
chris 4:b230e85fc5e7 104
chris 4:b230e85fc5e7 105 /*!
chris 4:b230e85fc5e7 106 Destroys instance.
chris 4:b230e85fc5e7 107 */
chris 4:b230e85fc5e7 108 ~WS2812();
chris 4:b230e85fc5e7 109
kenjiArai 6:583738208b96 110 void write(int buf[]);
kenjiArai 6:583738208b96 111 void write_offsets(int buf[], int r_offset = 0,
kenjiArai 6:583738208b96 112 int g_offset = 0, int b_offset = 0);
kenjiArai 6:583738208b96 113 void setAll(int color);
chris 4:b230e85fc5e7 114
kenjiArai 6:583738208b96 115 void set_brightness_mode(BrightnessControl mode);
kenjiArai 6:583738208b96 116 void set_brightness(unsigned char br);
chris 0:be22a9d4df5f 117
chris 0:be22a9d4df5f 118 private:
kenjiArai 6:583738208b96 119 SPI __spi;
kenjiArai 6:583738208b96 120
kenjiArai 6:583738208b96 121 void __write (int color);
chris 0:be22a9d4df5f 122
chris 4:b230e85fc5e7 123 int __size;
kenjiArai 6:583738208b96 124 unsigned char __br;
kenjiArai 6:583738208b96 125 BrightnessControl __mode;
chris 0:be22a9d4df5f 126
chris 0:be22a9d4df5f 127 };
chris 0:be22a9d4df5f 128
chris 0:be22a9d4df5f 129 #endif