void TSI_Calibrate(TSI_Type *base, tsi_calibration_data_t *calBuff) { assert(calBuff != NULL); uint8_t i = 0U; bool is_int_enabled = false; if (base->GENCS & TSI_GENCS_TSIIEN_MASK) { is_int_enabled = true; TSI_DisableInterrupts(base, kTSI_GlobalInterruptEnable); } for (i = 0U; i < FSL_FEATURE_TSI_CHANNEL_COUNT; i++) { TSI_SetMeasuredChannelNumber(base, i); TSI_StartSoftwareTrigger(base); while (!(TSI_GetStatusFlags(base) & kTSI_EndOfScanFlag)) { } calBuff->calibratedData[i] = TSI_GetCounter(base); TSI_ClearStatusFlags(base, kTSI_EndOfScanFlag); } if (is_int_enabled) { TSI_EnableInterrupts(base, kTSI_GlobalInterruptEnable); } }
/* Update mouse pointer location. */ static usb_status_t USB_DeviceHidMouseAction(void) { if(Ax > SENSITIVITY) { if(xDir==1) { g_UsbDeviceHidMouse.buffer[1] = 2U; }else{ g_UsbDeviceHidMouse.buffer[1] = (uint8_t)-2U; } }else{ g_UsbDeviceHidMouse.buffer[1] = 0; } if(Ay > SENSITIVITY) { if(yDir==1) { g_UsbDeviceHidMouse.buffer[2] = 2U; }else{ g_UsbDeviceHidMouse.buffer[2] = (uint8_t)-2U; } }else{ g_UsbDeviceHidMouse.buffer[2] = 0; } TSI_EnableHardwareTriggerScan(TSI0, false); /* Enable software trigger scan */ TSI_DisableInterrupts(TSI0, kTSI_EndOfScanInterruptEnable); TSI_ClearStatusFlags(TSI0, kTSI_EndOfScanFlag); TSI_SetMeasuredChannelNumber(TSI0, BOARD_TSI_ELECTRODE_2); TSI_StartSoftwareTrigger(TSI0); while (!(TSI_GetStatusFlags(TSI0) & kTSI_EndOfScanFlag)) { } /* Left mouse button */ if(TSI_GetCounter(TSI0) > TOUCH_THRESHHOLD){ g_UsbDeviceHidMouse.buffer[0] |= 1U; }else{ g_UsbDeviceHidMouse.buffer[0] &= ~1U; } TSI_EnableHardwareTriggerScan(TSI0, false); /* Enable software trigger scan */ TSI_DisableInterrupts(TSI0, kTSI_EndOfScanInterruptEnable); TSI_ClearStatusFlags(TSI0, kTSI_EndOfScanFlag); TSI_SetMeasuredChannelNumber(TSI0, BOARD_TSI_ELECTRODE_1); TSI_StartSoftwareTrigger(TSI0); while (!(TSI_GetStatusFlags(TSI0) & kTSI_EndOfScanFlag)) { } /* Right mouse button */ if(TSI_GetCounter(TSI0) > TOUCH_THRESHHOLD){ g_UsbDeviceHidMouse.buffer[0] |= 2U; }else{ g_UsbDeviceHidMouse.buffer[0] &= ~2U; } /* Send mouse report to the host */ return USB_DeviceHidSend(g_UsbDeviceHidMouse.hidHandle, USB_HID_MOUSE_ENDPOINT_IN, g_UsbDeviceHidMouse.buffer, USB_HID_MOUSE_REPORT_LENGTH); }