Library for MAX5387 dual channel digi pot
max5387.cpp@1:f50b0fb1f7f6, 2015-07-20 (annotated)
- Committer:
- j3
- Date:
- Mon Jul 20 18:35:30 2015 +0000
- Revision:
- 1:f50b0fb1f7f6
- Parent:
- 0:bc5ccbaf1650
- Child:
- 2:602efd0437b9
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 | #include "max5387.h" |
j3 | 0:bc5ccbaf1650 | 47 | |
j3 | 0:bc5ccbaf1650 | 48 | |
j3 | 0:bc5ccbaf1650 | 49 | #define MAX5387_CMD_A 0x11 |
j3 | 0:bc5ccbaf1650 | 50 | #define MAX5387_CMD_B 0x12 |
j3 | 0:bc5ccbaf1650 | 51 | #define MAX5387_CMD_AB 0x13 |
j3 | 0:bc5ccbaf1650 | 52 | |
j3 | 0:bc5ccbaf1650 | 53 | |
j3 | 0:bc5ccbaf1650 | 54 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 55 | Max5387::Max5387(I2C *i2c_bus, max5387_i2c_adrs_t i2c_adrs): _p_i2c(i2c_bus) |
j3 | 0:bc5ccbaf1650 | 56 | { |
j3 | 0:bc5ccbaf1650 | 57 | _i2c_owner = false; |
j3 | 0:bc5ccbaf1650 | 58 | |
j3 | 0:bc5ccbaf1650 | 59 | _w_adrs = (i2c_adrs << 1); |
j3 | 0:bc5ccbaf1650 | 60 | } |
j3 | 0:bc5ccbaf1650 | 61 | |
j3 | 0:bc5ccbaf1650 | 62 | |
j3 | 0:bc5ccbaf1650 | 63 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 64 | Max5387::Max5387(PinName sda, PinName scl, max5387_i2c_adrs_t i2c_adrs) |
j3 | 0:bc5ccbaf1650 | 65 | { |
j3 | 0:bc5ccbaf1650 | 66 | _p_i2c = new I2C(sda, scl); |
j3 | 0:bc5ccbaf1650 | 67 | _i2c_owner = true; |
j3 | 0:bc5ccbaf1650 | 68 | |
j3 | 0:bc5ccbaf1650 | 69 | _w_adrs = (i2c_adrs << 1); |
j3 | 0:bc5ccbaf1650 | 70 | } |
j3 | 0:bc5ccbaf1650 | 71 | |
j3 | 0:bc5ccbaf1650 | 72 | |
j3 | 0:bc5ccbaf1650 | 73 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 74 | Max5387::~Max5387() |
j3 | 0:bc5ccbaf1650 | 75 | { |
j3 | 0:bc5ccbaf1650 | 76 | if(_i2c_owner) |
j3 | 0:bc5ccbaf1650 | 77 | { |
j3 | 0:bc5ccbaf1650 | 78 | delete _p_i2c; |
j3 | 0:bc5ccbaf1650 | 79 | } |
j3 | 0:bc5ccbaf1650 | 80 | } |
j3 | 0:bc5ccbaf1650 | 81 | |
j3 | 0:bc5ccbaf1650 | 82 | |
j3 | 0:bc5ccbaf1650 | 83 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 84 | int16_t Max5387::write_ch_A(uint8_t val) |
j3 | 0:bc5ccbaf1650 | 85 | { |
j3 | 0:bc5ccbaf1650 | 86 | char data[] = {MAX5387_CMD_A, val}; |
j3 | 0:bc5ccbaf1650 | 87 | |
j3 | 0:bc5ccbaf1650 | 88 | return(_p_i2c->write(_w_adrs, data, 2, false)); |
j3 | 0:bc5ccbaf1650 | 89 | } |
j3 | 0:bc5ccbaf1650 | 90 | |
j3 | 0:bc5ccbaf1650 | 91 | |
j3 | 0:bc5ccbaf1650 | 92 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 93 | int16_t Max5387::write_ch_B(uint8_t val) |
j3 | 0:bc5ccbaf1650 | 94 | { |
j3 | 0:bc5ccbaf1650 | 95 | char data[] = {MAX5387_CMD_B, val}; |
j3 | 0:bc5ccbaf1650 | 96 | |
j3 | 0:bc5ccbaf1650 | 97 | return(_p_i2c->write(_w_adrs, data, 2, false)); |
j3 | 0:bc5ccbaf1650 | 98 | } |
j3 | 0:bc5ccbaf1650 | 99 | |
j3 | 0:bc5ccbaf1650 | 100 | |
j3 | 0:bc5ccbaf1650 | 101 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 102 | int16_t Max5387::write_ch_AB(uint8_t val) |
j3 | 0:bc5ccbaf1650 | 103 | { |
j3 | 0:bc5ccbaf1650 | 104 | char data[] = {MAX5387_CMD_AB, val}; |
j3 | 0:bc5ccbaf1650 | 105 | |
j3 | 0:bc5ccbaf1650 | 106 | return(_p_i2c->write(_w_adrs, data, 2, false)); |
j3 | 0:bc5ccbaf1650 | 107 | } |
j3 | 0:bc5ccbaf1650 | 108 |