You are reading a single comment by @Gordon and its replies.
Click here to read the full conversation.
-
Do you have other suggestions? If there's a better way of doing it I'd be interested.
Few ideas
- ifdef code and enable only if some pins are really negated in board file - you already mentioned it
- move this to common code if possible (?) so it is not in each port separately
- I am actually not sure what it should do and why and on what level this should be, is this mainly just for buttons and leds? So that in javascript code you can treat button/led in normal way - reading,writing, watching change? Will it work if the pull up/down are left alone and instead the negated flag would be visible flag on the Pin object (so you could even toggle it from js yourself on any pin?) because with such flag I'd left figuring out correct pulls on the user code too. So only value would be negated, not pull up/down, that is lot of complicated code. Also if only the BTN1 or LED1 would be negated but the underlying pin D13 not, it could also make the code handling 'normal' pins clear from this if Led and Button would be special object inherited from Pin. Then also the debouncing magic in setWatch in case of buttons would be more clear - watch on Button object would do it, watch on (same) Pin would not. Then maybe port specific code could drop it altogether and Pin and Led with this pin negation feature could be in common code.
So to sum it up I think making negated flag on pins completely invisible/transparent including pull up/down is too heavy and too much magic. Letting user know about it and possibly handle it could be better. An also maybe this should not be feature of the pin at all but something more high level - button, led.
- ifdef code and enable only if some pins are really negated in board file - you already mentioned it
Hi - yes, it probably makes sense to pull in the pin negation code. Maybe
#ifdef
so it's not bloating boards where it isn't used (I should probably have done this on NRF52 too).Do you have other suggestions? If there's a better way of doing it I'd be interested.
Yes, that'll help with things like the bootloader/espruino bootup. It's used when declaring stuff like:
But while it works fine when used from the C code, it doesn't work when accessing pins themselves