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