Skip to content

Incorrect chip id in LibGpiodDriver #2399

@HakanL

Description

@HakanL

Describe the bug

When attempting to open a GPIO chip using the LibGpiodDriver driver for a device (gpio expander) that isn't the built-in device on a Raspberry Pi I'm getting an error that the chip doesn't exist. I believe the issue is that the Id of the chip (which is used when opening a new GpioController for it) is assigned from an index when iterating, instead of the actual id. I'm calling GetAvailableChips and this is the output:

Found GPIO chip: gpiochip0, label pinctrl-rp1  54 lines
Found GPIO chip: gpiochip10, label gpio-brcmstb@107d508500  32 lines
Found GPIO chip: gpiochip11, label gpio-brcmstb@107d517c00  15 lines
Found GPIO chip: gpiochip12, label gpio-brcmstb@107d517c20  6 lines
Found GPIO chip: gpiochip13, label gpio-brcmstb@107d508520  4 lines
Found GPIO chip: gpiochip14, label 0-0040  16 lines
Found GPIO chip: gpiochip15, label mcp23008  8 lines
Found the MCP23008 GPIO expander chip (v2 base board) at id 6
Error in IoManager constructor: Unable to find a chip, error code: 2
System.IO.IOException: Unable to find a chip, error code: 2
   at System.Device.Gpio.Drivers.LibGpiodDriver..ctor(Int32 gpioChip)
   at DMXCore.DMXCore100.RpiIoManager..ctor(ILoggerFactory loggerFactory, IScheduler scheduler) in D:\Projects\DMXCore\100\Software\Shared\IO\RpiIoManager.cs:line 109

The chip I'm trying to access is the MCP23008 which has name gpiochip15, but the reported chipInfo.Id is 6 (its index when iterating, see https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/System/Device/Gpio/Drivers/LibGpiodDriver.cs#L132 which I believe is incorrect.

If I parse the Name property to get id 15 in the example above then I can access my device.

Steps to reproduce

Try to access a chip where the list of ids isn't sequential (happens on my Raspberry Pi 5).

Expected behavior

The Id of GpioChipInfo should be the correct id, not the index.

Actual behavior

Error: Unable to find a chip, error code: 2

Versions used

System.Device.Gpio 4.0.1 from Nuget

Metadata

Metadata

Assignees

Labels

Priority:1Work that is critical for the release, but we could probably ship withoutbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions