38 #include <px4_platform_common/px4_config.h> 39 #include <px4_platform_common/log.h> 40 #include <px4_platform_common/time.h> 44 #include <px4_platform_common/getopt.h> 67 if (*g_dev_ptr !=
nullptr) {
68 PX4_ERR(
"already started");
73 #if defined(PX4_I2C_BUS_EXPANSION) 74 *g_dev_ptr =
new AK09916(PX4_I2C_BUS_EXPANSION, path, rotation);
76 PX4_ERR(
"External I2C not available");
81 PX4_ERR(
"Internal I2C not available");
85 if (*g_dev_ptr ==
nullptr || (
OK != (*g_dev_ptr)->init())) {
86 PX4_ERR(
"driver start failed");
100 if (*g_dev_ptr ==
nullptr) {
101 PX4_ERR(
"driver not running");
105 (*g_dev_ptr)->stop();
115 if (*g_dev_ptr ==
nullptr) {
116 PX4_ERR(
"driver not running");
120 printf(
"state @ %p\n", *g_dev_ptr);
121 (*g_dev_ptr)->print_info();
129 PX4_INFO(
"missing command: try 'start', 'info', stop'");
130 PX4_INFO(
"options:");
131 PX4_INFO(
" -X (external bus)");
132 PX4_INFO(
" -R (rotation)");
139 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id())),
164 PX4_WARN(
"AK09916 mag init failed");
215 reinterpret_cast<uint8_t *>(®s),
sizeof(regs));
243 const uint8_t cmd = reg;
246 transfer(&cmd, 1, &ret, 1);
262 const uint8_t cmd[2] = { reg, value};
263 transfer(cmd, 2,
nullptr, 0);
295 }
while (retries > 0);
344 const char *myoptarg =
nullptr;
345 bool external_bus =
false;
348 while ((ch = px4_getopt(argc, argv,
"XR:", &myoptind, &myoptarg)) != EOF) {
355 rotation = (
enum Rotation)atoi(myoptarg);
364 if (myoptind >= argc) {
369 const char *verb = argv[myoptind];
371 if (!strcmp(verb,
"start")) {
375 if (!strcmp(verb,
"stop")) {
379 if (!strcmp(verb,
"info")) {
__EXPORT int ak09916_main(int argc, char *argv[])
Driver for the standalone AK09916 magnetometer.
static constexpr unsigned AK09916_CONVERSION_INTERVAL_us
void set_device_type(uint8_t devtype)
void set_error_count(uint64_t error_count)
static constexpr uint8_t AK09916_ST2_HOFL
uint8_t read_reg(uint8_t reg)
void usage()
Prints info about the driver argument usage.
count the number of times an event occurs
void write_reg(uint8_t reg, uint8_t value)
High-resolution timer with callouts and timekeeping.
void stop(bool external_bus)
#define AK09916_DEVICE_ID_A
void set_external(bool external)
AK09916(int bus, const char *path, enum Rotation rotation)
perf_counter_t _mag_reads
perf_counter_t _mag_overruns
void perf_count(perf_counter_t handle)
Count a performance event.
void perf_free(perf_counter_t handle)
Free a counter.
void init()
Activates/configures the hardware registers.
#define AK09916_CNTL2_CONTINOUS_MODE_100HZ
void update(hrt_abstime timestamp, int16_t x, int16_t y, int16_t z)
Rotation
Enum for board and external compass rotations.
perf_counter_t _mag_errors
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
void set_scale(float scale)
void start(bool, enum Rotation)
perf_counter_t _mag_overflows
virtual int init() override
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
static constexpr auto AK09916_DEVICE_PATH_MAG_EXT
#define DRV_MAG_DEVTYPE_AK09916
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
static constexpr float AK09916_MAG_RANGE_GA
Performance measuring tools.
static constexpr auto AK09916_DEVICE_PATH_MAG