Skip to content

Commit dc79093

Browse files
committed
Implementing GPIO and PINMAP HAL:
Added GPIO, PINMAP and other related HAL Files to the project Implemented GPIO and PINMAP HAL APIs Modified existing code to call the HAL APIs instead of Driver APIs Note: CHIP_SYSCON APIs are not abstracted as part of this commit since mbed HAL does not have corresponding APIs. Discussion pending. Signed-off-by: Pankaj Goenka <pgoenka@audience.com>
1 parent 05446a9 commit dc79093

20 files changed

Lines changed: 1027 additions & 43 deletions

File tree

embedded/common/modules/sensor-drivers/BMG160.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@
8989
#include "bmg160.h"
9090
#include "sensorhub.h"
9191
#include "common.h"
92-
#include "board.h"
9392
#include "gyro_common.h"
9493
#include "osp-sensors.h"
9594
#include "sensacq_i2c.h"
95+
#include "gpio_api.h"
96+
#include "gpio_irq_api.h"
9697

9798
static struct bmg160_t *p_bmg160 = NULL;
9899
static struct bmg160_t bmg160;
@@ -137,12 +138,15 @@ static void gyro_activate(bool enable)
137138

138139
void Gyro_HardwareSetup(osp_bool_t enable)
139140
{
141+
gpio_t hostifIrq;
142+
gpio_irq_t gpioIrq;
140143
NVIC_DisableIRQ(GYRO_PINT_IRQn);
141144
NVIC_SetPriority(GYRO_PINT_IRQn, SENSOR_IRQ_PRIORITY);
142-
Chip_GPIO_SetPinDIRInput(LPC_GPIO, GYRO_INT_PORT, GYRO_INT_PIN);
143-
Chip_INMUX_PinIntSel(GYRO_PINT_SEL,GYRO_INT_PORT, GYRO_INT_PIN);
144-
Chip_PININT_SetPinModeEdge(LPC_PININT, GYRO_PINT_CH);
145-
Chip_PININT_EnableIntHigh(LPC_PININT, GYRO_PINT_CH);
145+
hostifIrq.pin = ENCODE_PORT_PIN(GYRO_INT_PORT, GYRO_INT_PIN);
146+
gpio_dir(&hostifIrq,PIN_INPUT);
147+
gpioIrq.irq_index = GYRO_PINT_CH;
148+
gpioIrq.event = IRQ_EDGE_RISE;
149+
gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(GYRO_INT_PORT, GYRO_INT_PIN), NULL, GYRO_PINT_SEL);
146150
Chip_SYSCON_EnableWakeup(GYRO_WAKE);
147151
}
148152

@@ -228,18 +232,20 @@ void Gyro_ReadData(MsgGyroData *gyroData)
228232

229233
void GYRO_IRQHandler(void)
230234
{
235+
gpio_irq_t gpioIrq;
231236
uint32_t currTime = GetCurrentTime();
237+
gpioIrq.irq_index = GYRO_PINT_CH;
232238
#if 0
233239
PhysicalSensor_t* pSens = g_phySensors[PHYS_GYRO_ID];
234240
uint32_t currTime = g_Timer.GetCurrent();
235241
pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ;
236242
pSens->ts_lastSample = currTime;
237243

238244
pSens->irq_pending++;
239-
Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH);
245+
gpio_irq_disable(&gpioIrq);
240246
ResMgr_IRQDone();
241247
#else
242-
Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH);
248+
gpio_irq_disable(&gpioIrq);
243249
SendDataReadyIndication(GYRO_INPUT_SENSOR, currTime);
244250
#endif
245251
}

embedded/common/modules/sensor-drivers/bma2x2.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@
8080
#include "sensorhub.h"
8181
#include "common.h"
8282
#include "acc_common.h"
83-
#include "board.h"
8483
#include "osp-sensors.h"
8584
#include "sensacq_i2c.h"
85+
#include "gpio_api.h"
86+
#include "gpio_irq_api.h"
8687

8788
/* user defined code to be added here ... */
8889
static bma2x2_t *p_bma2x2;
@@ -122,23 +123,24 @@ static void accel_activate(bool enable)
122123
}
123124
void Accel_HardwareSetup(osp_bool_t enable)
124125
{
126+
gpio_t hostifIrq;
127+
gpio_irq_t gpioIrq;
125128
/* ACCEL INT1 irq setup */
126129
NVIC_DisableIRQ(ACCEL_PINT_IRQn);
127130
NVIC_SetPriority(ACCEL_PINT_IRQn, SENSOR_IRQ_PRIORITY);
128-
Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT_PORT, ACCEL_INT_PIN);
131+
hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT_PORT, ACCEL_INT_PIN);
132+
gpio_dir(&hostifIrq,PIN_INPUT);
129133

130-
Chip_INMUX_PinIntSel(ACCEL_PINT_SEL, ACCEL_INT_PORT, ACCEL_INT_PIN);
134+
gpioIrq.irq_index = ACCEL_PINT_CH;
135+
gpioIrq.event = IRQ_EDGE_RISE;
136+
gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(ACCEL_INT_PORT, ACCEL_INT_PIN), NULL, ACCEL_PINT_SEL);
131137

132-
133-
Chip_PININT_SetPinModeEdge(LPC_PININT, ACCEL_PINT_CH); /* edge sensitive and rising edge interrupt */
134-
Chip_PININT_EnableIntHigh(LPC_PININT, ACCEL_PINT_CH);
135-
136-
//Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT2_PORT, ACCEL_INT2_PIN);
138+
hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT2_PORT, ACCEL_INT2_PIN);
139+
gpio_dir(&hostifIrq,PIN_INPUT);
137140

138141
Chip_SYSCON_EnableWakeup(ACCEL_WAKE); /* enable to wake from sleep */
139142

140-
//Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
141-
143+
//gpio_irq_disable(&gpioIrq);
142144

143145
}
144146
void Accel_Initialize(AccelInitOption option)
@@ -221,7 +223,9 @@ void Accel_ReadData(MsgAccelData *accelData )
221223

222224
void ACCEL_IRQHandler(void)
223225
{
226+
gpio_irq_t gpioIrq;
224227
uint32_t currTime = GetCurrentTime();
228+
gpioIrq.irq_index = ACCEL_PINT_CH;
225229
#if 0
226230
uint32_t currTime = g_Timer.GetCurrent();
227231
PhysicalSensor_t* pSens = g_phySensors[PHYS_ACCEL_ID];
@@ -230,10 +234,10 @@ void ACCEL_IRQHandler(void)
230234

231235
pSens->irq_pending++;
232236

233-
Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
237+
gpio_irq_disable(&gpioIrq);
234238
ResMgr_IRQDone();
235239
#else
236-
Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
240+
gpio_irq_disable(&gpioIrq);
237241
SendDataReadyIndication(ACCEL_INPUT_SENSOR, currTime);
238242
#endif
239243
}

embedded/common/modules/sensor-drivers/bmm050.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
#include "mag_common.h"
9494
#include "osp-sensors.h"
9595
#include "sensacq_i2c.h"
96-
#include "board.h"
96+
#include "gpio_api.h"
97+
#include "gpio_irq_api.h"
9798

9899
static struct bmm050 *p_bmm050;
99100
static struct bmm050 bmm050;
@@ -126,18 +127,23 @@ static void mag_activate(bool enable)
126127

127128
void Mag_HardwareSetup(osp_bool_t enable)
128129
{
130+
gpio_t hostifIrq;
131+
gpio_irq_t gpioIrq;
129132
NVIC_SetPriority(MAG_PINT_IRQn, SENSOR_IRQ_PRIORITY);
130133
NVIC_DisableIRQ(MAG_PINT_IRQn);
131134

132135
/* MAG INT2 irq setup */
133-
Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT_PORT, MAG_INT_PIN);
134-
Chip_INMUX_PinIntSel(MAG_PINT_SEL, MAG_INT_PORT, MAG_INT_PIN); /* Configure INMUX block */
135-
Chip_PININT_SetPinModeEdge(LPC_PININT, MAG_PINT_CH);/* edge sensitive and rising edge interrupt */
136-
Chip_PININT_EnableIntHigh(LPC_PININT, MAG_PINT_CH);
136+
hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT_PORT, MAG_INT_PIN);
137+
gpio_dir(&hostifIrq,PIN_INPUT);
138+
gpioIrq.irq_index = MAG_PINT_CH;
139+
gpioIrq.event = IRQ_EDGE_RISE;
140+
gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(MAG_INT_PORT, MAG_INT_PIN), NULL, MAG_PINT_SEL);
141+
137142
Chip_SYSCON_EnableWakeup(MAG_WAKE); /* enable to wake from sleep */
138143
Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); /* enable to wake from sleep */
139144

140-
Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT3_PORT, MAG_INT3_PIN);
145+
hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT3_PORT, MAG_INT3_PIN);
146+
gpio_dir(&hostifIrq,PIN_INPUT);
141147

142148
}
143149

@@ -222,18 +228,20 @@ void Mag_ReadData(MsgMagData *magData)
222228
}
223229
void MAG_IRQHandler(void)
224230
{
231+
gpio_irq_t gpioIrq;
225232
uint32_t currTime = GetCurrentTime();
233+
gpioIrq.irq_index = MAG_PINT_CH;
226234
#if 0
227235
uint32_t currTime = g_Timer.GetCurrent();
228236
PhysicalSensor_t* pSens = g_phySensors[PHYS_MAG_ID];
229237
pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ;
230238
pSens->ts_lastSample = currTime;
231239

232240
pSens->irq_pending++;
233-
Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH);
241+
gpio_irq_disable(&gpioIrq);
234242
ResMgr_IRQDone();
235243
#else
236-
Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH);
244+
gpio_irq_disable(&gpioIrq);
237245
SendDataReadyIndication(MAG_INPUT_SENSOR, currTime);
238246
#endif
239247
}

embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,53 @@
726726
</File>
727727
</Group>
728728

729+
<Group>
730+
<GroupName>TARGET_LPC54102</GroupName>
731+
<tvExp>0</tvExp>
732+
<tvExpOptDlg>0</tvExpOptDlg>
733+
<cbSel>0</cbSel>
734+
<RteFlg>0</RteFlg>
735+
<File>
736+
<GroupNumber>10</GroupNumber>
737+
<FileNumber>36</FileNumber>
738+
<FileType>1</FileType>
739+
<tvExp>0</tvExp>
740+
<Focus>0</Focus>
741+
<tvExpOptDlg>0</tvExpOptDlg>
742+
<bDave2>0</bDave2>
743+
<PathWithFileName>..\..\..\..\targets\TARGET_LPC54102\gpio_api.c</PathWithFileName>
744+
<FilenameWithoutPath>gpio_api.c</FilenameWithoutPath>
745+
<RteFlg>0</RteFlg>
746+
<bShared>0</bShared>
747+
</File>
748+
<File>
749+
<GroupNumber>10</GroupNumber>
750+
<FileNumber>37</FileNumber>
751+
<FileType>1</FileType>
752+
<tvExp>0</tvExp>
753+
<Focus>0</Focus>
754+
<tvExpOptDlg>0</tvExpOptDlg>
755+
<bDave2>0</bDave2>
756+
<PathWithFileName>..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c</PathWithFileName>
757+
<FilenameWithoutPath>gpio_irq_api.c</FilenameWithoutPath>
758+
<RteFlg>0</RteFlg>
759+
<bShared>0</bShared>
760+
</File>
761+
<File>
762+
<GroupNumber>10</GroupNumber>
763+
<FileNumber>38</FileNumber>
764+
<FileType>1</FileType>
765+
<tvExp>0</tvExp>
766+
<Focus>0</Focus>
767+
<tvExpOptDlg>0</tvExpOptDlg>
768+
<bDave2>0</bDave2>
769+
<PathWithFileName>..\..\..\..\targets\TARGET_LPC54102\pinmap.c</PathWithFileName>
770+
<FilenameWithoutPath>pinmap.c</FilenameWithoutPath>
771+
<RteFlg>0</RteFlg>
772+
<bShared>0</bShared>
773+
</File>
774+
</Group>
775+
729776
<Group>
730777
<GroupName>::CMSIS</GroupName>
731778
<tvExp>0</tvExp>

embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@
365365
<MiscControls></MiscControls>
366366
<Define>INTERNAL_FLASH,BOARD_NXP_LPCXPRESS0_54102,PWRROMD_PRESENT,__FPU_PRESENT=1,CORE_M4,ANDROID_DEMO,DEBUG_BUILD,DEBUG_OUTPUT,ASF_PROFILING,ON_DEMAND_PROFILING</Define>
367367
<Undefine></Undefine>
368-
<IncludePath>..\..\..\..\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</IncludePath>
368+
<IncludePath>..\..\..\..\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</IncludePath>
369369
</VariousControls>
370370
</Cads>
371371
<Aads>
@@ -1025,6 +1025,26 @@
10251025
</File>
10261026
</Files>
10271027
</Group>
1028+
<Group>
1029+
<GroupName>TARGET_LPC54102</GroupName>
1030+
<Files>
1031+
<File>
1032+
<FileName>gpio_api.c</FileName>
1033+
<FileType>1</FileType>
1034+
<FilePath>..\..\..\..\targets\TARGET_LPC54102\gpio_api.c</FilePath>
1035+
</File>
1036+
<File>
1037+
<FileName>gpio_irq_api.c</FileName>
1038+
<FileType>1</FileType>
1039+
<FilePath>..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c</FilePath>
1040+
</File>
1041+
<File>
1042+
<FileName>pinmap.c</FileName>
1043+
<FileType>1</FileType>
1044+
<FilePath>..\..\..\..\targets\TARGET_LPC54102\pinmap.c</FilePath>
1045+
</File>
1046+
</Files>
1047+
</Group>
10281048
<Group>
10291049
<GroupName>::CMSIS</GroupName>
10301050
<GroupOption>

embedded/projects/osp-lpc54102/sources/app/hostif.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
#define _HOSTIF_H_
3434

3535
#include "spi-sensor-hub-priv.h"
36+
#include "gpio_api.h"
3637

3738
#ifdef __cplusplus
3839
extern "C" {
3940
#endif
4041

42+
extern gpio_t hostifIrq;
43+
4144
/** @defgroup SH_HOSTIF : Sensor hub host interface
4245
* @ingroup SENSOR_HUB
4346
* @{
@@ -65,7 +68,7 @@ void Hostif_StartTx(uint8_t *pBuf, uint16_t size, int magic);
6568
*/
6669
static INLINE void Hostif_AssertIRQ(void)
6770
{
68-
Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 0);
71+
gpio_write(&hostifIrq,0);
6972
}
7073

7174
/**
@@ -74,7 +77,7 @@ static INLINE void Hostif_AssertIRQ(void)
7477
*/
7578
static INLINE void Hostif_DeassertIRQ(void)
7679
{
77-
Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1);
80+
gpio_write(&hostifIrq,1);
7881
}
7982

8083
/**
@@ -83,7 +86,7 @@ static INLINE void Hostif_DeassertIRQ(void)
8386
*/
8487
static INLINE bool Hostif_IRQActive(void)
8588
{
86-
return (Chip_GPIO_GetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN) == false);
89+
return (gpio_read(&hostifIrq) == false);
8790
}
8891

8992
/**

embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
* copyright, permission, and disclaimer notice must appear in all copies of
2929
* this code.
3030
*/
31-
#include "board.h"
3231
#include <string.h>
3332
#include <stdint.h>
3433
#include "sensorhub.h"
3534
#include "hostif.h"
3635
#include "osp-types.h"
3736
#include "common.h"
37+
#include "pinmap.h"
3838
/*****************************************************************************
3939
* Private types/enumerations/variables
4040
****************************************************************************/
@@ -56,6 +56,9 @@ typedef struct __HOSTIF_Ctrl_t {
5656
uint16_t txLength_next;
5757
} Hostif_Ctrl_t;
5858

59+
/* Host Interface Pin. Making it global since it is used in multiple places */
60+
gpio_t hostifIrq = {ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN)};
61+
5962
static Hostif_Ctrl_t g_hostif;
6063

6164
#define I2C_MEM_SZ 64 /* Size of memory for I2C Slave ROM driver */
@@ -275,8 +278,8 @@ void Hostif_Init(void)
275278
memset(&g_hostif, 0, sizeof(Hostif_Ctrl_t));
276279

277280
/* Setup I2C pin mux */
278-
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 27, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* i2c2 */
279-
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 28, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* I2C2 */
281+
pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_27), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN));
282+
pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_28), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN));
280283

281284
Chip_Clock_EnablePeriphClock(I2C_HOSTIF_CLK);
282285
Chip_SYSCON_PeriphReset(I2C_HOSTIF_RST);
@@ -320,12 +323,12 @@ void Hostif_Init(void)
320323
ROM_I2CS_Transfer(hI2C, &i2cXfer);
321324

322325
/* init host interrupt pin */
323-
Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN);
324-
326+
gpio_dir(&hostifIrq,PIN_OUTPUT);
327+
325328
/* de-assert interrupt line to high to indicate Host/AP that
326329
* there is no data to receive
327330
*/
328-
Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1);
331+
gpio_write(&hostifIrq,1);
329332

330333
/* Enable the interrupt for the I2C */
331334
NVIC_SetPriority(I2C_HOSTIF_IRQn, HOSTIF_IRQ_PRIORITY);

0 commit comments

Comments
 (0)