@@ -63,6 +63,7 @@ void LSM9DS1::init(interface_mode interface, uint8_t xgAddr, uint8_t mAddr)
6363 settings.device .commInterface = interface;
6464 settings.device .agAddress = xgAddr;
6565 settings.device .mAddress = mAddr ;
66+ settings.device .i2c = &Wire;
6667
6768 settings.gyro .enabled = true ;
6869 settings.gyro .enableX = true ;
@@ -335,8 +336,7 @@ void LSM9DS1::initAccel()
335336// remove errors due to imprecise or varying initial placement. Calibration of sensor data in this manner
336337// is good practice.
337338void LSM9DS1::calibrate (bool autoCalc)
338- {
339- uint8_t data[6 ] = {0 , 0 , 0 , 0 , 0 , 0 };
339+ {
340340 uint8_t samples = 0 ;
341341 int ii;
342342 int32_t aBiasRawTemp[3 ] = {0 , 0 , 0 };
@@ -1150,47 +1150,47 @@ uint8_t LSM9DS1::SPIreadBytes(uint8_t csPin, uint8_t subAddress,
11501150
11511151void LSM9DS1::initI2C ()
11521152{
1153- Wire. begin (); // Initialize I2C library
1153+ settings. device . i2c -> begin (); // Initialize I2C library
11541154}
11551155
11561156// Wire.h read and write protocols
11571157void LSM9DS1::I2CwriteByte (uint8_t address, uint8_t subAddress, uint8_t data)
11581158{
1159- Wire. beginTransmission (address); // Initialize the Tx buffer
1160- Wire. write (subAddress); // Put slave register address in Tx buffer
1161- Wire. write (data); // Put data in Tx buffer
1162- Wire. endTransmission (); // Send the Tx buffer
1159+ settings. device . i2c -> beginTransmission (address); // Initialize the Tx buffer
1160+ settings. device . i2c -> write (subAddress); // Put slave register address in Tx buffer
1161+ settings. device . i2c -> write (data); // Put data in Tx buffer
1162+ settings. device . i2c -> endTransmission (); // Send the Tx buffer
11631163}
11641164
11651165uint8_t LSM9DS1::I2CreadByte (uint8_t address, uint8_t subAddress)
11661166{
1167- uint8_t data; // `data` will store the register data
1168-
1169- Wire. beginTransmission (address); // Initialize the Tx buffer
1170- Wire. write (subAddress); // Put slave register address in Tx buffer
1171- Wire. endTransmission (false ); // Send the Tx buffer, but send a restart to keep connection alive
1172- Wire. requestFrom (address, (uint8_t ) 1 ); // Read one byte from slave register address
1173-
1174- data = Wire. read (); // Fill Rx buffer with result
1167+ uint8_t data; // `data` will store the register data
1168+
1169+ settings. device . i2c -> beginTransmission (address); // Initialize the Tx buffer
1170+ settings. device . i2c -> write (subAddress); // Put slave register address in Tx buffer
1171+ settings. device . i2c -> endTransmission (false ); // Send the Tx buffer, but send a restart to keep connection alive
1172+ settings. device . i2c -> requestFrom (address, (uint8_t ) 1 ); // Read one byte from slave register address
1173+
1174+ data = settings. device . i2c -> read (); // Fill Rx buffer with result
11751175 return data; // Return data read from slave register
11761176}
11771177
11781178uint8_t LSM9DS1::I2CreadBytes (uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count)
11791179{
11801180 byte retVal;
1181- Wire. beginTransmission (address); // Initialize the Tx buffer
1181+ settings. device . i2c -> beginTransmission (address); // Initialize the Tx buffer
11821182 // Next send the register to be read. OR with 0x80 to indicate multi-read.
1183- Wire. write (subAddress | 0x80 ); // Put slave register address in Tx buffer
1184- retVal = Wire. endTransmission (false ); // Send Tx buffer, send a restart to keep connection alive
1183+ settings. device . i2c -> write (subAddress | 0x80 ); // Put slave register address in Tx buffer
1184+ retVal = settings. device . i2c -> endTransmission (false ); // Send Tx buffer, send a restart to keep connection alive
11851185 if (retVal != 0 ) // endTransmission should return 0 on success
11861186 return 0 ;
1187-
1188- retVal = Wire. requestFrom (address, count); // Read bytes from slave register address
1187+
1188+ retVal = settings. device . i2c -> requestFrom (address, count); // Read bytes from slave register address
11891189 if (retVal != count)
11901190 return 0 ;
1191-
1191+
11921192 for (int i=0 ; i<count;)
1193- dest[i++] = Wire. read ();
1194-
1193+ dest[i++] = settings. device . i2c -> read ();
1194+
11951195 return count;
11961196}
0 commit comments