Library for MAX5387 dual channel digi pot
max5387.h@0:bc5ccbaf1650, 2015-07-20 (annotated)
- Committer:
- j3
- Date:
- Mon Jul 20 02:42:50 2015 +0000
- Revision:
- 0:bc5ccbaf1650
- Child:
- 4:89d2f70616ee
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:bc5ccbaf1650 | 1 | /******************************************************************//** |
j3 | 0:bc5ccbaf1650 | 2 | * @file max5387.h |
j3 | 0:bc5ccbaf1650 | 3 | * |
j3 | 0:bc5ccbaf1650 | 4 | * @author Justin Jordan |
j3 | 0:bc5ccbaf1650 | 5 | * |
j3 | 0:bc5ccbaf1650 | 6 | * @version 0.0 |
j3 | 0:bc5ccbaf1650 | 7 | * |
j3 | 0:bc5ccbaf1650 | 8 | * Started: 18JUL15 |
j3 | 0:bc5ccbaf1650 | 9 | * |
j3 | 0:bc5ccbaf1650 | 10 | * Updated: |
j3 | 0:bc5ccbaf1650 | 11 | * |
j3 | 0:bc5ccbaf1650 | 12 | * @brief Header file for Max5387 class |
j3 | 0:bc5ccbaf1650 | 13 | *********************************************************************** |
j3 | 0:bc5ccbaf1650 | 14 | * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:bc5ccbaf1650 | 15 | * |
j3 | 0:bc5ccbaf1650 | 16 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:bc5ccbaf1650 | 17 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:bc5ccbaf1650 | 18 | * to deal in the Software without restriction, including without limitation |
j3 | 0:bc5ccbaf1650 | 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:bc5ccbaf1650 | 20 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:bc5ccbaf1650 | 21 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:bc5ccbaf1650 | 22 | * |
j3 | 0:bc5ccbaf1650 | 23 | * The above copyright notice and this permission notice shall be included |
j3 | 0:bc5ccbaf1650 | 24 | * in all copies or substantial portions of the Software. |
j3 | 0:bc5ccbaf1650 | 25 | * |
j3 | 0:bc5ccbaf1650 | 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:bc5ccbaf1650 | 27 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:bc5ccbaf1650 | 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:bc5ccbaf1650 | 29 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:bc5ccbaf1650 | 30 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:bc5ccbaf1650 | 31 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:bc5ccbaf1650 | 32 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:bc5ccbaf1650 | 33 | * |
j3 | 0:bc5ccbaf1650 | 34 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:bc5ccbaf1650 | 35 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:bc5ccbaf1650 | 36 | * Products, Inc. Branding Policy. |
j3 | 0:bc5ccbaf1650 | 37 | * |
j3 | 0:bc5ccbaf1650 | 38 | * The mere transfer of this software does not imply any licenses |
j3 | 0:bc5ccbaf1650 | 39 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:bc5ccbaf1650 | 40 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:bc5ccbaf1650 | 41 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:bc5ccbaf1650 | 42 | * ownership rights. |
j3 | 0:bc5ccbaf1650 | 43 | **********************************************************************/ |
j3 | 0:bc5ccbaf1650 | 44 | |
j3 | 0:bc5ccbaf1650 | 45 | |
j3 | 0:bc5ccbaf1650 | 46 | #ifndef MAX5387_H |
j3 | 0:bc5ccbaf1650 | 47 | #define MAX5387_H |
j3 | 0:bc5ccbaf1650 | 48 | |
j3 | 0:bc5ccbaf1650 | 49 | #include "mbed.h" |
j3 | 0:bc5ccbaf1650 | 50 | |
j3 | 0:bc5ccbaf1650 | 51 | |
j3 | 0:bc5ccbaf1650 | 52 | class Max5387 |
j3 | 0:bc5ccbaf1650 | 53 | { |
j3 | 0:bc5ccbaf1650 | 54 | public: |
j3 | 0:bc5ccbaf1650 | 55 | |
j3 | 0:bc5ccbaf1650 | 56 | typedef enum |
j3 | 0:bc5ccbaf1650 | 57 | { |
j3 | 0:bc5ccbaf1650 | 58 | MAX5387_I2C_ADRS0 = 0x28, |
j3 | 0:bc5ccbaf1650 | 59 | MAX5387_I2C_ADRS1, |
j3 | 0:bc5ccbaf1650 | 60 | MAX5387_I2C_ADRS2, |
j3 | 0:bc5ccbaf1650 | 61 | MAX5387_I2C_ADRS3, |
j3 | 0:bc5ccbaf1650 | 62 | MAX5387_I2C_ADRS4, |
j3 | 0:bc5ccbaf1650 | 63 | MAX5387_I2C_ADRS5, |
j3 | 0:bc5ccbaf1650 | 64 | MAX5387_I2C_ADRS6, |
j3 | 0:bc5ccbaf1650 | 65 | MAX5387_I2C_ADRS7 |
j3 | 0:bc5ccbaf1650 | 66 | }max5387_i2c_adrs_t; |
j3 | 0:bc5ccbaf1650 | 67 | |
j3 | 0:bc5ccbaf1650 | 68 | |
j3 | 0:bc5ccbaf1650 | 69 | /**********************************************************//** |
j3 | 0:bc5ccbaf1650 | 70 | * @brief Constructor for Max5387 Class. |
j3 | 0:bc5ccbaf1650 | 71 | * |
j3 | 0:bc5ccbaf1650 | 72 | * @details Allows user to use existing I2C object |
j3 | 0:bc5ccbaf1650 | 73 | * |
j3 | 0:bc5ccbaf1650 | 74 | * On Entry: |
j3 | 0:bc5ccbaf1650 | 75 | * @param[in] i2c_bus - pointer to existing I2C object |
j3 | 0:bc5ccbaf1650 | 76 | * @param[in] i2c_adrs - 7-bit slave address of MAX5387 |
j3 | 0:bc5ccbaf1650 | 77 | * |
j3 | 0:bc5ccbaf1650 | 78 | * On Exit: |
j3 | 0:bc5ccbaf1650 | 79 | * @return none |
j3 | 0:bc5ccbaf1650 | 80 | **************************************************************/ |
j3 | 0:bc5ccbaf1650 | 81 | Max5387(I2C *i2c_bus, max5387_i2c_adrs_t i2c_adrs); |
j3 | 0:bc5ccbaf1650 | 82 | |
j3 | 0:bc5ccbaf1650 | 83 | |
j3 | 0:bc5ccbaf1650 | 84 | /**********************************************************//** |
j3 | 0:bc5ccbaf1650 | 85 | * @brief Constructor for Max5387 Class. |
j3 | 0:bc5ccbaf1650 | 86 | * |
j3 | 0:bc5ccbaf1650 | 87 | * @details Allows user to create a new I2C object if not |
j3 | 0:bc5ccbaf1650 | 88 | * already using one |
j3 | 0:bc5ccbaf1650 | 89 | * |
j3 | 0:bc5ccbaf1650 | 90 | * On Entry: |
j3 | 0:bc5ccbaf1650 | 91 | * @param[in] sda - sda pin of I2C bus |
j3 | 0:bc5ccbaf1650 | 92 | * @param[in] scl - scl pin of I2C bus |
j3 | 0:bc5ccbaf1650 | 93 | * @param[in] i2c_adrs - 7-bit slave address of MAX5387 |
j3 | 0:bc5ccbaf1650 | 94 | * |
j3 | 0:bc5ccbaf1650 | 95 | * On Exit: |
j3 | 0:bc5ccbaf1650 | 96 | * @return none |
j3 | 0:bc5ccbaf1650 | 97 | **************************************************************/ |
j3 | 0:bc5ccbaf1650 | 98 | Max5387(PinName sda, PinName scl, max5387_i2c_adrs_t i2c_adrs); |
j3 | 0:bc5ccbaf1650 | 99 | |
j3 | 0:bc5ccbaf1650 | 100 | |
j3 | 0:bc5ccbaf1650 | 101 | /**********************************************************//** |
j3 | 0:bc5ccbaf1650 | 102 | * @brief Default destructor for Max5387 Class. |
j3 | 0:bc5ccbaf1650 | 103 | * |
j3 | 0:bc5ccbaf1650 | 104 | * @details Destroys I2C object if owner |
j3 | 0:bc5ccbaf1650 | 105 | * |
j3 | 0:bc5ccbaf1650 | 106 | * On Entry: |
j3 | 0:bc5ccbaf1650 | 107 | * |
j3 | 0:bc5ccbaf1650 | 108 | * On Exit: |
j3 | 0:bc5ccbaf1650 | 109 | * @return none |
j3 | 0:bc5ccbaf1650 | 110 | **************************************************************/ |
j3 | 0:bc5ccbaf1650 | 111 | ~Max5387(); |
j3 | 0:bc5ccbaf1650 | 112 | |
j3 | 0:bc5ccbaf1650 | 113 | |
j3 | 0:bc5ccbaf1650 | 114 | /**********************************************************//** |
j3 | 0:bc5ccbaf1650 | 115 | * @brief Write channel A |
j3 | 0:bc5ccbaf1650 | 116 | * |
j3 | 0:bc5ccbaf1650 | 117 | * @details |
j3 | 0:bc5ccbaf1650 | 118 | * |
j3 | 0:bc5ccbaf1650 | 119 | * On Entry: |
j3 | 0:bc5ccbaf1650 | 120 | * @param[in] val - wiper position of channel A |
j3 | 0:bc5ccbaf1650 | 121 | * |
j3 | 0:bc5ccbaf1650 | 122 | * On Exit: |
j3 | 0:bc5ccbaf1650 | 123 | * @return 0 on success, non-0 on failure |
j3 | 0:bc5ccbaf1650 | 124 | **************************************************************/ |
j3 | 0:bc5ccbaf1650 | 125 | int16_t write_ch_A(uint8_t val); |
j3 | 0:bc5ccbaf1650 | 126 | |
j3 | 0:bc5ccbaf1650 | 127 | |
j3 | 0:bc5ccbaf1650 | 128 | /**********************************************************//** |
j3 | 0:bc5ccbaf1650 | 129 | * @brief Write channel B |
j3 | 0:bc5ccbaf1650 | 130 | * |
j3 | 0:bc5ccbaf1650 | 131 | * @details |
j3 | 0:bc5ccbaf1650 | 132 | * |
j3 | 0:bc5ccbaf1650 | 133 | * On Entry: |
j3 | 0:bc5ccbaf1650 | 134 | * @param[in] val - wiper position of channel B |
j3 | 0:bc5ccbaf1650 | 135 | * |
j3 | 0:bc5ccbaf1650 | 136 | * On Exit: |
j3 | 0:bc5ccbaf1650 | 137 | * @return 0 on success, non-0 on failure |
j3 | 0:bc5ccbaf1650 | 138 | **************************************************************/ |
j3 | 0:bc5ccbaf1650 | 139 | int16_t write_ch_B(uint8_t val); |
j3 | 0:bc5ccbaf1650 | 140 | |
j3 | 0:bc5ccbaf1650 | 141 | |
j3 | 0:bc5ccbaf1650 | 142 | /**********************************************************//** |
j3 | 0:bc5ccbaf1650 | 143 | * @brief Write channel A&B |
j3 | 0:bc5ccbaf1650 | 144 | * |
j3 | 0:bc5ccbaf1650 | 145 | * @details |
j3 | 0:bc5ccbaf1650 | 146 | * |
j3 | 0:bc5ccbaf1650 | 147 | * On Entry: |
j3 | 0:bc5ccbaf1650 | 148 | * @param[in] val - wiper position of channel A&B |
j3 | 0:bc5ccbaf1650 | 149 | * |
j3 | 0:bc5ccbaf1650 | 150 | * On Exit: |
j3 | 0:bc5ccbaf1650 | 151 | * @return 0 on success, non-0 on failure |
j3 | 0:bc5ccbaf1650 | 152 | **************************************************************/ |
j3 | 0:bc5ccbaf1650 | 153 | int16_t write_ch_AB(uint8_t val); |
j3 | 0:bc5ccbaf1650 | 154 | |
j3 | 0:bc5ccbaf1650 | 155 | |
j3 | 0:bc5ccbaf1650 | 156 | private: |
j3 | 0:bc5ccbaf1650 | 157 | |
j3 | 0:bc5ccbaf1650 | 158 | I2C *_p_i2c; |
j3 | 0:bc5ccbaf1650 | 159 | bool _i2c_owner; |
j3 | 0:bc5ccbaf1650 | 160 | uint8_t _w_adrs; |
j3 | 0:bc5ccbaf1650 | 161 | }; |
j3 | 0:bc5ccbaf1650 | 162 | |
j3 | 0:bc5ccbaf1650 | 163 | #endif/* MAX5387_H */ |