1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "mbed_assert.h"
19 #include "reserved_pins.h"
21 static const PinName reserved_pins[] = TARGET_RESERVED_PINS;
23 uint32_t gpio_set(PinName pin) {
24 MBED_ASSERT(pin != (PinName)NC);
25 // PIO default value of following ports are not same as others
29 for (i = 0; i < sizeof(reserved_pins) / sizeof(PinName); i ++) {
30 if (pin == reserved_pins[i]) {
36 return ((pin & 0x0F00) >> 8);
39 void gpio_init(gpio_t *obj, PinName pin) {
41 if (pin == (PinName)NC)
44 LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
46 obj->reg_mask_read = &port_reg->MASKED_ACCESS[1 << gpio_set(pin)];
47 obj->reg_dir = &port_reg->DIR;
48 obj->reg_write = &port_reg->DATA;
51 void gpio_mode(gpio_t *obj, PinMode mode) {
52 pin_mode(obj->pin, mode);
55 void gpio_dir(gpio_t *obj, PinDirection direction) {
56 MBED_ASSERT(obj->pin != (PinName)NC);
57 int pin_number = ((obj->pin & 0x0F00) >> 8);
60 *obj->reg_dir &= ~(1 << pin_number);
63 *obj->reg_dir |= (1 << pin_number);