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

Dependents:   IGLOO_board

Fork of mbed-dev by mbed official

Committer:
ua1arn
Date:
Mon Jul 30 12:31:10 2018 +0000
Revision:
188:3f10722804f9
Parent:
186:707f6e361f3e
before add multi-configuration USB descriptors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anna Bridge 186:707f6e361f3e 1 /*******************************************************************************
Anna Bridge 186:707f6e361f3e 2 * Copyright (c) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
Anna Bridge 186:707f6e361f3e 3 *
Anna Bridge 186:707f6e361f3e 4 * Permission is hereby granted, free of charge, to any person obtaining a
Anna Bridge 186:707f6e361f3e 5 * copy of this software and associated documentation files (the "Software"),
Anna Bridge 186:707f6e361f3e 6 * to deal in the Software without restriction, including without limitation
Anna Bridge 186:707f6e361f3e 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Anna Bridge 186:707f6e361f3e 8 * and/or sell copies of the Software, and to permit persons to whom the
Anna Bridge 186:707f6e361f3e 9 * Software is furnished to do so, subject to the following conditions:
Anna Bridge 186:707f6e361f3e 10 *
Anna Bridge 186:707f6e361f3e 11 * The above copyright notice and this permission notice shall be included
Anna Bridge 186:707f6e361f3e 12 * in all copies or substantial portions of the Software.
Anna Bridge 186:707f6e361f3e 13 *
Anna Bridge 186:707f6e361f3e 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Anna Bridge 186:707f6e361f3e 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Anna Bridge 186:707f6e361f3e 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Anna Bridge 186:707f6e361f3e 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Anna Bridge 186:707f6e361f3e 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Anna Bridge 186:707f6e361f3e 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Anna Bridge 186:707f6e361f3e 20 * OTHER DEALINGS IN THE SOFTWARE.
Anna Bridge 186:707f6e361f3e 21 *
Anna Bridge 186:707f6e361f3e 22 * Except as contained in this notice, the name of Maxim Integrated
Anna Bridge 186:707f6e361f3e 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Anna Bridge 186:707f6e361f3e 24 * Products, Inc. Branding Policy.
Anna Bridge 186:707f6e361f3e 25 *
Anna Bridge 186:707f6e361f3e 26 * The mere transfer of this software does not imply any licenses
Anna Bridge 186:707f6e361f3e 27 * of trade secrets, proprietary technology, copyrights, patents,
Anna Bridge 186:707f6e361f3e 28 * trademarks, maskwork rights, or any other form of intellectual
Anna Bridge 186:707f6e361f3e 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
Anna Bridge 186:707f6e361f3e 30 * ownership rights.
Anna Bridge 186:707f6e361f3e 31 *******************************************************************************
Anna Bridge 186:707f6e361f3e 32 */
Anna Bridge 186:707f6e361f3e 33
Anna Bridge 186:707f6e361f3e 34 #include "mbed_assert.h"
Anna Bridge 186:707f6e361f3e 35 #include "pinmap.h"
Anna Bridge 186:707f6e361f3e 36 #include "objects.h"
Anna Bridge 186:707f6e361f3e 37 #include "gpio_regs.h"
Anna Bridge 186:707f6e361f3e 38
Anna Bridge 186:707f6e361f3e 39 void pin_function(PinName name, int function)
Anna Bridge 186:707f6e361f3e 40 {
Anna Bridge 186:707f6e361f3e 41 MBED_ASSERT(name != (PinName)NC);
Anna Bridge 186:707f6e361f3e 42
Anna Bridge 186:707f6e361f3e 43 if ((function >= 0) && (function <= 0xF)) {
Anna Bridge 186:707f6e361f3e 44 unsigned int port = PINNAME_TO_PORT(name);
Anna Bridge 186:707f6e361f3e 45 unsigned int pin = PINNAME_TO_PIN(name);
Anna Bridge 186:707f6e361f3e 46 uint32_t temp = MXC_GPIO->func_sel[port] & ~(0xF << (pin*4));
Anna Bridge 186:707f6e361f3e 47 MXC_GPIO->func_sel[port] = temp | ((uint32_t)function << (pin*4));
Anna Bridge 186:707f6e361f3e 48 } else {
Anna Bridge 186:707f6e361f3e 49 /* Assume this is a pointer to a pin function object */
Anna Bridge 186:707f6e361f3e 50 pin_function_t *obj = (pin_function_t*)function;
Anna Bridge 186:707f6e361f3e 51
Anna Bridge 186:707f6e361f3e 52 if ((*obj->reg_ack & obj->ack_mask) != obj->req_val) {
Anna Bridge 186:707f6e361f3e 53 /* Request pin mapping */
Anna Bridge 186:707f6e361f3e 54 *obj->reg_req |= obj->req_val;
Anna Bridge 186:707f6e361f3e 55
Anna Bridge 186:707f6e361f3e 56 /* Check for acknowledgment */
Anna Bridge 186:707f6e361f3e 57 MBED_ASSERT((*obj->reg_ack & obj->ack_mask) == obj->req_val);
Anna Bridge 186:707f6e361f3e 58 }
Anna Bridge 186:707f6e361f3e 59 }
Anna Bridge 186:707f6e361f3e 60 }
Anna Bridge 186:707f6e361f3e 61
Anna Bridge 186:707f6e361f3e 62 void pin_mode(PinName name, PinMode mode)
Anna Bridge 186:707f6e361f3e 63 {
Anna Bridge 186:707f6e361f3e 64 MBED_ASSERT(name != (PinName)NC);
Anna Bridge 186:707f6e361f3e 65 unsigned int port = PINNAME_TO_PORT(name);
Anna Bridge 186:707f6e361f3e 66 unsigned int pin = PINNAME_TO_PIN(name);
Anna Bridge 186:707f6e361f3e 67
Anna Bridge 186:707f6e361f3e 68 /* Must set mode while retaining direction */
Anna Bridge 186:707f6e361f3e 69
Anna Bridge 186:707f6e361f3e 70 /* Get the current direction */
Anna Bridge 186:707f6e361f3e 71 uint32_t curr_mode = (MXC_GPIO->out_mode[port] >> (pin * 4)) & 0xF;
Anna Bridge 186:707f6e361f3e 72 PinDirection direction = PIN_OUTPUT;
Anna Bridge 186:707f6e361f3e 73 if ((curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP) ||
Anna Bridge 186:707f6e361f3e 74 (curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN) ||
Anna Bridge 186:707f6e361f3e 75 (curr_mode == MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z)) {
Anna Bridge 186:707f6e361f3e 76 direction = PIN_INPUT;
Anna Bridge 186:707f6e361f3e 77 }
Anna Bridge 186:707f6e361f3e 78
Anna Bridge 186:707f6e361f3e 79 /* Set mode based on current direction */
Anna Bridge 186:707f6e361f3e 80 pin_dir_mode(name, direction, mode);
Anna Bridge 186:707f6e361f3e 81 }