Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
ambient8_click.h
Go to the documentation of this file.
1 
5 /*
6  * Copyright (c) 2022, Cascoda Ltd.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holder nor the
17  * names of its contributors may be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * Example click interface driver
34 */
35 
36 #ifndef AMBIENT8_CLICK_H
37 #define AMBIENT8_CLICK_H
38 
39 #include <stdint.h>
40 
41 /* master measurement (read access) modes */
43 {
44  LTR303ALS_MODE_ONE_SHOT, /* one-shot conversion - sensor in standby mode otherwise */
45  LTR303ALS_MODE_CONTINUOUS, /* continuous conversion - sensor always active */
46 };
47 
48 /* measurement mode */
49 #define LTR303ALS_MODE LTR303ALS_MODE_ONE_SHOT
50 
51 /* data acquisition status */
53 {
54  AMBIENT8_ST_OK = 0, /* read values ok */
55  AMBIENT8_ST_FAIL = 1, /* acquisition failed */
56  AMBIENT8_ST_INVALID = 2 /* data invalid / not ready */
57 };
58 
59 /* i2c address */
60 #define AMBIENT8_DEVICE_ADDRESS 0x29
61 
62 /* timing parameters [ms] */
63 #define LTR303ALS_T_ACTIVE 10 /* time [ms] before data after setting active mode */
64 #define LTR303ALS_T_POWERUP 100 /* time [ms] before data after power-up */
65 
66 /* part id and manufacturer id */
67 #define LTR303ALS_PARTID 0xA0
68 #define LTR303ALS_MANFID 0x05
69 
70 /* register addresses */
72 {
88 };
89 
90 /* ALS control register (already bitshifted) */
91 #define LTR303ALS_MODE_STANDBY 0x00
92 #define LTR303ALS_MODE_ACTIVE 0x01
93 #define LTR303ALS_SW_RESET 0x02
94 #define LTR303ALS_GAIN_1X 0x00
95 #define LTR303ALS_GAIN_2X 0x04
96 #define LTR303ALS_GAIN_4X 0x08
97 #define LTR303ALS_GAIN_8X 0x0C
98 #define LTR303ALS_GAIN_48X 0x18
99 #define LTR303ALS_GAIN_96X 0x1C
100 
101 /* ALS status register (already bitshifted) */
102 #define LTR303ALS_DATA_VALID 0x80
103 #define LTR303ALS_DATA_STATUS 0x04
104 
105 /* ALS measurement rate register (already bitshifted) */
106 /* measurement time (period) [ms] (default 500) */
107 #define LTR303ALS_TMEAS_50 0x00
108 #define LTR303ALS_TMEAS_100 0x01
109 #define LTR303ALS_TMEAS_200 0x02
110 #define LTR303ALS_TMEAS_500 0x03
111 #define LTR303ALS_TMEAS_1000 0x04
112 #define LTR303ALS_TMEAS_2000 0x05
113 /* integration time [ms] (default 100) */
114 #define LTR303ALS_TINT_50 0x08
115 #define LTR303ALS_TINT_100 0x00
116 #define LTR303ALS_TINT_150 0x20
117 #define LTR303ALS_TINT_200 0x10
118 #define LTR303ALS_TINT_250 0x28
119 #define LTR303ALS_TINT_300 0x30
120 #define LTR303ALS_TINT_350 0x38
121 #define LTR303ALS_TINT_400 0x18
122 
123 /* default gain, measurement time and integration period */
124 #define LTR303ALS_GAIN 1 // gain, 1, 2, 4, 8, 48, 96
125 #define LTR303ALS_TINT 100 // integration time [ms]: 50, 100, 150, 200, 250, 300, 350, 400
126 #define LTR303ALS_TMEAS 200 // measurement time [ms]: 50, 100, 200, 500, 1000, 2000
127 
128 /* new functions */
129 uint8_t MIKROSDK_AMBIENT8_Initialise(void);
130 uint8_t MIKROSDK_AMBIENT8_Reinitialise(void);
131 uint8_t MIKROSDK_AMBIENT8_Reconfigure(uint16_t meastime, uint16_t inttime, uint8_t gain);
132 uint8_t MIKROSDK_AMBIENT8_Acquire(uint32_t *illuminance_ch0, uint32_t *illuminance_ch1, uint32_t *illuminance_ambient);
133 
134 #endif // AMBIENT8_CLICK_H
uint8_t MIKROSDK_AMBIENT8_Initialise(void)
Definition: ambient8.c:264
uint8_t MIKROSDK_AMBIENT8_Reinitialise(void)
Definition: ambient8.c:302
sif_ltr303als_reg_address
Definition: ambient8_click.h:72
ltr303als_mode
Definition: ambient8_click.h:43
@ LTR303ALS_MODE_ONE_SHOT
Definition: ambient8_click.h:44
@ LTR303ALS_MODE_CONTINUOUS
Definition: ambient8_click.h:45
uint8_t MIKROSDK_AMBIENT8_Reconfigure(uint16_t meastime, uint16_t inttime, uint8_t gain)
Definition: ambient8.c:318
uint8_t MIKROSDK_AMBIENT8_Acquire(uint32_t *illuminance_ch0, uint32_t *illuminance_ch1, uint32_t *illuminance_ambient)
Definition: ambient8.c:332
ambient8_status
Definition: ambient8_click.h:53
@ AMBIENT8_ST_FAIL
Definition: ambient8_click.h:55
@ AMBIENT8_ST_INVALID
Definition: ambient8_click.h:56
@ AMBIENT8_ST_OK
Definition: ambient8_click.h:54
@ LTR303ALS_REG_THRES_LOW_1
Definition: ambient8_click.h:86
@ LTR303ALS_REG_DATA_CH1_0
Definition: ambient8_click.h:77
@ LTR303ALS_REG_THRES_UP_0
Definition: ambient8_click.h:83
@ LTR303ALS_REG_INT_PERS
Definition: ambient8_click.h:87
@ LTR303ALS_REG_CONTROL
Definition: ambient8_click.h:73
@ LTR303ALS_REG_DATA_CH0_1
Definition: ambient8_click.h:80
@ LTR303ALS_REG_MEAS_RATE
Definition: ambient8_click.h:74
@ LTR303ALS_REG_DATA_CH1_1
Definition: ambient8_click.h:78
@ LTR303ALS_REG_DATA_CH0_0
Definition: ambient8_click.h:79
@ LTR303ALS_REG_PART_ID
Definition: ambient8_click.h:75
@ LTR303ALS_REG_STATUS
Definition: ambient8_click.h:81
@ LTR303ALS_REG_THRES_LOW_0
Definition: ambient8_click.h:85
@ LTR303ALS_REG_THRES_UP_1
Definition: ambient8_click.h:84
@ LTR303ALS_REG_INTERRUPT
Definition: ambient8_click.h:82
@ LTR303ALS_REG_MANUFAC_ID
Definition: ambient8_click.h:76