mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins

Dependents:   IGLOO_board

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Thu Apr 19 17:12:19 2018 +0100
Revision:
184:08ed48f1de7f
mbed-dev library. Release version 161

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 184:08ed48f1de7f 1 /* mbed Microcontroller Library
AnnaBridge 184:08ed48f1de7f 2 * (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2017 All rights reserved
AnnaBridge 184:08ed48f1de7f 3 *
AnnaBridge 184:08ed48f1de7f 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 184:08ed48f1de7f 5 * you may not use this file except in compliance with the License.
AnnaBridge 184:08ed48f1de7f 6 * You may obtain a copy of the License at
AnnaBridge 184:08ed48f1de7f 7 *
AnnaBridge 184:08ed48f1de7f 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 184:08ed48f1de7f 9 *
AnnaBridge 184:08ed48f1de7f 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 184:08ed48f1de7f 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 184:08ed48f1de7f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 184:08ed48f1de7f 13 * See the License for the specific language governing permissions and
AnnaBridge 184:08ed48f1de7f 14 * limitations under the License.
AnnaBridge 184:08ed48f1de7f 15 */
AnnaBridge 184:08ed48f1de7f 16 #include "gpio_api.h"
AnnaBridge 184:08ed48f1de7f 17 #include "PeripheralNames.h"
AnnaBridge 184:08ed48f1de7f 18 #include "pinmap.h"
AnnaBridge 184:08ed48f1de7f 19 #include "mbed_error.h"
AnnaBridge 184:08ed48f1de7f 20
AnnaBridge 184:08ed48f1de7f 21 #define GPIO_DATA PIN_DATA(0, 3)
AnnaBridge 184:08ed48f1de7f 22 extern const PinMap PinMap_GPIO_IRQ[];
AnnaBridge 184:08ed48f1de7f 23
AnnaBridge 184:08ed48f1de7f 24 uint32_t gpio_set(PinName pin)
AnnaBridge 184:08ed48f1de7f 25 {
AnnaBridge 184:08ed48f1de7f 26 // Check that pin is valid
AnnaBridge 184:08ed48f1de7f 27 MBED_ASSERT(pin != (PinName)NC);
AnnaBridge 184:08ed48f1de7f 28
AnnaBridge 184:08ed48f1de7f 29 // Set pin function as GPIO pin
AnnaBridge 184:08ed48f1de7f 30 pin_function(pin, GPIO_DATA);
AnnaBridge 184:08ed48f1de7f 31
AnnaBridge 184:08ed48f1de7f 32 // Return pin mask
AnnaBridge 184:08ed48f1de7f 33 return (1 << (pin & 0x07));
AnnaBridge 184:08ed48f1de7f 34 }
AnnaBridge 184:08ed48f1de7f 35
AnnaBridge 184:08ed48f1de7f 36 void gpio_init(gpio_t *obj, PinName pin)
AnnaBridge 184:08ed48f1de7f 37 {
AnnaBridge 184:08ed48f1de7f 38 // Store above pin mask, pin name into GPIO object
AnnaBridge 184:08ed48f1de7f 39 obj->pin = pin;
AnnaBridge 184:08ed48f1de7f 40 obj->mask = gpio_set(pin);
AnnaBridge 184:08ed48f1de7f 41 obj->port = (GPIO_Port) (pin >> 3);
AnnaBridge 184:08ed48f1de7f 42 CG_SetFcPeriphA((1 << obj->port), ENABLE);
AnnaBridge 184:08ed48f1de7f 43 }
AnnaBridge 184:08ed48f1de7f 44
AnnaBridge 184:08ed48f1de7f 45 void gpio_mode(gpio_t *obj, PinMode mode)
AnnaBridge 184:08ed48f1de7f 46 {
AnnaBridge 184:08ed48f1de7f 47 // Set pin mode
AnnaBridge 184:08ed48f1de7f 48 pin_mode(obj->pin, mode);
AnnaBridge 184:08ed48f1de7f 49 }
AnnaBridge 184:08ed48f1de7f 50
AnnaBridge 184:08ed48f1de7f 51 // Set gpio object pin direction
AnnaBridge 184:08ed48f1de7f 52 void gpio_dir(gpio_t *obj, PinDirection direction)
AnnaBridge 184:08ed48f1de7f 53 {
AnnaBridge 184:08ed48f1de7f 54 // Set direction
AnnaBridge 184:08ed48f1de7f 55 switch (direction) {
AnnaBridge 184:08ed48f1de7f 56 case PIN_INPUT:
AnnaBridge 184:08ed48f1de7f 57 // Set pin input
AnnaBridge 184:08ed48f1de7f 58 GPIO_SetInput(obj->port, obj->mask);
AnnaBridge 184:08ed48f1de7f 59 break;
AnnaBridge 184:08ed48f1de7f 60 case PIN_OUTPUT:
AnnaBridge 184:08ed48f1de7f 61 // Set pin output
AnnaBridge 184:08ed48f1de7f 62 GPIO_SetOutput(obj->port, obj->mask);
AnnaBridge 184:08ed48f1de7f 63 break;
AnnaBridge 184:08ed48f1de7f 64 case PIN_INOUT:
AnnaBridge 184:08ed48f1de7f 65 // Set pin both input and output
AnnaBridge 184:08ed48f1de7f 66 GPIO_SetOutputEnableReg(obj->port, obj->mask, ENABLE);
AnnaBridge 184:08ed48f1de7f 67 GPIO_SetInputEnableReg(obj->port, obj->mask, ENABLE);
AnnaBridge 184:08ed48f1de7f 68 break;
AnnaBridge 184:08ed48f1de7f 69 default:
AnnaBridge 184:08ed48f1de7f 70 error("Invalid direction\n");
AnnaBridge 184:08ed48f1de7f 71 break;
AnnaBridge 184:08ed48f1de7f 72 }
AnnaBridge 184:08ed48f1de7f 73 }
AnnaBridge 184:08ed48f1de7f 74
AnnaBridge 184:08ed48f1de7f 75 void gpio_write(gpio_t *obj, int value)
AnnaBridge 184:08ed48f1de7f 76 {
AnnaBridge 184:08ed48f1de7f 77 // Write gpio object pin data
AnnaBridge 184:08ed48f1de7f 78 if ((value == 0) || (value == 1)) {
AnnaBridge 184:08ed48f1de7f 79 GPIO_WriteDataBit(obj->port, obj->mask, value);
AnnaBridge 184:08ed48f1de7f 80 } else {
AnnaBridge 184:08ed48f1de7f 81 error("Invalid value\n");
AnnaBridge 184:08ed48f1de7f 82 }
AnnaBridge 184:08ed48f1de7f 83 }
AnnaBridge 184:08ed48f1de7f 84
AnnaBridge 184:08ed48f1de7f 85 int gpio_read(gpio_t *obj)
AnnaBridge 184:08ed48f1de7f 86 {
AnnaBridge 184:08ed48f1de7f 87 // Read gpio object pin data
AnnaBridge 184:08ed48f1de7f 88 return GPIO_ReadDataBit(obj->port, obj->mask);
AnnaBridge 184:08ed48f1de7f 89 }