summaryrefslogtreecommitdiff
path: root/app/include/drivers/ext_power.h
blob: 6c1923e80ca5e8efd560cd2346ac72dd31cf64e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (c) 2020 The ZMK Contributors
 *
 * SPDX-License-Identifier: MIT
 */

#pragma once

#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @cond INTERNAL_HIDDEN
 *
 * Behavior driver API definition and system call entry points.
 *
 * (Internal use only.)
 */

typedef int (*ext_power_enable_t)(struct device *dev);
typedef int (*ext_power_disable_t)(struct device *dev);
typedef int (*ext_power_get_t)(struct device *dev);

__subsystem struct ext_power_api {
    ext_power_enable_t enable;
    ext_power_disable_t disable;
    ext_power_get_t get;
};
/**
 * @endcond
 */

/**
 * @brief Enable the external power output
 * @param dev Pointer to the device structure for the driver instance.
 *
 * @retval 0 If successful.
 * @retval Negative errno code if failure.
 */
__syscall int ext_power_enable(struct device *dev);

static inline int z_impl_ext_power_enable(struct device *dev) {
    const struct ext_power_api *api = (const struct ext_power_api *)dev->driver_api;

    if (api->enable == NULL) {
        return -ENOTSUP;
    }

    return api->enable(dev);
}

/**
 * @brief Disable the external power output
 * @param dev Pointer to the device structure for the driver instance.
 *
 * @retval 0 If successful.
 * @retval Negative errno code if failure.
 */
__syscall int ext_power_disable(struct device *dev);

static inline int z_impl_ext_power_disable(struct device *dev) {
    const struct ext_power_api *api = (const struct ext_power_api *)dev->driver_api;

    if (api->disable == NULL) {
        return -ENOTSUP;
    }

    return api->disable(dev);
}

/**
 * @brief Get the current status of the external power output
 * @param dev Pointer to the device structure for the driver instance.
 *
 * @retval 0 If ext power is disabled.
 * @retval 1 if ext power is enabled.
 * @retval Negative errno code if failure.
 */
__syscall int ext_power_get(struct device *dev);

static inline int z_impl_ext_power_get(struct device *dev) {
    const struct ext_power_api *api = (const struct ext_power_api *)dev->driver_api;

    if (api->get == NULL) {
        return -ENOTSUP;
    }

    return api->get(dev);
}

#ifdef __cplusplus
}
#endif

/**
 * @}
 */

#include <syscalls/ext_power.h>