fan3  2.0.0.0
fan3.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 FAN3_H
36 #define FAN3_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 
51 #include "drv_i2c_master.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define FAN3_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
66 
72 #define FAN3_RETVAL uint8_t
73 
74 #define FAN3_OK 0x00
75 #define FAN3_INIT_ERROR 0xFF
76 
82 #define FAN3_STOPPED 0x00
83 #define FAN3_SPEED1 0x01
84 #define FAN3_SPEED2 0x02
85 #define FAN3_SPEED3 0x03
86 #define FAN3_SPEED4 0x04
87 #define FAN3_SPEED5 0x05
88 #define FAN3_SPEED6 0x06
89 #define FAN3_SPEED7 0x07
90  // End group macro
93 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104  // Modules
105 
106  i2c_master_t i2c;
107 
108  // ctx variable
109 
110  uint8_t slave_address;
111 
112 } fan3_t;
113 
117 typedef struct
118 {
119  // Communication gpio pins
120 
121  pin_name_t scl;
122  pin_name_t sda;
123 
124  // static variable
125 
126  uint32_t i2c_speed;
127  uint8_t i2c_address;
128 
129 } fan3_cfg_t;
130  // End types group
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
152 
162 
173 void fan3_generic_write ( fan3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
174 
185 void fan3_generic_read ( fan3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
186 
195 void fan3_set_speed ( fan3_t *ctx, uint8_t new_speed );
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 #endif // _FAN3_H_
201  // End public_function group
204 
205 // ------------------------------------------------------------------------- END
fan3_generic_read
void fan3_generic_read(fan3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
fan3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: fan3.h:126
fan3_init
FAN3_RETVAL fan3_init(fan3_t *ctx, fan3_cfg_t *cfg)
Initialization function.
fan3_set_speed
void fan3_set_speed(fan3_t *ctx, uint8_t new_speed)
Set speed.
fan3_cfg_t::sda
pin_name_t sda
Definition: fan3.h:122
FAN3_RETVAL
#define FAN3_RETVAL
Definition: fan3.h:72
fan3_cfg_t::scl
pin_name_t scl
Definition: fan3.h:121
fan3_t
Click ctx object definition.
Definition: fan3.h:103
fan3_cfg_setup
void fan3_cfg_setup(fan3_cfg_t *cfg)
Config Object Initialization function.
fan3_cfg_t
Click configuration structure definition.
Definition: fan3.h:118
fan3_generic_write
void fan3_generic_write(fan3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
fan3_t::i2c
i2c_master_t i2c
Definition: fan3.h:106
fan3_t::slave_address
uint8_t slave_address
Definition: fan3.h:110
fan3_cfg_t::i2c_address
uint8_t i2c_address
Definition: fan3.h:127