leddriver2  2.0.0.0
leddriver2.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 LEDDRIVER2_H
36 #define LEDDRIVER2_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_pwm.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define LEDDRIVER2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
68 
74 #define LEDDRIVER2_RETVAL uint8_t
75 
76 #define LEDDRIVER2_OK 0x00
77 #define LEDDRIVER2_INIT_ERROR 0xFF
78 
84 #define LEDDRIVER2_DEF_FREQ 2000
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99 
100  // Modules
101 
102  pwm_t pwm;
103 
104  // ctx variable
105 
106  uint32_t pwm_freq;
107 
108 } leddriver2_t;
109 
113 typedef struct
114 {
115  // Communication gpio pins
116 
117  pin_name_t pwm;
118 
119  // static variable
120 
121  uint32_t dev_pwm_freq;
122 
124  // End types group
126 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
127 
133 #ifdef __cplusplus
134 extern "C"{
135 #endif
136 
146 
155 
165 void leddriver2_set_duty_cycle ( leddriver2_t *ctx, float duty_cycle );
166 
175 
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 #endif // _LEDDRIVER2_H_
189  // End public_function group
192 
193 // ------------------------------------------------------------------------- END
leddriver2_cfg_t::pwm
pin_name_t pwm
Definition: leddriver2.h:117
leddriver2_set_duty_cycle
void leddriver2_set_duty_cycle(leddriver2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
leddriver2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: leddriver2.h:121
leddriver2_cfg_t
Click configuration structure definition.
Definition: leddriver2.h:114
leddriver2_cfg_setup
void leddriver2_cfg_setup(leddriver2_cfg_t *cfg)
Config Object Initialization function.
leddriver2_t
Click ctx object definition.
Definition: leddriver2.h:98
leddriver2_t::pwm_freq
uint32_t pwm_freq
Definition: leddriver2.h:106
LEDDRIVER2_RETVAL
#define LEDDRIVER2_RETVAL
Definition: leddriver2.h:74
leddriver2_pwm_stop
void leddriver2_pwm_stop(leddriver2_t *ctx)
Stop PWM module.
leddriver2_pwm_start
void leddriver2_pwm_start(leddriver2_t *ctx)
Start PWM module.
leddriver2_t::pwm
pwm_t pwm
Definition: leddriver2.h:102
leddriver2_init
LEDDRIVER2_RETVAL leddriver2_init(leddriver2_t *ctx, leddriver2_cfg_t *cfg)
Initialization function.