Fork of Ds3231 library that replaces inheritance of I2C class with a private member var of type I2C *

Dependents:   ard2pmod DS3231_Alarm_Demo MAXREFDES130_131_Demo MAXREFDES130_Demo

Fork of ds3231 by Maxim Integrated

Revision:
15:16ca4c747252
Parent:
14:11630748e2f2
Child:
16:e1c0f63595d9
--- a/ds3231.h	Wed Mar 18 00:06:59 2015 +0000
+++ b/ds3231.h	Mon Mar 28 19:17:34 2016 +0000
@@ -1,19 +1,4 @@
 /******************************************************************//**
-* @file ds3231.h
-*
-* @author Justin Jordan
-*
-* @version 1.0
-*
-* Started: 11NOV14
-*
-* Updated: 
-*
-* @brief Header file for DS3231 class
-*
-***********************************************************************
-*
-* @copyright 
 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -53,31 +38,7 @@
 #include "mbed.h"
 
 
-#define DS3231_I2C_ADRS 0x68 
-#define I2C_WRITE 0
-#define I2C_READ  1
 
-#define AM_PM     (1 << 5) 
-#define MODE      (1 << 6)
-#define DY_DT     (1 << 6)
-#define ALRM_MASK (1 << 7)
-
-//control register bit masks
-#define A1IE  (1 << 0)
-#define A2IE  (1 << 1)
-#define INTCN (1 << 2)
-#define RS1   (1 << 3)
-#define RS2   (1 << 4)
-#define CONV  (1 << 5)
-#define BBSQW (1 << 6)
-#define EOSC  (1 << 7)
-
-//status register bit masks
-#define A1F     (1 << 0)
-#define A2F     (1 << 1)
-#define BSY     (1 << 2)
-#define EN32KHZ (1 << 3)
-#define OSF     (1 << 7)
   
 
 /**
@@ -191,38 +152,8 @@
 }ds3231_cntl_stat_t;
         
                 
-/******************************************************************//**
-* Ds3231 Class
-**********************************************************************/
-class Ds3231 : public I2C
+class Ds3231
 {
-    uint8_t w_adrs, r_adrs;
-    
-    /**********************************************************//**
-    * Private mmber fx, converts unsigned char to BCD
-    *
-    * On Entry:
-    *     @param[in] data - 0-255
-    *
-    * On Exit:
-    *     @return bcd_result = BCD representation of data
-    *
-    **************************************************************/
-    uint16_t uchar_2_bcd(uint8_t data);
-    
-    
-    /**********************************************************//**
-    * Private mmber fx, converts BCD to a uint8_t
-    *
-    * On Entry:
-    *     @param[in] bcd - 0-99
-    *
-    * On Exit:
-    *     @return rtn_val = integer rep. of BCD
-    *
-    **************************************************************/
-    uint8_t bcd_2_uchar(uint8_t bcd);
-    
     public:
     
         /**
@@ -274,6 +205,22 @@
         
         
         /**********************************************************//**
+        * Constructor for Ds3231 Class
+        *
+        * On Entry:
+        *     @param[in] i2c_bus - reference to existing bus
+        *
+        * On Exit:
+        * 
+        * @return none
+        **************************************************************/
+        Ds3231(I2C & i2c_bus);
+        
+        
+        ~Ds3231();
+        
+        
+        /**********************************************************//**
         * Sets the time on DS3231
         * Struct data is in integrer format, not BCD.  Fx will convert
         * to BCD for you.
@@ -545,5 +492,37 @@
         **************************************************************/
         time_t get_epoch(void);
         
+        private:
+        
+        I2C * _p_i2c;
+        
+        bool _i2c_owner;
+        uint8_t _w_adrs, _r_adrs;
+        
+        /**********************************************************//**
+        * Private mmber fx, converts unsigned char to BCD
+        *
+        * On Entry:
+        *     @param[in] data - 0-255
+        *
+        * On Exit:
+        *     @return bcd_result = BCD representation of data
+        *
+        **************************************************************/
+        uint16_t uchar_2_bcd(uint8_t data);
+        
+        
+        /**********************************************************//**
+        * Private mmber fx, converts BCD to a uint8_t
+        *
+        * On Entry:
+        *     @param[in] bcd - 0-99
+        *
+        * On Exit:
+        *     @return rtn_val = integer rep. of BCD
+        *
+        **************************************************************/
+        uint8_t bcd_2_uchar(uint8_t bcd);
+        
 };
 #endif /* DS3231_H*/