]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4XX/gpio_api.c
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"
20 uint32_t gpio_set(PinName pin
) {
21 MBED_ASSERT(pin
!= (PinName
)NC
);
22 uint32_t port_index
= (uint32_t) pin
>> 4;
24 // Enable GPIO peripheral clock
25 RCC
->AHB1ENR
|= 1 << port_index
;
27 pin_function(pin
, STM_PIN_DATA(0, 0));
28 return 1 << ((uint32_t) pin
& 0xF);
31 void gpio_init(gpio_t
*obj
, PinName pin
) {
33 if (pin
== (PinName
)NC
)
36 obj
->mask
= gpio_set(pin
);
38 uint32_t port_index
= (uint32_t) pin
>> 4;
40 GPIO_TypeDef
*port_reg
= (GPIO_TypeDef
*) (GPIOA_BASE
+ (port_index
<< 10));
41 obj
->reg_mode
= &port_reg
->MODER
;
42 obj
->reg_set
= &port_reg
->BSRRL
;
43 obj
->reg_clr
= &port_reg
->BSRRH
;
44 obj
->reg_in
= &port_reg
->IDR
;
47 void gpio_mode(gpio_t
*obj
, PinMode mode
) {
48 pin_mode(obj
->pin
, mode
);
51 void gpio_dir(gpio_t
*obj
, PinDirection direction
) {
52 MBED_ASSERT(obj
->pin
!= (PinName
)NC
);
55 pin_function(obj
->pin
, STM_PIN_DATA(0, 0));
58 pin_function(obj
->pin
, STM_PIN_DATA(1, 0));