Line data Source code
1 0 : /* 2 : * Copyright 2023 Google LLC 3 : * 4 : * SPDX-License-Identifier: Apache-2.0 5 : */ 6 : 7 : #ifndef ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_H_ 8 : #define ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_H_ 9 : 10 : #include <stdint.h> 11 : #include <zephyr/device.h> 12 : 13 : /** 14 : * @brief Analog axis API 15 : * @defgroup input_analog_axis Analog axis API 16 : * @ingroup io_interfaces 17 : * @{ 18 : */ 19 : 20 : /** 21 : * @brief Analog axis calibration data structure. 22 : * 23 : * Holds the calibration data for a single analog axis. Initial values are set 24 : * from the devicetree and can be changed by the applicatoin in runtime using 25 : * @ref analog_axis_calibration_set and @ref analog_axis_calibration_get. 26 : */ 27 1 : struct analog_axis_calibration { 28 : /** Input value that corresponds to the minimum output value. */ 29 1 : int16_t in_min; 30 : /** Input value that corresponds to the maximum output value. */ 31 1 : int16_t in_max; 32 : /** Input value center deadzone. */ 33 1 : uint16_t in_deadzone; 34 : }; 35 : 36 : /** 37 : * @brief Analog axis raw data callback. 38 : * 39 : * @param dev Analog axis device. 40 : * @param channel Channel number. 41 : * @param raw_val Raw value for the channel. 42 : */ 43 1 : typedef void (*analog_axis_raw_data_t)(const struct device *dev, 44 : int channel, int16_t raw_val); 45 : 46 : /** 47 : * @brief Set a raw data callback. 48 : * 49 : * Set a callback to receive raw data for the specified analog axis device. 50 : * This is meant to be use in the application to acquire the data to use for 51 : * calibration. Set cb to NULL to disable the callback. 52 : * 53 : * @param dev Analog axis device. 54 : * @param cb An analog_axis_raw_data_t callback to use, NULL disable. 55 : */ 56 1 : void analog_axis_set_raw_data_cb(const struct device *dev, analog_axis_raw_data_t cb); 57 : 58 : /** 59 : * @brief Get the number of defined axes. 60 : * 61 : * @retval n The number of defined axes for dev. 62 : */ 63 1 : int analog_axis_num_axes(const struct device *dev); 64 : 65 : /** 66 : * @brief Get the axis calibration data. 67 : * 68 : * @param dev Analog axis device. 69 : * @param channel Channel number. 70 : * @param cal Pointer to an analog_axis_calibration structure that is going to 71 : * get set with the current calibration data. 72 : * 73 : * @retval 0 If successful. 74 : * @retval -EINVAL If the specified channel is not valid. 75 : */ 76 1 : int analog_axis_calibration_get(const struct device *dev, 77 : int channel, 78 : struct analog_axis_calibration *cal); 79 : 80 : /** 81 : * @brief Set the axis calibration data. 82 : * 83 : * @param dev Analog axis device. 84 : * @param channel Channel number. 85 : * @param cal Pointer to an analog_axis_calibration structure with the new 86 : * calibration data 87 : * 88 : * @retval 0 If successful. 89 : * @retval -EINVAL If the specified channel is not valid. 90 : */ 91 1 : int analog_axis_calibration_set(const struct device *dev, 92 : int channel, 93 : struct analog_axis_calibration *cal); 94 : 95 : /** @} */ 96 : 97 : #endif /* ZEPHYR_INCLUDE_INPUT_ANALOG_AXIS_H_ */