10
10
#include <zephyr/drivers/sensor.h>
11
11
#include <zephyr/ztest.h>
12
12
13
+ #include "akm09918c.h"
13
14
#include "akm09918c_emul.h"
14
15
#include "akm09918c_reg.h"
15
16
@@ -72,19 +73,19 @@ static void test_fetch_magnetic_field(const struct akm09918c_fixture *fixture,
72
73
73
74
/* Assert the data is within 0.000005 Gauss */
74
75
actual_ugauss = values [0 ].val1 * INT64_C (1000000 ) + values [0 ].val2 ;
75
- expect_ugauss = magn_percent [0 ] * INT64_C ( 500 ) ;
76
+ expect_ugauss = magn_percent [0 ] * AKM09918C_MICRO_GAUSS_PER_BIT ;
76
77
zassert_within (expect_ugauss , actual_ugauss , INT64_C (5 ),
77
78
"(X) expected %" PRIi64 " micro-gauss, got %" PRIi64 " micro-gauss" ,
78
79
expect_ugauss , actual_ugauss );
79
80
80
81
actual_ugauss = values [1 ].val1 * INT64_C (1000000 ) + values [1 ].val2 ;
81
- expect_ugauss = magn_percent [1 ] * INT64_C ( 500 ) ;
82
+ expect_ugauss = magn_percent [1 ] * AKM09918C_MICRO_GAUSS_PER_BIT ;
82
83
zassert_within (expect_ugauss , actual_ugauss , INT64_C (5 ),
83
84
"(Y) expected %" PRIi64 " micro-gauss, got %" PRIi64 " micro-gauss" ,
84
85
expect_ugauss , actual_ugauss );
85
86
86
87
actual_ugauss = values [2 ].val1 * INT64_C (1000000 ) + values [2 ].val2 ;
87
- expect_ugauss = magn_percent [2 ] * INT64_C ( 500 ) ;
88
+ expect_ugauss = magn_percent [2 ] * AKM09918C_MICRO_GAUSS_PER_BIT ;
88
89
zassert_within (expect_ugauss , actual_ugauss , INT64_C (5 ),
89
90
"(Z) expected %" PRIi64 " micro-gauss, got %" PRIi64 " micro-gauss" ,
90
91
expect_ugauss , actual_ugauss );
@@ -94,9 +95,9 @@ ZTEST_F(akm09918c, test_fetch_magn)
94
95
{
95
96
/* Use (0.25, -0.33..., 0.91) as the factors */
96
97
const int16_t magn_percent [3 ] = {
97
- INT16_C (32752 ) / INT16_C (4 ),
98
- INT16_C (-32751 ) / INT16_C (3 ),
99
- (int16_t )(INT16_C (32752 ) * INT32_C (91 ) / INT32_C (100 )),
98
+ INT16_C (AKM09918C_MAGN_MAX_DATA_REG ) / INT16_C (4 ),
99
+ INT16_C (AKM09918C_MAGN_MIN_DATA_REG ) / INT16_C (3 ),
100
+ (int16_t )(INT16_C (AKM09918C_MAGN_MAX_DATA_REG ) * INT32_C (91 ) / INT32_C (100 )),
100
101
};
101
102
102
103
test_fetch_magnetic_field (fixture , magn_percent );
0 commit comments