Skip to content

Commit fd6925b

Browse files
committed
stmhal: Small bug fixes and simplifications.
1 parent f87b35e commit fd6925b

5 files changed

Lines changed: 12 additions & 14 deletions

File tree

stmhal/extint.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = {
110110
//
111111
// NOTE: param is for C callers. Python can use closure to get an object bound
112112
// with the function.
113-
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) {
113+
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) {
114114
const pin_obj_t *pin = NULL;
115115
uint v_line;
116116

@@ -129,20 +129,18 @@ uint extint_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_
129129
pin = pin_find(pin_obj);
130130
v_line = pin->pin;
131131
}
132-
int mode = mp_obj_get_int(mode_obj);
133132
if (mode != GPIO_MODE_IT_RISING &&
134133
mode != GPIO_MODE_IT_FALLING &&
135134
mode != GPIO_MODE_IT_RISING_FALLING &&
136135
mode != GPIO_MODE_EVT_RISING &&
137136
mode != GPIO_MODE_EVT_FALLING &&
138137
mode != GPIO_MODE_EVT_RISING_FALLING) {
139-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid ExtInt Mode: %d", mode));
138+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid ExtInt Mode: %d", mode));
140139
}
141-
int pull = mp_obj_get_int(pull_obj);
142140
if (pull != GPIO_NOPULL &&
143141
pull != GPIO_PULLUP &&
144142
pull != GPIO_PULLDOWN) {
145-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid ExtInt Pull: %d", pull));
143+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid ExtInt Pull: %d", pull));
146144
}
147145

148146
extint_vector_t *v = &extint_vector[v_line];
@@ -239,12 +237,12 @@ STATIC mp_obj_t extint_regs(void) {
239237
return mp_const_none;
240238
}
241239

242-
// line_obj = pyb.ExtInt(pin, mode, trigger, callback)
240+
// line_obj = pyb.ExtInt(pin, mode, pull, callback)
243241

244242
STATIC const mp_arg_parse_t pyb_extint_make_new_accepted_args[] = {
245243
{ MP_QSTR_pin, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
246-
{ MP_QSTR_mode, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
247-
{ MP_QSTR_trigger, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
244+
{ MP_QSTR_mode, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_INT, {.u_int = 0} },
245+
{ MP_QSTR_pull, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_INT, {.u_int = 0} },
248246
{ MP_QSTR_callback, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
249247
};
250248
#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
260258

261259
extint_obj_t *self = m_new_obj(extint_obj_t);
262260
self->base.type = type_in;
263-
self->line = extint_register(vals[0].u_obj, vals[1].u_obj, vals[2].u_obj, vals[3].u_obj, false, NULL);
261+
self->line = extint_register(vals[0].u_obj, vals[1].u_int, vals[2].u_int, vals[3].u_obj, false, NULL);
264262

265263
return self;
266264
}

stmhal/extint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
void extint_init(void);
2424

25-
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);
25+
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);
2626

2727
void extint_enable(uint line);
2828
void extint_disable(uint line);

stmhal/qstrdefsport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Q(send)
9090
Q(ExtInt)
9191
Q(pin)
9292
Q(mode)
93-
Q(trigger)
93+
Q(pull)
9494
Q(callback)
9595
Q(line)
9696
Q(enable)

stmhal/spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, uint n_args, cons
189189
else if (br_prescale <= 32) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; }
190190
else if (br_prescale <= 64) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; }
191191
else if (br_prescale <= 128) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; }
192-
else { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; }
192+
else { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; }
193193

194194
init->CLKPolarity = vals[2].u_int;
195195
init->CLKPhase = vals[3].u_int;

stmhal/usrsw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ static mp_obj_t pyb_switch(uint n_args, mp_obj_t *args) {
6969
// may have been disabled by an exception in the interrupt, or the
7070
// user disabling the line explicitly.
7171
extint_register((mp_obj_t)&MICROPY_HW_USRSW_PIN,
72-
MP_OBJ_NEW_SMALL_INT(MICROPY_HW_USRSW_EXTI_MODE),
73-
MP_OBJ_NEW_SMALL_INT(MICROPY_HW_USRSW_PULL),
72+
MICROPY_HW_USRSW_EXTI_MODE,
73+
MICROPY_HW_USRSW_PULL,
7474
switch_user_callback_obj == mp_const_none ? mp_const_none : (mp_obj_t)&switch_callback_obj,
7575
true, NULL);
7676
return mp_const_none;

0 commit comments

Comments
 (0)