summaryrefslogtreecommitdiff
path: root/app/include/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'app/include/drivers')
-rw-r--r--app/include/drivers/behavior.h44
-rw-r--r--app/include/drivers/ext_power.h104
2 files changed, 128 insertions, 20 deletions
diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h
index 45b8bea..cf259b1 100644
--- a/app/include/drivers/behavior.h
+++ b/app/include/drivers/behavior.h
@@ -10,6 +10,7 @@
#include <stddef.h>
#include <device.h>
#include <zmk/keys.h>
+#include <zmk/behavior.h>
/**
* @cond INTERNAL_HIDDEN
@@ -19,10 +20,10 @@
* (Internal use only.)
*/
-typedef int (*behavior_keymap_binding_callback_t)(struct device *dev, u32_t position, u32_t param1,
- u32_t param2);
-typedef int (*behavior_sensor_keymap_binding_callback_t)(struct device *dev, struct device *sensor,
- u32_t param1, u32_t param2);
+typedef int (*behavior_keymap_binding_callback_t)(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event);
+typedef int (*behavior_sensor_keymap_binding_callback_t)(struct zmk_behavior_binding *binding,
+ struct device *sensor);
__subsystem struct behavior_driver_api {
behavior_keymap_binding_callback_t binding_pressed;
@@ -42,18 +43,19 @@ __subsystem struct behavior_driver_api {
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
-__syscall int behavior_keymap_binding_pressed(struct device *dev, u32_t position, u32_t param1,
- u32_t param2);
+__syscall int behavior_keymap_binding_pressed(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event);
-static inline int z_impl_behavior_keymap_binding_pressed(struct device *dev, u32_t position,
- u32_t param1, u32_t param2) {
+static inline int z_impl_behavior_keymap_binding_pressed(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event) {
+ struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->driver_api;
if (api->binding_pressed == NULL) {
return -ENOTSUP;
}
- return api->binding_pressed(dev, position, param1, param2);
+ return api->binding_pressed(binding, event);
}
/**
@@ -64,18 +66,19 @@ static inline int z_impl_behavior_keymap_binding_pressed(struct device *dev, u32
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
-__syscall int behavior_keymap_binding_released(struct device *dev, u32_t position, u32_t param1,
- u32_t param2);
+__syscall int behavior_keymap_binding_released(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event);
-static inline int z_impl_behavior_keymap_binding_released(struct device *dev, u32_t position,
- u32_t param1, u32_t param2) {
+static inline int z_impl_behavior_keymap_binding_released(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event) {
+ struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->driver_api;
if (api->binding_released == NULL) {
return -ENOTSUP;
}
- return api->binding_released(dev, position, param1, param2);
+ return api->binding_released(binding, event);
}
/**
@@ -88,19 +91,20 @@ static inline int z_impl_behavior_keymap_binding_released(struct device *dev, u3
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
-__syscall int behavior_sensor_keymap_binding_triggered(struct device *dev, struct device *sensor,
- u32_t param1, u32_t param2);
+__syscall int behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding,
+ struct device *sensor);
-static inline int z_impl_behavior_sensor_keymap_binding_triggered(struct device *dev,
- struct device *sensor,
- u32_t param1, u32_t param2) {
+static inline int
+z_impl_behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding,
+ struct device *sensor) {
+ struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->driver_api;
if (api->sensor_binding_triggered == NULL) {
return -ENOTSUP;
}
- return api->sensor_binding_triggered(dev, sensor, param1, param2);
+ return api->sensor_binding_triggered(binding, sensor);
}
/**
diff --git a/app/include/drivers/ext_power.h b/app/include/drivers/ext_power.h
new file mode 100644
index 0000000..6c1923e
--- /dev/null
+++ b/app/include/drivers/ext_power.h
@@ -0,0 +1,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>