skidl icon indicating copy to clipboard operation
skidl copied to clipboard

[SKiDL Feature Request] Multiple slices to access pin numbers

Open Timot05 opened this issue 3 years ago • 4 comments

Would be useful to fetch pins in buses that contain multiple numbers slices. For example:

new_bus = Bus('GPIO[26:29]_ADC[0:3]')

Timot05 avatar Nov 08 '22 15:11 Timot05

Can you provide an example where this would be used?

devbisme avatar Nov 08 '22 15:11 devbisme

The pin names for the microcontroller that I'm currently using have the following names:

GPIO26_ADC1 GPIO27_ADC2 GPIO28_ADC3 GPIO29_ADC4

Timot05 avatar Nov 09 '22 06:11 Timot05

I see the problem. There are several solutions using the existing codebase. Here's the simplest one: use the split_pin_names function (introduced in version 1.0.0). If your microcontroller is in a part named mcu, then you can split all the pin names using underscore as the delimiter like so:

mcu.split_pin_names('_')

After that, each pin named GPIOXX_ADCYY will have additional aliases GPIOXX and ADCYY. Then you can access them using mcu['ADC[1:4]'] or mcu['GPIO[26:29]'].

This may cause some problems if you have other pins with underscore-separated names like DO_NOT_USE which would create pin aliases of DO, NOT and USE that may collide across multiple pins. If that's a problem, we'll think of a work-around.

devbisme avatar Nov 10 '22 14:11 devbisme

Thanks! I will give this a try.

Timot05 avatar Nov 12 '22 22:11 Timot05