1 /* 2 * Copyright (c) 2019 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Public API for Keyboard scan matrix devices. 10 * The scope of this API is simply to report which key event was triggered 11 * and users can later decode keys using their desired scan code tables in 12 * their application. In addition, typematic rate and delay can easily be 13 * implemented using a timer if desired. 14 */ 15 16 #ifndef ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_ 17 #define ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_ 18 19 #include <errno.h> 20 #include <zephyr/types.h> 21 #include <stddef.h> 22 #include <zephyr/device.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** 29 * @brief KSCAN APIs 30 * @defgroup kscan_interface Keyboard Scan Driver APIs 31 * @ingroup io_interfaces 32 * @{ 33 */ 34 35 /** 36 * @brief Keyboard scan callback called when user press/release 37 * a key on a matrix keyboard. 38 * 39 * @param dev Pointer to the device structure for the driver instance. 40 * @param row Describes row change. 41 * @param column Describes column change. 42 * @param pressed Describes the kind of key event. 43 */ 44 typedef void (*kscan_callback_t)(const struct device *dev, uint32_t row, 45 uint32_t column, 46 bool pressed); 47 48 /** 49 * @cond INTERNAL_HIDDEN 50 * 51 * Keyboard scan driver API definition and system call entry points. 52 * 53 * (Internal use only.) 54 */ 55 typedef int (*kscan_config_t)(const struct device *dev, 56 kscan_callback_t callback); 57 typedef int (*kscan_disable_callback_t)(const struct device *dev); 58 typedef int (*kscan_enable_callback_t)(const struct device *dev); 59 60 __subsystem struct kscan_driver_api { 61 kscan_config_t config; 62 kscan_disable_callback_t disable_callback; 63 kscan_enable_callback_t enable_callback; 64 }; 65 /** 66 * @endcond 67 */ 68 69 /** 70 * @brief Configure a Keyboard scan instance. 71 * 72 * @param dev Pointer to the device structure for the driver instance. 73 * @param callback called when keyboard devices reply to to a keyboard 74 * event such as key pressed/released. 75 * 76 * @retval 0 If successful. 77 * @retval Negative errno code if failure. 78 */ 79 __syscall int kscan_config(const struct device *dev, 80 kscan_callback_t callback); 81 z_impl_kscan_config(const struct device * dev,kscan_callback_t callback)82static inline int z_impl_kscan_config(const struct device *dev, 83 kscan_callback_t callback) 84 { 85 const struct kscan_driver_api *api = 86 (struct kscan_driver_api *)dev->api; 87 88 return api->config(dev, callback); 89 } 90 /** 91 * @brief Enables callback. 92 * @param dev Pointer to the device structure for the driver instance. 93 * 94 * @retval 0 If successful. 95 * @retval Negative errno code if failure. 96 */ 97 __syscall int kscan_enable_callback(const struct device *dev); 98 z_impl_kscan_enable_callback(const struct device * dev)99static inline int z_impl_kscan_enable_callback(const struct device *dev) 100 { 101 const struct kscan_driver_api *api = 102 (const struct kscan_driver_api *)dev->api; 103 104 if (api->enable_callback == NULL) { 105 return -ENOSYS; 106 } 107 108 return api->enable_callback(dev); 109 } 110 111 /** 112 * @brief Disables callback. 113 * @param dev Pointer to the device structure for the driver instance. 114 * 115 * @retval 0 If successful. 116 * @retval Negative errno code if failure. 117 */ 118 __syscall int kscan_disable_callback(const struct device *dev); 119 z_impl_kscan_disable_callback(const struct device * dev)120static inline int z_impl_kscan_disable_callback(const struct device *dev) 121 { 122 const struct kscan_driver_api *api = 123 (const struct kscan_driver_api *)dev->api; 124 125 if (api->disable_callback == NULL) { 126 return -ENOSYS; 127 } 128 129 return api->disable_callback(dev); 130 } 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 /** 137 * @} 138 */ 139 140 #include <syscalls/kscan.h> 141 142 #endif /* ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_ */ 143