/**************************************************************************//**
 * @brief
  *  Initializes and configures the Si1147 sensor.
 * @param[in] i2c
 *   The I2C peripheral to use (not used).
 * @param[in] addr
 *   The I2C address of the sensor.
 * @param[in] lowpower
 *   Set to 1 to initialize without autonomous mode (low power) or set to 0
 *   to enable autonomous mode.
 * @return
 *   Returns 0 on success.
 *****************************************************************************/
int Si1147_ConfigureDetection(I2C_TypeDef *i2c, uint8_t addr, int lowpower)
{
  s16          retval = 0;
  SI114X_CAL_S si114x_cal;
  si114x_handle->addr = addr;
  si114x_handle->i2c  = i2c;


  /* Note that the Si114xReset() actually performs the following functions: */
  /*     1. Pauses all prior measurements */
  /*     2. Clear  i2c registers that need to be cleared */
  /*     3. Clears irq status to make sure INT* is negated */
  /*     4. Delays 10 ms */
  /*     5. Sends HW Key */
  retval += Si114xReset(si114x_handle);

  retval += Si114xWriteToRegister(si114x_handle, REG_PS_LED21, (LED1I << 4) + LED2I);
  retval += Si114xWriteToRegister(si114x_handle, REG_PS_LED3, LED3I);



  /* UV Coefficients */
  si114x_get_calibration(si114x_handle, &si114x_cal, 1);
  si114x_set_ucoef(si114x_handle, 0, &si114x_cal);



  retval += Si114xParamSet(si114x_handle, PARAM_CH_LIST, GESTURE_TASKLIST | UV_TASKLIST);

  retval += Si114xWriteToRegister(si114x_handle, REG_IRQ_ENABLE, GESTURE_IRQ);

  retval += Si114xParamSet(si114x_handle, PARAM_PS_ADC_MISC, 0x24);  /* PS_ADC_MISC to high signal range */
  retval += Si114xParamSet(si114x_handle, PARAM_PS1_ADC_MUX, 0x00);  /* PS1_ADCMUX, PS2_ADCMUX, PS3_ADCMUX to small photodiode */
  retval += Si114xParamSet(si114x_handle, PARAM_PS2_ADC_MUX, 0x00);
  retval += Si114xParamSet(si114x_handle, PARAM_PS3_ADC_MUX, 0x00);

  /* Configure the ALS IR channel for the same settings as PS */

  retval += Si114xParamSet(si114x_handle, PARAM_ALSIR_ADC_MISC, RANGE_EN);
  retval += Si114xParamSet(si114x_handle, PARAM_ALSVIS_ADC_MISC, RANGE_EN);

  if (!lowpower)
  {
    /* Set up how often the device wakes up to make measurements (10ms) */
    retval += Si114xWriteToRegister(si114x_handle, REG_MEAS_RATE_MSB, (MEASRATE_FAST & 0xff00) >> 8);
    retval += Si114xWriteToRegister(si114x_handle, REG_MEAS_RATE_LSB, MEASRATE_FAST & 0x00ff);
    /* Enable Autonomous Operation */
    retval += Si114xPsAlsAuto(si114x_handle);

  }
Beispiel #2
0
/**************************************************************************//**
 * @brief
  *  Initializes and configures the Si1146 sensor for UV index measurements.
 * @param[in] fullInit
 *   The I2C peripheral to use (not used).
 * @param[in] handle
 *   The si114x handle for programmer's toolkit
 * @return
 *   Returns 0 on success.
 *****************************************************************************/
int Si114x_ConfigureUV(int fullInit, HANDLE *handle)
{
  s16          retval = 0;
  SI114X_CAL_S si114x_cal;

  /* Set handle */
  si114x_handle = *handle;

  /* Note that the Si114xReset() actually performs the following functions: */
  /*     1. Pauses all prior measurements */
  /*     2. Clear  i2c registers that need to be cleared */
  /*     3. Clears irq status to make sure INT* is negated */
  /*     4. Delays 10 ms */
  /*     5. Sends HW Key */
  if (fullInit)
     retval += Si114xReset(si114x_handle);

  /* UV Coefficients */
  si114x_get_calibration(si114x_handle, &si114x_cal, 0);
  si114x_set_ucoef(si114x_handle, 0, &si114x_cal);


  if (fullInit)
  {
     retval += Si114xParamSet(si114x_handle, PARAM_CH_LIST, UV_TASKLIST);
     retval += Si114xWriteToRegister(si114x_handle, REG_IRQ_ENABLE, IE_ALS_EVRYSAMPLE);

     retval += Si114xParamSet(si114x_handle, PARAM_PS_ADC_MISC, 0x24);  /* PS_ADC_MISC to high signal range */
     retval += Si114xParamSet(si114x_handle, PARAM_PS1_ADC_MUX, 0x00);  /* PS1_ADCMUX, PS2_ADCMUX, PS3_ADCMUX to small photodiode */
     retval += Si114xParamSet(si114x_handle, PARAM_PS2_ADC_MUX, 0x00);
     retval += Si114xParamSet(si114x_handle, PARAM_PS3_ADC_MUX, 0x00);
  }
  /* Configure the ALS IR channel for the same settings as PS */
  retval += Si114xParamSet(si114x_handle, PARAM_ALSIR_ADC_MISC, RANGE_EN);
  retval += Si114xParamSet(si114x_handle, PARAM_ALSVIS_ADC_MISC, RANGE_EN);
  /* If nothing went wrong after all of this time, the value */
  /* returned will be 0. Otherwise, it will be some negative */
  /* number */
  return retval;
}