Fork of Library for MAXREFDES72# that supports configuration of shield for different PMOD types and the DS3231 RTC
Fork of ard2pmod by
ard2pmod.cpp@0:bb62cd328247, 2014-11-20 (annotated)
- Committer:
- j3
- Date:
- Thu Nov 20 21:10:15 2014 +0000
- Revision:
- 0:bb62cd328247
- Child:
- 2:686912ed055f
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:bb62cd328247 | 1 | /******************************************************************//** |
j3 | 0:bb62cd328247 | 2 | * @file ard2pmod.cpp |
j3 | 0:bb62cd328247 | 3 | * |
j3 | 0:bb62cd328247 | 4 | * @author Justin Jordan |
j3 | 0:bb62cd328247 | 5 | * |
j3 | 0:bb62cd328247 | 6 | * @version 0.0 |
j3 | 0:bb62cd328247 | 7 | * |
j3 | 0:bb62cd328247 | 8 | * Started: 11NOV14 |
j3 | 0:bb62cd328247 | 9 | * |
j3 | 0:bb62cd328247 | 10 | * Updated: |
j3 | 0:bb62cd328247 | 11 | * |
j3 | 0:bb62cd328247 | 12 | * @brief Source file for ard2pmod class |
j3 | 0:bb62cd328247 | 13 | * |
j3 | 0:bb62cd328247 | 14 | *********************************************************************** |
j3 | 0:bb62cd328247 | 15 | * |
j3 | 0:bb62cd328247 | 16 | * @copyright |
j3 | 0:bb62cd328247 | 17 | * Copyright (C) 2013 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:bb62cd328247 | 18 | * |
j3 | 0:bb62cd328247 | 19 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:bb62cd328247 | 20 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:bb62cd328247 | 21 | * to deal in the Software without restriction, including without limitation |
j3 | 0:bb62cd328247 | 22 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:bb62cd328247 | 23 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:bb62cd328247 | 24 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:bb62cd328247 | 25 | * |
j3 | 0:bb62cd328247 | 26 | * The above copyright notice and this permission notice shall be included |
j3 | 0:bb62cd328247 | 27 | * in all copies or substantial portions of the Software. |
j3 | 0:bb62cd328247 | 28 | * |
j3 | 0:bb62cd328247 | 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:bb62cd328247 | 30 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:bb62cd328247 | 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:bb62cd328247 | 32 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:bb62cd328247 | 33 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:bb62cd328247 | 34 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:bb62cd328247 | 35 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:bb62cd328247 | 36 | * |
j3 | 0:bb62cd328247 | 37 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:bb62cd328247 | 38 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:bb62cd328247 | 39 | * Products, Inc. Branding Policy. |
j3 | 0:bb62cd328247 | 40 | * |
j3 | 0:bb62cd328247 | 41 | * The mere transfer of this software does not imply any licenses |
j3 | 0:bb62cd328247 | 42 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:bb62cd328247 | 43 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:bb62cd328247 | 44 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:bb62cd328247 | 45 | * ownership rights. |
j3 | 0:bb62cd328247 | 46 | **********************************************************************/ |
j3 | 0:bb62cd328247 | 47 | |
j3 | 0:bb62cd328247 | 48 | |
j3 | 0:bb62cd328247 | 49 | #include "ard2pmod.h" |
j3 | 0:bb62cd328247 | 50 | |
j3 | 0:bb62cd328247 | 51 | |
j3 | 0:bb62cd328247 | 52 | /**************************************************************//** |
j3 | 0:bb62cd328247 | 53 | * Constructor for Ard2Pmod Class |
j3 | 0:bb62cd328247 | 54 | * |
j3 | 0:bb62cd328247 | 55 | * On Entry: |
j3 | 0:bb62cd328247 | 56 | * @param[in] pmod_type - desired PMOD interface |
j3 | 0:bb62cd328247 | 57 | * |
j3 | 0:bb62cd328247 | 58 | * On Exit: |
j3 | 0:bb62cd328247 | 59 | * @return none |
j3 | 0:bb62cd328247 | 60 | * |
j3 | 0:bb62cd328247 | 61 | * Example: |
j3 | 0:bb62cd328247 | 62 | * @code |
j3 | 0:bb62cd328247 | 63 | * #include "ard2pmod.h" |
j3 | 0:bb62cd328247 | 64 | * |
j3 | 0:bb62cd328247 | 65 | * int main(void) |
j3 | 0:bb62cd328247 | 66 | * { |
j3 | 0:bb62cd328247 | 67 | * Ard2Pmod ard2pmod(PMOD_TYPE_1_GPIO); |
j3 | 0:bb62cd328247 | 68 | * |
j3 | 0:bb62cd328247 | 69 | * //main app. |
j3 | 0:bb62cd328247 | 70 | * for(;;) |
j3 | 0:bb62cd328247 | 71 | * { |
j3 | 0:bb62cd328247 | 72 | * } |
j3 | 0:bb62cd328247 | 73 | * } |
j3 | 0:bb62cd328247 | 74 | * @endcode |
j3 | 0:bb62cd328247 | 75 | ******************************************************************/ |
j3 | 0:bb62cd328247 | 76 | Ard2Pmod::Ard2Pmod(pmod_type_t pmod_type) : |
j3 | 0:bb62cd328247 | 77 | Max14661(ARD2PMOD_SDA, ARD2PMOD_SCL, MAX14661_I2C_ADRS0), |
j3 | 0:bb62cd328247 | 78 | Ds3231(ARD2PMOD_SDA, ARD2PMOD_SCL) |
j3 | 0:bb62cd328247 | 79 | { |
j3 | 0:bb62cd328247 | 80 | uint8_t mux_data[4]; |
j3 | 0:bb62cd328247 | 81 | |
j3 | 0:bb62cd328247 | 82 | switch(pmod_type) |
j3 | 0:bb62cd328247 | 83 | { |
j3 | 0:bb62cd328247 | 84 | case PMOD_TYPE_I2C: |
j3 | 0:bb62cd328247 | 85 | mux_data[0] = SW07; |
j3 | 0:bb62cd328247 | 86 | mux_data[1] = ((SW12 | SW09) >> 8); |
j3 | 0:bb62cd328247 | 87 | mux_data[2] = SW08; |
j3 | 0:bb62cd328247 | 88 | mux_data[3] = ((SW11 | SW10) >> 8); |
j3 | 0:bb62cd328247 | 89 | |
j3 | 0:bb62cd328247 | 90 | wrt_shadow_registers(mux_data); |
j3 | 0:bb62cd328247 | 91 | wrt_cmd_registers(C0PY_SHADOW, C0PY_SHADOW); |
j3 | 0:bb62cd328247 | 92 | |
j3 | 0:bb62cd328247 | 93 | break; |
j3 | 0:bb62cd328247 | 94 | |
j3 | 0:bb62cd328247 | 95 | case PMOD_TYPE_1_GPIO: |
j3 | 0:bb62cd328247 | 96 | wrt_cmd_registers(DISABLE_BANK, DISABLE_BANK); |
j3 | 0:bb62cd328247 | 97 | break; |
j3 | 0:bb62cd328247 | 98 | |
j3 | 0:bb62cd328247 | 99 | case PMOD_TYPE_2_SPI: |
j3 | 0:bb62cd328247 | 100 | wrt_cmd_registers(DISABLE_BANK, DISABLE_BANK); |
j3 | 0:bb62cd328247 | 101 | break; |
j3 | 0:bb62cd328247 | 102 | |
j3 | 0:bb62cd328247 | 103 | case PMOD_TYPE_3_UART: |
j3 | 0:bb62cd328247 | 104 | mux_data[0] = SW02; |
j3 | 0:bb62cd328247 | 105 | mux_data[1] = (SW12 >> 8); |
j3 | 0:bb62cd328247 | 106 | mux_data[2] = SW01; |
j3 | 0:bb62cd328247 | 107 | mux_data[3] = (SW11 >> 8); |
j3 | 0:bb62cd328247 | 108 | |
j3 | 0:bb62cd328247 | 109 | wrt_shadow_registers(mux_data); |
j3 | 0:bb62cd328247 | 110 | wrt_cmd_registers(C0PY_SHADOW, C0PY_SHADOW); |
j3 | 0:bb62cd328247 | 111 | |
j3 | 0:bb62cd328247 | 112 | break; |
j3 | 0:bb62cd328247 | 113 | |
j3 | 0:bb62cd328247 | 114 | case PMOD_TYPE_4_UART: |
j3 | 0:bb62cd328247 | 115 | mux_data[0] = SW01; |
j3 | 0:bb62cd328247 | 116 | mux_data[1] = (SW13 >> 8); |
j3 | 0:bb62cd328247 | 117 | mux_data[2] = SW02; |
j3 | 0:bb62cd328247 | 118 | mux_data[3] = (SW12 >> 8); |
j3 | 0:bb62cd328247 | 119 | |
j3 | 0:bb62cd328247 | 120 | wrt_shadow_registers(mux_data); |
j3 | 0:bb62cd328247 | 121 | wrt_cmd_registers(C0PY_SHADOW, C0PY_SHADOW); |
j3 | 0:bb62cd328247 | 122 | |
j3 | 0:bb62cd328247 | 123 | break; |
j3 | 0:bb62cd328247 | 124 | |
j3 | 0:bb62cd328247 | 125 | case PMOD_TYPE_5_HBRIDGE: |
j3 | 0:bb62cd328247 | 126 | wrt_cmd_registers(DISABLE_BANK, DISABLE_BANK); |
j3 | 0:bb62cd328247 | 127 | break; |
j3 | 0:bb62cd328247 | 128 | |
j3 | 0:bb62cd328247 | 129 | case PMOD_TYPE_6_HBRIDGE: |
j3 | 0:bb62cd328247 | 130 | wrt_cmd_registers(DISABLE_BANK, DISABLE_BANK); |
j3 | 0:bb62cd328247 | 131 | break; |
j3 | 0:bb62cd328247 | 132 | |
j3 | 0:bb62cd328247 | 133 | default: |
j3 | 0:bb62cd328247 | 134 | wrt_cmd_registers(DISABLE_BANK, DISABLE_BANK); |
j3 | 0:bb62cd328247 | 135 | } |
j3 | 0:bb62cd328247 | 136 | |
j3 | 0:bb62cd328247 | 137 | } |
j3 | 0:bb62cd328247 | 138 | |
j3 | 0:bb62cd328247 | 139 |