| Nordic Thingy:52 v2.0.0

pca20020.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
39 #ifndef PCA20020_H
40 #define PCA20020_H
41
42 #include <stdint.h>
43 #include "sdk_config.h"
44 #include "drv_ext_light.h"
45 #include "drv_ext_gpio.h"
46 #include "nrf_gpio.h"
47 #include "nrf_saadc.h"
48
49 #define MPU9250_ADDR 0x68
50 #define LPS22HB_ADDR 0x5C
51 #define BH1745_ADDR 0x38
52 #define SX1509_ADDR 0x3E
53 #define CCS811_ADDR 0x5A
54 #define HTS221_ADDR 0x5F
55
56 #if defined(THINGY_HW_v0_8_0)
57 #define LIS2DH12_ADDR 0x18
58 #elif defined(THINGY_HW_v0_9_0)
59 #define LIS2DH12_ADDR 0x18
60 #else
61 #define LIS2DH12_ADDR 0x19
62 #endif
63
64 #define TWI_SENSOR_INSTANCE 0
65
66 typedef enum
67 {
68 PIN_CLEAR,
69 PIN_SET,
70 PIN_NO_OUTPUT
71 }pin_output_state_t;
72
73
74 // Pin configurations used when powering down
75 // Standard output cleared
76 #define NRF_PIN_OUTPUT_CLEAR {NRF_GPIO_PIN_DIR_OUTPUT, \
77 NRF_GPIO_PIN_INPUT_DISCONNECT, \
78 NRF_GPIO_PIN_NOPULL, \
79 NRF_GPIO_PIN_S0S1, \
80 NRF_GPIO_PIN_NOSENSE, \
81 PIN_CLEAR}
82 // Standard output set
83 #define NRF_PIN_OUTPUT_SET {NRF_GPIO_PIN_DIR_OUTPUT, \
84 NRF_GPIO_PIN_INPUT_DISCONNECT, \
85 NRF_GPIO_PIN_NOPULL, \
86 NRF_GPIO_PIN_S0S1, \
87 NRF_GPIO_PIN_NOSENSE, \
88 PIN_SET}
89 // Standard input pullup
90 #define NRF_PIN_DISCON_PULLUP {NRF_GPIO_PIN_DIR_INPUT, \
91 NRF_GPIO_PIN_INPUT_DISCONNECT, \
92 NRF_GPIO_PIN_PULLUP, \
93 NRF_GPIO_PIN_S0S1, \
94 NRF_GPIO_PIN_NOSENSE, \
95 PIN_NO_OUTPUT}
96 // Standard input nopull
97 #define NRF_PIN_DISCON_NOPULL {NRF_GPIO_PIN_DIR_INPUT, \
98 NRF_GPIO_PIN_INPUT_DISCONNECT, \
99 NRF_GPIO_PIN_NOPULL, \
100 NRF_GPIO_PIN_S0S1, \
101 NRF_GPIO_PIN_NOSENSE, \
102 PIN_NO_OUTPUT}
103 // Standard input pulldown
104 #define NRF_PIN_DISCON_PULLDOWN {NRF_GPIO_PIN_DIR_INPUT, \
105 NRF_GPIO_PIN_INPUT_DISCONNECT, \
106 NRF_GPIO_PIN_PULLDOWN, \
107 NRF_GPIO_PIN_S0S1, \
108 NRF_GPIO_PIN_NOSENSE, \
109 PIN_NO_OUTPUT}
110
111 /* IO extender configuration. The input buf must be enabled on all pins. */
112 #define SX_PIN_OUTPUT_CLEAR {DRV_EXT_GPIO_PIN_DIR_OUTPUT, \
113 DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED, \
114 DRV_EXT_GPIO_PIN_NOPULL, \
115 DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL, \
116 DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED, \
117 PIN_CLEAR}
118
119 #define SX_PIN_OUTPUT_SET {DRV_EXT_GPIO_PIN_DIR_OUTPUT, \
120 DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED, \
121 DRV_EXT_GPIO_PIN_NOPULL, \
122 DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL, \
123 DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED, \
124 PIN_SET}
125
126 #define SX_PIN_INPUT_NOPULL {DRV_EXT_GPIO_PIN_DIR_INPUT, \
127 DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED, \
128 DRV_EXT_GPIO_PIN_NOPULL, \
129 DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL, \
130 DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED, \
131 PIN_NO_OUTPUT}
132
133 #define SX_PIN_INPUT_PULLDOWN {DRV_EXT_GPIO_PIN_DIR_INPUT, \
134 DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED, \
135 DRV_EXT_GPIO_PIN_PULLDOWN, \
136 DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL, \
137 DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED, \
138 PIN_NO_OUTPUT}
139
140 #define SX_PIN_INPUT_PULLUP {DRV_EXT_GPIO_PIN_DIR_INPUT, \
141 DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED, \
142 DRV_EXT_GPIO_PIN_PULLUP, \
143 DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL, \
144 DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED, \
145 PIN_NO_OUTPUT}
146
147 typedef struct
148 {
149 nrf_gpio_pin_dir_t dir;
150 nrf_gpio_pin_input_t input;
151 nrf_gpio_pin_pull_t pull;
152 nrf_gpio_pin_drive_t drive;
153 nrf_gpio_pin_sense_t sense;
154 pin_output_state_t state;
155 }nrf_gpio_cfg_t;
156
157 typedef struct
158 {
159 drv_ext_gpio_pin_dir_t dir;
160 drv_ext_gpio_pin_input_buf_t input_buf;
161 drv_ext_gpio_pin_pull_t pull_config;
162 drv_ext_gpio_pin_drive_type_t drive_type;
163 drv_ext_gpio_pin_slew_rate_t slew_rate;
164 pin_output_state_t state;
165 }sx_gpio_cfg_t;
166
167 typedef enum
168 {
169 VDD_ON = true,
170 VDD_OFF = false
171 }vdd_state_t;
172
173 // IO extender pin configuration for system off
174 #define SX_IOEXT_NUM_PINS 16
175
176 #define SX_IOEXT_0 0
177 #define IOEXT_PIN00_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
178
179 #define SX_IOEXT_1 1
180 #define IOEXT_PIN01_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
181
182 #define SX_IOEXT_2 2
183 #define IOEXT_PIN02_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
184
185 #if defined(THINGY_HW_v0_7_0)
186 #define SX_BAT_CHG_EN 3
187 #define IOEXT_PIN03_SYSTEM_DEFAULT_CFG SX_PIN_INPUT_NOPULL
188 #elif defined(THINGY_HW_v0_8_0)
189 #define SX_BAT_CHG_EN 3
190 #define IOEXT_PIN03_SYSTEM_DEFAULT_CFG SX_PIN_INPUT_NOPULL
191 #else
192 #define SX_IOEXT_3 3
193 #define IOEXT_PIN03_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
194 #endif
195
196 #if defined(THINGY_HW_v0_7_0)
197 #define SX_SPK_PWR_CTRL 4
198 #define IOEXT_PIN04_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
199 #elif defined(THINGY_HW_v0_8_0)
200 #define SX_SPK_PWR_CTRL 4
201 #define IOEXT_PIN04_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
202 #else
203 #define SX_BAT_MON_EN 4
204 #define IOEXT_PIN04_SYSTEM_DEFAULT_CFG SX_PIN_INPUT_NOPULL
205 #endif
206
207 #define SX_LIGHTWELL_G 5
208 #define IOEXT_PIN05_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
209
210 #define SX_LIGHTWELL_B 6
211 #define IOEXT_PIN06_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
212
213 #define SX_LIGHTWELL_R 7
214 #define IOEXT_PIN07_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
215
216 #if defined(THINGY_HW_v0_7_0)
217 #define SX_MPU_PWR_CTRL 8
218 #define IOEXT_PIN08_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
219 #elif defined(THINGY_HW_v0_8_0)
220 #define SX_MPU_PWR_CTRL 8
221 #define IOEXT_PIN08_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
222 #elif defined(THINGY_HW_v0_9_0)
223 #define SX_MPU_PWR_CTRL 8
224 #define IOEXT_PIN08_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
225 #else
226 #define SX_MPU_PWR_CTRL 8
227 #define IOEXT_PIN08_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
228 #endif
229
230 #if defined(THINGY_HW_v0_7_0)
231 #define SX_MIC_PWR_CTRL 9
232 #define IOEXT_PIN09_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
233 #elif defined(THINGY_HW_v0_8_0)
234 #define SX_MIC_PWR_CTRL 9
235 #define IOEXT_PIN09_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
236 #elif defined(THINGY_HW_v0_9_0)
237 #define SX_MIC_PWR_CTRL 9
238 #define IOEXT_PIN09_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
239 #else
240 #define SX_MIC_PWR_CTRL 9
241 #define IOEXT_PIN09_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
242 #endif
243
244 #if defined(THINGY_HW_v0_7_0)
245 #define SX_CCS_PWR_CTRL 10
246 #define IOEXT_PIN10_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
247 #elif defined(THINGY_HW_v0_8_0)
248 #define SX_CCS_PWR_CTRL 10
249 #define IOEXT_PIN10_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
250 #elif defined(THINGY_HW_v0_9_0)
251 #define SX_CCS_PWR_CTRL 10
252 #define IOEXT_PIN10_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
253 #else
254 #define SX_CCS_PWR_CTRL 10
255 #define IOEXT_PIN10_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_CLEAR
256 #endif
257
258 #define SX_CCS_RESET 11
259 #define IOEXT_PIN11_SYSTEM_DEFAULT_CFG SX_PIN_INPUT_PULLDOWN
260
261 #define SX_CCS_WAKE 12
262 #define IOEXT_PIN12_SYSTEM_DEFAULT_CFG SX_PIN_INPUT_PULLDOWN
263
264 #define SX_SENSE_LED_R 13
265 #define IOEXT_PIN13_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
266
267 #define SX_SENSE_LED_G 14
268 #define IOEXT_PIN14_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
269
270 #define SX_SENSE_LED_B 15
271 #define IOEXT_PIN15_SYSTEM_DEFAULT_CFG SX_PIN_OUTPUT_SET
272
273 #define IOEXT_SYSTEM_DEFAULT_PIN_CFG \
274 { \
275 IOEXT_PIN00_SYSTEM_DEFAULT_CFG, \
276 IOEXT_PIN01_SYSTEM_DEFAULT_CFG, \
277 IOEXT_PIN02_SYSTEM_DEFAULT_CFG, \
278 IOEXT_PIN03_SYSTEM_DEFAULT_CFG, \
279 IOEXT_PIN04_SYSTEM_DEFAULT_CFG, \
280 IOEXT_PIN05_SYSTEM_DEFAULT_CFG, \
281 IOEXT_PIN06_SYSTEM_DEFAULT_CFG, \
282 IOEXT_PIN07_SYSTEM_DEFAULT_CFG, \
283 IOEXT_PIN08_SYSTEM_DEFAULT_CFG, \
284 IOEXT_PIN09_SYSTEM_DEFAULT_CFG, \
285 IOEXT_PIN10_SYSTEM_DEFAULT_CFG, \
286 IOEXT_PIN11_SYSTEM_DEFAULT_CFG, \
287 IOEXT_PIN12_SYSTEM_DEFAULT_CFG, \
288 IOEXT_PIN13_SYSTEM_DEFAULT_CFG, \
289 IOEXT_PIN14_SYSTEM_DEFAULT_CFG, \
290 IOEXT_PIN15_SYSTEM_DEFAULT_CFG \
291 };
292
293 //nRF pin configuration for system off
294 #define NRF_NUM_GPIO_PINS 32
295
296 #define OSC_XL1 0
297 #define PIN00_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
298
299 #define OSC_XL2 1
300 #define PIN01_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
301
302 #define ANA_DIG0 2
303 #define PIN02_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
304
305 #define ANA_DIG1 3
306 #define PIN03_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
307
308 #define ANA_DIG2 4
309 #define PIN04_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
310
311 #if defined(THINGY_HW_v0_7_0)
312 #define ANA_DIG3 5
313 #define PIN05_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
314 #elif defined(THINGY_HW_v0_8_0)
315 #define ANA_DIG3 5
316 #define PIN05_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
317 #elif defined(THINGY_HW_v0_9_0)
318 #define ANA_DIG3 5
319 #define PIN05_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
320 #else
321 #define IOEXT_OSCIO 5
322 #define PIN05_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
323 #endif
324
325 #define MPU_INT 6
326 #define PIN06_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
327
328 #define TWI_SDA 7
329 #define PIN07_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
330
331 #define TWI_SCL 8
332 #define PIN08_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
333
334 #define NFC1 9
335 #define PIN09_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
336
337 #define NFC2 10
338 #define PIN10_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
339
340 #define BUTTON 11
341 #define PIN11_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLUP
342
343 #define LIS_INT1 12
344 #define PIN12_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
345
346 #define USB_DETECT 13
347 #define PIN13_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
348
349 #define TWI_SDA_EXT 14
350 #define PIN14_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
351
352 #define TWI_SCL_EXT 15
353 #define PIN15_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
354
355 #define SX_RESET 16
356 #define PIN16_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
357
358 #define BAT_CHG_STAT 17
359 #define PIN17_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
360
361 #define MOS_1 18
362 #define PIN18_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
363
364 #define MOS_2 19
365 #define PIN19_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
366
367 #define MOS_3 20
368 #define PIN20_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
369
370 #define MOS_4 21
371 #define PIN21_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
372
373 #define CCS_INT 22
374 #define PIN22_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
375
376 #define LPS_INT 23
377 #if defined(THINGY_HW_v0_7_0)
378 #define PIN23_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
379 #elif defined(THINGY_HW_v0_8_0)
380 #define PIN23_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
381 #elif defined(THINGY_HW_v0_9_0)
382 #define PIN23_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
383 #else
384 #define PIN23_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
385 #endif
386
387 #define HTS_INT 24
388 #if defined(THINGY_HW_v0_7_0)
389 #define PIN24_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
390 #elif defined(THINGY_HW_v0_8_0)
391 #define PIN24_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
392 #elif defined(THINGY_HW_v0_9_0)
393 #define PIN24_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
394 #else
395 #define PIN24_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
396 #endif
397
398 #define MIC_DOUT 25
399 #define PIN25_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
400
401 #define MIC_CLK 26
402 #define PIN26_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
403
404 #define SPEAKER 27
405 #define PIN27_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
406
407 #define BATTERY 28
408 #define BATTERY_AIN NRF_SAADC_INPUT_AIN4
409 #define PIN28_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
410
411 #if defined(THINGY_HW_v0_7_0)
412 #define VOLUME 29
413 #define PIN29_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
414 #elif defined(THINGY_HW_v0_8_0)
415 #define VOLUME 29
416 #define PIN29_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
417 #elif defined(THINGY_HW_v0_9_0)
418 #define SPK_PWR_CTRL 29
419 #define PIN29_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
420 #else
421 #define SPK_PWR_CTRL 29
422 #define PIN29_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
423 #endif
424
428 #define VDD_PWR_CTRL 30
429 #if defined(THINGY_HW_v0_7_0)
430 #define PIN30_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_SET
431 #elif defined(THINGY_HW_v0_8_0)
432 #define PIN30_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_SET
433 #elif defined(THINGY_HW_v0_9_0)
434 #define PIN30_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_SET
435 #else
436 #define PIN30_SYSTEM_DEFAULT_CFG NRF_PIN_OUTPUT_CLEAR
437 #endif
438
439 #define BH_INT 31
440 #if defined(THINGY_HW_v0_7_0)
441 #define PIN31_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
442 #elif defined(THINGY_HW_v0_8_0)
443 #define PIN31_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
444 #elif defined(THINGY_HW_v0_9_0)
445 #define PIN31_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_NOPULL
446 #else
447 #define PIN31_SYSTEM_DEFAULT_CFG NRF_PIN_DISCON_PULLDOWN
448 #endif
449
450 #define NRF_SYSTEM_DEFAULT_PIN_CFG \
451 { \
452 PIN00_SYSTEM_DEFAULT_CFG, \
453 PIN01_SYSTEM_DEFAULT_CFG, \
454 PIN02_SYSTEM_DEFAULT_CFG, \
455 PIN03_SYSTEM_DEFAULT_CFG, \
456 PIN04_SYSTEM_DEFAULT_CFG, \
457 PIN05_SYSTEM_DEFAULT_CFG, \
458 PIN06_SYSTEM_DEFAULT_CFG, \
459 PIN07_SYSTEM_DEFAULT_CFG, \
460 PIN08_SYSTEM_DEFAULT_CFG, \
461 PIN09_SYSTEM_DEFAULT_CFG, \
462 PIN10_SYSTEM_DEFAULT_CFG, \
463 PIN11_SYSTEM_DEFAULT_CFG, \
464 PIN12_SYSTEM_DEFAULT_CFG, \
465 PIN13_SYSTEM_DEFAULT_CFG, \
466 PIN14_SYSTEM_DEFAULT_CFG, \
467 PIN15_SYSTEM_DEFAULT_CFG, \
468 PIN16_SYSTEM_DEFAULT_CFG, \
469 PIN17_SYSTEM_DEFAULT_CFG, \
470 PIN18_SYSTEM_DEFAULT_CFG, \
471 PIN19_SYSTEM_DEFAULT_CFG, \
472 PIN20_SYSTEM_DEFAULT_CFG, \
473 PIN21_SYSTEM_DEFAULT_CFG, \
474 PIN22_SYSTEM_DEFAULT_CFG, \
475 PIN23_SYSTEM_DEFAULT_CFG, \
476 PIN24_SYSTEM_DEFAULT_CFG, \
477 PIN25_SYSTEM_DEFAULT_CFG, \
478 PIN26_SYSTEM_DEFAULT_CFG, \
479 PIN27_SYSTEM_DEFAULT_CFG, \
480 PIN28_SYSTEM_DEFAULT_CFG, \
481 PIN29_SYSTEM_DEFAULT_CFG, \
482 PIN30_SYSTEM_DEFAULT_CFG, \
483 PIN31_SYSTEM_DEFAULT_CFG \
484 };
485
486 #define DRV_EXT_RGB_LED_SENSE 0
487 #define DRV_EXT_RGB_LED_LIGHTWELL 1
488 #define DRV_EXT_LIGHT_NUM 2
489
490 #define BATT_VOLTAGE_DIVIDER_R1 1500000
491 #define BATT_VOLTAGE_DIVIDER_R2 180000
492
493 #ifdef __GNUC__
494 #pragma GCC diagnostic push
495 #pragma GCC diagnostic ignored "-Wunused-variable"
496 #endif
497
498 DRV_EXT_LIGHT_DEF(my_led_0);
499 DRV_EXT_LIGHT_DEF(my_led_1);
500
501 #define DRV_EXT_LIGHT_CFG \
502 { \
503 { \
504 .type = DRV_EXT_LIGHT_TYPE_RGB, \
505 .pin.rgb = { \
506 .r = SX_SENSE_LED_R, \
507 .g = SX_SENSE_LED_G, \
508 .b = SX_SENSE_LED_B }, \
509 .p_data = &my_led_0 \
510 }, \
511 { \
512 .type = DRV_EXT_LIGHT_TYPE_RGB, \
513 .pin.rgb = { \
514 .r = SX_LIGHTWELL_R, \
515 .g = SX_LIGHTWELL_G, \
516 .b = SX_LIGHTWELL_B }, \
517 .p_data = &my_led_1 \
518 }, \
519 };
520
521 #define BATT_MEAS_INTERVAL_MS 5000 // Measurement interval [ms].
522 #define BATT_MEAS_LOW_BATT_LIMIT_MV 3100 // Cutoff voltage [mV].
523 #define BATT_MEAS_FULL_BATT_LIMIT_MV 4190 // Full charge definition [mV].
524 #define BATT_MEAS_INVALID_PIN 255 // Invalid pin definition.
525 #define BATT_MEAS_VOLTAGE_TO_SOC_ELEMENTS 111 // Number of elements in the state of charge vector.
526 #define BATT_MEAS_VOLTAGE_TO_SOC_DELTA_MV 10 // mV between each element in the SoC vector.
527
531 static const uint8_t BATT_MEAS_VOLTAGE_TO_SOC[] = {
532 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
533 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4,
534 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13, 13, 14, 15, 16,
535 18, 19, 22, 25, 28, 32, 36, 40, 44, 47, 51, 53, 56, 58, 60, 62, 64, 66, 67, 69,
536 71, 72, 74, 76, 77, 79, 81, 82, 84, 85, 85, 86, 86, 86, 87, 88, 88, 89, 90, 91,
537 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 100};
538
539 #if defined(THINGY_HW_v0_8_0)
540 #define BAT_MON_EN_PIN_USED false
541 #define BAT_MON_EN_PIN_NO BATT_MEAS_INVALID_PIN
542 #else
543 #define BAT_MON_EN_PIN_USED true
544 #define BAT_MON_EN_PIN_NO SX_BAT_MON_EN
545 #endif
546
547 // Battery monitoring setup.
548 #define BATT_MEAS_PARAM_CFG \
549 { \
550 .batt_meas_param = { \
551 .app_timer_prescaler = APP_TIMER_PRESCALER, \
552 .adc_pin_no = BATTERY, \
553 .adc_pin_no_ain = BATTERY_AIN, \
554 .usb_detect_pin_no = USB_DETECT, \
555 .batt_chg_stat_pin_no = BAT_CHG_STAT, \
556 .batt_mon_en_pin_used = BAT_MON_EN_PIN_USED, \
557 .batt_mon_en_pin_no = BAT_MON_EN_PIN_NO, \
558 .batt_voltage_limit_low = BATT_MEAS_LOW_BATT_LIMIT_MV, \
559 .batt_voltage_limit_full = BATT_MEAS_FULL_BATT_LIMIT_MV, \
560 .state_of_charge = \
561 { \
562 .num_elements = BATT_MEAS_VOLTAGE_TO_SOC_ELEMENTS,\
563 .first_element_mv = BATT_MEAS_LOW_BATT_LIMIT_MV, \
564 .delta_mv = BATT_MEAS_VOLTAGE_TO_SOC_DELTA_MV,\
565 .voltage_to_soc = BATT_MEAS_VOLTAGE_TO_SOC, \
566 }, \
567 .voltage_divider = \
568 { \
569 .r_1_ohm = BATT_VOLTAGE_DIVIDER_R1, \
570 .r_2_ohm = BATT_VOLTAGE_DIVIDER_R2, \
571 }, \
572 }, \
573 };
574
575 // Low frequency clock source to be used by the SoftDevice
576 #define NRF_CLOCK_LFCLKSRC {.source = NRF_CLOCK_LF_SRC_XTAL, \
577 .rc_ctiv = 0, \
578 .rc_temp_ctiv = 0, \
579 .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}
580
581 #endif /*PCA20020_H*/
drv_ext_gpio_pin_dir_t
drv_ext_gpio_pin_dir_t
Pin direction definitions.
Definition: drv_ext_gpio.h:69
drv_ext_gpio_pin_slew_rate_t
drv_ext_gpio_pin_slew_rate_t
Regular or increased slew rate.
Definition: drv_ext_gpio.h:102
drv_ext_gpio_pin_drive_type_t
drv_ext_gpio_pin_drive_type_t
Push-pull or open drain operation.
Definition: drv_ext_gpio.h:94
DRV_EXT_LIGHT_DEF
#define DRV_EXT_LIGHT_DEF(light_id)
Define to create timers associated with each light source.
Definition: drv_ext_light.h:146
drv_ext_gpio_pin_input_buf_t
drv_ext_gpio_pin_input_buf_t
Connection of input buffer.
Definition: drv_ext_gpio.h:77
drv_ext_gpio_pin_pull_t
drv_ext_gpio_pin_pull_t
Pin to be pulled down, up, or no-pull.
Definition: drv_ext_gpio.h:85