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 "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 UVC_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
66 
72 #define UVC_RETVAL uint8_t
73 
74 #define UVC_OK 0x00
75 #define UVC_INIT_ERROR 0xFF
76 
82 #define UVC_DEVICE_SLAVE_ADDR 0x4D
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97  // Output pins
98 
99  digital_out_t an;
100 
101  // Modules
102 
103  i2c_master_t i2c;
104 
105  // ctx variable
106 
107  uint8_t slave_address;
108 
109 } uvc_t;
110 
114 typedef struct
115 {
116  // Communication gpio pins
117 
118  pin_name_t scl;
119  pin_name_t sda;
120 
121  // Additional gpio pins
122 
123  pin_name_t an;
124 
125  // static variable
126 
127  uint32_t i2c_speed;
128  uint8_t i2c_address;
129 
130 } uvc_cfg_t;
131  // End types group
133 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
152 void uvc_cfg_setup ( uvc_cfg_t *cfg );
153 
163 
174 void uvc_generic_write ( uvc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
175 
186 void uvc_generic_read ( uvc_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
187 
197 uint16_t uvc_read_raw_data ( uvc_t *ctx );
198 
208 float uvc_get_voltage ( uvc_t *ctx );
209 
220 float uvc_calculate_power ( float voltage );
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 #endif // _UVC_H_
226  // End public_function group
229 
230 // ------------------------------------------------------------------------- END
uvc_cfg_t::sda
pin_name_t sda
Definition: uvc.h:119
uvc_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uvc.h:127
uvc_calculate_power
float uvc_calculate_power(float voltage)
Calculate power.
uvc_cfg_t::scl
pin_name_t scl
Definition: uvc.h:118
uvc_get_voltage
float uvc_get_voltage(uvc_t *ctx)
Calculate voltage.
uvc_t
Click ctx object definition.
Definition: uvc.h:96
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:123
uvc_t::i2c
i2c_master_t i2c
Definition: uvc.h:103
uvc_cfg_t::i2c_address
uint8_t i2c_address
Definition: uvc.h:128
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:99
uvc_cfg_t
Click configuration structure definition.
Definition: uvc.h:115
uvc_t::slave_address
uint8_t slave_address
Definition: uvc.h:107
UVC_RETVAL
#define UVC_RETVAL
Definition: uvc.h:72
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.