mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Dec 02 11:30:05 2013 +0000
Revision:
52:a51c77007319
Child:
70:c1fbde68b492
Synchronized with git revision 49df530ae72ce97ccc773d1f2c13b38e868e6abd

Full URL: https://github.com/mbedmicro/mbed/commit/49df530ae72ce97ccc773d1f2c13b38e868e6abd/

Add STMicroelectronics NUCLEO_F103RB target

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:a51c77007319 1 /* mbed Microcontroller Library
mbed_official 52:a51c77007319 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 52:a51c77007319 3 *
mbed_official 52:a51c77007319 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 52:a51c77007319 5 * you may not use this file except in compliance with the License.
mbed_official 52:a51c77007319 6 * You may obtain a copy of the License at
mbed_official 52:a51c77007319 7 *
mbed_official 52:a51c77007319 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 52:a51c77007319 9 *
mbed_official 52:a51c77007319 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 52:a51c77007319 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 52:a51c77007319 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 52:a51c77007319 13 * See the License for the specific language governing permissions and
mbed_official 52:a51c77007319 14 * limitations under the License.
mbed_official 52:a51c77007319 15 */
mbed_official 52:a51c77007319 16 #include "gpio_api.h"
mbed_official 52:a51c77007319 17 #include "pinmap.h"
mbed_official 52:a51c77007319 18
mbed_official 52:a51c77007319 19 uint32_t gpio_set(PinName pin) {
mbed_official 52:a51c77007319 20 if (pin == NC) return 0;
mbed_official 52:a51c77007319 21
mbed_official 52:a51c77007319 22 pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
mbed_official 52:a51c77007319 23
mbed_official 52:a51c77007319 24 return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
mbed_official 52:a51c77007319 25 }
mbed_official 52:a51c77007319 26
mbed_official 52:a51c77007319 27 void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
mbed_official 52:a51c77007319 28 if (pin == NC) return;
mbed_official 52:a51c77007319 29
mbed_official 52:a51c77007319 30 // Get GPIO structure base address
mbed_official 52:a51c77007319 31 uint32_t pin_number = (uint32_t)pin;
mbed_official 52:a51c77007319 32 uint32_t port_index = (pin_number >> 4);
mbed_official 52:a51c77007319 33 GPIO_TypeDef *gpio = (GPIO_TypeDef *)(GPIOA_BASE + (port_index << 10));
mbed_official 52:a51c77007319 34
mbed_official 52:a51c77007319 35 // Fill GPIO object structure for future use
mbed_official 52:a51c77007319 36 obj->pin = pin;
mbed_official 52:a51c77007319 37 obj->mask = gpio_set(pin);
mbed_official 52:a51c77007319 38 obj->reg_in = &gpio->IDR;
mbed_official 52:a51c77007319 39 obj->reg_set = &gpio->BSRR;
mbed_official 52:a51c77007319 40 obj->reg_clr = &gpio->BRR;
mbed_official 52:a51c77007319 41
mbed_official 52:a51c77007319 42 // Configure GPIO
mbed_official 52:a51c77007319 43 if (direction == PIN_OUTPUT) {
mbed_official 52:a51c77007319 44 pin_function(pin, STM_PIN_DATA(GPIO_Mode_Out_PP, 0));
mbed_official 52:a51c77007319 45 }
mbed_official 52:a51c77007319 46 else { // PIN_INPUT
mbed_official 52:a51c77007319 47 pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
mbed_official 52:a51c77007319 48 }
mbed_official 52:a51c77007319 49 }
mbed_official 52:a51c77007319 50
mbed_official 52:a51c77007319 51 void gpio_mode(gpio_t *obj, PinMode mode) {
mbed_official 52:a51c77007319 52 pin_mode(obj->pin, mode);
mbed_official 52:a51c77007319 53 }
mbed_official 52:a51c77007319 54
mbed_official 52:a51c77007319 55 void gpio_dir(gpio_t *obj, PinDirection direction) {
mbed_official 52:a51c77007319 56 if (direction == PIN_OUTPUT) {
mbed_official 52:a51c77007319 57 pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_Out_PP, 0));
mbed_official 52:a51c77007319 58 }
mbed_official 52:a51c77007319 59 else { // PIN_INPUT
mbed_official 52:a51c77007319 60 pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
mbed_official 52:a51c77007319 61 }
mbed_official 52:a51c77007319 62 }