4G_module/include/cmiot/cm_gpio.h

328 lines
8.4 KiB
C
Raw Permalink Normal View History

2024-09-02 17:54:29 +08:00
/**
* @file cm_gpio.h
* @brief GPIO接口
* @copyright Copyright © 2021 China Mobile IOT. All rights reserved.
* @author By ZHANGXW
* @date 2021/03/09
*
* @defgroup gpio gpio
* @ingroup PI
* @{
*/
#ifndef __CM_GPIO_H__
#define __CM_GPIO_H__
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/** 引脚ID,详情参照资源综述 */
typedef enum{
CM_GPIO_NUM_0,
CM_GPIO_NUM_1,
CM_GPIO_NUM_2,
CM_GPIO_NUM_3,
CM_GPIO_NUM_4,
CM_GPIO_NUM_5,
CM_GPIO_NUM_6,
CM_GPIO_NUM_7,
CM_GPIO_NUM_8,
CM_GPIO_NUM_9,
CM_GPIO_NUM_10,
CM_GPIO_NUM_11,
CM_GPIO_NUM_12,
CM_GPIO_NUM_13,
CM_GPIO_NUM_14,
CM_GPIO_NUM_15,
CM_GPIO_NUM_16,
CM_GPIO_NUM_17,
CM_GPIO_NUM_18,
CM_GPIO_NUM_19,
CM_GPIO_NUM_20,
CM_GPIO_NUM_21,
CM_GPIO_NUM_22,
CM_GPIO_NUM_23,
CM_GPIO_NUM_24,
CM_GPIO_NUM_25,
CM_GPIO_NUM_26,
CM_GPIO_NUM_27,
CM_GPIO_NUM_28,
CM_GPIO_NUM_29,
CM_GPIO_NUM_30,
CM_GPIO_NUM_31,
CM_GPIO_NUM_32,
CM_GPIO_NUM_33,
CM_GPIO_NUM_34,
CM_GPIO_NUM_35,
CM_GPIO_NUM_36,
CM_GPIO_NUM_MAX
}cm_gpio_num_e;
/* *GPIO工作模式 */
typedef enum
{
CM_GPIO_MODE_NUM/*!<不可用 工作模式数量*/
} cm_gpio_mode_e;
/** I/O方向 */
typedef enum{
CM_GPIO_DIRECTION_INPUT = 0,
CM_GPIO_DIRECTION_OUTPUT,
}cm_gpio_direction_e;
/** 上/下拉 */
typedef enum{
CM_GPIO_PULL_NONE,
CM_GPIO_PULL_DOWN,
CM_GPIO_PULL_UP,
}cm_gpio_pull_e;
/** 边沿+电平触发 */
typedef enum{
CM_GPIO_IT_EDGE_RISING,
CM_GPIO_IT_EDGE_FALLING,
CM_GPIO_IT_EDGE_BOTH,
CM_GPIO_IT_LEVEL_HIGH,/*!<不支持*/
CM_GPIO_IT_LEVEL_LOW,/*!<不支持*/
}cm_gpio_interrupt_e;
/** 高低电平 */
typedef enum{
CM_GPIO_LEVEL_LOW,
CM_GPIO_LEVEL_HIGH,
}cm_gpio_level_e;
/** 命令码 */
typedef enum{
CM_GPIO_CMD_SET_PULL, /*!< 上下拉设置命令码*/
CM_GPIO_CMD_GET_PULL, /*!< 上下拉获取命令码*/
CM_GPIO_CMD_SET_LEVEL, /*!< 驱动能力设置命令码*/
CM_GPIO_CMD_GET_LEVEL, /*!< 驱动能力获取命令码*/
CM_GPIO_CMD_SET_DIRECTION, /*!< 输入输出设置命令码*/
CM_GPIO_CMD_GET_DIRECTION, /*!< 输入输出获取命令码*/
} cm_gpio_cmd_e;
/** 配置 */
typedef struct{
cm_gpio_mode_e mode;/*!< 不支持*/
cm_gpio_direction_e direction;
cm_gpio_pull_e pull;
} cm_gpio_cfg_t;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
***********************GPIO使用注意事项*************************************
* 1GPIO引脚和SD卡控制引脚所用PIN脚存在复用关系使PIN脚进行
* GPIO功能开发cm_sd.h中SD卡使用注意事项
* 2GPIO引脚和SD卡控制引脚复用关系见
***************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/**
* @brief GPIO
*
* @param [in] gpio_num GPIO号
* @param [in] cfg
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details
*/
int32_t cm_gpio_init(cm_gpio_num_e gpio_num, cm_gpio_cfg_t *cfg);
/**
* @brief
*
* @param [in] gpio_num GPIO号
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_deinit(cm_gpio_num_e gpio_num);
/**
* @brief
*
* @param [in] gpio_num GPIO号
* @param [in] level
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_set_level(cm_gpio_num_e gpio_num, cm_gpio_level_e level);
/**
* @brief
*
* @param [in] gpio_num GPIO号
* @param [out] level
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_get_level(cm_gpio_num_e gpio_num, cm_gpio_level_e *level);
/**
* @brief /
*
* @param [in] gpio_num GPIO号
* @param [in] type
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_set_pull(cm_gpio_num_e gpio_num, cm_gpio_pull_e type);
/**
* @brief /
*
* @param [in] gpio_num GPIO号
* @param [out] type
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_get_pull(cm_gpio_num_e gpio_num, cm_gpio_pull_e *type);
/**
* @brief I/O方向模式配置
*
* @param [in] gpio_num GPIO号
* @param [in] dir /
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_set_direction(cm_gpio_num_e gpio_num, cm_gpio_direction_e dir);
/**
* @brief I/O方向模式配置
*
* @param [in] gpio_num GPIO号
* @param [out] dir /
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_get_direction(cm_gpio_num_e gpio_num, cm_gpio_direction_e *dir);
/**
* @brief
*
* @param [in] gpio_num GPIO号
* @param [in] interrupt_cb
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details log日志
*/
int32_t cm_gpio_interrupt_register(cm_gpio_num_e gpio_num, void *interrupt_cb);
/**
* @brief 使
*
* @param [in] gpio_num GPIO号
* @param [in] intr_mode
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_interrupt_enable(cm_gpio_num_e gpio_num, cm_gpio_interrupt_e intr_mode);
/**
* @brief
*
* @param [in] gpio_num GPIO号
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details More details
*/
int32_t cm_gpio_interrupt_disable(cm_gpio_num_e gpio_num);
/**
* @brief GPIO控制
*
* @param [in] gpio_num GPIO号
* @param [in] cmd
* @param [in/out] arg
*
* @return
* = 0 - \n
* < 0 - ,
*
* @details cmd值arg参数类型须对应配置\n
* cmd = \ref GPIO_CMD_SET_PULL, arg传入\ref cm_gpio_pull_e * \n
* cmd = \ref GPIO_CMD_GET_PULL, arg传入\ref cm_gpio_pull_e * \n
* cmd = \ref GPIO_CMD_SET_LEVEL, arg传入\ref cm_gpio_level_e * \n
* cmd = \ref GPIO_CMD_GET_LEVEL, arg传入\ref cm_gpio_level_e * \n
* cmd = \ref GPIO_CMD_SET_DIRECTION, arg传入\ref cm_gpio_direction_e * \n
* cmd = \ref GPIO_CMD_GET_DIRECTION, arg传入\ref cm_gpio_direction_e * \n
*/
int32_t cm_gpio_ioctl(cm_gpio_num_e gpio_num, int32_t cmd, void *arg);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __CM_GPIO_H__ */
/** @}*/