ZYNQ连载07-PIN设备
1. 简述
RT-Thread PIN设备
这里参看RT-Thread提供的PIN设备管理接口,简单封装了几个接口函数。
2. 实现
#include "include/drv_gpio.h"
#define LOG_TAG "drv_gpio"
static XGpioPs xgpiops;
void rt_pin_mode(rt_base_t pin, rt_uint8_t mode)
{
XGpioPs_Config *xgpiops_config;
xgpiops_config = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID);
if (XST_SUCCESS != XGpioPs_CfgInitialize(&xgpiops, xgpiops_config, xgpiops_config->BaseAddr))
log_e("XGpioPs_CfgInitialize fail");
switch (mode)
{
case PIN_MODE_OUTPUT:
XGpioPs_SetDirectionPin(&xgpiops, pin, 1);
XGpioPs_SetOutputEnablePin(&xgpiops, pin, 1);
break;
case PIN_MODE_INPUT:
XGpioPs_SetDirectionPin(&xgpiops, pin, 0);
break;
default:
log_e("XGpioPs_SetDirectionPin fail");
break;
}
}
void rt_pin_write(rt_base_t pin, rt_uint8_t value)
{
XGpioPs_WritePin(&xgpiops, pin, value);
}
rt_int8_t rt_pin_read(rt_base_t pin)
{
return (rt_int8_t)XGpioPs_ReadPin(&xgpiops, pin);
}