Library for MAX5387 dual channel digi pot
max5387.cpp@4:89d2f70616ee, 2016-05-12 (annotated)
- Committer:
- j3
- Date:
- Thu May 12 22:53:08 2016 +0000
- Revision:
- 4:89d2f70616ee
- Parent:
- 3:25deebfe51ba
updated documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:bc5ccbaf1650 | 1 | /******************************************************************//** |
j3 | 3:25deebfe51ba | 2 | * @file max5387.cpp |
j3 | 0:bc5ccbaf1650 | 3 | * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:bc5ccbaf1650 | 4 | * |
j3 | 0:bc5ccbaf1650 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:bc5ccbaf1650 | 6 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:bc5ccbaf1650 | 7 | * to deal in the Software without restriction, including without limitation |
j3 | 0:bc5ccbaf1650 | 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:bc5ccbaf1650 | 9 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:bc5ccbaf1650 | 10 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:bc5ccbaf1650 | 11 | * |
j3 | 0:bc5ccbaf1650 | 12 | * The above copyright notice and this permission notice shall be included |
j3 | 0:bc5ccbaf1650 | 13 | * in all copies or substantial portions of the Software. |
j3 | 0:bc5ccbaf1650 | 14 | * |
j3 | 0:bc5ccbaf1650 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:bc5ccbaf1650 | 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:bc5ccbaf1650 | 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:bc5ccbaf1650 | 18 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:bc5ccbaf1650 | 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:bc5ccbaf1650 | 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:bc5ccbaf1650 | 21 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:bc5ccbaf1650 | 22 | * |
j3 | 0:bc5ccbaf1650 | 23 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:bc5ccbaf1650 | 24 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:bc5ccbaf1650 | 25 | * Products, Inc. Branding Policy. |
j3 | 0:bc5ccbaf1650 | 26 | * |
j3 | 0:bc5ccbaf1650 | 27 | * The mere transfer of this software does not imply any licenses |
j3 | 0:bc5ccbaf1650 | 28 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:bc5ccbaf1650 | 29 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:bc5ccbaf1650 | 30 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:bc5ccbaf1650 | 31 | * ownership rights. |
j3 | 0:bc5ccbaf1650 | 32 | **********************************************************************/ |
j3 | 0:bc5ccbaf1650 | 33 | |
j3 | 0:bc5ccbaf1650 | 34 | |
j3 | 0:bc5ccbaf1650 | 35 | #include "max5387.h" |
j3 | 0:bc5ccbaf1650 | 36 | |
j3 | 0:bc5ccbaf1650 | 37 | |
j3 | 2:602efd0437b9 | 38 | #define MAX5387_CMD_A (0x11) |
j3 | 2:602efd0437b9 | 39 | #define MAX5387_CMD_B (0x12) |
j3 | 2:602efd0437b9 | 40 | #define MAX5387_CMD_AB (0x13) |
j3 | 0:bc5ccbaf1650 | 41 | |
j3 | 0:bc5ccbaf1650 | 42 | |
j3 | 0:bc5ccbaf1650 | 43 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 44 | Max5387::Max5387(I2C *i2c_bus, max5387_i2c_adrs_t i2c_adrs): _p_i2c(i2c_bus) |
j3 | 0:bc5ccbaf1650 | 45 | { |
j3 | 0:bc5ccbaf1650 | 46 | _i2c_owner = false; |
j3 | 0:bc5ccbaf1650 | 47 | |
j3 | 0:bc5ccbaf1650 | 48 | _w_adrs = (i2c_adrs << 1); |
j3 | 0:bc5ccbaf1650 | 49 | } |
j3 | 0:bc5ccbaf1650 | 50 | |
j3 | 0:bc5ccbaf1650 | 51 | |
j3 | 0:bc5ccbaf1650 | 52 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 53 | Max5387::Max5387(PinName sda, PinName scl, max5387_i2c_adrs_t i2c_adrs) |
j3 | 0:bc5ccbaf1650 | 54 | { |
j3 | 0:bc5ccbaf1650 | 55 | _p_i2c = new I2C(sda, scl); |
j3 | 0:bc5ccbaf1650 | 56 | _i2c_owner = true; |
j3 | 0:bc5ccbaf1650 | 57 | |
j3 | 0:bc5ccbaf1650 | 58 | _w_adrs = (i2c_adrs << 1); |
j3 | 0:bc5ccbaf1650 | 59 | } |
j3 | 0:bc5ccbaf1650 | 60 | |
j3 | 0:bc5ccbaf1650 | 61 | |
j3 | 0:bc5ccbaf1650 | 62 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 63 | Max5387::~Max5387() |
j3 | 0:bc5ccbaf1650 | 64 | { |
j3 | 0:bc5ccbaf1650 | 65 | if(_i2c_owner) |
j3 | 0:bc5ccbaf1650 | 66 | { |
j3 | 0:bc5ccbaf1650 | 67 | delete _p_i2c; |
j3 | 0:bc5ccbaf1650 | 68 | } |
j3 | 0:bc5ccbaf1650 | 69 | } |
j3 | 0:bc5ccbaf1650 | 70 | |
j3 | 0:bc5ccbaf1650 | 71 | |
j3 | 0:bc5ccbaf1650 | 72 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 73 | int16_t Max5387::write_ch_A(uint8_t val) |
j3 | 0:bc5ccbaf1650 | 74 | { |
j3 | 0:bc5ccbaf1650 | 75 | char data[] = {MAX5387_CMD_A, val}; |
j3 | 0:bc5ccbaf1650 | 76 | |
j3 | 0:bc5ccbaf1650 | 77 | return(_p_i2c->write(_w_adrs, data, 2, false)); |
j3 | 0:bc5ccbaf1650 | 78 | } |
j3 | 0:bc5ccbaf1650 | 79 | |
j3 | 0:bc5ccbaf1650 | 80 | |
j3 | 0:bc5ccbaf1650 | 81 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 82 | int16_t Max5387::write_ch_B(uint8_t val) |
j3 | 0:bc5ccbaf1650 | 83 | { |
j3 | 0:bc5ccbaf1650 | 84 | char data[] = {MAX5387_CMD_B, val}; |
j3 | 0:bc5ccbaf1650 | 85 | |
j3 | 0:bc5ccbaf1650 | 86 | return(_p_i2c->write(_w_adrs, data, 2, false)); |
j3 | 0:bc5ccbaf1650 | 87 | } |
j3 | 0:bc5ccbaf1650 | 88 | |
j3 | 0:bc5ccbaf1650 | 89 | |
j3 | 0:bc5ccbaf1650 | 90 | //********************************************************************* |
j3 | 0:bc5ccbaf1650 | 91 | int16_t Max5387::write_ch_AB(uint8_t val) |
j3 | 0:bc5ccbaf1650 | 92 | { |
j3 | 0:bc5ccbaf1650 | 93 | char data[] = {MAX5387_CMD_AB, val}; |
j3 | 0:bc5ccbaf1650 | 94 | |
j3 | 0:bc5ccbaf1650 | 95 | return(_p_i2c->write(_w_adrs, data, 2, false)); |
j3 | 0:bc5ccbaf1650 | 96 | } |
j3 | 0:bc5ccbaf1650 | 97 |