diff --git a/docs/psoc6/feature_list.rst b/docs/psoc6/feature_list.rst index a333971ec50d2..d43d048c9d41b 100644 --- a/docs/psoc6/feature_list.rst +++ b/docs/psoc6/feature_list.rst @@ -38,6 +38,10 @@ Enabled modules * I2C * RTC * SoftI2C + * SPI + * SoftSPI + * PWM + * Timer * micropython * ucryptolib * uctypes @@ -117,6 +121,8 @@ Table :ref:`configuration details ` below lists specifi +-----------------+----------------------------------------------------------------------------------------------------------------------+ | machine.SoftSPI | Option ``MICROPY_PY_MACHINE_SOFTSPI`` enabled. | +-----------------+----------------------------------------------------------------------------------------------------------------------+ +| machine.Timer | mode = Timer.PERIODIC is not supported | ++-----------------+----------------------------------------------------------------------------------------------------------------------+ | machine.SPI | Option ``MICROPY_PY_MACHINE_SPI``, ``MICROPY_PY_MACHINE_SPI_MSB`` , ``MICROPY_PY_MACHINE_SPI_MSB`` enabled. | +-----------------+----------------------------------------------------------------------------------------------------------------------+ | psoc6 | Option to enable the external instead of the internal flash: ``MICROPY_ENABLE_EXT_QSPI_FLASH``. | diff --git a/docs/psoc6/quickref.rst b/docs/psoc6/quickref.rst index 51e0cfbc31205..7df9aabceb14c 100644 --- a/docs/psoc6/quickref.rst +++ b/docs/psoc6/quickref.rst @@ -426,4 +426,19 @@ Methods ^^^^^^^ All the methods(functions) given in :ref:`machine.SPI ` class have been implemented in this port +Timers +------ + +Hardware timer is supported. + +Use the :mod:`machine.Timer` class:: + + from machine import Timer + import time + tim = Timer(0) #Default assignment: period=9999, frequency=10000 + tim.init(period=2000, mode=Timer.ONE_SHOT, callback=lambda t:print(2)) + time.sleep_ms(100) + +Here id=0 should be passed mandatorily. +.. note:: Here mode=Timer.PERIODIC is not currently supported diff --git a/ports/psoc6/modules/machine/machine_timer.c b/ports/psoc6/modules/machine/machine_timer.c index d5d87a31021e0..d1a9b5d4dac00 100644 --- a/ports/psoc6/modules/machine/machine_timer.c +++ b/ports/psoc6/modules/machine/machine_timer.c @@ -31,13 +31,13 @@ static void isr_timer(void *callback_arg, cyhal_timer_event_t event) { STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); qstr mode = self->mode == TIMER_MODE_ONE_SHOT ? MP_QSTR_ONE_SHOT : MP_QSTR_PERIODIC; - mp_printf(print, "Timer(mode=%q, period=%u, tick_hz=1000)", mode, self->period); + mp_printf(print, "Timer(mode=%q, period=%u, tick_hz=%u)", mode, self->period, self->freq); } STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_callback, ARG_period, ARG_freq, }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = TIMER_MODE_PERIODIC} }, + { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = TIMER_MODE_ONE_SHOT} }, { MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, { MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 9999u} }, { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 10000u} },