Takuo WATANABE
/
pin_port_test
A test program for pin_port
main.cpp@0:e1196d52682f, 2015-12-21 (annotated)
- Committer:
- takuo
- Date:
- Mon Dec 21 07:46:16 2015 +0000
- Revision:
- 0:e1196d52682f
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takuo | 0:e1196d52682f | 1 | /** A test program for pin_port |
takuo | 0:e1196d52682f | 2 | * Takuo WATANABE |
takuo | 0:e1196d52682f | 3 | * http://mbed.org/users/takuo/code/pin_port/ |
takuo | 0:e1196d52682f | 4 | */ |
takuo | 0:e1196d52682f | 5 | |
takuo | 0:e1196d52682f | 6 | #include "mbed.h" |
takuo | 0:e1196d52682f | 7 | #include "pin_port.h" |
takuo | 0:e1196d52682f | 8 | #include "pins.h" |
takuo | 0:e1196d52682f | 9 | |
takuo | 0:e1196d52682f | 10 | #define LEN(a) (sizeof(a) / sizeof((a)[0])) |
takuo | 0:e1196d52682f | 11 | |
takuo | 0:e1196d52682f | 12 | bool test_pin(PinName pin) { |
takuo | 0:e1196d52682f | 13 | PortName port; |
takuo | 0:e1196d52682f | 14 | int pos = pin_port(pin, &port); |
takuo | 0:e1196d52682f | 15 | if (pin == port_pin(port, pos)) |
takuo | 0:e1196d52682f | 16 | return true; |
takuo | 0:e1196d52682f | 17 | else { |
takuo | 0:e1196d52682f | 18 | printf("bad: %d -> (%d, %d)\n", (int)pin, (int)port, pos); |
takuo | 0:e1196d52682f | 19 | return false; |
takuo | 0:e1196d52682f | 20 | } |
takuo | 0:e1196d52682f | 21 | } |
takuo | 0:e1196d52682f | 22 | |
takuo | 0:e1196d52682f | 23 | void test_pins() { |
takuo | 0:e1196d52682f | 24 | bool ok = true; |
takuo | 0:e1196d52682f | 25 | for (int i = 0; i < LEN(pins); i++) { |
takuo | 0:e1196d52682f | 26 | printf("."); |
takuo | 0:e1196d52682f | 27 | if (!test_pin(pins[i])) |
takuo | 0:e1196d52682f | 28 | ok = false; |
takuo | 0:e1196d52682f | 29 | } |
takuo | 0:e1196d52682f | 30 | printf("\n"); |
takuo | 0:e1196d52682f | 31 | if (ok) |
takuo | 0:e1196d52682f | 32 | printf("OK\n"); |
takuo | 0:e1196d52682f | 33 | } |
takuo | 0:e1196d52682f | 34 | |
takuo | 0:e1196d52682f | 35 | int main() { |
takuo | 0:e1196d52682f | 36 | PortName port; |
takuo | 0:e1196d52682f | 37 | int pos = pin_port(LED1, &port); |
takuo | 0:e1196d52682f | 38 | printf("LED1: port=%d, bit=%d\n", (int)port, pos); |
takuo | 0:e1196d52682f | 39 | test_pins(); |
takuo | 0:e1196d52682f | 40 | return 0; |
takuo | 0:e1196d52682f | 41 | } |