Initial (buggy) version

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleControls by RedBearLab

Committer:
MarkSPA
Date:
Wed Mar 01 21:10:07 2017 +0000
Revision:
13:daadb429b388
Parent:
4:c8515fbd2e44
Cleaned up version for DRHS

Who changed what in which revision?

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