/*
  * Stop measuring
  */
 void EFM32_CapSenseSlider::stop() {
     if(_running == true) {
         LESENSE_ScanStop();
         unblockSleepMode(EM2);
         _running = false;
     }
 }
Пример #2
0
/** The asynchronous IRQ handler
 *  @param obj The I2C object which holds the transfer information
 *  @return Returns event flags if a transfer termination condition was met or 0 otherwise.
 */
uint32_t i2c_irq_handler_asynch(i2c_t *obj)
{

    // For now, we are assuming a solely interrupt-driven implementation.

    I2C_TransferReturn_TypeDef status = I2C_Transfer(obj->i2c.i2c);
    switch(status) {
        case i2cTransferInProgress:
            // Still busy transferring, so let it.
            return 0;
        case i2cTransferDone:
            // Transfer has completed

            // Disable interrupt
            i2c_enable_interrupt(obj, 0, false);

            unblockSleepMode(EM1);

            return I2C_EVENT_TRANSFER_COMPLETE & obj->i2c.events;
        case i2cTransferNack:
            // A NACK has been received while an ACK was expected. This is usually because the slave did not respond to the address.
            // Disable interrupt
            i2c_enable_interrupt(obj, 0, false);

            unblockSleepMode(EM1);

            return I2C_EVENT_ERROR_NO_SLAVE & obj->i2c.events;
        default:
            // An error situation has arisen.
            // Disable interrupt
            i2c_enable_interrupt(obj, 0, false);

            unblockSleepMode(EM1);

            // return error
            return I2C_EVENT_ERROR & obj->i2c.events;
    }
}
Пример #3
0
/** Abort ongoing asynchronous transaction.
 *  @param obj The I2C object
 */
void i2c_abort_asynch(i2c_t *obj)
{
    // Do not deactivate I2C twice
    if (!i2c_active(obj)) return;

    // Disable interrupt
    i2c_enable_interrupt(obj, 0, false);

    // Abort
    obj->i2c.i2c->CMD = I2C_CMD_STOP | I2C_CMD_ABORT;

    // Block until free
    while(i2c_active(obj));

    unblockSleepMode(EM1);
}
/*
 * Function Name: ADC_setup
 * Description: Configures ADC0
 */
void LEUART_Setup(void)
{
	/* Enabling the required clocks */
	CMU_ClockEnable(cmuClock_LFB, true);           //Enable the clock input to LETIMER
	CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO); //Selecting the ULFRCO as the source clock
	CMU_ClockEnable(cmuClock_LEUART0, true);           //Enable the clock input to LETIMER
	/* Defining the LEUART1 initialization data */
		LEUART_Init_TypeDef leuart0Init =
		{
		  .enable   = leuartEnable,        // Activate data reception on LEUn_TX pin.
		  .refFreq  = 0,                   // Inherit the clock frequency from the LEUART clock source
		  .baudrate = LEUART0_BAUD,    // Baudrate = 9600 bps
		  .databits = LEUART0_Databits,    // Each LEUART frame contains 8 databits
		  .parity   = LEUART0_Parity,      // No parity bits in use
		  .stopbits = LEUART0_Stopbits,    // Setting the number of stop bits in a frame to 2 bitperiods
		};

		LEUART_Init(LEUART0, &leuart0Init);

		// Route LEUART1 TX,RX pin to DMA location 0
		LEUART0->ROUTE = LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN | LEUART_ROUTE_LOCATION_LOC0;

		// Enable GPIO for LEUART1. TX is on D4
		GPIO_PinModeSet(gpioPortD, 4, gpioModePushPull, 0);
		// Enable GPIO for LEUART1. RX is on D5
		GPIO_PinModeSet(gpioPortD, 5, gpioModeInputPull, 0);
		// Pull PD15(CTS pin of BLE module) to GRND
		GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 0);

}

/*
 *Function name: LETIMER0_IRQHandler
 *Description : Interrupt Service Routine for LETIMER.
 */
void LETIMER0_IRQHandler(void)
{
    LETIMER_IntClear(LETIMER0, LETIMER_IF_UF); //Clear LETIMER0 underflow (UF) and COMP1 flag.
    DMA_ActivateBasic(DMA_CHANNEL_ADC, true, false, (void *)ADC_Buffer, (void *)&(ADC0->SINGLEDATA), ADC_SAMPLES - 1);
    ADC_Setup();
    // ADC start
    ADC_Start(ADC0, adcStartSingle);
    unblockSleepMode(EM2);
    blockSleepMode(EM1);
    trfComplete=false;
}
Пример #5
0
void pwmout_free(pwmout_t *obj)
{
    if(pwmout_disable_channel_route(pwmout_get_channel_route(obj->channel))) {
        //Channel was previously enabled, so do housekeeping
        unblockSleepMode(EM1);
    } else {
        //This channel was disabled already
    }
    
    pwmout_enable_pins(obj, false);
    
    if(pwmout_all_inactive()) {
        //Stop timer
        PWM_TIMER->CMD = TIMER_CMD_STOP;
        while(PWM_TIMER->STATUS & TIMER_STATUS_RUNNING);
        
        //Disable clock
        CMU_ClockEnable(PWM_TIMER_CLOCK, false);
    }
}
/*
 *Function name: DMA_CallBack()
 *Description :  Call back function of the DMA
 */
void DMA_CallBack(unsigned int channel, bool primary, void *user)
{
    unblockSleepMode(EM1);
    blockSleepMode(EM2);

	if(!trfComplete)
	{
		ADC_Reset(ADC0);		// Reset the ADC; Turn it off
	    //ADC0->CMD = ADC_CMD_SINGLESTOP;

		int temp = 0, i = 0;
		    char tempChar[7];			//To store the temperature in char, for transmitting
		    char temp_string[TX_bufferSize];

		    (void) channel;
		    (void) primary;
		    (void) user;

		    for (i = 0; i < ADC_SAMPLES; i++)
		    {
		        temp += (ADC_Buffer[i]);
		    }
		    temperature = temp / ADC_SAMPLES;
		    temperature = convertToCelsius(temperature); //Get value of Temperature in deg C


		    if (temperature > HIGHTEMP)
		    {
		        //GPIO_PinOutClear(gpioPortE,2);
		        //GPIO_PinOutSet(gpioPortE,3);
		    	/* To extract the digits of the temperature variable and put in tempChar. A basic digit extraction algorithm is used and then each digit is passed one by one. */
		        temp 		= temperature*10;
				tempChar[0] = (temp/100)+48;
				temp 	    = temp%100;
				tempChar[1] = (temp/10)+48;
				temp 		= temp%10;
				tempChar[2] = '.';
				tempChar[3] = (temp)+48;
				tempChar[4] = 'C';			// Pad the 4th position of charTemp as C
				tempChar[5] = '\r';			// Pad carriage return
				tempChar[6] = '\n';			// Pad line feed

				strcpy(temp_string,HighTemp);					// Copy the HighTemp message in the temporary string
				strcat(temp_string,tempChar);					// Concatenate with the tempChar to get the final message

    			LEUART0->CTRL |= LEUART_CTRL_TXDMAWU;				// Enable DMA wake up for LEUART TX in EM2
    			// Activate DMA transfers for LEUART TX
		        DMA_ActivateBasic(DMA_CHANNEL_TX, true, false, (void *)&(LEUART0->TXDATA), (void *)temp_string, strlen(temp_string) - 1);

		    }
		    else if (temperature < LOWTEMP)
		    {
		        //GPIO_PinOutSet(gpioPortE,2);
		        //GPIO_PinOutClear(gpioPortE,3);

		        temp 		= temperature*10;
				tempChar[0] = (temp/100)+48;
				temp 	    = temp%100;
				tempChar[1] = (temp/10)+48;
				temp 		= temp%10;
				tempChar[2] = '.';
				tempChar[3] = (temp)+48;
				tempChar[4] = 'C';
				tempChar[5] = '\r';
				tempChar[6] = '\n';

				strcpy(temp_string,LowTemp);					// Copy the LowTemp message in the temporary string
				strcat(temp_string,tempChar);					// Concatenate with the tempChar to get the final message

				LEUART0->CTRL |= LEUART_CTRL_TXDMAWU;				// Enable DMA wake up for LEUART TX in EM2
				// Activate DMA transfers for LEUART TX
				DMA_ActivateBasic(DMA_CHANNEL_TX, true, false, (void *)&(LEUART0->TXDATA), (void *)temp_string, strlen(temp_string) -1);

		    }
		   trfComplete=true;
	}

	else
	{
		(void) channel;
		(void) primary;
		(void) user;

		// Disable DMA wake-up from LEUART1 TX
		LEUART0->CTRL &= ~LEUART_CTRL_TXDMAWU;
	}
}