Nordic Thingy:52 v2.2.0
drv_ext_light.h
1 /*
2  Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form, except as embedded into a Nordic
12  Semiconductor ASA integrated circuit in a product or a software update for
13  such product, must reproduce the above copyright notice, this list of
14  conditions and the following disclaimer in the documentation and/or other
15  materials provided with the distribution.
16 
17  3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  contributors may be used to endorse or promote products derived from this
19  software without specific prior written permission.
20 
21  4. This software, with or without modification, must only be used with a
22  Nordic Semiconductor ASA integrated circuit.
23 
24  5. Any software provided in binary form under this license must not be reverse
25  engineered, decompiled, modified and/or disassembled.
26 
27  THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29  OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30  DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
48 #ifndef __DRV_EXT_LIGHT_H__
49 #define __DRV_EXT_LIGHT_H__
50 
51 #include <stdint.h>
52 #include "app_error.h"
53 #include "drv_sx1509.h"
54 #include "sx150x_led_drv_regs.h"
55 #include "sx150x_led_drv_calc.h"
56 #include "app_timer.h"
57 
58 #define DRV_EXT_LIGHT_INTENSITY_MAX ((uint8_t)(0xFF))
59 #define DRV_EXT_LIGHT_INTENSITY_OFF (0)
60 
61 #define DRV_EXT_LIGHT_MAX_PIN_ID_ALLOWED 16
62 #define DRV_EXT_LIGHT_NUM_LIGHTS_MAX (((DRV_SX1509_HIGHINPMODE_PIN15_Pos + 1) < (16)) ? \
63  (DRV_SX1509_HIGHINPMODE_PIN15_Pos + 1) : (16))
64 #define DRV_EXT_LIGHT_IOEXT_CLKX_DIV_MAX (DRV_SX1509_MISC_CLKX_Msk >> DRV_SX1509_MISC_CLKX_Pos)
65 #define DRV_EXT_LIGHT_INVALID_RESYNC_PIN 255
66 
68 enum
69 {
75 };
76 
80 typedef enum
81 {
82  DRV_EXT_LIGHT_CLKX_DIV_1 = 1,
83  DRV_EXT_LIGHT_CLKX_DIV_2 ,
84  DRV_EXT_LIGHT_CLKX_DIV_4 ,
85  DRV_EXT_LIGHT_CLKX_DIV_8 ,
86  DRV_EXT_LIGHT_CLKX_DIV_16,
87  DRV_EXT_LIGHT_CLKX_DIV_32,
88  DRV_EXT_LIGHT_CLKX_DIV_64,
90 
93 typedef enum
94 {
95  DRV_EXT_LIGHT_COLOR_NONE,
96  DRV_EXT_LIGHT_COLOR_RED,
97  DRV_EXT_LIGHT_COLOR_GREEN,
98  DRV_EXT_LIGHT_COLOR_YELLOW,
99  DRV_EXT_LIGHT_COLOR_BLUE,
100  DRV_EXT_LIGHT_COLOR_PURPLE,
101  DRV_EXT_LIGHT_COLOR_CYAN,
102  DRV_EXT_LIGHT_COLOR_WHITE
104 
107 typedef enum
108 {
115 
118 typedef struct
119 {
120  uint32_t active_time_ms;
121  uint32_t inactive_time_ms;
125 
128 #define DRV_EXT_LIGHT_STATUS_INIT \
129 { \
130  .active_time_ms = 0, \
131  .inactive_time_ms = 0, \
132  .colors = DRV_EXT_LIGHT_COLOR_NONE, \
133  .ioext_osc_status = EXTENDER_OSC_UNUSED \
134 }
135 
138 typedef struct
139 {
141  app_timer_id_t timer;
143 
146 #define DRV_EXT_LIGHT_DEF(light_id) \
147  static drv_ext_light_status_t light_id##_timings = DRV_EXT_LIGHT_STATUS_INIT; \
148  static app_timer_t light_id##_timer_data = { {0} }; \
149  static drv_ext_light_data_t light_id = {.p_status = &light_id##_timings, .timer = &light_id##_timer_data} \
150 
151 
153 typedef enum
154 {
158 
161 typedef struct
162 {
164  union
165  {
166  uint8_t mono;
167  struct
168  {
169  uint8_t r;
170  uint8_t g;
171  uint8_t b;
172  }rgb;
173  }pin;
176 
179 typedef struct
180 {
182  uint8_t num_lights;
185  uint8_t resync_pin;
187 
190 typedef struct
191 {
192  uint8_t r;
193  uint8_t g;
194  uint8_t b;
196 
199 typedef struct
200 {
202  drv_ext_light_sequence_t sequence_vals;
204 
207 #define SEQUENCE_REAL_VAL_INIT(PARAM) drv_ext_light_sequence_t PARAM = SEQUENCE_DEFAULT_VAL
208 
216 ret_code_t drv_ext_light_reset(void);
217 
228 ret_code_t drv_ext_light_on(uint32_t id);
229 
240 ret_code_t drv_ext_light_off(uint32_t id);
241 
251 ret_code_t drv_ext_light_intensity_set(uint32_t id, uint8_t intensity);
252 
262 ret_code_t drv_ext_light_rgb_intensity_set(uint32_t id, drv_ext_light_rgb_intensity_t const * const p_intensity);
263 
281 ret_code_t drv_ext_light_sequence(uint32_t id, drv_ext_light_sequence_t * const p_sequence);
282 
300 ret_code_t drv_ext_light_rgb_sequence(uint32_t id, drv_ext_light_rgb_sequence_t * const p_sequence);
301 
316 ret_code_t drv_ext_light_init(drv_ext_light_init_t const * p_init, bool on_init_reset);
317 
318 #endif
319 
uint8_t mono
Monochrome pin.
Definition: drv_ext_light.h:166
drv_ext_light_data_t * p_data
Associated data for this light (app timer and timings).
Definition: drv_ext_light.h:174
The color mix and sequence variables if a sequence (e.g. breathe) is used.
Definition: drv_ext_light.h:199
drv_ext_light_conf_t const * p_light_conf
Array of lights, each with their specific configuraion.
Definition: drv_ext_light.h:181
drv_sx1509_cfg_t const * p_twi_conf
pointer to TWI (I2C) configuration for communication between master and IO extender.
Definition: drv_ext_light.h:184
SX1509 configuration.
Definition: drv_sx1509.h:70
The type of light is not supported.
Definition: drv_ext_light.h:73
Ext osc not used for this light.
Definition: drv_ext_light.h:109
drv_ext_light_clkx_div_t
Defines the frequency of the LED driver clock (ClkX) of the SX1509 according to ClkX = fOSC/2^(DRV_EX...
Definition: drv_ext_light.h:80
uint8_t r
Red intensity.
Definition: drv_ext_light.h:192
Not supported.
Definition: drv_ext_light.h:72
ret_code_t drv_ext_light_rgb_sequence(uint32_t id, drv_ext_light_rgb_sequence_t *const p_sequence)
Function for setting color for a given light through the GPIO extender.
Simplified struct for setting RGB intensity directly.
Definition: drv_ext_light.h:190
drv_ext_light_color_mix_t color
Color mix used for the sequence.
Definition: drv_ext_light.h:201
ret_code_t drv_ext_light_init(drv_ext_light_init_t const *p_init, bool on_init_reset)
Function for initializing the drv_ext_light driver.
uint8_t g
RGB G pin.
Definition: drv_ext_light.h:170
drv_ext_light_ioext_osc_status_t
The state of the IO extender oscillator for each light.
Definition: drv_ext_light.h:107
uint8_t r
RGB R pin.
Definition: drv_ext_light.h:169
Ext osc used on a permanent basis (light dimmed).
Definition: drv_ext_light.h:112
Number of different possible IO extender oscillator statuses.
Definition: drv_ext_light.h:113
drv_ext_light_sequence_t sequence_vals
Defines sequence values: on/off/fade_in/fade_out times, and on/off intensities.
Definition: drv_ext_light.h:202
ret_code_t drv_ext_light_on(uint32_t id)
Function for turning a given light on.
uint8_t resync_pin
Pin used to resync IO extender counters. Use DRV_EXT_LIGHT_INVALID_RESYNC_PIN if unused.
Definition: drv_ext_light.h:185
ret_code_t drv_ext_light_sequence(uint32_t id, drv_ext_light_sequence_t *const p_sequence)
Function for setting color for a given light through the GPIO extender.
Struct for initializing the light driver.
Definition: drv_ext_light.h:179
ret_code_t drv_ext_light_rgb_intensity_set(uint32_t id, drv_ext_light_rgb_intensity_t const *const p_intensity)
Function for setting color for RGB LEDs.
uint8_t b
RGB B pin.
Definition: drv_ext_light.h:171
Ext osc running (Light currently on).
Definition: drv_ext_light.h:110
ret_code_t drv_ext_light_intensity_set(uint32_t id, uint8_t intensity)
Function for setting intensity of monochrome light.
App timer and internal light timing struct.
Definition: drv_ext_light.h:138
app_timer_id_t timer
App timer information.
Definition: drv_ext_light.h:141
drv_ext_light_status_t * p_status
Light status information.
Definition: drv_ext_light.h:140
Monochrome (single) LED.
Definition: drv_ext_light.h:155
ret_code_t drv_ext_light_reset(void)
Function for resetting all the registers of the IO extender to their default values.
drv_ext_light_reg_type_t type
Monochrome or RGB.
Definition: drv_ext_light.h:163
Struct used by the app_timer handler, mainly for power saving.
Definition: drv_ext_light.h:118
uint32_t inactive_time_ms
Total time for a light to be off.
Definition: drv_ext_light.h:121
Ext osc paused (Light currently off).
Definition: drv_ext_light.h:111
drv_ext_light_reg_type_t
Monochrome (single) or RGB light.
Definition: drv_ext_light.h:153
ret_code_t drv_ext_light_off(uint32_t id)
Function for turning a given light off.
Invalid parameters.
Definition: drv_ext_light.h:71
drv_ext_light_color_mix_t
The following color combinations are possible when using drv_ext_light_rgb_sequence_t.
Definition: drv_ext_light.h:93
uint8_t g
Green intensity.
Definition: drv_ext_light.h:193
RGB LED (three IOs used).
Definition: drv_ext_light.h:156
Struct that defines the type of light (monochrome or RGB) and the corresponding connected pins...
Definition: drv_ext_light.h:161
drv_ext_light_ioext_osc_status_t ioext_osc_status
Status, holds information on the current use of the IO extender oscillator.
Definition: drv_ext_light.h:123
uint32_t active_time_ms
Total time for a light to be on or dimmed.
Definition: drv_ext_light.h:120
drv_ext_light_color_mix_t colors
Color mix used for breathe, single-shot, or blink.
Definition: drv_ext_light.h:122
uint8_t num_lights
Number of connected lights.
Definition: drv_ext_light.h:182
drv_ext_light_clkx_div_t clkx_div
IO extender clock divider.
Definition: drv_ext_light.h:183
The desired time is too long. Increase the ClkX divider.
Definition: drv_ext_light.h:74
Successful.
Definition: drv_ext_light.h:70
uint8_t b
Blue intensity.
Definition: drv_ext_light.h:194