Library for MAX32625PICO board. Configures IOH supply and I/O voltage rails.
Dependents: MAX34417_demo BER_Board PICO_board_demo_copy PICO_board_demo ... more
max32625pico.cpp@0:65bda25808e4, 2017-05-23 (annotated)
- Committer:
- switches
- Date:
- Tue May 23 00:12:03 2017 +0000
- Revision:
- 0:65bda25808e4
New library for the max32625pico board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:65bda25808e4 | 1 | /******************************************************************************* |
switches | 0:65bda25808e4 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
switches | 0:65bda25808e4 | 3 | * |
switches | 0:65bda25808e4 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
switches | 0:65bda25808e4 | 5 | * copy of this software and associated documentation files (the "Software"), |
switches | 0:65bda25808e4 | 6 | * to deal in the Software without restriction, including without limitation |
switches | 0:65bda25808e4 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
switches | 0:65bda25808e4 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
switches | 0:65bda25808e4 | 9 | * Software is furnished to do so, subject to the following conditions: |
switches | 0:65bda25808e4 | 10 | * |
switches | 0:65bda25808e4 | 11 | * The above copyright notice and this permission notice shall be included |
switches | 0:65bda25808e4 | 12 | * in all copies or substantial portions of the Software. |
switches | 0:65bda25808e4 | 13 | * |
switches | 0:65bda25808e4 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
switches | 0:65bda25808e4 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
switches | 0:65bda25808e4 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
switches | 0:65bda25808e4 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
switches | 0:65bda25808e4 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
switches | 0:65bda25808e4 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
switches | 0:65bda25808e4 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
switches | 0:65bda25808e4 | 21 | * |
switches | 0:65bda25808e4 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
switches | 0:65bda25808e4 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
switches | 0:65bda25808e4 | 24 | * Products, Inc. Branding Policy. |
switches | 0:65bda25808e4 | 25 | * |
switches | 0:65bda25808e4 | 26 | * The mere transfer of this software does not imply any licenses |
switches | 0:65bda25808e4 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
switches | 0:65bda25808e4 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
switches | 0:65bda25808e4 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
switches | 0:65bda25808e4 | 30 | * ownership rights. |
switches | 0:65bda25808e4 | 31 | ******************************************************************************* |
switches | 0:65bda25808e4 | 32 | */ |
switches | 0:65bda25808e4 | 33 | |
switches | 0:65bda25808e4 | 34 | #include "mbed.h" |
switches | 0:65bda25808e4 | 35 | #include "max32625.h" |
switches | 0:65bda25808e4 | 36 | #include "ioman_regs.h" |
switches | 0:65bda25808e4 | 37 | #include "gpio_regs.h" |
switches | 0:65bda25808e4 | 38 | #include "PinNames.h" |
switches | 0:65bda25808e4 | 39 | #include "max32625pico.h" |
switches | 0:65bda25808e4 | 40 | |
switches | 0:65bda25808e4 | 41 | //****************************************************************************** |
switches | 0:65bda25808e4 | 42 | MAX32625PICO::MAX32625PICO() : en3V3(P3_6, 0), enIOH(P2_2, 0), selSWD(P2_3, 0) |
switches | 0:65bda25808e4 | 43 | { |
switches | 0:65bda25808e4 | 44 | } |
switches | 0:65bda25808e4 | 45 | |
switches | 0:65bda25808e4 | 46 | //****************************************************************************** |
switches | 0:65bda25808e4 | 47 | MAX32625PICO::MAX32625PICO(vddioh_mode_t iohMode, vio_t dipVio, vio_t swdVio) : en3V3(P3_6, 0), enIOH(P2_2, 0), selSWD(P2_3, 0) |
switches | 0:65bda25808e4 | 48 | { |
switches | 0:65bda25808e4 | 49 | init(iohMode, dipVio, swdVio); |
switches | 0:65bda25808e4 | 50 | } |
switches | 0:65bda25808e4 | 51 | |
switches | 0:65bda25808e4 | 52 | //****************************************************************************** |
switches | 0:65bda25808e4 | 53 | MAX32625PICO::~MAX32625PICO() |
switches | 0:65bda25808e4 | 54 | { |
switches | 0:65bda25808e4 | 55 | } |
switches | 0:65bda25808e4 | 56 | |
switches | 0:65bda25808e4 | 57 | //****************************************************************************** |
switches | 0:65bda25808e4 | 58 | int MAX32625PICO::init(vddioh_mode_t iohMode, vio_t dipVio, vio_t swdVio) |
switches | 0:65bda25808e4 | 59 | { |
switches | 0:65bda25808e4 | 60 | // Set LED pins to open drain |
switches | 0:65bda25808e4 | 61 | uint32_t out_mode = MXC_GPIO->out_mode[2]; |
switches | 0:65bda25808e4 | 62 | out_mode &= ~(0xFFF0000); // Clear modes for bits 4-6 |
switches | 0:65bda25808e4 | 63 | out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (4 * 4)) |
switches | 0:65bda25808e4 | 64 | |(MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (5 * 4)) |
switches | 0:65bda25808e4 | 65 | |(MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (6 * 4)); |
switches | 0:65bda25808e4 | 66 | MXC_GPIO->out_mode[2] = out_mode; |
switches | 0:65bda25808e4 | 67 | |
switches | 0:65bda25808e4 | 68 | en3V3 = 0; // Disable local 3.3V IOH supply by default |
switches | 0:65bda25808e4 | 69 | enIOH = 0; // Disable external IOH supply by default |
switches | 0:65bda25808e4 | 70 | selSWD = 0; // Select DIP pins by default |
switches | 0:65bda25808e4 | 71 | |
switches | 0:65bda25808e4 | 72 | |
switches | 0:65bda25808e4 | 73 | switch (iohMode) { |
switches | 0:65bda25808e4 | 74 | case IOH_SWD_IN : |
switches | 0:65bda25808e4 | 75 | selSWD = 1; // Use SWD pins |
switches | 0:65bda25808e4 | 76 | case IOH_DIP_IN : |
switches | 0:65bda25808e4 | 77 | enIOH = 1; // Enable external connections |
switches | 0:65bda25808e4 | 78 | break; |
switches | 0:65bda25808e4 | 79 | case IOH_SWD_OUT : |
switches | 0:65bda25808e4 | 80 | selSWD = 1; // Use SWD pins |
switches | 0:65bda25808e4 | 81 | case IOH_DIP_OUT : |
switches | 0:65bda25808e4 | 82 | enIOH = 1; // Enable external connections |
switches | 0:65bda25808e4 | 83 | case IOH_3V3 : |
switches | 0:65bda25808e4 | 84 | en3V3 = 1; // Enable local 3.3V supply connection to IOH |
switches | 0:65bda25808e4 | 85 | break; |
switches | 0:65bda25808e4 | 86 | case IOH_OFF : |
switches | 0:65bda25808e4 | 87 | default: |
switches | 0:65bda25808e4 | 88 | break; |
switches | 0:65bda25808e4 | 89 | |
switches | 0:65bda25808e4 | 90 | } |
switches | 0:65bda25808e4 | 91 | |
switches | 0:65bda25808e4 | 92 | // Set DIP pin ports to dipVio |
switches | 0:65bda25808e4 | 93 | vddioh(P0_0, dipVio); |
switches | 0:65bda25808e4 | 94 | vddioh(P0_1, dipVio); |
switches | 0:65bda25808e4 | 95 | vddioh(P0_2, dipVio); |
switches | 0:65bda25808e4 | 96 | vddioh(P0_3, dipVio); |
switches | 0:65bda25808e4 | 97 | vddioh(P0_4, dipVio); |
switches | 0:65bda25808e4 | 98 | vddioh(P0_5, dipVio); |
switches | 0:65bda25808e4 | 99 | vddioh(P0_6, dipVio); |
switches | 0:65bda25808e4 | 100 | vddioh(P0_7, dipVio); |
switches | 0:65bda25808e4 | 101 | vddioh(P1_6, dipVio); |
switches | 0:65bda25808e4 | 102 | vddioh(P1_7, dipVio); |
switches | 0:65bda25808e4 | 103 | vddioh(P4_4, dipVio); |
switches | 0:65bda25808e4 | 104 | vddioh(P4_5, dipVio); |
switches | 0:65bda25808e4 | 105 | vddioh(P4_6, dipVio); |
switches | 0:65bda25808e4 | 106 | vddioh(P4_7, dipVio); |
switches | 0:65bda25808e4 | 107 | // Set SWD pin ports to swdVio |
switches | 0:65bda25808e4 | 108 | vddioh(P3_0, swdVio); |
switches | 0:65bda25808e4 | 109 | vddioh(P3_1, swdVio); |
switches | 0:65bda25808e4 | 110 | vddioh(P3_2, swdVio); |
switches | 0:65bda25808e4 | 111 | vddioh(P3_3, swdVio); |
switches | 0:65bda25808e4 | 112 | vddioh(P3_4, swdVio); |
switches | 0:65bda25808e4 | 113 | vddioh(P3_7, swdVio); |
switches | 0:65bda25808e4 | 114 | |
switches | 0:65bda25808e4 | 115 | // Set 1-Wire port to VDDIOH |
switches | 0:65bda25808e4 | 116 | vddioh(P4_0, VIO_IOH); |
switches | 0:65bda25808e4 | 117 | vddioh(P4_1, VIO_IOH); |
switches | 0:65bda25808e4 | 118 | |
switches | 0:65bda25808e4 | 119 | return 0; |
switches | 0:65bda25808e4 | 120 | } |
switches | 0:65bda25808e4 | 121 | |
switches | 0:65bda25808e4 | 122 | //****************************************************************************** |
switches | 0:65bda25808e4 | 123 | int MAX32625PICO::vddioh(PinName pin, vio_t vio) |
switches | 0:65bda25808e4 | 124 | { |
switches | 0:65bda25808e4 | 125 | __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0; |
switches | 0:65bda25808e4 | 126 | |
switches | 0:65bda25808e4 | 127 | if (pin == NOT_CONNECTED) { |
switches | 0:65bda25808e4 | 128 | return -1; |
switches | 0:65bda25808e4 | 129 | } |
switches | 0:65bda25808e4 | 130 | |
switches | 0:65bda25808e4 | 131 | use_vddioh += PINNAME_TO_PORT(pin) >> 2; |
switches | 0:65bda25808e4 | 132 | if (vio) { |
switches | 0:65bda25808e4 | 133 | *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3))); |
switches | 0:65bda25808e4 | 134 | } else { |
switches | 0:65bda25808e4 | 135 | *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3))); |
switches | 0:65bda25808e4 | 136 | } |
switches | 0:65bda25808e4 | 137 | |
switches | 0:65bda25808e4 | 138 | return 0; |
switches | 0:65bda25808e4 | 139 | } |