Commit a9a10169 authored by Wenxi Xu's avatar Wenxi Xu
Browse files

优化头文件注释

parent 9ea40ad5
Loading
Loading
Loading
Loading
+35 −34
Original line number Diff line number Diff line
@@ -3,57 +3,58 @@
 *
 * SPDX-License-Identifier: Apache-2.0
 */
#ifndef SBUS_H
#define SBUS_H
#ifndef ZEPHYR_DRIVERS_SBUS_H_
#define ZEPHYR_DRIVERS_SBUS_H_

#include "zephyr/toolchain.h"
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <zephyr/device.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

// SBUS API 函数指针定义
typedef void (*sbus_api_parseframe_t)(const struct device *dev);
typedef float (*sbus_api_getchannel_percentage_t)(const struct device *dev, uint8_t channelid);
typedef int (*sbus_api_getchannel_digital_t)(const struct device *dev, uint8_t channelid);

// SBUS 驱动 API 结构体
__subsystem struct sbus_driver_api {
    sbus_api_getchannel_percentage_t getchannel_percentage;
    sbus_api_getchannel_digital_t    getchannel_digital;
/**
 * @brief SBUS driver API
 */
struct sbus_driver_api {
	float (*getchannel_percentage)(const struct device *dev, uint8_t channelid);
	int (*getchannel_digital)(const struct device *dev, uint8_t channelid);
};

// 系统调用声明
/**
 * @brief Get the percentage value of a SBUS channel
 *
 * @param dev Pointer to the SBUS device
 * @param channelid Channel ID to read
 * @return float Percentage value (-1.0 to 1.0)
 */
__syscall float sbus_get_percent(const struct device *dev, uint8_t channelid);
__syscall int   sbus_get_digit(const struct device *dev, uint8_t channelid);

// 实现函数

static inline float z_impl_sbus_get_percent(const struct device *dev, uint8_t channelid) {
static inline float z_impl_sbus_get_percent(const struct device *dev, uint8_t channelid)
{
	const struct sbus_driver_api *api = (const struct sbus_driver_api *)dev->api;
    if (api->getchannel_percentage) {
        float temp = api->getchannel_percentage(dev, channelid);
        return temp;
    }
    return 0.0f;
	return api->getchannel_percentage(dev, channelid);
}

static inline int z_impl_sbus_get_digit(const struct device *dev, uint8_t channelid) {
/**
 * @brief Get the digital value of a SBUS channel
 *
 * @param dev Pointer to the SBUS device
 * @param channelid Channel ID to read
 * @return int Digital value
 */
__syscall int sbus_get_digit(const struct device *dev, uint8_t channelid);

static inline int z_impl_sbus_get_digit(const struct device *dev, uint8_t channelid)
{
	const struct sbus_driver_api *api = (const struct sbus_driver_api *)dev->api;
    if (api->getchannel_digital) {
	return api->getchannel_digital(dev, channelid);
}
    return -1;
}

#ifdef __cplusplus
}
#endif

#include <zephyr/syscalls/sbus.h>
#include <syscalls/sbus.h>

#endif // SBUS_H
 No newline at end of file
#endif /* ZEPHYR_DRIVERS_SBUS_H_ */
 No newline at end of file