mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
extmod/machine_i2s: Factor I2S.irq method.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -528,15 +528,8 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) {
|
||||
self->i2s_event_queue = NULL;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_i2s_irq(mp_obj_t self_in, mp_obj_t handler) {
|
||||
machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (handler != mp_const_none && !mp_obj_is_callable(handler)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid callback"));
|
||||
}
|
||||
|
||||
if (handler != mp_const_none) {
|
||||
self->io_mode = NON_BLOCKING;
|
||||
|
||||
STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) {
|
||||
if (self->io_mode == NON_BLOCKING) {
|
||||
// create a queue linking the MicroPython task to a FreeRTOS task
|
||||
// that manages the non blocking mode of operation
|
||||
self->non_blocking_mode_queue = xQueueCreate(1, sizeof(non_blocking_descriptor_t));
|
||||
@@ -563,14 +556,8 @@ STATIC mp_obj_t machine_i2s_irq(mp_obj_t self_in, mp_obj_t handler) {
|
||||
vQueueDelete(self->non_blocking_mode_queue);
|
||||
self->non_blocking_mode_queue = NULL;
|
||||
}
|
||||
|
||||
self->io_mode = BLOCKING;
|
||||
}
|
||||
|
||||
self->callback_for_non_blocking = handler;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_irq_obj, machine_i2s_irq);
|
||||
|
||||
MP_REGISTER_ROOT_POINTER(struct _machine_i2s_obj_t *machine_i2s_obj[I2S_NUM_AUTO]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user