Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32625/port_api.c@151:91825d030f9b, 2016-11-14 (annotated)
- Committer:
- DangerousElectrician
- Date:
- Mon Nov 14 04:39:23 2016 +0000
- Revision:
- 151:91825d030f9b
- Parent:
- 150:02e0a0aed4ec
stuff changed?
Who changed what in which revision?
User | Revision | Line number | New 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 "port_api.h" |
<> | 150:02e0a0aed4ec | 35 | #include "pinmap.h" |
<> | 150:02e0a0aed4ec | 36 | #include "gpio_api.h" |
<> | 150:02e0a0aed4ec | 37 | #include "gpio_regs.h" |
<> | 150:02e0a0aed4ec | 38 | #include "clkman_regs.h" |
<> | 150:02e0a0aed4ec | 39 | |
<> | 150:02e0a0aed4ec | 40 | PinName port_pin(PortName port, int pin_n) |
<> | 150:02e0a0aed4ec | 41 | { |
<> | 150:02e0a0aed4ec | 42 | return (PinName)((port << PORT_SHIFT) | pin_n); |
<> | 150:02e0a0aed4ec | 43 | } |
<> | 150:02e0a0aed4ec | 44 | |
<> | 150:02e0a0aed4ec | 45 | void port_init(port_t *obj, PortName port, int mask, PinDirection direction) |
<> | 150:02e0a0aed4ec | 46 | { |
<> | 150:02e0a0aed4ec | 47 | obj->port = port; |
<> | 150:02e0a0aed4ec | 48 | obj->mask = mask; |
<> | 150:02e0a0aed4ec | 49 | obj->reg_out = &MXC_GPIO->out_val[port]; |
<> | 150:02e0a0aed4ec | 50 | obj->reg_in = &MXC_GPIO->in_val[port]; |
<> | 150:02e0a0aed4ec | 51 | obj->mode = PullDefault; |
<> | 150:02e0a0aed4ec | 52 | |
<> | 150:02e0a0aed4ec | 53 | /* Ensure that the GPIO clock is enabled */ |
<> | 150:02e0a0aed4ec | 54 | MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1; |
<> | 150:02e0a0aed4ec | 55 | |
<> | 150:02e0a0aed4ec | 56 | uint32_t i; |
<> | 150:02e0a0aed4ec | 57 | // The function is set per pin: reuse gpio logic |
<> | 150:02e0a0aed4ec | 58 | for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { |
<> | 150:02e0a0aed4ec | 59 | if (obj->mask & (1 << i)) { |
<> | 150:02e0a0aed4ec | 60 | gpio_set(port_pin(obj->port, i)); |
<> | 150:02e0a0aed4ec | 61 | pin_dir_mode(port_pin(obj->port, i), direction, obj->mode); |
<> | 150:02e0a0aed4ec | 62 | } |
<> | 150:02e0a0aed4ec | 63 | } |
<> | 150:02e0a0aed4ec | 64 | } |
<> | 150:02e0a0aed4ec | 65 | |
<> | 150:02e0a0aed4ec | 66 | void port_mode(port_t *obj, PinMode mode) |
<> | 150:02e0a0aed4ec | 67 | { |
<> | 150:02e0a0aed4ec | 68 | uint32_t i; |
<> | 150:02e0a0aed4ec | 69 | obj->mode = mode; |
<> | 150:02e0a0aed4ec | 70 | // The mode is set per pin: reuse pinmap logic |
<> | 150:02e0a0aed4ec | 71 | for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { |
<> | 150:02e0a0aed4ec | 72 | if (obj->mask & (1 << i)) { |
<> | 150:02e0a0aed4ec | 73 | pin_mode(port_pin(obj->port, i), mode); |
<> | 150:02e0a0aed4ec | 74 | } |
<> | 150:02e0a0aed4ec | 75 | } |
<> | 150:02e0a0aed4ec | 76 | } |
<> | 150:02e0a0aed4ec | 77 | |
<> | 150:02e0a0aed4ec | 78 | void port_dir(port_t *obj, PinDirection direction) |
<> | 150:02e0a0aed4ec | 79 | { |
<> | 150:02e0a0aed4ec | 80 | uint32_t i; |
<> | 150:02e0a0aed4ec | 81 | // The mode is set per pin: reuse gpio logic |
<> | 150:02e0a0aed4ec | 82 | for (i = 0; i < MXC_GPIO_MAX_PINS_PER_PORT; i++) { |
<> | 150:02e0a0aed4ec | 83 | if (obj->mask & (1 << i)) { |
<> | 150:02e0a0aed4ec | 84 | pin_dir_mode(port_pin(obj->port, i), direction, obj->mode); |
<> | 150:02e0a0aed4ec | 85 | } |
<> | 150:02e0a0aed4ec | 86 | } |
<> | 150:02e0a0aed4ec | 87 | } |
<> | 150:02e0a0aed4ec | 88 | |
<> | 150:02e0a0aed4ec | 89 | void port_write(port_t *obj, int value) |
<> | 150:02e0a0aed4ec | 90 | { |
<> | 150:02e0a0aed4ec | 91 | *obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask); |
<> | 150:02e0a0aed4ec | 92 | } |
<> | 150:02e0a0aed4ec | 93 | |
<> | 150:02e0a0aed4ec | 94 | int port_read(port_t *obj) |
<> | 150:02e0a0aed4ec | 95 | { |
<> | 150:02e0a0aed4ec | 96 | return (*obj->reg_in & obj->mask); |
<> | 150:02e0a0aed4ec | 97 | } |
<> | 150:02e0a0aed4ec | 98 |