Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/F_AK09918.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum AK09918_err_type_t {

class AK09918 : public IMUBase {
public:
AK09918() {};
explicit AK09918(TwoWire& wire = Wire) : wire(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override;
Expand Down Expand Up @@ -109,35 +109,36 @@ class AK09918 : public IMUBase {
calData calibration;
uint8_t IMUAddress;

TwoWire& wire;

void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.write(data); // Put data in Tx buffer
wire.endTransmission(); // Send the Tx buffer
}

uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}

void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read();
wire.requestFrom(address, count); // Read bytes from slave register address
while (wire.available()) {
dest[i++] = wire.read();
} // Put read results in the Rx buffer
}

Expand Down
33 changes: 17 additions & 16 deletions src/F_AK8963.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class AK8963 : public IMUBase {
public:
AK8963() {};
explicit AK8963(TwoWire& wire = Wire) : wire(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override;
Expand Down Expand Up @@ -81,35 +81,36 @@ class AK8963 : public IMUBase {
calData calibration;
uint8_t IMUAddress;

TwoWire& wire;

void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.write(data); // Put data in Tx buffer
wire.endTransmission(); // Send the Tx buffer
}

uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}

void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read();
wire.requestFrom(address, count); // Read bytes from slave register address
while (wire.available()) {
dest[i++] = wire.read();
} // Put read results in the Rx buffer
}

Expand Down
33 changes: 17 additions & 16 deletions src/F_AK8975.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class AK8975 : public IMUBase {
public:
AK8975() {};
explicit AK8975(TwoWire& wire = Wire) : wire(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override;
Expand Down Expand Up @@ -81,35 +81,36 @@ class AK8975 : public IMUBase {
calData calibration;
uint8_t IMUAddress;

TwoWire& wire;

void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.write(data); // Put data in Tx buffer
wire.endTransmission(); // Send the Tx buffer
}

uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}

void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read();
wire.requestFrom(address, count); // Read bytes from slave register address
while (wire.available()) {
dest[i++] = wire.read();
} // Put read results in the Rx buffer
}

Expand Down
33 changes: 17 additions & 16 deletions src/F_BMI055.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

class BMI055 : public IMUBase {
public:
BMI055() {};
explicit BMI055(TwoWire& wire = Wire) : wire(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override;
Expand Down Expand Up @@ -94,35 +94,36 @@ class BMI055 : public IMUBase {
uint8_t AccelAddress;
uint8_t GyroAddress;

TwoWire& wire;

void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.write(data); // Put data in Tx buffer
wire.endTransmission(); // Send the Tx buffer
}

uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}

void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read();
wire.requestFrom(address, count); // Read bytes from slave register address
while (wire.available()) {
dest[i++] = wire.read();
} // Put read results in the Rx buffer
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/F_BMI055_AK8975.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BMI055_QMC5883L : public IMUBase {
public:
BMI055_QMC5883L() {};
explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override {
Expand Down
2 changes: 1 addition & 1 deletion src/F_BMI055_HMC5883L.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BMI055_HMC5883L : public IMUBase {
public:
BMI055_HMC5883L() {};
explicit BMI055_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override {
Expand Down
2 changes: 1 addition & 1 deletion src/F_BMI055_QMC5883L.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BMI055_QMC5883L : public IMUBase {
public:
BMI055_QMC5883L() {};
explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override {
Expand Down
33 changes: 17 additions & 16 deletions src/F_BMI160.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

class BMI160 : public IMUBase {
public:
BMI160() {};
explicit BMI160(TwoWire& wire = Wire) : wire(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override;
Expand Down Expand Up @@ -154,35 +154,36 @@ class BMI160 : public IMUBase {
calData calibration;
uint8_t IMUAddress;

TwoWire& wire;

void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.write(data); // Put data in Tx buffer
wire.endTransmission(); // Send the Tx buffer
}

uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}

void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
wire.beginTransmission(address); // Initialize the Tx buffer
wire.write(subAddress); // Put slave register address in Tx buffer
wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read();
wire.requestFrom(address, count); // Read bytes from slave register address
while (wire.available()) {
dest[i++] = wire.read();
} // Put read results in the Rx buffer
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/F_BMI160_AK8975.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BMI160_AK8975 : public IMUBase {
public:
BMI160_AK8975() {};
explicit BMI160_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override {
Expand Down
2 changes: 1 addition & 1 deletion src/F_BMI160_HMC5883L.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BMI160_HMC5883L : public IMUBase {
public:
BMI160_HMC5883L() {};
explicit BMI160_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override {
Expand Down
2 changes: 1 addition & 1 deletion src/F_BMI160_QMC5883L.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BMI160_QMC5883L : public IMUBase {
public:
BMI160_QMC5883L() {};
explicit BMI160_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {};

// Inherited via IMUBase
int init(calData cal, uint8_t address) override {
Expand Down
Loading
Loading