5.2.1 - Updated I2C files
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
targets/TARGET_Maxim/TARGET_MAX32620/pinmap.c@1:f30bdcd2b33b, 2017-02-27 (annotated)
- Committer:
- jacobjohnson
- Date:
- Mon Feb 27 17:45:05 2017 +0000
- Revision:
- 1:f30bdcd2b33b
- Parent:
- 0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c. This will need to be changed later, and accessed from the main level, but for now this allows the adc to read a value from 0 to 3.7V, instead of just up to 1V.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | /******************************************************************************* |
group-onsemi | 0:098463de4c5d | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
group-onsemi | 0:098463de4c5d | 3 | * |
group-onsemi | 0:098463de4c5d | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
group-onsemi | 0:098463de4c5d | 5 | * copy of this software and associated documentation files (the "Software"), |
group-onsemi | 0:098463de4c5d | 6 | * to deal in the Software without restriction, including without limitation |
group-onsemi | 0:098463de4c5d | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
group-onsemi | 0:098463de4c5d | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
group-onsemi | 0:098463de4c5d | 9 | * Software is furnished to do so, subject to the following conditions: |
group-onsemi | 0:098463de4c5d | 10 | * |
group-onsemi | 0:098463de4c5d | 11 | * The above copyright notice and this permission notice shall be included |
group-onsemi | 0:098463de4c5d | 12 | * in all copies or substantial portions of the Software. |
group-onsemi | 0:098463de4c5d | 13 | * |
group-onsemi | 0:098463de4c5d | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
group-onsemi | 0:098463de4c5d | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
group-onsemi | 0:098463de4c5d | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
group-onsemi | 0:098463de4c5d | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
group-onsemi | 0:098463de4c5d | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
group-onsemi | 0:098463de4c5d | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
group-onsemi | 0:098463de4c5d | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
group-onsemi | 0:098463de4c5d | 21 | * |
group-onsemi | 0:098463de4c5d | 22 | * Except as contained in this notice, the name of Maxim Integrated |
group-onsemi | 0:098463de4c5d | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
group-onsemi | 0:098463de4c5d | 24 | * Products, Inc. Branding Policy. |
group-onsemi | 0:098463de4c5d | 25 | * |
group-onsemi | 0:098463de4c5d | 26 | * The mere transfer of this software does not imply any licenses |
group-onsemi | 0:098463de4c5d | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
group-onsemi | 0:098463de4c5d | 28 | * trademarks, maskwork rights, or any other form of intellectual |
group-onsemi | 0:098463de4c5d | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
group-onsemi | 0:098463de4c5d | 30 | * ownership rights. |
group-onsemi | 0:098463de4c5d | 31 | ******************************************************************************* |
group-onsemi | 0:098463de4c5d | 32 | */ |
group-onsemi | 0:098463de4c5d | 33 | |
group-onsemi | 0:098463de4c5d | 34 | #include "mbed_assert.h" |
group-onsemi | 0:098463de4c5d | 35 | #include "pinmap.h" |
group-onsemi | 0:098463de4c5d | 36 | #include "objects.h" |
group-onsemi | 0:098463de4c5d | 37 | #include "gpio_regs.h" |
group-onsemi | 0:098463de4c5d | 38 | #include "ioman_regs.h" |
group-onsemi | 0:098463de4c5d | 39 | |
group-onsemi | 0:098463de4c5d | 40 | void pin_function(PinName name, int function) |
group-onsemi | 0:098463de4c5d | 41 | { |
group-onsemi | 0:098463de4c5d | 42 | MBED_ASSERT(name != (PinName)NC); |
group-onsemi | 0:098463de4c5d | 43 | |
group-onsemi | 0:098463de4c5d | 44 | if ((function >= 0) && (function <= 0xF)) { |
group-onsemi | 0:098463de4c5d | 45 | unsigned int port = PINNAME_TO_PORT(name); |
group-onsemi | 0:098463de4c5d | 46 | unsigned int pin = PINNAME_TO_PIN(name); |
group-onsemi | 0:098463de4c5d | 47 | uint32_t temp = MXC_GPIO->func_sel[port] & ~(0xF << (pin*4)); |
group-onsemi | 0:098463de4c5d | 48 | MXC_GPIO->func_sel[port] = temp | ((uint32_t)function << (pin*4)); |
group-onsemi | 0:098463de4c5d | 49 | } else { |
group-onsemi | 0:098463de4c5d | 50 | /* Assume this is a pointer to a pin function object */ |
group-onsemi | 0:098463de4c5d | 51 | pin_function_t *obj = (pin_function_t*)function; |
group-onsemi | 0:098463de4c5d | 52 | |
group-onsemi | 0:098463de4c5d | 53 | if ((*obj->reg_ack & obj->ack_mask) != obj->req_val) { |
group-onsemi | 0:098463de4c5d | 54 | /* Request pin mapping */ |
group-onsemi | 0:098463de4c5d | 55 | *obj->reg_req |= obj->req_val; |
group-onsemi | 0:098463de4c5d | 56 | |
group-onsemi | 0:098463de4c5d | 57 | /* Check for acknowledgment */ |
group-onsemi | 0:098463de4c5d | 58 | MBED_ASSERT((*obj->reg_ack & obj->ack_mask) == obj->req_val); |
group-onsemi | 0:098463de4c5d | 59 | } |
group-onsemi | 0:098463de4c5d | 60 | } |
group-onsemi | 0:098463de4c5d | 61 | } |
group-onsemi | 0:098463de4c5d | 62 | |
group-onsemi | 0:098463de4c5d | 63 | void pin_mode(PinName name, PinMode mode) |
group-onsemi | 0:098463de4c5d | 64 | { |
group-onsemi | 0:098463de4c5d | 65 | MBED_ASSERT(name != (PinName)NC); |
group-onsemi | 0:098463de4c5d | 66 | unsigned int port = PINNAME_TO_PORT(name); |
group-onsemi | 0:098463de4c5d | 67 | unsigned int pin = PINNAME_TO_PIN(name); |
group-onsemi | 0:098463de4c5d | 68 | |
group-onsemi | 0:098463de4c5d | 69 | /* Must set mode while retaining direction */ |
group-onsemi | 0:098463de4c5d | 70 | |
group-onsemi | 0:098463de4c5d | 71 | /* Get the current direction */ |
group-onsemi | 0:098463de4c5d | 72 | uint32_t out_mode = MXC_GPIO->out_mode[port]; |
group-onsemi | 0:098463de4c5d | 73 | uint32_t curr_mode = (out_mode >> (pin * 4)) & 0xF; |
group-onsemi | 0:098463de4c5d | 74 | PinDirection dir = PIN_OUTPUT; |
group-onsemi | 0:098463de4c5d | 75 | if ((curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP) || |
group-onsemi | 0:098463de4c5d | 76 | (curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN) || |
group-onsemi | 0:098463de4c5d | 77 | (curr_mode == MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z)) { |
group-onsemi | 0:098463de4c5d | 78 | dir = PIN_INPUT; |
group-onsemi | 0:098463de4c5d | 79 | } |
group-onsemi | 0:098463de4c5d | 80 | |
group-onsemi | 0:098463de4c5d | 81 | /* Set mode based on current direction */ |
group-onsemi | 0:098463de4c5d | 82 | uint32_t new_mode; |
group-onsemi | 0:098463de4c5d | 83 | if (dir == PIN_OUTPUT) { |
group-onsemi | 0:098463de4c5d | 84 | // PullUp = not valid, |
group-onsemi | 0:098463de4c5d | 85 | // PullDown = not valid, |
group-onsemi | 0:098463de4c5d | 86 | // OpenDrain = MXC_V_GPIO_OUT_MODE_OD, |
group-onsemi | 0:098463de4c5d | 87 | // PullNone = MXC_V_GPIO_OUT_MODE_NORMAL, |
group-onsemi | 0:098463de4c5d | 88 | if (mode == OpenDrain) { |
group-onsemi | 0:098463de4c5d | 89 | new_mode = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN; |
group-onsemi | 0:098463de4c5d | 90 | } else { |
group-onsemi | 0:098463de4c5d | 91 | new_mode = MXC_V_GPIO_OUT_MODE_NORMAL; |
group-onsemi | 0:098463de4c5d | 92 | } |
group-onsemi | 0:098463de4c5d | 93 | } else { |
group-onsemi | 0:098463de4c5d | 94 | // PullUp = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP |
group-onsemi | 0:098463de4c5d | 95 | // PullDown = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN |
group-onsemi | 0:098463de4c5d | 96 | // OpenDrain = MXC_V_GPIO_OUT_MODE_OD |
group-onsemi | 0:098463de4c5d | 97 | // PullNone = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z |
group-onsemi | 0:098463de4c5d | 98 | if (mode == PullUp) { |
group-onsemi | 0:098463de4c5d | 99 | new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP; |
group-onsemi | 0:098463de4c5d | 100 | MXC_GPIO->out_val[port] |= 1 << pin; |
group-onsemi | 0:098463de4c5d | 101 | } else if (mode == PullDown) { |
group-onsemi | 0:098463de4c5d | 102 | new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN; |
group-onsemi | 0:098463de4c5d | 103 | MXC_GPIO->out_val[port] &= ~(1 << pin); |
group-onsemi | 0:098463de4c5d | 104 | } else if (mode == OpenDrain) { |
group-onsemi | 0:098463de4c5d | 105 | new_mode = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN; |
group-onsemi | 0:098463de4c5d | 106 | MXC_GPIO->out_val[port] |= 1 << pin; |
group-onsemi | 0:098463de4c5d | 107 | } else { |
group-onsemi | 0:098463de4c5d | 108 | new_mode = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z; |
group-onsemi | 0:098463de4c5d | 109 | MXC_GPIO->out_val[port] &= ~(1 << pin); |
group-onsemi | 0:098463de4c5d | 110 | } |
group-onsemi | 0:098463de4c5d | 111 | } |
group-onsemi | 0:098463de4c5d | 112 | |
group-onsemi | 0:098463de4c5d | 113 | /* Set new mode */ |
group-onsemi | 0:098463de4c5d | 114 | out_mode &= ~(0xF << (pin * 4)); |
group-onsemi | 0:098463de4c5d | 115 | out_mode |= (new_mode << (pin * 4)); |
group-onsemi | 0:098463de4c5d | 116 | MXC_GPIO->out_mode[port] = out_mode; |
group-onsemi | 0:098463de4c5d | 117 | } |