2016-05-24 12:09:22 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-05-24 12:09:22 +03:00
|
|
|
*/
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#ifndef ZEPHYR_DRIVERS_SENSOR_HTS221_HTS221_H_
|
|
|
|
#define ZEPHYR_DRIVERS_SENSOR_HTS221_HTS221_H_
|
2016-05-24 12:09:22 +03:00
|
|
|
|
|
|
|
#include <device.h>
|
2019-06-26 10:33:55 -04:00
|
|
|
#include <sys/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 10:32:08 -05:00
|
|
|
#include <zephyr/types.h>
|
2019-06-25 15:53:52 -04:00
|
|
|
#include <drivers/gpio.h>
|
2016-05-24 12:09:22 +03:00
|
|
|
|
|
|
|
#define HTS221_AUTOINCREMENT_ADDR BIT(7)
|
|
|
|
|
|
|
|
#define HTS221_REG_WHO_AM_I 0x0F
|
|
|
|
#define HTS221_CHIP_ID 0xBC
|
|
|
|
|
|
|
|
#define HTS221_REG_CTRL1 0x20
|
|
|
|
#define HTS221_PD_BIT BIT(7)
|
2018-11-24 14:08:52 -06:00
|
|
|
#define HTS221_BDU_BIT BIT(2)
|
2016-05-24 12:09:22 +03:00
|
|
|
#define HTS221_ODR_SHIFT 0
|
|
|
|
|
|
|
|
#define HTS221_REG_CTRL3 0x22
|
|
|
|
#define HTS221_DRDY_EN BIT(2)
|
|
|
|
|
|
|
|
#define HTS221_REG_DATA_START 0x28
|
|
|
|
#define HTS221_REG_CONVERSION_START 0x30
|
|
|
|
|
|
|
|
struct hts221_data {
|
|
|
|
struct device *i2c;
|
2020-05-27 11:26:57 -05:00
|
|
|
int16_t rh_sample;
|
|
|
|
int16_t t_sample;
|
|
|
|
|
|
|
|
uint8_t h0_rh_x2;
|
|
|
|
uint8_t h1_rh_x2;
|
|
|
|
uint16_t t0_degc_x8;
|
|
|
|
uint16_t t1_degc_x8;
|
|
|
|
int16_t h0_t0_out;
|
|
|
|
int16_t h1_t0_out;
|
|
|
|
int16_t t0_out;
|
|
|
|
int16_t t1_out;
|
2016-05-24 12:09:22 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_HTS221_TRIGGER
|
2019-12-20 16:30:23 -06:00
|
|
|
struct device *dev;
|
|
|
|
struct device *drdy_dev;
|
|
|
|
struct gpio_callback drdy_cb;
|
2016-05-24 12:09:22 +03:00
|
|
|
|
|
|
|
struct sensor_trigger data_ready_trigger;
|
|
|
|
sensor_trigger_handler_t data_ready_handler;
|
|
|
|
|
2016-11-10 10:05:53 -05:00
|
|
|
#if defined(CONFIG_HTS221_TRIGGER_OWN_THREAD)
|
2017-06-02 14:08:45 -07:00
|
|
|
K_THREAD_STACK_MEMBER(thread_stack, CONFIG_HTS221_THREAD_STACK_SIZE);
|
2017-05-09 11:59:40 -07:00
|
|
|
struct k_thread thread;
|
2019-12-20 16:30:23 -06:00
|
|
|
struct k_sem drdy_sem;
|
2016-11-10 10:05:53 -05:00
|
|
|
#elif defined(CONFIG_HTS221_TRIGGER_GLOBAL_THREAD)
|
2016-11-10 08:21:34 -05:00
|
|
|
struct k_work work;
|
2016-05-24 12:09:22 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_HTS221_TRIGGER */
|
|
|
|
};
|
|
|
|
|
2019-12-20 16:30:23 -06:00
|
|
|
struct hts221_config {
|
|
|
|
const char *i2c_bus;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t i2c_addr;
|
2019-12-20 16:30:23 -06:00
|
|
|
#ifdef CONFIG_HTS221_TRIGGER
|
|
|
|
gpio_pin_t drdy_pin;
|
|
|
|
gpio_flags_t drdy_flags;
|
|
|
|
const char *drdy_controller;
|
|
|
|
#endif /* CONFIG_HTS221_TRIGGER */
|
|
|
|
};
|
|
|
|
|
2016-05-24 12:09:22 +03:00
|
|
|
#ifdef CONFIG_HTS221_TRIGGER
|
|
|
|
int hts221_trigger_set(struct device *dev,
|
|
|
|
const struct sensor_trigger *trig,
|
|
|
|
sensor_trigger_handler_t handler);
|
|
|
|
|
|
|
|
int hts221_init_interrupt(struct device *dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __SENSOR_HTS221__ */
|