Zephyr API
4.4.99
A Scalable Open Source RTOS
Toggle main menu visibility
Loading...
Searching...
No Matches
pwm_utils.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2025 Basalte bv
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_DRIVERS_PWM_PWM_UTILS_H_
8
#define ZEPHYR_INCLUDE_DRIVERS_PWM_PWM_UTILS_H_
9
10
#include <
stdbool.h
>
11
#include <
stdint.h
>
12
#include <
errno.h
>
13
14
#include <
zephyr/devicetree.h
>
15
#include <
zephyr/drivers/pwm.h
>
16
#include <
zephyr/sys/__assert.h
>
17
#include <
zephyr/sys/slist.h
>
18
19
#ifdef __cplusplus
20
extern
"C"
{
21
#endif
22
33
static
inline
int
pwm_manage_event_callback
(
sys_slist_t
*callbacks,
34
struct
pwm_event_callback
*callback,
bool
set)
35
{
36
__ASSERT_NO_MSG(callback != NULL);
37
__ASSERT_NO_MSG(callback->
handler
!= NULL);
38
39
if
(!
sys_slist_is_empty
(callbacks)) {
40
if
(!
sys_slist_find_and_remove
(callbacks, &callback->node)) {
41
if
(!set) {
42
return
-
EINVAL
;
43
}
44
}
45
}
else
if
(!set) {
46
return
-
EINVAL
;
47
}
48
49
if
(set) {
50
sys_slist_prepend
(callbacks, &callback->node);
51
}
52
53
return
0;
54
}
55
64
static
inline
void
pwm_fire_event_callbacks
(
sys_slist_t
*list,
const
struct
device
*dev,
65
uint32_t
channel,
pwm_events_t
events)
66
{
67
struct
pwm_event_callback
*cb, *tmp;
68
69
SYS_SLIST_FOR_EACH_CONTAINER_SAFE
(list, cb, tmp, node) {
70
if
(cb->
channel
==
channel
) {
71
__ASSERT_NO_MSG(cb->
handler
!= NULL);
72
73
cb->
handler
(dev, cb,
channel
, events);
74
}
75
}
76
}
77
78
#ifdef __cplusplus
79
}
80
#endif
81
82
#endif
/* ZEPHYR_INCLUDE_DRIVERS_PWM_PWM_UTILS_H_ */
__assert.h
devicetree.h
Devicetree main header.
pwm.h
Main header file for PWM (Pulse Width Modulation) driver API.
errno.h
System error numbers.
pwm_events_t
uint16_t pwm_events_t
Provides a type to hold PWM events.
Definition
pwm.h:124
sys_slist_find_and_remove
static bool sys_slist_find_and_remove(sys_slist_t *list, sys_snode_t *node)
Find and remove a node from a list.
Definition
slist.h:451
sys_slist_t
struct _slist sys_slist_t
Single-linked list structure.
Definition
slist.h:52
sys_slist_prepend
static void sys_slist_prepend(sys_slist_t *list, sys_snode_t *node)
Prepend a node to the given list.
Definition
slist.h:308
SYS_SLIST_FOR_EACH_CONTAINER_SAFE
#define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n)
Provide the primitive to safely iterate on a list under a container Note: __cn can be detached,...
Definition
slist.h:186
sys_slist_is_empty
static bool sys_slist_is_empty(const sys_slist_t *list)
Test if the given list is empty.
Definition
slist.h:271
EINVAL
#define EINVAL
Invalid argument.
Definition
errno.h:61
pwm_fire_event_callbacks
static void pwm_fire_event_callbacks(sys_slist_t *list, const struct device *dev, uint32_t channel, pwm_events_t events)
Generic function to go through and fire callback from a callback lists.
Definition
pwm_utils.h:64
pwm_manage_event_callback
static int pwm_manage_event_callback(sys_slist_t *callbacks, struct pwm_event_callback *callback, bool set)
Generic function to insert or remove a callback from a callback list.
Definition
pwm_utils.h:33
slist.h
Header file for the single-linked list API.
stdbool.h
stdint.h
uint32_t
__UINT32_TYPE__ uint32_t
Definition
stdint.h:90
device
Runtime device structure (in ROM) per driver instance.
Definition
device.h:513
pwm_event_callback
PWM event callback structure.
Definition
pwm.h:471
pwm_event_callback::channel
uint32_t channel
Channel the callback is interested in.
Definition
pwm.h:480
pwm_event_callback::handler
pwm_event_callback_handler_t handler
Actual callback function being called when relevant.
Definition
pwm.h:477
zephyr
drivers
pwm
pwm_utils.h
Generated on
for Zephyr API by
1.17.0