/**
 * \brief Read data from the gyroscope - X, Y, Z - 3 words
 * \return True if a valid reading could be taken, false otherwise
 */
static bool
gyro_read(uint16_t *data)
{
  bool success;

  if(interrupt_status & BIT_RAW_RDY_EN) {
    /* Select this sensor */
    SENSOR_SELECT();

    /* Burst read of all gyroscope values */
    success = sensor_common_read_reg(GYRO_XOUT_H, (uint8_t *)data, DATA_SIZE);

    if(success) {
      convert_to_le((uint8_t *)data, DATA_SIZE);
    } else {
      sensor_common_set_error_data((uint8_t *)data, DATA_SIZE);
    }

    SENSOR_DESELECT();
  } else {
    success = false;
  }

  return success;
}
Пример #2
0
/*******************************************************************************
* @fn          SensorHdc1080_read
*
* @brief       Get humidity sensor data
*
* @param       rawTemp - raw temperature value
*
* @param       rawHum - raw humidity value
*
* @return      true if I2C operations successful
*/
bool SensorHdc1080_read(uint16_t *rawTemp, uint16_t *rawHum)
{
    bool valid;

    if (success)
    {
        if (!SENSOR_SELECT())
        {
            return false;
        }

        success = SensorI2C_read((uint8_t*)&data, sizeof(data));
        SENSOR_DESELECT();

        // Store temperature
        *rawTemp = SWAP(data.temp);

        // Store humidity
        *rawHum = SWAP(data.hum);
    }

    valid = success;
    success = true; // Ready for next cycle

    return valid;
}
/**
 * \brief Select gyro and accelerometer axes
 */
static void
select_axes(void)
{
  val = ~mpu_config;
  SENSOR_SELECT();
  sensor_common_write_reg(PWR_MGMT_2, &val, 1);
  SENSOR_DESELECT();
}
/**************************************************************************************************
* @fn          sensorSht21StartHumMeasure
*
* @brief       Execute measurement step
*
* @return      none
*/
void sensorSht21StartHumMeasure(void)
{
  if (success)
  {
    SENSOR_SELECT();
    success = sensorSht21WriteCmd(SHT21_CMD_HUMI_T_NH);
    SENSOR_DESELECT();
  }
}
/**************************************************************************************************
* @fn          sensorSht21LatchHumMeasure
*
* @brief       Latch humidity measurement
*
* @return      none
*/
void sensorSht21LatchHumMeasure(void)
{
  if (success)
  {
    SENSOR_SELECT();
    success = sensorSht21ReadData(buf+DATA_LEN, DATA_LEN);
    SENSOR_DESELECT();
  }
}
/**
 * \brief Check whether a data or wake on motion interrupt has occurred
 * \return Return the interrupt status
 *
 * This driver does not use interrupts, however this function allows us to
 * determine whether a new sensor reading is available
 */
static uint8_t
int_status(void)
{
  SENSOR_SELECT();
  sensor_common_read_reg(INT_STATUS, &interrupt_status, 1);
  SENSOR_DESELECT();

  return interrupt_status;
}
Пример #7
0
/**
 * \brief       Start measurement
 */
static void
start(void)
{
  if(success) {
    SENSOR_SELECT();

    success = board_i2c_write_single(HDC1000_REG_TEMP);
    SENSOR_DESELECT();
  }
}
Пример #8
0
/*******************************************************************************
* @fn          sensorHdc1000Start
*
* @brief       Start measurement
*
* @return      none
*/
void sensorHdc1000Start(void)
{
  if (success)
  {
    if (!SENSOR_SELECT())
      return;

    success = bspI2cWriteSingle(HDC1000_REG_TEMP);
    SENSOR_DESELECT();
  }
}
/**
 * \brief Place the MPU in low power mode
 */
static void
sensor_sleep(void)
{
  SENSOR_SELECT();

  val = ALL_AXES;
  sensor_common_write_reg(PWR_MGMT_2, &val, 1);

  val = MPU_SLEEP;
  sensor_common_write_reg(PWR_MGMT_1, &val, 1);
  SENSOR_DESELECT();
}
Пример #10
0
/*******************************************************************************
* @fn          SensorHdc1080_test
*
* @brief       Humidity sensor self test
*
* @return      true if test passes
*******************************************************************************/
bool SensorHdc1080_test(void)
{
    uint16_t val;

    SENSOR_SELECT();
    SensorI2C_writeReg(HDC1080_REG_MANF_ID, 0, 0);
    SENSOR_DESELECT();

    SENSOR_SELECT();
    SensorI2C_read((uint8_t *)&val, 2);
    SENSOR_DESELECT();


    ST_ASSERT(val == HDC1080_VAL_MANF_ID);
    SENSOR_SELECT();
    SensorI2C_writeReg(HDC1080_REG_DEV_ID, 0, 0);
    SENSOR_DESELECT();



    SENSOR_SELECT();
    SensorI2C_read((uint8_t *)&val, 2);
    SENSOR_DESELECT();
    ST_ASSERT(val == HDC1080_VAL_DEV_ID);

//    // Verify manufacturer ID
//    ST_ASSERT(SensorI2C_readReg(HDC1080_REG_MANF_ID,(uint8_t*)&val,2));
//    val = SWAP(val);
//    ST_ASSERT(val == HDC1080_VAL_MANF_ID);

//    // Verify device ID
//    ST_ASSERT(SensorI2C_readReg(HDC1080_REG_DEV_ID,(uint8_t*)&val,2));
//    val = SWAP(val);
//    ST_ASSERT(val == HDC1080_VAL_DEV_ID);

//    SENSOR_DESELECT();

    return true;
}
Пример #11
0
/**
 * \brief       Initialise the humidity sensor driver
 * \return      True if I2C operation successful
 */
static bool
sensor_init(void)
{
  uint16_t val;

  SENSOR_SELECT();

  /* Enable reading data in one operation */
  val = SWAP(HDC1000_VAL_CONFIG);
  success = sensor_common_write_reg(HDC1000_REG_CONFIG, (uint8_t *)&val, 2);

  SENSOR_DESELECT();

  return success;
}
Пример #12
0
/*******************************************************************************
* @fn          sensorHdc1000Init
*
* @brief       Initialise the humidity sensor driver
*
* @return      True if I2C operation successful
*******************************************************************************/
bool sensorHdc1000Init(void)
{
  uint16_t val;

  if (!SENSOR_SELECT())
    return false;

  // Enable reading data in one operation
  val = SWAP(HDC1000_VAL_CONFIG);
  success = sensorWriteReg(HDC1000_REG_CONFIG,(uint8_t*)&val,2);

  SENSOR_DESELECT();

  return success;
}
/**************************************************************************************************
* @fn          sensorSht21Test
*
* @brief       Humidity sensor self test
*
* @return      none
**************************************************************************************************/
bool sensorSht21Test(void)
{
  uint8_t val;

  SENSOR_SELECT();

  // Verify write and read
  val = USR_REG_TEST_VAL;
  ST_ASSERT(sensorWriteReg(SHT21_CMD_WRITE_U_R,&val,1));
  ST_ASSERT(sensorReadReg(SHT21_CMD_READ_U_R,&val,1));
  ST_ASSERT(val == USR_REG_TEST_VAL);
  
  SENSOR_DESELECT();
  
  return true;
}
/**************************************************************************************************
* @fn          sensorSht21Init
*
* @brief       Initialize the humidity sensor driver
*
* @return      True if successful
**************************************************************************************************/
bool sensorSht21Init(void)
{
  SENSOR_SELECT();

  // Set 11 bit resolution
  success = sensorReadReg(SHT21_CMD_READ_U_R,&usr,1);
  if (success)
  {
    usr &= USR_REG_RES_MASK;
    usr |= USR_REG_11BITRES;
    success = sensorWriteReg(SHT21_CMD_WRITE_U_R,&usr,1);
  }
  
  SENSOR_DESELECT();
  
  return success;
}
Пример #15
0
/*******************************************************************************
* @fn          SensorHdc1080_start
*
* @brief       Start measurement
*
* @return      none
*/
void SensorHdc1080_start(void)
{
    if (success)
    {
        uint8_t val;

        if (!SENSOR_SELECT())
        {
            return;
        }

        val = HDC1080_REG_TEMP;
        success = SensorI2C_write(&val, sizeof(val));

        SENSOR_DESELECT();
    }
}
Пример #16
0
/*******************************************************************************
* @fn          sensorHdc1000Test
*
* @brief       Humidity sensor self test
*
* @return      true if test passes
*******************************************************************************/
bool sensorHdc1000Test(void)
{
  uint16_t val;

  SENSOR_SELECT();

  // Verify manufacturer ID
  ST_ASSERT(sensorReadReg(HDC1000_REG_MANF_ID,(uint8_t*)&val,2));
  val = SWAP(val);
  ST_ASSERT(val == HDC1000_VAL_MANF_ID);

  // Verify device ID
  ST_ASSERT(sensorReadReg(HDC1000_REG_DEV_ID,(uint8_t*)&val,2));
  val = SWAP(val);
  ST_ASSERT(val == HDC1000_VAL_DEV_ID);
  SENSOR_DESELECT();

  return true;
}
/**
 * \brief Exit low power mode
 */
static void
sensor_wakeup(void)
{
  SENSOR_SELECT();
  val = MPU_WAKE_UP;
  sensor_common_write_reg(PWR_MGMT_1, &val, 1);

  /* All axis initially disabled */
  val = ALL_AXES;
  sensor_common_write_reg(PWR_MGMT_2, &val, 1);
  mpu_config = 0;

  /* Restore the range */
  sensor_common_write_reg(ACCEL_CONFIG, &acc_range_reg, 1);

  /* Clear interrupts */
  sensor_common_read_reg(INT_STATUS, &val, 1);
  SENSOR_DESELECT();
}
Пример #18
0
/**
 * \brief       Take readings from the sensor
 * \return      true of I2C operations successful
 */
static bool
read_data()
{
  bool valid;

  if(success) {
    SENSOR_SELECT();

    success = board_i2c_read((uint8_t *)&data, sizeof(data));
    SENSOR_DESELECT();

    /* Store temperature */
    raw_temp = SWAP(data.temp);

    /* Store humidity */
    raw_hum = SWAP(data.hum);
  }

  valid = success;
  success = true;

  return valid;
}
/**
 * \brief Read data from the accelerometer - X, Y, Z - 3 words
 * \return True if a valid reading could be taken, false otherwise
 */
static bool
acc_read(uint16_t *data)
{
  bool success;

  if(interrupt_status & BIT_RAW_RDY_EN) {
    /* Burst read of all accelerometer values */
    SENSOR_SELECT();
    success = sensor_common_read_reg(ACCEL_XOUT_H, (uint8_t *)data, DATA_SIZE);
    SENSOR_DESELECT();

    if(success) {
      convert_to_le((uint8_t *)data, DATA_SIZE);
    } else {
      sensor_common_set_error_data((uint8_t *)data, DATA_SIZE);
    }
  } else {
    /* Data not ready */
    success = false;
  }

  return success;
}
/**
 * \brief Set the range of the accelerometer
 * \param new_range: ACC_RANGE_2G, ACC_RANGE_4G, ACC_RANGE_8G, ACC_RANGE_16G
 * \return true if the write to the sensor succeeded
 */
static bool
acc_set_range(uint8_t new_range)
{
  bool success;

  if(new_range == acc_range) {
    return true;
  }

  success = false;

  acc_range_reg = (new_range << 3);

  /* Apply the range */
  SENSOR_SELECT();
  success = sensor_common_write_reg(ACCEL_CONFIG, &acc_range_reg, 1);
  SENSOR_DESELECT();

  if(success) {
    acc_range = new_range;
  }

  return success;
}