We've put live a version of the mbed library with some new features and some behavioural improvements. The main highlights are:
Here are the full details...
Based on some feedback, we've improved the behaviour of the Digital I/O interfaces:
The DigitalIn, DigitalInOut and DigitalOut classes have been optimised to improve performance (see Igor Skochinsky's excellent analysis in http://mbed.org/users/igorsk/notebook/fast-gpio-with-c-templates/). Reads are at about 2x previous speeds, DigitalOut's speed is over 5x as fast, and DigitalInOut's write is over 4x as fast. Also there is now no overhead between using the assignment, or the read/write methods. This also means Bus I/O, which is built on these, is faster too.
DigitalIn and DigitalInOut now also has an open drain option via the mode() method (as requested in http://mbed.org/forum/mbed/topic/178/)
DigitalInOut od(p21); od.mode(OpenDrain);
We've added PortIn, PortInOut and PortOut classes to complement the Digital I/O and Bus I/O interfaces. The main distinction is:
The Bus I/O is the most flexible way to create a collection of pins that can be written in one go, but at the cost of performance; it is really just a collection of Digital I/O pins that are written to one after the other. For performance, writing to multiple pins on a Port I/O is much better, and has similar performance to a single Digital I/O pin. The downside vs Bus I/O is less flexibility of pin selection and layout.
When you create a Port class, you give the constructor the port name, and a mask which indicates which bits of that port are going to be active. You then read from or write to the 32-bit port, with each bit indicating the pin on the port. The class ignores the bits which are for pins you set as '0' in the mask. This has the nice property that multiple Port interfaces can coexist on the same physical port.
Here is an example:
#include "mbed.h"
// LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
PortOut leds(Port1, 0x00B40000); // the mask indicates which bits are considered part of the port
int main() {
while(1) {
leds = 0x00A00000;
wait(1);
leds = 0x00140000;
wait(1);
}
} There are obviously only some pins of ports available, but there is an 8-bit bus available which could be useful for parallel interfaces:
+----------+
GND -+ 1 40 +- Vout
-+ 2 39 +-
-+ 3 38 +-
-+ 4 37 +-
P0.9 -+ 5 36 +-
P0.8 -+ 6 35 +-
P0.7 -+ 7 34 +-
P0.6 -+ 8 33 +-
P0.0 -+ 9 32 +-
P0.1 -+ 10 31 +-
P0.18 -+ 11 30 +- P0.4
P0.17 -+ 12 29 +- P0.5
P0.15 -+ 13 28 +- P0.10
P0.16 -+ 14 27 +- P0.11
P0.23 -+ 15 26 +- P2.0
P0.24 -+ 16 25 +- P2.1
P0.25 -+ 17 24 +- P2.2
P0.26 -+ 18 23 +- P2.3
P1.30 -+ 19 22 +- P2.4
P1.31 -+ 20 21 +- P2.5
+----------+
LED1 LED2 LED3 LED4
P1.18 P1.20 P1.21 P1.23
Here are some of the other tweaks that made it in...
To get these updates for existing programs, simply click on the mbed library in your compiler project and choose "Update to latest revision!". Any problems, suggestions or thumbs ups, please tell us in the Bugs/Suggestions forum!
That's it for this library update. We do have some more new features and improvements that are in the works now, which hopefully will get to you soon.
Please log in to post a comment.
We've just put live a further bug-fix update that solves:
Thanks for the reports that help identify these issues!
To get these updates for existing programs, simply click on the mbed library in your compiler project and choose "Update to latest revision!".
If you ever want to revert to the older version of the library, you can always do that by:
The @ specifies the svn version, so all previous library versions are always available.
Any problems/feedback, please report them in the Bugs/Suggestions forum as usual. More features in the pipeline, coming soon...