From 98cdc4e0feeaea37484c2645426134662ed08ca8 Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 10 Jul 2012 18:33:14 +0000 Subject: [PATCH] Several fixes to LPC43 pin and GPIO configuration git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4925 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c | 8 ++++---- nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h | 6 +++--- nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c | 12 ++++++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c index edb5bf3e0..2b2c88f31 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c @@ -158,7 +158,7 @@ static inline void lpc43_configoutput(uint16_t gpiocfg, int lpc43_gpio_config(uint16_t gpiocfg) { unsigned int port = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); - unsigned int pin = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + unsigned int pin = ((gpiocfg & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT); irqstate_t flags; int ret = OK; @@ -167,7 +167,7 @@ int lpc43_gpio_config(uint16_t gpiocfg) /* Handle the GPIO configuration by the basic mode of the pin */ flags = irqsave(); - switch (gpiocfg & GPIO_PORT_MASK) + switch (gpiocfg & GPIO_MODE_MASK) { case GPIO_MODE_INPUT: /* GPIO input pin */ lpc43_configinput(gpiocfg, port, pin); @@ -215,7 +215,7 @@ int lpc43_gpio_config(uint16_t gpiocfg) void lpc43_gpio_write(uint16_t gpiocfg, bool value) { unsigned int port = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); - unsigned int pin = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + unsigned int pin = ((gpiocfg & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT); DEBUGASSERT(port < NUM_GPIO_PORTS && pin < NUM_GPIO_PINS); @@ -238,7 +238,7 @@ void lpc43_gpio_write(uint16_t gpiocfg, bool value) bool lpc43_gpio_read(uint16_t gpiocfg) { unsigned int port = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); - unsigned int pin = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + unsigned int pin = ((gpiocfg & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT); DEBUGASSERT(port < NUM_GPIO_PORTS && pin < NUM_GPIO_PINS); diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h index f494be6b5..8f8460966 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h @@ -68,7 +68,7 @@ * ---- ---- ---- ---- * Normal GPIO: MMV. .... PPPB BBBB * Normal Interrupt: MMCC CIII PPPB BBBB - * Group Interrupt: MM.N P.. PPPB BBBB + * Group Interrupt: MM.N P... PPPB BBBB */ /* GPIO mode: @@ -184,10 +184,10 @@ * 1111 1100 0000 0000 * 5432 1098 7654 3210 * ---- ---- ---- ---- - * .... GPII .... .... + * .... .... PPP. .... */ -#define GPIO_PORT_SHIFT (4) /* Bits 4-6: Port number */ +#define GPIO_PORT_SHIFT (5) /* Bits 5-7: Port number */ #define GPIO_PORT_MASK (7 << GPIO_PORT_SHIFT) # define GPIO_PORT0 (0 << GPIO_PORT_SHIFT) # define GPIO_PORT1 (1 << GPIO_PORT_SHIFT) diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c b/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c index 2f748a9b1..fb5173339 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c @@ -43,6 +43,7 @@ #include #include +#include "up_arch.h" #include "lpc43_pinconfig.h" /**************************************************************************** @@ -83,10 +84,6 @@ int lpc43_pin_config(uint32_t pinconf) uintptr_t regaddr; uint32_t regval; - /* Get the address of the pin configuration register */ - - regaddr = LPC43_SCU_SFSP(pinset, pin); - /* Set up common pin configurations */ regval = (func << SCU_PIN_MODE_SHIFT); @@ -146,5 +143,12 @@ int lpc43_pin_config(uint32_t pinconf) break; } + /* Get the address of the pin configuration register and save the new + * pin configuration. + */ + + regaddr = LPC43_SCU_SFSP(pinset, pin); + putreg32(regval, regaddr); + return OK; }