|
@@ -6,26 +6,30 @@
|
|
|
#include "wm_include.h"
|
|
#include "wm_include.h"
|
|
|
#include "luat_irq.h"
|
|
#include "luat_irq.h"
|
|
|
|
|
|
|
|
-// typedef struct wm_gpio_conf
|
|
|
|
|
-// {
|
|
|
|
|
-// luat_gpio_irq_cb cb;
|
|
|
|
|
-// void* args;
|
|
|
|
|
-// }wm_gpio_conf_t;
|
|
|
|
|
-
|
|
|
|
|
|
|
+typedef struct gpio_cb_args
|
|
|
|
|
+{
|
|
|
|
|
+ luat_gpio_irq_cb irq_cb;
|
|
|
|
|
+ void*irq_args;
|
|
|
|
|
+}gpio_cb_args_t;
|
|
|
|
|
|
|
|
-// static wm_gpio_conf_t confs[WM_IO_PB_31 + 1];
|
|
|
|
|
|
|
+static gpio_cb_args_t gpio_isr_cb[WM_IO_PB_31] = {0};
|
|
|
|
|
|
|
|
static void luat_gpio_irq_callback(void *ptr)
|
|
static void luat_gpio_irq_callback(void *ptr)
|
|
|
{
|
|
{
|
|
|
int pin = (int)ptr;
|
|
int pin = (int)ptr;
|
|
|
if (pin < 0 || pin > WM_IO_PB_31)
|
|
if (pin < 0 || pin > WM_IO_PB_31)
|
|
|
return;
|
|
return;
|
|
|
- int ret = tls_get_gpio_irq_status(pin);
|
|
|
|
|
- if(ret)
|
|
|
|
|
- {
|
|
|
|
|
- tls_clr_gpio_irq_status(pin);
|
|
|
|
|
- luat_gpio_irq_default(pin, (void*)tls_gpio_read(pin));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (gpio_isr_cb[pin].irq_cb){
|
|
|
|
|
+ gpio_isr_cb[pin].irq_cb(pin,gpio_isr_cb[pin].irq_args);
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ int ret = tls_get_gpio_irq_status(pin);
|
|
|
|
|
+ if(ret)
|
|
|
|
|
+ {
|
|
|
|
|
+ tls_clr_gpio_irq_status(pin);
|
|
|
|
|
+ luat_gpio_irq_default(pin, (void*)tls_gpio_read(pin));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int luat_gpio_setup(luat_gpio_t *gpio){
|
|
int luat_gpio_setup(luat_gpio_t *gpio){
|
|
@@ -88,10 +92,10 @@ int luat_gpio_setup(luat_gpio_t *gpio){
|
|
|
}
|
|
}
|
|
|
tls_clr_gpio_irq_status(gpio->pin);
|
|
tls_clr_gpio_irq_status(gpio->pin);
|
|
|
if (gpio->irq_cb) {
|
|
if (gpio->irq_cb) {
|
|
|
- tls_gpio_isr_register(gpio->pin, gpio->irq_cb, (void *)gpio->pin);
|
|
|
|
|
- }else{
|
|
|
|
|
- tls_gpio_isr_register(gpio->pin, luat_gpio_irq_callback, (void *)gpio->pin);
|
|
|
|
|
|
|
+ gpio_isr_cb[gpio->pin].irq_cb = gpio->irq_cb;
|
|
|
|
|
+ gpio_isr_cb[gpio->pin].irq_args = gpio->irq_args;
|
|
|
}
|
|
}
|
|
|
|
|
+ tls_gpio_isr_register(gpio->pin, luat_gpio_irq_callback, (void *)gpio->pin);
|
|
|
tls_gpio_irq_enable(gpio->pin, irq);
|
|
tls_gpio_irq_enable(gpio->pin, irq);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -128,14 +132,10 @@ void luat_gpio_close(int pin)
|
|
|
if (pin < 0 || pin > WM_IO_PB_31) return;
|
|
if (pin < 0 || pin > WM_IO_PB_31) return;
|
|
|
tls_gpio_cfg(pin, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
|
|
tls_gpio_cfg(pin, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
|
|
|
tls_gpio_irq_disable(pin);
|
|
tls_gpio_irq_disable(pin);
|
|
|
- // confs[pin].cb = NULL;
|
|
|
|
|
|
|
+ if (gpio_isr_cb[pin].irq_cb)
|
|
|
|
|
+ {
|
|
|
|
|
+ gpio_isr_cb[pin].irq_cb = 0;
|
|
|
|
|
+ gpio_isr_cb[pin].irq_args = 0;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// int luat_gpio_set_irq_cb(int pin, luat_gpio_irq_cb cb, void* args) {
|
|
|
|
|
-// if (pin < 0 || pin > WM_IO_PB_31) return -1;
|
|
|
|
|
-// if (cb) {
|
|
|
|
|
-// confs[pin].cb = cb;
|
|
|
|
|
-// confs[pin].args = args;
|
|
|
|
|
-// }
|
|
|
|
|
-// return 0;
|
|
|
|
|
-// }
|
|
|