IVSC Project

Dependencies:   USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
kevinkent
Date:
Wed Nov 14 20:01:50 2012 +0000
Parent:
0:960d250e49b2
Child:
2:d0778c36d28d
Commit message:
Added DAC support

Changed in this revision

DigiPot.cpp Show annotated file Show diff for this revision Revisions of this file
DigiPot.h Show annotated file Show diff for this revision Revisions of this file
MCP4651.cpp Show annotated file Show diff for this revision Revisions of this file
MCP4651.h Show annotated file Show diff for this revision Revisions of this file
MCP4661.cpp Show diff for this revision Revisions of this file
MCP4661.h Show diff for this revision Revisions of this file
Max5250.cpp Show annotated file Show diff for this revision Revisions of this file
Max5250.h Show annotated file Show diff for this revision Revisions of this file
PCA9532.cpp Show diff for this revision Revisions of this file
PCA9532.h Show diff for this revision Revisions of this file
Relay.cpp Show annotated file Show diff for this revision Revisions of this file
Relay.h Show annotated file Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DigiPot.cpp	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,103 @@
+//
+#include "DigiPot.h"
+#include "mbed.h"
+#include "MCP4651.h"
+
+// Enable pins for PCA9
+BusOut Pbus(p14,p13,p12,p11);
+
+Serial dbg(USBTX, USBRX);
+
+MCP4651 Chip1(p9, p10, 0x1);
+MCP4651 Chip2(p9, p10, 0x2);
+MCP4651 Chip3(p9, p10, 0x3);
+MCP4651 Chip4(p9, p10, 0x5);
+MCP4651 Chip5(p9, p10, 0x6);
+MCP4651 Chip6(p9, p10, 0x7);
+
+
+//  The MCP4651 go to mid scale on reset
+//  Use the general call commands to set all pots to zero
+//  Set the lowest values pot to approximately 10k
+ 
+int PotReset(void) {
+    char wip0[2] = {0x80, 0x0};
+    char wip1[2] = {0x90, 0x0};    
+    I2C GenCall(p9,p10);
+    
+    // Reset R1 & R2
+    Pbus = 0x1;
+    GenCall.write(0x0, wip0, 2);
+    GenCall.write(0x0, wip1, 2);
+    Chip1.SetValue(0,50); // About 10k on 50k pot
+    Chip4.SetValue(0,50);
+    
+    // Reset R3 & R4
+    Pbus = 0x2;
+    GenCall.write(0x0, wip0, 2);
+    GenCall.write(0x0, wip1, 2);
+    Chip1.SetValue(0,50);
+    Chip4.SetValue(0,50);
+    
+    // Reset R5 & R6
+    Pbus = 0x4;
+    GenCall.write(0x0, wip0, 2);
+    GenCall.write(0x0, wip1, 2);
+    Chip1.SetValue(0,50);
+    Chip4.SetValue(0,50);
+    
+    // Pbus = 0x8; /* Not Used at this time */
+    Pbus = 0;
+    return(0);
+} // End PotReset
+
+//  Decode the HID report and set the pots
+int SetResist( uint8_t *data) {
+    int wiper = 0, value = 0;
+    dbg.printf("data[0] = %d\n",data[0]);
+    dbg.printf("data[1] = %d\n",data[1]);
+    dbg.printf("data[2] = %d\n",data[2]);
+    dbg.printf("data[3] = %d\n",data[3]);
+    dbg.printf("data[4] = %d\n",data[4]);
+    dbg.printf("data[5] = %d\n",data[5]);
+    if (data[0] != 3) return(1);
+    if (data[1] == 0) return(1); // Zero = bus disable
+    if (data[3] == 0) return(1); // Zero disallowed
+    Pbus = data[1];
+    if(data[4] > 0) wiper = (data[4] - 1);
+    value = data[5];
+    
+    switch (data[3]) {
+        case 1:
+            Chip1.SetValue(wiper, value);
+            dbg.printf("Set Pbus = %d, Chip = %d, Pot = %d, Value = %d\n", data[1], data[3], wiper, value);
+            break;
+        case 2:
+            Chip2.SetValue(wiper, value);
+            dbg.printf("Set Pbus = %d, Chip = %d, Pot = %d, Value = %d\n", data[1], data[3], wiper, value);
+            break;
+        case 3:
+            Chip3.SetValue(wiper, value);
+            dbg.printf("Set Pbus = %d, Chip = %d, Pot = %d, Value = %d\n", data[1], data[3], wiper, value);
+            break;
+        case 4:
+            Chip4.SetValue(wiper, value);
+            dbg.printf("Set Pbus = %d, Chip = %d, Pot = %d, Value = %d\n", data[1], data[3], wiper, value);
+            break;
+        case 5:
+            Chip5.SetValue(wiper, value);
+            dbg.printf("Set Pbus = %d, Chip = %d, Pot = %d, Value = %d\n", data[1], data[3], wiper, value);
+            break;
+        case 6:
+            Chip6.SetValue(wiper, value);
+            dbg.printf("Set Pbus = %d, Chip = %d, Pot = %d, Value = %d\n", data[1], data[3], wiper, value);
+            break;
+        default:
+            break;
+       }
+    dbg.printf("got here\n");
+    data[0] = 0;
+    Pbus = 0;
+    return(0);
+} // End SetResist
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DigiPot.h	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,5 @@
+//Digipot.h
+#include "mbed.h"
+
+int PotReset(void);
+int SetResist (uint8_t *);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP4651.cpp	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,78 @@
+/* mbed MCP4651 DigiPot Driver Library
+ *
+ * Copyright (c) 2012, Kevin Kent
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include "MCP4651.h"
+#include "mbed.h"
+
+/*
+ Constructor, pin names for I2C and the I2C offset address of the device
+ */
+MCP4651::MCP4651(PinName sda, PinName scl, int addr)
+        : _i2c(sda, scl) {
+
+    _i2c.frequency(1000000);
+
+    // Full I2C address = 0101b + A2:A1:A0:R/W
+    _addr = MCP4651_BASE + (addr << 1);
+
+}
+
+/* 
+Sets the value of the selected wiper
+*/
+
+int MCP4651::SetValue (int wiper, int value) {
+    int reg;
+    if (wiper == 0) {reg = MCP4651_VOL_WIPER0;}
+    if (wiper == 1) {reg = MCP4651_VOL_WIPER1 << 4;}
+    
+    _write(reg, value);
+
+    return(0);
+}
+
+
+
+
+// private functions for low level IO
+
+void MCP4651::_write(int reg, int data) {
+    char args[2];
+    args[0] = reg;
+    args[1] = data;
+    _i2c.write(_addr, args,2);
+}
+
+int MCP4651::_read(int reg) {
+    char args[2];
+    args[0] = reg;
+    _i2c.write(_addr, args, 1);
+    _i2c.read(_addr, args, 1);
+    return(args[0]);
+}
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP4651.h	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,71 @@
+/* mbed MCP4651 DigiPot Driver Library
+ *
+ * Copyright (c) 2012, Kevin Kent Trane US Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MCP4651_H
+#define MCP4651_H
+
+#include "mbed.h"
+
+// register names
+#define MCP4651_VOL_WIPER0  0
+#define MCP4651_VOL_WIPER1  1
+
+#define MCP4651_REG_TCON    4
+
+
+
+// Command modes
+// Left Shifted 2 bits for low nibble
+#define MCP4651_WR  0x0 // 00b
+#define MCP4651_RD  0xB // 11b
+#define MCP4651_INC 0x4 // 01b
+#define MCP4651_DEC 0x2 // 10b
+
+// Base Address of MCP4651 
+// 0101b + A2:A1:A0:R/W
+#define MCP4651_BASE 0x50
+
+class MCP4651 {
+
+public:
+
+    MCP4651(PinName sda, PinName scl, int addr);
+
+//    int SetLed  (int led, int mode);
+//    int SetMode (int mask, int mode);
+//    int Duty (int channel, float duty);
+//    int Period (int channel, float period);
+    int SetValue (int wiper, int value);
+    int GetValue (int wiper);
+
+protected:
+
+    void _write(int reg, int data);
+    int _read(int reg);
+    int _addr;
+    I2C _i2c;
+
+};
+
+
+#endif
\ No newline at end of file
--- a/MCP4661.cpp	Thu May 17 23:11:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/* mbed MCP4661 DigiPot Driver Library
- *
- * Copyright (c) 2012, Kevin Kent
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-#include "MCP4661.h"
-#include "mbed.h"
-
-/*
- Constructor, pin names for I2C and the I2C address of the device
- */
-MCP4661::MCP4661(PinName sda, PinName scl, int addr)
-        : _i2c(sda, scl) {
-
-    _i2c.frequency(1000000);
-
-    _addr = addr;
-
-}
-
-
-int MCP4661::SetValue (int wiper, int value) {
-    int reg;
-    if (wiper == 0) {reg = MCP4661_VOL_WIPER0;}
-    if (wiper == 1) {
-        reg = MCP4661_VOL_WIPER1;
-        reg = (reg << 4 );
-    }
-    reg |= MCP4661_WR;
-    _write(reg, value);
-    return(0);
-}
-int MCP4661::SetMode (int mask, int mode) {
-    if ( (mode < 0) || (mode > 3) ) {
-        return(1);
-    } else {
-        for (int i=0 ; i < 16 ; i++ ) {
-
-            // if this matches, set the LED to the mode
-            if (mask & (0x1 << i)) {
-                SetLed(i,mode);
-            }
-        }
-    }
-    return(0);
-}
-
-
-
-/*
- led is in the range 0-15
- mode is inthe range 0-3
- */
-int MCP4661::SetLed(int led, int mode) {
-
-    int reg = 0;
-    int offset = (led % 4);
-
-    printf("\nSetLed(%d,%d)\n", led, mode);
-
-    // makesure mode is within bounds
-    if ( (mode < 0) || (mode > 3) ) {
-        printf("Error : Invalid mode supplied\n");
-        return(1);
-    }
-
-    // determine which register this is,
- 
-
-    // read the current status of the register
-    char regval = _read(reg);
-
-    // clear the two bit slice at the calculated offset
-    regval &= ~(0x3 << (2 * offset));
-
-    // now OR in the mode, shifted by 2*offset
-    regval |= (mode << (2 * offset));
-
-    // write the new value back
-    _write(reg, regval);
-
-    return(0);
-}
-
-
-
-// private functions for low level IO
-
-void MCP4661::_write(int reg, int data) {
-    char args[2];
-    args[0] = reg;
-    args[1] = data;
-    _i2c.write(_addr, args,2);
-}
-
-int MCP4661::_read(int reg) {
-    char args[2];
-    args[0] = reg;
-    _i2c.write(_addr, args, 1);
-    _i2c.read(_addr, args, 1);
-    return(args[0]);
-}
-
-
-
-
-
--- a/MCP4661.h	Thu May 17 23:11:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/* mbed MCP4661 DigiPot Driver Library
- *
- * Copyright (c) 2012, Kevin Kent Trane US Inc
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef MCP4661_H
-#define MCP4661_H
-
-#include "mbed.h"
-
-// register names
-#define MCP4661_VOL_WIPER0  0
-#define MCP4661_VOL_WIPER1  1
-#define MCP4661_NV_WIPER0   2
-#define MCP4661_NV_WIPER1   3
-#define MCP4661_REG_TCON    4
-#define MCP4661_REG_STATUS  5
-#define MCP4661_EEPROM_0    6
-// #define MCP4661_EEPROM1  7
-// The Data EEPROM is 0x6 to 0xf
-
-
-// Command modes
-#define MCP4661_WR  0
-#define MODE_ON   1
-#define MODE_PWM0 2
-#define MODE_PWM1 3
-
-class MCP4661 {
-
-public:
-
-    MCP4661(PinName sda, PinName scl, int addr);
-
-    int SetLed  (int led, int mode);
-    int SetMode (int mask, int mode);
-    int Duty (int channel, float duty);
-    int Period (int channel, float period);
-    int SetValue (int wiper, int value);
-
-protected:
-
-    void _write(int reg, int data);
-    int _read(int reg);
-    int _addr;
-    I2C _i2c;
-
-};
-
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Max5250.cpp	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "Max5250.h" 
+
+ SPI spi(p5, NC, p7); 
+ DigitalOut cs(p8);
+ Serial dbg1(USBTX, USBRX);
+ 
+int DAC_Setup(void) {
+    spi.format(16,0);
+    spi.frequency(1000000);
+    return 1;
+    }
+
+/**********************************************************************
+* Configures the command from the data bytes and writes to the SPI  
+* MAX5250 command structure: A1,A0, C1,C0, D9..D0, S1,S0
+* A1,A0 - DAC addr, C1,C0 = 3 for immediate update, 1 for deferred update
+* D9..D0 = 10bit value [Vo = (Vref* D/1024)(Gain)] Gain = 1 in this desgin
+* S1,S0 = always zero
+*/
+int SetDAC(uint8_t *data){
+    int cmd;
+    
+    data[2] &= 3; //Fix to 3 max.
+    cmd = (data[1] << 12);
+    cmd += (data[2] << 10);
+    cmd += (data[3] << 2);
+    dbg1.printf("cmd = %0x\n", cmd);
+    
+    cs = 0;
+    spi.write(cmd);
+    cs = 1;
+    return 1;
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Max5250.h	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,4 @@
+#include "mbed.h"
+
+int DAC_Setup(void);
+int SetDAC(uint8_t *);
\ No newline at end of file
--- a/PCA9532.cpp	Thu May 17 23:11:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,191 +0,0 @@
-/* mbed PCF9532 LED Driver Library
- *
- * Copyright (c) 2010, cstyles (http://mbed.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-#include "PCA9532.h"
-#include "mbed.h"
-
-/*
- Constructor, pin names for I2C and the I2C addrss of the device
- */
-PCA9532::PCA9532(PinName scl, PinName sda, int addr)
-        : _i2c(scl, sda) {
-
-    _i2c.frequency(1000000);
-
-    _addr = addr;
-
-}
-
-
-
-
-
-/*
- Set the period
- */
-int PCA9532::Period (int channel, float period) {
-
-    char reg = 0;
-    
-    if (channel == 0) {
-       reg = PCA9532_REG_PSC0;
-    } else if (channel == 1) {
-       reg = PCA9532_REG_PSC1;
-    } else {
-        return (1);
-    }
-
-    if (period > 1.0) {
-        period = 255;
-    } else if ( period < 0.0 ) {
-        period = 0;
-    } else {
-        period = 256 * period;
-    }
-
-    _write(reg, period);
-    return(0);
-
-}
-
-
-/*
- Set the duty cycle
- */
-int PCA9532::Duty (int channel, float d) {
-
-    char duty = 0;
-    char reg = 0;
-    
-    if (channel == 0) {
-       reg = PCA9532_REG_PWM0;
-    } else if (channel == 1) {
-       reg = PCA9532_REG_PWM1;
-    } else {
-        return (1);
-    }
-
-    if (d > 1.0) {
-        duty = 255;
-    } else if ( d < 0.0 ) {
-        duty = 0;
-    } else {
-        duty = 256 * d;
-    }
-
-    _write(reg, duty);
-    return(0);
-
-}
-
-/*
- Set each of the LEDs in this mask to the give mode
- Loop through the mask calling SetLed on each match
- alt_mode specifies the mode of the non-Matches of SetMode
- */
-int PCA9532::SetMode (int mask, int mode) {
-    if ( (mode < 0) || (mode > 3) ) {
-        return(1);
-    } else {
-        for (int i=0 ; i < 16 ; i++ ) {
-
-            // if this matches, set the LED to the mode
-            if (mask & (0x1 << i)) {
-                SetLed(i,mode);
-            }
-        }
-    }
-    return(0);
-}
-
-
-
-/*
- led is in the range 0-15
- mode is inthe range 0-3
- */
-int PCA9532::SetLed(int led, int mode) {
-
-    int reg = 0;
-    int offset = (led % 4);
-
-    printf("\nSetLed(%d,%d)\n", led, mode);
-
-    // makesure mode is within bounds
-    if ( (mode < 0) || (mode > 3) ) {
-        printf("Error : Invalid mode supplied\n");
-        return(1);
-    }
-
-    // determine which register this is,
-    if (led < 4) {
-        reg = PCA9532_REG_LS0;
-    } else if ( (led > 3) && (led < 8) ) {
-        reg = PCA9532_REG_LS1;
-    } else if ( (led > 7) && (led < 12) ) {
-        reg = PCA9532_REG_LS2;
-    } else if ( (led > 11) && (led < 16) ) {
-        reg = PCA9532_REG_LS3;
-    } else {
-        return(1);
-    }
-
-    // read the current status of the register
-    char regval = _read(reg);
-
-    // clear the two bit slice at the calculated offset
-    regval &= ~(0x3 << (2 * offset));
-
-    // now OR in the mode, shifted by 2*offset
-    regval |= (mode << (2 * offset));
-
-    // write the new value back
-    _write(reg, regval);
-
-    return(0);
-}
-
-
-
-// private functions for low level IO
-
-void PCA9532::_write(int reg, int data) {
-    char args[2];
-    args[0] = reg;
-    args[1] = data;
-    _i2c.write(_addr, args,2);
-}
-
-int PCA9532::_read(int reg) {
-    char args[2];
-    args[0] = reg;
-    _i2c.write(_addr, args, 1);
-    _i2c.read(_addr, args, 1);
-    return(args[0]);
-}
-
-
-
-
-
--- a/PCA9532.h	Thu May 17 23:11:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/* mbed PCF9532 LED Driver Library
- *
- * Copyright (c) 2010, cstyles (http://mbed.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef PCA9532_H
-#define PCA9532_H
-
-#include "mbed.h"
-
-// register names
-#define PCA9532_REG_INPUT0 0
-#define PCA9532_REG_INPUT1 1
-#define PCA9532_REG_PSC0   2
-#define PCA9532_REG_PWM0   3
-#define PCA9532_REG_PSC1   4
-#define PCA9532_REG_PWM1   5
-#define PCA9532_REG_LS0    6
-#define PCA9532_REG_LS1    7
-#define PCA9532_REG_LS2    8
-#define PCA9532_REG_LS3    9
-
-// LED modes
-#define MODE_OFF  0
-#define MODE_ON   1
-#define MODE_PWM0 2
-#define MODE_PWM1 3
-
-class PCA9532 {
-
-public:
-
-    PCA9532(PinName sda, PinName scl, int addr);
-
-    int SetLed  (int led, int mode);
-    int SetMode (int mask, int mode);
-    int Duty (int channel, float duty);
-    int Period (int channel, float period);
-
-protected:
-
-    void _write(int reg, int data);
-    int _read(int reg);
-    int _addr;
-    I2C _i2c;
-
-};
-
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Relay.cpp	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "Relay.h"
+
+DigitalOut v13_en(p15);
+DigitalOut v18_en(p16);
+DigitalOut Ext_Sw(p17);
+DigitalOut Hpco(p18);
+
+//Set all relays open (NO->Com)
+int Def_Relay(void) {
+    Hpco = 0;
+    Ext_Sw = 0;
+    v13_en = 0;
+    v18_en = 0;
+    return 1;
+    }
+
+int Set_Relay(uint8_t *data) {
+    data[1] &= 0xf; //Only 4 relays
+    data[2] &= 0x1; //Only allow Zero or One
+    switch (data[1]) {
+        case 1:
+            v13_en = data[2];
+            break;
+        case 2:
+            v18_en = data[2];
+            break;
+        case 3:
+            Hpco = data[2];
+            break;
+        case 4:
+            Ext_Sw = data[2];
+            break;
+        default:
+            break;
+        }
+    return 1;
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Relay.h	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,5 @@
+//Relay.h
+
+
+int Def_Relay(void);
+int Set_Relay(uint8_t *data);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/samux/code/USBDevice/#140cdf8e2d60
--- a/main.cpp	Thu May 17 23:11:08 2012 +0000
+++ b/main.cpp	Wed Nov 14 20:01:50 2012 +0000
@@ -1,27 +1,60 @@
 #include "mbed.h"
-#include "MCP4661.h"
+#include "USBHID.h"
+#include "DigiPot.h"
+#include "Max5250.h"
+#include "Relay.h"
 
-DigitalOut myled(LED1);
-DigitalOut res(LED2);
-MCP4661 pot1(p28, p27, 0x5c);
-Serial pc(USBTX,USBRX);
- 
+ Serial pc(USBTX,USBRX);
+ USBHID hid;
+ HID_REPORT recv, xmit;
+ BusOut leds(LED1,LED2,LED3,LED4);
+
+
+ int main(void) {
+    int msgtype;
+    leds = 0xf;
+    xmit.length=64;
+   //Fill the report
+   for (int i = 0; i < xmit.length; i++)
+        xmit.data[i] =  0xa5;
 
-int main() {
-    int mid = 0x1;   
-    int address = 0x5c;
-    pc.printf("Hello Mbed World\n");
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-       res = pot1.SetValue(0,mid);
-       pc.printf("Val = %d",mid);
-        //data[0] = 0x04;
-       //res =  i2c.write(address, data, 1);
-        mid++;
-        wait(1.0);
-        res= 0;
-        wait(1.0);
-    }
-}
+    pc.printf("Resetting to Room Temp\n");
+    PotReset();
+   
+    pc.printf("Hello from mbed\n");
+    
+    DAC_Setup();      
+    pc.printf("DAC Setup Complete\n");
+   
+    pc.printf("Relays Resetting\n");
+    Def_Relay();
+   
+ while (1) {
+        hid.read(&recv);
+        leds = recv.data[0];
+        msgtype = recv.data[0];
+      
+        switch (msgtype) {
+        case 0:
+        case 1:
+        case 2:
+            break;
+        case 3:
+           pc.printf("Going to Resistor set\n");
+            SetResist(recv.data);
+        case 4:
+           pc.printf("Going to DAC set\n");
+            SetDAC(recv.data);
+            break;
+        case 5:
+           pc.printf("Going to Relay set\n");
+            Set_Relay(recv.data);
+            break;        
+        default:
+            break;
+        } //End switch
+      
+      hid.send(&xmit);   
+    } //End while
+ } //End Main
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 14 20:01:50 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06
\ No newline at end of file
--- a/mbed.lib	Thu May 17 23:11:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/projects/libraries/svn/mbed/trunk@43
\ No newline at end of file