valeria toffoli
/
COG4050_adxrs290_adxrs453
driver for gyro
Fork of COG4050_adxl355_adxl357-ver2 by
ADXRS290/ADXRS290.cpp
- Committer:
- vtoffoli
- Date:
- 2018-08-14
- Revision:
- 7:5aaa09c40283
- Parent:
- 6:45d2393ef468
- Child:
- 9:1afd906c5ed2
File content as of revision 7:5aaa09c40283:
#include <stdint.h> #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; adxrs290.format(8,_SPI_MODE); adxrs290.lock(); gyro_sens = 5e-3; t_sens = 0.1; } void ADXRS290::frequency(int hz) { adxrs290.frequency(hz); } /** ----------------------------------- */ /** Writes the reg register with data */ /** ----------------------------------- */ 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(){ return read_reg_u16(DATAX0); } uint16_t ADXRS290::scany(){ return read_reg_u16(DATAY0); } uint16_t ADXRS290::scant(){ return read_reg_u16(TEMP0); }