@@ -59,7 +59,7 @@ void machine_pin_deinit(void) {
59
59
}
60
60
61
61
STATIC void gpio_callback_handler (struct device * port , struct gpio_callback * cb , gpio_port_pins_t pins ) {
62
- machine_pin_irq_obj_t * irq = ( void * )(( uintptr_t ) cb - offsetof( machine_pin_irq_obj_t , callback ) );
62
+ machine_pin_irq_obj_t * irq = CONTAINER_OF ( cb , machine_pin_irq_obj_t , callback );
63
63
64
64
#if MICROPY_STACK_CHECK
65
65
// This callback executes in an ISR context so the stack-limit check must be changed to
@@ -219,7 +219,7 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
219
219
irq -> base .handler = mp_const_none ;
220
220
irq -> base .ishard = false;
221
221
irq -> next = MP_STATE_PORT (machine_pin_irq_list );
222
- gpio_init_callback (& irq -> callback , gpio_callback_handler , 0 );
222
+ gpio_init_callback (& irq -> callback , gpio_callback_handler , BIT ( self -> pin ) );
223
223
int ret = gpio_add_callback (self -> port , & irq -> callback );
224
224
if (ret != 0 ) {
225
225
mp_raise_OSError (- ret );
@@ -231,20 +231,19 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
231
231
232
232
if (n_args > 1 || kw_args -> used != 0 ) {
233
233
// configure irq
234
- self -> irq -> callback .pin_mask &= ~BIT (self -> pin );
234
+ int ret = gpio_pin_interrupt_configure (self -> port , self -> pin , GPIO_INT_DISABLE );
235
+ if (ret != 0 ) {
236
+ mp_raise_OSError (- ret );
237
+ }
235
238
236
239
self -> irq -> base .handler = args [ARG_handler ].u_obj ;
237
240
self -> irq -> base .ishard = args [ARG_hard ].u_bool ;
238
241
239
- int ret ;
240
- if (args [ARG_handler ].u_obj == mp_const_none ) {
241
- ret = gpio_pin_interrupt_configure (self -> port , self -> pin , GPIO_INT_DISABLE );
242
- } else {
242
+ if (args [ARG_handler ].u_obj != mp_const_none ) {
243
243
ret = gpio_pin_interrupt_configure (self -> port , self -> pin , args [ARG_trigger ].u_int );
244
- self -> irq -> callback .pin_mask |= BIT (self -> pin );
245
- }
246
- if (ret != 0 ) {
247
- mp_raise_OSError (- ret );
244
+ if (ret != 0 ) {
245
+ mp_raise_OSError (- ret );
246
+ }
248
247
}
249
248
}
250
249
0 commit comments