Nordic Thingy:52
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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 
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;
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 
280 ret_code_t drv_ext_light_sequence(uint32_t id, drv_ext_light_sequence_t * const p_sequence);
281 
298 ret_code_t drv_ext_light_rgb_sequence(uint32_t id, drv_ext_light_rgb_sequence_t * const p_sequence);
299 
314 ret_code_t drv_ext_light_init(drv_ext_light_init_t const * p_init, bool on_init_reset);
315 
316 #endif
317