drivers: sensor: bmi160: Define accessors for the bmi160
Add inline functions to obtain the data and configuration. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
c3823b9144
commit
a32f87b1e0
3 changed files with 27 additions and 18 deletions
|
@ -26,7 +26,7 @@ struct bmi160_data bmi160_data;
|
|||
static int bmi160_transceive(const struct device *dev, uint8_t reg,
|
||||
bool write, void *data, size_t length)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
const struct spi_buf buf[2] = {
|
||||
{
|
||||
.buf = ®,
|
||||
|
@ -208,7 +208,7 @@ static int bmi160_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli)
|
|||
static int bmi160_acc_odr_set(const struct device *dev, uint16_t freq_int,
|
||||
uint16_t freq_milli)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
int odr = bmi160_freq_to_odr_val(freq_int, freq_milli);
|
||||
|
||||
if (odr < 0) {
|
||||
|
@ -310,7 +310,7 @@ static int bmi160_do_calibration(const struct device *dev, uint8_t foc_conf)
|
|||
#if defined(CONFIG_BMI160_ACCEL_RANGE_RUNTIME)
|
||||
static int bmi160_acc_range_set(const struct device *dev, int32_t range)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
int32_t reg_val = bmi160_range_to_reg_val(range,
|
||||
bmi160_acc_range_map,
|
||||
BMI160_ACC_RANGE_MAP_SIZE);
|
||||
|
@ -373,7 +373,7 @@ static int bmi160_acc_calibrate(const struct device *dev,
|
|||
enum sensor_channel chan,
|
||||
const struct sensor_value *xyz_calib_value)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
uint8_t foc_pos[] = {
|
||||
BMI160_FOC_ACC_X_POS,
|
||||
BMI160_FOC_ACC_Y_POS,
|
||||
|
@ -477,7 +477,7 @@ static int bmi160_gyr_odr_set(const struct device *dev, uint16_t freq_int,
|
|||
#if defined(CONFIG_BMI160_GYRO_RANGE_RUNTIME)
|
||||
static int bmi160_gyr_range_set(const struct device *dev, uint16_t range)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
int32_t reg_val = bmi160_range_to_reg_val(range,
|
||||
bmi160_gyr_range_map,
|
||||
BMI160_GYR_RANGE_MAP_SIZE);
|
||||
|
@ -561,7 +561,7 @@ static int bmi160_gyr_ofs_set(const struct device *dev,
|
|||
static int bmi160_gyr_calibrate(const struct device *dev,
|
||||
enum sensor_channel chan)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
|
||||
ARG_UNUSED(chan);
|
||||
|
||||
|
@ -639,7 +639,7 @@ static int bmi160_attr_set(const struct device *dev, enum sensor_channel chan,
|
|||
static int bmi160_sample_fetch(const struct device *dev,
|
||||
enum sensor_channel chan)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
size_t i;
|
||||
|
||||
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
|
||||
|
@ -721,7 +721,7 @@ static inline void bmi160_gyr_channel_get(const struct device *dev,
|
|||
enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
|
||||
bmi160_channel_convert(chan, bmi160->scale.gyr,
|
||||
bmi160->sample.gyr, val);
|
||||
|
@ -733,7 +733,7 @@ static inline void bmi160_acc_channel_get(const struct device *dev,
|
|||
enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
|
||||
bmi160_channel_convert(chan, bmi160->scale.acc,
|
||||
bmi160->sample.acc, val);
|
||||
|
@ -745,7 +745,7 @@ static int bmi160_temp_channel_get(const struct device *dev,
|
|||
{
|
||||
uint16_t temp_raw = 0U;
|
||||
int32_t temp_micro = 0;
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
|
||||
if (bmi160->pmu_sts.raw == 0U) {
|
||||
return -EINVAL;
|
||||
|
@ -806,7 +806,7 @@ static const struct sensor_driver_api bmi160_api = {
|
|||
|
||||
int bmi160_init(const struct device *dev)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
uint8_t val = 0U;
|
||||
int32_t acc_range, gyr_range;
|
||||
|
||||
|
|
|
@ -485,6 +485,16 @@ struct bmi160_data {
|
|||
#endif /* CONFIG_BMI160_TRIGGER */
|
||||
};
|
||||
|
||||
static inline struct bmi160_data *to_data(const struct device *dev)
|
||||
{
|
||||
return dev->data;
|
||||
}
|
||||
|
||||
static inline const struct bmi160_cfg *to_config(const struct device *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
int bmi160_read(const struct device *dev, uint8_t reg_addr,
|
||||
uint8_t *data, uint8_t len);
|
||||
int bmi160_byte_read(const struct device *dev, uint8_t reg_addr,
|
||||
|
|
|
@ -16,7 +16,7 @@ LOG_MODULE_DECLARE(BMI160, CONFIG_SENSOR_LOG_LEVEL);
|
|||
|
||||
static void bmi160_handle_anymotion(const struct device *dev)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
struct sensor_trigger anym_trigger = {
|
||||
.type = SENSOR_TRIG_DELTA,
|
||||
.chan = SENSOR_CHAN_ACCEL_XYZ,
|
||||
|
@ -29,7 +29,7 @@ static void bmi160_handle_anymotion(const struct device *dev)
|
|||
|
||||
static void bmi160_handle_drdy(const struct device *dev, uint8_t status)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
struct sensor_trigger drdy_trigger = {
|
||||
.type = SENSOR_TRIG_DATA_READY,
|
||||
};
|
||||
|
@ -122,7 +122,7 @@ static int bmi160_trigger_drdy_set(const struct device *dev,
|
|||
enum sensor_channel chan,
|
||||
sensor_trigger_handler_t handler)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
uint8_t drdy_en = 0U;
|
||||
|
||||
#if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND)
|
||||
|
@ -157,7 +157,7 @@ static int bmi160_trigger_drdy_set(const struct device *dev,
|
|||
static int bmi160_trigger_anym_set(const struct device *dev,
|
||||
sensor_trigger_handler_t handler)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
uint8_t anym_en = 0U;
|
||||
|
||||
bmi160->handler_anymotion = handler;
|
||||
|
@ -266,9 +266,8 @@ int bmi160_trigger_set(const struct device *dev,
|
|||
|
||||
int bmi160_trigger_mode_init(const struct device *dev)
|
||||
{
|
||||
struct bmi160_data *bmi160 = dev->data;
|
||||
|
||||
const struct bmi160_cfg *cfg = dev->config;
|
||||
struct bmi160_data *bmi160 = to_data(dev);
|
||||
const struct bmi160_cfg *cfg = to_config(dev);
|
||||
|
||||
bmi160->gpio = device_get_binding((char *)cfg->gpio_port);
|
||||
if (!bmi160->gpio) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue