uvc  2.0.0.0
uvc.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 UVC_H
36 #define UVC_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 UVC_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
56 
62 #define UVC_RETVAL uint8_t
63 
64 #define UVC_OK 0x00
65 #define UVC_INIT_ERROR 0xFF
66 
72 #define UVC_DEVICE_SLAVE_ADDR 0x4D
73  // End group macro
76 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Output pins
88 
89  digital_out_t an;
90 
91  // Modules
92 
93  i2c_master_t i2c;
94 
95  // ctx variable
96 
97  uint8_t slave_address;
98 
99 } uvc_t;
100 
104 typedef struct
105 {
106  // Communication gpio pins
107 
108  pin_name_t scl;
109  pin_name_t sda;
110 
111  // Additional gpio pins
112 
113  pin_name_t an;
114 
115  // static variable
116 
117  uint32_t i2c_speed;
118  uint8_t i2c_address;
119 
120 } uvc_cfg_t;
121  // End types group
123 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
124 
130 #ifdef __cplusplus
131 extern "C"{
132 #endif
133 
142 void uvc_cfg_setup ( uvc_cfg_t *cfg );
143 
153 
164 void uvc_generic_write ( uvc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
165 
176 void uvc_generic_read ( uvc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
177 
187 uint16_t uvc_read_raw_data ( uvc_t *ctx );
188 
198 float uvc_get_voltage ( uvc_t *ctx );
199 
210 float uvc_calculate_power ( float voltage );
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 #endif // _UVC_H_
216  // End public_function group
219 
220 // ------------------------------------------------------------------------- END
uvc_cfg_t::sda
pin_name_t sda
Definition: uvc.h:109
uvc_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uvc.h:117
uvc_calculate_power
float uvc_calculate_power(float voltage)
Calculate power.
uvc_cfg_t::scl
pin_name_t scl
Definition: uvc.h:108
uvc_get_voltage
float uvc_get_voltage(uvc_t *ctx)
Calculate voltage.
uvc_t
Click ctx object definition.
Definition: uvc.h:86
uvc_init
UVC_RETVAL uvc_init(uvc_t *ctx, uvc_cfg_t *cfg)
Initialization function.
uvc_generic_read
void uvc_generic_read(uvc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uvc_cfg_t::an
pin_name_t an
Definition: uvc.h:113
uvc_t::i2c
i2c_master_t i2c
Definition: uvc.h:93
uvc_cfg_t::i2c_address
uint8_t i2c_address
Definition: uvc.h:118
uvc_generic_write
void uvc_generic_write(uvc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uvc_t::an
digital_out_t an
Definition: uvc.h:89
uvc_cfg_t
Click configuration structure definition.
Definition: uvc.h:105
uvc_t::slave_address
uint8_t slave_address
Definition: uvc.h:97
UVC_RETVAL
#define UVC_RETVAL
Definition: uvc.h:62
uvc_cfg_setup
void uvc_cfg_setup(uvc_cfg_t *cfg)
Config Object Initialization function.
uvc_read_raw_data
uint16_t uvc_read_raw_data(uvc_t *ctx)
Read 12bit raw data.