2019-09-30 20:31:03 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Public API for Keyboard scan matrix devices.
|
|
|
|
* The scope of this API is simply to report which key event was triggered
|
|
|
|
* and users can later decode keys using their desired scan code tables in
|
2019-10-29 00:27:57 +01:00
|
|
|
* their application. In addition, typematic rate and delay can easily be
|
2019-09-30 20:31:03 +02:00
|
|
|
* implemented using a timer if desired.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_
|
|
|
|
#define ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_
|
|
|
|
|
2022-10-11 20:05:39 +02:00
|
|
|
#include <errno.h>
|
2019-09-30 20:31:03 +02:00
|
|
|
#include <zephyr/types.h>
|
|
|
|
#include <stddef.h>
|
2022-04-21 06:07:09 +02:00
|
|
|
#include <zephyr/device.h>
|
2019-09-30 20:31:03 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief KSCAN APIs
|
|
|
|
* @defgroup kscan_interface Keyboard Scan Driver APIs
|
2023-08-26 00:24:48 +02:00
|
|
|
* @since 2.1
|
|
|
|
* @version 1.0.0
|
2019-09-30 20:31:03 +02:00
|
|
|
* @ingroup io_interfaces
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Keyboard scan callback called when user press/release
|
|
|
|
* a key on a matrix keyboard.
|
|
|
|
*
|
2020-12-17 00:22:38 +01:00
|
|
|
* @param dev Pointer to the device structure for the driver instance.
|
|
|
|
* @param row Describes row change.
|
|
|
|
* @param column Describes column change.
|
2019-09-30 20:31:03 +02:00
|
|
|
* @param pressed Describes the kind of key event.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
typedef void (*kscan_callback_t)(const struct device *dev, uint32_t row,
|
|
|
|
uint32_t column,
|
2019-09-30 20:31:03 +02:00
|
|
|
bool pressed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @cond INTERNAL_HIDDEN
|
|
|
|
*
|
|
|
|
* Keyboard scan driver API definition and system call entry points.
|
|
|
|
*
|
|
|
|
* (Internal use only.)
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
typedef int (*kscan_config_t)(const struct device *dev,
|
|
|
|
kscan_callback_t callback);
|
|
|
|
typedef int (*kscan_disable_callback_t)(const struct device *dev);
|
|
|
|
typedef int (*kscan_enable_callback_t)(const struct device *dev);
|
2019-09-30 20:31:03 +02:00
|
|
|
|
2020-03-04 22:32:01 +01:00
|
|
|
__subsystem struct kscan_driver_api {
|
2019-09-30 20:31:03 +02:00
|
|
|
kscan_config_t config;
|
|
|
|
kscan_disable_callback_t disable_callback;
|
|
|
|
kscan_enable_callback_t enable_callback;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configure a Keyboard scan instance.
|
|
|
|
*
|
|
|
|
* @param dev Pointer to the device structure for the driver instance.
|
2024-06-21 10:37:21 +02:00
|
|
|
* @param callback called when keyboard devices reply to a keyboard
|
2019-10-29 00:27:57 +01:00
|
|
|
* event such as key pressed/released.
|
2019-09-30 20:31:03 +02:00
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval Negative errno code if failure.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
__syscall int kscan_config(const struct device *dev,
|
2019-09-30 20:31:03 +02:00
|
|
|
kscan_callback_t callback);
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static inline int z_impl_kscan_config(const struct device *dev,
|
2019-09-30 20:31:03 +02:00
|
|
|
kscan_callback_t callback)
|
|
|
|
{
|
|
|
|
const struct kscan_driver_api *api =
|
2020-05-28 21:23:02 +02:00
|
|
|
(struct kscan_driver_api *)dev->api;
|
2019-09-30 20:31:03 +02:00
|
|
|
|
|
|
|
return api->config(dev, callback);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Enables callback.
|
|
|
|
* @param dev Pointer to the device structure for the driver instance.
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval Negative errno code if failure.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
__syscall int kscan_enable_callback(const struct device *dev);
|
2019-09-30 20:31:03 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static inline int z_impl_kscan_enable_callback(const struct device *dev)
|
2019-09-30 20:31:03 +02:00
|
|
|
{
|
|
|
|
const struct kscan_driver_api *api =
|
2020-05-28 21:23:02 +02:00
|
|
|
(const struct kscan_driver_api *)dev->api;
|
2019-09-30 20:31:03 +02:00
|
|
|
|
|
|
|
if (api->enable_callback == NULL) {
|
2021-03-24 18:47:17 +01:00
|
|
|
return -ENOSYS;
|
2019-09-30 20:31:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return api->enable_callback(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disables callback.
|
|
|
|
* @param dev Pointer to the device structure for the driver instance.
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval Negative errno code if failure.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
__syscall int kscan_disable_callback(const struct device *dev);
|
2019-09-30 20:31:03 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static inline int z_impl_kscan_disable_callback(const struct device *dev)
|
2019-09-30 20:31:03 +02:00
|
|
|
{
|
|
|
|
const struct kscan_driver_api *api =
|
2020-05-28 21:23:02 +02:00
|
|
|
(const struct kscan_driver_api *)dev->api;
|
2019-09-30 20:31:03 +02:00
|
|
|
|
|
|
|
if (api->disable_callback == NULL) {
|
2021-03-24 18:47:17 +01:00
|
|
|
return -ENOSYS;
|
2019-09-30 20:31:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return api->disable_callback(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2024-01-24 10:35:04 +01:00
|
|
|
#include <zephyr/syscalls/kscan.h>
|
2019-09-30 20:31:03 +02:00
|
|
|
|
|
|
|
#endif /* ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_ */
|