test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

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