Skip to content

Commit 741bfc2

Browse files
committed
[LPC1549] Fixed GPIO
Clean-up PinNames.h and GPIOrelated functions.
1 parent e06e842 commit 741bfc2

File tree

3 files changed

+18
-62
lines changed

3 files changed

+18
-62
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/PinNames.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ typedef enum {
2727
PIN_OUTPUT
2828
} PinDirection;
2929

30-
#define PORT_SHIFT 5
31-
3230
typedef enum {
3331
// LPC Pin Names
3432
P0_0 = 0,
3533
P0_1, P0_2, P0_3, P0_4, P0_5, P0_6, P0_7, P0_8, P0_9, P0_10, P0_11, P0_12, P0_13, P0_14, P0_15, P0_16, P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23, P0_24, P0_25, P0_26, P0_27, P0_28, P0_29, P0_30, P0_31,
3634
P1_0, P1_1, P1_2, P1_3, P1_4, P1_5, P1_6, P1_7, P1_8, P1_9, P1_10, P1_11, P1_12, P1_13, P1_14, P1_15, P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23, P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31,
3735
P2_0, P2_1, P2_2, P2_3, P2_4, P2_5, P2_6, P2_7, P2_8, P2_9, P2_10, P2_11, P2_12,
38-
36+
37+
LED_RED = P0_25,
38+
LED_GREEN = P0_3,
39+
LED_BLUE = P1_1,
3940

4041
// mbed original LED naming
41-
LED1 = P0_1,
42-
LED2 = P0_3,
43-
LED3 = P0_25,
44-
LED4 = P0_25,
45-
LED_RED = P0_2,
42+
LED1 = LED_BLUE,
43+
LED2 = LED_GREEN,
44+
LED3 = LED_RED,
45+
LED4 = LED_RED,
4646

4747
// Serial to USB pins
48-
USBTX = P0_4,
49-
USBRX = P0_0,
48+
USBTX = P0_18,
49+
USBRX = P0_13,
5050

5151
// Not connected
5252
NC = (int)0xFFFFFFFF,

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/gpio_api.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,20 @@
1717
#include "pinmap.h"
1818

1919
static int gpio_enabled = 0;
20+
2021
static void gpio_enable(void) {
2122
gpio_enabled = 1;
2223

23-
/* Enable AHB clock to the GPIO domain. */
24-
LPC_SYSCON->SYSAHBCLKCTRL0 |= (1<<14);
25-
LPC_SYSCON->SYSAHBCLKCTRL0 |= (1<<15);
26-
LPC_SYSCON->SYSAHBCLKCTRL0 |= (1<<16);
27-
28-
/* Peripheral reset control to GPIO and GPIO INT, a "1" bring it out of reset. */
29-
LPC_SYSCON->PRESETCTRL0 &= ~(0x1<<14);
30-
LPC_SYSCON->PRESETCTRL0 |= (0x1<<14);
31-
LPC_SYSCON->PRESETCTRL0 &= ~(0x1<<15);
32-
LPC_SYSCON->PRESETCTRL0 |= (0x1<<15);
33-
LPC_SYSCON->PRESETCTRL0 &= ~(0x1<<16);
34-
LPC_SYSCON->PRESETCTRL0 |= (0x1<<16);
24+
/* Enable AHB clock to the GPIO0/1/2 and IOCON domain. */
25+
LPC_SYSCON->SYSAHBCLKCTRL0 |= (0xFUL << 13);
3526
}
3627

3728
uint32_t gpio_set(PinName pin) {
38-
int f = 0;
3929

4030
if (!gpio_enabled)
4131
gpio_enable();
4232

43-
pin_function(pin, f);
44-
45-
return (1 << ((int)pin & 0x1F));
33+
return (1UL << ((int)pin & 0x1f));
4634
}
4735

4836
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
@@ -51,7 +39,7 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
5139
obj->pin = pin;
5240
obj->mask = gpio_set(pin);
5341

54-
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
42+
unsigned int port = (unsigned int)(pin >> 5);
5543

5644
obj->reg_set = &LPC_GPIO_PORT->SET[port];
5745
obj->reg_clr = &LPC_GPIO_PORT->CLR[port];

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/pinmap.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,19 @@
1616
#include "pinmap.h"
1717
#include "error.h"
1818

19-
__IO uint32_t* IOCON_REGISTERS[76] = {
20-
&LPC_IOCON->PIO0_0 , &LPC_IOCON->PIO0_1 , &LPC_IOCON->PIO0_2 ,
21-
&LPC_IOCON->PIO0_3 , &LPC_IOCON->PIO0_4 , &LPC_IOCON->PIO0_5 ,
22-
&LPC_IOCON->PIO0_6 , &LPC_IOCON->PIO0_7 , &LPC_IOCON->PIO0_8 ,
23-
&LPC_IOCON->PIO0_9 , &LPC_IOCON->PIO0_10, &LPC_IOCON->PIO0_11,
24-
&LPC_IOCON->PIO0_12, &LPC_IOCON->PIO0_13, &LPC_IOCON->PIO0_14,
25-
&LPC_IOCON->PIO0_15, &LPC_IOCON->PIO0_16, &LPC_IOCON->PIO0_17,
26-
&LPC_IOCON->PIO0_18, &LPC_IOCON->PIO0_19, &LPC_IOCON->PIO0_20,
27-
&LPC_IOCON->PIO0_21, &LPC_IOCON->PIO0_22, &LPC_IOCON->PIO0_23,
28-
&LPC_IOCON->PIO0_24, &LPC_IOCON->PIO0_25, &LPC_IOCON->PIO0_26,
29-
&LPC_IOCON->PIO0_27, &LPC_IOCON->PIO0_28, &LPC_IOCON->PIO0_29,
30-
&LPC_IOCON->PIO0_30, &LPC_IOCON->PIO0_31,
31-
32-
&LPC_IOCON->PIO1_0 , &LPC_IOCON->PIO1_1 , &LPC_IOCON->PIO1_2 ,
33-
&LPC_IOCON->PIO1_3 , &LPC_IOCON->PIO1_4 , &LPC_IOCON->PIO1_5 ,
34-
&LPC_IOCON->PIO1_6 , &LPC_IOCON->PIO1_7 , &LPC_IOCON->PIO1_8 ,
35-
&LPC_IOCON->PIO1_9 , &LPC_IOCON->PIO1_10, &LPC_IOCON->PIO1_11,
36-
&LPC_IOCON->PIO1_12, &LPC_IOCON->PIO1_13, &LPC_IOCON->PIO1_14,
37-
&LPC_IOCON->PIO1_15, &LPC_IOCON->PIO1_16, &LPC_IOCON->PIO1_17,
38-
&LPC_IOCON->PIO1_18, &LPC_IOCON->PIO1_19, &LPC_IOCON->PIO1_20,
39-
&LPC_IOCON->PIO1_21, &LPC_IOCON->PIO1_22, &LPC_IOCON->PIO1_23,
40-
&LPC_IOCON->PIO1_24, &LPC_IOCON->PIO1_25, &LPC_IOCON->PIO1_26,
41-
&LPC_IOCON->PIO1_27, &LPC_IOCON->PIO1_28, &LPC_IOCON->PIO1_29,
42-
&LPC_IOCON->PIO1_30, &LPC_IOCON->PIO1_31,
43-
44-
&LPC_IOCON->PIO2_0 , &LPC_IOCON->PIO2_1 , &LPC_IOCON->PIO2_2 ,
45-
&LPC_IOCON->PIO2_3 , &LPC_IOCON->PIO2_4 , &LPC_IOCON->PIO2_5 ,
46-
&LPC_IOCON->PIO2_6 , &LPC_IOCON->PIO2_7 , &LPC_IOCON->PIO2_8 ,
47-
&LPC_IOCON->PIO2_9 , &LPC_IOCON->PIO2_10, &LPC_IOCON->PIO2_11,
48-
};
49-
5019
void pin_function(PinName pin, int function) {
51-
5220
}
5321

5422
void pin_mode(PinName pin, PinMode mode) {
5523
if (pin == (uint32_t)NC) { return; }
5624

57-
if ((pin == 22) || (pin == 23)) {
25+
if ((pin == P0_22) || (pin == P0_23)) {
5826
// The true open-drain pins PIO0_22 and PIO0_23 can be configured for different I2C-bus speeds.
5927
return;
6028
}
6129

62-
__IO uint32_t *reg = IOCON_REGISTERS[pin];
63-
30+
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + (pin * 4));
31+
6432
if (mode == OpenDrain) {
6533
*reg |= (1 << 10);
6634
} else {

0 commit comments

Comments
 (0)