micropython/extmod
robert-hh 61bbd78eba mimxrt: Implement Quadrature Encoder and Counter classes.
These classes are based on the Quadrature Encoder blocks of the i.MXRT
MCUs.  The i.MXRT 102x has two encoders, the other ones four.  The i.MXRT
101x does not support this function.  It is implemented as two classes,
Encoder and Counter.

The number of pins that can be uses as inputs is limited by the MCU
architecture and the board schematics.  The Encoder class supports:
- Defining the module.
- Defining the input pins.
- Defining a pin for an index signal.
- Defining a pin for a reset signal.
- Defining an output pin showing the compare match signal.
- Setting the number of cycles per revolution (min/max).
- Setting the initial value for the position.
- Setting the counting direction.
- Setting a glitch filter.
- Defining callbacks for getting to a specific position, overrun and
  underrun (starting the next revolution).  These callbacks can be hard
  interrupts to ensure short latency.

The encoder counts all phases of a cycle.  The span for the position is
2**32, for the revolution is 2**16.  The highest input frequency is
CPU-Clock/24.  Note that the "phases" argument is emulated at the API
level (the hardware will always count all phases).

The Counter mode counts single pulses on input A of the Encoder.  The
configuration supports:
- Defining the module.
- Defining the input pin.
- Defining the counting direction, either fixed or controlled by the level
  of an input pin.
- Defining a pin for an index signal.
- Defining an output pin showing the compare match signal.
- Setting the counter value.
- Setting the glitch filter.
- Defining a callback which is called at a certain value.
- Settings for MIMXRT1015. The MIMXRT1015 MCU has only one encoder/counter
  unit.

The counting range is 0 - 2**32-1 and a 16 bit overrun counter.  The
highest input frequency is CPU-Clock/12.

The implementation of the `.irq()` method uses the common code from
`shared/runtime/mpirq.c`, including the `irq().flags()` and
`irq().trigger()` methods.

Signed-off-by: robert-hh <robert@hammelrath.com>
2026-03-08 23:54:15 +11:00
..
asyncio extmod/asyncio: Pass globals in __import__ call. 2025-11-21 00:07:35 +11:00
axtls-include all: Prune trailing whitespace. 2024-03-07 16:25:17 +11:00
berkeley-db all: Update extmod, ports, examples to build with new berkeley-db lib. 2024-03-16 12:19:12 +11:00
btstack extmod/modbluetooth: Add timeout to deinit. 2025-06-04 02:21:32 +10:00
libmetal extmod/libmetal: Fix libmetal rules for mkdir dependencies. 2024-09-06 17:14:03 +10:00
littlefs-include lib/littlefs: Reuse existing CRC32 function to save space. 2025-05-07 17:03:28 +10:00
lwip-include extmod/modlwip: Remove unused include and functions. 2025-08-16 14:52:52 +10:00
mbedtls extmod/mbedtls: Factor out mbedtls_hardware_poll() to common code. 2026-03-03 23:43:42 +11:00
nimble extmod/modbluetooth: Add timeout to deinit. 2025-06-04 02:21:32 +10:00
cyw43_config_common.h rp2,extmod/cyw43: Move the LWIP responder fix into common CYW43 config. 2025-05-08 15:32:05 +10:00
extmod.cmake extmod/machine_i2c_target: Add new machine.I2CTarget class. 2025-08-01 23:03:17 +10:00
extmod.mk extmod/machine_i2c_target: Add new machine.I2CTarget class. 2025-08-01 23:03:17 +10:00
font_petme128_8x8.h extmod: Move font_petme128_8x8.h from ports/stm32 to extmod. 2022-05-05 13:30:40 +10:00
machine_adc_block.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_adc.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_bitstream.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_i2c_target.c extmod/machine_i2c_target: Add new machine.I2CTarget class. 2025-08-01 23:03:17 +10:00
machine_i2c.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_i2s.c extmod: Ensure stream ioctl's are a no-op for unknown requests. 2026-02-07 16:33:21 +11:00
machine_mem.c extmod/modmachine: Add MICROPY_PY_MACHINE_MEMX configuration option. 2024-03-15 12:04:34 +11:00
machine_pinbase.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_pulse.c esp8266/modmachine: Use common machine_time_pulse_us implementation. 2025-06-13 16:27:35 +10:00
machine_pwm.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_signal.c extmod/modmachine: Add MICROPY_PY_MACHINE_SIGNAL configuration option. 2024-03-15 12:04:25 +11:00
machine_spi.c extmod/machine_spi: Support firstbit=LSB for machine.SoftSPI. 2024-07-12 22:59:31 +10:00
machine_timer.c extmod/machine_timer: Support hard IRQ soft timer callbacks. 2025-09-25 23:59:24 +10:00
machine_uart.c py/stream: Add a stream.readinto1() method for machine.UART. 2025-09-11 12:42:24 +10:00
machine_usb_device.c shared/tinyusb: Remove USBD_RHPORT constant. 2025-11-30 23:18:57 +11:00
machine_wdt.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
misc.h extmod/os_dupterm: Let mp_os_dupterm_tx_strn() return num bytes written. 2023-12-22 10:26:52 +11:00
modasyncio.c extmod/modasyncio: Add support for a callback on TaskQueue push. 2024-06-20 00:11:05 +10:00
modbinascii.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modbluetooth.c extmod/modbluetooth: Add timeout to deinit. 2025-06-04 02:21:32 +10:00
modbluetooth.h extmod/modbluetooth: Add timeout to deinit. 2025-06-04 02:21:32 +10:00
modbtree.c extmod/modbtree: Add checks for already-closed database. 2024-07-22 10:42:29 +10:00
modcryptolib.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
moddeflate.c extmod/moddeflate: Keep DeflateIO state consistent on window alloc fail. 2025-03-27 11:58:59 +11:00
modframebuf.c extmod/modframebuf: Save code size in setpixel. 2025-08-15 01:17:00 +10:00
modhashlib.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modheapq.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modjson.c extmod/modjson: Detect unterminated composite entities. 2025-05-19 02:09:40 +02:00
modlwip.c extmod,rp2: Keep LWIP timer running if lwip poll_sockets() is called. 2026-03-04 11:44:30 +11:00
modmachine.c extmod/machine_i2c_target: Add new machine.I2CTarget class. 2025-08-01 23:03:17 +10:00
modmachine.h mimxrt: Implement Quadrature Encoder and Counter classes. 2026-03-08 23:54:15 +11:00
modmarshal.c extmod/modmarshal: Support marshal.dumps of functions with children. 2026-01-27 01:20:36 +11:00
modnetwork.c extmod/modnetwork: Consolidate definition of common drivers. 2025-06-10 11:20:38 +10:00
modnetwork.h extmod/network_lwip: Add sys_untimeout_all_with_arg helper function. 2025-07-17 13:38:58 +10:00
modonewire.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modopenamp_remoteproc_store.c extmod/modopenamp: Check that mp_vfs_open actually returned a stream. 2025-09-28 22:46:05 +10:00
modopenamp_remoteproc.c extmod/modopenamp: Add support for building Open-AMP on device side. 2024-08-08 17:59:32 +10:00
modopenamp_remoteproc.h extmod/modopenamp_remoteproc: Add new OpenAMP RemoteProc class. 2024-03-15 18:11:28 +11:00
modopenamp.c extmod/modopenamp: Rework trace buffer setup procedure. 2026-01-04 12:02:59 +11:00
modopenamp.h extmod/modopenamp: Rework trace buffer setup procedure. 2026-01-04 12:02:59 +11:00
modos.c extmod/modos: Raise an error at a negative argument of os.urandom(). 2026-02-24 23:36:02 +11:00
modplatform.c extmod/modplatform: Expose CPU features/extensions. 2025-09-11 11:58:29 +10:00
modplatform.h extmod/modplatform: Distinguish RISC-V 64 from RISC-V 32. 2024-12-10 12:10:36 +11:00
modrandom.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modre.c extmod/modre: Add support for start- and endpos. 2025-08-11 14:11:56 +10:00
modselect.c extmod/modselect: Handle pending events before entering poll. 2026-01-26 23:33:11 +11:00
modsocket.c extmod/modsocket: Add missing static in private function definitions. 2025-01-02 13:33:39 +11:00
modtime.c extmod/modtime: Move tuple creation to common localtime implementation. 2025-08-15 12:09:13 +10:00
modtime.h all: Rename *umodule*.h to remove the "u" prefix. 2023-06-08 17:54:14 +10:00
modtls_axtls.c py/stream: Use detailed error strings for TLS sockets. 2026-02-07 16:34:20 +11:00
modtls_mbedtls.c py/stream: Use detailed error strings for TLS sockets. 2026-02-07 16:34:20 +11:00
moductypes.c extmod/moductypes: Error if small ints are not big enough. 2025-09-28 23:23:04 +10:00
modvfs.c extmod/modvfs: Add vfs.rom_ioctl function and its ioctl constants. 2025-03-06 12:52:35 +11:00
modwebrepl.c all: Use new mp_obj_new_str_from_cstr() function. 2024-07-04 15:55:03 +10:00
modwebsocket.c extmod/modwebsocket: Save a few bytes of text by using bit checks. 2025-10-05 15:43:02 +11:00
modwebsocket.h all: Rename *umodule*.h to remove the "u" prefix. 2023-06-08 17:54:14 +10:00
mpbthci.c extmod/modbluetooth: Refactor stack/hci/driver/port bindings. 2020-09-08 11:41:31 +10:00
mpbthci.h extmod,alif,mimxrt,rp2,stm32: Create common cyw43 driver config header. 2025-05-08 15:32:05 +10:00
network_cyw43.c extmod/network_cyw43: Disconnect STA if making inactive. 2025-05-20 23:14:41 +10:00
network_cyw43.h extmod: Add network-level class binding to cyw43 driver. 2019-06-03 16:47:35 +10:00
network_esp_hosted.c extmod/modnetwork: Consolidate definition of common drivers. 2025-06-10 11:20:38 +10:00
network_lwip.c extmod/network_lwip: Add sys_untimeout_all_with_arg helper function. 2025-07-17 13:38:58 +10:00
network_ninaw10.c extmod/network_nina: Fix the AP security mode constants. 2024-07-12 01:03:46 +10:00
network_ppp_lwip.c esp32/network_ppp: Stop polling if PPP was disconnected. 2025-08-25 23:11:33 +10:00
network_wiznet5k.c all: Use enum instead of bool argument to mp_handle_pending. 2026-02-05 00:29:36 +11:00
os_dupterm.c extmod/os_dupterm: Handle exception properly when it occurs in parallel. 2024-03-16 10:59:03 +11:00
vfs_blockdev.c extmod/vfs_blockdev: Check return type is an integer. 2025-10-01 11:14:39 +10:00
vfs_fat_diskio.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
vfs_fat_file.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
vfs_fat.c shared/timeutils: Standardize supported date range on all platforms. 2025-07-09 11:54:21 +10:00
vfs_fat.h extmod: Factor out block-device struct to make independent of fatfs. 2019-10-29 12:12:37 +11:00
vfs_lfs.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
vfs_lfs.h extmod: Add VFS littlefs bindings. 2019-10-29 14:17:29 +11:00
vfs_lfsx_file.c extmod: Ensure stream ioctl's are a no-op for unknown requests. 2026-02-07 16:33:21 +11:00
vfs_lfsx.c extmod/vfs_lfsx: Allow overriding the LFS2 on-disk version format. 2025-07-23 15:51:08 +10:00
vfs_posix_file.c extmod: Ensure stream ioctl's are a no-op for unknown requests. 2026-02-07 16:33:21 +11:00
vfs_posix.c extmod/vfs_posix: Add MICROPY_VFS_POSIX_WRITABLE option. 2025-07-24 10:39:41 +10:00
vfs_posix.h extmod/vfs: Introduce a C-level VFS protocol, with fast import_stat. 2018-06-06 14:33:42 +10:00
vfs_reader.c extmod/vfs_reader: Process pending events during file reads. 2026-02-24 18:46:01 +11:00
vfs_rom_file.c extmod/vfs_rom: Add VfsRom filesystem object. 2024-12-23 13:04:54 +11:00
vfs_rom.c extmod/vfs_rom: Implement minimal VfsRom.getcwd() method. 2025-03-27 17:04:12 +11:00
vfs_rom.h extmod/vfs_rom: Add VfsRom filesystem object. 2024-12-23 13:04:54 +11:00
vfs.c all: Replace legacy name with MicroPython and MPy as applicable. 2025-10-04 00:19:40 +10:00
vfs.h extmod/vfs: Add mp_vfs_mount_romfs_protected() helper. 2025-03-06 12:52:35 +11:00
virtpin.c py/obj: Add accessors for type slots and use everywhere. 2022-09-19 19:06:07 +10:00
virtpin.h all: Unify header guard usage. 2017-07-18 11:57:39 +10:00