Skip to content

Commit

Permalink
Fixed #9 and test ticker test code
Browse files Browse the repository at this point in the history
Clean-up GPIO stuff, but it shoud be same behavior as before.
  • Loading branch information
toyowata committed Jul 21, 2013
1 parent 796bbbe commit 794ab9c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 81 deletions.
92 changes: 47 additions & 45 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/PinNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,55 +27,57 @@ typedef enum {
PIN_OUTPUT
} PinDirection;

#define PORT_SHIFT 5
#define PORT_SHIFT 12
#define PIN_SHIFT 8

typedef enum {
// LPC1114 Pin Names (PORT[15:12] + PIN[11:8] + IOCON offset[7:0])
P0_0 = 0x000c,
P0_1 = 0x0110,
P0_2 = 0x021c,
P0_3 = 0x032c,
P0_4 = 0x0430,
P0_5 = 0x0534,
P0_6 = 0x064c,
P0_7 = 0x0750,
P0_8 = 0x0860,
P0_9 = 0x0964,
P0_10 = 0x0a68,
P0_11 = 0x0b74,

P1_0 = 0x1078,
P1_1 = 0x117c,
P1_2 = 0x1280,
P1_3 = 0x1390,
P1_4 = 0x1494,
P1_5 = 0x15a0,
P1_6 = 0x16a4,
P1_7 = 0x17a8,
P1_8 = 0x1814,
P1_9 = 0x1938,
P1_10 = 0x1a6c,
P1_11 = 0x1b98,

P2_0 = 0x2008,
P2_1 = 0x2128,
P2_2 = 0x225c,
P2_3 = 0x238c,
P2_4 = 0x2440,
P2_5 = 0x2544,
P2_6 = 0x2600,
P2_7 = 0x2720,
P2_8 = 0x2824,
P2_9 = 0x2954,
P2_10 = 0x2a58,
P2_11 = 0x2b70,

P0_0 = (0 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x0c,
P0_1 = (0 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x10,
P0_2 = (0 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x1c,
P0_3 = (0 << PORT_SHIFT) | (3 << PIN_SHIFT) | 0x2c,
P0_4 = (0 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x30,
P0_5 = (0 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0x34,
P0_6 = (0 << PORT_SHIFT) | (6 << PIN_SHIFT) | 0x4c,
P0_7 = (0 << PORT_SHIFT) | (7 << PIN_SHIFT) | 0x50,
P0_8 = (0 << PORT_SHIFT) | (8 << PIN_SHIFT) | 0x60,
P0_9 = (0 << PORT_SHIFT) | (9 << PIN_SHIFT) | 0x64,
P0_10 = (0 << PORT_SHIFT) | (10 << PIN_SHIFT) | 0x68,
P0_11 = (0 << PORT_SHIFT) | (11 << PIN_SHIFT) | 0x74,

P1_0 = (1 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x78,
P1_1 = (1 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x7c,
P1_2 = (1 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x80,
P1_3 = (1 << PORT_SHIFT) | (3 << PIN_SHIFT) | 0x90,
P1_4 = (1 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x94,
P1_5 = (1 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0xa0,
P1_6 = (1 << PORT_SHIFT) | (6 << PIN_SHIFT) | 0xa4,
P1_7 = (1 << PORT_SHIFT) | (7 << PIN_SHIFT) | 0xa8,
P1_8 = (1 << PORT_SHIFT) | (8 << PIN_SHIFT) | 0x14,
P1_9 = (1 << PORT_SHIFT) | (9 << PIN_SHIFT) | 0x38,
P1_10 = (1 << PORT_SHIFT) | (10 << PIN_SHIFT) | 0x6c,
P1_11 = (1 << PORT_SHIFT) | (11 << PIN_SHIFT) | 0x98,

P2_0 = (2 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x08,
P2_1 = (2 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x28,
P2_2 = (2 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x5c,
P2_3 = (2 << PORT_SHIFT) | (3 << PIN_SHIFT) | 0x8c,
P2_4 = (2 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x40,
P2_5 = (2 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0x44,
P2_6 = (2 << PORT_SHIFT) | (6 << PIN_SHIFT) | 0x00,
P2_7 = (2 << PORT_SHIFT) | (7 << PIN_SHIFT) | 0x20,
P2_8 = (2 << PORT_SHIFT) | (8 << PIN_SHIFT) | 0x24,
P2_9 = (2 << PORT_SHIFT) | (9 << PIN_SHIFT) | 0x54,
P2_10 = (2 << PORT_SHIFT) | (10 << PIN_SHIFT) | 0x58,
P2_11 = (2 << PORT_SHIFT) | (11 << PIN_SHIFT) | 0x70,

P3_0 = 0x3084,
P3_1 = 0x3188,
P3_2 = 0x329c,
P3_3 = 0x33ac,
P3_4 = 0x343c,
P3_5 = 0x3548,
P3_0 = (3 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x84,
P3_1 = (3 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x88,
P3_2 = (3 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x9c,
P3_3 = (3 << PORT_SHIFT) | (3 << PIN_SHIFT) | 0xac,
P3_4 = (3 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x3c,
P3_5 = (3 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0x48,

// mbed DIP Pin Names (CQ board)
p4 = P0_0,
Expand Down
37 changes: 7 additions & 30 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/gpio_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,21 @@ uint32_t gpio_set(PinName pin) {
(1) : (0);

pin_function(pin, f);

int pin_number = ((pin & 0x0F00) >> 8);
return (pin_number + 1); // port n data address offset
return ((pin & 0x0F00) >> 8);
}

void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
if(pin == NC) return;

obj->pin = pin;
LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000));

LPC_GPIO_TypeDef *port_reg;

switch (pin & 0xF000) {
case 0x0000:
port_reg = LPC_GPIO0;
break;
case 0x1000:
port_reg = LPC_GPIO1;
break;
case 0x2000:
port_reg = LPC_GPIO2;
break;
case 0x3000:
port_reg = LPC_GPIO3;
break;
default:
return;
}

#warning TODO (@toyowata): Need to check array offset
obj->mask = &port_reg->MASKED_ACCESS[gpio_set(pin)];
obj->reg_dir = &port_reg->DIR;
obj->reg_in = &port_reg->DATA;
obj->reg_data= &port_reg->DATA;


obj->reg_mask_read = &port_reg->MASKED_ACCESS[gpio_set(pin) + 1];
obj->reg_dir = &port_reg->DIR;
obj->reg_write = &port_reg->DATA;

gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@ extern "C" {

typedef struct {
PinName pin;
__IO uint32_t *mask;
__I uint32_t *reg_mask_read;
__IO uint32_t *reg_dir;
__IO uint32_t *reg_data;
__I uint32_t *reg_in;
__IO uint32_t *reg_write;
} gpio_t;

static inline void gpio_write(gpio_t *obj, int value) {
uint32_t pin_number = ((obj->pin & 0x0F00) >> 8);
if (value)
*obj->reg_data |= (1 << pin_number);
*obj->reg_write |= (1 << pin_number);
else
*obj->reg_data &= ~(1 << pin_number);
*obj->reg_write &= ~(1 << pin_number);
}

static inline int gpio_read(gpio_t *obj) {
return ((*obj->mask) ? 1 : 0);
return ((*obj->reg_mask_read) ? 1 : 0);
}

#ifdef __cplusplus
Expand Down

0 comments on commit 794ab9c

Please sign in to comment.