Skip to content

bitstream()/dht_readinto() need new HAL primitives (PyMCU/PyMCU#450), not thin wrappers #18

Description

@begeistert

Update 2026-09-15: not a thin wrapper, precise HAL work filed at PyMCU/PyMCU#450

Checked what a wrapper would actually call. Neither is one:

  • bitstream()'s timing argument is a runtime 4-tuple, not compile-time constants, so it
    needs a genuinely runtime-parameterized pulse primitive. pulse_delay_us (already in
    lib/src/pymcu/hal/avr/pulse/atmega328p.py) is the missing piece, but it is microsecond
    granularity: fine for most one-wire protocols, not for WS2812-class sub-microsecond timing
    (pymcu.hal.avr.ws2812 hardcodes counted-NOP timing per protocol instead, for that reason).
  • dht_readinto()'s actual bit-bang routine already exists, but in pymcu-lib-dht
    (src/pymcu_lib_dht/mcu/_dht/avr.py), a separate PyPI package, not PyMCU/PyMCU -- and it
    is hardcoded to PD2-PD7 only. Wrapping a downstream sensor package from this compat
    layer would invert how this project's layering works everywhere else.

Both need real HAL additions, not wrappers: named precisely, with the exact function
signatures to add, at PyMCU/PyMCU#450 (milestone Peripherals).

Original report

machine.bitstream(pin, encoding, timing, data) and machine.dht_readinto(pin, buf) are
MicroPython's generic, precisely-timed single-pin bit-banging primitives (used to drive
WS2812-style LEDs and to read DHT11/22 humidity sensors without a dedicated peripheral).
Neither is exported by src/pymcu_micropython/machine.py.

Repo choice

PyMCU/PyMCU#450 (HAL). src/pymcu_micropython/machine.py needs only thin @inline wrappers
once either lands.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions