示例#1
0
文件: tsi.c 项目: forbelief/KL25EM
void hw_tsi_init(uint_8 chnlID)
{
	//开启TSI时钟
	SIM_SCGC5 |= (SIM_SCGC5_TSI_MASK) | (SIM_SCGC5_PORTA_MASK);
	//通道5使能
	PORTA_PCR4 = PORT_PCR_MUX(0); 
    //配置TSI通用寄存器
	 TSI0_GENCS |= (TSI_GENCS_REFCHRG(4)
				| TSI_GENCS_DVOLT(0)
				| TSI_GENCS_EXTCHRG(6)
				| TSI_GENCS_PS(2)
				| TSI_GENCS_NSCN(11)
				| TSI_GENCS_TSIIEN_MASK
				| TSI_GENCS_STPE_MASK
	);
	 
    TSI0_GENCS &= ~TSI_GENCS_ESOR_MASK;
    TSI0_GENCS &= ~TSI_GENCS_STM_MASK;
	//清越值标志位和扫描完成位
	TSI0_GENCS |= (TSI_GENCS_OUTRGF_MASK) | (TSI_GENCS_EOSF_MASK);
	//选择通道
	TSI0_DATA |= (TSI_DATA_TSICH(chnlID)); 
	//TSI使能
	TSI0_GENCS |= (TSI_GENCS_TSIEN_MASK);
}
示例#2
0
文件: TSIDrv.c 项目: tjusyj/FRDMKL46Z
void TSI_Init (void)
{
  SIM_SCGC5 |= SIM_SCGC5_TSI_MASK;  // Enable clock gating for TSI
  
  /* Enable proper GPIO as TSI channels */
  PORTB_PCR17 =  PORT_PCR_MUX(0);   // PTA1 as TSI channel 2
  PORTB_PCR16 =  PORT_PCR_MUX(0);   // PTA2 as TSI channel 3

  enable_irq(TSI_irq_no);
  
  TSI0_GENCS |= (TSI_GENCS_ESOR_MASK
                   | TSI_GENCS_MODE(0)
                   | TSI_GENCS_REFCHRG(4)
                   | TSI_GENCS_DVOLT(0)
                   | TSI_GENCS_EXTCHRG(7)  
                   | TSI_GENCS_PS(4)
                   | TSI_GENCS_NSCN(11)
                   | TSI_GENCS_TSIIEN_MASK 
                   | TSI_GENCS_STPE_MASK
                   //| TSI_GENCS_STM_MASK     //Trigger for the module 0=Sofware 
                   );
  
  TSI0_GENCS |= TSI_GENCS_TSIEN_MASK; 
  
  TSI_SelfCalibration();
}
示例#3
0
static  void  BSP_TSI_Init (void)
{
    BSP_TSI_Slider.EndFlg = DEF_FALSE;                          /* Initialize global variables.                         */

    BSP_TSI_Slider.Electrodes[0].PinNbr    = BSP_TSI_PIN9;
    BSP_TSI_Slider.Electrodes[1].PinNbr    = BSP_TSI_PIN10;

    BSP_TSI_Slider.Electrodes[0].Threshold = BSP_TSI_THRESHOLD;
    BSP_TSI_Slider.Electrodes[1].Threshold = BSP_TSI_THRESHOLD;

    SIM_SCGC5   |= SIM_SCGC5_TSI_MASK;                          /* Enable clock gating for TSI.                         */

                                                                /* Enable proper GPIO as TSI channels.                  */
    PORTB_PCR16  = PORT_PCR_MUX(0);                             /* PTB16 as TSI channel 9.                              */
    PORTB_PCR17  = PORT_PCR_MUX(0);                             /* PTB17 as TSI channel 10.                             */

    BSP_IntVectSet(BSP_INT_ID_TSI0, BSP_TSI_IntHandler);        /* Register the interrupt handler.                      */
    BSP_IntEn(BSP_INT_ID_TSI0);                                 /* Enable the TSI module interrupts.                    */

    TSI0_GENCS  |= (TSI_GENCS_ESOR_MASK
                |   TSI_GENCS_MODE(0)
                |   TSI_GENCS_REFCHRG(4)
                |   TSI_GENCS_DVOLT(0)
                |   TSI_GENCS_EXTCHRG(7)
                |   TSI_GENCS_PS(4)
                |   TSI_GENCS_NSCN(11)
                |   TSI_GENCS_TSIIEN_MASK
                |   TSI_GENCS_STPE_MASK);

    TSI0_GENCS  |=  TSI_GENCS_TSIEN_MASK;                       /* Enable the TSI module.                               */

    BSP_TSI_SelfCal();                                          /* Self calibration.                                    */
}
示例#4
0
int touchRead(uint8_t pin)
{
	uint32_t ch;

	if (pin >= NUM_DIGITAL_PINS) return 0;
	ch = pin2tsi[pin];
	if (ch == 255) return 0;

	*portConfigRegister(pin) = PORT_PCR_MUX(0);
	SIM_SCGC5 |= SIM_SCGC5_TSI;
#if defined(HAS_KINETIS_TSI)
	TSI0_GENCS = 0;
	TSI0_PEN = (1 << ch);
	TSI0_SCANC = TSI_SCANC_REFCHRG(3) | TSI_SCANC_EXTCHRG(CURRENT);
	TSI0_GENCS = TSI_GENCS_NSCN(NSCAN) | TSI_GENCS_PS(PRESCALE) | TSI_GENCS_TSIEN | TSI_GENCS_SWTS;
	delayMicroseconds(10);
	while (TSI0_GENCS & TSI_GENCS_SCNIP) ; // wait
	delayMicroseconds(1);
	return *((volatile uint16_t *)(&TSI0_CNTR1) + ch);
#elif defined(HAS_KINETIS_TSI_LITE)
	TSI0_GENCS = TSI_GENCS_REFCHRG(4) | TSI_GENCS_EXTCHRG(3) | TSI_GENCS_PS(PRESCALE)
		| TSI_GENCS_NSCN(NSCAN) | TSI_GENCS_TSIEN | TSI_GENCS_EOSF;
	TSI0_DATA = TSI_DATA_TSICH(ch) | TSI_DATA_SWTS;
	delayMicroseconds(10);
	while (TSI0_GENCS & TSI_GENCS_SCNIP) ; // wait
	delayMicroseconds(1);
	return TSI0_DATA & 0xFFFF;
#endif
}
示例#5
0
// Initialize touch input
void touchInit(uint32_t channelMask)
{
   int i;

   // Turn on clock gating for TSI and configure touch input
   clkEnable(CLK_TSI);

   TSI0_GENCS |= ( TSI_GENCS_ESOR_MASK    // Enable end of scan interrupt
                 | TSI_GENCS_MODE(0)      // Capacitive sensing
                 | TSI_GENCS_REFCHRG(4)   // Reference charge 4 uA
                 | TSI_GENCS_DVOLT(0)     // Voltage rails
                 | TSI_GENCS_EXTCHRG(7)   // External osc charge
                 | TSI_GENCS_PS(4)        // Pre-scalar divide by 4
                 | TSI_GENCS_NSCN(11)     // Scans per electrode
                 | TSI_GENCS_TSIIEN_MASK  // Input interrupt enable
                 | TSI_GENCS_STPE_MASK    // Enable in STOP mode
                 );

   TSI0_GENCS |= TSI_GENCS_TSIEN_MASK;

   // Read initial (baseline) values for each enabled channel
   sEnableMask = channelMask;
   for (i = (NUM_CHANNELS - 1); i >= 0; i--)
   {
      if ((1 << i) & sEnableMask)
      {
         scanStart(i);
         while (!(TSI0_GENCS & TSI_GENCS_EOSF_MASK)) // Wait until done
         ;

         sBaseCounts[i] = scanData();
      }
   }

   // Enable TSI interrupts and start the scan timer
   irqRegister(INT_TSI0, tsiIrqHandler, 0);
   irqEnable(INT_TSI0);

   {
      osTimerDef_t tDef;
      
      tDef.ptimer = startTimerCb;
      tDef.millisec = TOUCH_SCAN_TIME;
      tDef.name = "touch";

      sStartTimer = osTimerCreate(&tDef, osTimerPeriodic, 0);
      osTimerStart(sStartTimer, TOUCH_SCAN_TIME);
   }
}
示例#6
0
void capElectrodeWakeableSleep(int electrodeIdx)
{
    Electrode* wakeElectrode = electrodeList + electrodeIdx;

    TSI0_GENCS &= ~TSI_GENCS_TSIEN_MASK;

    isSleeping = 1;
    TSI0_TSHD = TSI_TSHD_THRESL(wakeElectrode->baseline / 2) | TSI_TSHD_THRESH(wakeElectrode->baseline + 5);
    TSI0_DATA = TSI_DATA_TSICH(wakeElectrode->channel);
    TSI0_GENCS = // Fields to clear
        TSI_GENCS_OUTRGF_MASK | TSI_GENCS_EOSF_MASK
            |
            // Fields to set: 16uA ref charge, 8uA ext charge, 0.43V DVolt, 1 scans, enable interrupt & module, enable in low power, hardware trigger
            TSI_GENCS_REFCHRG(5) | TSI_GENCS_DVOLT(2) | TSI_GENCS_EXTCHRG(4) | TSI_GENCS_STPE_MASK |
            TSI_GENCS_PS(1) | TSI_GENCS_NSCN(0) | TSI_GENCS_TSIEN_MASK | TSI_GENCS_TSIIEN_MASK | TSI_GENCS_STM_MASK;
}
示例#7
0
void capElectrodeInit()
{
#if defined(CAPELECTRODE_TIMESTAMPS)
    tpmEnableTimer(TPM_TIMER);
    tpmStartTimer(TPM_TIMER, TPM_CLOCKS_PER_MILLISECOND, 0);
#endif

    SIM_SCGC5 |= SIM_SCGC5_TSI_MASK;

    TSI0_GENCS = // Fields to clear
        TSI_GENCS_OUTRGF_MASK | TSI_GENCS_EOSF_MASK
            |
            // Fields to set: int on end scan, 16uA ref charge, 8uA ext charge, 0.43V DVolt, X scans, enable interrupt & module, enable in low power
            TSI_GENCS_ESOR_MASK | TSI_GENCS_REFCHRG(5) | TSI_GENCS_DVOLT(2) | TSI_GENCS_EXTCHRG(4) | TSI_GENCS_STPE_MASK |
            TSI_GENCS_PS(4) | TSI_GENCS_NSCN(TSI_SCAN_COUNT - 1) | TSI_GENCS_TSIEN_MASK | TSI_GENCS_TSIIEN_MASK;
}
示例#8
0
// Initialize touch input
void touch_init(uint32_t channel_mask)
{
    // Turn on clock gating for TSI and configure touch input
    SIM_SCGC5 |= SIM_SCGC5_TSI_MASK;
    TSI0_GENCS |= (TSI_GENCS_ESOR_MASK          // Enable end of scan interrupt
                   | TSI_GENCS_MODE(0)          // Capactive sensing
                   | TSI_GENCS_REFCHRG(4)       // Reference charge 4 uA
                   | TSI_GENCS_DVOLT(0)         // Voltage rails
                   | TSI_GENCS_EXTCHRG(7)       // External osc charge
                   | TSI_GENCS_PS(4)            // Prescalar divide by 4
                   | TSI_GENCS_NSCN(11)         // Scans per electrode
                   | TSI_GENCS_TSIIEN_MASK      // Input interrupt enable
                   | TSI_GENCS_STPE_MASK        // Enable in STOP mode 
                   );

    TSI0_GENCS |= TSI_GENCS_TSIEN_MASK;

    // Enable touch I/O pins for Freedom board, and configure 
    // the scan sequence
    PORTB_PCR16 = PORT_PCR_MUX(0);      // PTB16 as touch channel 9
    PORTB_PCR17 = PORT_PCR_MUX(0);      // PTB17 as touch channel 10    

    // Read initial (baseline) values for each enabled channel
    int i, first_channel = 0;
    enable_mask = channel_mask;
    for(i=15; i>=0; i--) {
        if((1 << i) & enable_mask) {
            scan_start(i);
            while(!(TSI0_GENCS & TSI_GENCS_EOSF_MASK))      // Wait until done
                ;

            base_counts[i] = scan_data();
            first_channel = i;
        }
    }
    
    // Enable TSI interrupts and start the first scan
    enable_irq(INT_TSI0);
    scan_start(first_channel);
}
示例#9
0
void TSISensor::TSISensor_reset(void) {
    SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;
    SIM->SCGC5 |= SIM_SCGC5_TSI_MASK;

    TSI0->GENCS |= (TSI_GENCS_ESOR_MASK
                   | TSI_GENCS_MODE(0)
                   | TSI_GENCS_REFCHRG(4)
                   | TSI_GENCS_DVOLT(0)
                   | TSI_GENCS_EXTCHRG(7)
                   | TSI_GENCS_PS(4)
                   | TSI_GENCS_NSCN(11)
                   | TSI_GENCS_TSIIEN_MASK
                   | TSI_GENCS_STPE_MASK
                   );

    TSI0->GENCS |= TSI_GENCS_TSIEN_MASK;

    //NVIC_SetVector(TSI0_IRQn, (uint32_t)&tsi_irq);
    //NVIC_EnableIRQ(TSI0_IRQn);

    selfCalibration();
}
示例#10
0
/*******************************************************************
 * TSI module initialization.
 */
void TSI_Init (void)
{
    SIM_SCGC5 |= SIM_SCGC5_TSI_MASK; // Enable clock gating for TSI

    /* Enable proper GPIO as TSI channels */
    PORTA_PCR13 = PORT_PCR_MUX(0);   // PTB16 as TSI channel 9
    PORTB_PCR12 = PORT_PCR_MUX(0);   // PTB17 as TSI channel 8
    enable_irq(INT_TSI0-16);
    TSI0_GENCS |= (TSI_GENCS_ESOR_MASK
                   | TSI_GENCS_MODE(0)
                   | TSI_GENCS_REFCHRG(4)
                   | TSI_GENCS_DVOLT(0)
                   | TSI_GENCS_EXTCHRG(7)  
                   | TSI_GENCS_PS(4)
                   | TSI_GENCS_NSCN(11)
                   | TSI_GENCS_TSIIEN_MASK
                   | TSI_GENCS_STPE_MASK
                   //| TSI_GENCS_STM_MASK     //Trigger for the module 0=Sofware 
                   );

    TSI0_GENCS |= TSI_GENCS_TSIEN_MASK; //Enable TSI module.
    TSI_SelfCalibration();
}