It looks like there are some really great ideas on this forum. Specifically, we came across this post while exploring a scheme for implementing pins as C++ objects.
A little background is that we develop Modkit Micro which provides an even more simplified Wiring-esque API in both graphical-block and traditional text-based forms.
From Wiring we inherited a number of text-based functions:
pinMode(PIN13,OUTPUT);
digitalWrite(PIN13,HIGH);
etc..
This is almost identical to the "block" form, which wraps each statement in a rectangular box, with dropdown holders for each parameter like
| pinMode (PIN13 v) (OUTPUT v) |
| digitalWrite (PIN13 v) (HIGH v) |
(where the "v" indicates a dropdown arrow.)
This scheme allowed us to start to explore the boundary between traditional-text and graphical code and we're happy to say that we think we're just beginning to scratch the surface of what we will eventually discover at that intersection. But along with this scheme, it became clear that our text based API would need to remain C-like even though we could access the full power of C++ to pull it all together. The first place this became clear was when implementing components like servos which are exposed as objects in Wiring.
Servo myServo;
...
myServo.attach(12);
myServo.write(90);
It made sense to instantiate and "attach" the servo to a pin graphically so the only question was how to expose the write function. The "dot" syntax (myServo.write()) didn't make sense in our graphical blocks so we looked back to digitalWrite etc and had an epiphany. What we realized is that the base Wiring API always takes the pin a given function is operating on as the first parameter, so it made complete sense that the component (eg servo) would be the first parameter to the function that would operate on it. We ended up with:
setAngle(SERVO1,90); or
| setAngle (SERVO1 v) (90 v) |
To implement this, you can either keep an array of Servo objects and define setAngle as:
void setAngle(int servoNum,int angle){
servoArray[servoNum].write(angle);
}
or pass in an actual servo object and call write on that:
void setAngle(Servo s, int angle){
s.write(angle);
}
We currently have a mix of these two styles of component code, but obviously prefer the class-based approach and will move everything in that direction as we start to document and expose our internals. With this background in mind, we started to look into class-based pins as we began to move beyond just AVR devices. Our first non-AVR target will be the MSP430 Launchpad from TI. We've been working with TI on adding support and have a proof of concept implementation based on the wonderful Energia Project by Robert Wessels (TI employee on his own time). The problem is that the pin numbers were not implemented in a way that can be used with both digitalWrite and analogRead. We don't care if we pass pins around as ints or as objects but we do care that the same "pin id" can be used across the different pin functions. So for this and many other reasons that are touched on in the original post, we think moving to class based pins is the way to go. So rather than having the pin function look up the right peripheral from the numerical pin id, you have a pin object that contains enough info to call the pin function directly.
So mainly we wanted to say thanks to @siy and @gbulmer for all your ideas in that original post. I hope we can continue that discussion here with a focus on how we can move forward rather than why we would want to (which I think the original post makes quite clear) Also could anyone interested in this direction (especially @siy and @gbulmer) please send me an email to ed [at] modk [dot] it, so we can loop you in to the larger discussion? We'd hate to see your experience and ideas go to waste!