Skip to content

Commit a64b192

Browse files
committed
MCUXpresso: Update the LPC GPIO drivers
Update to the latest SDK GPIO driver Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent c05a893 commit a64b192

File tree

8 files changed

+176
-214
lines changed

8 files changed

+176
-214
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/gpio_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void gpio_write(gpio_t *obj, int value)
6262
uint32_t pin_number = obj->pin & 0x1F;
6363
uint8_t port_number = obj->pin / 32;
6464

65-
GPIO_WritePinOutput(GPIO, port_number, pin_number, value);
65+
GPIO_PinWrite(GPIO, port_number, pin_number, value);
6666
}
6767

6868
int gpio_read(gpio_t *obj)
@@ -71,5 +71,5 @@ int gpio_read(gpio_t *obj)
7171
uint32_t pin_number = obj->pin & 0x1F;
7272
uint8_t port_number = obj->pin / 32;
7373

74-
return (int)GPIO_ReadPinInput(GPIO, port_number, pin_number);
74+
return (int)GPIO_PinRead(GPIO, port_number, pin_number);
7575
}

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/port_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ void port_dir(port_t *obj, PinDirection dir)
7171

7272
void port_write(port_t *obj, int value)
7373
{
74-
GPIO_WriteMPort(GPIO, obj->port, value);
74+
GPIO_PortMaskedWrite(GPIO, obj->port, value);
7575
}
7676

7777
int port_read(port_t *obj)
7878
{
79-
return (int)(GPIO_ReadMPort(GPIO, obj->port));
79+
return (int)(GPIO_PortMaskedRead(GPIO, obj->port));
8080
}
8181

8282
#endif
Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,112 @@
11
/*
22
* Copyright (c) 2016, Freescale Semiconductor, Inc.
3+
* Copyright 2016-2018 NXP
34
* All rights reserved.
45
*
5-
* Redistribution and use in source and binary forms, with or without modification,
6-
* are permitted provided that the following conditions are met:
7-
*
8-
* o Redistributions of source code must retain the above copyright notice, this list
9-
* of conditions and the following disclaimer.
10-
*
11-
* o Redistributions in binary form must reproduce the above copyright notice, this
12-
* list of conditions and the following disclaimer in the documentation and/or
13-
* other materials provided with the distribution.
14-
*
15-
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16-
* contributors may be used to endorse or promote products derived from this
17-
* software without specific prior written permission.
18-
*
19-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6+
* SPDX-License-Identifier: BSD-3-Clause
297
*/
308

319
#include "fsl_gpio.h"
3210

11+
/* Component ID definition, used by tools. */
12+
#ifndef FSL_COMPONENT_ID
13+
#define FSL_COMPONENT_ID "platform.drivers.lpc_gpio"
14+
#endif
15+
3316
/*******************************************************************************
3417
* Variables
3518
******************************************************************************/
19+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
20+
/*! @brief Array to map FGPIO instance number to clock name. */
21+
static const clock_ip_name_t s_gpioClockName[] = GPIO_CLOCKS;
22+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
3623

24+
#if !(defined(FSL_FEATURE_GPIO_HAS_NO_RESET) && FSL_FEATURE_GPIO_HAS_NO_RESET)
25+
/*! @brief Pointers to GPIO resets for each instance. */
26+
static const reset_ip_name_t s_gpioResets[] = GPIO_RSTS_N;
27+
#endif
3728
/*******************************************************************************
3829
* Prototypes
3930
************ ******************************************************************/
4031

4132
/*******************************************************************************
4233
* Code
4334
******************************************************************************/
35+
/*!
36+
* brief Initializes the GPIO peripheral.
37+
*
38+
* This function ungates the GPIO clock.
39+
*
40+
* param base GPIO peripheral base pointer.
41+
* param port GPIO port number.
42+
*/
43+
void GPIO_PortInit(GPIO_Type *base, uint32_t port)
44+
{
45+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
46+
assert(port < ARRAY_SIZE(s_gpioClockName));
4447

48+
/* Upgate the GPIO clock */
49+
CLOCK_EnableClock(s_gpioClockName[port]);
50+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
51+
#if !(defined(FSL_FEATURE_GPIO_HAS_NO_RESET) && FSL_FEATURE_GPIO_HAS_NO_RESET)
52+
/* Reset the GPIO module */
53+
RESET_PeripheralReset(s_gpioResets[port]);
54+
#endif
55+
}
56+
57+
/*!
58+
* brief Initializes a GPIO pin used by the board.
59+
*
60+
* To initialize the GPIO, define a pin configuration, either input or output, in the user file.
61+
* Then, call the GPIO_PinInit() function.
62+
*
63+
* This is an example to define an input pin or output pin configuration:
64+
* code
65+
* // Define a digital input pin configuration,
66+
* gpio_pin_config_t config =
67+
* {
68+
* kGPIO_DigitalInput,
69+
* 0,
70+
* }
71+
* //Define a digital output pin configuration,
72+
* gpio_pin_config_t config =
73+
* {
74+
* kGPIO_DigitalOutput,
75+
* 0,
76+
* }
77+
* endcode
78+
*
79+
* param base GPIO peripheral base pointer(Typically GPIO)
80+
* param port GPIO port number
81+
* param pin GPIO pin number
82+
* param config GPIO pin configuration pointer
83+
*/
4584
void GPIO_PinInit(GPIO_Type *base, uint32_t port, uint32_t pin, const gpio_pin_config_t *config)
4685
{
4786
if (config->pinDirection == kGPIO_DigitalInput)
4887
{
88+
#if defined(FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR) && (FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR)
89+
base->DIRCLR[port] = 1U << pin;
90+
#else
4991
base->DIR[port] &= ~(1U << pin);
92+
#endif /*FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR*/
5093
}
5194
else
5295
{
53-
base->DIR[port] |= 1U << pin;
5496
/* Set default output value */
5597
if (config->outputLogic == 0U)
5698
{
5799
base->CLR[port] = (1U << pin);
58100
}
59101
else
60102
{
61-
base->PIN[port] = (1U << pin);
103+
base->SET[port] = (1U << pin);
62104
}
105+
/* Set pin direction */
106+
#if defined(FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR) && (FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR)
107+
base->DIRSET[port] = 1U << pin;
108+
#else
109+
base->DIR[port] |= 1U << pin;
110+
#endif /*FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR*/
63111
}
64112
}

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/drivers/fsl_gpio.h

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
11
/*
22
* Copyright (c) 2016, Freescale Semiconductor, Inc.
3+
* Copyright 2016-2018 NXP
34
* All rights reserved.
45
*
5-
* Redistribution and use in source and binary forms, with or without modification,
6-
* are permitted provided that the following conditions are met:
7-
*
8-
* o Redistributions of source code must retain the above copyright notice, this list
9-
* of conditions and the following disclaimer.
10-
*
11-
* o Redistributions in binary form must reproduce the above copyright notice, this
12-
* list of conditions and the following disclaimer in the documentation and/or
13-
* other materials provided with the distribution.
14-
*
15-
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16-
* contributors may be used to endorse or promote products derived from this
17-
* software without specific prior written permission.
18-
*
19-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22-
* DISCLAIMED. IN NO EVENT SDRVL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6+
* SPDX-License-Identifier: BSD-3-Clause
297
*/
308

319
#ifndef _LPC_GPIO_H_
@@ -46,8 +24,8 @@
4624

4725
/*! @name Driver version */
4826
/*@{*/
49-
/*! @brief LPC GPIO driver version 1.0.0. */
50-
#define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(1, 0, 0))
27+
/*! @brief LPC GPIO driver version 2.1.3. */
28+
#define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 1, 3))
5129
/*@}*/
5230

5331
/*! @brief LPC GPIO direction definition */
@@ -80,6 +58,16 @@ extern "C" {
8058
/*! @name GPIO Configuration */
8159
/*@{*/
8260

61+
/*!
62+
* @brief Initializes the GPIO peripheral.
63+
*
64+
* This function ungates the GPIO clock.
65+
*
66+
* @param base GPIO peripheral base pointer.
67+
* @param port GPIO port number.
68+
*/
69+
void GPIO_PortInit(GPIO_Type *base, uint32_t port);
70+
8371
/*!
8472
* @brief Initializes a GPIO pin used by the board.
8573
*
@@ -124,10 +112,11 @@ void GPIO_PinInit(GPIO_Type *base, uint32_t port, uint32_t pin, const gpio_pin_c
124112
* - 0: corresponding pin output low-logic level.
125113
* - 1: corresponding pin output high-logic level.
126114
*/
127-
static inline void GPIO_WritePinOutput(GPIO_Type *base, uint32_t port, uint32_t pin, uint8_t output)
115+
static inline void GPIO_PinWrite(GPIO_Type *base, uint32_t port, uint32_t pin, uint8_t output)
128116
{
129117
base->B[port][pin] = output;
130118
}
119+
131120
/*@}*/
132121
/*! @name GPIO Input Operations */
133122
/*@{*/
@@ -142,10 +131,11 @@ static inline void GPIO_WritePinOutput(GPIO_Type *base, uint32_t port, uint32_t
142131
* - 0: corresponding pin input low-logic level.
143132
* - 1: corresponding pin input high-logic level.
144133
*/
145-
static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t port, uint32_t pin)
134+
static inline uint32_t GPIO_PinRead(GPIO_Type *base, uint32_t port, uint32_t pin)
146135
{
147136
return (uint32_t)base->B[port][pin];
148137
}
138+
149139
/*@}*/
150140

151141
/*!
@@ -155,7 +145,7 @@ static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t port, uint32_
155145
* @param port GPIO port number
156146
* @param mask GPIO pin number macro
157147
*/
158-
static inline void GPIO_SetPinsOutput(GPIO_Type *base, uint32_t port, uint32_t mask)
148+
static inline void GPIO_PortSet(GPIO_Type *base, uint32_t port, uint32_t mask)
159149
{
160150
base->SET[port] = mask;
161151
}
@@ -167,7 +157,7 @@ static inline void GPIO_SetPinsOutput(GPIO_Type *base, uint32_t port, uint32_t m
167157
* @param port GPIO port number
168158
* @param mask GPIO pin number macro
169159
*/
170-
static inline void GPIO_ClearPinsOutput(GPIO_Type *base, uint32_t port, uint32_t mask)
160+
static inline void GPIO_PortClear(GPIO_Type *base, uint32_t port, uint32_t mask)
171161
{
172162
base->CLR[port] = mask;
173163
}
@@ -179,10 +169,11 @@ static inline void GPIO_ClearPinsOutput(GPIO_Type *base, uint32_t port, uint32_t
179169
* @param port GPIO port number
180170
* @param mask GPIO pin number macro
181171
*/
182-
static inline void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t port, uint32_t mask)
172+
static inline void GPIO_PortToggle(GPIO_Type *base, uint32_t port, uint32_t mask)
183173
{
184174
base->NOT[port] = mask;
185175
}
176+
186177
/*@}*/
187178

188179
/*!
@@ -191,7 +182,7 @@ static inline void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t port, uint32_
191182
* @param base GPIO peripheral base pointer(Typically GPIO)
192183
* @param port GPIO port number
193184
*/
194-
static inline uint32_t GPIO_ReadPinsInput(GPIO_Type *base, uint32_t port)
185+
static inline uint32_t GPIO_PortRead(GPIO_Type *base, uint32_t port)
195186
{
196187
return (uint32_t)base->PIN[port];
197188
}
@@ -207,7 +198,7 @@ static inline uint32_t GPIO_ReadPinsInput(GPIO_Type *base, uint32_t port)
207198
* @param port GPIO port number
208199
* @param mask GPIO pin number macro
209200
*/
210-
static inline void GPIO_SetPortMask(GPIO_Type *base, uint32_t port, uint32_t mask)
201+
static inline void GPIO_PortMaskedSet(GPIO_Type *base, uint32_t port, uint32_t mask)
211202
{
212203
base->MASK[port] = mask;
213204
}
@@ -219,7 +210,7 @@ static inline void GPIO_SetPortMask(GPIO_Type *base, uint32_t port, uint32_t mas
219210
* @param port GPIO port number
220211
* @param output GPIO port output value.
221212
*/
222-
static inline void GPIO_WriteMPort(GPIO_Type *base, uint32_t port, uint32_t output)
213+
static inline void GPIO_PortMaskedWrite(GPIO_Type *base, uint32_t port, uint32_t output)
223214
{
224215
base->MPIN[port] = output;
225216
}
@@ -232,7 +223,7 @@ static inline void GPIO_WriteMPort(GPIO_Type *base, uint32_t port, uint32_t outp
232223
* @param port GPIO port number
233224
* @retval masked GPIO port value
234225
*/
235-
static inline uint32_t GPIO_ReadMPort(GPIO_Type *base, uint32_t port)
226+
static inline uint32_t GPIO_PortMaskedRead(GPIO_Type *base, uint32_t port)
236227
{
237228
return (uint32_t)base->MPIN[port];
238229
}

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/drivers/fsl_reset.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
* Definitions
4747
******************************************************************************/
4848

49+
/*! @name Driver version */
50+
/*@{*/
51+
/*! @brief reset driver version 2.0.0. */
52+
#define FSL_RESET_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
53+
/*@}*/
54+
4955
/*!
5056
* @brief Enumeration for peripheral reset control bits
5157
*
@@ -111,7 +117,7 @@ typedef enum _SYSCON_RSTn
111117
{ \
112118
kGINT_RST_SHIFT_RSTn, kGINT_RST_SHIFT_RSTn \
113119
} /* Reset bits for GINT peripheral. GINT0 & GINT1 share same slot */
114-
#define GPIO_RSTS \
120+
#define GPIO_RSTS_N \
115121
{ \
116122
kGPIO0_RST_SHIFT_RSTn, kGPIO1_RST_SHIFT_RSTn \
117123
} /* Reset bits for GPIO peripheral */

0 commit comments

Comments
 (0)