mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-22 01:15:26 +08:00
[bsp][drv_gpio] fix the error code return when pin number is illegal
This commit is contained in:
parent
2549b82bd6
commit
6a9c42a19d
@ -160,7 +160,7 @@ static rt_ssize_t ifx_pin_read(struct rt_device *device, rt_base_t pin)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return -RT_ERROR;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cyhal_gpio_read(gpio_pin);
|
return cyhal_gpio_read(gpio_pin);
|
||||||
|
@ -157,6 +157,10 @@ static rt_ssize_t v85xx_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_V85XXPIN(pin);
|
gpio_pin = PIN_V85XXPIN(pin);
|
||||||
value = GPIOBToF_ReadInputDataBit(gpio_port, gpio_pin);
|
value = GPIOBToF_ReadInputDataBit(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ static rt_ssize_t acm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = HAL_GPIO_ReadPin(index->gpio, index->pin);
|
value = HAL_GPIO_ReadPin(index->gpio, index->pin);
|
||||||
|
@ -216,7 +216,7 @@ static rt_ssize_t _pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = HAL_GPIO_ReadPin(index->gpio, index->pin);
|
value = HAL_GPIO_ReadPin(index->gpio, index->pin);
|
||||||
|
@ -68,7 +68,7 @@ static rt_ssize_t air105_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return -1;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +169,10 @@ static rt_ssize_t air32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_AIRPIN(pin);
|
gpio_pin = PIN_AIRPIN(pin);
|
||||||
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ static rt_ssize_t pin_read(struct rt_device *device, rt_base_t pin)
|
|||||||
if ((pin > PIN_NUM(pin_index)) || (pin_index[pin].magic != PIN_MAGIC))
|
if ((pin > PIN_NUM(pin_index)) || (pin_index[pin].magic != PIN_MAGIC))
|
||||||
{
|
{
|
||||||
LOG_E("pin:%d value wrongful", pin);
|
LOG_E("pin:%d value wrongful", pin);
|
||||||
return 0;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gpio_get_value(pin_index[pin].pin_port, pin_index[pin].pin);
|
return gpio_get_value(pin_index[pin].pin_port, pin_index[pin].pin);
|
||||||
|
@ -185,6 +185,10 @@ static rt_ssize_t apm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_APMPIN(pin);
|
gpio_pin = PIN_APMPIN(pin);
|
||||||
value = GPIO_ReadInputBit(gpio_port, gpio_pin);
|
value = GPIO_ReadInputBit(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -198,6 +198,11 @@ static rt_ssize_t at32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_ATPIN(pin);
|
gpio_pin = PIN_ATPIN(pin);
|
||||||
value = gpio_input_data_bit_read(gpio_port, gpio_pin);
|
value = gpio_input_data_bit_read(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ rt_ssize_t es32f0_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
value = ald_gpio_read_pin(index->gpio, index->pin);
|
value = ald_gpio_read_pin(index->gpio, index->pin);
|
||||||
return value;
|
return value;
|
||||||
|
@ -255,7 +255,7 @@ rt_ssize_t es32f3_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
value = ald_gpio_read_pin(index->gpio, index->pin);
|
value = ald_gpio_read_pin(index->gpio, index->pin);
|
||||||
return value;
|
return value;
|
||||||
|
@ -254,7 +254,7 @@ rt_ssize_t es32f3_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
value = ald_gpio_read_pin(index->gpio, index->pin);
|
value = ald_gpio_read_pin(index->gpio, index->pin);
|
||||||
return value;
|
return value;
|
||||||
@ -337,7 +337,7 @@ rt_err_t es32f3_pin_attach_irq(struct rt_device *device, rt_base_t pin,
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
/* pin no. convert to dec no. */
|
/* pin no. convert to dec no. */
|
||||||
for (irqindex = 0; irqindex < 16; irqindex++)
|
for (irqindex = 0; irqindex < 16; irqindex++)
|
||||||
@ -349,7 +349,7 @@ rt_err_t es32f3_pin_attach_irq(struct rt_device *device, rt_base_t pin,
|
|||||||
}
|
}
|
||||||
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
if (pin_irq_hdr_tab[irqindex].pin == pin &&
|
if (pin_irq_hdr_tab[irqindex].pin == pin &&
|
||||||
@ -363,7 +363,7 @@ rt_err_t es32f3_pin_attach_irq(struct rt_device *device, rt_base_t pin,
|
|||||||
if (pin_irq_hdr_tab[irqindex].pin != -1)
|
if (pin_irq_hdr_tab[irqindex].pin != -1)
|
||||||
{
|
{
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
return RT_EBUSY;
|
return -RT_EBUSY;
|
||||||
}
|
}
|
||||||
pin_irq_hdr_tab[irqindex].pin = pin;
|
pin_irq_hdr_tab[irqindex].pin = pin;
|
||||||
pin_irq_hdr_tab[irqindex].hdr = hdr;
|
pin_irq_hdr_tab[irqindex].hdr = hdr;
|
||||||
@ -381,7 +381,7 @@ rt_err_t es32f3_pin_detach_irq(struct rt_device *device, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (irqindex = 0; irqindex < 16; irqindex++)
|
for (irqindex = 0; irqindex < 16; irqindex++)
|
||||||
@ -393,7 +393,7 @@ rt_err_t es32f3_pin_detach_irq(struct rt_device *device, rt_base_t pin)
|
|||||||
}
|
}
|
||||||
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
if (pin_irq_hdr_tab[irqindex].pin == -1)
|
if (pin_irq_hdr_tab[irqindex].pin == -1)
|
||||||
@ -425,7 +425,7 @@ rt_err_t es32f3_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
if (enabled == PIN_IRQ_ENABLE)
|
if (enabled == PIN_IRQ_ENABLE)
|
||||||
{
|
{
|
||||||
@ -439,13 +439,13 @@ rt_err_t es32f3_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
|||||||
}
|
}
|
||||||
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
if (pin_irq_hdr_tab[irqindex].pin == -1)
|
if (pin_irq_hdr_tab[irqindex].pin == -1)
|
||||||
{
|
{
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
irqmap = &pin_irq_map[irqindex];
|
irqmap = &pin_irq_map[irqindex];
|
||||||
ald_gpio_exti_init(index->gpio, index->pin, &exti_initstruct);
|
ald_gpio_exti_init(index->gpio, index->pin, &exti_initstruct);
|
||||||
@ -479,14 +479,14 @@ rt_err_t es32f3_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
|||||||
irqmap = get_pin_irq_map(index->pin);
|
irqmap = get_pin_irq_map(index->pin);
|
||||||
if (irqmap == RT_NULL)
|
if (irqmap == RT_NULL)
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*csi_vic_disable_sirq(irqmap->irqno);*/
|
/*csi_vic_disable_sirq(irqmap->irqno);*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,10 @@ static rt_ssize_t fm33_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_STPIN(pin);
|
gpio_pin = PIN_STPIN(pin);
|
||||||
value = FL_GPIO_GetInputPin(gpio_port, gpio_pin);
|
value = FL_GPIO_GetInputPin(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -404,7 +408,7 @@ static rt_err_t fm33_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
|||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
const static struct rt_pin_ops _fm33_pin_ops =
|
const static struct rt_pin_ops _fm33_pin_ops =
|
||||||
{
|
{
|
||||||
fm33_pin_mode,
|
fm33_pin_mode,
|
||||||
fm33_pin_write,
|
fm33_pin_write,
|
||||||
fm33_pin_read,
|
fm33_pin_read,
|
||||||
|
@ -147,6 +147,10 @@ static rt_ssize_t ft32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_FTPIN(pin);
|
gpio_pin = PIN_FTPIN(pin);
|
||||||
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -370,7 +370,7 @@ static rt_ssize_t gd32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = gpio_input_bit_get(index->gpio_periph, index->pin);
|
value = gpio_input_bit_get(index->gpio_periph, index->pin);
|
||||||
|
@ -256,7 +256,7 @@ static rt_ssize_t gd32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = gpio_input_bit_get(index->gpio_periph, index->pin);
|
value = gpio_input_bit_get(index->gpio_periph, index->pin);
|
||||||
|
@ -302,6 +302,10 @@ static rt_ssize_t hc32_pin_read(struct rt_device *device, rt_base_t pin)
|
|||||||
value = PIN_HIGH;
|
value = PIN_HIGH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,10 @@ static rt_ssize_t _pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
value = PIN_HIGH;
|
value = PIN_HIGH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ static rt_ssize_t _pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
|
|
||||||
if (pin >= PIN_MAX_NUM)
|
if (pin >= PIN_MAX_NUM)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_port = GPIO_PORT(pin);
|
gpio_port = GPIO_PORT(pin);
|
||||||
|
@ -120,6 +120,11 @@ static rt_int8_t hk32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_HKPIN(pin);
|
gpio_pin = PIN_HKPIN(pin);
|
||||||
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,13 +310,15 @@ static rt_err_t hpm_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_u
|
|||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const static struct rt_pin_ops hpm_pin_ops = {
|
const static struct rt_pin_ops hpm_pin_ops =
|
||||||
.pin_mode = hpm_pin_mode,
|
{
|
||||||
.pin_write = hpm_pin_write,
|
.pin_mode = hpm_pin_mode,
|
||||||
.pin_read = hpm_pin_read,
|
.pin_write = hpm_pin_write,
|
||||||
.pin_attach_irq = hpm_pin_attach_irq,
|
.pin_read = hpm_pin_read,
|
||||||
.pin_detach_irq = hpm_pin_detach_irq,
|
.pin_attach_irq = hpm_pin_attach_irq,
|
||||||
.pin_irq_enable = hpm_pin_irq_enable};
|
.pin_detach_irq = hpm_pin_detach_irq,
|
||||||
|
.pin_irq_enable = hpm_pin_irq_enable
|
||||||
|
};
|
||||||
|
|
||||||
int rt_hw_pin_init(void)
|
int rt_hw_pin_init(void)
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ static rt_ssize_t drv_pin_read(struct rt_device *device, rt_base_t pin)
|
|||||||
if(pin_channel == -1)
|
if(pin_channel == -1)
|
||||||
{
|
{
|
||||||
LOG_E("pin %d not set mode", pin);
|
LOG_E("pin %d not set mode", pin);
|
||||||
return -1;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
return gpiohs_get_pin(pin_channel) == GPIO_PV_HIGH ? PIN_HIGH : PIN_LOW;
|
return gpiohs_get_pin(pin_channel) == GPIO_PV_HIGH ? PIN_HIGH : PIN_LOW;
|
||||||
}
|
}
|
||||||
@ -248,7 +248,6 @@ const static struct rt_pin_ops drv_pin_ops =
|
|||||||
drv_pin_mode,
|
drv_pin_mode,
|
||||||
drv_pin_write,
|
drv_pin_write,
|
||||||
drv_pin_read,
|
drv_pin_read,
|
||||||
|
|
||||||
drv_pin_attach_irq,
|
drv_pin_attach_irq,
|
||||||
drv_pin_detach_irq,
|
drv_pin_detach_irq,
|
||||||
drv_pin_irq_enable
|
drv_pin_irq_enable
|
||||||
|
@ -119,7 +119,6 @@ const static struct rt_pin_ops _ls1c_pin_ops =
|
|||||||
ls1c_pin_mode,
|
ls1c_pin_mode,
|
||||||
ls1c_pin_write,
|
ls1c_pin_write,
|
||||||
ls1c_pin_read,
|
ls1c_pin_read,
|
||||||
|
|
||||||
ls1c_pin_attach_irq,
|
ls1c_pin_attach_irq,
|
||||||
ls1c_pin_detach_irq,
|
ls1c_pin_detach_irq,
|
||||||
ls1c_pin_irq_enable,
|
ls1c_pin_irq_enable,
|
||||||
|
@ -146,6 +146,10 @@ static rt_ssize_t mm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_STPIN(pin);
|
gpio_pin = PIN_STPIN(pin);
|
||||||
value = GPIO_ReadInDataBit(gpio_port, gpio_pin);
|
value = GPIO_ReadInDataBit(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ rt_ssize_t mm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
||||||
{
|
{
|
||||||
|
@ -180,7 +180,7 @@ rt_ssize_t mm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
||||||
{
|
{
|
||||||
|
@ -169,7 +169,7 @@ rt_ssize_t mm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
||||||
{
|
{
|
||||||
|
@ -274,6 +274,10 @@ static rt_ssize_t msp432_pin_read(struct rt_device *device, rt_base_t pin)
|
|||||||
{
|
{
|
||||||
value = (rt_ssize_t)GPIOPinRead(index->gpioBaseAddress, index->pin);
|
value = (rt_ssize_t)GPIOPinRead(index->gpioBaseAddress, index->pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ static rt_ssize_t n32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = GPIO_ReadInputDataBit(index->gpio, index->pin);
|
value = GPIO_ReadInputDataBit(index->gpio, index->pin);
|
||||||
|
@ -588,7 +588,7 @@ rt_ssize_t n32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
||||||
|
@ -124,7 +124,7 @@ static rt_ssize_t nrf5x_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = nrf_gpio_pin_read(pin);
|
value = nrf_gpio_pin_read(pin);
|
||||||
|
@ -184,7 +184,7 @@ static rt_ssize_t gd32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = gpio_input_bit_get(index->gpio, index->pin);
|
value = gpio_input_bit_get(index->gpio, index->pin);
|
||||||
|
@ -176,7 +176,9 @@ static void nu_gpio_write(struct rt_device *device, rt_base_t pin, rt_uint8_t va
|
|||||||
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
||||||
{
|
{
|
||||||
if (nu_port_check(pin))
|
if (nu_port_check(pin))
|
||||||
return PIN_LOW;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,9 @@ static void nu_gpio_write(struct rt_device *device, rt_base_t pin, rt_uint8_t va
|
|||||||
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
||||||
{
|
{
|
||||||
if (nu_port_check(pin))
|
if (nu_port_check(pin))
|
||||||
return PIN_LOW;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return GPIO_PIN_DATA_S(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
return GPIO_PIN_DATA_S(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,9 @@ static void nu_gpio_write(struct rt_device *device, rt_base_t pin, rt_uint8_t va
|
|||||||
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
||||||
{
|
{
|
||||||
if (nu_port_check(pin))
|
if (nu_port_check(pin))
|
||||||
return PIN_LOW;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,9 @@ static void nu_gpio_write(struct rt_device *device, rt_base_t pin, rt_uint8_t va
|
|||||||
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
||||||
{
|
{
|
||||||
if (nu_port_check(pin))
|
if (nu_port_check(pin))
|
||||||
return PIN_LOW;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,9 @@ static void nu_gpio_write(struct rt_device *device, rt_base_t pin, rt_uint8_t va
|
|||||||
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
||||||
{
|
{
|
||||||
if (nu_port_check(pin))
|
if (nu_port_check(pin))
|
||||||
return PIN_LOW;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,9 @@ static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
|||||||
GPIO_PORT PORT;
|
GPIO_PORT PORT;
|
||||||
|
|
||||||
if (nu_port_check(pin))
|
if (nu_port_check(pin))
|
||||||
return PIN_LOW;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
PORT = (GPIO_PORT)(GPIOA + (NU_GET_PORT(pin) * PORT_OFFSET));
|
PORT = (GPIO_PORT)(GPIOA + (NU_GET_PORT(pin) * PORT_OFFSET));
|
||||||
|
|
||||||
|
@ -173,7 +173,9 @@ static void nu_gpio_write(struct rt_device *device, rt_base_t pin, rt_uint8_t va
|
|||||||
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
static rt_ssize_t nu_gpio_read(struct rt_device *device, rt_base_t pin)
|
||||||
{
|
{
|
||||||
if (nu_port_check(pin))
|
if (nu_port_check(pin))
|
||||||
return PIN_LOW;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
return GPIO_PIN_DATA(NU_GET_PORT(pin), NU_GET_PINS(pin));
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,7 @@ static rt_ssize_t imxrt_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
if (PIN_INVALID_CHECK(port, pin_num))
|
if (PIN_INVALID_CHECK(port, pin_num))
|
||||||
{
|
{
|
||||||
LOG_D("invalid pin,rtt pin: %d,port: %d,pin: %d \n", pin,port + 1,pin_num);
|
LOG_D("invalid pin,rtt pin: %d,port: %d,pin: %d \n", pin,port + 1,pin_num);
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GPIO_PinReadPadStatus(mask_tab[port].gpio, pin_num);
|
return GPIO_PinReadPadStatus(mask_tab[port].gpio, pin_num);
|
||||||
|
@ -147,7 +147,9 @@ static rt_ssize_t lpc_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
rt_ssize_t value;
|
rt_ssize_t value;
|
||||||
|
|
||||||
if(pin > PIN_MAX_VAL)
|
if(pin > PIN_MAX_VAL)
|
||||||
return -RT_ERROR;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
portx = get_port(pin);
|
portx = get_port(pin);
|
||||||
piny = get_pin(pin);
|
piny = get_pin(pin);
|
||||||
|
@ -195,11 +195,7 @@ rt_ssize_t drv_pin_read(struct rt_device *device, rt_base_t pin)
|
|||||||
|
|
||||||
if (pin_instance == RT_NULL)
|
if (pin_instance == RT_NULL)
|
||||||
{
|
{
|
||||||
rt_kprintf("Pin %d-%c-%d not set mode\n",
|
return -RT_EINVAL;
|
||||||
ctrl_id,
|
|
||||||
port_id == 0 ? 'a' : 'b',
|
|
||||||
pin_id);
|
|
||||||
return -RT_ERROR;
|
|
||||||
}
|
}
|
||||||
return FGpioGetInputValue(pin_instance) == FGPIO_PIN_HIGH ? PIN_HIGH : PIN_LOW;
|
return FGpioGetInputValue(pin_instance) == FGPIO_PIN_HIGH ? PIN_HIGH : PIN_LOW;
|
||||||
}
|
}
|
||||||
|
@ -172,8 +172,7 @@ static rt_ssize_t ra_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
{
|
{
|
||||||
if ((pin > RA_MAX_PIN_VALUE) || (pin < RA_MIN_PIN_VALUE))
|
if ((pin > RA_MAX_PIN_VALUE) || (pin < RA_MIN_PIN_VALUE))
|
||||||
{
|
{
|
||||||
LOG_E("GPIO pin value is illegal");
|
return -RT_EINVAL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
return R_BSP_PinRead(pin);
|
return R_BSP_PinRead(pin);
|
||||||
}
|
}
|
||||||
|
@ -229,6 +229,10 @@ static rt_ssize_t stm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_STPIN(pin);
|
gpio_pin = PIN_STPIN(pin);
|
||||||
state = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
|
state = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return (state == GPIO_PIN_RESET) ? PIN_LOW : PIN_HIGH;
|
return (state == GPIO_PIN_RESET) ? PIN_LOW : PIN_HIGH;
|
||||||
}
|
}
|
||||||
@ -503,13 +507,13 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
|||||||
}
|
}
|
||||||
static const struct rt_pin_ops _stm32_pin_ops =
|
static const struct rt_pin_ops _stm32_pin_ops =
|
||||||
{
|
{
|
||||||
stm32_pin_mode,
|
stm32_pin_mode,
|
||||||
stm32_pin_write,
|
stm32_pin_write,
|
||||||
stm32_pin_read,
|
stm32_pin_read,
|
||||||
stm32_pin_attach_irq,
|
stm32_pin_attach_irq,
|
||||||
stm32_pin_dettach_irq,
|
stm32_pin_dettach_irq,
|
||||||
stm32_pin_irq_enable,
|
stm32_pin_irq_enable,
|
||||||
stm32_pin_get,
|
stm32_pin_get,
|
||||||
};
|
};
|
||||||
|
|
||||||
rt_inline void pin_irq_hdr(int irqno)
|
rt_inline void pin_irq_hdr(int irqno)
|
||||||
|
@ -332,7 +332,7 @@ static rt_ssize_t swm_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_obj = _pin2struct(pin);
|
gpio_obj = _pin2struct(pin);
|
||||||
if (gpio_obj == RT_NULL)
|
if (gpio_obj == RT_NULL)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
return (rt_ssize_t)GPIO_GetBit(gpio_obj->gpio, gpio_obj->pin);
|
return (rt_ssize_t)GPIO_GetBit(gpio_obj->gpio, gpio_obj->pin);
|
||||||
}
|
}
|
||||||
@ -496,14 +496,15 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const static struct rt_pin_ops swm_pin_ops =
|
const static struct rt_pin_ops swm_pin_ops =
|
||||||
{
|
{
|
||||||
.pin_mode = swm_pin_mode,
|
.pin_mode = swm_pin_mode,
|
||||||
.pin_write = swm_pin_write,
|
.pin_write = swm_pin_write,
|
||||||
.pin_read = swm_pin_read,
|
.pin_read = swm_pin_read,
|
||||||
.pin_attach_irq = swm_pin_attach_irq,
|
.pin_attach_irq = swm_pin_attach_irq,
|
||||||
.pin_detach_irq = swm_pin_detach_irq,
|
.pin_detach_irq = swm_pin_detach_irq,
|
||||||
.pin_irq_enable = swm_pin_irq_enable,
|
.pin_irq_enable = swm_pin_irq_enable,
|
||||||
.pin_get = swm_pin_get};
|
.pin_get = swm_pin_get
|
||||||
|
};
|
||||||
|
|
||||||
static void swm_pin_isr(GPIO_TypeDef *GPIOx)
|
static void swm_pin_isr(GPIO_TypeDef *GPIOx)
|
||||||
{
|
{
|
||||||
|
@ -354,7 +354,7 @@ static rt_ssize_t swm_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_obj = _pin2struct(pin);
|
gpio_obj = _pin2struct(pin);
|
||||||
if (gpio_obj == RT_NULL)
|
if (gpio_obj == RT_NULL)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
return (rt_ssize_t)GPIO_GetBit(gpio_obj->gpio, gpio_obj->pin);
|
return (rt_ssize_t)GPIO_GetBit(gpio_obj->gpio, gpio_obj->pin);
|
||||||
}
|
}
|
||||||
@ -521,14 +521,15 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct rt_pin_ops swm_pin_ops =
|
static const struct rt_pin_ops swm_pin_ops =
|
||||||
{
|
{
|
||||||
.pin_mode = swm_pin_mode,
|
.pin_mode = swm_pin_mode,
|
||||||
.pin_write = swm_pin_write,
|
.pin_write = swm_pin_write,
|
||||||
.pin_read = swm_pin_read,
|
.pin_read = swm_pin_read,
|
||||||
.pin_attach_irq = swm_pin_attach_irq,
|
.pin_attach_irq = swm_pin_attach_irq,
|
||||||
.pin_detach_irq = swm_pin_detach_irq,
|
.pin_detach_irq = swm_pin_detach_irq,
|
||||||
.pin_irq_enable = swm_pin_irq_enable,
|
.pin_irq_enable = swm_pin_irq_enable,
|
||||||
.pin_get = swm_pin_get};
|
.pin_get = swm_pin_get
|
||||||
|
};
|
||||||
|
|
||||||
static void swm_pin_isr(GPIO_TypeDef *GPIOx)
|
static void swm_pin_isr(GPIO_TypeDef *GPIOx)
|
||||||
{
|
{
|
||||||
|
@ -132,7 +132,7 @@ rt_ssize_t _pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
if (LL_GPIO_ReadPin(index->gpio, index->pin) == GPIO_PIN_RESET)
|
if (LL_GPIO_ReadPin(index->gpio, index->pin) == GPIO_PIN_RESET)
|
||||||
{
|
{
|
||||||
|
@ -212,7 +212,7 @@ rt_ssize_t tkm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return PIN_LOW;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
if (GPIO_ReadInputDataBit(index->gpio, index->pin) == Bit_RESET)
|
||||||
{
|
{
|
||||||
|
@ -118,7 +118,7 @@ static rt_ssize_t tm4c123_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
index = get_pin(pin);
|
index = get_pin(pin);
|
||||||
if (index == RT_NULL)
|
if (index == RT_NULL)
|
||||||
{
|
{
|
||||||
return value;
|
return -RT_EINVAL;
|
||||||
}
|
}
|
||||||
value = GPIOPinRead(index ->gpioBaseAddress, index ->pin);
|
value = GPIOPinRead(index ->gpioBaseAddress, index ->pin);
|
||||||
|
|
||||||
|
@ -155,6 +155,10 @@ static rt_ssize_t ch32_pin_read(rt_device_t dev, rt_base_t pin)
|
|||||||
gpio_pin = PIN_STPIN(pin);
|
gpio_pin = PIN_STPIN(pin);
|
||||||
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
value = GPIO_ReadInputDataBit(gpio_port, gpio_pin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -50,21 +50,23 @@ void xgpiops_pin_write(rt_device_t dev, rt_base_t pin, rt_uint8_t value)
|
|||||||
rt_ssize_t xgpiops_pin_read(rt_device_t dev, rt_base_t pin)
|
rt_ssize_t xgpiops_pin_read(rt_device_t dev, rt_base_t pin)
|
||||||
{
|
{
|
||||||
if (pin >= Gpio.MaxPinNum)
|
if (pin >= Gpio.MaxPinNum)
|
||||||
return 0;
|
{
|
||||||
|
return -RT_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
int DataRead = XGpioPs_ReadPin(&Gpio, pin);
|
int DataRead = XGpioPs_ReadPin(&Gpio, pin);
|
||||||
return DataRead?PIN_HIGH:PIN_LOW;
|
return DataRead?PIN_HIGH:PIN_LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
const static struct rt_pin_ops _xgpiops_pin_ops =
|
const static struct rt_pin_ops _xgpiops_pin_ops =
|
||||||
{
|
{
|
||||||
xgpiops_pin_mode,
|
xgpiops_pin_mode,
|
||||||
xgpiops_pin_write,
|
xgpiops_pin_write,
|
||||||
xgpiops_pin_read,
|
xgpiops_pin_read,
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
int rt_hw_pin_init(void)
|
int rt_hw_pin_init(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user