aboutsummaryrefslogtreecommitdiff
path: root/ports/teensy/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/teensy/timer.c')
-rw-r--r--ports/teensy/timer.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/ports/teensy/timer.c b/ports/teensy/timer.c
index 88e960cfa..08dc13fab 100644
--- a/ports/teensy/timer.c
+++ b/ports/teensy/timer.c
@@ -49,8 +49,8 @@ typedef enum {
} pyb_channel_mode;
STATIC const struct {
- qstr name;
- uint32_t oc_mode;
+ qstr name;
+ uint32_t oc_mode;
} channel_mode_info[] = {
{ MP_QSTR_PWM, FTM_OCMODE_PWM1 },
{ MP_QSTR_PWM_INVERTED, FTM_OCMODE_PWM2 },
@@ -195,8 +195,8 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
mp_printf(print, "Timer(%u, prescaler=%u, period=%u, mode=%s)",
self->tim_id,
1 << (self->ftm.Instance->SC & 7),
- self->ftm.Instance->MOD & 0xffff,
- self->ftm.Init.CounterMode == FTM_COUNTERMODE_UP ? "UP" : "CENTER");
+ self->ftm.Instance->MOD & 0xffff,
+ self->ftm.Init.CounterMode == FTM_COUNTERMODE_UP ? "UP" : "CENTER");
}
}
@@ -319,10 +319,20 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
tim->tim_id = mp_obj_get_int(args[0]);
switch (tim->tim_id) {
- case 0: tim->ftm.Instance = FTM0; tim->irqn = IRQ_FTM0; break;
- case 1: tim->ftm.Instance = FTM1; tim->irqn = IRQ_FTM1; break;
- case 2: tim->ftm.Instance = FTM2; tim->irqn = IRQ_FTM2; break;
- default: mp_raise_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id);
+ case 0:
+ tim->ftm.Instance = FTM0;
+ tim->irqn = IRQ_FTM0;
+ break;
+ case 1:
+ tim->ftm.Instance = FTM1;
+ tim->irqn = IRQ_FTM1;
+ break;
+ case 2:
+ tim->ftm.Instance = FTM2;
+ tim->irqn = IRQ_FTM2;
+ break;
+ default:
+ mp_raise_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id);
}
if (n_args > 1 || n_kw > 0) {
@@ -551,9 +561,9 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *args, mp_map_t
case CHANNEL_MODE_OC_INACTIVE:
case CHANNEL_MODE_OC_TOGGLE: {
FTM_OC_InitTypeDef oc_config;
- oc_config.OCMode = channel_mode_info[chan->mode].oc_mode;
- oc_config.Pulse = vals[4].u_int;
- oc_config.OCPolarity = vals[5].u_int;
+ oc_config.OCMode = channel_mode_info[chan->mode].oc_mode;
+ oc_config.Pulse = vals[4].u_int;
+ oc_config.OCPolarity = vals[5].u_int;
if (oc_config.OCPolarity == 0xffffffff) {
oc_config.OCPolarity = FTM_OCPOLARITY_HIGH;
}
@@ -573,7 +583,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *args, mp_map_t
case CHANNEL_MODE_IC: {
FTM_IC_InitTypeDef ic_config;
- ic_config.ICPolarity = vals[5].u_int;
+ ic_config.ICPolarity = vals[5].u_int;
if (ic_config.ICPolarity == 0xffffffff) {
ic_config.ICPolarity = FTM_ICPOLARITY_RISING;
}
@@ -716,9 +726,9 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_prescaler), MP_ROM_PTR(&pyb_timer_prescaler_obj) },
{ MP_ROM_QSTR(MP_QSTR_period), MP_ROM_PTR(&pyb_timer_period_obj) },
{ MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_timer_callback_obj) },
-#if MICROPY_TIMER_REG
+ #if MICROPY_TIMER_REG
{ MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pyb_timer_reg_obj) },
-#endif
+ #endif
{ MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_INT(FTM_COUNTERMODE_UP) },
{ MP_ROM_QSTR(MP_QSTR_CENTER), MP_ROM_INT(FTM_COUNTERMODE_CENTER) },
{ MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_INT(CHANNEL_MODE_PWM_NORMAL) },
@@ -754,9 +764,9 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m
pyb_timer_channel_obj_t *self = self_in;
mp_printf(print, "TimerChannel(timer=%u, channel=%u, mode=%s)",
- self->timer->tim_id,
- self->channel,
- qstr_str(channel_mode_info[self->mode].name));
+ self->timer->tim_id,
+ self->channel,
+ qstr_str(channel_mode_info[self->mode].name));
}
/// \method capture([value])
@@ -773,7 +783,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m
/// Get or set the pulse width value associated with a channel.
/// capture, compare, and pulse_width are all aliases for the same function.
/// pulse_width is the logical name to use when the channel is in PWM mode.
-///
+///
/// In edge aligned mode, a pulse_width of `period + 1` corresponds to a duty cycle of 100%
/// In center aligned mode, a pulse width of `period` corresponds to a duty cycle of 100%
STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) {
@@ -860,8 +870,8 @@ reg_t timer_channel_reg[] = {
mp_obj_t pyb_timer_channel_reg(uint n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *self = args[0];
return reg_cmd(&self->timer->ftm.Instance->channel[self->channel],
- timer_channel_reg, MP_ARRAY_SIZE(timer_channel_reg),
- n_args - 1, args + 1);
+ timer_channel_reg, MP_ARRAY_SIZE(timer_channel_reg),
+ n_args - 1, args + 1);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_reg_obj, 1, 3, pyb_timer_channel_reg);
#endif
@@ -873,9 +883,9 @@ STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_pulse_width_percent), MP_ROM_PTR(&pyb_timer_channel_pulse_width_percent_obj) },
{ MP_ROM_QSTR(MP_QSTR_capture), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
{ MP_ROM_QSTR(MP_QSTR_compare), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
-#if MICROPY_TIMER_REG
+ #if MICROPY_TIMER_REG
{ MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pyb_timer_channel_reg_obj) },
-#endif
+ #endif
};
STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table);
@@ -906,10 +916,10 @@ STATIC bool ftm_handle_irq_callback(pyb_timer_obj_t *self, mp_uint_t channel, mp
self->callback = mp_const_none;
if (channel == 0xffffffff) {
printf("Uncaught exception in Timer(" UINT_FMT
- ") interrupt handler\n", self->tim_id);
+ ") interrupt handler\n", self->tim_id);
} else {
printf("Uncaught exception in Timer(" UINT_FMT ") channel "
- UINT_FMT " interrupt handler\n", self->tim_id, channel);
+ UINT_FMT " interrupt handler\n", self->tim_id, channel);
}
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
}
@@ -956,7 +966,7 @@ STATIC void ftm_irq_handler(uint tim_id) {
} else {
__HAL_FTM_DISABLE_CH_IT(&self->ftm, chan->channel);
printf("No callback for Timer %d channel %u (now disabled)\n",
- self->tim_id, chan->channel);
+ self->tim_id, chan->channel);
}
}
chan = chan->next;
@@ -971,7 +981,7 @@ STATIC void ftm_irq_handler(uint tim_id) {
__HAL_FTM_CLEAR_CH_FLAG(&self->ftm, channel);
__HAL_FTM_DISABLE_CH_IT(&self->ftm, channel);
printf("Unhandled interrupt Timer %d channel %u (now disabled)\n",
- tim_id, channel);
+ tim_id, channel);
}
}
}