driver2 2.0.0.0
driver2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2021 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef DRIVER2_H
29#define DRIVER2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_pwm.h"
52
73#define DRIVER2_PIN_ENABLE 0x01
74#define DRIVER2_PIN_DISABLE 0x00
75
80#define DRIVER2_DEF_FREQ 5000
81
82 // driver2_cfg
83
98#define DRIVER2_MAP_MIKROBUS( cfg, mikrobus ) \
99 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
100 cfg.sd = MIKROBUS( mikrobus, MIKROBUS_CS ); \
101 cfg.fb = MIKROBUS( mikrobus, MIKROBUS_INT )
102
103 // driver2_map
104 // driver2
105
115typedef struct
116{
117 // Output pins
118 digital_out_t sd;
120 // Input pins
121 digital_in_t fb;
123 // Modules
124 pwm_t pwm;
126 // ctx variable
127 uint32_t pwm_freq;
129} driver2_t;
130
135typedef struct
136{
137 // Communication gpio pins
138 pin_name_t pwm;
140 // Additional gpio pins
141 pin_name_t sd;
142 pin_name_t fb;
144 // Static variable
145 uint32_t dev_pwm_freq;
148
153typedef enum
154{
156 DRIVER2_ERROR = -1
157
159
176
191
206
218err_t driver2_set_duty_cycle ( driver2_t *ctx, float duty_cycle );
219
231
243
252void driver2_set_sd_pin ( driver2_t *ctx, uint8_t state );
253
262void driver2_set_pwm_pin ( driver2_t *ctx, uint8_t state );
263
272
273#ifdef __cplusplus
274}
275#endif
276#endif // DRIVER2_H
277
278 // driver2
279
280// ------------------------------------------------------------------------ END
driver2_return_value_t
Driver 2 Click return value data.
Definition driver2.h:154
@ DRIVER2_ERROR
Definition driver2.h:156
@ DRIVER2_OK
Definition driver2.h:155
err_t driver2_init(driver2_t *ctx, driver2_cfg_t *cfg)
Driver 2 initialization function.
err_t driver2_default_cfg(driver2_t *ctx)
Driver 2 default configuration function.
void driver2_cfg_setup(driver2_cfg_t *cfg)
Driver 2 configuration object setup function.
void driver2_set_pwm_pin(driver2_t *ctx, uint8_t state)
Set PWM pin.
void driver2_set_sd_pin(driver2_t *ctx, uint8_t state)
Set SD pin.
err_t driver2_set_duty_cycle(driver2_t *ctx, float duty_cycle)
Driver 2 sets PWM duty cycle.
uint8_t driver2_get_fb_pin(driver2_t *ctx)
Get FB pin.
err_t driver2_pwm_stop(driver2_t *ctx)
Driver 2 stop PWM module.
err_t driver2_pwm_start(driver2_t *ctx)
Driver 2 start PWM module.
Driver 2 Click configuration object.
Definition driver2.h:136
pin_name_t sd
Definition driver2.h:141
pin_name_t fb
Definition driver2.h:142
uint32_t dev_pwm_freq
Definition driver2.h:145
pin_name_t pwm
Definition driver2.h:138
Driver 2 Click driver selector.
Definition driver2.h:116
digital_out_t sd
Definition driver2.h:118
digital_in_t fb
Definition driver2.h:121
uint32_t pwm_freq
Definition driver2.h:127
pwm_t pwm
Definition driver2.h:124