Skip to content

Commit

Permalink
ports/psoc6: Timer Documentation.
Browse files Browse the repository at this point in the history
Signed-off-by: IFX-Anusha <Anusha.TR-EE@infineon.com>
  • Loading branch information
IFX-Anusha committed Jul 28, 2023
1 parent b0bcc24 commit 240048e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/psoc6/feature_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Enabled modules
* I2C
* RTC
* SoftI2C
* SPI
* SoftSPI
* PWM
* Timer
* micropython
* ucryptolib
* uctypes
Expand Down Expand Up @@ -117,6 +121,8 @@ Table :ref:`configuration details <table_mpy_configuration>` 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``. |
Expand Down
15 changes: 15 additions & 0 deletions docs/psoc6/quickref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,19 @@ Methods
^^^^^^^
All the methods(functions) given in :ref:`machine.SPI <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
4 changes: 2 additions & 2 deletions ports/psoc6/modules/machine/machine_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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} },
Expand Down

0 comments on commit 240048e

Please sign in to comment.