A test program for pin_port

Dependencies:   mbed pin_port

Files at this revision

API Documentation at this revision

Comitter:
takuo
Date:
Mon Dec 21 07:46:16 2015 +0000
Commit message:
Initial commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
pin_port.lib Show annotated file Show diff for this revision Revisions of this file
pins.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r e1196d52682f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 21 07:46:16 2015 +0000
@@ -0,0 +1,41 @@
+/** A test program for pin_port
+ * Takuo WATANABE
+ * http://mbed.org/users/takuo/code/pin_port/
+ */
+
+#include "mbed.h"
+#include "pin_port.h"
+#include "pins.h"
+
+#define LEN(a) (sizeof(a) / sizeof((a)[0]))
+
+bool test_pin(PinName pin) {
+    PortName port;
+    int pos = pin_port(pin, &port);
+    if (pin == port_pin(port, pos))
+        return true;
+    else {
+        printf("bad: %d -> (%d, %d)\n", (int)pin, (int)port, pos);
+        return false;
+    }
+}
+
+void test_pins() {
+    bool ok = true;
+    for (int i = 0; i < LEN(pins); i++) {
+        printf(".");
+        if (!test_pin(pins[i]))
+            ok = false;
+    }
+    printf("\n");
+    if (ok)
+        printf("OK\n");
+}
+
+int main() {
+    PortName port;
+    int pos = pin_port(LED1, &port);
+    printf("LED1: port=%d, bit=%d\n", (int)port, pos);
+    test_pins();
+    return 0;
+}
diff -r 000000000000 -r e1196d52682f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 21 07:46:16 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file
diff -r 000000000000 -r e1196d52682f pin_port.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pin_port.lib	Mon Dec 21 07:46:16 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/takuo/code/pin_port/#5b6a266f2211
diff -r 000000000000 -r e1196d52682f pins.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pins.h	Mon Dec 21 07:46:16 2015 +0000
@@ -0,0 +1,38 @@
+PinName pins[] = {
+#if defined(TARGET_LPC1768)
+    P0_0,  P0_1,  P0_2,  P0_3,  P0_4,  P0_5,  P0_6,  P0_7,  P0_8,  P0_9,  P0_10, P0_11, P0_12, P0_13, P0_14, P0_15,
+    P0_16, P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23, P0_24, P0_25, P0_26, P0_27, P0_28, P0_29, P0_30, P0_31,
+    P1_0,  P1_1,  P1_2,  P1_3,  P1_4,  P1_5,  P1_6,  P1_7,  P1_8,  P1_9,  P1_10, P1_11, P1_12, P1_13, P1_14, P1_15,
+    P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23, P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31,
+    P2_0,  P2_1,  P2_2,  P2_3,  P2_4,  P2_5,  P2_6,  P2_7,  P2_8,  P2_9,  P2_10, P2_11, P2_12, P2_13, P2_14, P2_15,
+    P2_16, P2_17, P2_18, P2_19, P2_20, P2_21, P2_22, P2_23, P2_24, P2_25, P2_26, P2_27, P2_28, P2_29, P2_30, P2_31,
+    P3_0,  P3_1,  P3_2,  P3_3,  P3_4,  P3_5,  P3_6,  P3_7,  P3_8,  P3_9,  P3_10, P3_11, P3_12, P3_13, P3_14, P3_15,
+    P3_16, P3_17, P3_18, P3_19, P3_20, P3_21, P3_22, P3_23, P3_24, P3_25, P3_26, P3_27, P3_28, P3_29, P3_30, P3_31,
+    P4_0,  P4_1,  P4_2,  P4_3,  P4_4,  P4_5,  P4_6,  P4_7,  P4_8,  P4_9,  P4_10, P4_11, P4_12, P4_13, P4_14, P4_15,
+    P4_16, P4_17, P4_18, P4_19, P4_20, P4_21, P4_22, P4_23, P4_24, P4_25, P4_26, P4_27, P4_28, P4_29, P4_30, P4_31,
+#elif defined(TARGET_LPC11U24)
+    P0_0,  P0_1,  P0_2,  P0_3,  P0_4,  P0_5,  P0_6,  P0_7,  P0_8,  P0_9,  P0_10, P0_11, P0_12, P0_13, P0_14, P0_15,
+    P0_16, P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23, P0_24, P0_25, P0_26, P0_27, 
+    P1_0,  P1_1,  P1_2,  P1_3,  P1_4,  P1_5,  P1_6,  P1_7,  P1_8,  P1_9,  P1_10, P1_11, P1_12, P1_13, P1_14, P1_15,
+    P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23, P1_24, P1_25, P1_26, P1_27, P1_28, P1_29,        P1_31,
+#elif defined(TARGET_KL25Z) || defined(TARGET_KL46Z) || (defined(TARGET_MCU_K64F) && defined(TARGET_FRDM))
+    PTA0,  PTA1,  PTA2,  PTA3,  PTA4,  PTA5,  PTA6,  PTA7,  PTA8,  PTA9,  PTA10, PTA11, PTA12, PTA13, PTA14, PTA15,
+    PTA16, PTA17, PTA18, PTA19, PTA20, PTA21, PTA22, PTA23, PTA24, PTA25, PTA26, PTA27, PTA28, PTA29, PTA30, PTA31,
+    PTB0,  PTB1,  PTB2,  PTB3,  PTB4,  PTB5,  PTB6,  PTB7,  PTB8,  PTB9,  PTB10, PTB11, PTB12, PTB13, PTB14, PTB15,
+    PTB16, PTB17, PTB18, PTB19, PTB20, PTB21, PTB22, PTB23, PTB24, PTB25, PTB26, PTB27, PTB28, PTB29, PTB30, PTB31,
+    PTC0,  PTC1,  PTC2,  PTC3,  PTC4,  PTC5,  PTC6,  PTC7,  PTC8,  PTC9,  PTC10, PTC11, PTC12, PTC13, PTC14, PTC15,
+    PTC16, PTC17, PTC18, PTC19, PTC20, PTC21, PTC22, PTC23, PTC24, PTC25, PTC26, PTC27, PTC28, PTC29, PTC30, PTC31,
+    PTD0,  PTD1,  PTD2,  PTD3,  PTD4,  PTD5,  PTD6,  PTD7,  PTD8,  PTD9,  PTD10, PTD11, PTD12, PTD13, PTD14, PTD15,
+    PTD16, PTD17, PTD18, PTD19, PTD20, PTD21, PTD22, PTD23, PTD24, PTD25, PTD26, PTD27, PTD28, PTD29, PTD30, PTD31,
+    PTE0,  PTE1,  PTE2,  PTE3,  PTE4,  PTE5,  PTE6,  PTE7,  PTE8,  PTE9,  PTE10, PTE11, PTE12, PTE13, PTE14, PTE15,
+    PTE16, PTE17, PTE18, PTE19, PTE20, PTE21, PTE22, PTE23, PTE24, PTE25, PTE26, PTE27, PTE28, PTE29, PTE30, PTE31,
+#elif defined(TARGET_NUCLEO_F401RE)
+    PA_0, PA_1, PA_2, PA_3, PA_4, PA_5, PA_6, PA_7, PA_8, PA_9, PA_10, PA_11, PA_12, PA_13, PA_14, PA_15,
+    PB_0, PB_1, PB_2, PB_3, PB_4, PB_5, PB_6, PB_7, PB_8, PB_9, PB_10,        PB_12, PB_13, PB_14, PB_15,
+    PC_0, PC_1, PC_2, PC_3, PC_4, PC_5, PC_6, PC_7, PC_8, PC_9, PC_10, PC_11, PC_12, PC_13, PC_14, PC_15,
+                PD_2,
+    PH_0, PH_1,
+#else
+#error "Unsupported target"
+#endif
+};