You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/03/12 18:41:37 UTC

[GitHub] vrahane closed pull request #881: Lps33hw

vrahane closed pull request #881: Lps33hw
URL: https://github.com/apache/mynewt-core/pull/881
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h b/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
new file mode 100644
index 000000000..8c92e723b
--- /dev/null
+++ b/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __SENSOR_LPS33HW_H__
+#define __SENSOR_LPS33HW_H__
+
+#include "os/os.h"
+#include "os/os_dev.h"
+#include "sensor/sensor.h"
+#include "hal/hal_gpio.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LPS33HW_I2C_ADDR (0x5C)
+
+#define LPS33HW_INT_LEVEL (0x80)
+#define LPS33HW_INT_OPEN (0x40)
+#define LPS33HW_INT_LATCH_EN (0x20)
+#define LPS33HW_INT_RD_CLEAR (0x10)
+
+enum lps33hw_output_data_rates {
+    LPS33HW_ONE_SHOT            = 0x00,
+    LPS33HW_1HZ                 = 0x01,
+    LPS33HW_10HZ                = 0x02,
+    LPS33HW_25HZ                = 0x03,
+    LPS33HW_50HZ                = 0x04,
+    LPS33HW_75HZ                = 0x05
+};
+
+enum lps33hw_low_pass_config {
+    LPS33HW_LPF_DISABLED        = 0x00, /* Bandwidth = data rate / 2 */
+    LPS33HW_LPF_ENABLED_LOW_BW  = 0x02, /* Bandwidth = data rate / 9 */
+    LPS33HW_LPF_ENABLED_HIGH_BW = 0x03  /* Bandwidth = data rate / 20 */
+};
+
+struct lps33hw_int_cfg {
+    uint8_t pin;
+    unsigned int data_rdy : 1;
+    unsigned int pressure_low : 1;
+    unsigned int pressure_high : 1;
+    unsigned int active_low : 1;
+    unsigned int open_drain : 1;
+    unsigned int latched : 1;
+};
+
+struct lps33hw_cfg {
+    sensor_type_t mask;
+    struct lps33hw_int_cfg int_cfg;
+    enum lps33hw_output_data_rates data_rate;
+    enum lps33hw_low_pass_config lpf;
+    unsigned int autozero : 1;
+    unsigned int autorifp : 1;
+};
+
+struct lps33hw_private_driver_data {
+    sensor_data_func_t user_handler;
+    void *user_arg;
+};
+
+struct lps33hw {
+    struct os_dev dev;
+    struct sensor sensor;
+    struct lps33hw_cfg cfg;
+    os_time_t last_read_time;
+    struct lps33hw_private_driver_data pdd;
+};
+
+/**
+ * Set the output data rate.
+ *
+ * @param The interface object associated with the lps33hw.
+ * @param Data rate value.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_set_data_rate(struct sensor_itf *itf,
+    enum lps33hw_output_data_rates rate);
+
+/**
+ * Configure the Low Pass Filter.
+ *
+ * @param The interface object associated with the lps33hw.
+ * @param Low pass filter config value
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_set_lpf(struct sensor_itf *itf,
+    enum lps33hw_low_pass_config lpf);
+
+/**
+ * Software reset.
+ *
+ * @param The interface object associated with the lps33hw.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_reset(struct sensor_itf *itf);
+
+/*
+ * Get pressure.
+ *
+ * @param The interface object associated with the lps33hw.
+ * @param Pressure.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_get_pressure(struct sensor_itf *itf, float *pressure);
+
+/*
+ * Get temperature.
+ *
+ * @param The interface object associated with the lps33hw.
+ * @param Temperature.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_get_temperature(struct sensor_itf *itf, float *temperature);
+
+/*
+ * Set pressure reference.
+ *
+ * @param The interface object associated with the lps33hw.
+ * @param The pressure reference.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_set_reference(struct sensor_itf *itf, float reference);
+
+/*
+ * Set pressure threshold.
+ *
+ * @param The interface object associated with the lps33hw.
+ * @param The pressure reference.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_set_threshold(struct sensor_itf *itf, float threshold);
+
+/*
+ * Set pressure RPDS.
+ *
+ * @param The interface object associated with the lps33hw.
+ * @param The pressure offset, unsure of units.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_set_rpds(struct sensor_itf *itf, uint16_t rpds);
+
+/**
+ * Initialise gpio interrupt and setup handler. Call lp33hw_config_interrupt
+ * first
+ *
+ * @param The sensor object associated with this lps33hw.
+ * @param Handler, called back in the ISR.
+ * @param Argument to be passed to the handler.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_enable_interrupt(struct sensor *sensor,
+    hal_gpio_irq_handler_t handler, void * arg);
+
+/**
+ * Disable gpio interrupt.
+ *
+ * @param The sensor object associated with this lps33hw.
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+void lps33hw_disable_interrupt(struct sensor *sensor);
+
+/**
+ * Configure interrupt.
+ *
+ * @param The device object associated with this lps33hw.
+ * @param Interrupt config struct
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_config_interrupt(struct sensor *sensor, struct lps33hw_int_cfg cfg);
+
+/**
+ * Expects to be called back through os_dev_create().
+ *
+ * @param The device object associated with this pressure sensor
+ * @param Argument passed to OS device init, unused
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int lps33hw_init(struct os_dev *, void *);
+int lps33hw_config(struct lps33hw *, struct lps33hw_cfg *);
+
+#if MYNEWT_VAL(LPS33HW_CLI)
+int lps33hw_shell_init(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_LPS33HW_H__ */
diff --git a/hw/drivers/sensors/lps33hw/pkg.yml b/hw/drivers/sensors/lps33hw/pkg.yml
new file mode 100644
index 000000000..a9aad3b42
--- /dev/null
+++ b/hw/drivers/sensors/lps33hw/pkg.yml
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: hw/drivers/sensors/lps33hw
+pkg.description: Driver for the lps33hw and lps22hb pressure sensors.
+pkg.author: "Apache Mynewt dev@mynewt.apache.org"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - lps33hw
+    - lps22hb
+    - pressure
+    - i2c
+    - sensor
+    - st
+
+pkg.deps:
+    - "@apache-mynewt-core/hw/hal"
+    - "@apache-mynewt-core/kernel/os"
+    - "@apache-mynewt-core/hw/sensor"
+
+pkg.req_apis:
+    - stats
+    - log
+
+pkg.deps.LPS33HW_CLI:
+    - "@apache-mynewt-core/util/parse"
diff --git a/hw/drivers/sensors/lps33hw/src/lps33hw.c b/hw/drivers/sensors/lps33hw/src/lps33hw.c
new file mode 100644
index 000000000..dffaf16e9
--- /dev/null
+++ b/hw/drivers/sensors/lps33hw/src/lps33hw.c
@@ -0,0 +1,874 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * resarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include <math.h>
+
+#include "defs/error.h"
+#include "os/os.h"
+#include "sysinit/sysinit.h"
+#include "hal/hal_i2c.h"
+#include "sensor/sensor.h"
+#include "sensor/pressure.h"
+#include "sensor/temperature.h"
+#include "lps33hw/lps33hw.h"
+#include "lps33hw_priv.h"
+#include "log/log.h"
+#include "stats/stats.h"
+
+#include "lps33hw_priv.h"
+
+/* Define the stats section and records */
+STATS_SECT_START(lps33hw_stat_section)
+    STATS_SECT_ENTRY(read_errors)
+    STATS_SECT_ENTRY(write_errors)
+STATS_SECT_END
+
+/* Define stat names for querying */
+STATS_NAME_START(lps33hw_stat_section)
+    STATS_NAME(lps33hw_stat_section, read_errors)
+    STATS_NAME(lps33hw_stat_section, write_errors)
+STATS_NAME_END(lps33hw_stat_section)
+
+/* Global variable used to hold stats data */
+STATS_SECT_DECL(lps33hw_stat_section) g_lps33hwstats;
+
+#define LOG_MODULE_LPS33HW    (33)
+#define LPS33HW_INFO(...)     LOG_INFO(&_log, LOG_MODULE_LPS33HW, __VA_ARGS__)
+#define LPS33HW_ERR(...)      LOG_ERROR(&_log, LOG_MODULE_LPS33HW, __VA_ARGS__)
+static struct log _log;
+
+#define LPS33HW_PRESS_OUT_DIV (4096.0)
+#define LPS33HW_TEMP_OUT_DIV (100.0)
+#define LPS33HW_PRESS_THRESH_DIV (16)
+
+/* Exports for the sensor API */
+static int lps33hw_sensor_read(struct sensor *, sensor_type_t,
+        sensor_data_func_t, void *, uint32_t);
+static int lps33hw_sensor_get_config(struct sensor *, sensor_type_t,
+        struct sensor_cfg *);
+static int lps33hw_sensor_set_trigger_thresh(struct sensor *sensor,
+        sensor_type_t sensor_type, struct sensor_type_traits *stt);
+static int lps33hw_sensor_handle_interrupt(struct sensor *sensor);
+static int lps33hw_sensor_clear_low_thresh(struct sensor *sensor,
+        sensor_type_t type);
+static int lps33hw_sensor_clear_high_thresh(struct sensor *sensor,
+        sensor_type_t type);
+
+static const struct sensor_driver g_lps33hw_sensor_driver = {
+    .sd_read                      = lps33hw_sensor_read,
+    .sd_get_config                = lps33hw_sensor_get_config,
+    .sd_set_trigger_thresh        = lps33hw_sensor_set_trigger_thresh,
+    .sd_handle_interrupt          = lps33hw_sensor_handle_interrupt,
+    .sd_clear_low_trigger_thresh  = lps33hw_sensor_clear_low_thresh,
+    .sd_clear_high_trigger_thresh = lps33hw_sensor_clear_high_thresh
+};
+
+/*
+ * Converts pressure value in hectopascals to a value found in the pressure
+ * threshold register of the device.
+ *
+ * @param Pressure value in hectopascals.
+ *
+ * @return Pressure value to write to the threshold registers.
+ */
+static uint16_t
+lps33hw_hpa_to_threshold_reg(float hpa)
+{
+    /* Threshold is unsigned. */
+    if (hpa < 0) {
+        return 0;
+    } else if (hpa == INFINITY) {
+        return 0xffff;
+    }
+    return hpa * LPS33HW_PRESS_THRESH_DIV;
+}
+
+/*
+ * Converts pressure value in hectopascals to a value found in the pressure
+ * reference register of the device.
+ *
+ * @param Pressure value in hectopascals.
+ *
+ * @return Pressure value to write to the reference registers.
+ */
+static int32_t
+lps33hw_hpa_to_reg(float hpa)
+{
+    if (hpa == INFINITY) {
+        return 0x007fffff;
+    }
+    return (int32_t)(hpa * LPS33HW_PRESS_OUT_DIV);
+}
+
+/*
+ * Converts pressure read from the device output registers to a value in
+ * hectopascals.
+ *
+ * @param Pressure value read from the output registers.
+ *
+ * @return Pressure value in hectopascals.
+ */
+static float
+lps33hw_reg_to_hpa(int32_t reg)
+{
+    return reg / LPS33HW_PRESS_OUT_DIV;
+}
+
+/*
+ * Converts temperature read from the device output registers to a value in
+ * degrees C.
+ *
+ * @param Temperature value read from the output registers.
+ *
+ * @return Temperature value in degrees C.
+ */
+static float
+lps33hw_reg_to_degc(int16_t reg)
+{
+    return reg / LPS33HW_TEMP_OUT_DIV;
+}
+
+
+/**
+ * Writes a single byte to the specified register
+ *
+ * @param The sensor interface
+ * @param The register address to write to
+ * @param The value to write
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+static int
+lps33hw_set_reg(struct sensor_itf *itf, uint8_t reg, uint8_t value)
+{
+    int rc;
+    uint8_t payload[2] = { reg, value };
+
+    struct hal_i2c_master_data data_struct = {
+        .address = itf->si_addr,
+        .len = 2,
+        .buffer = payload
+    };
+
+    rc = hal_i2c_master_write(itf->si_num, &data_struct,
+                              OS_TICKS_PER_SEC / 10, 1);
+
+    if (rc) {
+        LPS33HW_ERR("Failed to write to 0x%02X:0x%02X with value 0x%02X\n",
+                       itf->si_addr, reg, value);
+        STATS_INC(g_lps33hwstats, read_errors);
+    }
+
+    return rc;
+}
+
+/**
+ * Read bytes from the specified register
+ *
+ * @param The sensor interface
+ * @param The register address to read from
+ * @param Pointer to where the register value should be written
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+static int
+lps33hw_get_regs(struct sensor_itf *itf, uint8_t reg, uint8_t size,
+    uint8_t *buffer)
+{
+    int rc;
+
+    struct hal_i2c_master_data data_struct = {
+        .address = itf->si_addr,
+        .len = 1,
+        .buffer = &reg
+    };
+
+    /* Register write */
+    rc = hal_i2c_master_write(itf->si_num, &data_struct,
+                              OS_TICKS_PER_SEC / 10, 1);
+    if (rc) {
+        LPS33HW_ERR("I2C access failed at address 0x%02X\n", itf->si_addr);
+        STATS_INC(g_lps33hwstats, write_errors);
+        return rc;
+    }
+
+    /* Read */
+    data_struct.len = size;
+    data_struct.buffer = buffer;
+    rc = hal_i2c_master_read(itf->si_num, &data_struct,
+                             (OS_TICKS_PER_SEC / 10) * size, 1);
+
+    if (rc) {
+         LPS33HW_ERR("Failed to read from 0x%02X:0x%02X\n", itf->si_addr, reg);
+         STATS_INC(g_lps33hwstats, read_errors);
+    }
+    return rc;
+}
+
+static int
+lps33hw_apply_value(struct lps33hw_register_value addr, uint8_t value,
+    uint8_t *reg)
+{
+    value <<= addr.pos;
+
+    if ((value & (~addr.mask)) != 0) {
+        return -1;
+    }
+
+    *reg &= ~addr.mask;
+    *reg |= value;
+
+    return 0;
+}
+
+int
+lps33hw_set_value(struct sensor_itf *itf, struct lps33hw_register_value addr,
+    uint8_t value)
+{
+    int rc;
+    uint8_t reg;
+
+    rc = lps33hw_get_regs(itf, addr.reg, 1, &reg);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = lps33hw_apply_value(addr, value, &reg);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return lps33hw_set_reg(itf, addr.reg, reg);
+}
+
+int
+lps33hw_get_value(struct sensor_itf *itf, struct lps33hw_register_value addr,
+    uint8_t *value)
+{
+    int rc;
+    uint8_t reg;
+
+    rc = lps33hw_get_regs(itf, addr.reg, 1, &reg);
+
+    *value = (reg & addr.mask) >> addr.pos;
+
+    return rc;
+}
+
+int
+lps33hw_set_data_rate(struct sensor_itf *itf,
+    enum lps33hw_output_data_rates rate)
+{
+    return lps33hw_set_value(itf, LPS33HW_CTRL_REG1_ODR, rate);
+}
+
+int
+lps33hw_set_lpf(struct sensor_itf *itf, enum lps33hw_low_pass_config lpf)
+{
+    return lps33hw_set_value(itf, LPS33HW_CTRL_REG1_LPFP_CFG, lpf);
+}
+
+int
+lps33hw_reset(struct sensor_itf *itf)
+{
+    return lps33hw_set_reg(itf, LPS33HW_CTRL_REG2, 0x04);
+}
+
+int
+lps33hw_get_pressure_regs(struct sensor_itf *itf, uint8_t reg, float *pressure)
+{
+    int rc;
+    uint8_t payload[3];
+    int32_t int_press;
+
+    rc = lps33hw_get_regs(itf, reg, 3, payload);
+    if (rc) {
+        return rc;
+    }
+
+    int_press = (((int32_t)payload[2] << 16) |
+        ((int32_t)payload[1] << 8) | payload[0]);
+
+    if (int_press & 0x00800000) {
+        int_press |= 0xff000000;
+    }
+
+    *pressure = lps33hw_reg_to_hpa(int_press);
+
+    return 0;
+}
+
+int
+lps33hw_get_pressure(struct sensor_itf *itf, float *pressure) {
+    return lps33hw_get_pressure_regs(itf, LPS33HW_PRESS_OUT, pressure);
+}
+
+int
+lps33hw_get_temperature(struct sensor_itf *itf, float *temperature)
+{
+    int rc;
+    uint8_t payload[2];
+    uint16_t int_temp;
+
+    rc = lps33hw_get_regs(itf, LPS33HW_TEMP_OUT, 2, payload);
+    if (rc) {
+        return rc;
+    }
+
+    int_temp = (((uint32_t)payload[1] << 8) | payload[0]);
+
+    *temperature = lps33hw_reg_to_degc(int_temp);
+
+    return 0;
+}
+
+int
+lps33hw_set_reference(struct sensor_itf *itf, float reference)
+{
+    int rc;
+    int32_t int_reference;
+
+    int_reference = lps33hw_hpa_to_reg(reference);
+
+    rc = lps33hw_set_reg(itf, LPS33HW_REF_P, int_reference & 0xff);
+    if (rc) {
+        return rc;
+    }
+    rc = lps33hw_set_reg(itf, LPS33HW_REF_P + 1, (int_reference >> 8) & 0xff);
+    if (rc) {
+        return rc;
+    }
+
+    return lps33hw_set_reg(itf, LPS33HW_REF_P + 2, (int_reference >> 16) &
+        0xff);
+}
+
+int
+lps33hw_set_threshold(struct sensor_itf *itf, float threshold)
+{
+    int rc;
+    int16_t int_threshold;
+
+    int_threshold = lps33hw_hpa_to_threshold_reg(threshold);
+
+    rc = lps33hw_set_reg(itf, LPS33HW_THS_P, int_threshold & 0xff);
+    if (rc) {
+        return rc;
+    }
+
+    return lps33hw_set_reg(itf, LPS33HW_THS_P + 1, (int_threshold >> 8) & 0xff);
+}
+
+int
+lps33hw_set_rpds(struct sensor_itf *itf, uint16_t rpds)
+{
+    int rc;
+
+    rc = lps33hw_set_reg(itf, LPS33HW_RPDS, rpds & 0xff);
+    if (rc) {
+        return rc;
+    }
+
+    return lps33hw_set_reg(itf, LPS33HW_RPDS + 1, (rpds >> 8) & 0xff);
+}
+
+int
+lps33hw_enable_interrupt(struct sensor *sensor, hal_gpio_irq_handler_t handler,
+            void *arg)
+{
+    int rc;
+    struct lps33hw *lps33hw;
+    struct sensor_itf *itf;
+    hal_gpio_irq_trig_t trig;
+    hal_gpio_pull_t pull;
+    struct lps33hw_int_cfg *int_cfg;
+    float press;
+    uint8_t int_source;
+
+    lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+    itf = SENSOR_GET_ITF(sensor);
+    int_cfg = &lps33hw->cfg.int_cfg;
+    trig = (int_cfg->active_low) ? HAL_GPIO_TRIG_FALLING : HAL_GPIO_TRIG_RISING;
+    pull = (int_cfg->open_drain) ? HAL_GPIO_PULL_UP : HAL_GPIO_PULL_NONE;
+
+    rc = hal_gpio_irq_init(int_cfg->pin, handler, arg, trig, pull);
+    if (rc) {
+        return rc;
+    }
+
+    hal_gpio_irq_enable(int_cfg->pin);
+
+    /* Read pressure and interrupt sources in order to reset the interrupt */
+    rc = lps33hw_get_pressure_regs(itf, LPS33HW_PRESS_OUT, &press);
+    if (rc) {
+        return rc;
+    }
+    (void)press;
+
+    rc = lps33hw_get_regs(itf, LPS33HW_INT_SOURCE, 1, &int_source);
+    if (rc) {
+        return rc;
+    }
+    (void)int_source;
+
+    return 0;
+}
+
+void
+lps33hw_disable_interrupt(struct sensor *sensor)
+{
+    struct lps33hw *lps33hw;
+    struct lps33hw_int_cfg *int_cfg;
+
+    lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+    int_cfg = &lps33hw->cfg.int_cfg;
+
+    hal_gpio_irq_release(int_cfg->pin);
+}
+
+/**
+ * Handles and interrupt
+ *
+ * @param Pointer to sensor structure
+ *
+ * @return 0 on success, non-zero on failure
+ */
+static int
+lps33hw_sensor_handle_interrupt(struct sensor *sensor)
+{
+    LPS33HW_ERR("Unhandled interrupt\n");
+    return 0;
+}
+
+/**
+ * Clears the low threshold interrupt
+ *
+ * @param Pointer to sensor structure
+ * @param Sensor type
+ *
+ * @return 0 on success, non-zero on failure
+ */
+static int
+lps33hw_sensor_clear_low_thresh(struct sensor *sensor, sensor_type_t type)
+{
+    struct lps33hw *lps33hw;
+    struct sensor_itf *itf;
+    struct lps33hw_int_cfg *int_cfg;
+
+    lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+    itf = SENSOR_GET_ITF(sensor);
+    int_cfg = &lps33hw->cfg.int_cfg;
+
+    if (type != SENSOR_TYPE_PRESSURE) {
+        return SYS_EINVAL;
+    }
+
+    int_cfg->pressure_low = 0;
+
+    return lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_PLE, 0);
+}
+
+/**
+ * Clears the high threshold interrupt
+ *
+ * @param Pointer to sensor structure
+ * @param Sensor type
+ *
+ * @return 0 on success, non-zero on failure
+ */
+static int
+lps33hw_sensor_clear_high_thresh(struct sensor *sensor, sensor_type_t type)
+{
+    struct lps33hw *lps33hw;
+    struct sensor_itf *itf;
+    struct lps33hw_int_cfg *int_cfg;
+
+    lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+    itf = SENSOR_GET_ITF(sensor);
+    int_cfg = &lps33hw->cfg.int_cfg;
+
+    if (type != SENSOR_TYPE_PRESSURE) {
+        return SYS_EINVAL;
+    }
+
+    int_cfg->pressure_high = 0;
+
+    return lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_PHE, 0);
+}
+
+static void
+lps33hw_threshold_interrupt_handler(void * arg)
+{
+    struct sensor_type_traits *stt = arg;
+    sensor_mgr_put_read_evt(stt);
+}
+
+int
+lps33hw_config_interrupt(struct sensor *sensor, struct lps33hw_int_cfg cfg)
+{
+    int rc;
+    struct lps33hw *lps33hw;
+    struct sensor_itf *itf;
+
+    lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+    itf = SENSOR_GET_ITF(sensor);
+
+    lps33hw->cfg.int_cfg = cfg;
+
+    if (cfg.data_rdy) {
+        rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_PLE, 0);
+        if (rc) {
+            return rc;
+        }
+        rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_PHE, 0);
+        if (rc) {
+            return rc;
+        }
+        rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_DIFF_EN, 0);
+        if (rc) {
+            return rc;
+        }
+        rc = lps33hw_set_value(itf, LPS33HW_CTRL_REG3_INT_S, 0);
+        if (rc) {
+            return rc;
+        }
+    } else if (cfg.pressure_low || cfg.pressure_high){
+        rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_PLE,
+            cfg.pressure_low);
+        if (rc) {
+            return rc;
+        }
+        rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_PHE,
+            cfg.pressure_high);
+        if (rc) {
+            return rc;
+        }
+        rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_DIFF_EN, 1);
+        if (rc) {
+            return rc;
+        }
+        rc = lps33hw_set_value(itf, LPS33HW_CTRL_REG3_INT_S, cfg.pressure_high |
+            (cfg.pressure_low << 1));
+        if (rc) {
+            return rc;
+        }
+    } else {
+        rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_DIFF_EN, 0);
+        if (rc) {
+            return rc;
+        }
+    }
+    rc = lps33hw_set_value(itf, LPS33HW_CTRL_REG3_DRDY, cfg.data_rdy);
+    if (rc) {
+        return rc;
+    }
+    rc = lps33hw_set_value(itf, LPS33HW_CTRL_REG3_INT_H_L, cfg.active_low);
+    if (rc) {
+        return rc;
+    }
+    rc = lps33hw_set_value(itf, LPS33HW_CTRL_REG3_PP_OD, cfg.open_drain);
+    if (rc) {
+        return rc;
+    }
+    rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_LIR, cfg.latched);
+    if (rc) {
+        return rc;
+    }
+
+    return rc;
+}
+
+/**
+ * Sets up trigger thresholds and enables interrupts
+ *
+ * @param Pointer to sensor structure
+ * @param type of sensor
+ * @param threshold settings to configure
+ *
+ * @return 0 on success, non-zero on failure
+ */
+static int
+lps33hw_sensor_set_trigger_thresh(struct sensor *sensor,
+                                  sensor_type_t sensor_type,
+                                  struct sensor_type_traits *stt)
+{
+    struct lps33hw *lps33hw;
+    struct sensor_itf *itf;
+    int rc;
+    struct sensor_press_data *low_thresh;
+    struct sensor_press_data *high_thresh;
+    struct lps33hw_int_cfg int_cfg;
+    float reference;
+    float threshold;
+
+    if (sensor_type != SENSOR_TYPE_PRESSURE) {
+        return SYS_EINVAL;
+    }
+
+    lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+    itf = SENSOR_GET_ITF(sensor);
+
+    low_thresh  = stt->stt_low_thresh.spd;
+    high_thresh = stt->stt_high_thresh.spd;
+    int_cfg = lps33hw->cfg.int_cfg;
+
+    /* turn off existing dready interrupt */
+    int_cfg.data_rdy = 0;
+    int_cfg.pressure_low = low_thresh->spd_press_is_valid;
+    int_cfg.pressure_high = high_thresh->spd_press_is_valid;
+
+    threshold = 0;
+    reference = 0;
+
+    /*
+     * Device only has one threshold which can be set to trigger on positive or
+     * negative thresholds, set it to the lower threshold.
+     */
+
+    if (int_cfg.pressure_low) {
+        if (int_cfg.pressure_high) {
+            threshold = (high_thresh->spd_press - low_thresh->spd_press) / 2;
+            reference = low_thresh->spd_press + threshold;
+        } else {
+            reference = low_thresh->spd_press;
+        }
+    } else if (int_cfg.pressure_high) {
+        reference = high_thresh->spd_press;
+    }
+
+    rc = lps33hw_set_reference(itf, reference);
+    if (rc) {
+        return rc;
+    }
+
+    rc = lps33hw_set_threshold(itf, threshold);
+    if (rc) {
+        return rc;
+    }
+
+    rc = lps33hw_config_interrupt(sensor, int_cfg);
+    if (rc) {
+        return rc;
+    }
+
+    rc = lps33hw_enable_interrupt(sensor, lps33hw_threshold_interrupt_handler,
+        stt);
+    if (rc) {
+        return rc;
+    }
+
+    return 0;
+}
+
+int
+lps33hw_init(struct os_dev *dev, void *arg)
+{
+    struct lps33hw *lps;
+    struct sensor *sensor;
+    int rc;
+
+    if (!arg || !dev) {
+        return SYS_ENODEV;
+    }
+
+    lps = (struct lps33hw *) dev;
+
+    sensor = &lps->sensor;
+    lps->cfg.mask = SENSOR_TYPE_ALL;
+
+    log_register(dev->od_name, &_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+
+    /* Initialise the stats entry */
+    rc = stats_init(
+        STATS_HDR(g_lps33hwstats),
+        STATS_SIZE_INIT_PARMS(g_lps33hwstats, STATS_SIZE_32),
+        STATS_NAME_INIT_PARMS(lps33hw_stat_section));
+    SYSINIT_PANIC_ASSERT(rc == 0);
+    /* Register the entry with the stats registry */
+    rc = stats_register(dev->od_name, STATS_HDR(g_lps33hwstats));
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = sensor_init(sensor, dev);
+    if (rc) {
+        return rc;
+    }
+
+    /* Add the pressure and temperature driver */
+    rc = sensor_set_driver(sensor, SENSOR_TYPE_PRESSURE |
+        SENSOR_TYPE_TEMPERATURE,
+        (struct sensor_driver *) &g_lps33hw_sensor_driver);
+    if (rc) {
+        return rc;
+    }
+
+    rc = sensor_set_interface(sensor, arg);
+    if (rc) {
+        return rc;
+    }
+
+    return sensor_mgr_register(sensor);
+}
+
+int
+lps33hw_config(struct lps33hw *lps, struct lps33hw_cfg *cfg)
+{
+    int rc;
+    struct sensor_itf *itf;
+
+    itf = SENSOR_GET_ITF(&(lps->sensor));
+
+    uint8_t val;
+    rc = lps33hw_get_regs(itf, LPS33HW_WHO_AM_I, 1, &val);
+    if (rc) {
+        return rc;
+    }
+    if (val != LPS33HW_WHO_AM_I_VAL) {
+        return SYS_EINVAL;
+    }
+
+    rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_AUTORIFP, cfg->autorifp);
+    if (rc) {
+        return rc;
+    }
+
+    rc = lps33hw_set_value(itf, LPS33HW_INTERRUPT_CFG_AUTOZERO, cfg->autozero);
+    if (rc) {
+        return rc;
+    }
+
+    rc = lps33hw_set_data_rate(itf, cfg->data_rate);
+    if (rc) {
+        return rc;
+    }
+
+    rc = lps33hw_set_lpf(itf, cfg->lpf);
+    if (rc) {
+        return rc;
+    }
+
+    rc = lps33hw_config_interrupt(&(lps->sensor), cfg->int_cfg);
+    if (rc) {
+
+    }
+
+    rc = sensor_set_type_mask(&(lps->sensor), cfg->mask);
+    if (rc) {
+        return rc;
+    }
+
+    lps->cfg.mask = cfg->mask;
+
+    return 0;
+}
+
+static void
+lps33hw_read_interrupt_handler(void *arg)
+{
+    int rc;
+    struct sensor *sensor;
+    struct lps33hw *lps33hw;
+    struct sensor_itf *itf;
+    struct sensor_press_data spd;
+
+    sensor = (struct sensor *)arg;
+    lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+    itf = SENSOR_GET_ITF(sensor);
+
+    rc = lps33hw_get_pressure(itf, &spd.spd_press);
+    if (rc) {
+        LPS33HW_ERR("Get pressure failed\n");
+        spd.spd_press_is_valid = 0;
+    } else {
+        spd.spd_press_is_valid = 1;
+        lps33hw->pdd.user_handler(sensor, lps33hw->pdd.user_arg,
+            &spd, SENSOR_TYPE_PRESSURE);
+    }
+}
+
+static int
+lps33hw_sensor_read(struct sensor *sensor, sensor_type_t type,
+        sensor_data_func_t data_func, void *data_arg, uint32_t timeout)
+{
+    (void)timeout;
+    int rc;
+    struct sensor_itf *itf;
+
+    itf = SENSOR_GET_ITF(sensor);
+    if (type & SENSOR_TYPE_PRESSURE) {
+        struct lps33hw *lps33hw;
+
+        lps33hw = (struct lps33hw *)SENSOR_GET_DEVICE(sensor);
+        if (lps33hw->cfg.int_cfg.data_rdy) {
+            /* Stream read */
+            lps33hw->pdd.user_handler = data_func;
+            lps33hw->pdd.user_arg = data_arg;
+
+            rc = lps33hw_enable_interrupt(sensor,
+                lps33hw_read_interrupt_handler, sensor);
+            if (rc) {
+                return rc;
+            }
+        } else {
+            /* Read once */
+            struct sensor_press_data spd;
+
+            rc = lps33hw_get_pressure(itf, &spd.spd_press);
+            if (rc) {
+                return rc;
+            }
+
+            spd.spd_press_is_valid = 1;
+
+            rc = data_func(sensor, data_arg, &spd, SENSOR_TYPE_PRESSURE);
+        }
+    } else if (type & SENSOR_TYPE_TEMPERATURE) {
+        struct sensor_temp_data std;
+
+        rc = lps33hw_get_temperature(itf, &std.std_temp);
+        if (rc) {
+            return rc;
+        }
+
+        std.std_temp_is_valid = 1;
+
+        rc = data_func(sensor, data_arg, &std,
+                SENSOR_TYPE_TEMPERATURE);
+    } else {
+         return SYS_EINVAL;
+    }
+
+    return rc;
+}
+
+static int
+lps33hw_sensor_get_config(struct sensor *sensor, sensor_type_t type,
+        struct sensor_cfg *cfg)
+{
+    /* If the read isn't looking for pressure, don't do anything. */
+    if (!(type & (SENSOR_TYPE_PRESSURE | SENSOR_TYPE_TEMPERATURE))) {
+        return SYS_EINVAL;
+    }
+
+    cfg->sc_valtype = SENSOR_VALUE_TYPE_FLOAT;
+
+    return 0;
+}
diff --git a/hw/drivers/sensors/lps33hw/src/lps33hw_priv.h b/hw/drivers/sensors/lps33hw/src/lps33hw_priv.h
new file mode 100644
index 000000000..0bfb32714
--- /dev/null
+++ b/hw/drivers/sensors/lps33hw/src/lps33hw_priv.h
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __LPS33HW_PRIV_H__
+#define __LPS33HW_PRIV_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum lps33hw_registers {
+    LPS33HW_INTERRUPT_CFG = 0x0b,
+    LPS33HW_THS_P = 0x0c,
+    LPS33HW_WHO_AM_I = 0x0f,
+    LPS33HW_CTRL_REG1 = 0x10,
+    LPS33HW_CTRL_REG2 = 0x11,
+    LPS33HW_CTRL_REG3 = 0x12,
+    LPS33HW_FIFO_CTRL = 0x14,
+    LPS33HW_REF_P = 0x15,
+    LPS33HW_RPDS = 0x18,
+    LPS33HW_RES_CONF = 0x1a,
+    LPS33HW_INT_SOURCE = 0x25,
+    LPS33HW_FIFO_STATUS = 0x26,
+    LPS33HW_STATUS = 0x27,
+    LPS33HW_PRESS_OUT = 0x28,
+    LPS33HW_TEMP_OUT = 0x2b,
+    LPS33HW_LPFP_RES = 0x33
+};
+
+/* registers */
+struct lps33hw_register_value {
+    uint8_t reg;
+    uint8_t pos;
+    uint8_t mask;
+};
+
+#define LPS33HW_INT_LOW_BIT (0x01)
+#define LPS33HW_INT_HIGH_BIT (0x01)
+
+#define LPS33HW_REGISTER_VALUE(r, n, p, m) \
+static const struct lps33hw_register_value n = {.reg = r, .pos = p, .mask = m}
+
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_AUTORIFP, 7, 0x80);
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_RESET_ARP, 6, 0x40);
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_AUTOZERO, 5, 0x20);
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_RESET_AZ, 4, 0x10);
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_DIFF_EN, 3, 0x08);
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_LIR, 2, 0x04);
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_PLE, 1, 0x02);
+LPS33HW_REGISTER_VALUE(LPS33HW_INTERRUPT_CFG, LPS33HW_INTERRUPT_CFG_PHE, 0, 0x01);
+
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG1, LPS33HW_CTRL_REG1_ODR, 4, 0x70);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG1, LPS33HW_CTRL_REG1_EN_LPFP, 3, 0x04);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG1, LPS33HW_CTRL_REG1_LPFP_CFG, 2, 0x03);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG1, LPS33HW_CTRL_REG1_BDU, 1, 0x02);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG1, LPS33HW_CTRL_REG1_SIM, 0, 0x01);
+
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG2, LPS33HW_CTRL_REG2_BOOT, 7, 0x80);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG2, LPS33HW_CTRL_REG2_FIFO_EN, 6, 0x40);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG2, LPS33HW_CTRL_REG2_STOP_ON_FTH, 5, 0x20);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG2, LPS33HW_CTRL_REG2_IF_ADD_INC, 4, 0x10);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG2, LPS33HW_CTRL_REG2_I2C_DIS, 3, 0x08);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG2, LPS33HW_CTRL_REG2_SWRESET, 2, 0x04);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG2, LPS33HW_CTRL_REG2_ONE_SHOT, 0, 0x01);
+
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG3, LPS33HW_CTRL_REG3_INT_H_L, 7, 0x80);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG3, LPS33HW_CTRL_REG3_PP_OD, 6, 0x40);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG3, LPS33HW_CTRL_REG3_F_FSS5, 5, 0x20);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG3, LPS33HW_CTRL_REG3_F_FTH, 4, 0x10);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG3, LPS33HW_CTRL_REG3_F_OVR, 3, 0x08);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG3, LPS33HW_CTRL_REG3_DRDY, 2, 0x04);
+LPS33HW_REGISTER_VALUE(LPS33HW_CTRL_REG3, LPS33HW_CTRL_REG3_INT_S, 0, 0x03);
+
+LPS33HW_REGISTER_VALUE(LPS33HW_RES_CONF, LPS33HW_CTRL_RES_CONF_LC_EN, 0, 0x01);
+
+LPS33HW_REGISTER_VALUE(LPS33HW_INT_SOURCE, LPS33HW_INT_SOURCE_BOOT_STATUS, 7, 0x80);
+LPS33HW_REGISTER_VALUE(LPS33HW_INT_SOURCE, LPS33HW_INT_SOURCE_IA, 2, 0x04);
+LPS33HW_REGISTER_VALUE(LPS33HW_INT_SOURCE, LPS33HW_INT_SOURCE_PL, 1, 0x02);
+LPS33HW_REGISTER_VALUE(LPS33HW_INT_SOURCE, LPS33HW_INT_SOURCE_PH, 0, 0x01);
+
+LPS33HW_REGISTER_VALUE(LPS33HW_STATUS, LPS33HW_STATUS_T_OR, 5, 0x20);
+LPS33HW_REGISTER_VALUE(LPS33HW_STATUS, LPS33HW_STATUS_P_OR, 5, 0x10);
+LPS33HW_REGISTER_VALUE(LPS33HW_STATUS, LPS33HW_STATUS_T_DA, 5, 0x02);
+LPS33HW_REGISTER_VALUE(LPS33HW_STATUS, LPS33HW_STATUS_P_DA, 5, 0x01);
+
+#define LPS33HW_WHO_AM_I_VAL (0xb1)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LPS33HW_PRIV_H__ */
diff --git a/hw/drivers/sensors/lps33hw/src/lps33hw_shell.c b/hw/drivers/sensors/lps33hw/src/lps33hw_shell.c
new file mode 100644
index 000000000..514e1d8be
--- /dev/null
+++ b/hw/drivers/sensors/lps33hw/src/lps33hw_shell.c
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include <errno.h>
+#include "sysinit/sysinit.h"
+#include "console/console.h"
+#include "hal/hal_gpio.h"
+#include "lps33hw/lps33hw.h"
+#include "lps33hw_priv.h"
+
+#if MYNEWT_VAL(LPS33HW_CLI)
+
+#include "shell/shell.h"
+#include "parse/parse.h"
+
+static int lps33hw_shell_cmd(int argc, char **argv);
+
+static struct shell_cmd lps33hw_shell_cmd_struct = {
+    .sc_cmd = "lps33hw",
+    .sc_cmd_func = lps33hw_shell_cmd
+};
+
+static struct sensor_itf g_sensor_itf = {
+    .si_type = MYNEWT_VAL(LPS33HW_SHELL_ITF_TYPE),
+    .si_num = MYNEWT_VAL(LPS33HW_SHELL_ITF_NUM),
+    .si_addr = MYNEWT_VAL(LPS33HW_SHELL_ITF_ADDR)
+};
+
+static int
+lps33hw_shell_err_too_many_args(char *cmd_name)
+{
+    console_printf("Error: too many arguments for command \"%s\"\n",
+                   cmd_name);
+    return EINVAL;
+}
+
+static int
+lps33hw_shell_err_unknown_arg(char *cmd_name)
+{
+    console_printf("Error: unknown argument \"%s\"\n",
+                   cmd_name);
+    return EINVAL;
+}
+
+static int
+lps33hw_shell_cmd_read_press(int argc, char **argv)
+{
+    int rc;
+    float press;
+    char tmpstr[13];
+
+    if (argc > 2) {
+        return lps33hw_shell_err_too_many_args(argv[1]);
+    }
+
+    rc = lps33hw_get_pressure(&g_sensor_itf, &press);
+    if (rc) {
+        console_printf("Read falied: %d\r\n", rc);
+        return rc;
+    }
+
+    console_printf("Pressure: %s\r\n", sensor_ftostr(press, tmpstr, 13));
+    return 0;
+}
+
+static int
+lps33hw_shell_cmd_read_temp(int argc, char **argv)
+{
+    int rc;
+    float temp;
+    char tmpstr[13];
+
+    if (argc > 2) {
+        return lps33hw_shell_err_too_many_args(argv[1]);
+    }
+
+    rc = lps33hw_get_temperature(&g_sensor_itf, &temp);
+    if (rc) {
+        console_printf("Read falied: %d\r\n", rc);
+        return rc;
+    }
+
+    console_printf("Temperature: %s\r\n", sensor_ftostr(temp, tmpstr, 13));
+    return 0;
+}
+
+static int
+lps33hw_shell_help(void)
+{
+    console_printf("%s cmd [flags...]\n", lps33hw_shell_cmd_struct.sc_cmd);
+    console_printf("cmd:\n");
+    console_printf("\trp\n");
+    console_printf("\trt\n");
+
+    return 0;
+}
+
+static int
+lps33hw_shell_cmd(int argc, char **argv)
+{
+    if (argc == 1) {
+        return lps33hw_shell_help();
+    }
+
+    /* Read pressure */
+    if (argc > 1 && strcmp(argv[1], "rp") == 0) {
+        return lps33hw_shell_cmd_read_press(argc, argv);
+    }
+
+    /* Read temperature */
+    if (argc > 1 && strcmp(argv[1], "rt") == 0) {
+        return lps33hw_shell_cmd_read_temp(argc, argv);
+    }
+
+    return lps33hw_shell_err_unknown_arg(argv[1]);
+}
+
+int
+lps33hw_shell_init(void)
+{
+    int rc;
+    rc = shell_cmd_register(&lps33hw_shell_cmd_struct);
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    return rc;
+}
+
+#endif
diff --git a/hw/drivers/sensors/lps33hw/syscfg.yml b/hw/drivers/sensors/lps33hw/syscfg.yml
new file mode 100644
index 000000000..f88de36c9
--- /dev/null
+++ b/hw/drivers/sensors/lps33hw/syscfg.yml
@@ -0,0 +1,34 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    LPS33HW_SHELL_ITF_NUM:
+        description: 'Shell interface number for the LPS33HW'
+        value: 0
+    LPS33HW_SHELL_ITF_TYPE:
+        description: 'Shell interface type for the LPS33HW'
+        value: 1
+    LPS33HW_SHELL_CSPIN:
+        description: 'CS pin for LPS33HW'
+        value : -1
+    LPS33HW_SHELL_ITF_ADDR:
+        description: 'Slave address for LPS33HW'
+        value : 0x5C
+    LPS33HW_CLI:
+        description: 'Enable shell support for the LPS33HW'
+        value: 0
diff --git a/hw/sensor/creator/src/sensor_creator.c b/hw/sensor/creator/src/sensor_creator.c
index 06f3921a1..d81befae6 100644
--- a/hw/sensor/creator/src/sensor_creator.c
+++ b/hw/sensor/creator/src/sensor_creator.c
@@ -58,10 +58,15 @@
 #include <bma253/bma253.h>
 #endif
 
+
 #if MYNEWT_VAL(ADXL345_OFB)
 #include <adxl345/adxl345.h>
 #endif
 
+#if MYNEWT_VAL(LPS33HW_OFB)
+#include <lps33hw/lps33hw.h>
+#endif
+
 /* Driver definitions */
 #if MYNEWT_VAL(DRV2605_OFB)
 static struct drv2605 drv2605;
@@ -107,6 +112,10 @@ static struct bma253 bma253;
 static struct adxl345 adxl345;
 #endif
 
+#if MYNEWT_VAL(LPS33HW_OFB)
+static struct lps33hw lps33hw;
+#endif
+
 /**
  * If a UART sensor needs to be created, interface is defined in
  * the following way
@@ -228,6 +237,14 @@ static struct sensor_itf i2c_0_itf_adxl = {
 };
 #endif
 
+#if MYNEWT_VAL(I2C_0) && MYNEWT_VAL(LPS33HW_OFB)
+static struct sensor_itf i2c_0_itf_lps = {
+    .si_type = MYNEWT_VAL(LPS33HW_SHELL_ITF_TYPE),
+    .si_num  = MYNEWT_VAL(LPS33HW_SHELL_ITF_NUM),
+    .si_addr = MYNEWT_VAL(LPS33HW_SHELL_ITF_ADDR)
+};
+#endif
+
 /**
  * MS5837 Sensor default configuration used by the creator package
  *
@@ -602,13 +619,43 @@ config_adxl345_sensor(void)
     cfg.tap_cfg.suppress = 0;
 
     cfg.freefall_threshold = 0x07; /* 440mg */
-    cfg.freefall_time = 0x14; /* 100ms */ 
+    cfg.freefall_time = 0x14; /* 100ms */
 
     cfg.mask = SENSOR_TYPE_ACCELEROMETER;
 
     rc = adxl345_config((struct adxl345 *) dev, &cfg);
     assert(rc == 0);
-    
+#endif
+
+/*
+ * LPS33HW Sensor default configuration used by the creator package
+ *
+ * @return 0 on success, non-zero on failure
+ */
+#if MYNEWT_VAL(LPS33HW_OFB)
+static int
+config_lps33hw_sensor(void)
+{
+    int rc;
+    struct os_dev *dev;
+    struct lps33hw_cfg cfg;
+
+    cfg.mask = SENSOR_TYPE_PRESSURE | SENSOR_TYPE_TEMPERATURE;
+    cfg.data_rate = LPS33HW_1HZ;
+    cfg.lpf = LPS33HW_LPF_DISABLED;
+    cfg.int_cfg.pin = 0;
+    cfg.int_cfg.data_rdy = 0;
+    cfg.int_cfg.pressure_low = 0;
+    cfg.int_cfg.pressure_high = 0;
+    cfg.int_cfg.active_low = 0;
+    cfg.int_cfg.open_drain = 0;
+    cfg.int_cfg.latched = 0;
+
+    dev = (struct os_dev *) os_dev_open("lps33hw_0", OS_TIMEOUT_NEVER, NULL);
+    assert(dev != NULL);
+
+    rc = lps33hw_config((struct lps33hw *) dev, &cfg);
+
     os_dev_close(dev);
     return rc;
 }
@@ -729,5 +776,13 @@ sensor_dev_create(void)
     assert(rc == 0);
 #endif
 
+#if MYNEWT_VAL(LPS33HW_OFB)
+    rc = os_dev_create((struct os_dev *) &lps33hw, "lps33hw_0",
+      OS_DEV_INIT_PRIMARY, 0, lps33hw_init, (void *)&i2c_0_itf_lps);
+    assert(rc == 0);
+
+    rc = config_lps33hw_sensor();
+    assert(rc == 0);
+#endif
 
 }
diff --git a/hw/sensor/creator/syscfg.yml b/hw/sensor/creator/syscfg.yml
index e0b1da7dc..ab9d90f68 100644
--- a/hw/sensor/creator/syscfg.yml
+++ b/hw/sensor/creator/syscfg.yml
@@ -52,3 +52,6 @@ syscfg.defs:
     ADXL345_OFB:
         description: 'ADXL345 is present'
         value : 0
+    LPS33HW_OFB:
+        description: 'LPS33HW is present'
+        value : 0


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services