![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
IVSC Project
MCP4651.h@4:262764d24e4d, 2013-06-07 (annotated)
- Committer:
- kevinkent
- Date:
- Fri Jun 07 19:59:29 2013 +0000
- Revision:
- 4:262764d24e4d
- Parent:
- 1:82f2ef52759e
Version 1.2
; Added MSG[0] = 0x06 tow write one pot chain with a single message
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevinkent | 1:82f2ef52759e | 1 | /* mbed MCP4651 DigiPot Driver Library |
kevinkent | 1:82f2ef52759e | 2 | * |
kevinkent | 1:82f2ef52759e | 3 | * Copyright (c) 2012, Kevin Kent Trane US Inc |
kevinkent | 1:82f2ef52759e | 4 | * |
kevinkent | 1:82f2ef52759e | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
kevinkent | 1:82f2ef52759e | 6 | * of this software and associated documentation files (the "Software"), to deal |
kevinkent | 1:82f2ef52759e | 7 | * in the Software without restriction, including without limitation the rights |
kevinkent | 1:82f2ef52759e | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
kevinkent | 1:82f2ef52759e | 9 | * copies of the Software, and to permit persons to whom the Software is |
kevinkent | 1:82f2ef52759e | 10 | * furnished to do so, subject to the following conditions: |
kevinkent | 1:82f2ef52759e | 11 | * |
kevinkent | 1:82f2ef52759e | 12 | * The above copyright notice and this permission notice shall be included in |
kevinkent | 1:82f2ef52759e | 13 | * all copies or substantial portions of the Software. |
kevinkent | 1:82f2ef52759e | 14 | * |
kevinkent | 1:82f2ef52759e | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
kevinkent | 1:82f2ef52759e | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
kevinkent | 1:82f2ef52759e | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
kevinkent | 1:82f2ef52759e | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
kevinkent | 1:82f2ef52759e | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kevinkent | 1:82f2ef52759e | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
kevinkent | 1:82f2ef52759e | 21 | * THE SOFTWARE. |
kevinkent | 1:82f2ef52759e | 22 | */ |
kevinkent | 1:82f2ef52759e | 23 | |
kevinkent | 1:82f2ef52759e | 24 | #ifndef MCP4651_H |
kevinkent | 1:82f2ef52759e | 25 | #define MCP4651_H |
kevinkent | 1:82f2ef52759e | 26 | |
kevinkent | 1:82f2ef52759e | 27 | #include "mbed.h" |
kevinkent | 1:82f2ef52759e | 28 | |
kevinkent | 1:82f2ef52759e | 29 | // register names |
kevinkent | 1:82f2ef52759e | 30 | #define MCP4651_VOL_WIPER0 0 |
kevinkent | 1:82f2ef52759e | 31 | #define MCP4651_VOL_WIPER1 1 |
kevinkent | 1:82f2ef52759e | 32 | |
kevinkent | 1:82f2ef52759e | 33 | #define MCP4651_REG_TCON 4 |
kevinkent | 1:82f2ef52759e | 34 | |
kevinkent | 1:82f2ef52759e | 35 | |
kevinkent | 1:82f2ef52759e | 36 | |
kevinkent | 1:82f2ef52759e | 37 | // Command modes |
kevinkent | 1:82f2ef52759e | 38 | // Left Shifted 2 bits for low nibble |
kevinkent | 1:82f2ef52759e | 39 | #define MCP4651_WR 0x0 // 00b |
kevinkent | 1:82f2ef52759e | 40 | #define MCP4651_RD 0xB // 11b |
kevinkent | 1:82f2ef52759e | 41 | #define MCP4651_INC 0x4 // 01b |
kevinkent | 1:82f2ef52759e | 42 | #define MCP4651_DEC 0x2 // 10b |
kevinkent | 1:82f2ef52759e | 43 | |
kevinkent | 1:82f2ef52759e | 44 | // Base Address of MCP4651 |
kevinkent | 1:82f2ef52759e | 45 | // 0101b + A2:A1:A0:R/W |
kevinkent | 1:82f2ef52759e | 46 | #define MCP4651_BASE 0x50 |
kevinkent | 1:82f2ef52759e | 47 | |
kevinkent | 1:82f2ef52759e | 48 | class MCP4651 { |
kevinkent | 1:82f2ef52759e | 49 | |
kevinkent | 1:82f2ef52759e | 50 | public: |
kevinkent | 1:82f2ef52759e | 51 | |
kevinkent | 1:82f2ef52759e | 52 | MCP4651(PinName sda, PinName scl, int addr); |
kevinkent | 1:82f2ef52759e | 53 | |
kevinkent | 1:82f2ef52759e | 54 | // int SetLed (int led, int mode); |
kevinkent | 1:82f2ef52759e | 55 | // int SetMode (int mask, int mode); |
kevinkent | 1:82f2ef52759e | 56 | // int Duty (int channel, float duty); |
kevinkent | 1:82f2ef52759e | 57 | // int Period (int channel, float period); |
kevinkent | 1:82f2ef52759e | 58 | int SetValue (int wiper, int value); |
kevinkent | 1:82f2ef52759e | 59 | int GetValue (int wiper); |
kevinkent | 1:82f2ef52759e | 60 | |
kevinkent | 1:82f2ef52759e | 61 | protected: |
kevinkent | 1:82f2ef52759e | 62 | |
kevinkent | 1:82f2ef52759e | 63 | void _write(int reg, int data); |
kevinkent | 1:82f2ef52759e | 64 | int _read(int reg); |
kevinkent | 1:82f2ef52759e | 65 | int _addr; |
kevinkent | 1:82f2ef52759e | 66 | I2C _i2c; |
kevinkent | 1:82f2ef52759e | 67 | |
kevinkent | 1:82f2ef52759e | 68 | }; |
kevinkent | 1:82f2ef52759e | 69 | |
kevinkent | 1:82f2ef52759e | 70 | |
kevinkent | 1:82f2ef52759e | 71 | #endif |