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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define AMBIENT4_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
70 
77 #define AMBIENT4_RETVAL uint8_t
78 
79 #define AMBIENT4_OK 0x00
80 #define AMBIENT4_INIT_ERROR 0xFF
81 
87 #define AMBIENT4_CMD_POWER_DOWN 0x00
88 #define AMBIENT4_CMD_POWER_ON 0x01
89 #define AMBIENT4_CMD_AUTO_RESOLUTION_MODE 0x10
90 #define AMBIENT4_CMD_HIGH_RESOLUTION_MODE 0x12
91 #define AMBIENT4_CMD_LOW_RESOLUTION_MODE 0x13
92  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  // Output pins
107 
108  digital_out_t rst;
109 
110  // Modules
111 
112  i2c_master_t i2c;
113 
114  // ctx variable
115 
116  uint8_t slave_address;
117 
118 } ambient4_t;
119 
123 typedef struct
124 {
125  // Communication gpio pins
126 
127  pin_name_t scl;
128  pin_name_t sda;
129 
130  // Additional gpio pins
131 
132  pin_name_t rst;
133 
134  // static variable
135 
136  uint32_t i2c_speed;
137  uint8_t i2c_address;
138 
140  // End types group
142 
143 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
144 
150 #ifdef __cplusplus
151 extern "C"{
152 #endif
153 
163 
173 
182 
193 void ambient4_generic_write ( ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
194 
206 void ambient4_generic_read ( ambient4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
207 
217 void ambient4_send_command ( ambient4_t *ctx, uint8_t cmd );
218 
227 uint16_t ambient4_read_data ( ambient4_t *ctx );
228 
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 #endif // _AMBIENT4_H_
243  // End public_function group
246 
247 // ------------------------------------------------------------------------- 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:108
ambient4_cfg_t
Click configuration structure definition.
Definition: ambient4.h:124
ambient4_cfg_t::rst
pin_name_t rst
Definition: ambient4.h:132
ambient4_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient4.h:137
ambient4_t::slave_address
uint8_t slave_address
Definition: ambient4.h:116
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:136
ambient4_t
Click ctx object definition.
Definition: ambient4.h:105
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:127
ambient4_t::i2c
i2c_master_t i2c
Definition: ambient4.h:112
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:128
AMBIENT4_RETVAL
#define AMBIENT4_RETVAL
Definition: ambient4.h:77