driver for gyro

Dependencies:   COG4050_ADT7420

Fork of COG4050_adxl355_adxl357-ver2 by ADI_CAC

Revision:
9:1afd906c5ed2
Parent:
7:5aaa09c40283
diff -r 9e6ead2ee8d7 -r 1afd906c5ed2 ADXRS290/ADXRS290.cpp
--- a/ADXRS290/ADXRS290.cpp	Tue Aug 21 13:25:37 2018 +0000
+++ b/ADXRS290/ADXRS290.cpp	Fri Sep 07 15:49:25 2018 +0000
@@ -10,8 +10,6 @@
     cs = 1;
     adxrs290.format(8,_SPI_MODE);
     adxrs290.lock();
-    gyro_sens = 5e-3;
-    t_sens = 0.1;
 }
 void ADXRS290::frequency(int hz)
 {
@@ -60,8 +58,11 @@
 void ADXRS290::set_filter_ctl_reg(ADXRS290_filter_ctl_t hpf, ADXRS290_filter_ctl_t lpf){
     write_reg(FILTER, hpf|lpf);
 }
-void ADXRS290::set_sync(ADXRS290_dataready_ctl_t data){}
-    
+void ADXRS290::set_sync(ADXRS290_dataready_ctl_t data){
+    }
+/** ----------------------------------- */
+/** READ data registers              */
+/** ----------------------------------- */ 
 uint16_t ADXRS290::scanx(){    
     return read_reg_u16(DATAX0);
 }
@@ -70,4 +71,27 @@
 }
 uint16_t ADXRS290::scant(){
     return read_reg_u16(TEMP0);
-}    
\ No newline at end of file
+}    
+ADXRS290::ADXRS290_rate_t ADXRS290::scan(){
+    uint16_t datax, datay, dataz;
+    ADXRS290_rate_t res;
+    // multiple byte read procedure
+    adxrs290.format(8, _SPI_MODE);
+    cs = false;
+    adxrs290.write(static_cast<uint8_t>(DATAX0) | _READ_REG_CMD);
+    datax = adxrs290.write(_DUMMY_BYTE);
+    datax = (datax) | (adxrs290.write(_DUMMY_BYTE)<<8);
+    datay = adxrs290.write(_DUMMY_BYTE);
+    datay = (datay) | (adxrs290.write(_DUMMY_BYTE)<<8);
+    dataz = adxrs290.write(_DUMMY_BYTE);
+    dataz = (dataz) | (adxrs290.write(_DUMMY_BYTE)<<8);
+    cs = true;
+    // 2s compl conversion
+    if ((datax & 0x8000) == 0) {res.rt_x=float(datax);}
+    else{res.rt_x=float((~(datax - 0x01)) & 0xffff) * -1;}
+    if ((datay & 0x8000) == 0) {res.rt_y=float(datay);}
+    else{res.rt_y=float((~(datay - 0x01)) & 0xffff) * -1;}
+    if ((dataz & 0x8000) == 0) {res.rt_z=float(dataz);}
+    else{res.rt_z=float((~(dataz - 0x01)) & 0xffff) * -1;}
+    return res;
+}
\ No newline at end of file