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 "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 AMBIENT4_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
66 
73 #define AMBIENT4_RETVAL uint8_t
74 
75 #define AMBIENT4_OK 0x00
76 #define AMBIENT4_INIT_ERROR 0xFF
77 
83 #define AMBIENT4_CMD_POWER_DOWN 0x00
84 #define AMBIENT4_CMD_POWER_ON 0x01
85 #define AMBIENT4_CMD_AUTO_RESOLUTION_MODE 0x10
86 #define AMBIENT4_CMD_HIGH_RESOLUTION_MODE 0x12
87 #define AMBIENT4_CMD_LOW_RESOLUTION_MODE 0x13
88  // End group macro
91 // --------------------------------------------------------------- PUBLIC TYPES
100 typedef struct
101 {
102  // Output pins
103 
104  digital_out_t rst;
105 
106  // Modules
107 
108  i2c_master_t i2c;
109 
110  // ctx variable
111 
112  uint8_t slave_address;
113 
114 } ambient4_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t scl;
124  pin_name_t sda;
125 
126  // Additional gpio pins
127 
128  pin_name_t rst;
129 
130  // static variable
131 
132  uint32_t i2c_speed;
133  uint8_t i2c_address;
134 
136  // End types group
138 
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
169 
178 
189 void ambient4_generic_write ( ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
190 
202 void ambient4_generic_read ( ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
203 
213 void ambient4_send_command ( ambient4_t *ctx, uint8_t cmd );
214 
223 uint16_t ambient4_read_data ( ambient4_t *ctx );
224 
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 #endif // _AMBIENT4_H_
239  // End public_function group
242 
243 // ------------------------------------------------------------------------- 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_setup
void ambient4_cfg_setup(ambient4_cfg_t *cfg)
Config Object Initialization function.
ambient4_t::rst
digital_out_t rst
Definition: ambient4.h:104
ambient4_cfg_t
Click configuration structure definition.
Definition: ambient4.h:120
ambient4_cfg_t::rst
pin_name_t rst
Definition: ambient4.h:128
ambient4_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient4.h:133
ambient4_t::slave_address
uint8_t slave_address
Definition: ambient4.h:112
ambient4_init
AMBIENT4_RETVAL ambient4_init(ambient4_t *ctx, ambient4_cfg_t *cfg)
Initialization function.
ambient4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient4.h:132
ambient4_t
Click ctx object definition.
Definition: ambient4.h:101
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:123
ambient4_t::i2c
i2c_master_t i2c
Definition: ambient4.h:108
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:124
AMBIENT4_RETVAL
#define AMBIENT4_RETVAL
Definition: ambient4.h:73