mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/hal/TARGET_STM/TARGET_STM32F4XX/gpio_api.c@323:9e901b0a5aa1, 2014-09-13 (annotated)
- Committer:
- shaoziyang
- Date:
- Sat Sep 13 14:25:46 2014 +0000
- Revision:
- 323:9e901b0a5aa1
- Parent:
- 227:7bd0639b8911
test with CLOCK_SETUP = 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 20:4263a77256ae | 1 | /* mbed Microcontroller Library |
bogdanm | 20:4263a77256ae | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 20:4263a77256ae | 3 | * |
bogdanm | 20:4263a77256ae | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 20:4263a77256ae | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 20:4263a77256ae | 6 | * You may obtain a copy of the License at |
bogdanm | 20:4263a77256ae | 7 | * |
bogdanm | 20:4263a77256ae | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 20:4263a77256ae | 9 | * |
bogdanm | 20:4263a77256ae | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 20:4263a77256ae | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 20:4263a77256ae | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 20:4263a77256ae | 13 | * See the License for the specific language governing permissions and |
bogdanm | 20:4263a77256ae | 14 | * limitations under the License. |
bogdanm | 20:4263a77256ae | 15 | */ |
mbed_official | 227:7bd0639b8911 | 16 | #include "mbed_assert.h" |
bogdanm | 20:4263a77256ae | 17 | #include "gpio_api.h" |
bogdanm | 20:4263a77256ae | 18 | #include "pinmap.h" |
bogdanm | 20:4263a77256ae | 19 | |
bogdanm | 20:4263a77256ae | 20 | uint32_t gpio_set(PinName pin) { |
mbed_official | 227:7bd0639b8911 | 21 | MBED_ASSERT(pin != (PinName)NC); |
bogdanm | 20:4263a77256ae | 22 | uint32_t port_index = (uint32_t) pin >> 4; |
bogdanm | 20:4263a77256ae | 23 | |
bogdanm | 20:4263a77256ae | 24 | // Enable GPIO peripheral clock |
bogdanm | 20:4263a77256ae | 25 | RCC->AHB1ENR |= 1 << port_index; |
bogdanm | 20:4263a77256ae | 26 | |
bogdanm | 20:4263a77256ae | 27 | pin_function(pin, STM_PIN_DATA(0, 0)); |
bogdanm | 20:4263a77256ae | 28 | return 1 << ((uint32_t) pin & 0xF); |
bogdanm | 20:4263a77256ae | 29 | } |
bogdanm | 20:4263a77256ae | 30 | |
mbed_official | 113:65a335a675de | 31 | void gpio_init(gpio_t *obj, PinName pin) { |
mbed_official | 227:7bd0639b8911 | 32 | obj->pin = pin; |
mbed_official | 227:7bd0639b8911 | 33 | if (pin == (PinName)NC) |
mbed_official | 227:7bd0639b8911 | 34 | return; |
bogdanm | 20:4263a77256ae | 35 | |
bogdanm | 20:4263a77256ae | 36 | obj->mask = gpio_set(pin); |
bogdanm | 20:4263a77256ae | 37 | |
bogdanm | 20:4263a77256ae | 38 | uint32_t port_index = (uint32_t) pin >> 4; |
bogdanm | 20:4263a77256ae | 39 | |
bogdanm | 20:4263a77256ae | 40 | GPIO_TypeDef *port_reg = (GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)); |
bogdanm | 20:4263a77256ae | 41 | obj->reg_mode = &port_reg->MODER; |
bogdanm | 20:4263a77256ae | 42 | obj->reg_set = &port_reg->BSRRL; |
bogdanm | 20:4263a77256ae | 43 | obj->reg_clr = &port_reg->BSRRH; |
bogdanm | 20:4263a77256ae | 44 | obj->reg_in = &port_reg->IDR; |
bogdanm | 20:4263a77256ae | 45 | } |
bogdanm | 20:4263a77256ae | 46 | |
bogdanm | 20:4263a77256ae | 47 | void gpio_mode(gpio_t *obj, PinMode mode) { |
bogdanm | 20:4263a77256ae | 48 | pin_mode(obj->pin, mode); |
bogdanm | 20:4263a77256ae | 49 | } |
bogdanm | 20:4263a77256ae | 50 | |
bogdanm | 20:4263a77256ae | 51 | void gpio_dir(gpio_t *obj, PinDirection direction) { |
mbed_official | 227:7bd0639b8911 | 52 | MBED_ASSERT(obj->pin != (PinName)NC); |
bogdanm | 20:4263a77256ae | 53 | switch (direction) { |
mbed_official | 227:7bd0639b8911 | 54 | case PIN_INPUT : |
mbed_official | 227:7bd0639b8911 | 55 | pin_function(obj->pin, STM_PIN_DATA(0, 0)); |
mbed_official | 227:7bd0639b8911 | 56 | break; |
mbed_official | 227:7bd0639b8911 | 57 | case PIN_OUTPUT: |
mbed_official | 227:7bd0639b8911 | 58 | pin_function(obj->pin, STM_PIN_DATA(1, 0)); |
mbed_official | 227:7bd0639b8911 | 59 | break; |
bogdanm | 20:4263a77256ae | 60 | } |
bogdanm | 20:4263a77256ae | 61 | } |