diff --git a/adafruit_lps25hw.py b/adafruit_lps25hw.py new file mode 100644 index 0000000..d299461 --- /dev/null +++ b/adafruit_lps25hw.py @@ -0,0 +1,308 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Bryan Siepert for Adafruit Industries +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_lps35hw` +================================================================================ + +A driver for the ST LPS35HW water resistant MEMS pressure sensor + + +* Author(s): Bryan Siepert + +Implementation Notes +-------------------- + +**Hardware:** + +* `LPS35HW Breakout `_ + +**Software and Dependencies:** + * Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register + +""" + +# imports + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LPS35HW.git" +import time +from micropython import const +import adafruit_bus_device.i2c_device as i2cdevice +from adafruit_register.i2c_struct import UnaryStruct +from adafruit_register.i2c_bits import RWBits, ROBits +from adafruit_register.i2c_bit import RWBit +# pylint: disable=bad-whitespace +# _INTERRUPT_CFG = const(0x0B) +# _THS_P_L = const(0x0C) +# _THS_P_H = const(0x0D) +_WHO_AM_I = const(0x0F) +_CTRL_REG1 = const(0x20) +_CTRL_REG2 = const(0x21) +# _CTRL_REG3 = const(0x2) +# _FIFO_CTRL = const(0x14) +# _REF_P_XL = const(0x15) +# _REF_P_L = const(0x16) +# _REF_P_H = const(0x17) +# _RPDS_L = const(0x18) +# _RPDS_H = const(0x19) +# _RES_CONF = const(0x1A) +# _INT_SOURCE = const(0x25) +# _FIFO_STATUS = const(0x26) +# _STATUS = const(0x27) +_PRESS_OUT_XL = const(0x28) +# _PRESS_OUT_L = const(0x29) +# _PRESS_OUT_H = const(0x2A) +# _TEMP_OUT_L = const(0x2B) +# _TEMP_OUT_H = const(0x2C) +# _LPFP_RES = const(0x33) +# pylint: enable=bad-whitespace + +class DataRate: # pylint: disable=too-few-public-methods + """Options for ``data_rate`` + + +---------------------------+-------------------------+ + | ``DataRate`` | Time | + +===========================+=========================+ + | ``DataRate.ONE_SHOT`` | One shot mode | + +---------------------------+-------------------------+ + | ``DataRate.RATE_1_HZ`` | 1 hz | + +---------------------------+-------------------------+ + | ``DataRate.RATE_10_HZ`` | 10 hz (Default) | + +---------------------------+-------------------------+ + | ``DataRate.RATE_25_HZ`` | 25 hz | + +---------------------------+-------------------------+ + | ``DataRate.RATE_50_HZ`` | 50 hz | + +---------------------------+-------------------------+ + | ``DataRate.RATE_75_HZ`` | 75 hz | + +---------------------------+-------------------------+ + + """ + ONE_SHOT = const(0x00) + RATE_1_HZ = const(0x01) + RATE_10_HZ = const(0x02) + RATE_25_HZ = const(0x03) + RATE_50_HZ = const(0x04) + RATE_75_HZ = const(0x05) + +class LPS25HW: # pylint: disable=too-many-instance-attributes + """Driver for the ST LPS35HW MEMS pressure sensor + + :param ~busio.I2C i2c_bus: The I2C bus the LPS34HW is connected to. + :param address: The I2C device address for the sensor. Default is ``0x5d`` but will accept + ``0x5c`` when the ``SDO`` pin is connected to Ground. + + """ + _chip_id = UnaryStruct(_WHO_AM_I, "