ADT7320 temperature sensor.

Dependents:   sscm

Fork of T_adt7320 by wimbeaumont Project

Files at this revision

API Documentation at this revision

Comitter:
NickRyder
Date:
Tue Oct 07 21:31:07 2014 +0000
Parent:
1:1b9f706b8abc
Commit message:
Tidying up.

Changed in this revision

adt7320.cpp Show annotated file Show diff for this revision Revisions of this file
adt7320.h Show annotated file Show diff for this revision Revisions of this file
diff -r 1b9f706b8abc -r 186e3c0afcad adt7320.cpp
--- a/adt7320.cpp	Sun Oct 05 17:12:21 2014 +0000
+++ b/adt7320.cpp	Tue Oct 07 21:31:07 2014 +0000
@@ -9,80 +9,73 @@
 
 
 
-adt7320::adt7320(SWSPI *spiinterface ,DigitalOut* chipselect )
-:getVersion( ADT7320_HDR_VER ,ADT7320_SRC_VER , __TIME__, __DATE__)
+adt7320::adt7320(SWSPI * spiinterface, DigitalOut * chipselect):
+    getVersion(ADT7320_HDR_VER, ADT7320_SRC_VER, __TIME__, __DATE__)
 {
     spi=spiinterface;
     cs=chipselect;
-    }
+}
 
 void adt7320::set_spi_mode(u8 nrbyte){
     spi->format(nrbyte,1);
     spi->frequency(10000000);             
 }
 
-
-u8   adt7320::format_cmd( u8 reg, bool rw){
-    u8  cmd=0; ;
-    reg= reg & 0x7;
+u8 adt7320::format_cmd(u8 reg, bool rw){
+    u8 cmd = 0;
+    reg = reg & 0x7;
     cmd = reg << 3;
-    if ( rw)  cmd |= 0x40;  // write bit 6 
+    if (rw) cmd |= 0x40;  // write bit 6 
     return cmd; 
 }    
-    
 
-
-u8   adt7320::getR08( u8 reg){
+u8 adt7320::getR08(u8 reg) {
     set_spi_mode(16);
-    u16 data=0x00FF;
-    u16 cmd = (u16) format_cmd(reg,true);
-    cmd = cmd <<8;
-    data= data | cmd;
-     cs->write(CS_ACTIVE);
-     data= spi->write(data);
-     cs->write(CS_DEACTIVE);
-     return (u8)(0x00FF &data);         
-    
+    u16 data = 0x00FF;
+    u16 cmd = (u16) format_cmd(reg, true);
+    cmd = cmd << 8;
+    data = data | cmd;
+    cs->write(CS_ACTIVE);
+    data= spi->write(data);
+    cs->write(CS_DEACTIVE);
+    return (u8) (0x00FF & data);
 }
 
-
-void   adt7320::setR08( u8 reg, u8 datain){
+void adt7320::setR08(u8 reg, u8 datain) {
     set_spi_mode(16);
-    u16 data=0x0000;
-    u16 cmd = (u16) format_cmd(reg,false);
-    cmd = cmd <<8;
-    data= datain | cmd;
+    u16 data = 0x0000;
+    u16 cmd = (u16) format_cmd(reg, false);
+    cmd = cmd << 8;
+    data = datain | cmd;
     cs->write(CS_ACTIVE);
-    data= spi->write(data);
+    data = spi->write(data);
     cs->write(CS_DEACTIVE);    
 }
 
-u16   adt7320::getR16( u8 reg){
+u16 adt7320::getR16(u8 reg) {
     set_spi_mode(24);
-    u32 data=0x0000FFFF;
-    u32 cmd =(u32) format_cmd(reg,true);
-    cmd = cmd <<16;
-    data= data | cmd;
-     cs->write(CS_ACTIVE);
-     data= spi->write(data);
-     cs->write(CS_DEACTIVE);
-     return (u16)(0x0000FFFF &data);             
+    u32 data = 0x0000FFFF;
+    u32 cmd = (u32) format_cmd(reg, true);
+    cmd = cmd << 16;
+    data = data | cmd;
+    cs->write(CS_ACTIVE);
+    data= spi->write(data);
+    cs->write(CS_DEACTIVE);
+    return (u16) (0x0000FFFF & data);             
 }
 
-void  adt7320::setR16( u8 reg,u16 datain){
-        set_spi_mode(24);
-        u32 data=0x00000000;
-        u32 cmd =(u32) format_cmd(reg,false);
-        cmd = cmd <<16;
-        data= datain | cmd;
-        cs->write(CS_ACTIVE);
-        data= spi->write(data);
-        cs->write(CS_DEACTIVE);
+void  adt7320::setR16(u8 reg, u16 datain) {
+    set_spi_mode(24);
+    u32 data = 0x00000000;
+    u32 cmd = (u32) format_cmd(reg, false);
+    cmd = cmd << 16;
+    data = datain | cmd;
+    cs->write(CS_ACTIVE);
+    data = spi->write(data);
+    cs->write(CS_DEACTIVE);
 }
 
-
-
-u8  adt7320::getId(){
+u8 adt7320::getId(){
     return getR08(0x03);
 }
 
@@ -91,19 +84,16 @@
 }    
 
 void adt7320::set_TcritSP(u16 tcrit){
-    
-    setR16(0x04,tcrit );   
+    setR16(0x04, tcrit);   
 }    
 
-
-
 u16 adt7320::get_T(){
     return getR16(0x02);   
 }    
 
 
-      void adt7320::init1(){}
-       void adt7320::init2(){}
+void adt7320::init1() {
+}
 
-
-
+void adt7320::init2() {
+}
\ No newline at end of file
diff -r 1b9f706b8abc -r 186e3c0afcad adt7320.h
--- a/adt7320.h	Sun Oct 05 17:12:21 2014 +0000
+++ b/adt7320.h	Tue Oct 07 21:31:07 2014 +0000
@@ -12,37 +12,27 @@
 
 #define ADT7320_HDR_VER "1.13" 
 
-class adt7320 : public getVersion{
-
-void set_spi_mode(u8 nrbyte);
-
-private:
-    SWSPI* spi;
-    DigitalOut* cs;
-    
-    u8   format_cmd( u8 reg, bool rw);
-    u8   getR08( u8 addr);
-    void setR08( u8 addr, u8 datain);
-    u16  getR16( u8 addr);
-    void  setR16( u8 addr, u16 datain);
-        
-public:
-
-    adt7320(SWSPI *spiinterface ,DigitalOut* chipselect );
-    float getTemperature(){return -280;};    // to be implenented 
-    u8  getId();
-    u16 get_TcritSP();
-    void set_TcritSP(u16 tcrit);
-    u16 get_T(); //  get the temperature register
-    u16 get_hdr_ver();// returns the hdr version nr 
-    u16 get_src_ver();// returns the src version nr 
-    void init1();
-    void init2();
-    
-   
+class adt7320 : public getVersion {
+    void set_spi_mode(u8 nrbyte);
+    private:
+        SWSPI* spi;
+        DigitalOut* cs;
+        u8 format_cmd(u8 reg, bool rw);
+        u8 getR08(u8 addr);
+        void setR08(u8 addr, u8 datain);
+        u16 getR16(u8 addr);
+        void setR16(u8 addr, u16 datain);
+    public:
+        adt7320(SWSPI * spiinterface, DigitalOut * chipselect);
+        float getTemperature() {return -280;};    // to be implenented 
+        u8 getId();
+        u16 get_TcritSP();
+        void set_TcritSP(u16 tcrit);
+        u16 get_T(); //  get the temperature register
+        u16 get_hdr_ver();// returns the hdr version nr 
+        u16 get_src_ver();// returns the src version nr 
+        void init1();
+        void init2();
 };
 
-
-
-
 #endif 
\ No newline at end of file