ambient4  2.0.0.0
ambient4.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * 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 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define AMBIENT4_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
57 
64 #define AMBIENT4_RETVAL uint8_t
65 
66 #define AMBIENT4_OK 0x00
67 #define AMBIENT4_INIT_ERROR 0xFF
68 
74 #define AMBIENT4_CMD_POWER_DOWN 0x00
75 #define AMBIENT4_CMD_POWER_ON 0x01
76 #define AMBIENT4_CMD_AUTO_RESOLUTION_MODE 0x10
77 #define AMBIENT4_CMD_HIGH_RESOLUTION_MODE 0x12
78 #define AMBIENT4_CMD_LOW_RESOLUTION_MODE 0x13
79  // End group macro
82 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef struct
92 {
93  // Output pins
94 
95  digital_out_t rst;
96 
97  // Modules
98 
99  i2c_master_t i2c;
100 
101  // ctx variable
102 
103  hal_i2c_address_t slave_address;
104 
105 } ambient4_t;
106 
110 typedef struct
111 {
112  // Communication gpio pins
113 
114  pin_name_t scl;
115  pin_name_t sda;
116 
117  // Additional gpio pins
118 
119  pin_name_t rst;
120 
121  // static variable
122 
123  hal_i2c_speed_t i2c_speed;
124  hal_i2c_address_t i2c_address;
125 
127  // End types group
129 
130 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
131 
137 #ifdef __cplusplus
138 extern "C"{
139 #endif
140 
149 void ambient4_cfg_setup ( ambient4_cfg_t *cfg );
150 
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
ambient4_generic_read
void ambient4_generic_read(ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
ambient4_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: ambient4.h:124
ambient4_t::slave_address
hal_i2c_address_t slave_address
Definition: ambient4.h:103
ambient4_cfg_setup
void ambient4_cfg_setup(ambient4_cfg_t *cfg)
Config Object Initialization function.
ambient4_t::rst
digital_out_t rst
Definition: ambient4.h:95
ambient4_cfg_t
Click configuration structure definition.
Definition: ambient4.h:110
ambient4_cfg_t::rst
pin_name_t rst
Definition: ambient4.h:119
ambient4_init
AMBIENT4_RETVAL ambient4_init(ambient4_t *ctx, ambient4_cfg_t *cfg)
Initialization function.
ambient4_t
Click ctx object definition.
Definition: ambient4.h:91
ambient4_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: ambient4.h:123
ambient4_default_cfg
void ambient4_default_cfg(ambient4_t *ctx)
Click Default Configuration function.
ambient4_send_command
void ambient4_send_command(ambient4_t *ctx, uint8_t cmd)
Function for send command.
ambient4_device_reset
void ambient4_device_reset(ambient4_t *ctx)
Function for device reset.
ambient4_cfg_t::scl
pin_name_t scl
Definition: ambient4.h:114
ambient4_t::i2c
i2c_master_t i2c
Definition: ambient4.h:99
ambient4_read_data
uint16_t ambient4_read_data(ambient4_t *ctx)
Function for read 16bit data.
ambient4_generic_write
void ambient4_generic_write(ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ambient4_cfg_t::sda
pin_name_t sda
Definition: ambient4.h:115
AMBIENT4_RETVAL
#define AMBIENT4_RETVAL
Definition: ambient4.h:64