ISL1208 library based on original ISL1208 library, modified to suit our needs.

Fork of ISL1208 by Neil Thiessen

Revision:
4:42dc07f9ffb3
Parent:
3:115e4dacfe07
Child:
5:d67ac8351c76
--- a/ISL1208.cpp	Thu Nov 07 18:21:19 2013 +0000
+++ b/ISL1208.cpp	Tue Nov 12 17:15:20 2013 +0000
@@ -22,19 +22,13 @@
     m_I2C.frequency(400000);
 }
 
-bool ISL1208::open(OscillatorMode mode)
+bool ISL1208::open()
 {
     //Probe for the ISL1208 using a Zero Length Transfer
     if (!m_I2C.write(m_ADDR, NULL, 0)) {
         //Read the current status register
         char sr = read8(REG_CTL_SR);
 
-        //Configure the oscillator mode
-        if (mode == OSCILLATOR_CRYSTAL)
-            sr &= ~(1 << 6);
-        else
-            sr |= (1 << 6);
-
         //Disable auto reset for BAT and ALM bits
         sr &= ~(1 << 7);
 
@@ -171,6 +165,33 @@
     write8(REG_CTL_SR, value);
 }
 
+ISL1208::OscillatorMode ISL1208::oscillatorMode()
+{
+    //Read the 8-bit register value
+    char value = read8(REG_CTL_SR);
+
+    //Return the status of the XTOSCB bit
+    if (value & (1 << 6))
+        return OSCILLATOR_EXTERNAL;
+    else
+        return OSCILLATOR_CRYSTAL;
+}
+
+void ISL1208::oscillatorMode(OscillatorMode mode)
+{
+    //Read the current 8-bit register value
+    char value = read8(REG_CTL_SR);
+
+    //Set or clear the XTOSCB bit
+    if (mode == OSCILLATOR_EXTERNAL)
+        value |= (1 << 6);
+    else
+        value &= ~(1 << 6);
+
+    //Write the value back out
+    write8(REG_CTL_SR, value);
+}
+
 ISL1208::OutputFrequency ISL1208::foutFrequency()
 {
     //Read the 8-bit register value