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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 
41 #include "drv_i2c_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define FAN3_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
56 
62 #define FAN3_RETVAL uint8_t
63 
64 #define FAN3_OK 0x00
65 #define FAN3_INIT_ERROR 0xFF
66 
72 #define FAN3_STOPPED 0x00
73 #define FAN3_SPEED1 0x01
74 #define FAN3_SPEED2 0x02
75 #define FAN3_SPEED3 0x03
76 #define FAN3_SPEED4 0x04
77 #define FAN3_SPEED5 0x05
78 #define FAN3_SPEED6 0x06
79 #define FAN3_SPEED7 0x07
80  // End group macro
83 // --------------------------------------------------------------- PUBLIC TYPES
92 typedef struct
93 {
94  // Modules
95 
96  i2c_master_t i2c;
97 
98  // ctx variable
99 
100  uint8_t slave_address;
101 
102 } fan3_t;
103 
107 typedef struct
108 {
109  // Communication gpio pins
110 
111  pin_name_t scl;
112  pin_name_t sda;
113 
114  // static variable
115 
116  uint32_t i2c_speed;
117  uint8_t i2c_address;
118 
119 } fan3_cfg_t;
120  // End types group
122 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
123 
129 #ifdef __cplusplus
130 extern "C"{
131 #endif
132 
141 void fan3_cfg_setup ( fan3_cfg_t *cfg );
142 
151 FAN3_RETVAL fan3_init ( fan3_t *ctx, fan3_cfg_t *cfg );
152 
163 void fan3_generic_write ( fan3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
164 
175 void fan3_generic_read ( fan3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
176 
185 void fan3_set_speed ( fan3_t *ctx, uint8_t new_speed );
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 #endif // _FAN3_H_
191  // End public_function group
194 
195 // ------------------------------------------------------------------------- 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:116
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:112
FAN3_RETVAL
#define FAN3_RETVAL
Definition: fan3.h:62
fan3_cfg_t::scl
pin_name_t scl
Definition: fan3.h:111
fan3_t
Click ctx object definition.
Definition: fan3.h:92
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:107
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:96
fan3_t::slave_address
uint8_t slave_address
Definition: fan3.h:100
fan3_cfg_t::i2c_address
uint8_t i2c_address
Definition: fan3.h:117