Greg Steiert / maxim_dev

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:0e018d759a2a 1 /*******************************************************************************
switches 0:0e018d759a2a 2 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
switches 0:0e018d759a2a 3 *
switches 0:0e018d759a2a 4 * Permission is hereby granted, free of charge, to any person obtaining a
switches 0:0e018d759a2a 5 * copy of this software and associated documentation files (the "Software"),
switches 0:0e018d759a2a 6 * to deal in the Software without restriction, including without limitation
switches 0:0e018d759a2a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
switches 0:0e018d759a2a 8 * and/or sell copies of the Software, and to permit persons to whom the
switches 0:0e018d759a2a 9 * Software is furnished to do so, subject to the following conditions:
switches 0:0e018d759a2a 10 *
switches 0:0e018d759a2a 11 * The above copyright notice and this permission notice shall be included
switches 0:0e018d759a2a 12 * in all copies or substantial portions of the Software.
switches 0:0e018d759a2a 13 *
switches 0:0e018d759a2a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
switches 0:0e018d759a2a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
switches 0:0e018d759a2a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
switches 0:0e018d759a2a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
switches 0:0e018d759a2a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
switches 0:0e018d759a2a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
switches 0:0e018d759a2a 20 * OTHER DEALINGS IN THE SOFTWARE.
switches 0:0e018d759a2a 21 *
switches 0:0e018d759a2a 22 * Except as contained in this notice, the name of Maxim Integrated
switches 0:0e018d759a2a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
switches 0:0e018d759a2a 24 * Products, Inc. Branding Policy.
switches 0:0e018d759a2a 25 *
switches 0:0e018d759a2a 26 * The mere transfer of this software does not imply any licenses
switches 0:0e018d759a2a 27 * of trade secrets, proprietary technology, copyrights, patents,
switches 0:0e018d759a2a 28 * trademarks, maskwork rights, or any other form of intellectual
switches 0:0e018d759a2a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
switches 0:0e018d759a2a 30 * ownership rights.
switches 0:0e018d759a2a 31 *******************************************************************************
switches 0:0e018d759a2a 32 */
switches 0:0e018d759a2a 33
switches 0:0e018d759a2a 34 #include "mbed_assert.h"
switches 0:0e018d759a2a 35 #include "gpio_api.h"
switches 0:0e018d759a2a 36 #include "pinmap.h"
switches 0:0e018d759a2a 37 #include "gpio_regs.h"
switches 0:0e018d759a2a 38 #include "clkman_regs.h"
switches 0:0e018d759a2a 39
switches 0:0e018d759a2a 40 uint32_t gpio_set(PinName name)
switches 0:0e018d759a2a 41 {
switches 0:0e018d759a2a 42 MBED_ASSERT(name != (PinName)NC);
switches 0:0e018d759a2a 43 pin_function(name, 0);
switches 0:0e018d759a2a 44 return 1 << PINNAME_TO_PIN(name);
switches 0:0e018d759a2a 45 }
switches 0:0e018d759a2a 46
switches 0:0e018d759a2a 47 void gpio_init(gpio_t *obj, PinName name)
switches 0:0e018d759a2a 48 {
switches 0:0e018d759a2a 49 obj->name = name;
switches 0:0e018d759a2a 50 if (name == (PinName)NC) {
switches 0:0e018d759a2a 51 return;
switches 0:0e018d759a2a 52 }
switches 0:0e018d759a2a 53
switches 0:0e018d759a2a 54 unsigned int port = PINNAME_TO_PORT(name);
switches 0:0e018d759a2a 55 unsigned int pin = PINNAME_TO_PIN(name);
switches 0:0e018d759a2a 56
switches 0:0e018d759a2a 57 obj->reg_out = (uint32_t*)BITBAND(&MXC_GPIO->out_val[port], pin);
switches 0:0e018d759a2a 58 obj->reg_in = (uint32_t*)BITBAND(&MXC_GPIO->in_val[port], pin);
switches 0:0e018d759a2a 59
switches 0:0e018d759a2a 60 /* Ensure that the GPIO clock is enabled */
switches 0:0e018d759a2a 61 if (MXC_CLKMAN->clk_ctrl_1_gpio == MXC_E_CLKMAN_CLK_SCALE_DISABLED) {
switches 0:0e018d759a2a 62 MXC_CLKMAN->clk_ctrl_1_gpio = MXC_E_CLKMAN_CLK_SCALE_ENABLED;
switches 0:0e018d759a2a 63 }
switches 0:0e018d759a2a 64 }
switches 0:0e018d759a2a 65
switches 0:0e018d759a2a 66 void gpio_mode(gpio_t *obj, PinMode mode)
switches 0:0e018d759a2a 67 {
switches 0:0e018d759a2a 68 pin_mode(obj->name, mode);
switches 0:0e018d759a2a 69 }
switches 0:0e018d759a2a 70
switches 0:0e018d759a2a 71 void pin_dir(PinName name, PinDirection direction)
switches 0:0e018d759a2a 72 {
switches 0:0e018d759a2a 73 MBED_ASSERT(name != (PinName)NC);
switches 0:0e018d759a2a 74
switches 0:0e018d759a2a 75 unsigned int port = PINNAME_TO_PORT(name);
switches 0:0e018d759a2a 76 unsigned int pin = PINNAME_TO_PIN(name);
switches 0:0e018d759a2a 77
switches 0:0e018d759a2a 78 /* Set function */
switches 0:0e018d759a2a 79 MXC_GPIO->func_sel[port] &= ~(0xF << (4 * pin));
switches 0:0e018d759a2a 80
switches 0:0e018d759a2a 81 /* Normal input is always enabled */
switches 0:0e018d759a2a 82 MXC_GPIO->in_mode[port] &= ~(0xF << (4 * pin));
switches 0:0e018d759a2a 83
switches 0:0e018d759a2a 84 /* Set requested output mode */
switches 0:0e018d759a2a 85 uint32_t out_mode = MXC_GPIO->out_mode[port];
switches 0:0e018d759a2a 86 out_mode &= ~(0xF << (4 * pin));
switches 0:0e018d759a2a 87 out_mode |= (direction << (4 * pin));
switches 0:0e018d759a2a 88 MXC_GPIO->out_mode[port] = out_mode;
switches 0:0e018d759a2a 89 }
switches 0:0e018d759a2a 90
switches 0:0e018d759a2a 91 void gpio_dir(gpio_t *obj, PinDirection direction)
switches 0:0e018d759a2a 92 {
switches 0:0e018d759a2a 93 pin_dir(obj->name, direction);
switches 0:0e018d759a2a 94 }