mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
bogdanm
Date:
Mon Aug 19 18:17:02 2013 +0300
Revision:
19:398f4c622e1b
Sync with official mbed library release 66

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 19:398f4c622e1b 1 /* mbed Microcontroller Library
bogdanm 19:398f4c622e1b 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 19:398f4c622e1b 3 *
bogdanm 19:398f4c622e1b 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 19:398f4c622e1b 5 * you may not use this file except in compliance with the License.
bogdanm 19:398f4c622e1b 6 * You may obtain a copy of the License at
bogdanm 19:398f4c622e1b 7 *
bogdanm 19:398f4c622e1b 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 19:398f4c622e1b 9 *
bogdanm 19:398f4c622e1b 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 19:398f4c622e1b 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 19:398f4c622e1b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 19:398f4c622e1b 13 * See the License for the specific language governing permissions and
bogdanm 19:398f4c622e1b 14 * limitations under the License.
bogdanm 19:398f4c622e1b 15 */
bogdanm 19:398f4c622e1b 16 #include "gpio_api.h"
bogdanm 19:398f4c622e1b 17 #include "pinmap.h"
bogdanm 19:398f4c622e1b 18
bogdanm 19:398f4c622e1b 19 uint32_t gpio_set(PinName pin) {
bogdanm 19:398f4c622e1b 20 // PIO default value of following ports are not same as others
bogdanm 19:398f4c622e1b 21 int f = ((pin == P0_0 ) || // RESET
bogdanm 19:398f4c622e1b 22 (pin == P0_11) || // R
bogdanm 19:398f4c622e1b 23 (pin == P1_0 ) || // R
bogdanm 19:398f4c622e1b 24 (pin == P1_1 ) || // R
bogdanm 19:398f4c622e1b 25 (pin == P1_2 )) ? // R
bogdanm 19:398f4c622e1b 26 (1) : (0);
bogdanm 19:398f4c622e1b 27
bogdanm 19:398f4c622e1b 28 pin_function(pin, f);
bogdanm 19:398f4c622e1b 29 return ((pin & 0x0F00) >> 8);
bogdanm 19:398f4c622e1b 30 }
bogdanm 19:398f4c622e1b 31
bogdanm 19:398f4c622e1b 32 void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
bogdanm 19:398f4c622e1b 33 if(pin == NC) return;
bogdanm 19:398f4c622e1b 34
bogdanm 19:398f4c622e1b 35 obj->pin = pin;
bogdanm 19:398f4c622e1b 36 LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
bogdanm 19:398f4c622e1b 37
bogdanm 19:398f4c622e1b 38 obj->reg_mask_read = &port_reg->MASKED_ACCESS[1 << gpio_set(pin)];
bogdanm 19:398f4c622e1b 39 obj->reg_dir = &port_reg->DIR;
bogdanm 19:398f4c622e1b 40 obj->reg_write = &port_reg->DATA;
bogdanm 19:398f4c622e1b 41
bogdanm 19:398f4c622e1b 42 gpio_dir(obj, direction);
bogdanm 19:398f4c622e1b 43
bogdanm 19:398f4c622e1b 44 switch (direction) {
bogdanm 19:398f4c622e1b 45 case PIN_OUTPUT: pin_mode(pin, PullNone); break;
bogdanm 19:398f4c622e1b 46 case PIN_INPUT : pin_mode(pin, PullDown); break;
bogdanm 19:398f4c622e1b 47 }
bogdanm 19:398f4c622e1b 48 }
bogdanm 19:398f4c622e1b 49
bogdanm 19:398f4c622e1b 50 void gpio_mode(gpio_t *obj, PinMode mode) {
bogdanm 19:398f4c622e1b 51 pin_mode(obj->pin, mode);
bogdanm 19:398f4c622e1b 52 }
bogdanm 19:398f4c622e1b 53
bogdanm 19:398f4c622e1b 54 void gpio_dir(gpio_t *obj, PinDirection direction) {
bogdanm 19:398f4c622e1b 55 int pin_number = ((obj->pin & 0x0F00) >> 8);
bogdanm 19:398f4c622e1b 56 switch (direction) {
bogdanm 19:398f4c622e1b 57 case PIN_INPUT : *obj->reg_dir &= ~(1 << pin_number); break;
bogdanm 19:398f4c622e1b 58 case PIN_OUTPUT: *obj->reg_dir |= (1 << pin_number); break;
bogdanm 19:398f4c622e1b 59 }
bogdanm 19:398f4c622e1b 60 }