ambient4  2.0.0.0
ambient4.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 AMBIENT4_H
36 #define AMBIENT4_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 AMBIENT4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
56 
63 #define AMBIENT4_RETVAL uint8_t
64 
65 #define AMBIENT4_OK 0x00
66 #define AMBIENT4_INIT_ERROR 0xFF
67 
73 #define AMBIENT4_CMD_POWER_DOWN 0x00
74 #define AMBIENT4_CMD_POWER_ON 0x01
75 #define AMBIENT4_CMD_AUTO_RESOLUTION_MODE 0x10
76 #define AMBIENT4_CMD_HIGH_RESOLUTION_MODE 0x12
77 #define AMBIENT4_CMD_LOW_RESOLUTION_MODE 0x13
78  // End group macro
81 // --------------------------------------------------------------- PUBLIC TYPES
90 typedef struct
91 {
92  // Output pins
93 
94  digital_out_t rst;
95 
96  // Modules
97 
98  i2c_master_t i2c;
99 
100  // ctx variable
101 
102  uint8_t slave_address;
103 
104 } ambient4_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112 
113  pin_name_t scl;
114  pin_name_t sda;
115 
116  // Additional gpio pins
117 
118  pin_name_t rst;
119 
120  // static variable
121 
122  uint32_t i2c_speed;
123  uint8_t i2c_address;
124 
126  // End types group
128 
129 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
130 
136 #ifdef __cplusplus
137 extern "C"{
138 #endif
139 
148 void ambient4_cfg_setup ( ambient4_cfg_t *cfg );
149 
159 
167 void ambient4_default_cfg ( ambient4_t *ctx );
168 
179 void ambient4_generic_write ( ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
180 
192 void ambient4_generic_read ( ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
193 
203 void ambient4_send_command ( ambient4_t *ctx, uint8_t cmd );
204 
213 uint16_t ambient4_read_data ( ambient4_t *ctx );
214 
223 void ambient4_device_reset ( ambient4_t *ctx );
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 #endif // _AMBIENT4_H_
229  // End public_function group
232 
233 // ------------------------------------------------------------------------- END
void ambient4_device_reset(ambient4_t *ctx)
Function for device reset.
uint8_t i2c_address
Definition: ambient4.h:123
void ambient4_default_cfg(ambient4_t *ctx)
Click Default Configuration function.
uint32_t i2c_speed
Definition: ambient4.h:122
Click ctx object definition.
Definition: ambient4.h:90
pin_name_t rst
Definition: ambient4.h:118
void ambient4_generic_write(ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
Click configuration structure definition.
Definition: ambient4.h:109
pin_name_t sda
Definition: ambient4.h:114
i2c_master_t i2c
Definition: ambient4.h:98
digital_out_t rst
Definition: ambient4.h:94
void ambient4_send_command(ambient4_t *ctx, uint8_t cmd)
Function for send command.
uint16_t ambient4_read_data(ambient4_t *ctx)
Function for read 16bit data.
pin_name_t scl
Definition: ambient4.h:113
uint8_t slave_address
Definition: ambient4.h:102
#define AMBIENT4_RETVAL
Definition: ambient4.h:63
AMBIENT4_RETVAL ambient4_init(ambient4_t *ctx, ambient4_cfg_t *cfg)
Initialization function.
void ambient4_generic_read(ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void ambient4_cfg_setup(ambient4_cfg_t *cfg)
Config Object Initialization function.