Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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