valeria toffoli
/
COG4050_adxrs290_adxrs453
driver for gyro
Fork of COG4050_adxl355_adxl357-ver2 by
Diff: ADXRS290/ADXRS290.cpp
- Revision:
- 7:5aaa09c40283
- Parent:
- 6:45d2393ef468
- Child:
- 9:1afd906c5ed2
diff -r 45d2393ef468 -r 5aaa09c40283 ADXRS290/ADXRS290.cpp --- a/ADXRS290/ADXRS290.cpp Tue Aug 14 06:49:07 2018 +0000 +++ b/ADXRS290/ADXRS290.cpp Tue Aug 14 11:33:30 2018 +0000 @@ -2,7 +2,9 @@ #include "mbed.h" #include "ADXRS290.h" - +/** ----------------------------------- */ +/** SPI - MAX 5MHZ */ +/** ----------------------------------- */ ADXRS290::ADXRS290(PinName cs_pin, PinName MOSI, PinName MISO, PinName SCK): adxrs290(MOSI, MISO, SCK), cs(cs_pin) { cs = 1; @@ -11,8 +13,6 @@ gyro_sens = 5e-3; t_sens = 0.1; } - -/** SPI bus frequency */ void ADXRS290::frequency(int hz) { adxrs290.frequency(hz); @@ -21,15 +21,53 @@ /** ----------------------------------- */ /** Writes the reg register with data */ /** ----------------------------------- */ -void ADXRS290::write_reg(ADXRS290_register_t reg, uint8_t data){} -uint8_t ADXRS290::read_reg(ADXRS290_register_t reg){} -uint16_t ADXRS290::read_reg_u16(ADXRS290_register_t reg){} - -void ADXRS290::set_power_ctl_reg(uint8_t data){} -void ADXRS290::set_filter_ctl_reg(ADXRS290_filter_ctl_t hpf, ADXRS290_filter_ctl_t odr){} +void ADXRS290::write_reg(ADXRS290_register_t reg, uint8_t data){ + adxrs290.format(8, _SPI_MODE); + cs = false; + adxrs290.write(static_cast<uint8_t>(reg) | _WRITE_REG_CMD); + adxrs290.write(data); + cs = true; +} +/** ----------------------------------- */ +/** Reads the reg register */ +/** ----------------------------------- */ +uint8_t ADXRS290::read_reg(ADXRS290_register_t reg){ + uint8_t ret_val; + adxrs290.format(8, _SPI_MODE); + cs = false; + adxrs290.write(static_cast<uint8_t>(reg) | _READ_REG_CMD); + ret_val = adxrs290.write(_DUMMY_BYTE); + cs = true; + return ret_val; +} +uint16_t ADXRS290::read_reg_u16(ADXRS290_register_t reg){ + uint16_t ret_val = 0; + adxrs290.format(8, _SPI_MODE); + cs = false; + adxrs290.write(static_cast<uint8_t>(reg) | _READ_REG_CMD); + ret_val = adxrs290.write(_DUMMY_BYTE); + ret_val = (ret_val) | (adxrs290.write(_DUMMY_BYTE)<<8); + cs = true; + return ret_val; +} +/** ----------------------------------- */ +/** Sets the CTL registers */ +/** ----------------------------------- */ +void ADXRS290::set_power_ctl_reg(uint8_t data){ + write_reg(POWER_CTL, data); + wait(0.1); +} +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){} -uint16_t ADXRS290::scanx(){} -uint16_t ADXRS290::scany(){} -uint16_t ADXRS290::scant(){} - \ No newline at end of file +uint16_t ADXRS290::scanx(){ + return read_reg_u16(DATAX0); +} +uint16_t ADXRS290::scany(){ + return read_reg_u16(DATAY0); +} +uint16_t ADXRS290::scant(){ + return read_reg_u16(TEMP0); +} \ No newline at end of file