Edit online

接口设计

3 Mar 2025
Read time: 2 minute(s)

Driver 层接口设计

1. drv_cir_init

函数原型

rt_err_t drv_cir_init(rt_device_t pdev)

功能说明

CIR 模块初始化

参数定义

pdev: 指向 CIR 设备的指针

返回值

执行成功返回 RT_EOK

注意事项

-

2. drv_cir_open

函数原型

rt_err_t drv_cir_open(rt_device_t pdev, rt_uint16_t oflag)

功能说明

打开红外模块

参数定义

pdev: 指向 CIR 设备的指针
oflag: 打开设备时设置的标志

返回值

执行成功返回 RT_EOK,否则返回-RT_EINVAL

注意事项

oflag 可设置的值:
RT_DEVICE_FLAG_WRONLY
RT_DEVICE_FLAG_RDONLY
RT_DEVICE_FLAG_RDWR
RT_DEVICE_FLAG_INT_RX
设置 RT_DEVICE_FLAG_RDONLY 时,必须同时设置 RT_DEVICE_FLAG_INT_RX

3. drv_cir_close

函数原型

rt_err_t drv_cir_close(rt_device_t pdev)

功能说明

关闭红外模块

参数定义

pdev: 指向 CIR 设备的指针

返回值

执行成功返回 RT_EOK

注意事项

-

4. drv_cir_read

函数原型

rt_size_t drv_cir_read(rt_device_t pdev, rt_off_t pos, void *buffer, rt_size_t size)

功能说明

读取 CIR 接收到的红外信号

参数定义

pdev: 指向 CIR 设备的指针
buffer: 指向接收数据的指针
size: 读取的数据字节数

返回值

执行成功返回 0

注意事项

-

HAL 层接口设计

5. hal_cir_set_tx_carrier

函数原型

int hal_cir_set_tx_carrier(aic_cir_ctrl_t * aic_cir_ctrl, uint8_t protocol, uint32_t tx_duty);

功能说明

设置 CIR 的发送载波参数

参数定义

aic_cir_ctrl: 指向 aic_cir_ctrl_t 的指针
protocol: 使用的 CIR 协议
tx_duty: 协议的占空比

返回值

执行成功返回 0

注意事项

protocol 取值: NEC, 0; RC5, 1
tx_duty: 若占空比为 33%,则 tx_duty 设置为 33

6. hal_cir_send_data

函数原型

void hal_cir_send_data(aic_cir_ctrl_t * aic_cir_ctrl, uint8_t * tx_data, uint32_t size);

功能说明

CIR 发送数据

参数定义

aic_cir_ctrl: 指向 aic_cir_ctrl_t 的指针
tx_data: 指向要发送的数据指针
size: 发送的数据字节数

返回值

执行成功返回 0

注意事项

-

7. hal_cir_set_rx_sample_clock

函数原型

void hal_cir_set_rx_sample_clock(aic_cir_ctrl_t * aic_cir_ctrl, uint8_t protocol);

功能说明

设置 CIR 接收采样时钟

参数定义

aic_cir_ctrl: 指向 aic_cir_ctrl_t 的指针
protocol: 使用的 CIR 协议

返回值

执行成功返回 0

注意事项

-