[components] drivers pin irq change apis

This commit is contained in:
Aubr.Cool 2017-03-14 10:26:49 +08:00
parent 320b116b5f
commit aa8e5cc412
3 changed files with 66 additions and 78 deletions

View File

@ -653,7 +653,8 @@ rt_err_t stm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
return RT_EOK; return RT_EOK;
} }
rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin) rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint32_t enabled)
{ {
const struct pin_index *index; const struct pin_index *index;
const struct pin_irq_map *irqmap; const struct pin_irq_map *irqmap;
@ -668,12 +669,13 @@ rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin)
{ {
return RT_ENOSYS; return RT_ENOSYS;
} }
if(enabled == PIN_IRQ_ENABLE)
{
irqindex = bit2bitno(index->pin); irqindex = bit2bitno(index->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)
{ {
@ -712,20 +714,9 @@ rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin)
EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); EXTI_Init(&EXTI_InitStructure);
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
return RT_EOK;
} }
rt_err_t stm32_pin_irq_disable(struct rt_device *device, rt_base_t pin) else if(enabled == PIN_IRQ_DISABLE)
{ {
const struct pin_index *index;
const struct pin_irq_map *irqmap;
EXTI_InitTypeDef EXTI_InitStructure;
index = get_pin(pin);
if (index == RT_NULL)
{
return RT_ENOSYS;
}
irqmap = get_pin_irq_map(index->pin); irqmap = get_pin_irq_map(index->pin);
if(irqmap == RT_NULL) if(irqmap == RT_NULL)
{ {
@ -736,6 +727,12 @@ rt_err_t stm32_pin_irq_disable(struct rt_device *device, rt_base_t pin)
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = DISABLE; EXTI_InitStructure.EXTI_LineCmd = DISABLE;
EXTI_Init(&EXTI_InitStructure); EXTI_Init(&EXTI_InitStructure);
}
else
{
return RT_ENOSYS;
}
return RT_EOK; return RT_EOK;
} }
const static struct rt_pin_ops _stm32_pin_ops = const static struct rt_pin_ops _stm32_pin_ops =
@ -746,7 +743,6 @@ const static struct rt_pin_ops _stm32_pin_ops =
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_irq_disable
}; };
int stm32_hw_pin_init(void) int stm32_hw_pin_init(void)

View File

@ -50,6 +50,9 @@ struct rt_device_pin
#define PIN_IRQ_MODE_FALLING 0x01 #define PIN_IRQ_MODE_FALLING 0x01
#define PIN_IRQ_MODE_RISING_FALLING 0x02 #define PIN_IRQ_MODE_RISING_FALLING 0x02
#define PIN_IRQ_DISABLE 0x00
#define PIN_IRQ_ENABLE 0x01
#define PIN_IRQ_PIN_NONE -1 #define PIN_IRQ_PIN_NONE -1
struct rt_device_pin_mode struct rt_device_pin_mode
@ -64,8 +67,8 @@ struct rt_device_pin_status
}; };
struct rt_pin_irq_hdr struct rt_pin_irq_hdr
{ {
rt_int32_t pin; rt_int16_t pin;
rt_uint32_t mode; rt_uint16_t mode;
void (*hdr)(void *args); void (*hdr)(void *args);
void *args; void *args;
}; };
@ -79,8 +82,7 @@ struct rt_pin_ops
rt_err_t (*pin_attach_irq)(struct rt_device *device, rt_int32_t pin, rt_err_t (*pin_attach_irq)(struct rt_device *device, rt_int32_t pin,
rt_uint32_t mode, void (*hdr)(void *args), void *args); rt_uint32_t mode, void (*hdr)(void *args), void *args);
rt_err_t (*pin_dettach_irq)(struct rt_device *device, rt_int32_t pin); rt_err_t (*pin_dettach_irq)(struct rt_device *device, rt_int32_t pin);
rt_err_t (*pin_irq_enable)(struct rt_device *device, rt_base_t pin); rt_err_t (*pin_irq_enable)(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled);
rt_err_t (*pin_irq_disable)(struct rt_device *device, rt_base_t pin);
}; };
int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data); int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data);
@ -91,8 +93,7 @@ int rt_pin_read(rt_base_t pin);
rt_err_t rt_pin_attach_irq(rt_int32_t pin, rt_uint32_t mode, rt_err_t rt_pin_attach_irq(rt_int32_t pin, rt_uint32_t mode,
void (*hdr)(void *args), void *args); void (*hdr)(void *args), void *args);
rt_err_t rt_pin_dettach_irq(rt_int32_t pin); rt_err_t rt_pin_dettach_irq(rt_int32_t pin);
rt_err_t pin_irq_enable(rt_base_t pin); rt_err_t pin_irq_enable(rt_base_t pin, rt_uint32_t enabled);
rt_err_t pin_irq_disable(rt_base_t pin);
int rt_device_pin_irq_register(const char *name, const struct rt_pin_ops *ops, int rt_device_pin_irq_register(const char *name, const struct rt_pin_ops *ops,
void *user_data); void *user_data);

View File

@ -117,21 +117,12 @@ rt_err_t rt_pin_dettach_irq(rt_int32_t pin)
} }
return RT_ENOSYS; return RT_ENOSYS;
} }
rt_err_t pin_irq_enable(rt_base_t pin) rt_err_t pin_irq_enable(rt_base_t pin, rt_uint32_t enabled)
{ {
RT_ASSERT(_hw_pin.ops != RT_NULL); RT_ASSERT(_hw_pin.ops != RT_NULL);
if(_hw_pin.ops->pin_irq_enable) if(_hw_pin.ops->pin_irq_enable)
{ {
return _hw_pin.ops->pin_irq_enable(&_hw_pin.parent, pin); return _hw_pin.ops->pin_irq_enable(&_hw_pin.parent, pin, enabled);
}
return RT_ENOSYS;
}
rt_err_t pin_irq_disable(rt_base_t pin)
{
RT_ASSERT(_hw_pin.ops != RT_NULL);
if(_hw_pin.ops->pin_irq_disable)
{
return _hw_pin.ops->pin_irq_disable(&_hw_pin.parent, pin);
} }
return RT_ENOSYS; return RT_ENOSYS;
} }