mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 00:50:24 +08:00
extmod/machine_i2s: Factor I2S.irq method.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
cdd9ad8d62
commit
1477986815
@ -61,6 +61,7 @@ STATIC void copy_appbuf_to_ringbuf_non_blocking(machine_i2s_obj_t *self);
|
||||
STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id);
|
||||
STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self);
|
||||
STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self);
|
||||
|
||||
// The port provides implementations of the above in this file.
|
||||
#include MICROPY_PY_MACHINE_I2S_INCLUDEFILE
|
||||
@ -309,6 +310,27 @@ STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_i2s_deinit_obj, machine_i2s_deinit);
|
||||
|
||||
// I2S.irq(handler)
|
||||
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;
|
||||
} else {
|
||||
self->io_mode = BLOCKING;
|
||||
}
|
||||
|
||||
self->callback_for_non_blocking = handler;
|
||||
|
||||
mp_machine_i2s_irq_update(self);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_irq_obj, machine_i2s_irq);
|
||||
|
||||
// Shift() is typically used as a volume control.
|
||||
// shift=1 increases volume by 6dB, shift=-1 decreases volume by 6dB
|
||||
STATIC mp_obj_t machine_i2s_shift(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -813,22 +813,9 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
self->io_mode = BLOCKING;
|
||||
}
|
||||
|
||||
self->callback_for_non_blocking = handler;
|
||||
return mp_const_none;
|
||||
STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) {
|
||||
(void)self;
|
||||
}
|
||||
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[MICROPY_HW_I2S_NUM]);
|
||||
|
||||
|
@ -686,21 +686,8 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
self->io_mode = BLOCKING;
|
||||
}
|
||||
|
||||
self->callback_for_non_blocking = handler;
|
||||
return mp_const_none;
|
||||
STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) {
|
||||
(void)self;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_irq_obj, machine_i2s_irq);
|
||||
|
||||
MP_REGISTER_ROOT_POINTER(void *machine_i2s_obj[2]);
|
||||
|
@ -662,22 +662,9 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
self->io_mode = BLOCKING;
|
||||
}
|
||||
|
||||
self->callback_for_non_blocking = handler;
|
||||
return mp_const_none;
|
||||
STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) {
|
||||
(void)self;
|
||||
}
|
||||
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[MICROPY_HW_MAX_I2S]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user