From a125a25a9704d50419e677a813a54fa951e4a143 Mon Sep 17 00:00:00 2001 From: Toyomasa Watarai Date: Wed, 24 Jul 2013 18:37:12 +0900 Subject: [PATCH] Implemented PortIn, PortOut and PortInOut API #8 Followingt test cases have been passed: * PortOut (#24) * PortOut PortIn (#9) * PortInOut (#8) --- .../hal/TARGET_NXP/TARGET_LPC11XX/device.h | 6 ++-- .../hal/TARGET_NXP/TARGET_LPC11XX/objects.h | 2 +- .../hal/TARGET_NXP/TARGET_LPC11XX/port_api.c | 35 ++++++++++--------- libraries/tests/mbed/portinout/main.cpp | 9 +++++ libraries/tests/mbed/portout/main.cpp | 2 +- libraries/tests/mbed/portout_portin/main.cpp | 9 +++++ 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/device.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/device.h index 7a93c9bbec..ab3d323804 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/device.h +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/device.h @@ -16,9 +16,9 @@ #ifndef MBED_DEVICE_H #define MBED_DEVICE_H -#define DEVICE_PORTIN 0 -#define DEVICE_PORTOUT 0 -#define DEVICE_PORTINOUT 0 +#define DEVICE_PORTIN 1 +#define DEVICE_PORTOUT 1 +#define DEVICE_PORTINOUT 1 #define DEVICE_INTERRUPTIN 1 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/objects.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/objects.h index f736bcf5f7..752af4de29 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/objects.h +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/objects.h @@ -32,7 +32,7 @@ struct gpio_irq_s { struct port_s { __IO uint32_t *reg_dir; - __IO uint32_t *reg_mpin; + __IO uint32_t *reg_data; PortName port; uint32_t mask; }; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/port_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/port_api.c index f39a420a33..6928c33fd8 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/port_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/port_api.c @@ -14,32 +14,35 @@ * limitations under the License. */ -#warning TODO(@toyowata) This platform doesn't support PortIn, PortOut and PortInOut -#if 0 - #include "port_api.h" #include "pinmap.h" #include "gpio_api.h" -PinName port_pin(PortName port, int pin_n) { - return (PinName)((port << PORT_SHIFT) | pin_n); +// LPC114 IOCON offset table [port][pin] + +static uint8_t iocon_offset[4][12] = { + {0x0c,0x10,0x1c,0x2c,0x30,0x34,0x4c,0x50,0x60,0x64,0x68,0x74}, // PORT 0 + {0x78,0x7c,0x80,0x90,0x94,0xa0,0xa4,0xa8,0x14,0x38,0x6c,0x98}, // PORT 1 + {0x08,0x28,0x5c,0x8c,0x40,0x44,0x00,0x20,0x24,0x54,0x58,0x70}, // PORT 2 + {0x84,0x88,0x9c,0xac,0x3c,0x48} // PORT 3 +}; + +static PinName port_pin(PortName port, int pin) { + return (PinName)((port << PORT_SHIFT) | (pin << PIN_SHIFT) | (uint32_t)iocon_offset[port][pin]); } void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { obj->port = port; obj->mask = mask; - LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + ((int)port * 0x20)); + LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (port * 0x10000))); - port_reg->MASK = ~mask; - - obj->reg_out = &port_reg->PIN; - obj->reg_in = &port_reg->PIN; - obj->reg_dir = &port_reg->DIR; + obj->reg_data = &port_reg->DATA; + obj->reg_dir = &port_reg->DIR; uint32_t i; // The function is set per pin: reuse gpio logic - for (i=0; i<32; i++) { + for (i=0; i<12; i++) { if (obj->mask & (1<port, i)); } @@ -51,7 +54,7 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { void port_mode(port_t *obj, PinMode mode) { uint32_t i; // The mode is set per pin: reuse pinmap logic - for (i=0; i<32; i++) { + for (i=0; i<12; i++) { if (obj->mask & (1<port, i), mode); } @@ -66,10 +69,10 @@ void port_dir(port_t *obj, PinDirection dir) { } void port_write(port_t *obj, int value) { - *obj->reg_mpin = value; + *obj->reg_data = (value & obj->mask); } int port_read(port_t *obj) { - return (*obj->reg_mpin); + return (*obj->reg_data & obj->mask); } -#endif + diff --git a/libraries/tests/mbed/portinout/main.cpp b/libraries/tests/mbed/portinout/main.cpp index 7ae5a4e327..8c0c1ff5c3 100644 --- a/libraries/tests/mbed/portinout/main.cpp +++ b/libraries/tests/mbed/portinout/main.cpp @@ -18,6 +18,15 @@ #define P2_2 (1 << 0) // p2.0 -> p26 #define PORT_2 Port2 +#elif defined(TARGET_LPC1114) +#define P1_1 (1 << 9) // p0.9 +#define P1_2 (1 << 8) // p0.8 +#define PORT_1 Port0 + +#define P2_1 (1 << 1) // p1.1 +#define P2_2 (1 << 0) // p1.0 +#define PORT_2 Port1 + #elif defined(TARGET_KL25Z) #define P1_1 (1 << 1) // PTA1 #define P1_2 (1 << 2) // PTA2 diff --git a/libraries/tests/mbed/portout/main.cpp b/libraries/tests/mbed/portout/main.cpp index 1fd9732302..d6e04353cd 100644 --- a/libraries/tests/mbed/portout/main.cpp +++ b/libraries/tests/mbed/portout/main.cpp @@ -5,7 +5,7 @@ # define LED2 (1 << 20) // P1.20 # define LED3 (1 << 21) // P1.21 # define LED4 (1 << 23) // P1.23 -# elif defined(TARGET_LPC11U24) +# elif defined(TARGET_LPC11U24) || defined(TARGET_LPC1114) # define LED1 (1 << 8) // P1.8 # define LED2 (1 << 9) // P1.9 # define LED3 (1 << 10) // P1.10 diff --git a/libraries/tests/mbed/portout_portin/main.cpp b/libraries/tests/mbed/portout_portin/main.cpp index c29d20d359..67ed528fc3 100644 --- a/libraries/tests/mbed/portout_portin/main.cpp +++ b/libraries/tests/mbed/portout_portin/main.cpp @@ -18,6 +18,15 @@ #define P2_2 (1 << 0) // p2.0 -> p26 #define PORT_2 Port2 +#elif defined(TARGET_LPC1114) +#define P1_1 (1 << 9) // p0.9 +#define P1_2 (1 << 8) // p0.8 +#define PORT_1 Port0 + +#define P2_1 (1 << 1) // p1.1 +#define P2_2 (1 << 0) // p1.0 +#define PORT_2 Port1 + #elif defined(TARGET_KL25Z) #define P1_1 (1 << 1) // PTA1 #define P1_2 (1 << 2) // PTA2