Lines Matching refs:mTask
256 static struct SensorData mTask;
289 for (i = 0; i < ARRAY_SIZE(mTask.transfers); i++) {
290 if (!mTask.transfers[i].inUse) {
291 mTask.transfers[i].inUse = true;
292 mTask.transfers[i].state = state;
293 return &mTask.transfers[i];
336 osEnqueuePrivateEvt(EVT_SENSOR_PROX_INTERRUPT, NULL, NULL, mTask.tid);
344 osEnqueuePrivateEvt(EVT_SENSOR_PROX_INTERRUPT, NULL, NULL, mTask.tid);
348 osEnqueuePrivateEvt(EVT_SENSOR_ALS_INTERRUPT, NULL, NULL, mTask.tid);
377 osEnqueuePrivateEvt(EVT_SENSOR_I2C, cookie, NULL, mTask.tid);
384 osEnqueuePrivateEvt(EVT_SENSOR_ALS_TIMER, cookie, NULL, mTask.tid);
403 (AMS_TMD4903_ATIME_MS * getAlsGainFromSetting(mTask.alsGain))) * mTask.alsOffset;
410 if ((mTask.alsGain != ALS_GAIN_64X) && (sample < AMS_TMD4903_ALS_GAIN_64X_THOLD)) {
411 mTask.alsDebounceSamples = (mTask.nextAlsGain == ALS_GAIN_64X) ? (mTask.alsDebounceSamples + 1) : 1;
412 mTask.nextAlsGain = ALS_GAIN_64X;
413 } else if ((mTask.alsGain != ALS_GAIN_16X) && (sample >= AMS_TMD4903_ALS_GAIN_64X_THOLD) && (sample < AMS_TMD4903_ALS_GAIN_16X_THOLD)) {
414 mTask.alsDebounceSamples = (mTask.nextAlsGain == ALS_GAIN_16X) ? (mTask.alsDebounceSamples + 1) : 1;
415 mTask.nextAlsGain = ALS_GAIN_16X;
416 } else if ((mTask.alsGain != ALS_GAIN_4X) && (sample >= AMS_TMD4903_ALS_GAIN_16X_THOLD) && (sample < AMS_TMD4903_ALS_GAIN_4X_THOLD)) {
417 mTask.alsDebounceSamples = (mTask.nextAlsGain == ALS_GAIN_4X) ? (mTask.alsDebounceSamples + 1) : 1;
418 mTask.nextAlsGain = ALS_GAIN_4X;
419 } else if ((mTask.alsGain != ALS_GAIN_1X) && (sample >= AMS_TMD4903_ALS_GAIN_4X_THOLD)) {
420 mTask.alsDebounceSamples = (mTask.nextAlsGain == ALS_GAIN_1X) ? (mTask.alsDebounceSamples + 1) : 1;
421 mTask.nextAlsGain = ALS_GAIN_1X;
424 return (mTask.alsDebounceSamples >= AMS_TMD4903_ALS_DEBOUNCE_SAMPLES);
481 if (on && !mTask.alsTimerHandle) {
482 mTask.alsTimerHandle = timTimerSet(AMS_TMD4903_ALS_TIMER_DELAY, 0, 50, alsTimerCallback, NULL, false);
483 } else if (!on && mTask.alsTimerHandle) {
484 timTimerCancel(mTask.alsTimerHandle);
485 mTask.alsTimerHandle = 0;
488 mTask.lastAlsSample.idata = AMS_TMD4903_ALS_INVALID;
489 mTask.alsOn = on;
490 mTask.nextAlsGain = ALS_GAIN_4X;
491 mTask.alsChangingGain = false;
493 mTask.alsSkipSample = true;
494 mTask.alsDebounceSamples = 0;
496 setMode(on, mTask.proxOn, (on) ? SENSOR_STATE_ENABLING_ALS : SENSOR_STATE_DISABLING_ALS);
502 return sensorSignalInternalEvt(mTask.alsHandle, SENSOR_INTERNAL_EVT_FW_STATE_CHG, 1, 0);
512 return sensorSignalInternalEvt(mTask.alsHandle, SENSOR_INTERNAL_EVT_RATE_CHG, rate, latency);
524 if (mTask.alsOn || mTask.proxOn) {
530 mTask.alsOn = true;
531 mTask.lastAlsSample.idata = AMS_TMD4903_ALS_INVALID;
532 mTask.alsCalibrating = true;
533 mTask.alsOffset = 1.0f;
534 mTask.alsChangingGain = false;
535 mTask.alsSkipSample = false;
537 extiClearPendingGpio(mTask.pin);
538 enableInterrupt(mTask.pin, &mTask.isr, EXTI_TRIGGER_FALLING);
549 mTask.alsOffset = *(float*)data;
551 INFO_PRINT("Received als cfg data: %d\n", (int)mTask.alsOffset);
561 if (mTask.lastAlsSample.idata != AMS_TMD4903_ALS_INVALID) {
562 result = osEnqueuePrivateEvt(sensorGetMyEventType(SENS_TYPE_ALS), mTask.lastAlsSample.vptr, NULL, tid);
572 extiClearPendingGpio(mTask.pin);
573 enableInterrupt(mTask.pin, &mTask.isr, EXTI_TRIGGER_FALLING);
575 disableInterrupt(mTask.pin, &mTask.isr);
576 extiClearPendingGpio(mTask.pin);
579 mTask.lastProxState = PROX_STATE_INIT;
580 mTask.proxOn = on;
581 mTask.proxDirectMode = false;
583 setMode(mTask.alsOn, on, (on) ? SENSOR_STATE_ENABLING_PROX : SENSOR_STATE_DISABLING_PROX);
589 return sensorSignalInternalEvt(mTask.proxHandle, SENSOR_INTERNAL_EVT_FW_STATE_CHG, 1, 0);
599 return sensorSignalInternalEvt(mTask.proxHandle, SENSOR_INTERNAL_EVT_RATE_CHG, rate, latency);
612 if (mTask.alsOn || mTask.proxOn) {
618 mTask.lastProxState = PROX_STATE_INIT;
619 mTask.proxOn = true;
620 mTask.proxCalibrating = true;
621 mTask.proxDirectMode = false;
623 extiClearPendingGpio(mTask.pin);
624 enableInterrupt(mTask.pin, &mTask.isr, EXTI_TRIGGER_FALLING);
655 if (mTask.lastProxState != PROX_STATE_INIT) {
656 sample.fdata = (mTask.lastProxState == PROX_STATE_NEAR) ? AMS_TMD4903_REPORT_NEAR_VALUE : AMS_TMD4903_REPORT_FAR_VALUE;
714 sensorUnregister(mTask.alsHandle);
715 sensorUnregister(mTask.proxHandle);
742 nextXfer->txrxBuf[17] = mTask.alsGain; // REG_CFG1
755 if (mTask.alsOn) {
758 (int)getAlsGainFromSetting(mTask.alsGain), (int)sample.fdata);
760 if (mTask.alsCalibrating) {
763 mTask.alsOn = false;
764 mTask.alsCalibrating = false;
767 } else if (mTask.alsSkipSample) {
768 mTask.alsSkipSample = false;
769 } else if (!mTask.alsChangingGain) {
770 if (mTask.lastAlsSample.idata != sample.idata) {
772 mTask.lastAlsSample.fdata = sample.fdata;
776 DEBUG_PRINT("Changing ALS gain from %dx to %dx\n", (int)getAlsGainFromSetting(mTask.alsGain),
777 (int)getAlsGainFromSetting(mTask.nextAlsGain));
778 if (writeRegister(AMS_TMD4903_REG_CFG1, mTask.nextAlsGain,
780 mTask.alsChangingGain = true;
791 uint8_t lastProxState = mTask.lastProxState;
794 if (mTask.proxOn) {
804 mTask.lastProxState = PROX_STATE_NEAR;
807 mTask.lastProxState = PROX_STATE_FAR;
810 if (mTask.lastProxState != lastProxState)
820 if (mTask.lastProxState == PROX_STATE_FAR) {
821 disableInterrupt(mTask.pin, &mTask.isr);
822 extiClearPendingGpio(mTask.pin);
868 sensorRegisterInitComplete(mTask.alsHandle);
869 sensorRegisterInitComplete(mTask.proxHandle);
884 disableInterrupt(mTask.pin, &mTask.isr);
885 extiClearPendingGpio(mTask.pin);
887 mTask.proxOn = false;
888 mTask.proxCalibrating = false;
907 sensorSignalInternalEvt(mTask.alsHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, true, 0);
911 sensorSignalInternalEvt(mTask.proxHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, true, 0);
916 mTask.alsGain = ALS_GAIN_4X;
917 writeRegister(AMS_TMD4903_REG_CFG1, mTask.alsGain, SENSOR_STATE_DISABLING_ALS_2);
921 sensorSignalInternalEvt(mTask.alsHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, false, 0);
935 sensorSignalInternalEvt(mTask.proxHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, false, 0);
939 if (mTask.alsOn) {
940 mTask.alsChangingGain = false;
941 mTask.alsGain = mTask.nextAlsGain;
942 mTask.alsDebounceSamples = 0;
943 mTask.alsSkipSample = true;
956 if (mTask.proxOn) {
957 mTask.proxDirectMode = true;
958 extiClearPendingGpio(mTask.pin);
959 enableInterrupt(mTask.pin, &mTask.isr, EXTI_TRIGGER_BOTH);
977 mTask.tid = myTid;
978 mTask.alsOn = false;
979 mTask.proxOn = false;
980 mTask.lastAlsSample.idata = AMS_TMD4903_ALS_INVALID;
981 mTask.lastProxState = PROX_STATE_INIT;
982 mTask.proxCalibrating = false;
983 mTask.alsOffset = 1.0f;
984 mTask.alsGain = ALS_GAIN_4X;
986 mTask.pin = gpioRequest(PROX_INT_PIN);
987 gpioConfigInput(mTask.pin, GPIO_SPEED_LOW, GPIO_PULL_NONE);
988 syscfgSetExtiPort(mTask.pin);
989 mTask.isr.func = proxIsr;
991 mTask.alsHandle = sensorRegister(&sensorInfoAls, &sensorOpsAls, NULL, false);
992 mTask.proxHandle = sensorRegister(&sensorInfoProx, &sensorOpsProx, NULL, false);
1001 disableInterrupt(mTask.pin, &mTask.isr);
1002 extiUnchainIsr(PROX_IRQ, &mTask.isr);
1003 extiClearPendingGpio(mTask.pin);
1004 gpioRelease(mTask.pin);
1006 sensorUnregister(mTask.alsHandle);
1007 sensorUnregister(mTask.proxHandle);
1034 disableInterrupt(mTask.pin, &mTask.isr);
1035 extiClearPendingGpio(mTask.pin);
1049 if (mTask.proxCalibrating) {