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