예제 #1
0
void HardwareInit()
{
	// Set this only if nRF is power at 2V or more
	//nrf_power_dcdcen_set(true);
	NRF_POWER->DCDCEN = 1;

    IOPinCfg(s_GpioPins, s_NbGpioPins);

	IOPinClear(0, BLUEIO_TAG_BME680_LED2_BLUE_PIN);
	IOPinClear(0, BLUEIO_TAG_BME680_LED2_GREEN_PIN);
	IOPinClear(0, BLUEIO_TAG_BME680_LED2_RED_PIN);

	g_Timer.Init(s_TimerCfg);

	// Initialize I2C
#ifdef NEBLINA_MODULE
    g_Spi.Init(s_SpiCfg);
#else
    g_I2c.Init(s_I2cCfg);
#endif

	bsec_library_return_t bsec_status;

	// NOTE : For BME680 air quality calculation, this library is require to be initialized
	// before initializing the sensor driver.
	bsec_status = bsec_init();

	if (bsec_status != BSEC_OK)
	{
		printf("BSEC init failed\r\n");

		return;
	}

	// Inititalize sensor
    g_TphSensor.Init(s_TphSensorCfg, g_pIntrf, &g_Timer);

//    g_TphSensor.Disable();

//	g_I2c.Disable();

//	while(1) __WFE();


	if (g_TphSensor.DeviceID() == BME680_ID)
    {
    	g_GasSensor.Init(s_GasSensorCfg, g_pIntrf, NULL);
    }


    g_TphSensor.StartSampling();

	usDelay(300000);

    // Update sensor data
    TPHSENSOR_DATA tphdata;

    g_TphSensor.Read(tphdata);

    if (g_TphSensor.DeviceID() == BME680_ID)
    {
		GASSENSOR_DATA gdata;
		g_GasSensor.Read(gdata);
    }

	g_TphSensor.StartSampling();

	g_AdvData.Type = BLEADV_MANDATA_TYPE_TPH;
	// Do memcpy to adv data. Due to byte alignment, cannot read directly into
	// adv data
	memcpy(g_AdvData.Data, ((uint8_t*)&tphdata) + sizeof(tphdata.Timestamp), sizeof(BLEADV_MANDATA_TPHSENSOR));


	g_I2c.Disable();

#ifdef NRF52_SERIES
	g_Adc.Init(s_AdcCfg);
	g_Adc.OpenChannel(s_ChanCfg, s_NbChan);
	g_Adc.StartConversion();
#endif

#ifdef USE_TIMER_UPDATE
	// Only with SDK14

	uint64_t period = g_Timer.EnableTimerTrigger(0, 500UL, TIMER_TRIG_TYPE_CONTINUOUS);
#endif
}
예제 #2
0
void ReadPTHData()
{
	static uint32_t gascnt = 0;
	TPHSENSOR_DATA data;
	GASSENSOR_DATA gdata;
#if 1

	g_I2c.Enable();

	g_TphSensor.Read(data);


/*
	if (g_TphSensor.DeviceID() == BME680_ID && (gascnt & 0x3) == 0)
	{
		g_GasSensor.Read(gdata);
	}
*/
	if ((gascnt & 0xf) == 0)
	{
#ifdef NRF52_SERIES
		g_Adc.Enable();
		g_Adc.OpenChannel(s_ChanCfg, s_NbChan);
		g_Adc.StartConversion();

		g_AdvData.Type = BLEADV_MANDATA_TYPE_BAT;

		memcpy(&g_AdvBat, &g_BatData, sizeof(BLUEIO_DATA_BAT));
#endif
	}
	else if ((gascnt & 0x3) == 0)
	{
		BLEADV_MANDATA_GASSENSOR gas;

		g_GasSensor.Read(gdata);

		g_AdvData.Type = BLEADV_MANDATA_TYPE_GAS;
		gas.GasRes = gdata.GasRes[gdata.MeasIdx];
		gas.AirQIdx = gdata.AirQualIdx;

		memcpy(&g_GasData, &gas, sizeof(BLEADV_MANDATA_GASSENSOR));

		g_TphSensor.StartSampling();
	}
	else
	{
		g_AdvData.Type = BLEADV_MANDATA_TYPE_TPH;

		// NOTE : M0 does not access unaligned data
		// use local 4 bytes align stack variable then mem copy
		// skip timestamp as advertising pack is limited in size
		memcpy(&g_TPHData, ((uint8_t*)&data) + sizeof(data.Timestamp), sizeof(BLEADV_MANDATA_TPHSENSOR));
	}

//	g_TphSensor.StartSampling();

	g_I2c.Disable();

#ifdef NRF52_SERIES
	g_Adc.Enable();
	g_Adc.OpenChannel(s_ChanCfg, s_NbChan);
	g_Adc.StartConversion();
#endif

#endif
	// Update advertisement data
	BleAppAdvManDataSet(g_AdvDataBuff, sizeof(g_AdvDataBuff), NULL, 0);
//	BleAppAdvManDataSet((uint8_t*)&gascnt, sizeof(gascnt), NULL, 0);

	gascnt++;
}