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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define AMBIENT9_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define AMBIENT9_RETVAL uint8_t
63 
64 #define AMBIENT9_OK 0x00
65 #define AMBIENT9_INIT_ERROR 0xFF
66 
68 #define AMBIENT9_SLAVE_ADDR 0x53
69 
70 #define AMBIENT9_REG_MAIN_CTRL 0x00
71 #define AMBIENT9_REG_PS_LED 0x01
72 #define AMBIENT9_REG_PS_PULSES 0x02
73 #define AMBIENT9_REG_PS_MEAS_RATE 0x03
74 #define AMBIENT9_REG_ALS_MEAS_RATE 0x04
75 #define AMBIENT9_REG_ALS_GAIN 0x05
76 #define AMBIENT9_REG_PART_ID 0x06
77 #define AMBIENT9_REG_MAIN_STATUS 0x07
78 #define AMBIENT9_REG_PS_DATA_0 0x08
79 #define AMBIENT9_REG_PS_DATA_1 0x09
80 #define AMBIENT9_REG_LS_CLEAR_DATA_0 0x0A
81 #define AMBIENT9_REG_LS_CLEAR_DATA_1 0x0B
82 #define AMBIENT9_REG_LS_CLEAR_DATA_2 0x0C
83 #define AMBIENT9_REG_ALS_DATA_0 0x0D
84 #define AMBIENT9_REG_ALS_DATA_1 0x0E
85 #define AMBIENT9_REG_ALS_DATA_2 0x0F
86 #define AMBIENT9_REG_INT_CFG 0x19
87 #define AMBIENT9_REG_INT_PST 0x1A
88 #define AMBIENT9_REG_PS_THRES_UP_0 0x1B
89 #define AMBIENT9_REG_PS_THRES_UP_1 0x1C
90 #define AMBIENT9_REG_PS_THRES_LOW_0 0x1D
91 #define AMBIENT9_REG_PS_THRES_LOW_1 0x1E
92 #define AMBIENT9_REG_PS_CAN_DIG_0 0x1F
93 #define AMBIENT9_REG_PS_CAN_DIG_1 0x20
94 #define AMBIENT9_REG_PS_CAN_ANA_DURATION 0x21
95 #define AMBIENT9_REG_PS_CAN_ANA_CURRENT 0x22
96 #define AMBIENT9_REG_PS_AV_HYST 0x23
97 #define AMBIENT9_REG_ALS_THRES_UP_0 0x24
98 #define AMBIENT9_REG_ALS_THRES_UP_1 0x25
99 #define AMBIENT9_REG_ALS_THRES_UP_2 0x26
100 #define AMBIENT9_REG_ALS_THRES_LOW_0 0x27
101 #define AMBIENT9_REG_ALS_THRES_LOW_1 0x28
102 #define AMBIENT9_REG_ALS_THRES_LOW_2 0x29
103 #define AMBIENT9_REG_ALS_THRES_VAR 0x2A
104 
105 #define AMBIENT9_PART_ID_VAL 0x03
106 #define AMBIENT9_POWER_ON 0x20
107 
108 #define AMBIENT9_ALS 0xAA
109 #define AMBIENT9_PROXY 0xBB
110  // End group macro
112 // --------------------------------------------------------------- PUBLIC TYPES
121 typedef struct
122 {
123  // Input pins
124 
125  digital_in_t int_pin;
126 
127  // Modules
128 
129  i2c_master_t i2c;
130 
131  // ctx variable
132 
133  uint8_t slave_address;
134 
135 } ambient9_t;
136 
140 typedef struct
141 {
142  // Communication gpio pins
143 
144  pin_name_t scl;
145  pin_name_t sda;
146 
147  // Additional gpio pins
148 
149  pin_name_t int_pin;
150 
151  // static variable
152 
153  uint32_t i2c_speed;
154  uint8_t i2c_address;
155 
157  // End types group
159 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160 
166 #ifdef __cplusplus
167 extern "C"{
168 #endif
169 
178 void ambient9_cfg_setup ( ambient9_cfg_t *cfg );
179 
188 
199 void ambient9_generic_write ( ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
200 
212 void ambient9_generic_read ( ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
213 
221 uint8_t ambient9_get_int_status ( ambient9_t *ctx );
222 
230 uint32_t ambient9_als_data ( ambient9_t *ctx );
231 
239 uint16_t ambient9_proxy_data ( ambient9_t *ctx );
240 
248 void ambient9_enable_data ( ambient9_t *ctx, uint8_t als_ps );
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // _AMBIENT9_H_
254  // End public_function group
257 
258 // ------------------------------------------------------------------------- END
ambient9_cfg_t::scl
pin_name_t scl
Definition: ambient9.h:144
ambient9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient9.h:153
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:149
ambient9_cfg_t
Click configuration structure definition.
Definition: ambient9.h:140
ambient9_t::int_pin
digital_in_t int_pin
Definition: ambient9.h:125
ambient9_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient9.h:154
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:129
AMBIENT9_RETVAL
#define AMBIENT9_RETVAL
Definition: ambient9.h:62
ambient9_cfg_t::sda
pin_name_t sda
Definition: ambient9.h:145
ambient9_t
Click ctx object definition.
Definition: ambient9.h:121
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:133
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.