mbed library sources. Supersedes mbed-src.
Dependents: Hobbyking_Cheetah_Compact Hobbyking_Cheetah_Compact_DRV8323_14bit Hobbyking_Cheetah_Compact_DRV8323_V51_201907 HKC_MiniCheetah ... more
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32630/port_api.c@157:ff67d9f36b67, 2017-02-02 (annotated)
- Committer:
- <>
- Date:
- Thu Feb 02 17:01:33 2017 +0000
- Revision:
- 157:ff67d9f36b67
This updates the lib to the mbed lib v135
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 157:ff67d9f36b67 | 1 | /******************************************************************************* |
<> | 157:ff67d9f36b67 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
<> | 157:ff67d9f36b67 | 3 | * |
<> | 157:ff67d9f36b67 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
<> | 157:ff67d9f36b67 | 5 | * copy of this software and associated documentation files (the "Software"), |
<> | 157:ff67d9f36b67 | 6 | * to deal in the Software without restriction, including without limitation |
<> | 157:ff67d9f36b67 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
<> | 157:ff67d9f36b67 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
<> | 157:ff67d9f36b67 | 9 | * Software is furnished to do so, subject to the following conditions: |
<> | 157:ff67d9f36b67 | 10 | * |
<> | 157:ff67d9f36b67 | 11 | * The above copyright notice and this permission notice shall be included |
<> | 157:ff67d9f36b67 | 12 | * in all copies or substantial portions of the Software. |
<> | 157:ff67d9f36b67 | 13 | * |
<> | 157:ff67d9f36b67 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
<> | 157:ff67d9f36b67 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
<> | 157:ff67d9f36b67 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
<> | 157:ff67d9f36b67 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
<> | 157:ff67d9f36b67 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
<> | 157:ff67d9f36b67 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
<> | 157:ff67d9f36b67 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
<> | 157:ff67d9f36b67 | 21 | * |
<> | 157:ff67d9f36b67 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
<> | 157:ff67d9f36b67 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
<> | 157:ff67d9f36b67 | 24 | * Products, Inc. Branding Policy. |
<> | 157:ff67d9f36b67 | 25 | * |
<> | 157:ff67d9f36b67 | 26 | * The mere transfer of this software does not imply any licenses |
<> | 157:ff67d9f36b67 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
<> | 157:ff67d9f36b67 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
<> | 157:ff67d9f36b67 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
<> | 157:ff67d9f36b67 | 30 | * ownership rights. |
<> | 157:ff67d9f36b67 | 31 | ******************************************************************************* |
<> | 157:ff67d9f36b67 | 32 | */ |
<> | 157:ff67d9f36b67 | 33 | |
<> | 157:ff67d9f36b67 | 34 | #include "port_api.h" |
<> | 157:ff67d9f36b67 | 35 | #include "pinmap.h" |
<> | 157:ff67d9f36b67 | 36 | #include "gpio_api.h" |
<> | 157:ff67d9f36b67 | 37 | #include "gpio_regs.h" |
<> | 157:ff67d9f36b67 | 38 | #include "clkman_regs.h" |
<> | 157:ff67d9f36b67 | 39 | |
<> | 157:ff67d9f36b67 | 40 | PinName port_pin(PortName port, int pin_n) |
<> | 157:ff67d9f36b67 | 41 | { |
<> | 157:ff67d9f36b67 | 42 | return (PinName)((port << PORT_SHIFT) | pin_n); |
<> | 157:ff67d9f36b67 | 43 | } |
<> | 157:ff67d9f36b67 | 44 | |
<> | 157:ff67d9f36b67 | 45 | void port_init(port_t *obj, PortName port, int mask, PinDirection direction) |
<> | 157:ff67d9f36b67 | 46 | { |
<> | 157:ff67d9f36b67 | 47 | obj->port = port; |
<> | 157:ff67d9f36b67 | 48 | obj->mask = mask; |
<> | 157:ff67d9f36b67 | 49 | obj->reg_out = &MXC_GPIO->out_val[port]; |
<> | 157:ff67d9f36b67 | 50 | obj->reg_in = &MXC_GPIO->in_val[port]; |
<> | 157:ff67d9f36b67 | 51 | obj->mode = PullDefault; |
<> | 157:ff67d9f36b67 | 52 | |
<> | 157:ff67d9f36b67 | 53 | /* Ensure that the GPIO clock is enabled */ |
<> | 157:ff67d9f36b67 | 54 | MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1; |
<> | 157:ff67d9f36b67 | 55 | |
<> | 157:ff67d9f36b67 | 56 | uint32_t i; |
<> | 157:ff67d9f36b67 | 57 | // The function is set per pin: reuse gpio logic |
<> | 157:ff67d9f36b67 | 58 | for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { |
<> | 157:ff67d9f36b67 | 59 | if (obj->mask & (1 << i)) { |
<> | 157:ff67d9f36b67 | 60 | gpio_set(port_pin(obj->port, i)); |
<> | 157:ff67d9f36b67 | 61 | pin_dir_mode(port_pin(obj->port, i), direction, obj->mode); |
<> | 157:ff67d9f36b67 | 62 | } |
<> | 157:ff67d9f36b67 | 63 | } |
<> | 157:ff67d9f36b67 | 64 | } |
<> | 157:ff67d9f36b67 | 65 | |
<> | 157:ff67d9f36b67 | 66 | void port_mode(port_t *obj, PinMode mode) |
<> | 157:ff67d9f36b67 | 67 | { |
<> | 157:ff67d9f36b67 | 68 | uint32_t i; |
<> | 157:ff67d9f36b67 | 69 | obj->mode = mode; |
<> | 157:ff67d9f36b67 | 70 | // The mode is set per pin: reuse pinmap logic |
<> | 157:ff67d9f36b67 | 71 | for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { |
<> | 157:ff67d9f36b67 | 72 | if (obj->mask & (1 << i)) { |
<> | 157:ff67d9f36b67 | 73 | pin_mode(port_pin(obj->port, i), mode); |
<> | 157:ff67d9f36b67 | 74 | } |
<> | 157:ff67d9f36b67 | 75 | } |
<> | 157:ff67d9f36b67 | 76 | } |
<> | 157:ff67d9f36b67 | 77 | |
<> | 157:ff67d9f36b67 | 78 | void port_dir(port_t *obj, PinDirection direction) |
<> | 157:ff67d9f36b67 | 79 | { |
<> | 157:ff67d9f36b67 | 80 | uint32_t i; |
<> | 157:ff67d9f36b67 | 81 | // The mode is set per pin: reuse gpio logic |
<> | 157:ff67d9f36b67 | 82 | for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { |
<> | 157:ff67d9f36b67 | 83 | if (obj->mask & (1 << i)) { |
<> | 157:ff67d9f36b67 | 84 | pin_dir_mode(port_pin(obj->port, i), direction, obj->mode); |
<> | 157:ff67d9f36b67 | 85 | } |
<> | 157:ff67d9f36b67 | 86 | } |
<> | 157:ff67d9f36b67 | 87 | } |
<> | 157:ff67d9f36b67 | 88 | |
<> | 157:ff67d9f36b67 | 89 | void port_write(port_t *obj, int value) |
<> | 157:ff67d9f36b67 | 90 | { |
<> | 157:ff67d9f36b67 | 91 | *obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask); |
<> | 157:ff67d9f36b67 | 92 | } |
<> | 157:ff67d9f36b67 | 93 | |
<> | 157:ff67d9f36b67 | 94 | int port_read(port_t *obj) |
<> | 157:ff67d9f36b67 | 95 | { |
<> | 157:ff67d9f36b67 | 96 | return (*obj->reg_in & obj->mask); |
<> | 157:ff67d9f36b67 | 97 | } |
<> | 157:ff67d9f36b67 | 98 |