-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from adafruit/LPS22
LPS22 support (and some LPS25 changes)
- Loading branch information
Showing
8 changed files
with
345 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <Adafruit_LPS2X.h> | ||
|
||
/*! @brief Initializer for post i2c/spi init | ||
* @param sensor_id Optional unique ID for the sensor set | ||
* @returns True if chip identified and initialized | ||
*/ | ||
bool Adafruit_LPS22::_init(int32_t sensor_id) { | ||
|
||
Adafruit_BusIO_Register chip_id = Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS2X_WHOAMI, 1); | ||
|
||
// make sure we're talking to the right chip | ||
uint8_t id = chip_id.read(); | ||
|
||
if (id != LPS22HB_CHIP_ID) { | ||
return false; | ||
} | ||
_sensorid_pressure = sensor_id; | ||
_sensorid_temp = sensor_id + 1; | ||
|
||
temp_scaling = 100; | ||
|
||
ctrl1_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS22_CTRL_REG1, 1); | ||
ctrl2_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS22_CTRL_REG2, 1); | ||
ctrl3_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS22_CTRL_REG3, 1); | ||
threshp_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS22_THS_P_L_REG, 1); | ||
|
||
reset(); | ||
// do any software reset or other initial setup | ||
setDataRate(LPS22_RATE_25_HZ); | ||
// interrupt on data ready | ||
configureInterrupt(true, false, true); | ||
|
||
pressure_sensor = new Adafruit_LPS2X_Pressure(this); | ||
temp_sensor = new Adafruit_LPS2X_Temp(this); | ||
|
||
delay(10); // delay for first reading | ||
return true; | ||
} | ||
|
||
/** | ||
* @brief Sets the rate at which pressure and temperature measurements | ||
* | ||
* @param new_data_rate The data rate to set. Must be a `lps22_rate_t` | ||
*/ | ||
void Adafruit_LPS22::setDataRate(lps22_rate_t new_data_rate) { | ||
Adafruit_BusIO_RegisterBits data_rate = | ||
Adafruit_BusIO_RegisterBits(ctrl1_reg, 3, 4); | ||
|
||
data_rate.write((uint8_t)new_data_rate); | ||
} | ||
|
||
/** | ||
* @brief Gets the current rate at which pressure and temperature measurements | ||
* are taken | ||
* | ||
* @return lps22_rate_t The current data rate | ||
*/ | ||
lps22_rate_t Adafruit_LPS22::getDataRate(void) { | ||
Adafruit_BusIO_RegisterBits data_rate = | ||
Adafruit_BusIO_RegisterBits(ctrl1_reg, 3, 4); | ||
|
||
return (lps22_rate_t)data_rate.read(); | ||
} | ||
|
||
/** | ||
* @brief Configures the INT pin | ||
* @param activelow Pass true to make the INT pin drop low on interrupt | ||
* @param opendrain Pass true to make the INT pin an open drain output | ||
* @param data_ready If true, interrupt fires on new data ready | ||
* @param pres_high If true, interrupt fires on high threshold pass | ||
* @param pres_low If true, interrupt fires on low threshold pass | ||
* @param fifo_full If true, interrupt fires on fifo full | ||
* @param fifo_watermark If true, interrupt fires on fifo watermark pass | ||
* @param fifo_overflow If true, interrupt fires on fifo overflow | ||
*/ | ||
void Adafruit_LPS22::configureInterrupt(bool activelow, bool opendrain, | ||
bool data_ready, bool pres_high, | ||
bool pres_low, bool fifo_full, | ||
bool fifo_watermark, | ||
bool fifo_overflow) { | ||
uint8_t reg = (activelow << 7) | (opendrain << 6) | (fifo_full << 5) | | ||
(fifo_watermark << 4) | (fifo_overflow << 3) | | ||
(data_ready << 2); | ||
ctrl3_reg->write(reg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <Adafruit_LPS2X.h> | ||
|
||
/*! @brief Initializer for post i2c/spi init | ||
* @param sensor_id Optional unique ID for the sensor set | ||
* @returns True if chip identified and initialized | ||
*/ | ||
bool Adafruit_LPS25::_init(int32_t sensor_id) { | ||
|
||
Adafruit_BusIO_Register chip_id = Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS2X_WHOAMI, 1); | ||
|
||
// make sure we're talking to the right chip | ||
uint8_t id = chip_id.read(); | ||
|
||
if (id != LPS25HB_CHIP_ID) { | ||
return false; | ||
} | ||
_sensorid_pressure = sensor_id; | ||
_sensorid_temp = sensor_id + 1; | ||
|
||
temp_scaling = 480; | ||
inc_spi_flag = 0x40; | ||
|
||
ctrl1_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS25_CTRL_REG1, 1); | ||
ctrl2_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS25_CTRL_REG2, 1); | ||
ctrl3_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS25_CTRL_REG3, 1); | ||
threshp_reg = new Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS25_THS_P_L_REG, 1); | ||
|
||
reset(); | ||
// do any software reset or other initial setup | ||
powerDown(false); | ||
setDataRate(LPS25_RATE_25_HZ); | ||
|
||
pressure_sensor = new Adafruit_LPS2X_Pressure(this); | ||
temp_sensor = new Adafruit_LPS2X_Temp(this); | ||
delay(10); // delay for first reading | ||
return true; | ||
} | ||
|
||
/** | ||
* @brief Sets the rate at which pressure and temperature measurements | ||
* | ||
* @param new_data_rate The data rate to set. Must be a `lps25_rate_t` | ||
*/ | ||
void Adafruit_LPS25::setDataRate(lps25_rate_t new_data_rate) { | ||
Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS25_CTRL_REG1, 1); | ||
Adafruit_BusIO_RegisterBits data_rate = | ||
Adafruit_BusIO_RegisterBits(&ctrl1, 3, 4); | ||
|
||
data_rate.write((uint8_t)new_data_rate); | ||
} | ||
|
||
/** | ||
* @brief Gets the current rate at which pressure and temperature measurements | ||
* are taken | ||
* | ||
* @return lps25_rate_t The current data rate | ||
*/ | ||
lps25_rate_t Adafruit_LPS25::getDataRate(void) { | ||
Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( | ||
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LPS25_CTRL_REG1, 1); | ||
Adafruit_BusIO_RegisterBits data_rate = | ||
Adafruit_BusIO_RegisterBits(&ctrl1, 3, 4); | ||
|
||
return (lps25_rate_t)data_rate.read(); | ||
} | ||
|
||
/** | ||
* @brief Puts the sensor into power down mode, shutting the sensor down | ||
* | ||
* @param power_down | ||
*/ | ||
void Adafruit_LPS25::powerDown(bool power_down) { | ||
Adafruit_BusIO_RegisterBits pd = Adafruit_BusIO_RegisterBits(ctrl1_reg, 1, 7); | ||
pd.write(!power_down); // pd bit->0 == power down | ||
} | ||
|
||
/** | ||
* @brief Configures the INT pin, by default it will output DRDY signal | ||
* @param activelow Pass true to make the INT pin drop low on interrupt | ||
* @param opendrain Pass true to make the INT pin an open drain output | ||
* @param pres_high If true, interrupt fires on high threshold pass | ||
* @param pres_low If true, interrupt fires on low threshold pass | ||
*/ | ||
void Adafruit_LPS25::configureInterrupt(bool activelow, bool opendrain, | ||
bool pres_high, bool pres_low) { | ||
uint8_t reg = | ||
(activelow << 7) | (opendrain << 6) | (pres_low << 1) | pres_high; | ||
ctrl3_reg->write(reg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.