5 #include "libpropeller/l3gd20/l3gd20.h" 6 #include "libpropeller/i2c/i2cMOCK.h" 10 const int kSDAPin = 1;
11 const int kSCLPin = 2;
20 static void setUp(
void) {
22 bus->
Init(kSCLPin, kSDAPin);
23 gyro.
Init(bus, libpropeller::L3GD20::LSB_1);
26 static void tearDown(
void) {
33 static void test_Init(
void) {
34 TEST_ASSERT_EQUAL_INT(0b00110000, bus->GetPutStack());
35 TEST_ASSERT_EQUAL_INT(0b11111111, bus->GetPutStack());
36 TEST_ASSERT_EQUAL_INT(-1, bus->GetPutStack());
39 static void test_ReadGyroPositiveNumbers(
void) {
40 char indata[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
41 bus->SetXYZ(indata, 6);
43 TEST_ASSERT_TRUE(gyro.
ReadGyro(x, y, z));
45 TEST_ASSERT_EQUAL_HEX32(0x0201, x);
46 TEST_ASSERT_EQUAL_HEX32(0x0403, y);
47 TEST_ASSERT_EQUAL_HEX32(0x0605, z);
50 static void test_ReadGyroNegativeNumbers(
void) {
51 char indata[] = {0x01, 0xF2, 0x03, 0xF4, 0x05, 0xF6};
52 bus->SetXYZ(indata, 6);
54 TEST_ASSERT_TRUE(gyro.
ReadGyro(x, y, z));
56 TEST_ASSERT_EQUAL_HEX32(0xFFFFF201, x);
57 TEST_ASSERT_EQUAL_HEX32(0xFFFFF403, y);
58 TEST_ASSERT_EQUAL_HEX32(0xFFFFF605, z);
bool Init(I2C *i2c_bus, const AddressLSB address=LSB_0)
void Init(const int scl=28, const int sda=29, const int frequency=400000)
bool ReadGyro(int &x, int &y, int &z)