API for driving Adafruit's NeoPixels using RedBear's BLE Nano or BLE nRF51822

Dependencies:   BLE_API mbed nRF51822

Dependents:   RedBearNano_NeoPixels_Example NeoTester

Committer:
bickster
Date:
Thu Jul 09 01:06:35 2015 +0000
Revision:
0:bb19df120222
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bickster 0:bb19df120222 1 /* Copyright (c) 2015 bickster, MIT License
bickster 0:bb19df120222 2 *
bickster 0:bb19df120222 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bickster 0:bb19df120222 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
bickster 0:bb19df120222 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
bickster 0:bb19df120222 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
bickster 0:bb19df120222 7 * furnished to do so, subject to the following conditions:
bickster 0:bb19df120222 8 *
bickster 0:bb19df120222 9 * The above copyright notice and this permission notice shall be included in all copies or
bickster 0:bb19df120222 10 * substantial portions of the Software.
bickster 0:bb19df120222 11 *
bickster 0:bb19df120222 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bickster 0:bb19df120222 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bickster 0:bb19df120222 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bickster 0:bb19df120222 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bickster 0:bb19df120222 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bickster 0:bb19df120222 17 */
bickster 0:bb19df120222 18 #ifndef NEOPIXEL_H
bickster 0:bb19df120222 19 #define NEOPIXEL_H
bickster 0:bb19df120222 20
bickster 0:bb19df120222 21 #include <stdbool.h>
bickster 0:bb19df120222 22 #include <stdint.h>
bickster 0:bb19df120222 23
bickster 0:bb19df120222 24
bickster 0:bb19df120222 25 //These defines are timed specific to a series of if statements and will need to be changed
bickster 0:bb19df120222 26 //to compensate for different writing algorithms than the one in neopixel.c
bickster 0:bb19df120222 27 #define NEOPIXEL_SEND_ONE NRF_GPIO->OUTSET = (1UL << PIN); \
bickster 0:bb19df120222 28 NRF_GPIO->OUTSET = (1UL << PIN); \
bickster 0:bb19df120222 29 NRF_GPIO->OUTSET = (1UL << PIN); \
bickster 0:bb19df120222 30 NRF_GPIO->OUTCLR = (1UL << PIN);
bickster 0:bb19df120222 31
bickster 0:bb19df120222 32 #define NEOPIXEL_SEND_ZERO NRF_GPIO->OUTSET = (1UL << PIN); \
bickster 0:bb19df120222 33 NRF_GPIO->OUTCLR = (1UL << PIN); \
bickster 0:bb19df120222 34 NRF_GPIO->OUTCLR = (1UL << PIN); \
bickster 0:bb19df120222 35 NRF_GPIO->OUTCLR = (1UL << PIN); \
bickster 0:bb19df120222 36 NRF_GPIO->OUTCLR = (1UL << PIN);
bickster 0:bb19df120222 37
bickster 0:bb19df120222 38 typedef union {
bickster 0:bb19df120222 39 struct {
bickster 0:bb19df120222 40 uint8_t g, r, b;
bickster 0:bb19df120222 41 }simple;
bickster 0:bb19df120222 42 uint8_t grb[3];
bickster 0:bb19df120222 43 } color_t;
bickster 0:bb19df120222 44
bickster 0:bb19df120222 45 typedef struct {
bickster 0:bb19df120222 46 uint8_t pin_num;
bickster 0:bb19df120222 47 uint16_t num_leds;
bickster 0:bb19df120222 48 color_t *leds;
bickster 0:bb19df120222 49 } neopixel_strip_t;
bickster 0:bb19df120222 50
bickster 0:bb19df120222 51 /**
bickster 0:bb19df120222 52 @brief Initialize GPIO and data location
bickster 0:bb19df120222 53 @param[in] pointer to Strip structure
bickster 0:bb19df120222 54 @param[in] pin number for GPIO
bickster 0:bb19df120222 55 */
bickster 0:bb19df120222 56 void neopixel_init(neopixel_strip_t *strip, uint8_t pin_num, uint16_t num_leds);
bickster 0:bb19df120222 57
bickster 0:bb19df120222 58 /**
bickster 0:bb19df120222 59 @brief Turn all LEDs off
bickster 0:bb19df120222 60 @param[in] pointer to Strip structure
bickster 0:bb19df120222 61 */
bickster 0:bb19df120222 62 void neopixel_clear(neopixel_strip_t *strip);
bickster 0:bb19df120222 63
bickster 0:bb19df120222 64 /**
bickster 0:bb19df120222 65 @brief Update strip with structure data
bickster 0:bb19df120222 66 @param[in] pointer to Strip structure
bickster 0:bb19df120222 67 */
bickster 0:bb19df120222 68 void neopixel_show(neopixel_strip_t *strip);
bickster 0:bb19df120222 69
bickster 0:bb19df120222 70 /**
bickster 0:bb19df120222 71 @brief Write RGB value to LED structure
bickster 0:bb19df120222 72 @param[in] pointer to Strip structure
bickster 0:bb19df120222 73 @param[in] red value
bickster 0:bb19df120222 74 @param[in] green value
bickster 0:bb19df120222 75 @param[in] blue value
bickster 0:bb19df120222 76 @param[in] LED number (starting at 1)
bickster 0:bb19df120222 77 @retval 0 Successful write
bickster 0:bb19df120222 78 @retval 1 LED number is out of bounds
bickster 0:bb19df120222 79 */
bickster 0:bb19df120222 80 uint8_t neopixel_set_color(neopixel_strip_t *strip, uint16_t index, uint8_t red, uint8_t green, uint8_t blue );
bickster 0:bb19df120222 81
bickster 0:bb19df120222 82
bickster 0:bb19df120222 83 /**
bickster 0:bb19df120222 84 @brief Write RGB value to LED structure and update LED
bickster 0:bb19df120222 85 @param[in] pointer to Strip structure
bickster 0:bb19df120222 86 @param[in] red value
bickster 0:bb19df120222 87 @param[in] green value
bickster 0:bb19df120222 88 @param[in] blue value
bickster 0:bb19df120222 89 @param[in] LED number (starting at 1)
bickster 0:bb19df120222 90 @retval 0 Successful write
bickster 0:bb19df120222 91 @retval 1 LED number is out of bounds
bickster 0:bb19df120222 92 */
bickster 0:bb19df120222 93 uint8_t neopixel_set_color_and_show(neopixel_strip_t *strip, uint16_t index, uint8_t red, uint8_t green, uint8_t blue);
bickster 0:bb19df120222 94
bickster 0:bb19df120222 95 /**
bickster 0:bb19df120222 96 @brief Clears structure data
bickster 0:bb19df120222 97 @param[in] pointer to Strip structure
bickster 0:bb19df120222 98 */
bickster 0:bb19df120222 99 void neopixel_destroy(neopixel_strip_t *strip);
bickster 0:bb19df120222 100
bickster 0:bb19df120222 101 #endif