leddriver  2.0.0.0
leddriver.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 LEDDRIVER_H
36 #define LEDDRIVER_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define LEDDRIVER_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
54 
60 #define LEDDRIVER_RETVAL uint8_t
61 
62 #define LEDDRIVER_OK 0x00
63 #define LEDDRIVER_INIT_ERROR 0xFF
64 #define LEDDRIVER_FREQ_ERROR 0xFE
65 
71 #define LEDDRIVER_DEF_FREQ 10000
72  // End group macro
75 // --------------------------------------------------------------- PUBLIC TYPES
84 typedef struct
85 {
86  pwm_t pwm;
87 
88  uint32_t pwm_freq;
89 
90 } leddriver_t;
91 
95 typedef struct
96 {
97  pin_name_t pwm;
98 
99  uint32_t dev_pwm_freq;
100 
102  // End types group
104 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
105 
111 #ifdef __cplusplus
112 extern "C"{
113 #endif
114 
124 
134 
142 uint16_t leddriver_get_pwm_max_duty ( leddriver_t *ctx );
143 
152 err_t leddriver_set_duty_cycle ( leddriver_t *ctx, float duty_cycle );
153 
161 err_t leddriver_pwm_stop ( leddriver_t *ctx );
162 
170 err_t leddriver_pwm_start ( leddriver_t *ctx );
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 #endif // _LEDDRIVER_H_
176  // End public_function group
179 
180 // ------------------------------------------------------------------------- END
leddriver_init
LEDDRIVER_RETVAL leddriver_init(leddriver_t *ctx, leddriver_cfg_t *cfg)
Initialization function.
LEDDRIVER_RETVAL
#define LEDDRIVER_RETVAL
Definition: leddriver.h:60
leddriver_t::pwm_freq
uint32_t pwm_freq
Definition: leddriver.h:88
leddriver_cfg_setup
void leddriver_cfg_setup(leddriver_cfg_t *cfg)
Config Object Initialization function.
leddriver_pwm_stop
err_t leddriver_pwm_stop(leddriver_t *ctx)
Stop PWM module.
leddriver_set_duty_cycle
err_t leddriver_set_duty_cycle(leddriver_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
leddriver_pwm_start
err_t leddriver_pwm_start(leddriver_t *ctx)
Start PWM module.
leddriver_cfg_t::pwm
pin_name_t pwm
Definition: leddriver.h:97
leddriver_t::pwm
pwm_t pwm
Definition: leddriver.h:86
leddriver_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: leddriver.h:99
leddriver_t
Click ctx object definition.
Definition: leddriver.h:84
leddriver_cfg_t
Click configuration structure definition.
Definition: leddriver.h:95
leddriver_get_pwm_max_duty
uint16_t leddriver_get_pwm_max_duty(leddriver_t *ctx)
Get Max PWM Duty Cycle function.