test

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Nov 08 13:50:44 2017 +0000
Revision:
178:d650f5d4c87a
Parent:
150:02e0a0aed4ec
This updates the lib to the mbed lib v 155

Who changed what in which revision?

UserRevisionLine numberNew 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 "gpio_api.h"
<> 150:02e0a0aed4ec 36 #include "pinmap.h"
<> 150:02e0a0aed4ec 37 #include "gpio_regs.h"
<> 150:02e0a0aed4ec 38 #include "clkman_regs.h"
<> 150:02e0a0aed4ec 39
<> 150:02e0a0aed4ec 40 uint32_t gpio_set(PinName name)
<> 150:02e0a0aed4ec 41 {
<> 150:02e0a0aed4ec 42 MBED_ASSERT(name != (PinName)NC);
<> 150:02e0a0aed4ec 43 pin_function(name, 0);
<> 150:02e0a0aed4ec 44 return 1 << PINNAME_TO_PIN(name);
<> 150:02e0a0aed4ec 45 }
<> 150:02e0a0aed4ec 46
<> 150:02e0a0aed4ec 47 void gpio_init(gpio_t *obj, PinName name)
<> 150:02e0a0aed4ec 48 {
<> 150:02e0a0aed4ec 49 obj->name = name;
<> 150:02e0a0aed4ec 50 if (name == (PinName)NC) {
<> 150:02e0a0aed4ec 51 return;
<> 150:02e0a0aed4ec 52 }
<> 150:02e0a0aed4ec 53
<> 150:02e0a0aed4ec 54 unsigned int port = PINNAME_TO_PORT(name);
<> 150:02e0a0aed4ec 55 unsigned int pin = PINNAME_TO_PIN(name);
<> 150:02e0a0aed4ec 56
<> 150:02e0a0aed4ec 57 obj->reg_out = (uint32_t*)BITBAND(&MXC_GPIO->out_val[port], pin);
<> 150:02e0a0aed4ec 58 obj->reg_in = (uint32_t*)BITBAND(&MXC_GPIO->in_val[port], pin);
<> 150:02e0a0aed4ec 59 obj->mode = PullDefault;
<> 150:02e0a0aed4ec 60
<> 150:02e0a0aed4ec 61 /* Ensure that the GPIO clock is enabled */
<> 150:02e0a0aed4ec 62 MXC_CLKMAN->clk_gate_ctrl1 |= MXC_F_CLKMAN_CLK_GATE_CTRL1_GPIO_CLK_GATER;
<> 150:02e0a0aed4ec 63
<> 150:02e0a0aed4ec 64 /* Ensure that the GPIO clock is enabled */
<> 150:02e0a0aed4ec 65 MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1;
<> 150:02e0a0aed4ec 66 }
<> 150:02e0a0aed4ec 67
<> 150:02e0a0aed4ec 68 void gpio_mode(gpio_t *obj, PinMode mode)
<> 150:02e0a0aed4ec 69 {
<> 150:02e0a0aed4ec 70 obj->mode = mode;
<> 150:02e0a0aed4ec 71 pin_mode(obj->name, mode);
<> 150:02e0a0aed4ec 72 }
<> 150:02e0a0aed4ec 73
<> 150:02e0a0aed4ec 74 void pin_dir_mode(PinName name, PinDirection direction, PinMode mode)
<> 150:02e0a0aed4ec 75 {
<> 150:02e0a0aed4ec 76 MBED_ASSERT(name != (PinName)NC);
<> 150:02e0a0aed4ec 77
<> 150:02e0a0aed4ec 78 unsigned int port = PINNAME_TO_PORT(name);
<> 150:02e0a0aed4ec 79 unsigned int pin = PINNAME_TO_PIN(name);
<> 150:02e0a0aed4ec 80
<> 150:02e0a0aed4ec 81 /* Set function; Firmware Control (GPIO mode) */
<> 150:02e0a0aed4ec 82 MXC_GPIO->func_sel[port] &= ~(0xF << (4 * pin));
<> 150:02e0a0aed4ec 83
<> 150:02e0a0aed4ec 84 /* Normal input is always enabled */
<> 150:02e0a0aed4ec 85 MXC_GPIO->in_mode[port] &= ~(0xF << (4 * pin));
<> 150:02e0a0aed4ec 86
<> 150:02e0a0aed4ec 87 uint32_t new_mode;
<> 150:02e0a0aed4ec 88 if (direction == PIN_OUTPUT) {
<> 150:02e0a0aed4ec 89 // PullUp = not valid,
<> 150:02e0a0aed4ec 90 // PullDown = not valid,
<> 150:02e0a0aed4ec 91 // OpenDrain = MXC_V_GPIO_OUT_MODE_OD,
<> 150:02e0a0aed4ec 92 // PullNone = MXC_V_GPIO_OUT_MODE_NORMAL,
<> 150:02e0a0aed4ec 93 if (mode == OpenDrain) {
<> 150:02e0a0aed4ec 94 new_mode = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN;
<> 150:02e0a0aed4ec 95 } else {
<> 150:02e0a0aed4ec 96 new_mode = MXC_V_GPIO_OUT_MODE_NORMAL;
<> 150:02e0a0aed4ec 97 }
<> 150:02e0a0aed4ec 98 } else {
<> 150:02e0a0aed4ec 99 // PullUp = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP
<> 150:02e0a0aed4ec 100 // PullDown = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN
<> 150:02e0a0aed4ec 101 // OpenDrain = MXC_V_GPIO_OUT_MODE_OD
<> 150:02e0a0aed4ec 102 // PullNone = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z
<> 150:02e0a0aed4ec 103 if (mode == PullUp) {
<> 150:02e0a0aed4ec 104 new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP;
<> 150:02e0a0aed4ec 105 MXC_GPIO->out_val[port] |= 1 << pin;
<> 150:02e0a0aed4ec 106 } else if (mode == PullDown) {
<> 150:02e0a0aed4ec 107 new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN;
<> 150:02e0a0aed4ec 108 MXC_GPIO->out_val[port] &= ~(1 << pin);
<> 150:02e0a0aed4ec 109 } else if (mode == OpenDrain) {
<> 150:02e0a0aed4ec 110 new_mode = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN;
<> 150:02e0a0aed4ec 111 MXC_GPIO->out_val[port] |= 1 << pin;
<> 150:02e0a0aed4ec 112 } else {
<> 150:02e0a0aed4ec 113 new_mode = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z;
<> 150:02e0a0aed4ec 114 MXC_GPIO->out_val[port] &= ~(1 << pin);
<> 150:02e0a0aed4ec 115 }
<> 150:02e0a0aed4ec 116 }
<> 150:02e0a0aed4ec 117
<> 150:02e0a0aed4ec 118 /* Set new mode */
<> 150:02e0a0aed4ec 119 uint32_t out_mode = MXC_GPIO->out_mode[port];
<> 150:02e0a0aed4ec 120 out_mode &= ~(0xF << (pin * 4));
<> 150:02e0a0aed4ec 121 out_mode |= (new_mode << (pin * 4));
<> 150:02e0a0aed4ec 122 MXC_GPIO->out_mode[port] = out_mode;
<> 150:02e0a0aed4ec 123 }
<> 150:02e0a0aed4ec 124
<> 150:02e0a0aed4ec 125 void gpio_dir(gpio_t *obj, PinDirection direction)
<> 150:02e0a0aed4ec 126 {
<> 150:02e0a0aed4ec 127 pin_dir_mode(obj->name, direction, obj->mode);
<> 150:02e0a0aed4ec 128 }