diff --git a/embedded/common/modules/sensor-drivers/BMG160.c b/embedded/common/modules/sensor-drivers/BMG160.c
index 4a227bc..f94bd06 100644
--- a/embedded/common/modules/sensor-drivers/BMG160.c
+++ b/embedded/common/modules/sensor-drivers/BMG160.c
@@ -89,10 +89,11 @@
#include "bmg160.h"
#include "sensorhub.h"
#include "common.h"
-#include "board.h"
#include "gyro_common.h"
#include "osp-sensors.h"
#include "sensacq_i2c.h"
+#include "gpio_api.h"
+#include "gpio_irq_api.h"
static struct bmg160_t *p_bmg160 = NULL;
static struct bmg160_t bmg160;
@@ -137,12 +138,15 @@ static void gyro_activate(bool enable)
void Gyro_HardwareSetup(osp_bool_t enable)
{
+ gpio_t hostifIrq;
+ gpio_irq_t gpioIrq;
NVIC_DisableIRQ(GYRO_PINT_IRQn);
NVIC_SetPriority(GYRO_PINT_IRQn, SENSOR_IRQ_PRIORITY);
- Chip_GPIO_SetPinDIRInput(LPC_GPIO, GYRO_INT_PORT, GYRO_INT_PIN);
- Chip_INMUX_PinIntSel(GYRO_PINT_SEL,GYRO_INT_PORT, GYRO_INT_PIN);
- Chip_PININT_SetPinModeEdge(LPC_PININT, GYRO_PINT_CH);
- Chip_PININT_EnableIntHigh(LPC_PININT, GYRO_PINT_CH);
+ hostifIrq.pin = ENCODE_PORT_PIN(GYRO_INT_PORT, GYRO_INT_PIN);
+ gpio_dir(&hostifIrq,PIN_INPUT);
+ gpioIrq.irq_index = GYRO_PINT_CH;
+ gpioIrq.event = IRQ_EDGE_RISE;
+ gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(GYRO_INT_PORT, GYRO_INT_PIN), NULL, GYRO_PINT_SEL);
Chip_SYSCON_EnableWakeup(GYRO_WAKE);
}
@@ -228,7 +232,9 @@ void Gyro_ReadData(MsgGyroData *gyroData)
void GYRO_IRQHandler(void)
{
+ gpio_irq_t gpioIrq;
uint32_t currTime = GetCurrentTime();
+ gpioIrq.irq_index = GYRO_PINT_CH;
#if 0
PhysicalSensor_t* pSens = g_phySensors[PHYS_GYRO_ID];
uint32_t currTime = g_Timer.GetCurrent();
@@ -236,10 +242,10 @@ void GYRO_IRQHandler(void)
pSens->ts_lastSample = currTime;
pSens->irq_pending++;
- Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH);
+ gpio_irq_disable(&gpioIrq);
ResMgr_IRQDone();
#else
- Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH);
+ gpio_irq_disable(&gpioIrq);
SendDataReadyIndication(GYRO_INPUT_SENSOR, currTime);
#endif
}
diff --git a/embedded/common/modules/sensor-drivers/bma2x2.c b/embedded/common/modules/sensor-drivers/bma2x2.c
index 8a22084..24612ea 100644
--- a/embedded/common/modules/sensor-drivers/bma2x2.c
+++ b/embedded/common/modules/sensor-drivers/bma2x2.c
@@ -80,9 +80,10 @@
#include "sensorhub.h"
#include "common.h"
#include "acc_common.h"
-#include "board.h"
#include "osp-sensors.h"
#include "sensacq_i2c.h"
+#include "gpio_api.h"
+#include "gpio_irq_api.h"
/* user defined code to be added here ... */
static bma2x2_t *p_bma2x2;
@@ -122,23 +123,24 @@ static void accel_activate(bool enable)
}
void Accel_HardwareSetup(osp_bool_t enable)
{
+ gpio_t hostifIrq;
+ gpio_irq_t gpioIrq;
/* ACCEL INT1 irq setup */
NVIC_DisableIRQ(ACCEL_PINT_IRQn);
NVIC_SetPriority(ACCEL_PINT_IRQn, SENSOR_IRQ_PRIORITY);
- Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT_PORT, ACCEL_INT_PIN);
+ hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT_PORT, ACCEL_INT_PIN);
+ gpio_dir(&hostifIrq,PIN_INPUT);
- Chip_INMUX_PinIntSel(ACCEL_PINT_SEL, ACCEL_INT_PORT, ACCEL_INT_PIN);
+ gpioIrq.irq_index = ACCEL_PINT_CH;
+ gpioIrq.event = IRQ_EDGE_RISE;
+ gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(ACCEL_INT_PORT, ACCEL_INT_PIN), NULL, ACCEL_PINT_SEL);
-
- Chip_PININT_SetPinModeEdge(LPC_PININT, ACCEL_PINT_CH); /* edge sensitive and rising edge interrupt */
- Chip_PININT_EnableIntHigh(LPC_PININT, ACCEL_PINT_CH);
-
- //Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT2_PORT, ACCEL_INT2_PIN);
+ hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT2_PORT, ACCEL_INT2_PIN);
+ gpio_dir(&hostifIrq,PIN_INPUT);
Chip_SYSCON_EnableWakeup(ACCEL_WAKE); /* enable to wake from sleep */
- //Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
-
+ //gpio_irq_disable(&gpioIrq);
}
void Accel_Initialize(AccelInitOption option)
@@ -221,7 +223,9 @@ void Accel_ReadData(MsgAccelData *accelData )
void ACCEL_IRQHandler(void)
{
+ gpio_irq_t gpioIrq;
uint32_t currTime = GetCurrentTime();
+ gpioIrq.irq_index = ACCEL_PINT_CH;
#if 0
uint32_t currTime = g_Timer.GetCurrent();
PhysicalSensor_t* pSens = g_phySensors[PHYS_ACCEL_ID];
@@ -230,10 +234,10 @@ void ACCEL_IRQHandler(void)
pSens->irq_pending++;
- Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
+ gpio_irq_disable(&gpioIrq);
ResMgr_IRQDone();
#else
- Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
+ gpio_irq_disable(&gpioIrq);
SendDataReadyIndication(ACCEL_INPUT_SENSOR, currTime);
#endif
}
diff --git a/embedded/common/modules/sensor-drivers/bmm050.c b/embedded/common/modules/sensor-drivers/bmm050.c
index 3c28a3c..c8e377a 100644
--- a/embedded/common/modules/sensor-drivers/bmm050.c
+++ b/embedded/common/modules/sensor-drivers/bmm050.c
@@ -93,7 +93,8 @@
#include "mag_common.h"
#include "osp-sensors.h"
#include "sensacq_i2c.h"
-#include "board.h"
+#include "gpio_api.h"
+#include "gpio_irq_api.h"
static struct bmm050 *p_bmm050;
static struct bmm050 bmm050;
@@ -126,18 +127,23 @@ static void mag_activate(bool enable)
void Mag_HardwareSetup(osp_bool_t enable)
{
+ gpio_t hostifIrq;
+ gpio_irq_t gpioIrq;
NVIC_SetPriority(MAG_PINT_IRQn, SENSOR_IRQ_PRIORITY);
NVIC_DisableIRQ(MAG_PINT_IRQn);
/* MAG INT2 irq setup */
- Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT_PORT, MAG_INT_PIN);
- Chip_INMUX_PinIntSel(MAG_PINT_SEL, MAG_INT_PORT, MAG_INT_PIN); /* Configure INMUX block */
- Chip_PININT_SetPinModeEdge(LPC_PININT, MAG_PINT_CH);/* edge sensitive and rising edge interrupt */
- Chip_PININT_EnableIntHigh(LPC_PININT, MAG_PINT_CH);
+ hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT_PORT, MAG_INT_PIN);
+ gpio_dir(&hostifIrq,PIN_INPUT);
+ gpioIrq.irq_index = MAG_PINT_CH;
+ gpioIrq.event = IRQ_EDGE_RISE;
+ gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(MAG_INT_PORT, MAG_INT_PIN), NULL, MAG_PINT_SEL);
+
Chip_SYSCON_EnableWakeup(MAG_WAKE); /* enable to wake from sleep */
Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); /* enable to wake from sleep */
- Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT3_PORT, MAG_INT3_PIN);
+ hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT3_PORT, MAG_INT3_PIN);
+ gpio_dir(&hostifIrq,PIN_INPUT);
}
@@ -222,7 +228,9 @@ void Mag_ReadData(MsgMagData *magData)
}
void MAG_IRQHandler(void)
{
+ gpio_irq_t gpioIrq;
uint32_t currTime = GetCurrentTime();
+ gpioIrq.irq_index = MAG_PINT_CH;
#if 0
uint32_t currTime = g_Timer.GetCurrent();
PhysicalSensor_t* pSens = g_phySensors[PHYS_MAG_ID];
@@ -230,10 +238,10 @@ void MAG_IRQHandler(void)
pSens->ts_lastSample = currTime;
pSens->irq_pending++;
- Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH);
+ gpio_irq_disable(&gpioIrq);
ResMgr_IRQDone();
#else
- Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH);
+ gpio_irq_disable(&gpioIrq);
SendDataReadyIndication(MAG_INPUT_SENSOR, currTime);
#endif
}
diff --git a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx
index d17778c..302b7d2 100644
--- a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx
+++ b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx
@@ -726,6 +726,53 @@
+
+ TARGET_LPC54102
+ 0
+ 0
+ 0
+ 0
+
+ 10
+ 36
+ 1
+ 0
+ 0
+ 0
+ 0
+ ..\..\..\..\targets\TARGET_LPC54102\gpio_api.c
+ gpio_api.c
+ 0
+ 0
+
+
+ 10
+ 37
+ 1
+ 0
+ 0
+ 0
+ 0
+ ..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c
+ gpio_irq_api.c
+ 0
+ 0
+
+
+ 10
+ 38
+ 1
+ 0
+ 0
+ 0
+ 0
+ ..\..\..\..\targets\TARGET_LPC54102\pinmap.c
+ pinmap.c
+ 0
+ 0
+
+
+
::CMSIS
0
diff --git a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx
index ab37608..a25d0be 100644
--- a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx
+++ b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx
@@ -365,7 +365,7 @@
INTERNAL_FLASH,BOARD_NXP_LPCXPRESS0_54102,PWRROMD_PRESENT,__FPU_PRESENT=1,CORE_M4,ANDROID_DEMO,DEBUG_BUILD,DEBUG_OUTPUT,ASF_PROFILING,ON_DEMAND_PROFILING
- ..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\common\modules\sensor-drivers;..\..\..\common\modules\bus-drivers;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\sources\lpcopen\software\lpc_core\lpc_board\boards_5410x\lpcxpresso_54102;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_common;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x\config;..\sources\lpcopen\software\lpc_core\lpc_board\board_common;..\sources\HostInterface;c:\keil_v5\arm\rv31\inc
+ ..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\common\modules\sensor-drivers;..\..\..\common\modules\bus-drivers;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\sources\lpcopen\software\lpc_core\lpc_board\boards_5410x\lpcxpresso_54102;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_common;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x\config;..\sources\lpcopen\software\lpc_core\lpc_board\board_common;..\sources\HostInterface;..\..\..\..\include\hal;..\..\..\..\targets\TARGET_LPC54102
@@ -1025,6 +1025,26 @@
+
+ TARGET_LPC54102
+
+
+ gpio_api.c
+ 1
+ ..\..\..\..\targets\TARGET_LPC54102\gpio_api.c
+
+
+ gpio_irq_api.c
+ 1
+ ..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c
+
+
+ pinmap.c
+ 1
+ ..\..\..\..\targets\TARGET_LPC54102\pinmap.c
+
+
+
::CMSIS
diff --git a/embedded/projects/osp-lpc54102/sources/app/hostif.h b/embedded/projects/osp-lpc54102/sources/app/hostif.h
index c6d7b85..fd0bbb9 100644
--- a/embedded/projects/osp-lpc54102/sources/app/hostif.h
+++ b/embedded/projects/osp-lpc54102/sources/app/hostif.h
@@ -33,11 +33,14 @@
#define _HOSTIF_H_
#include "spi-sensor-hub-priv.h"
+#include "gpio_api.h"
#ifdef __cplusplus
extern "C" {
#endif
+extern gpio_t hostifIrq;
+
/** @defgroup SH_HOSTIF : Sensor hub host interface
* @ingroup SENSOR_HUB
* @{
@@ -65,7 +68,7 @@ void Hostif_StartTx(uint8_t *pBuf, uint16_t size, int magic);
*/
static INLINE void Hostif_AssertIRQ(void)
{
- Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 0);
+ gpio_write(&hostifIrq,0);
}
/**
@@ -74,7 +77,7 @@ static INLINE void Hostif_AssertIRQ(void)
*/
static INLINE void Hostif_DeassertIRQ(void)
{
- Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1);
+ gpio_write(&hostifIrq,1);
}
/**
@@ -83,7 +86,7 @@ static INLINE void Hostif_DeassertIRQ(void)
*/
static INLINE bool Hostif_IRQActive(void)
{
- return (Chip_GPIO_GetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN) == false);
+ return (gpio_read(&hostifIrq) == false);
}
/**
diff --git a/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c b/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c
index 9a9ac22..4570815 100644
--- a/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c
+++ b/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c
@@ -28,13 +28,13 @@
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/
-#include "board.h"
#include
#include
#include "sensorhub.h"
#include "hostif.h"
#include "osp-types.h"
#include "common.h"
+#include "pinmap.h"
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
@@ -56,6 +56,9 @@ typedef struct __HOSTIF_Ctrl_t {
uint16_t txLength_next;
} Hostif_Ctrl_t;
+/* Host Interface Pin. Making it global since it is used in multiple places */
+gpio_t hostifIrq = {ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN)};
+
static Hostif_Ctrl_t g_hostif;
#define I2C_MEM_SZ 64 /* Size of memory for I2C Slave ROM driver */
@@ -275,8 +278,8 @@ void Hostif_Init(void)
memset(&g_hostif, 0, sizeof(Hostif_Ctrl_t));
/* Setup I2C pin mux */
- Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 27, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* i2c2 */
- Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 28, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* I2C2 */
+ pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_27), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN));
+ pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_28), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN));
Chip_Clock_EnablePeriphClock(I2C_HOSTIF_CLK);
Chip_SYSCON_PeriphReset(I2C_HOSTIF_RST);
@@ -320,12 +323,12 @@ void Hostif_Init(void)
ROM_I2CS_Transfer(hI2C, &i2cXfer);
/* init host interrupt pin */
- Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN);
-
+ gpio_dir(&hostifIrq,PIN_OUTPUT);
+
/* de-assert interrupt line to high to indicate Host/AP that
* there is no data to receive
*/
- Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1);
+ gpio_write(&hostifIrq,1);
/* Enable the interrupt for the I2C */
NVIC_SetPriority(I2C_HOSTIF_IRQn, HOSTIF_IRQ_PRIORITY);
diff --git a/embedded/projects/osp-lpc54102/sources/app/main.c b/embedded/projects/osp-lpc54102/sources/app/main.c
index 477e06d..1cb122e 100644
--- a/embedded/projects/osp-lpc54102/sources/app/main.c
+++ b/embedded/projects/osp-lpc54102/sources/app/main.c
@@ -18,13 +18,14 @@
/*---------------------------------------------------------------------*\
| I N C L U D E F I L E S
\*---------------------------------------------------------------------*/
-#include "board.h"
#include "common.h"
#include "hw_setup.h"
#include "sensorhub.h"
#include
#include "romapi_uart.h"
-
+#include "gpio_api.h"
+#include "pinmap.h"
+#include "hostif.h"
/*---------------------------------------------------------------------*\
| E X T E R N A L V A R I A B L E S & F U N C T I O N S
@@ -99,9 +100,9 @@ static void UART_PinMuxSetup(void)
{
#if defined(BOARD_NXP_LPCXPRESSO_54102)
/* Setup UART TX Pin */
- Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 0, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN));
+ pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_0), (PINMAP_FUNC1 | PINMAP_MODE_INACT | PINMAP_DIGITAL_EN));
/* Setup UART RX Pin */
- Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 1, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN));
+ pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_1), (PINMAP_FUNC1 | PINMAP_MODE_INACT | PINMAP_DIGITAL_EN));
Chip_SYSCON_Enable_ASYNC_Syscon(true); /* Enable Async APB */
Chip_Clock_SetAsyncSysconClockDiv(1); /* Set Async clock divider to 1 */
#else
@@ -744,11 +745,11 @@ int main(void)
Board_LED_Set(2, false);
/* Initialize GPIO pin interrupt module */
- Chip_PININT_Init(LPC_PININT);
+ gpio_init((gpio_t *)NULL,(PinName)NULL);
wdt_init();
- Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN);
+ gpio_dir(&hostifIrq,PIN_OUTPUT);
// Use the same setting in the bosch example. Restore to Audience setting later when able to run on the new board
setupClocking();
diff --git a/include/hal/gpio_api.h b/include/hal/gpio_api.h
new file mode 100644
index 0000000..e770369
--- /dev/null
+++ b/include/hal/gpio_api.h
@@ -0,0 +1,60 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef GPIO_API_H
+#define GPIO_API_H
+
+#include "common.h"
+#include "PinNames.h"
+#include "Gpio_object.h"
+#include "port_api.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Set the given pin as GPIO
+ * @param pin The pin to be set as GPIO
+ * @return The GPIO port mask for this pin
+ **/
+uint32_t gpio_set(PinName pin);
+
+/* Checks if gpio object is connected (pin was not initialized with NC)
+ * @param pin The pin to be set as GPIO
+ * @return 0 if port is initialized with NC
+ **/
+int gpio_is_connected(const gpio_t *obj);
+
+/* GPIO object */
+void gpio_init(gpio_t *obj, PinName pin);
+
+void gpio_mode (gpio_t *obj, PinMode mode);
+void gpio_dir (gpio_t *obj, PinDirection direction);
+
+void gpio_write(gpio_t *obj, int value);
+int gpio_read (gpio_t *obj);
+
+// the following set of functions are generic and are implemented in the common gpio.c file
+void gpio_init_in(gpio_t* gpio, PinName pin);
+void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode);
+void gpio_init_out(gpio_t* gpio, PinName pin);
+void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value);
+void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/hal/gpio_irq_api.h b/include/hal/gpio_irq_api.h
new file mode 100644
index 0000000..bda4789
--- /dev/null
+++ b/include/hal/gpio_irq_api.h
@@ -0,0 +1,53 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef GPIO_IRQ_API_H
+#define GPIO_IRQ_API_H
+
+#include "common.h"
+#include "PinNames.h"
+#include "Objects.h"
+#include "device.h"
+
+#if DEVICE_INTERRUPTIN
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ IRQ_EDGE_RISE,
+ IRQ_EDGE_FALL,
+ IRQ_LEVEL_HIGH,
+ IRQ_LEVEL_LOW
+} gpio_irq_event;
+
+typedef struct gpio_irq_s gpio_irq_t;
+
+typedef void (*gpio_irq_handler)(uint32_t id, gpio_irq_event event);
+
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id);
+void gpio_irq_free(gpio_irq_t *obj);
+void gpio_irq_set (gpio_irq_t *obj, gpio_irq_event event, uint32_t enable);
+void gpio_irq_enable(gpio_irq_t *obj);
+void gpio_irq_disable(gpio_irq_t *obj);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif
diff --git a/include/hal/pinmap.h b/include/hal/pinmap.h
new file mode 100644
index 0000000..db2088f
--- /dev/null
+++ b/include/hal/pinmap.h
@@ -0,0 +1,43 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef PINMAP_H
+#define PINMAP_H
+
+#include "PinNames.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ PinName pin;
+ int peripheral;
+ int function;
+} PinMap;
+
+void pin_function(PinName pin, uint32_t function);
+void pin_mode (PinName pin, PinMode mode);
+
+uint32_t pinmap_peripheral(PinName pin, const PinMap* map);
+uint32_t pinmap_merge (uint32_t a, uint32_t b);
+void pinmap_pinout (PinName pin, const PinMap *map);
+uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/hal/port_api.h b/include/hal/port_api.h
new file mode 100644
index 0000000..b0ae6df
--- /dev/null
+++ b/include/hal/port_api.h
@@ -0,0 +1,42 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef PORTMAP_H
+#define PORTMAP_H
+
+#include "common.h"
+
+#if DEVICE_PORTIN || DEVICE_PORTOUT
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct port_s port_t;
+
+PinName port_pin(PortName port, int pin_n);
+
+void port_init (port_t *obj, PortName port, int mask, PinDirection dir);
+void port_mode (port_t *obj, PinMode mode);
+void port_dir (port_t *obj, PinDirection dir);
+void port_write(port_t *obj, int value);
+int port_read (port_t *obj);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+#endif
diff --git a/targets/TARGET_LPC54102/PinNames.h b/targets/TARGET_LPC54102/PinNames.h
new file mode 100644
index 0000000..17c5d76
--- /dev/null
+++ b/targets/TARGET_LPC54102/PinNames.h
@@ -0,0 +1,147 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#ifndef PINNAMES_H
+#define PINNAMES_H
+
+#include "common.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// MODE (see GPIOMode_TypeDef structure)
+// AFNUM (see AF_mapping constant table)
+#define ENCODE_PIN_DATA(MODE, AFNUM) (((MODE) << 8) | (AFNUM))
+#define DECODE_PIN_MODE(X) ((X) >> 8)
+#define DECODE_PIN_AFNUM(X) ((X) & 0xFF)
+
+// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
+// Low nibble = pin number
+#define ENCODE_PORT_PIN(port,pin) (PinName)(((uint32_t)port << 16) + (uint16_t)pin)
+#define DECODE_PORT(X) (((uint32_t)(X) >> 16) & 0xF)
+#define DECODE_PIN(X) ((uint32_t)(X) & 0xFFFF)
+
+typedef enum {
+ PIN_INPUT,
+ PIN_OUTPUT
+} PinDirection;
+
+typedef enum {
+ Pin_0 = 0x00,
+ Pin_1 = 0x01,
+ Pin_2 = 0x02,
+ Pin_3 = 0x03,
+ Pin_4 = 0x04,
+ Pin_5 = 0x05,
+ Pin_6 = 0x06,
+ Pin_7 = 0x07,
+ Pin_8 = 0x08,
+ Pin_9 = 0x09,
+ Pin_10 = 0x0A,
+ Pin_11 = 0x0B,
+ Pin_12 = 0x0C,
+ Pin_13 = 0x0D,
+ Pin_14 = 0x0E,
+ Pin_15 = 0x0F,
+ Pin_16 = 0x10,
+ Pin_17 = 0x11,
+ Pin_18 = 0x12,
+ Pin_19 = 0x13,
+ Pin_20 = 0x14,
+ Pin_21 = 0x15,
+ Pin_22 = 0x16,
+ Pin_23 = 0x17,
+ Pin_24 = 0x18,
+ Pin_25 = 0x19,
+ Pin_26 = 0x1A,
+ Pin_27 = 0x1B,
+ Pin_28 = 0x1C,
+ Pin_29 = 0x1D,
+ Pin_30 = 0x1E,
+ Pin_31 = 0x1F,
+ Pin_All= 0xFFFF
+} PinNumber;
+
+typedef enum {
+ Port_0 = 0x00,
+ Port_1 = 0x01,
+ Port_2 = 0x02,
+ Port_3 = 0x03,
+ Port_4 = 0x04,
+ Port_5 = 0x05,
+ Port_6 = 0x06,
+ Port_7 = 0x07,
+ Port_All= 0xFFFF
+} PortNumber;
+
+#define NC (uint32_t)0xFFFFFFFF
+typedef uint32_t PinName;
+
+/**
+ * PIN function and mode selection definitions
+ * Might need to be changed while porting to different platform
+ */
+typedef int32_t PinMode;
+
+typedef enum {
+ PINMAP_FUNC0 = 0x0, /*!< Selects pin function 0 */
+ PINMAP_FUNC1 = 0x1, /*!< Selects pin function 1 */
+ PINMAP_FUNC2 = 0x2, /*!< Selects pin function 2 */
+ PINMAP_FUNC3 = 0x3, /*!< Selects pin function 3 */
+ PINMAP_FUNC4 = 0x4, /*!< Selects pin function 4 */
+ PINMAP_FUNC5 = 0x5, /*!< Selects pin function 5 */
+ PINMAP_FUNC6 = 0x6, /*!< Selects pin function 6 */
+ PINMAP_FUNC7 = 0x7 /*!< Selects pin function 7 */
+} PINMAP_FUNC;
+
+typedef enum{
+ PINMAP_MODE_INACT = (0x0 << 3), /*!< No addition pin function */
+ PINMAP_MODE_PULLDOWN = (0x1 << 3), /*!< Selects pull-down function */
+ PINMAP_MODE_PULLUP = (0x2 << 3), /*!< Selects pull-up function */
+ PINMAP_MODE_REPEATER = (0x3 << 3) /*!< Selects pin repeater function */
+} PINMAP_MODE;
+
+#define PINMAP_HYS_EN (0x1 << 5) /*!< Enables hysteresis */
+#define PINMAP_GPIO_MODE (0x1 << 5) /*!< GPIO Mode */
+#define PINMAP_I2C_SLEW (0x1 << 5) /*!< I2C Slew Rate Control */
+#define PINMAP_INV_EN (0x1 << 6) /*!< Enables invert function on input */
+#define PINMAP_ANALOG_EN (0x0 << 7) /*!< Enables analog function by setting 0 to bit 7 */
+#define PINMAP_DIGITAL_EN (0x1 << 7) /*!< Enables digital function by setting 1 to bit 7(default) */
+#define PINMAP_STDI2C_EN (0x1 << 8) /*!< I2C standard mode/fast-mode */
+#define PINMAP_FASTI2C_EN (0x3 << 8) /*!< I2C Fast-mode Plus and high-speed slave */
+#define PINMAP_INPFILT_OFF (0x1 << 8) /*!< Input filter Off for GPIO pins */
+#define PINMAP_INPFILT_ON (0x0 << 8) /*!< Input filter On for GPIO pins */
+#define PINMAP_OPENDRAIN_EN (0x1 << 10) /*!< Enables open-drain function */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/targets/TARGET_LPC54102/PortNames.h b/targets/TARGET_LPC54102/PortNames.h
new file mode 100644
index 0000000..27b668f
--- /dev/null
+++ b/targets/TARGET_LPC54102/PortNames.h
@@ -0,0 +1,48 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#ifndef PORTNAMES_H
+#define PORTNAMES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ PortA = 0,
+ PortB = 1,
+ PortC = 2,
+ PortD = 3,
+ PortE = 4
+} PortName;
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/targets/TARGET_LPC54102/device.h b/targets/TARGET_LPC54102/device.h
new file mode 100644
index 0000000..c411d65
--- /dev/null
+++ b/targets/TARGET_LPC54102/device.h
@@ -0,0 +1,71 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#ifndef DEVICE_H
+#define DEVICE_H
+
+#define DEVICE_PORTIN 1
+#define DEVICE_PORTOUT 1
+#define DEVICE_PORTINOUT 1
+
+#define DEVICE_INTERRUPTIN 1
+
+#define DEVICE_ANALOGIN 1
+#define DEVICE_ANALOGOUT 0
+
+#define DEVICE_SERIAL 1
+
+#define DEVICE_I2C 1
+#define DEVICE_I2CSLAVE 0
+
+#define DEVICE_SPI 1
+#define DEVICE_SPISLAVE 0
+
+#define DEVICE_RTC 1
+
+#define DEVICE_PWMOUT 1
+
+#define DEVICE_SLEEP 1
+
+#define DEVICE_ERROR_PATTERN 1 //fast blink green and blue leds on error
+//=======================================
+
+#define DEVICE_SEMIHOST 0
+#define DEVICE_LOCALFILESYSTEM 0
+#define DEVICE_ID_LENGTH 24
+
+#define DEVICE_DEBUG_AWARENESS 0
+
+#define DEVICE_STDIO_MESSAGES 1
+
+//#define DEVICE_ERROR_RED 0
+
+#include "objects.h"
+
+#endif
diff --git a/targets/TARGET_LPC54102/gpio_api.c b/targets/TARGET_LPC54102/gpio_api.c
new file mode 100644
index 0000000..f6c0fa3
--- /dev/null
+++ b/targets/TARGET_LPC54102/gpio_api.c
@@ -0,0 +1,47 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#include "gpio_api.h"
+#include "pinmap.h"
+#include "Gpio_object.h"
+
+void gpio_init(gpio_t __attribute__((unused)) *obj, PinName __attribute__((unused)) pin) {
+ Chip_PININT_Init(LPC_PININT);
+}
+
+void gpio_dir(gpio_t *obj, PinDirection direction) {
+ ASF_assert(obj != NULL);
+ ASF_assert(obj->pin != (PinName)NC);
+ if (direction == PIN_OUTPUT) {
+ Chip_GPIO_SetPinDIROutput(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin));
+ }
+ else { // PIN_INPUT
+ Chip_GPIO_SetPinDIRInput(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin));
+ }
+}
diff --git a/targets/TARGET_LPC54102/gpio_irq_api.c b/targets/TARGET_LPC54102/gpio_irq_api.c
new file mode 100644
index 0000000..eff7018
--- /dev/null
+++ b/targets/TARGET_LPC54102/gpio_irq_api.c
@@ -0,0 +1,71 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#include
+#include "common.h"
+
+#include "gpio_irq_api.h"
+#include "pinmap.h"
+
+
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
+
+ ASF_assert(pin != NC);
+ Chip_INMUX_PinIntSel(id, DECODE_PORT(pin), DECODE_PIN(pin));
+ gpio_irq_enable(obj);
+ return 0;
+}
+
+void gpio_irq_enable(gpio_irq_t *obj) {
+ switch(obj->event){
+ case IRQ_EDGE_RISE:
+ Chip_PININT_SetPinModeEdge(LPC_PININT, obj->irq_index); /* edge sensitive */
+ Chip_PININT_EnableIntHigh(LPC_PININT, obj->irq_index); /* Rising edge interrupt */
+ break;
+ case IRQ_EDGE_FALL:
+ Chip_PININT_SetPinModeEdge(LPC_PININT, obj->irq_index); /* Edge sensitive */
+ Chip_PININT_EnableIntLow(LPC_PININT, obj->irq_index); /* Falling edge interrupt */
+ break;
+ case IRQ_LEVEL_HIGH:
+ Chip_PININT_SetPinModeLevel(LPC_PININT, obj->irq_index); /* Level sensitive */
+ Chip_PININT_EnableIntHigh(LPC_PININT, obj->irq_index); /* High level interrupt */
+ break;
+ case IRQ_LEVEL_LOW:
+ Chip_PININT_SetPinModeLevel(LPC_PININT, obj->irq_index); /* Level sensitive */
+ Chip_PININT_EnableIntLow(LPC_PININT, obj->irq_index); /* Low level interrupt */
+ break;
+ default:
+ D1_printf("GPIO_IRQ_ENABLE: Bad IRQ Mode: %d\r\n", obj->irq_index);
+ while(1){};
+ }
+}
+
+void gpio_irq_disable(gpio_irq_t *obj) {
+ Chip_PININT_ClearIntStatus(LPC_PININT, obj->irq_index);
+}
diff --git a/targets/TARGET_LPC54102/gpio_object.h b/targets/TARGET_LPC54102/gpio_object.h
new file mode 100644
index 0000000..6b2358d
--- /dev/null
+++ b/targets/TARGET_LPC54102/gpio_object.h
@@ -0,0 +1,68 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#ifndef GPIO_OBJECT_H
+#define GPIO_OBJECT_H
+
+#include "common.h"
+#include "PortNames.h"
+#include "PinNames.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ PinName pin;
+ uint32_t mask;
+ __IO uint32_t *reg_in;
+ __IO uint32_t *reg_set;
+ __IO uint32_t *reg_clr;
+} gpio_t;
+
+static __inline void gpio_write(gpio_t *obj, int value) {
+ ASF_assert(obj->pin != (PinName)NC);
+ Chip_GPIO_SetPinState(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin), (bool)value);
+}
+
+static __inline int gpio_read(gpio_t *obj) {
+ ASF_assert(obj->pin != (PinName)NC);
+ return (Chip_GPIO_GetPinState(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin)));
+}
+
+static __inline int gpio_is_connected(const gpio_t *obj) {
+ //return obj->pin != (PinName)NC;
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/targets/TARGET_LPC54102/objects.h b/targets/TARGET_LPC54102/objects.h
new file mode 100644
index 0000000..1a511c4
--- /dev/null
+++ b/targets/TARGET_LPC54102/objects.h
@@ -0,0 +1,98 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#ifndef OBJECTS_H
+#define OBJECTS_H
+
+#include "common.h"
+#include "PortNames.h"
+//#include "PeripheralNames.h"
+#include "PinNames.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct gpio_irq_s {
+ IRQn_Type irq_n;
+ uint32_t irq_index;
+ uint32_t event;
+};
+
+struct port_s {
+ PortName port;
+ uint32_t mask;
+ PinDirection direction;
+ __IO uint32_t *reg_in;
+ __IO uint32_t *reg_out;
+};
+
+struct analogin_s {
+// ADCName adc;
+ PinName pin;
+};
+
+struct serial_s {
+// UARTName uart;
+ int index; // Used by irq
+ uint32_t baudrate;
+ uint32_t databits;
+ uint32_t stopbits;
+ uint32_t parity;
+};
+
+struct spi_s {
+// SPIName spi;
+ uint32_t bits;
+ uint32_t cpol;
+ uint32_t cpha;
+ uint32_t mode;
+ uint32_t nss;
+ uint32_t br_presc;
+};
+
+struct i2c_s {
+// I2CName i2c;
+ uint32_t i2c; //TBD: DUMMY - Please remove
+};
+
+struct pwmout_s {
+// PWMName pwm;
+ PinName pin;
+ uint32_t period;
+ uint32_t pulse;
+};
+
+#include "gpio_object.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/targets/TARGET_LPC54102/pinmap.c b/targets/TARGET_LPC54102/pinmap.c
new file mode 100644
index 0000000..f09b4b4
--- /dev/null
+++ b/targets/TARGET_LPC54102/pinmap.c
@@ -0,0 +1,144 @@
+/* mbed Microcontroller Library
+ *******************************************************************************
+ * Copyright (c) 2014, STMicroelectronics
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *******************************************************************************
+ */
+#include "device.h"
+#include "pinmap.h"
+
+// Alternate-function mapping
+#if 0
+static const uint32_t AF_mapping[] = {
+ 0, // 0 = No AF
+ GPIO_Remap_SPI1, // 1
+ GPIO_Remap_I2C1, // 2
+ GPIO_Remap_USART1, // 3
+ GPIO_Remap_USART2, // 4
+ GPIO_FullRemap_TIM2, // 5
+ GPIO_FullRemap_TIM3, // 6
+ GPIO_PartialRemap_TIM3, // 7
+ GPIO_Remap_I2C1 // 8
+};
+#endif
+
+// Enable GPIO clock and return GPIO base address
+uint32_t Set_GPIO_Clock(uint32_t port_idx) {
+#if 0
+ uint32_t gpio_add = 0;
+ switch (port_idx) {
+ case PortA:
+ gpio_add = GPIOA_BASE;
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
+ break;
+ case PortB:
+ gpio_add = GPIOB_BASE;
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
+ break;
+ case PortC:
+ gpio_add = GPIOC_BASE;
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
+ break;
+ case PortD:
+ gpio_add = GPIOD_BASE;
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
+ break;
+ default:
+ D1_printf("Port number is not correct.");
+ break;
+ }
+ return gpio_add;
+#endif
+ return 0;
+}
+
+/**
+ * Configure pin (input, output, alternate function or analog) + output speed + AF
+ */
+void pin_function(PinName pin, uint32_t data) {
+
+ uint32_t port_index = DECODE_PORT(pin);
+ uint32_t pin_index = DECODE_PIN(pin);
+
+ ASF_assert(pin != (PinName)NC);
+
+ // Configure GPIO
+ Chip_IOCON_PinMuxSet(LPC_IOCON, port_index, pin_index, data);
+}
+
+/**
+ * Configure pin pull-up/pull-down
+ */
+void pin_mode(PinName pin, PinMode mode) {
+#if 0
+ ASF_assert(pin != (PinName)NC);
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ uint32_t port_index = STM_PORT(pin);
+ uint32_t pin_index = STM_PIN(pin);
+
+ // Enable GPIO clock
+ uint32_t gpio_add = Set_GPIO_Clock(port_index);
+ GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
+
+ // Configure open-drain and pull-up/down
+ switch (mode) {
+ case AnalogInput:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
+ break;
+ case Floating:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ break;
+ case PullUp:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+ break;
+ case PullDown:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
+ break;
+ case OpenDrain:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ break;
+ case PushPullOutput:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ break;
+ case OpenDrainOutputAF:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
+ break;
+ case PushPullOutputAF:
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ break;
+ default:
+ D1_printf("PINMAP: Bad GPIO Mode: %d\r\n", mode);
+ break;
+ }
+
+ // Configure GPIO
+ GPIO_InitStructure.GPIO_Pin = (uint16_t)pin_index;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(gpio, &GPIO_InitStructure);
+#endif
+}
+