From fd6925b4b90761a535bd7b14be019b7870491b2f Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 20 Apr 2014 01:25:58 +0100 Subject: [PATCH] stmhal: Small bug fixes and simplifications. --- stmhal/extint.c | 16 +++++++--------- stmhal/extint.h | 2 +- stmhal/qstrdefsport.h | 2 +- stmhal/spi.c | 2 +- stmhal/usrsw.c | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/stmhal/extint.c b/stmhal/extint.c index 07afb1eef4..ede4f39515 100644 --- a/stmhal/extint.c +++ b/stmhal/extint.c @@ -110,7 +110,7 @@ STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = { // // NOTE: param is for C callers. Python can use closure to get an object bound // with the function. -uint extint_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_obj_t callback_obj, bool override_callback_obj, void *param) { +uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t callback_obj, bool override_callback_obj, void *param) { const pin_obj_t *pin = NULL; uint v_line; @@ -129,20 +129,18 @@ uint extint_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_ pin = pin_find(pin_obj); v_line = pin->pin; } - int mode = mp_obj_get_int(mode_obj); if (mode != GPIO_MODE_IT_RISING && mode != GPIO_MODE_IT_FALLING && mode != GPIO_MODE_IT_RISING_FALLING && mode != GPIO_MODE_EVT_RISING && mode != GPIO_MODE_EVT_FALLING && mode != GPIO_MODE_EVT_RISING_FALLING) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid ExtInt Mode: %d", mode)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid ExtInt Mode: %d", mode)); } - int pull = mp_obj_get_int(pull_obj); if (pull != GPIO_NOPULL && pull != GPIO_PULLUP && pull != GPIO_PULLDOWN) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid ExtInt Pull: %d", pull)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid ExtInt Pull: %d", pull)); } extint_vector_t *v = &extint_vector[v_line]; @@ -239,12 +237,12 @@ STATIC mp_obj_t extint_regs(void) { return mp_const_none; } -// line_obj = pyb.ExtInt(pin, mode, trigger, callback) +// line_obj = pyb.ExtInt(pin, mode, pull, callback) STATIC const mp_arg_parse_t pyb_extint_make_new_accepted_args[] = { { MP_QSTR_pin, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_mode, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_trigger, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_mode, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_INT, {.u_int = 0} }, + { MP_QSTR_pull, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_INT, {.u_int = 0} }, { MP_QSTR_callback, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, }; #define PYB_EXTINT_MAKE_NEW_NUM_ARGS (sizeof(pyb_extint_make_new_accepted_args) / sizeof(pyb_extint_make_new_accepted_args[0])) @@ -260,7 +258,7 @@ STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const extint_obj_t *self = m_new_obj(extint_obj_t); self->base.type = type_in; - self->line = extint_register(vals[0].u_obj, vals[1].u_obj, vals[2].u_obj, vals[3].u_obj, false, NULL); + self->line = extint_register(vals[0].u_obj, vals[1].u_int, vals[2].u_int, vals[3].u_obj, false, NULL); return self; } diff --git a/stmhal/extint.h b/stmhal/extint.h index c64931211f..f2231b5d4f 100644 --- a/stmhal/extint.h +++ b/stmhal/extint.h @@ -22,7 +22,7 @@ void extint_init(void); -uint extint_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t trigger_obj, mp_obj_t callback_obj, bool override_callback_obj, void *param); +uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t callback_obj, bool override_callback_obj, void *param); void extint_enable(uint line); void extint_disable(uint line); diff --git a/stmhal/qstrdefsport.h b/stmhal/qstrdefsport.h index dc06c3e259..f59f6131bc 100644 --- a/stmhal/qstrdefsport.h +++ b/stmhal/qstrdefsport.h @@ -90,7 +90,7 @@ Q(send) Q(ExtInt) Q(pin) Q(mode) -Q(trigger) +Q(pull) Q(callback) Q(line) Q(enable) diff --git a/stmhal/spi.c b/stmhal/spi.c index 44d7b4aa5a..9e48bc899e 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -189,7 +189,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, uint n_args, cons else if (br_prescale <= 32) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; } else if (br_prescale <= 64) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; } else if (br_prescale <= 128) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; } - else { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; } + else { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; } init->CLKPolarity = vals[2].u_int; init->CLKPhase = vals[3].u_int; diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c index 0d5d7e9b0c..72f9ec28cc 100644 --- a/stmhal/usrsw.c +++ b/stmhal/usrsw.c @@ -69,8 +69,8 @@ static mp_obj_t pyb_switch(uint n_args, mp_obj_t *args) { // may have been disabled by an exception in the interrupt, or the // user disabling the line explicitly. extint_register((mp_obj_t)&MICROPY_HW_USRSW_PIN, - MP_OBJ_NEW_SMALL_INT(MICROPY_HW_USRSW_EXTI_MODE), - MP_OBJ_NEW_SMALL_INT(MICROPY_HW_USRSW_PULL), + MICROPY_HW_USRSW_EXTI_MODE, + MICROPY_HW_USRSW_PULL, switch_user_callback_obj == mp_const_none ? mp_const_none : (mp_obj_t)&switch_callback_obj, true, NULL); return mp_const_none;