Improved HTS221 driver and related demo: added multiple register read/write.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9812 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
31f02dd767
commit
b1eb97df61
|
@ -60,8 +60,8 @@
|
|||
* @param[in] i2cp pointer to the I2C interface
|
||||
* @param[in] reg first sub-register address
|
||||
* @param[out] rxbuf pointer to an output buffer
|
||||
* @return the operation status.
|
||||
* @param[in] n number of consecutive register to read
|
||||
* @return the operation status.
|
||||
* @notapi
|
||||
*/
|
||||
msg_t hts221I2CReadRegister(I2CDriver *i2cp, uint8_t reg, uint8_t* rxbuf,
|
||||
|
@ -108,7 +108,7 @@ msg_t hts221Calibrate(HTS221Driver *devp, uint8_t flag) {
|
|||
msg_t msg;
|
||||
uint8_t calib[16], H0_rH_x2, H1_rH_x2, msb;
|
||||
int16_t H0_T0_OUT, H1_T0_OUT, T0_degC_x8, T1_degC_x8, T0_OUT, T1_OUT;
|
||||
float sens;
|
||||
float sens;
|
||||
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cAcquireBus(devp->config->i2cp);
|
||||
|
@ -116,7 +116,7 @@ msg_t hts221Calibrate(HTS221Driver *devp, uint8_t flag) {
|
|||
#endif /* HTS221_SHARED_I2C */
|
||||
|
||||
/* Retrieving rH values from Calibration registers */
|
||||
msg = hts221I2CReadRegister(devp->config->i2cp,
|
||||
msg = hts221I2CReadRegister(devp->config->i2cp,
|
||||
HTS221_AD_CALIB_0, calib, 16);
|
||||
|
||||
#if HTS221_SHARED_I2C
|
||||
|
@ -138,7 +138,7 @@ msg_t hts221Calibrate(HTS221Driver *devp, uint8_t flag) {
|
|||
}
|
||||
T0_degC_x8 += msb << 8;
|
||||
|
||||
T1_degC_x8 = calib[3];
|
||||
T1_degC_x8 = calib[3];
|
||||
/* Completing T1_degC_x8 value */
|
||||
msb = ((calib[5] & HTS221_SEL(0x03, 2)) >> 2);
|
||||
if(msb & HTS221_SEL(0x01, 1)) {
|
||||
|
@ -195,12 +195,12 @@ static size_t sens_get_axes_number(void *ip) {
|
|||
return (thermo_get_axes_number(ip) + hygro_get_axes_number(ip));
|
||||
}
|
||||
|
||||
static msg_t hygro_read_raw(void *ip, int32_t axis[]) {
|
||||
static msg_t hygro_read_raw(void *ip, int32_t* axis) {
|
||||
int16_t tmp;
|
||||
uint8_t buff[2];
|
||||
msg_t msg = MSG_OK;
|
||||
|
||||
*axis = 0.0f;
|
||||
*axis = 0;
|
||||
|
||||
osalDbgCheck((ip != NULL) && (axis != NULL));
|
||||
osalDbgAssert((((HTS221Driver *)ip)->state == HTS221_READY),
|
||||
|
@ -232,10 +232,10 @@ static msg_t hygro_read_raw(void *ip, int32_t axis[]) {
|
|||
|
||||
static msg_t thermo_read_raw(void *ip, int32_t axis[]) {
|
||||
int16_t tmp;
|
||||
uint8_t buff[2];
|
||||
uint8_t buff[2];
|
||||
msg_t msg = MSG_OK;
|
||||
|
||||
*axis = 0.0f;
|
||||
*axis = 0.0f;
|
||||
|
||||
osalDbgCheck((ip != NULL) && (axis != NULL));
|
||||
osalDbgAssert((((HTS221Driver *)ip)->state == HTS221_READY),
|
||||
|
@ -252,8 +252,7 @@ static msg_t thermo_read_raw(void *ip, int32_t axis[]) {
|
|||
#endif /* HTS221_SHARED_I2C */
|
||||
|
||||
msg = hts221I2CReadRegister(((HTS221Driver *)ip)->config->i2cp,
|
||||
HTS221_AD_TEMP_OUT_L,
|
||||
buff, 2);
|
||||
HTS221_AD_TEMP_OUT_L, buff, 2);
|
||||
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cReleaseBus(((HTS221Driver *)ip)->config->i2cp);
|
||||
|
@ -467,41 +466,49 @@ void hts221Start(HTS221Driver *devp, const HTS221Config *config) {
|
|||
devp->config = config;
|
||||
|
||||
#if HTS221_USE_I2C
|
||||
#if HTS221_SHARED_I2C
|
||||
|
||||
/* Control register 1 configuration block.*/
|
||||
{
|
||||
cr[0] = HTS221_AD_CTRL_REG1;
|
||||
cr[1] = devp->config->outputdatarate | HTS221_CTRL_REG1_PD;
|
||||
#if HTS221_USE_ADVANCED || defined(__DOXYGEN__)
|
||||
cr[1] |= devp->config->blockdataupdate;
|
||||
#endif
|
||||
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cAcquireBus((devp)->config->i2cp);
|
||||
#endif /* HTS221_SHARED_I2C */
|
||||
i2cStart((devp)->config->i2cp,
|
||||
(devp)->config->i2ccfg);
|
||||
|
||||
/* Control register 1 configuration block.*/
|
||||
{
|
||||
cr[0] = HTS221_AD_CTRL_REG1;
|
||||
cr[1] = devp->config->outputdatarate | HTS221_CTRL_REG1_PD;
|
||||
#if HTS221_USE_ADVANCED || defined(__DOXYGEN__)
|
||||
cr[1] |= devp->config->blockdataupdate;
|
||||
hts221I2CWriteRegister(devp->config->i2cp, cr, 1);
|
||||
|
||||
#endif
|
||||
hts221I2CWriteRegister(devp->config->i2cp, cr, 1);
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cReleaseBus((devp)->config->i2cp);
|
||||
#endif /* HTS221_SHARED_I2C */
|
||||
}
|
||||
|
||||
/* Average register configuration block.*/
|
||||
{
|
||||
cr[0] = HTS221_AD_AV_CONF;
|
||||
cr[0] = HTS221_AD_AV_CONF;
|
||||
cr[1] = 0x05;
|
||||
#if HTS221_USE_ADVANCED || defined(__DOXYGEN__)
|
||||
cr[1] = devp->config->reshumidity | devp->config->restemperature;
|
||||
|
||||
#endif
|
||||
hts221I2CWriteRegister(devp->config->i2cp, cr, 1);
|
||||
}
|
||||
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cReleaseBus((devp)->config->i2cp);
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cAcquireBus((devp)->config->i2cp);
|
||||
i2cStart((devp)->config->i2cp,
|
||||
(devp)->config->i2ccfg);
|
||||
#endif /* HTS221_SHARED_I2C */
|
||||
|
||||
hts221I2CWriteRegister(devp->config->i2cp, cr, 1);
|
||||
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cReleaseBus((devp)->config->i2cp);
|
||||
#endif /* HTS221_SHARED_I2C */
|
||||
}
|
||||
#endif /* HTS221_USE_I2C */
|
||||
|
||||
|
||||
|
||||
if(devp->config->sensitivity == NULL) {
|
||||
hts221Calibrate(devp, HTS221_FLAG_HYGRO_SENS | HTS221_FLAG_THERMO_SENS);
|
||||
}
|
||||
|
@ -541,27 +548,23 @@ void hts221Stop(HTS221Driver *devp) {
|
|||
osalDbgAssert((devp->state == HTS221_STOP) || (devp->state == HTS221_READY),
|
||||
"hts221Stop(), invalid state");
|
||||
|
||||
if (devp->state == HTS221_READY) {
|
||||
#if (HTS221_USE_I2C)
|
||||
if (devp->state == HTS221_STOP) {
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cAcquireBus((devp)->config->i2cp);
|
||||
i2cStart((devp)->config->i2cp,
|
||||
(devp)->config->i2ccfg);
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cAcquireBus((devp)->config->i2cp);
|
||||
i2cStart((devp)->config->i2cp, (devp)->config->i2ccfg);
|
||||
#endif /* HTS221_SHARED_I2C */
|
||||
|
||||
/* Control register 1 configuration block.*/
|
||||
{
|
||||
cr[0] = HTS221_AD_CTRL_REG1;
|
||||
cr[1] = 0;
|
||||
hts221I2CWriteRegister(devp->config->i2cp, cr, 1);
|
||||
}
|
||||
cr[0] = HTS221_AD_CTRL_REG1;
|
||||
cr[1] = 0;
|
||||
hts221I2CWriteRegister(devp->config->i2cp, cr, 1);
|
||||
|
||||
i2cStop((devp)->config->i2cp);
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cReleaseBus((devp)->config->i2cp);
|
||||
i2cStop((devp)->config->i2cp);
|
||||
#if HTS221_SHARED_I2C
|
||||
i2cReleaseBus((devp)->config->i2cp);
|
||||
#endif /* HTS221_SHARED_I2C */
|
||||
}
|
||||
#endif /* HTS221_USE_I2C */
|
||||
}
|
||||
devp->state = HTS221_STOP;
|
||||
}
|
||||
/** @} */
|
||||
|
|
|
@ -378,7 +378,7 @@ struct HTS221Driver {
|
|||
const struct BaseSensorVMT *vmt_basesensor;
|
||||
/** @brief BaseHygrometer Virtual Methods Table. */
|
||||
const struct BaseHygrometerVMT *vmt_basehygrometer;
|
||||
/** @brief BaseThermometer Virtual Methods Table. */
|
||||
/** @brief BaseThermometer Virtual Methods Table. */
|
||||
const struct BaseThermometerVMT *vmt_basethermometer;
|
||||
_hts221_data
|
||||
};
|
||||
|
|
|
@ -201,7 +201,7 @@ CPPWARN = -Wall -Wextra -Wundef
|
|||
|
||||
# List all user C define here, like -D_DEBUG=1
|
||||
UDEFS = -DCHPRINTF_USE_FLOAT=1 -DSHELL_CMD_TEST_ENABLED=0 \
|
||||
-DHTS221_USE_ADVANCED=0
|
||||
-DHTS221_USE_ADVANCED=0 -DLPS25H_SHARED_I2C=0
|
||||
|
||||
# Define ASM defines here
|
||||
UADEFS =
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="H0_rH_x2-hts221Calibrate-(format)" val="1"/><content id="tmp-hygro_read_raw.lto_priv.26-(format)" val="2"/><content id="rxbuf-lps25hI2CReadRegister-(format)" val="4"/><content id="null-lps25hI2CReadRegister-(format)" val="4"/><content id="null-read_raw-(format)" val="1"/><content id="null-lps25hStart-(format)" val="4"/><content id="tmp-read_raw.lto_priv.21-(format)" val="0"/><content id="cr-hts221Start-(format)" val="2"/><content id="reg-hts221I2CReadRegister-(format)" val="2"/><content id="rxbuf-hts221I2CReadRegister-(format)" val="2"/></contentList>"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="rxbuf-hts221I2CReadRegister-(format)" val="2"/><content id="reg-hts221I2CReadRegister-(format)" val="2"/><content id="cr-hts221Start-(format)" val="2"/><content id="tmp-read_raw.lto_priv.21-(format)" val="0"/><content id="null-lps25hStart-(format)" val="4"/><content id="null-read_raw-(format)" val="1"/><content id="null-lps25hI2CReadRegister-(format)" val="4"/><content id="rxbuf-lps25hI2CReadRegister-(format)" val="4"/><content id="tmp-hygro_read_raw.lto_priv.26-(format)" val="2"/><content id="H0_rH_x2-hts221Calibrate-(format)" val="1"/></contentList>"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <globalVariableList/> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList/> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
|
||||
|
|
Loading…
Reference in New Issue