ambient9  2.0.0.0
ambient9.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef AMBIENT9_H
36 #define AMBIENT9_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define AMBIENT9_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define AMBIENT9_RETVAL uint8_t
77 
78 #define AMBIENT9_OK 0x00
79 #define AMBIENT9_INIT_ERROR 0xFF
80 
82 #define AMBIENT9_SLAVE_ADDR 0x53
83 
84 #define AMBIENT9_REG_MAIN_CTRL 0x00
85 #define AMBIENT9_REG_PS_LED 0x01
86 #define AMBIENT9_REG_PS_PULSES 0x02
87 #define AMBIENT9_REG_PS_MEAS_RATE 0x03
88 #define AMBIENT9_REG_ALS_MEAS_RATE 0x04
89 #define AMBIENT9_REG_ALS_GAIN 0x05
90 #define AMBIENT9_REG_PART_ID 0x06
91 #define AMBIENT9_REG_MAIN_STATUS 0x07
92 #define AMBIENT9_REG_PS_DATA_0 0x08
93 #define AMBIENT9_REG_PS_DATA_1 0x09
94 #define AMBIENT9_REG_LS_CLEAR_DATA_0 0x0A
95 #define AMBIENT9_REG_LS_CLEAR_DATA_1 0x0B
96 #define AMBIENT9_REG_LS_CLEAR_DATA_2 0x0C
97 #define AMBIENT9_REG_ALS_DATA_0 0x0D
98 #define AMBIENT9_REG_ALS_DATA_1 0x0E
99 #define AMBIENT9_REG_ALS_DATA_2 0x0F
100 #define AMBIENT9_REG_INT_CFG 0x19
101 #define AMBIENT9_REG_INT_PST 0x1A
102 #define AMBIENT9_REG_PS_THRES_UP_0 0x1B
103 #define AMBIENT9_REG_PS_THRES_UP_1 0x1C
104 #define AMBIENT9_REG_PS_THRES_LOW_0 0x1D
105 #define AMBIENT9_REG_PS_THRES_LOW_1 0x1E
106 #define AMBIENT9_REG_PS_CAN_DIG_0 0x1F
107 #define AMBIENT9_REG_PS_CAN_DIG_1 0x20
108 #define AMBIENT9_REG_PS_CAN_ANA_DURATION 0x21
109 #define AMBIENT9_REG_PS_CAN_ANA_CURRENT 0x22
110 #define AMBIENT9_REG_PS_AV_HYST 0x23
111 #define AMBIENT9_REG_ALS_THRES_UP_0 0x24
112 #define AMBIENT9_REG_ALS_THRES_UP_1 0x25
113 #define AMBIENT9_REG_ALS_THRES_UP_2 0x26
114 #define AMBIENT9_REG_ALS_THRES_LOW_0 0x27
115 #define AMBIENT9_REG_ALS_THRES_LOW_1 0x28
116 #define AMBIENT9_REG_ALS_THRES_LOW_2 0x29
117 #define AMBIENT9_REG_ALS_THRES_VAR 0x2A
118 
119 #define AMBIENT9_PART_ID_VAL 0x03
120 #define AMBIENT9_POWER_ON 0x20
121 
122 #define AMBIENT9_ALS 0xAA
123 #define AMBIENT9_PROXY 0xBB
124  // End group macro
126 // --------------------------------------------------------------- PUBLIC TYPES
135 typedef struct
136 {
137  // Input pins
138 
139  digital_in_t int_pin;
140 
141  // Modules
142 
143  i2c_master_t i2c;
144 
145  // ctx variable
146 
147  uint8_t slave_address;
148 
149 } ambient9_t;
150 
154 typedef struct
155 {
156  // Communication gpio pins
157 
158  pin_name_t scl;
159  pin_name_t sda;
160 
161  // Additional gpio pins
162 
163  pin_name_t int_pin;
164 
165  // static variable
166 
167  uint32_t i2c_speed;
168  uint8_t i2c_address;
169 
171  // End types group
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
193 
202 
213 void ambient9_generic_write ( ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
214 
226 void ambient9_generic_read ( ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
236 
244 uint32_t ambient9_als_data ( ambient9_t *ctx );
245 
253 uint16_t ambient9_proxy_data ( ambient9_t *ctx );
254 
262 void ambient9_enable_data ( ambient9_t *ctx, uint8_t als_ps );
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 #endif // _AMBIENT9_H_
268  // End public_function group
271 
272 // ------------------------------------------------------------------------- END
ambient9_cfg_t::scl
pin_name_t scl
Definition: ambient9.h:158
ambient9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient9.h:167
ambient9_get_int_status
uint8_t ambient9_get_int_status(ambient9_t *ctx)
Generic function for getting int pin status.
ambient9_init
AMBIENT9_RETVAL ambient9_init(ambient9_t *ctx, ambient9_cfg_t *cfg)
Initialization function.
ambient9_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient9.h:163
ambient9_cfg_t
Click configuration structure definition.
Definition: ambient9.h:155
ambient9_t::int_pin
digital_in_t int_pin
Definition: ambient9.h:139
ambient9_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient9.h:168
ambient9_als_data
uint32_t ambient9_als_data(ambient9_t *ctx)
Generic function for reading ALS data from sensor.
ambient9_t::i2c
i2c_master_t i2c
Definition: ambient9.h:143
AMBIENT9_RETVAL
#define AMBIENT9_RETVAL
Definition: ambient9.h:76
ambient9_cfg_t::sda
pin_name_t sda
Definition: ambient9.h:159
ambient9_t
Click ctx object definition.
Definition: ambient9.h:136
ambient9_enable_data
void ambient9_enable_data(ambient9_t *ctx, uint8_t als_ps)
Function for enabeling sensor for ALS or proximity.
ambient9_t::slave_address
uint8_t slave_address
Definition: ambient9.h:147
ambient9_generic_read
void ambient9_generic_read(ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
ambient9_generic_write
void ambient9_generic_write(ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ambient9_proxy_data
uint16_t ambient9_proxy_data(ambient9_t *ctx)
Generic function for reading proximity data from sensor.
ambient9_cfg_setup
void ambient9_cfg_setup(ambient9_cfg_t *cfg)
Config Object Initialization function.