Ejemplo n.º 1
0
void app_touch_task(void)
{
	uint16_t status_flag;
	uint16_t burst_flag;

#ifdef _DEBUG_INTERFACE_
	/* Process commands from PC */
	QDebug_ProcessCommands();
#endif

	if (time_to_measure_touch) {
		time_to_measure_touch = false;
		do {
			status_flag = qt_measure_sensors(current_time_ms_touch);
			burst_flag = status_flag & QTLIB_BURST_AGAIN;

#ifdef _DEBUG_INTERFACE_
			QDebug_SendData(status_flag);
#endif

			/*
			 * Time-critical host application code should be placed
			 *here since
			 * a full burst cycle may delay critical task in the
			 *main application
			 */
		} while (burst_flag);

#ifdef _DEBUG_INTERFACE_
		/* Process commands from PC */
		QDebug_ProcessCommands();
#endif
	}
}
Ejemplo n.º 2
0
/*============================================================================
Name    :   main
------------------------------------------------------------------------------
Purpose :   main code entry point
Input   :
Output  :
Notes   :
============================================================================*/
int main( void )
{
   /*status flags to indicate the re-burst for library*/
   uint16_t status_flag = 0u;
   uint16_t burst_flag = 0u;
#ifdef QTOUCH_STUDIO_MASKS
  SNS_array[0]=0x01;
  SNS_array[1]=0x00;
  SNSK_array[0]=0x02;
  SNSK_array[1]=0x00;
#endif

    /* initialise host app, pins, watchdog, etc */
   init_system();

   /* Configure the Sensors as keys or Keys With Rotor/Sliders in this function */
   config_sensors();

   /* initialise touch sensing */
   qt_init_sensing();

   /*  Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user */
   qt_set_parameters( );

   /* configure timer ISR to fire regularly */
   init_timer_isr();

   /*  Address to pass address of user functions   */
   /*  This function is called after the library has made capacitive measurements,
   *   but before it has processed them. The user can use this hook to apply filter
   *   functions to the measured signal values.(Possibly to fix sensor layout faults)    */
    qt_filter_callback = 0;

   /* enable interrupts */
   __enable_interrupt();

   /* loop forever */
   for( ; ; )
   {
      if( time_to_measure_touch )
      {
         /*  clear flag: it's time to measure touch  */
         time_to_measure_touch = 0u;

         do {
            /*  one time measure touch sensors    */
            status_flag = qt_measure_sensors( current_time_ms_touch );
            burst_flag = status_flag & QTLIB_BURST_AGAIN;

            /*Time critical host application code goes here*/

         }while (  burst_flag) ;
  			
      }

      /*  Time Non-critical host application code goes here  */

   }
}
Ejemplo n.º 3
0
/*============================================================================
Name    :   touch_measure
------------------------------------------------------------------------------
Purpose :   This will call all the functions for touch related measurement.
Input   :   n/a
Output  :   n/a
Notes   :
============================================================================*/
void touch_measure()
{
   /*status flags to indicate the re-burst for library*/
   static uint16_t status_flag = 0u;
   static uint16_t burst_flag = 0u;

	  if( time_to_measure_touch )
        {

            /*  clear flag: it's time to measure touch  */
            time_to_measure_touch = 0u;

            do {
				#ifdef _DEBUG_INTERFACE_
				#ifdef _QDEBUG_TIME_STAMPS_
						TIMESTAMP0;
				#endif
				#endif
                /*  one time measure touch sensors    */
                status_flag = qt_measure_sensors( current_time_ms_touch );

				#ifdef _DEBUG_INTERFACE_
				#ifdef _QDEBUG_TIME_STAMPS_
					  TIMESTAMP2;
				#endif
				#endif
                burst_flag = status_flag & QTLIB_BURST_AGAIN;
				
				if (burst_flag != QTLIB_NO_ACTIVITY)
				{
					printf("\nburst = %d", burst_flag);
				}
				
				#ifdef _DEBUG_INTERFACE_
                /* send debug data */
                QDebug_SendData(status_flag);
				/* Process commands from PC */
            	QDebug_ProcessCommands();
				#endif
				#ifdef _DEBUG_INTERFACE_
				#ifdef _QDEBUG_TIME_STAMPS_
							TIMESTAMP3;
				#endif
				#endif

                /* Time-critical host application code goes here */

            } while (burst_flag);

        }


}
Ejemplo n.º 4
0
/**
 * \brief Measure touch sensors and do appropriate action
 */
void touch_handler(void)
{
	uint16_t qt_measurement_status;

	if (time_to_measure_touch) {
		time_to_measure_touch = false;

		do {
			qt_measurement_status =
				qt_measure_sensors(current_time_ms);

#ifdef _DEBUG_INTERFACE_
			QDebug_SendData(qt_measurement_status);
#endif
		} while (qt_measurement_status & QTLIB_BURST_AGAIN);

#ifdef _DEBUG_INTERFACE_
		QDebug_ProcessCommands();
#endif

		if (qt_measure_data.qt_touch_status.sensor_states[0] & 0x01) {
			LED_On(LED1);
		}
		else {
			LED_Off(LED1);
		}

		if (qt_measure_data.qt_touch_status.sensor_states[0] & 0x02) {
			uint8_t slider_pos =
				qt_measure_data.qt_touch_status.rotor_slider_values[0];
			tc_write_rb(&AVR32_TC0, 0, (slider_pos + 1));

			LED_On(LED2);
		}
		else {
			LED_Off(LED2);
		}
	}
}
Ejemplo n.º 5
0
/**
 * \brief Check if user is pressing the touch key
 *
 * \retval true if key is pressed.
 * \retval false if key is not pressed.
 */
bool touch_key_is_pressed(void)
{
	uint16_t status_flag;
	uint16_t burst_flag;

#ifdef _DEBUG_INTERFACE_
	/* Process commands from PC */
	QDebug_ProcessCommands();
#endif

	if (time_to_measure_touch) {
		time_to_measure_touch = false;

		do {
			status_flag = qt_measure_sensors(current_time_ms_touch);
			burst_flag = status_flag & QTLIB_BURST_AGAIN;

#ifdef _DEBUG_INTERFACE_
			QDebug_SendData(status_flag);
#endif
		/* Time-critical host application code should be placed here since
		 * a full burst cycle may delay critical task in the main application
		 */

		} while (burst_flag);

#ifdef _DEBUG_INTERFACE_
		/* Process commands from PC */
		QDebug_ProcessCommands();
#endif
	}

	if (TOUCH_GET_SENSOR_STATE(0)) {
		return 0;
	} else {
		return 1;
	}
}
Ejemplo n.º 6
0
int main( void )
{
    /*status flags to indicate the re-burst for library*/
    uint16_t status_flag = 0u;
    uint16_t burst_flag = 0u;
    /* initialise host app, pins, watchdog, etc */
    init_system();

    /* Configure the Sensors as keys or Keys With Rotor/Sliders in this function */
    config_sensors();

    /* initialise touch sensing */
    qt_init_sensing();

    /*  Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user */
    qt_set_parameters( );

    /* configure timer ISR to fire regularly */
    init_timer_isr();
#ifdef _DEBUG_INTERFACE_
    timestamp1_hword = current_time_ms_touch;
    timestamp1_lword = (uint16_t)TIMER_COUNTER_L;
    timestamp1_lword |= (uint16_t)(TIMER_COUNTER_H << 8);
#endif
    /*  Address to pass address of user functions   */
    /*  This function is called after the library has made capacitive measurements,
    *   but before it has processed them. The user can use this hook to apply filter
    *   functions to the measured signal values.(Possibly to fix sensor layout faults)    */
    qt_filter_callback = 0;
#ifdef _DEBUG_INTERFACE_
		QDebug_Init();
#endif

    /* enable interrupts */
    __enable_interrupt();
#ifdef _DEBUG_INTERFACE_
  /* Process commands from PC */
    QDebug_ProcessCommands();
#endif

    /* loop forever */
   for( ; ; )
   {
      if( time_to_measure_touch )
      {
         /*  clear flag: it's time to measure touch  */
         time_to_measure_touch = 0u;

         do {
 #ifdef _DEBUG_INTERFACE_           
	 	timestamp2_hword = current_time_ms_touch;
        timestamp2_lword = (uint16_t)TIMER_COUNTER_L;
        timestamp2_lword |= (uint16_t)(TIMER_COUNTER_H << 8);
#endif
            /*  one time measure touch sensors    */
            status_flag = qt_measure_sensors( current_time_ms_touch );
 #ifdef _DEBUG_INTERFACE_
		timestamp3_hword = current_time_ms_touch;
        timestamp3_lword = (uint16_t)TIMER_COUNTER_L;
        timestamp3_lword |= (uint16_t)(TIMER_COUNTER_H << 8);
#endif
            burst_flag = status_flag & QTLIB_BURST_AGAIN;
#ifdef _DEBUG_INTERFACE_   
		/* send debug data */ 
        QDebug_SendData(status_flag);
#endif
            /*Time critical host application code goes here*/

         }while (  burst_flag) ;
      }
#ifdef _DEBUG_INTERFACE_
  			/* Process commands from PC */
            QDebug_ProcessCommands();
#endif

      /*  Time Non-critical host application code goes here  */

   }
}
Ejemplo n.º 7
0
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/*Status flags to indicate the re-burst for library */
	uint16_t status_flag = 0u;
	uint16_t burst_flag = 0u;

	/* Initialize the SAM system */
	init_system();

	/* Reset touch sensing */
	qt_reset_sensing();

	/* Configure the Sensors as keys or Keys With Rotor/Sliders in this
	   function */
	config_sensors();

	/* Initialize touch sensing */
	qt_init_sensing();

	/* Set the parameters like recalibration threshold, Max_On_Duration etc
	   in this function by the user */
	qt_set_parameters();

	/* Configure timer ISR to fire regularly */
	init_timer_isr();

	/* Address to pass address of user functions */

	/* This function is called after the library has made capacitive
	   measurements, but before it has processed them. The user can
	   use this hook to apply filter functions to the measured signal
	   values.(Possibly to fix sensor layout faults) */
	qt_filter_callback = 0;

	/* Loop forever */
	for (;;) {
		if (time_to_measure_touch) {
			/* Clear flag: it's time to measure touch */
			time_to_measure_touch = 0u;

			do {
				/*  One time measure touch sensors    */
				status_flag = qt_measure_sensors
							(current_time_ms_touch);

				burst_flag = status_flag & QTLIB_BURST_AGAIN;

				/*Time critical host application code goes here */

			} while (burst_flag);
		}

		/* Get slider value and update the blink frequency */
		if (GET_ROTOR_SLIDER_POSITION(0) != qt_shift_data) {
			qt_shift_data = GET_ROTOR_SLIDER_POSITION(0);
#ifdef QT_DATA_REVERT
			configure_tc((QT_MAX_DATA - qt_shift_data)/LED_FREQ_DIV);
#else
			configure_tc(qt_shift_data/LED_FREQ_DIV);
#endif
		}
	}
}
Ejemplo n.º 8
0
int main(void)
{
		/*Status flags to indicate the re-burst for library */
	uint16_t status_flag = 0u;
	uint16_t burst_flag = 0u;

	uint8_t lft_pressed = 0;
	uint8_t rgt_pressed = 0;

	static uint8_t old_position = 0;

	uint8_t uc_char;
	uint8_t uc_flag;
	sysclk_init();
	board_init();
	configure_buttons();
	configure_hall();

	wdt_disable(WDT);
	pmc_enable_periph_clk(ID_PIOC);
	qt_reset_sensing();
	config_sensors();
	qt_init_sensing();
	/* Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user */
	qt_set_parameters();
	init_timer_isr();
	qt_filter_callback = 0;

	configure_console();
	printf(STRING_HEADER);
	
	configure_lcd();
	g_pwm_channel = configure_pwm();

	/* Cabeçalho do lcd */
	pos_lcd_x = 20;
	pos_lcd_y = 40;
	start_lcd(pos_lcd_x, pos_lcd_y, ul_duty, hall_1, hall_2, hall_3, phase);

	/* Infinite loop */
	while (1) {
		static uint8_t phase_aux;
		static uint32_t hall_1_aux, hall_2_aux, hall_3_aux, ul_duty_aux;

		/* Atualiza o display somente quando houver alteração nas variáveis que serão apresentadas */
		
		if(ul_duty_aux != ul_duty)
		{
			escreve_int_lcd("dc = ", ul_duty*100/PERIOD_VALUE, pos_lcd_x, 40);
			ul_duty_aux = ul_duty;
		}
		
		if(phase_aux != phase || hall_1_aux != hall_1 || hall_2_aux != hall_2 || hall_3_aux != hall_3)
		{
			escreve_int_lcd("hall1 = ", hall_1, pos_lcd_x, 60);
			escreve_int_lcd("hall2 = ", hall_2, pos_lcd_x, 80);
			escreve_int_lcd("hall3 = ", hall_3, pos_lcd_x, 100);
			escreve_int_lcd("phase = ", phase, pos_lcd_x, 120);

			phase_aux = phase;
			hall_1_aux = hall_1;
			hall_2_aux = hall_2;
			hall_3_aux = hall_3;
		}
		
		if(motor_run == 0 && ul_duty != 0)
			Hall_Phase();
		
		uc_char = 0;
		uc_flag = uart_read(CONSOLE_UART, &uc_char);
		if (!uc_flag) {
			if (uc_char == 't') {
				printf("   duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE);
				printf("   hall1 = %lu \r\n", hall_1);
				printf("   hall2 = %lu \r\n", hall_2);
				printf("   hall3 = %lu \r\n", hall_3);
				printf("   phase = %u \r\n\n", phase);
			}
			if (uc_char == 'a'){				
				if(ul_duty < PERIOD_VALUE) ul_duty++;
				printf("   duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE);
			}
			if (uc_char == 's'){
				if(ul_duty > INIT_DUTY_VALUE) ul_duty--;
				printf("   duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE);
			}
			if (uc_char == 'd')
			{
				ensaio = 1;
				printf("   Ensaio de rampa\r\n");
				printf("   para parar pressione a letra 'P'\r\n");	
			}
			if (uc_char == 'f')
			{
				ensaio = 2;
				printf("   Ensaio de degrau\r\n");
				printf("   para parar pressione a letra 'P'\r\n");
			}
			if (uc_char == 'p')
			{
				ensaio = 0;
				ul_duty = 0;
			}
			if (uc_char == 'i')
			{
				sel_rot = !sel_rot;
				printf("   Rotacao invertida\r\n");
				printf("   para parar pressione a letra 'P'\r\n");
			}
		}
		
		if (time_to_measure_touch) {

			/* Clear flag: it's time to measure touch */
			time_to_measure_touch = 0u;

			do {
				/*  One time measure touch sensors    */
				status_flag = qt_measure_sensors(current_time_ms_touch);

				burst_flag = status_flag & QTLIB_BURST_AGAIN;

				/*Time critical host application code goes here */

			} while (burst_flag);
		}

		/*  Time Non-critical host application code goes here */


		if ((GET_SENSOR_STATE(BOARD_LEFT_KEY_ID) != 0)
		&& (lft_pressed == 0)) {
			lft_pressed = 1;
			if(ul_duty > INIT_DUTY_VALUE) ul_duty--;
			printf("  duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE);
			} else {
			if ((GET_SENSOR_STATE(BOARD_LEFT_KEY_ID) == 0)
			&& (lft_pressed == 1)) {
				lft_pressed = 0;
			}
		}
		if ((GET_SENSOR_STATE(BOARD_RIGHT_KEY_ID) != 0)
		&& (rgt_pressed == 0)) {
			rgt_pressed = 1;
			if(ul_duty < PERIOD_VALUE) ul_duty++;
			printf("  duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE);
			} else {
			if ((GET_SENSOR_STATE(BOARD_RIGHT_KEY_ID) == 0)
			&& (rgt_pressed == 1)) {
				rgt_pressed = 0;
			}
		}


		if (GET_ROTOR_SLIDER_POSITION(0) != old_position) {
			old_position = GET_ROTOR_SLIDER_POSITION(0);
			if (motor_run==0) flag_hab_m = 1;
			ul_duty = old_position*PERIOD_VALUE/255;
		}
	}
}
Ejemplo n.º 9
0
/**
 * \brief Main Application Code
 *  - Initialize the system clocks
 *  - Initialize the touch functions
 *  - Initialize the timer 
 *  - if debug interface is enabled, initialize the qdebug commmands
 *  - When touch status in detect, Set the led & send data to QTouch Studio
 */
int main (void)
{
	// status flags to indicate the re-burst for library
	uint16_t status_flag = 0u;
	uint16_t burst_flag = 0u;
	/**
	* \brief Initialize the system clock 
	* Clock settings are done in cof_clock.h
	* It sets the cpu to run at crystal frequency 
	* which uses OSC0 as souce
	*/
	sysclk_init(); 

	//! Initializes the functions necessary for QTouch
	qtouch_init();

	//! Configure the timer ISR to fire regularly for QTouch Acquisition
	init_timer_isr();


	//! Address to pass address of user functions 
	/** 
	* \brief This function is called after the library has made 
	* capacitive measurements, but before it has processed them. 
	* The user can use this hook to apply filter functions to the measured 
	* signal values.(Possibly to fix sensor layout faults) 
	*/
    qt_filter_callback = 0;

#ifdef _DEBUG_INTERFACE_
	// Initialize QDebug protocol
	QDebug_Init();
#endif

	// Enable global interrupts
	cpu_irq_enable();

#ifdef _DEBUG_INTERFACE_
	// Process commands from PC
	QDebug_ProcessCommands();
#endif

	// loop forever 
	for( ; ; ) {
		if( time_to_measure_touch ) {
			if( qt_measure_data.qt_touch_status.sensor_states[0]) {
				gpio_clr_gpio_pin(STATUS_LED);
			} else {
				gpio_set_gpio_pin(STATUS_LED);
			}

			// clear flag: it's time to measure touch
			time_to_measure_touch = 0u;

			do {
				// one time measure touch sensors
				status_flag = qt_measure_sensors( current_time_ms_touch );
				burst_flag = status_flag & QTLIB_BURST_AGAIN;

				/*Time critical host application code goes here*/

#ifdef _DEBUG_INTERFACE_
				// send debug data 
				QDebug_SendData(status_flag);
#endif

			} while (burst_flag) ;
#ifdef _DEBUG_INTERFACE_
			// Process commands from PC
			QDebug_ProcessCommands();
#endif
		}

	// Time Non-critical host application code goes here
	}  //end of loop forever
	
} // end of main
Ejemplo n.º 10
0
/**************************************************************************//**
*  \brief Touch task handler
******************************************************************************/
uint8_t Touch_measurement(uint8_t *button_event, uint8_t *button_state)
{
	uint8_t temp_status1;
	uint8_t temp_status2;

	uint8_t button = INVALID_KEY;
	uint8_t event = BUTTON_NO_EVENT;

	/* time_to_measure_touch = 1; //added for timing debug */

	/* After sending the data, do Touch Measurements */
	if ((time_to_measure_touch) || (burst_flag)) {
		time_to_measure_touch = 0u;

		/* Measure touch once */
		status_flag = qt_measure_sensors(current_time_ms_touch);
		burst_flag = status_flag & QTLIB_BURST_AGAIN;

		/* check whether the sensor status is changed from previous
		 * status */
		temp_status1 = memory_map.body.sensor_status[0] ^
				qt_measure_data.qt_touch_status.sensor_states[0];
		temp_status2 = memory_map.body.sensor_status[1] ^
				qt_measure_data.qt_touch_status.sensor_states[1];
		temp_status2 &= 0x03;

		/* If Sensor status is changed, do not sleep, but buzz  */
		if (temp_status1 | temp_status2) {
			event = BUTTON_PRESSED_EVENT;
			if (qt_measure_data.qt_touch_status.sensor_states[0] &
					0x01) {
				button = KEY_SW16;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x02) {
				button = KEY_SW09;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x04) {
				button = KEY_SW10;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x08) {
				button = KEY_SW17;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x10) {
				button = KEY_SW14;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x20) {
				button = KEY_SW11;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x40) {
				button = KEY_SW12;
			} else if (qt_measure_data.qt_touch_status.sensor_states
					[0] & 0x80) {
				button = KEY_SW15;
			} else {
				event = BUTTON_NO_EVENT;
			}

			if (qt_measure_data.qt_touch_status.sensor_states[1] &
					0x02) {
				button = KEY_SW13;
				event = BUTTON_PRESSED_EVENT;
#ifdef QDEBUG
				key_touch++;
#endif
			}

			if (qt_measure_data.qt_touch_status.sensor_states[1] &
					0x01) {
#ifdef QDEBUG
				wheel_pos1[wheel_index1++]
					= qt_measure_data.channel_signals
						[8];
				wheel_pos2[wheel_index2++]
					= qt_measure_data.channel_signals
						[9];
				wheel_pos3[wheel_index3++]
					= qt_measure_data.channel_signals
						[10];
				wheel_pos4[wheel_index4++]
					= qt_measure_data.channel_signals
						[11];
#endif
				if (qt_measure_data.qt_touch_status.
						rotor_slider_values[0] <
						memory_map.body.wheel_position)
				{
					button = KEY_ROT_CW;
					event = BUTTON_RELEASED_EVENT;
#ifdef QDEBUG
					rotor_up++;
#endif
				} else {
					button = KEY_ROT_CCW;
					event = BUTTON_RELEASED_EVENT;
#ifdef QDEBUG
					rotor_down++;
#endif
				}
			}

			/* Store back the current sensor status */
			temp_status1 = 0;
			temp_status2 = 0;
			memory_map.body.sensor_status[0]
				= qt_measure_data.qt_touch_status.
					sensor_states[0];
			memory_map.body.sensor_status[1]
				= qt_measure_data.qt_touch_status.
					sensor_states[1];
			memory_map.body.wheel_position
				= qt_measure_data.qt_touch_status.
					rotor_slider_values[0];

			if (event != BUTTON_NO_EVENT) {
				if (button == KEY_SW15) {
					led1_toggle();
				} else {
					led0_toggle();
				}

				*button_event = event;
				*button_state = button;
				return true;
			}

			/* Time-critical host application code goes here */
		}

		/* Non time-critical application code goes here */
	}

	return false;
}