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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define AMBIENT9_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define AMBIENT9_RETVAL uint8_t
73 
74 #define AMBIENT9_OK 0x00
75 #define AMBIENT9_INIT_ERROR 0xFF
76 
78 #define AMBIENT9_SLAVE_ADDR 0x53
79 
80 #define AMBIENT9_REG_MAIN_CTRL 0x00
81 #define AMBIENT9_REG_PS_LED 0x01
82 #define AMBIENT9_REG_PS_PULSES 0x02
83 #define AMBIENT9_REG_PS_MEAS_RATE 0x03
84 #define AMBIENT9_REG_ALS_MEAS_RATE 0x04
85 #define AMBIENT9_REG_ALS_GAIN 0x05
86 #define AMBIENT9_REG_PART_ID 0x06
87 #define AMBIENT9_REG_MAIN_STATUS 0x07
88 #define AMBIENT9_REG_PS_DATA_0 0x08
89 #define AMBIENT9_REG_PS_DATA_1 0x09
90 #define AMBIENT9_REG_LS_CLEAR_DATA_0 0x0A
91 #define AMBIENT9_REG_LS_CLEAR_DATA_1 0x0B
92 #define AMBIENT9_REG_LS_CLEAR_DATA_2 0x0C
93 #define AMBIENT9_REG_ALS_DATA_0 0x0D
94 #define AMBIENT9_REG_ALS_DATA_1 0x0E
95 #define AMBIENT9_REG_ALS_DATA_2 0x0F
96 #define AMBIENT9_REG_INT_CFG 0x19
97 #define AMBIENT9_REG_INT_PST 0x1A
98 #define AMBIENT9_REG_PS_THRES_UP_0 0x1B
99 #define AMBIENT9_REG_PS_THRES_UP_1 0x1C
100 #define AMBIENT9_REG_PS_THRES_LOW_0 0x1D
101 #define AMBIENT9_REG_PS_THRES_LOW_1 0x1E
102 #define AMBIENT9_REG_PS_CAN_DIG_0 0x1F
103 #define AMBIENT9_REG_PS_CAN_DIG_1 0x20
104 #define AMBIENT9_REG_PS_CAN_ANA_DURATION 0x21
105 #define AMBIENT9_REG_PS_CAN_ANA_CURRENT 0x22
106 #define AMBIENT9_REG_PS_AV_HYST 0x23
107 #define AMBIENT9_REG_ALS_THRES_UP_0 0x24
108 #define AMBIENT9_REG_ALS_THRES_UP_1 0x25
109 #define AMBIENT9_REG_ALS_THRES_UP_2 0x26
110 #define AMBIENT9_REG_ALS_THRES_LOW_0 0x27
111 #define AMBIENT9_REG_ALS_THRES_LOW_1 0x28
112 #define AMBIENT9_REG_ALS_THRES_LOW_2 0x29
113 #define AMBIENT9_REG_ALS_THRES_VAR 0x2A
114 
115 #define AMBIENT9_PART_ID_VAL 0x03
116 #define AMBIENT9_POWER_ON 0x20
117 
118 #define AMBIENT9_ALS 0xAA
119 #define AMBIENT9_PROXY 0xBB
120  // End group macro
122 // --------------------------------------------------------------- PUBLIC TYPES
131 typedef struct
132 {
133  // Input pins
134 
135  digital_in_t int_pin;
136 
137  // Modules
138 
139  i2c_master_t i2c;
140 
141  // ctx variable
142 
143  uint8_t slave_address;
144 
145 } ambient9_t;
146 
150 typedef struct
151 {
152  // Communication gpio pins
153 
154  pin_name_t scl;
155  pin_name_t sda;
156 
157  // Additional gpio pins
158 
159  pin_name_t int_pin;
160 
161  // static variable
162 
163  uint32_t i2c_speed;
164  uint8_t i2c_address;
165 
167  // End types group
169 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
170 
176 #ifdef __cplusplus
177 extern "C"{
178 #endif
179 
189 
198 
209 void ambient9_generic_write ( ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
210 
222 void ambient9_generic_read ( ambient9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
223 
232 
240 uint32_t ambient9_als_data ( ambient9_t *ctx );
241 
249 uint16_t ambient9_proxy_data ( ambient9_t *ctx );
250 
258 void ambient9_enable_data ( ambient9_t *ctx, uint8_t als_ps );
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif // _AMBIENT9_H_
264  // End public_function group
267 
268 // ------------------------------------------------------------------------- END
ambient9_cfg_t::scl
pin_name_t scl
Definition: ambient9.h:154
ambient9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient9.h:163
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:159
ambient9_cfg_t
Click configuration structure definition.
Definition: ambient9.h:151
ambient9_t::int_pin
digital_in_t int_pin
Definition: ambient9.h:135
ambient9_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient9.h:164
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:139
AMBIENT9_RETVAL
#define AMBIENT9_RETVAL
Definition: ambient9.h:72
ambient9_cfg_t::sda
pin_name_t sda
Definition: ambient9.h:155
ambient9_t
Click ctx object definition.
Definition: ambient9.h:132
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:143
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.