Example #1
0
OSStatus bmg160_data_readout(s16 *v_gyro_datax_s16, s16 *v_gyro_datay_s16, s16 *v_gyro_dataz_s16)
{
  OSStatus err = kUnknownErr;
  
  /* result of communication results*/
  s32 com_rslt = BMG160_ERROR;
  
  //-------------------------- NOTE ----------------------------------
  // this is to avoid i2c pin is re-init by other module because they use the same pin.
  MicoI2cInitialize(&bmg160_i2c_device);
  //------------------------------------------------------------------
    
  /************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA *********/

  com_rslt = bmg160_get_data_X(v_gyro_datax_s16);/* Read the gyro X data*/

  com_rslt += bmg160_get_data_Y(v_gyro_datay_s16);/* Read the gyro Y data*/

  com_rslt += bmg160_get_data_Z(v_gyro_dataz_s16);/* Read the gyro Z data*/
  
  /************ END READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY ********/
  
  if(0 == com_rslt){
    err = kNoErr;
  }
  return err;
}
OSStatus apds9930_sensor_init(void)
{
  OSStatus err = kNoErr;
  uint8_t device_id;
  
  MicoI2cFinalize(&apds_i2c_device); 
  
  /*int apds9930 sensor i2c device*/
  err = MicoI2cInitialize(&apds_i2c_device);
  require_noerr_action( err, exit, apds9930_log("APDS9930_ERROR: MicoI2cInitialize err = %d.", err) );
  
  if( false == MicoI2cProbeDevice(&apds_i2c_device, 5) ){
    apds9930_log("APDS9930_ERROR: no i2c device found!");
    err = kNotFoundErr;
    goto exit;
  }
  
  APDS9930_Clear_intrtrupt();
  
  err = APDS9930_Read_RegData(ID_ADDR, &device_id);
  require_noerr( err, exit );
  
  if(APDS9930_ID != device_id){
    apds9930_log("APDS9930_ERROR: device id err");
    err = kNotFoundErr;
    goto exit;
  }
  
  apds9930_enable();
  
exit:
  return err;
}
Example #3
0
OSStatus bmm050_data_readout(s16 *v_mag_datax_s16, s16 *v_mag_datay_s16, s16 *v_mag_dataz_s16)
{
  OSStatus err = kUnknownErr;
  struct bmm050_mag_data_s16_t data;
  
  /* result of communication results*/
  s32 com_rslt = BMM050_ERROR;
  
  //-------------------------- NOTE ----------------------------------
  // this is to avoid i2c pin is re-init by other module because they use the same pin.
  MicoI2cInitialize(&bmm050_i2c_device);
  //------------------------------------------------------------------
    
  /************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA *********/

  /* accessing the bmm050_mdata parameter by using data*/
  com_rslt = bmm050_read_mag_data_XYZ(&data);/* Reads the mag x y z data*/
  
  *v_mag_datax_s16 = data.datax;
  *v_mag_datay_s16 = data.datay;
  *v_mag_dataz_s16 = data.dataz;
  /************ END READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY ********/
  
  if(0 == com_rslt){
    err = kNoErr;
  }
  return err;
}
Example #4
0
OSStatus bme280_data_readout(s32 *v_actual_temp_s32, u32 *v_actual_press_u32, u32 *v_actual_humity_u32)
{
    OSStatus err = kUnknownErr;
    
	/* result of communication results*/
	s32 com_rslt = BME280_ERROR;
        
        //-------------------------- NOTE ----------------------------------
        // this is to avoid i2c pin is re-init by other module because they use the same pin.
        MicoI2cInitialize(&user_i2c_device);
        //------------------------------------------------------------------
          
//        /************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA *********/
//	/* API is used to read the true temperature*/
//	/* Input value as uncompensated temperature and output format*/
//        	com_rslt += bme280_compensate_temperature_int32(v_data_uncomp_tem_s32);
//        	com_rslt += bme280_compensate_pressure_int32(v_data_uncomp_pres_s32);
//        	com_rslt += bme280_compensate_humidity_int32(v_data_uncomp_hum_s32);
        
	/* API is used to read the true temperature, humidity and pressure*/
	com_rslt = bme280_read_pressure_temperature_humidity(v_actual_press_u32, 
                                                             v_actual_temp_s32, 
                                                             v_actual_humity_u32);
        /************ END READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY ********/
        
        if(0 == com_rslt){
          err = kNoErr;
        }
        return err;
}
Example #5
0
OSStatus bmg160_sensor_init(void)
{
  OSStatus err = kUnknownErr;
  /* variable used for read the gyro bandwidth data*/
  u8 v_gyro_value_u8 = BMG160_INIT_VALUE;
  /* variable used for set the gyro bandwidth data*/
  u8 v_bw_u8 = BMG160_INIT_VALUE;
  s32 com_rslt = BMG160_ERROR;  // result of communication results
 // u8 v_stand_by_time_u8 = BME280_INIT_VALUE;  //  The variable used to assign the standby time
  
  // I2C init
  MicoI2cFinalize(&bmg160_i2c_device);   // in case error
  err = MicoI2cInitialize(&bmg160_i2c_device);
  require_noerr_action( err, exit, bmg160_user_log("BMG160_ERROR: MicoI2cInitialize err = %d.", err) );
  if( false == MicoI2cProbeDevice(&bmg160_i2c_device, 5) ){
    bmg160_user_log("BMG160_ERROR: no i2c device found!");
    err = kNotFoundErr;
    goto exit;
  }
  
  // sensor init

  /*********************** START INITIALIZATION ************************/
  /*	Based on the user need configure I2C or SPI interface.
  *	It is example code to explain how to use the bme280 API*/
#ifdef BMG160_API
  BMG160_I2C_routine();
  com_rslt = bmg160_init(&bmg160);
  com_rslt += bmg160_set_power_mode(BMG160_MODE_NORMAL);
  /*------------------------------------------------------------------------*
  ************************* START GET and SET FUNCTIONS DATA ***************
  *--------------------------------------------------------------------------*/
  /* This API used to Write the bandwidth of the gyro sensor
  input value have to be give 0x10 bit BMG160_INIT_VALUE to 3
  The bandwidth set from the register */
  v_bw_u8 = C_BMG160_BW_230HZ_U8X;/* set gyro bandwidth of 230Hz*/
  com_rslt += bmg160_set_bw(v_bw_u8);

  /* This API used to read back the written value of bandwidth for gyro*/
  com_rslt += bmg160_get_bw(&v_gyro_value_u8);
  /*---------------------------------------------------------------------*
  ************************* END GET and SET FUNCTIONS ********************
  *----------------------------------------------------------------------*/
  if(com_rslt < 0){
    bmg160_user_log("BMG160_ERROR: bme280 sensor init failed!");
    err = kNotInitializedErr;
    goto exit;
  }
  /************************* END INITIALIZATION *************************/
#endif
  return kNoErr;
  
exit:
  return err;
}
Example #6
0
OSStatus bmm050_sensor_init(void)
{
  OSStatus err = kUnknownErr;
  /* Variable used to get the data rate*/
  u8 v_data_rate_u8 = BMM050_INIT_VALUE;
  /* Variable used to set the data rate*/
  u8 v_data_rate_value_u8 = BMM050_INIT_VALUE;
  s32 com_rslt = BMM050_ERROR;  // result of communication results
 // u8 v_stand_by_time_u8 = BME280_INIT_VALUE;  //  The variable used to assign the standby time
  
  // I2C init
  MicoI2cFinalize(&bmm050_i2c_device);   // in case error
  err = MicoI2cInitialize(&bmm050_i2c_device);
  require_noerr_action( err, exit, bmm050_user_log("BMM050_ERROR: MicoI2cInitialize err = %d.", err) );
  if( false == MicoI2cProbeDevice(&bmm050_i2c_device, 5) ){
    bmm050_user_log("BMM050_ERROR: no i2c device found!");
    err = kNotFoundErr;
    goto exit;
  }
  
  // sensor init

  /*********************** START INITIALIZATION ************************/
  /*	Based on the user need configure I2C or SPI interface.
  *	It is example code to explain how to use the bme280 API*/
#ifdef BMM050_API
  BMM050_I2C_routine();
  com_rslt = bmm050_init(&bmm050_t);
  com_rslt += bmm050_set_functional_state(BMM050_NORMAL_MODE);
  /*------------------------------------------------------------------------*
  ************************* START GET and SET FUNCTIONS DATA ****************
  *---------------------------------------------------------------------------*/
  /* This API used to Write the data rate of the sensor, input
  value have to be given
  data rate value set from the register 0x4C bit 3 to 5*/
  v_data_rate_value_u8 = BMM050_DATA_RATE_30HZ;/* set data rate of 30Hz*/
  com_rslt += bmm050_set_data_rate(v_data_rate_value_u8);

  /* This API used to read back the written value of data rate*/
  com_rslt += bmm050_get_data_rate(&v_data_rate_u8);
  /*-----------------------------------------------------------------*
  ************************* END GET and SET FUNCTIONS ****************
  *-------------------------------------------------------------------*/
  if(com_rslt < 0){
    bmm050_user_log("BMM050_ERROR: bme280 sensor init failed!");
    err = kNotInitializedErr;
    goto exit;
  }
  /************************* END INITIALIZATION *************************/
#endif
  return kNoErr;
  
exit:
  return err;
}
HUM_TEMP_StatusTypeDef HTS221_IO_Init(void)
{
  // I2C init
  MicoI2cFinalize(&hts221_i2c_device);   // in case error
  MicoI2cInitialize(&hts221_i2c_device);
  if( false == MicoI2cProbeDevice(&hts221_i2c_device, 5) ){
    hts221_log("HTS221_ERROR: no i2c device found!");
    return HUM_TEMP_ERROR;
  }
  return HUM_TEMP_OK;
}
Example #8
0
PRESSURE_StatusTypeDef LPS25HB_IO_Init(void)
{
  // I2C init
  MicoI2cFinalize(&lps25hb_i2c_device);   // in case error
  MicoI2cInitialize(&lps25hb_i2c_device);

  if( false == MicoI2cProbeDevice(&lps25hb_i2c_device, 5) ){
    lps25hb_log("LPS25HB_ERROR: no i2c device found!");
    return PRESSURE_ERROR;
  }
  return PRESSURE_OK;
}
Example #9
0
OSStatus UVIS25_IO_Init(void)
{
  // I2C init
  MicoI2cFinalize(&uvis25_i2c_device);   // in case error
  MicoI2cInitialize(&uvis25_i2c_device);

  if( false == MicoI2cProbeDevice(&uvis25_i2c_device, 5) ){
    uvis25_log("UVI25S_ERROR: no i2c device found!");
    return kNotInitializedErr;
  }
  return kNoErr;
}
Example #10
0
/*------------------------------- user interfaces ----------------------------*/
void rgb_led_init(void)
{
#ifndef RGB_LED_USE_I2C
  
  MicoGpioInitialize( (mico_gpio_t)RGB_LED_CIN, OUTPUT_OPEN_DRAIN_NO_PULL );
  MicoGpioInitialize( (mico_gpio_t)RGB_LED_DIN, OUTPUT_OPEN_DRAIN_NO_PULL );
  
#else
  
  // just use i2c sck && sda to send data to control p9813
  OSStatus err = kUnknownErr;
  err = MicoI2cInitialize(&p9813_i2c_device);
  //require_noerr_action( err, exit, bme280_log("ERROR: MicoI2cInitialize err = %d.", err) );
  
#endif
}
Example #11
0
// bme280_sensor_init
OSStatus bme280_sensor_init(void)
{
  OSStatus err = kUnknownErr;
  s32 com_rslt = BME280_ERROR;  // result of communication results
 // u8 v_stand_by_time_u8 = BME280_INIT_VALUE;  //  The variable used to assign the standby time
  
  // I2C init
  MicoI2cFinalize(&user_i2c_device);   // in case error
  err = MicoI2cInitialize(&user_i2c_device);
  require_noerr_action( err, exit, bme280_user_log("BME280_ERROR: MicoI2cInitialize err = %d.", err) );
  if( false == MicoI2cProbeDevice(&user_i2c_device, 5) ){
    bme280_user_log("BME280_ERROR: no i2c device found!");
    err = kNotFoundErr;
    goto exit;
  }
  
  // sensor init

  /*********************** START INITIALIZATION ************************/
  /*	Based on the user need configure I2C or SPI interface.
  *	It is example code to explain how to use the bme280 API*/
#ifdef BME280_API
  I2C_routine();
  com_rslt = bme280_init(&bme280);
  com_rslt += bme280_set_power_mode(BME280_NORMAL_MODE);
  com_rslt += bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);
  com_rslt += bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);
  com_rslt += bme280_set_oversamp_temperature(BME280_OVERSAMP_4X);
  /************************* START GET and SET FUNCTIONS DATA ****************/
  //com_rslt += bme280_set_standby_durn(BME280_STANDBY_TIME_1_MS);
  //com_rslt += bme280_get_standby_durn(&v_stand_by_time_u8);
  /************************** END GET and SET FUNCTIONS **************/
  if(com_rslt < 0){
    bme280_user_log("BME280_ERROR: bme280 sensor init failed!");
    err = kNotInitializedErr;
    goto exit;
  }
  /************************* END INITIALIZATION *************************/
#endif
  return kNoErr;
  
exit:
  return err;
}
Example #12
0
OSStatus bme280_data_pressure(u32 *v_actual_press_u32)
{
    	s32 com_rslt = BME280_ERROR;  // result of communication results
	s32 v_data_uncomp_pres_s32 = BME280_INIT_VALUE;  // uncompensated humidity
     
        //-------------------------- NOTE ----------------------------------
        // this is to avoid i2c pin is re-init by other module because they use the same pin.
        MicoI2cInitialize(&user_i2c_device);
        //------------------------------------------------------------------
        
        com_rslt = bme280_read_uncomp_pressure(&v_data_uncomp_pres_s32);
         if(0 != com_rslt){
          return kReadErr;
        }
        
        *v_actual_press_u32 = bme280_compensate_pressure_int32(v_data_uncomp_pres_s32);
        
        return kNoErr;
}