2016-06-08 20:59:31 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-06-08 20:59:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SENSOR_HMC5883L_H__
|
|
|
|
#define __SENSOR_HMC5883L_H__
|
|
|
|
|
|
|
|
#include <device.h>
|
|
|
|
#include <misc/util.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-06-08 20:59:31 +08:00
|
|
|
#include <gpio.h>
|
|
|
|
|
|
|
|
#define SYS_LOG_DOMAIN "HMC5883L"
|
2016-10-06 00:49:41 +08:00
|
|
|
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
2016-12-18 01:56:56 +08:00
|
|
|
#include <logging/sys_log.h>
|
2016-06-08 20:59:31 +08:00
|
|
|
|
|
|
|
#define HMC5883L_I2C_ADDR 0x1E
|
|
|
|
|
|
|
|
#define HMC5883L_REG_CONFIG_A 0x00
|
|
|
|
#define HMC5883L_ODR_SHIFT 2
|
|
|
|
|
|
|
|
#define HMC5883L_REG_CONFIG_B 0x01
|
|
|
|
#define HMC5883L_GAIN_SHIFT 5
|
|
|
|
|
|
|
|
#define HMC5883L_REG_MODE 0x02
|
|
|
|
#define HMC5883L_MODE_CONTINUOUS 0
|
|
|
|
|
|
|
|
#define HMC5883L_REG_DATA_START 0x03
|
|
|
|
|
|
|
|
#define HMC5883L_REG_CHIP_ID 0x0A
|
|
|
|
#define HMC5883L_CHIP_ID_A 'H'
|
|
|
|
#define HMC5883L_CHIP_ID_B '4'
|
|
|
|
#define HMC5883L_CHIP_ID_C '3'
|
|
|
|
|
|
|
|
static const char * const hmc5883l_odr_strings[] = {
|
|
|
|
"0.75", "1.5", "3", "7.5", "15", "30", "75"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const hmc5883l_fs_strings[] = {
|
|
|
|
"0.88", "1.3", "1.9", "2.5", "4", "4.7", "5.6", "8.1"
|
|
|
|
};
|
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
static const u16_t hmc5883l_gain[] = {
|
2016-06-08 20:59:31 +08:00
|
|
|
1370, 1090, 820, 660, 440, 390, 330, 230
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hmc5883l_data {
|
|
|
|
struct device *i2c;
|
2017-04-21 23:03:20 +08:00
|
|
|
s16_t x_sample;
|
|
|
|
s16_t y_sample;
|
|
|
|
s16_t z_sample;
|
|
|
|
u8_t gain_idx;
|
2016-06-08 20:59:31 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_HMC5883L_TRIGGER
|
|
|
|
struct device *gpio;
|
|
|
|
struct gpio_callback gpio_cb;
|
|
|
|
|
|
|
|
struct sensor_trigger data_ready_trigger;
|
|
|
|
sensor_trigger_handler_t data_ready_handler;
|
|
|
|
|
2016-11-10 23:05:53 +08:00
|
|
|
#if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD)
|
2017-06-03 05:08:45 +08:00
|
|
|
K_THREAD_STACK_MEMBER(thread_stack, CONFIG_HMC5883L_THREAD_STACK_SIZE);
|
2017-05-10 02:59:40 +08:00
|
|
|
struct k_thread thread;
|
2016-11-10 21:21:34 +08:00
|
|
|
struct k_sem gpio_sem;
|
2016-11-10 23:05:53 +08:00
|
|
|
#elif defined(CONFIG_HMC5883L_TRIGGER_GLOBAL_THREAD)
|
2016-11-10 21:21:34 +08:00
|
|
|
struct k_work work;
|
2016-06-08 20:59:31 +08:00
|
|
|
struct device *dev;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_HMC5883L_TRIGGER */
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_HMC5883L_TRIGGER
|
|
|
|
int hmc5883l_trigger_set(struct device *dev,
|
|
|
|
const struct sensor_trigger *trig,
|
|
|
|
sensor_trigger_handler_t handler);
|
|
|
|
|
|
|
|
int hmc5883l_init_interrupt(struct device *dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __SENSOR_HMC5883L__ */
|