Is there any kind of standard for the naming of peripheral pin assignments? If not, can we please implement one? #12855
Replies: 5 comments 3 replies
-
... and maybe also some consideration of recommended separation of bus settings, and names for those, so contention between devices (e.g. different speeds) can be managed better by driver writers (e.g. SD Card and LCD Touchscreen), along with some mechanism so we can have our code support SPI bus speed etc re-initialization (and only when required) |
Beta Was this translation helpful? Give feedback.
-
Just to clarify, are you raising this specifically to MicroPython or by "our community" do you mean embedded programming in general? FWIW, MicroPython has support for pin naming (via the pins.csv file). The idea being that you can write your code using e.g. |
Beta Was this translation helpful? Give feedback.
-
Yes - specifically to MicroPython (don't get me started on the wider embedded community - I've been on panels trying to sort out the IoT security sh*tshow for a few years now - nobody cooperates with anyone else, and the higher up the chain-of-responsibility you go, the worse it gets - all the way to government which is total paralysis - but I digress). I've been looking at code and drivers from a few dozen random places, and nothing works "out of the box", but after I fuss around in datasheets to find pin assignments, and replace all the hard-coded numbers in peoples files, everything seems to work nicely. I've been writing MCU drivers and other things for probably a decade or so now (just hobby stuff - low level C/assembly, but all non-python though) - I've never once come across or heard of any "pins.csv" before (update - nor it seems has google? Maybe it's an educational problem? - nobody's telling anyone about this, nor making the files available for anyone, nor telling anyone to use names instead of hardcoding pin numbers, etc. I've flashed about a dozen micropython boards this week from .bin files I've found in half a dozen different places, and yeah, still never seen anything by anyone about defining names for any pins; not to mention I've never gotten (or seen or been told about) any such files for any of the 50 or so ESP32 boards I've accumulated of the last few years :-( Heck - even half the boards I use in Arduino don't bother to define LED_BUILTIN - it seems to be an industry-wide problem. machine.Pin.board.FOO sounds too simplistic/naïve to be useful though? e.g. What if it was an LED? How do you turn it on? [the level differs between boards], What if your LED is RGB? Or RGBW? or RGBWW? or WS2812? or what if you need specific SPI data rates (what's a generic portable way to resolve multiple devices with different needs) ... working this out is not a trivial thing. And as for "FOO" - that's useless if there's no master standard - machine.Pin.board.SD_MISO and machine.Pin.board.MISO_SD or machine.Pin.board.SD_DAT0 (those last parts being actual circuit markings from just me getting my SD working today) ... where's the list of what people should be calling these things? Or the never-ending infuriation of clock pins being named SCK or CLK or other random abbreviations. So yeah... now I'm even more confused than before I asked the question :-) |
Beta Was this translation helpful? Give feedback.
-
Absolutely. This also extends to interfaces: pass UARTs, I2C or SPI instances, as objects. Then you can confine all hardware dependencies to a small, user-defined config file and write the whole library in a hardware-agnostic fashion. |
Beta Was this translation helpful? Give feedback.
-
Small contribution: when naming things, first don't surprise the user, so if the datasheet or the silk on the board names the pins, do (at least) use those names. (If the datasheet and the silk disagree - well, we live in a shitty world ... maybe provide both. That is, if the two name sets don't collide....) If you get to choose names, order the words ouside to inside, like a set of objects. So sd_miso, not miso_sd. (I prefer snake case, but that is a different war.) Whenever reasonable, prefer to have signals active high. I am a great fan of OO and decorators, so I often use an inverter (invert pin decorator) to adapt this convention to the hardware world, which is often active-low. Context: I am a former embedded head lecturer. Naming things was a major subject in my courses. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be nice if code was portable. Unfortunately, I'm not aware of any standards (except for the poorly supported Arduino LED_BUILTIN) for the naming of things like LED pins (and whether or not the logic on them is inverted), SD_CARD CS/SCK/MISO/MOSI pins, LCD displays (and their type and size etc), speakers and amplifier circuits, ambient light sensors, Touch-display pins, and in general the entire gamut of hardware options.
I'm also unaware of any attempts to try and create any kind of file format which could be added to a build so that programs running on the hardware can use "well known" names for things that require assignment.
Does any of the above exist?
Please can we put our collective heads together and come up with something to solve this?
I think our community would be greatly advantaged if something like this was built/specified/included, so that manufacturers of boards can simply supply this file (or just put it in a "copy/paste" section inside their store listing) - because we as users will then know that we will be able to painlessly get things working, and we will be able to share and contribute our code to others with different boards, whereupon it will just magically work there as well...
Beta Was this translation helpful? Give feedback.
All reactions