5656_PRESS_OUT_XL = const (0x28 | 0x80 ) # | 0x80 to set auto increment on multi-byte read
5757_TEMP_OUT_L = const (0x2B | 0x80 ) # | 0x80 to set auto increment on multi-byte read
5858
59- _LPS25_CHIP_ID = 0xBD
60- _LPS25_DEFAULT_ADDRESS = 0x5D
59+ _LPS25HB_CHIP_ID = 0xBD
60+ _LPS2X_DEFAULT_ADDRESS = 0x5D
6161
62- # define LPS2X_I2CADDR_DEFAULT 0x5D ///< LPS2X default i2c address
63- # define LPS2X_WHOAMI 0x0F ///< Chip ID register
62+ # _LPS2X_I2CADDR_DEFAULT = 0x5D # LPS2X default i2c address
63+ # _LPS2X_WHOAMI = 0x0F # Chip ID register
6464
65- # define LPS22HB_CHIP_ID 0xB1 ///< LPS22 default device id from WHOAMI
66- # define LPS22_THS_P_L_REG 0x0C ///< Pressure threshold value for int
67- # define LPS22_CTRL_REG1 0x10 ///< First control register. Includes BD & ODR
68- # define LPS22_CTRL_REG2 0x11 ///< Second control register. Includes SW Reset
69- # define LPS22_CTRL_REG3 0x12 ///< Third control register. Includes interrupt polarity
65+ _LPS22HB_CHIP_ID = 0xB1 # LPS22 default device id from WHOAMI
66+ # _LPS22_THS_P_L_REG = 0x0C # Pressure threshold value for int
67+ # _LPS22_CTRL_REG1 = 0x10 # First control register. Includes BD & ODR
68+ # _LPS22_CTRL_REG2 = 0x11 # Second control register. Includes SW Reset
69+ # _LPS22_CTRL_REG3 = 0x12 # Third control register. Includes interrupt polarity
7070
71- # define LPS25HB_CHIP_ID 0xBD ///< LPS25HB default device id from WHOAMI
72- # define LPS25_CTRL_REG1 0x20 ///< First control register. Includes BD & ODR
73- # define LPS25_CTRL_REG2 0x21 ///< Second control register. Includes SW Reset
74- # define LPS25_CTRL_REG3 0x22 ///< Third control register. Includes interrupt polarity
75- # define LPS25_CTRL_REG4 0x23 ///< Fourth control register. Includes DRDY INT control
76- # define LPS25_INTERRUPT_CFG 0x24 ///< Interrupt control register
77- # define LPS25_THS_P_L_REG 0xB0 ///< Pressure threshold value for int
71+ # _LPS25HB_CHIP_ID = 0xBD # LPS25HB default device id from WHOAMI
72+ # _LPS25_CTRL_REG1 = 0x20 # First control register. Includes BD & ODR
73+ # _LPS25_CTRL_REG2 = 0x21 # Second control register. Includes SW Reset
74+ # _LPS25_CTRL_REG3 = 0x22 # Third control register. Includes interrupt polarity
75+ # _LPS25_CTRL_REG4 = 0x23 # Fourth control register. Includes DRDY INT control
76+ # _LPS25_INTERRUPT_CFG = 0x24 # Interrupt control register
77+ # _LPS25_THS_P_L_REG = 0xB0 # Pressure threshold value for int
7878
79- # define LPS2X_PRESS_OUT_XL(0x28 | 0x80) ///< | 0x80 to set auto increment on multi-byte read
80- # define LPS2X_TEMP_OUT_L (0x2B | 0x80) ///< | 0x80 to set auto increment on
79+ # _LPS2X_PRESS_OUT_XL =(# | 0x80) ///< | 0x80 to set auto increment on multi-byte read
80+ # _LPS2X_TEMP_OUT_L = (0x2B # 0x80) ///< | 0x80 to set auto increment on
8181
8282
8383class CV :
@@ -162,9 +162,9 @@ class LPS2X: # pylint: disable=too-many-instance-attributes
162162 _raw_temperature = ROUnaryStruct (_TEMP_OUT_L , "<h" )
163163 _raw_pressure = ROBits (24 , _PRESS_OUT_XL , 0 , 3 )
164164
165- def __init__ (self , i2c_bus , address = _LPS25_DEFAULT_ADDRESS ):
165+ def __init__ (self , i2c_bus , address = _LPS2X_DEFAULT_ADDRESS , chip_id = None ):
166166 self .i2c_device = i2cdevice .I2CDevice (i2c_bus , address )
167- if not self ._chip_id in [_LPS25_CHIP_ID ]:
167+ if not self ._chip_id in [chip_id ]:
168168 raise RuntimeError (
169169 "Failed to find LPS2X! Found chip ID 0x%x" % self ._chip_id
170170 )
@@ -217,21 +217,6 @@ def data_rate(self, value):
217217 self ._data_rate = value
218218
219219
220- # /**
221- # * @brief
222- # *
223- # * Allowed values for `setDataRate`.
224- # */
225- # typedef enum {
226- # LPS22_RATE_ONE_SHOT,
227- # LPS22_RATE_1_HZ,
228- # LPS22_RATE_10_HZ,
229- # LPS22_RATE_25_HZ,
230- # LPS22_RATE_50_HZ,
231- # LPS22_RATE_75_HZ,
232- # } lps22_rate_t;
233-
234-
235220class LPS25 (LPS2X ):
236221 """Library for the ST LPS25 pressure sensors
237222
@@ -244,7 +229,7 @@ class LPS25(LPS2X):
244229 enabled = RWBit (_CTRL_REG1 , 7 )
245230 """Controls the power down state of the sensor. Setting to `False` will shut the sensor down"""
246231
247- def __init__ (self , i2c_bus , address = _LPS25_DEFAULT_ADDRESS ):
232+ def __init__ (self , i2c_bus , address = _LPS2X_DEFAULT_ADDRESS ):
248233
249234 Rate .add_values (
250235 (
@@ -257,7 +242,7 @@ def __init__(self, i2c_bus, address=_LPS25_DEFAULT_ADDRESS):
257242 )
258243 )
259244
260- super ().__init__ (i2c_bus , address )
245+ super ().__init__ (i2c_bus , address , chip_id = _LPS25HB_CHIP_ID )
261246 self .initialize ()
262247
263248 def initialize (self ):
@@ -266,6 +251,53 @@ def initialize(self):
266251 self .data_rate = Rate .LPS25_RATE_25_HZ # pylint:disable=no-member
267252
268253
254+ class LPS22 (LPS2X ):
255+ """Library for the ST LPS22 pressure sensors
256+
257+ :param ~busio.I2C i2c_bus: The I2C bus the LPS22HB is connected to.
258+ :param address: The I2C device address for the sensor. Default is ``0x5d`` but will accept
259+ ``0x5c`` when the ``SDO`` pin is connected to Ground.
260+
261+ """
262+
263+ enabled = RWBit (_CTRL_REG1 , 7 )
264+ """Controls the power down state of the sensor. Setting to `False` will shut the sensor down"""
265+
266+ def __init__ (
267+ self , i2c_bus , address = _LPS2X_DEFAULT_ADDRESS , chip_id = _LPS22HB_CHIP_ID
268+ ):
269+
270+ Rate .add_values (
271+ (
272+ # leave these for backwards compatibility? nah
273+ ("LPS22_RATE_ONE_SHOT" , 0 , 0 , None ),
274+ ("LPS22_RATE_1_HZ" , 1 , 1 , None ),
275+ ("LPS22_RATE_10_HZ" , 2 , 10 , None ),
276+ ("LPS22_RATE_25_HZ" , 3 , 25 , None ),
277+ ("LPS22_RATE_50_HZ" , 4 , 50 , None ),
278+ ("LPS22_RATE_75_HZ" , 5 , 75 , None ),
279+ )
280+ )
281+
282+ # /**
283+ # * @brief
284+ # *
285+ # * Allowed values for `setDataRate`.
286+ # */
287+ # typedef enum {
288+ # LPS22_RATE_ONE_SHOT,
289+
290+ # } lps22_rate_t;
291+
292+ super ().__init__ (i2c_bus , address )
293+ self .initialize ()
294+
295+ def initialize (self ):
296+ """Configure the sensor with the default settings. For use after calling `reset()`"""
297+ self .enabled = True
298+ self .data_rate = Rate .LPS22_RATE_75_HZ # pylint:disable=no-member
299+
300+
269301# """
270302# class Adafruit_LPS2X {
271303# public:
0 commit comments