Skip to content

raspberrypi: Some pins can't be used for IncrementalEncoder #4556

@jepler

Description

@jepler

User "Tosche" reported on Discord that their chosen pins for IncrementalEncoder didn't work, but it should have worked:

import microcontroller
import rotaryio
enc = rotaryio.IncrementalEncoder(board.GP14,board.GP15)

StateMachine.c's internal routine mask_and_rotate may be dealing incorrectly with NULL pins & zero bit_counts. However, while trying to diagnose this I ran into #4555 and don't have a fix I'm confident of. Here's what I tried:

 static uint32_t mask_and_rotate(const mcu_pin_obj_t *first_pin, uint32_t bit_count, uint32_t value) {
+    if (!first_pin || !bit_count) {
+        return 0;
+    }
     value = value & ((1 << bit_count) - 1);
     uint32_t shift = first_pin->number;
     return value << shift | value >> (32 - shift);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrp2040Raspberry Pi RP2040

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions