mbed library sources change for ST sensors and ST BLE
Fork of mbed-src by
targets/hal/TARGET_STM/TARGET_STM32F4XX/pinmap.c@636:83ea0d2b909b, 2016-04-14 (annotated)
- Committer:
- NickZhouARM
- Date:
- Thu Apr 14 07:07:44 2016 +0000
- Revision:
- 636:83ea0d2b909b
- Parent:
- 285:31249416b6f9
Working version for ST BLE + Sensors
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 "pinmap.h" |
mbed_official | 285:31249416b6f9 | 18 | #include "mbed_error.h" |
bogdanm | 20:4263a77256ae | 19 | |
bogdanm | 20:4263a77256ae | 20 | /** |
bogdanm | 20:4263a77256ae | 21 | * Set the pin into input, output, alternate function or analog mode |
bogdanm | 20:4263a77256ae | 22 | */ |
bogdanm | 20:4263a77256ae | 23 | void pin_function(PinName pin, int data) { |
mbed_official | 227:7bd0639b8911 | 24 | MBED_ASSERT(pin != (PinName)NC); |
bogdanm | 20:4263a77256ae | 25 | |
bogdanm | 20:4263a77256ae | 26 | int mode = STM_PIN_MODE(data); |
bogdanm | 20:4263a77256ae | 27 | int func = STM_PIN_FUNC(data); |
bogdanm | 20:4263a77256ae | 28 | |
bogdanm | 20:4263a77256ae | 29 | uint32_t pin_number = (uint32_t)pin; |
bogdanm | 20:4263a77256ae | 30 | int port_index = pin_number >> 4; |
bogdanm | 20:4263a77256ae | 31 | int pin_index = (pin_number & 0xF); |
bogdanm | 20:4263a77256ae | 32 | GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10))); |
bogdanm | 20:4263a77256ae | 33 | |
bogdanm | 20:4263a77256ae | 34 | // MODE |
bogdanm | 20:4263a77256ae | 35 | int offset = pin_index << 1; |
bogdanm | 20:4263a77256ae | 36 | gpio->MODER &= ~(0x3 << offset); |
bogdanm | 20:4263a77256ae | 37 | gpio->MODER |= mode << offset; |
bogdanm | 20:4263a77256ae | 38 | |
bogdanm | 20:4263a77256ae | 39 | // Set high-speed mode |
bogdanm | 20:4263a77256ae | 40 | gpio->OSPEEDR &= ~(0x3 << offset); |
bogdanm | 20:4263a77256ae | 41 | gpio->OSPEEDR |= (0x2 << offset); |
bogdanm | 20:4263a77256ae | 42 | |
bogdanm | 20:4263a77256ae | 43 | // FUNCTION |
bogdanm | 20:4263a77256ae | 44 | // Bottom seven pins are in AFR[0], top seven in AFR[1] |
bogdanm | 20:4263a77256ae | 45 | offset = (pin_index & 0x7) << 2; |
bogdanm | 20:4263a77256ae | 46 | if (pin_index <= 0x7) { |
bogdanm | 20:4263a77256ae | 47 | gpio->AFR[0] &= ~(0xF << offset); |
bogdanm | 20:4263a77256ae | 48 | gpio->AFR[0] |= func << offset; |
bogdanm | 20:4263a77256ae | 49 | } |
bogdanm | 20:4263a77256ae | 50 | else { |
bogdanm | 20:4263a77256ae | 51 | gpio->AFR[1] &= ~(0xF << offset); |
bogdanm | 20:4263a77256ae | 52 | gpio->AFR[1] |= func << offset; |
bogdanm | 20:4263a77256ae | 53 | } |
bogdanm | 20:4263a77256ae | 54 | } |
bogdanm | 20:4263a77256ae | 55 | |
bogdanm | 20:4263a77256ae | 56 | void pin_mode(PinName pin, PinMode mode) { |
mbed_official | 227:7bd0639b8911 | 57 | MBED_ASSERT(pin != (PinName)NC); |
bogdanm | 20:4263a77256ae | 58 | |
bogdanm | 20:4263a77256ae | 59 | uint32_t pin_number = (uint32_t)pin; |
bogdanm | 20:4263a77256ae | 60 | int port_index = pin_number >> 4; |
bogdanm | 20:4263a77256ae | 61 | int pin_index = (pin_number & 0xF); |
bogdanm | 20:4263a77256ae | 62 | int offset = pin_index << 1; |
bogdanm | 20:4263a77256ae | 63 | |
bogdanm | 20:4263a77256ae | 64 | GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10))); |
bogdanm | 20:4263a77256ae | 65 | if (mode == OpenDrain) { |
bogdanm | 20:4263a77256ae | 66 | gpio->OTYPER |= 1 << pin_index; |
bogdanm | 20:4263a77256ae | 67 | } |
bogdanm | 20:4263a77256ae | 68 | else { |
bogdanm | 20:4263a77256ae | 69 | gpio->OTYPER &= ~(1 << pin_index); |
bogdanm | 20:4263a77256ae | 70 | gpio->PUPDR &= ~(0x3 << offset); |
bogdanm | 20:4263a77256ae | 71 | gpio->PUPDR |= mode << offset; |
bogdanm | 20:4263a77256ae | 72 | } |
bogdanm | 20:4263a77256ae | 73 | } |
bogdanm | 20:4263a77256ae | 74 |