Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 267 additions & 0 deletions embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/* Open Sensor Platform Project
* https://github.com/sensorplatforms/open-sensor-platform
*
* Copyright (C) 2015 Audience Inc.
*
* 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.
*/
/*-------------------------------------------------------------------------------------------------*\
| I N C L U D E F I L E S
\*-------------------------------------------------------------------------------------------------*/
#include "common.h"
#include "Driver_GPIO.h"
#include "chip.h"

/*-------------------------------------------------------------------------------------------------*\
| P R I V A T E C O N S T A N T S & M A C R O S
\*-------------------------------------------------------------------------------------------------*/
#define OSP_GPIO_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR( 1,00 )

/*-------------------------------------------------------------------------------------------------*\
| T Y P E D E F I N I T I O N S
\*-------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------*\
| S T A T I C V A R I A B L E S D E F I N I T I O N S
\*-------------------------------------------------------------------------------------------------*/
/* Driver Version */
static const ARM_DRIVER_VERSION DriverVersion =
{
OSP_GPIO_API_VERSION,
OSP_GPIO_DRV_VERSION
};

/*-------------------------------------------------------------------------------------------------*\
| P R I V A T E F U N C T I O N S
\*-------------------------------------------------------------------------------------------------*/
/****************************************************************************************************
* @fn OSP_GPIO_GetVersion
* Get driver version.
*
* @param gpio_priv Private argument (Unused)
*
* @return ARM_DRIVER_VERSION
*
***************************************************************************************************/
static ARM_DRIVER_VERSION OSP_GPIO_GetVersion( void *gpio_priv )
{
return DriverVersion;
}

/****************************************************************************************************
* @fn OSP_GPIO_Initialize
* Initializes the GPIO Module and Hardware
*
* @param gpio_priv Private argument (Unused)
*
* @return Return code: On success return ARM_DRIVER_OK
*
***************************************************************************************************/
static int32_t OSP_GPIO_Initialize( void *gpio_priv )
{
/* Enable the peripheral clock in the PMC */
Chip_GPIO_Init( LPC_GPIO );

/* Enable Pin interrupt sources */
Chip_PININT_Init( NULL );
return ARM_DRIVER_OK;
}

/****************************************************************************************************
* @fn OSP_GPIO_Uninitialize
* Unitialize the GPIO Module
*
* @param gpio_priv Private argument (Unused)
*
* @return Return code: On success return ARM_DRIVER_OK
*
***************************************************************************************************/
static int32_t OSP_GPIO_Uninitialize( void *gpio_priv )
{
/* Uninitialize GPIO */
Chip_GPIO_DeInit( LPC_GPIO );

Chip_PININT_DeInit( NULL );
return ARM_DRIVER_OK;
}

/****************************************************************************************************
* @fn OSP_GPIO_PowerControl
* Control the GPIO's power state
*
* @param state Target GPIO Power state
* @param gpio_priv Private argument (Unused)
*
* @return Return code: On success return ARM_DRIVER_OK
*
***************************************************************************************************/
static int32_t OSP_GPIO_PowerControl( ARM_POWER_STATE state, void *gpio_priv )
{
switch ( state )
{
case ARM_POWER_OFF:
Chip_GPIO_DeInit( LPC_GPIO );
break;

case ARM_POWER_FULL:
Chip_GPIO_Init( LPC_GPIO );
break;

default:
return ARM_DRIVER_ERROR_UNSUPPORTED;
}
return ARM_DRIVER_OK;
}

/****************************************************************************************************
* @fn OSP_GPIO_SetDirection
* Set the direction of GPIO pin
*
* @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number)
* @param dir Direction (GPIO_DIR_INPUT or GPIO_DIR_OUTPUT)
* @param gpio_priv Private argument (Unused)
*
* @return Return code: On success return ARM_DRIVER_OK
*
***************************************************************************************************/
static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, void *gpio_priv )
{
uint32_t port_num = 0, pin_num = 0;

ASF_assert( pin != (PinName)NC );
ASF_assert( (dir == ARM_GPIO_DIR_INPUT) || (dir == ARM_GPIO_DIR_OUTPUT) );
port_num = DECODE_PORT( pin );
pin_num = DECODE_PIN( pin );

( dir == ARM_GPIO_DIR_OUTPUT ) ? Chip_GPIO_SetPinDIROutput( LPC_GPIO, port_num, pin_num ) : \
Chip_GPIO_SetPinDIRInput( LPC_GPIO, port_num, pin_num );
return ARM_DRIVER_OK;
}

/****************************************************************************************************
* @fn OSP_GPIO_SetTrigger
* Set the trigger mode for GPIO
*
* @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number)
* @param trigger Trigger mode
* @param gpio_priv Private argument (Unused)
*
* @return Return code: On success return ARM_DRIVER_OK
*
***************************************************************************************************/
static int32_t OSP_GPIO_SetTrigger( uint32_t pin, uint32_t trigger, void *gpio_priv )
{
uint8_t index = 0;
uint8_t pinInterruptChannel = 0;

ASF_assert( pin != (PinName)NC );

for ( ; index < MAX_PIN_INTERRUPT_CHANNEL; index++ )
{
if ( GPIO_PinMap[index].pin == pin )
{
pinInterruptChannel = GPIO_PinMap[index].pinInterruptChannel;
break;
}
}

ASF_assert( index < MAX_PIN_INTERRUPT_CHANNEL );

if ( trigger & (1 << ARM_GPIO_TRIGGER_EDGE) )
{
Chip_PININT_SetPinModeEdge( LPC_PININT, pinInterruptChannel ); /* edge sensitive */
}
else
{
Chip_PININT_SetPinModeLevel( LPC_PININT, pinInterruptChannel ); /* Level sensitive */
}

if ( (trigger & (1 << ARM_GPIO_TRIGGER_HIGH)) || (trigger & (1 << ARM_GPIO_TRIGGER_RISING)) )
{
Chip_PININT_EnableIntHigh( LPC_PININT, pinInterruptChannel ); /* Rising Edge/High Level */
}
else
{
Chip_PININT_EnableIntLow( LPC_PININT, pinInterruptChannel ); /* Falling Edge/Low Level */
}
return ARM_DRIVER_OK;
}

/****************************************************************************************************
* @fn OSP_GPIO_WritePin
* Set the GPIO Pin state
*
* @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number)
* @param val Value to be written (0 or 1)
* @param gpio_priv Private argument (Unused)
*
* @return Return code: On success return ARM_DRIVER_OK
*
***************************************************************************************************/
static int32_t OSP_GPIO_WritePin( uint32_t pin, uint32_t val, void *gpio_priv )
{
uint32_t port_num = 0, pin_num = 0;

ASF_assert( pin != (PinName)NC );
ASF_assert( val <= 1 );
port_num = DECODE_PORT( pin );
pin_num = DECODE_PIN( pin );

Chip_GPIO_WritePortBit( LPC_GPIO, port_num, pin_num, (bool) val );
return ARM_DRIVER_OK;
}

/****************************************************************************************************
* @fn OSP_GPIO_ReadPin
* Get the GPIO Pin value
*
* @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number)
* @param gpio_priv Private argument (Unused)
*
* @return pin value
*
***************************************************************************************************/
static int32_t OSP_GPIO_ReadPin( uint32_t pin, void *gpio_priv )
{
uint32_t port_num = 0, pin_num = 0;

ASF_assert( pin != (PinName)NC );
port_num = DECODE_PORT( pin );
pin_num = DECODE_PIN( pin );

return ( Chip_GPIO_ReadPortBit( LPC_GPIO, port_num, pin_num ) );
}

/****************************************************************************************************
* @fn OSP_GPIO_SetHandler
* Handler function
*
* @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number)
* @param handler Pointer to handler function
* @param data Data to pass to the handler
* @param gpio_priv Private argument (Unused)
*
* @return Return code: On success return ARM_DRIVER_OK
*
***************************************************************************************************/
static int32_t OSP_GPIO_SetHandler( uint32_t pin, ARM_GPIO_Handler_t handler, void *data, void *gpio_priv )
{
return ARM_DRIVER_ERROR_UNSUPPORTED; //Not Supported
}

/* Driver Definition */
ARM_BUILD_DRIVER_GPIO( GPIO, OSP_GPIO, NULL );

/*-------------------------------------------------------------------------------------------------*\
| E N D O F F I L E
\*-------------------------------------------------------------------------------------------------*/
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,26 @@
</File>
</Group>

<Group>
<GroupName>Device</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>13</GroupNumber>
<FileNumber>39</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c</PathWithFileName>
<FilenameWithoutPath>Driver_GPIO.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>

<Group>
<GroupName>::CMSIS</GroupName>
<tvExp>0</tvExp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,16 @@
</File>
</Files>
</Group>
<Group>
<GroupName>Device</GroupName>
<Files>
<File>
<FileName>Driver_GPIO.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>::CMSIS</GroupName>
</Group>
Expand Down Expand Up @@ -1579,6 +1589,16 @@
</File>
</Files>
</Group>
<Group>
<GroupName>Device</GroupName>
<Files>
<File>
<FileName>Driver_GPIO.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>::CMSIS</GroupName>
</Group>
Expand Down Expand Up @@ -2368,6 +2388,16 @@
</File>
</Files>
</Group>
<Group>
<GroupName>Device</GroupName>
<Files>
<File>
<FileName>Driver_GPIO.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>::CMSIS</GroupName>
</Group>
Expand Down Expand Up @@ -2740,7 +2770,7 @@
<MiscControls></MiscControls>
<Define>SYSTEM_CLOCK_FREQ=96000000, __FPU_PRESENT=1, CHIP_LPC5410X, CORE_M4, DEBUG_BUILD, XPRESSO_LPC54102_BOARD, UART_DMA_ENABLE, ANDROID_DEMO, ASF_PROFILING, ON_DEMAND_PROFILING</Define>
<Undefine></Undefine>
<IncludePath>..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface</IncludePath>
<IncludePath>..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface;..\..\..\..\external\CMSIS\Driver\Include</IncludePath>
</VariousControls>
</Cads>
<Aads>
Expand Down Expand Up @@ -3157,6 +3187,16 @@
</File>
</Files>
</Group>
<Group>
<GroupName>Device</GroupName>
<Files>
<File>
<FileName>Driver_GPIO.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>::CMSIS</GroupName>
</Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
#include "i2cs_driver.h"
#include "hostif_i2c.h"
#include <string.h>
#include "Driver_GPIO.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
\*-------------------------------------------------------------------------------------------------*/
extern ARM_DRIVER_GPIO Driver_GPIO;

/*-------------------------------------------------------------------------------------------------*\
| P R I V A T E C O N S T A N T S & M A C R O S
Expand Down Expand Up @@ -362,10 +364,10 @@ void Hostif_I2C_Init(void)
i2c_slave_mode(&slave_i2c_handle,1);

/* init host interrupt pin */
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN);
Driver_GPIO.SetDirection (ENCODE_PORT_PIN(HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN), ARM_GPIO_DIR_OUTPUT);
/* de-assert interrupt line to high to indicate Host/AP that
* there is no data to receive */
Chip_GPIO_SetPinState(LPC_GPIO_PORT, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 0);
* there is no data to receive */
Driver_GPIO.WritePin (ENCODE_PORT_PIN(HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN), false);

/* Enable the interrupt for the I2C */
NVIC_SetPriority(I2C_HOSTIF_IRQn, HOSTIF_IRQ_PRIORITY);
Expand Down
Loading