Hardware Abstraction Layer for FreeRTOS
pwm.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: MIT */
2
/*
3
* Author: Andreas Werner <kernel@andy89.org>
4
* Date: 2016
5
*/
6
#ifndef PWM_H_
7
#define PWM_H_
8
9
#include <FreeRTOS.h>
10
#include <stdint.h>
11
#include <stdbool.h>
12
#include <
system.h
>
13
#include <
hal.h
>
29
struct
pwm;
30
#ifdef CONFIG_PWM_MULTI
31
34
struct
pwm_ops {
35
struct
pwm *(*pwm_init)(uint32_t index);
36
int32_t (*
pwm_deinit
)(
struct
pwm *pwm);
37
38
int32_t (*
pwm_setPeriod
)(
struct
pwm *pwm, uint64_t us);
39
int32_t (*
pwm_setDutyCycle
)(
struct
pwm *pwm, uint64_t us);
40
};
41
#endif
42
45
struct
pwm_generic
{
50
bool
init
;
51
#ifdef CONFIG_INSTANCE_NAME
52
55
const
char
*name;
56
#endif
57
#ifdef CONFIG_PWM_MULTI
58
61
const
struct
pwm_ops *ops;
62
#endif
63
};
64
#ifndef CONFIG_PWM_MULTI
65
70
struct
pwm *
pwm_init
(uint32_t index);
76
int32_t
pwm_deinit
(
struct
pwm *pwm);
92
int32_t
pwm_setPeriod
(
struct
pwm *pwm, uint64_t us);
108
int32_t
pwm_setDutyCycle
(
struct
pwm *pwm, uint64_t us);
109
#else
110
inline
struct
pwm *
pwm_init
(uint32_t index) {
111
HAL_DEFINE_GLOBAL_ARRAY
(pwm);
112
struct
pwm_generic
*p = (
struct
pwm_generic
*)
HAL_GET_DEV
(pwm, index);
113
if
(p == NULL) {
114
return
NULL;
115
}
116
return
p->ops->pwm_init(index);
117
}
118
inline
int32_t
pwm_deinit
(
struct
pwm *pwm) {
119
struct
pwm_generic
*p = (
struct
pwm_generic
*) pwm;
120
return
p->ops->pwm_deinit(pwm);
121
}
122
123
inline
int32_t
pwm_setPeriod
(
struct
pwm *pwm, uint64_t us) {
124
struct
pwm_generic
*p = (
struct
pwm_generic
*) pwm;
125
return
p->ops->pwm_setPeriod(pwm, us);
126
}
127
inline
int32_t
pwm_setDutyCycle
(
struct
pwm *pwm, uint64_t us) {
128
struct
pwm_generic
*p = (
struct
pwm_generic
*) pwm;
129
return
p->ops->pwm_setDutyCycle(pwm, us);
130
}
131
#endif
132
133
#endif
pwm_generic
Definition:
pwm.h:45
hal.h
HAL_DEFINE_GLOBAL_ARRAY
#define HAL_DEFINE_GLOBAL_ARRAY(gns)
Definition:
hal.h:149
pwm_generic::init
bool init
Definition:
pwm.h:50
HAL_GET_DEV
#define HAL_GET_DEV(gns, index)
Definition:
hal.h:182
pwm_setDutyCycle
int32_t pwm_setDutyCycle(struct pwm *pwm, uint64_t us)
pwm_deinit
int32_t pwm_deinit(struct pwm *pwm)
pwm_setPeriod
int32_t pwm_setPeriod(struct pwm *pwm, uint64_t us)
system.h
pwm_init
struct pwm * pwm_init(uint32_t index)
driver
include
pwm.h
Generated on Tue Aug 17 2021 15:19:23 for Hardware Abstraction Layer for FreeRTOS by
1.8.20