BA / Mbed OS BaBoRo1
Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2006-2015 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 5 * you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 6 * You may obtain a copy of the License at
borlanic 0:380207fcb5c1 7 *
borlanic 0:380207fcb5c1 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 9 *
borlanic 0:380207fcb5c1 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 13 * See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 14 * limitations under the License.
borlanic 0:380207fcb5c1 15 */
borlanic 0:380207fcb5c1 16 #include "mbed_assert.h"
borlanic 0:380207fcb5c1 17 #include "gpio_api.h"
borlanic 0:380207fcb5c1 18 #include "pinmap.h"
borlanic 0:380207fcb5c1 19
borlanic 0:380207fcb5c1 20 uint32_t gpio_set(PinName pin) {
borlanic 0:380207fcb5c1 21 MBED_ASSERT(pin != (PinName)NC);
borlanic 0:380207fcb5c1 22 pin_function(pin, 1);
borlanic 0:380207fcb5c1 23 return 1 << ((pin & 0x7F) >> 2);
borlanic 0:380207fcb5c1 24 }
borlanic 0:380207fcb5c1 25
borlanic 0:380207fcb5c1 26 void gpio_init(gpio_t *obj, PinName pin) {
borlanic 0:380207fcb5c1 27 obj->pin = pin;
borlanic 0:380207fcb5c1 28 if (pin == (PinName)NC)
borlanic 0:380207fcb5c1 29 return;
borlanic 0:380207fcb5c1 30
borlanic 0:380207fcb5c1 31 obj->mask = gpio_set(pin);
borlanic 0:380207fcb5c1 32
borlanic 0:380207fcb5c1 33 unsigned int port = (unsigned int)pin >> PORT_SHIFT;
borlanic 0:380207fcb5c1 34
borlanic 0:380207fcb5c1 35 GPIO_Type *reg = (GPIO_Type *)(PTA_BASE + port * 0x40);
borlanic 0:380207fcb5c1 36 obj->reg_set = &reg->PSOR;
borlanic 0:380207fcb5c1 37 obj->reg_clr = &reg->PCOR;
borlanic 0:380207fcb5c1 38 obj->reg_in = &reg->PDIR;
borlanic 0:380207fcb5c1 39 obj->reg_dir = &reg->PDDR;
borlanic 0:380207fcb5c1 40 }
borlanic 0:380207fcb5c1 41
borlanic 0:380207fcb5c1 42 void gpio_mode(gpio_t *obj, PinMode mode) {
borlanic 0:380207fcb5c1 43 pin_mode(obj->pin, mode);
borlanic 0:380207fcb5c1 44 }
borlanic 0:380207fcb5c1 45
borlanic 0:380207fcb5c1 46 void gpio_dir(gpio_t *obj, PinDirection direction) {
borlanic 0:380207fcb5c1 47 MBED_ASSERT(obj->pin != (PinName)NC);
borlanic 0:380207fcb5c1 48 switch (direction) {
borlanic 0:380207fcb5c1 49 case PIN_INPUT :
borlanic 0:380207fcb5c1 50 *obj->reg_dir &= ~obj->mask;
borlanic 0:380207fcb5c1 51 break;
borlanic 0:380207fcb5c1 52 case PIN_OUTPUT:
borlanic 0:380207fcb5c1 53 *obj->reg_dir |= obj->mask;
borlanic 0:380207fcb5c1 54 break;
borlanic 0:380207fcb5c1 55 }
borlanic 0:380207fcb5c1 56 }