stmhal: Small bug fixes and simplifications.

pull/512/head
Damien George 2014-04-20 01:25:58 +01:00
rodzic f87b35e779
commit fd6925b4b9
5 zmienionych plików z 12 dodań i 14 usunięć

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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);

Wyświetl plik

@ -90,7 +90,7 @@ Q(send)
Q(ExtInt)
Q(pin)
Q(mode)
Q(trigger)
Q(pull)
Q(callback)
Q(line)
Q(enable)

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;