28 printf(
"icm20948-test: read test... ");
29 constexpr uint8_t who_am_i_address = 0;
30 constexpr uint8_t who_am_i_value = 0xea;
31 uint8_t ret = Serif::read(who_am_i_address);
32 if (ret == who_am_i_value) printf(
"passed!\n");
35 printf(
"unexpected who am I value %d?!\n", ret);
40 printf(
"icm20948-test: write test...");
42 constexpr uint8_t pwr_mgmt_1_address = 6;
43 constexpr uint8_t expected_value_after_reset = 0x41;
44 constexpr uint8_t wake_up_value = 0x01;
45 constexpr uint8_t reset_trigger_value = 0x81;
48 Serif::write(pwr_mgmt_1_address, reset_trigger_value);
52 uint8_t value_after_reset = Serif::read(pwr_mgmt_1_address);
53 if (value_after_reset != expected_value_after_reset)
55 printf(
" unexpected value after reset?!\n");
61 Serif::write(pwr_mgmt_1_address, wake_up_value);
65 uint8_t value_after_wake_up = Serif::read(pwr_mgmt_1_address);
66 if (value_after_wake_up != wake_up_value)
68 printf(
" write operation unsuccessful?!\n");
74 Serif::write(pwr_mgmt_1_address, reset_trigger_value);
80 printf(
"icm20948-test: register bases test...\n");
82 if (Registers::WHO_AM_I::read() != Registers::WHO_AM_I::after_reset)
84 printf(
" unexpected who am I value?!\n");
87 printf(
" WHO_AM_I good...\n");
89 Registers::PWR_MGMT_1::DEVICE_RESET::trigger();
92 auto v = Registers::PWR_MGMT_1::read();
93 if (v != Registers::PWR_MGMT_1::after_reset)
95 printf(
" unexpected value %x after reset?!\n", v);
98 printf(
" value after reset good...\n");
100 Registers::PWR_MGMT_1::SLEEP::disable();
104 uint8_t value_after_wake_up = Registers::PWR_MGMT_1::read();
105 uint8_t expected = Registers::PWR_MGMT_1::after_reset & ~Registers::PWR_MGMT_1::SLEEP::mask;
106 if (value_after_wake_up != expected)
108 printf(
" write operation unsuccessful?!\n");
111 printf(
" write operation good...\n");
113 Registers::PWR_MGMT_1::DEVICE_RESET::trigger();
116 printf(
" passed!\n");
119 printf(
"icm20948-test: AK09916 test... \n");
120 Registers::PWR_MGMT_1::DEVICE_RESET::trigger();
delay(10);
121 Registers::PWR_MGMT_1::SLEEP::disable();
delay(10);
122 Registers::PWR_MGMT_1::LP_EN::disable();
delay(1);
123 Registers::INT_PIN_CFG::BYPASS_EN::enable();
delay(1);
124 Registers::USER_CTRL::I2C_MST_EN::disable();
delay(1);
126 if (AK09916Registers::WIA2::read() != AK09916Registers::WIA2::after_reset)
128 printf(
"unable to connect to AK09916\n");
131 else printf(
"AK09916 connected...\n");
132 AK09916Registers::CNTL3::SRST::trigger();
delay(1);
133 AK09916Registers::CNTL2::MODE::PowerDown::set();
delay(1);
134 AK09916Registers::CNTL2::MODE::SelfTest::set();
delay(1);
136 while (i < 100 && !AK09916Registers::ST1::DRDY::read_field()) {
delay(10); }
139 printf(
"timeout while waiting for data ready?!\n");
142 constexpr uint8_t N_OUT = 8;
143 uint8_t measurement_data[N_OUT] = {0};
144 AK09916Serif::read(AK09916Registers::HXL::address, measurement_data, N_OUT);
145 int16_t x = measurement_data[1] << 8 | (measurement_data[0] & 0xFF);
146 int16_t y = measurement_data[3] << 8 | (measurement_data[2] & 0xFF);
147 int16_t z = measurement_data[5] << 8 | (measurement_data[4] & 0xFF);
148 if (!(-200 <= x && x <= 200))
150 printf(
"x data %d outside self-test range?! x: %d y: %d z: %d\n", x, x, y, z);
153 if (!(-200 <= y && y <= 200))
155 printf(
"y data %d outside self-test range?! x: %d y: %d z: %d\n", y, x, y, z);
158 if (!(-1000 <= z && z <= -200))
160 printf(
"z data %d outside self-test range?! x: %d y: %d z: %d\n", z, x, y, z);
163 printf(
"AK09916 self test pass! x: %d y: %d z: %d\n", x, y, z);