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