void fill_Display(void){
	dip204_set_cursor_position(2,1);
	dip204_write_string("Control  Velocidad");
	dip204_set_cursor_position(1,2);
	dip204_write_string("Direccion:");
	dip204_set_cursor_position(1,3);
	dip204_write_string("Velocidad:");
}
void clear_Display(void){
	for (int i = 1; i<5;i++){
		for(int j = 1;j<21;j++){
			dip204_set_cursor_position(j,i);
			dip204_write_string(" ");
		}
	}
}
void set_Current(int current){
	clear_Line(4);
	//delay_ms(200);
	char number[5];
	sprintf(number,"%04d",current);
	dip204_set_cursor_position(1,4);
	dip204_write_string(number);
	
}
Exemple #4
0
void gui_display_infobox(void)
{
        int i;

#if BOARD != EVK1100
        // Draw info box
        et024006_DrawFilledRect(SCROLL_X,
                                SCROLL_Y,
                                SCROLL_W,
                                SCROLL_H,
                                infobox_contents.bg_color);

        for (i = 0; i < INFO_MAX_LINES; i++)
        {
                if (strlen(infobox_contents.lines[i]))
                {
                        int x;
                        x = 160 - ((strlen(infobox_contents.lines[i]) / 2)*10);
                        if (x < 0) x = 10;
                        et024006_PrintString(infobox_contents.lines[i],
                                             (const unsigned char*)&FONT8x8,
                                             x,
                                             (i+1)*12+SCROLL_Y,
                                             INFO_FG_COLOR,
                                             infobox_contents.bg_color);
                }
        }
        if (info_bitmap.data && info_bitmap.data_len) {
                printk("Displaying pixmap (size %d)\n", info_bitmap.data_len);
                et024006_PutPixmap( (et024006_color_t *)info_bitmap.data,
                                    info_bitmap.width, // Map width
                                    0,  // map_x
                                    0,  // map_y
                                    40, // x
                                    40, // y
                                    info_bitmap.width, // width
                                    info_bitmap.height); // height
        }
        else {
                printk("Not displaying picture\n");
        }
#else
        dip204_clear_display();
        for (i = 0; i < INFO_MAX_LINES; i++)
        {
                int len = strlen(infobox_contents.lines[i]);
                int col = (MAX_LINE_LEN/2) - (len/2);
                if ( col <= 0) col = 1;
                dip204_set_cursor_position(col,i+1); /* col,line */
                dip204_write_string(infobox_contents.lines[i]);
                dip204_hide_cursor();
        }
#endif
}
Exemple #5
0
static void gs_button_4()
{
        /* enter */

        char chr;

        if (get_string_data.row == GS_MAX_ROWS)
        {
                /* Edit function row */
                if (get_string_data.col == 0) /* back */
                {
                        get_string_data.ready = true;
                        get_string_data.escape = true;
                }
                else if (get_string_data.col == 1) /* delete */
                {
                        gs_idx--;
                        if (gs_idx < 0) gs_idx = 0;
                        getstring[gs_idx] = 0;
                        gui_set_title(getstring, 1);
                }
                else if (get_string_data.col == 2) /* accept */
                {
                        get_string_data.ready = true;
                        get_string_data.escape = false;
                }
        }
        else
        {
                /* add current char */
                chr = char_array[get_string_data.row][get_string_data.col];
                getstring[gs_idx] = chr;
                gs_idx++;
                if (gs_idx > sizeof getstring) {
                        gs_idx = sizeof getstring;
                }
                getstring[gs_idx] = 0;
        }
#if BOARD == EVK1100
        dip204_set_cursor_position(1,1); /* col,line */
        dip204_write_string(getstring);
        dip204_set_cursor_position(get_string_data.col + 1 - get_string_data.colstart,
                                   get_string_data.row + 2 - get_string_data.rowstart); /* col,line */
#else
        gui_set_title(getstring, 1);
#endif
        mod = true;
}
Exemple #6
0
__interrupt
#endif
static void dip204_example_Joy_int_handler(void)
{
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP))
  {
    dip204_set_cursor_position(19,1);
    dip204_write_data(0xDE);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN))
  {
    dip204_set_cursor_position(19,3);
    dip204_write_data(0xE0);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_LEFT))
  {
    dip204_set_cursor_position(18,2);
    dip204_write_data(0xE1);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT))
  {
    dip204_set_cursor_position(20,2);
    dip204_write_data(0xDF);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_PUSH))
  {
    dip204_set_cursor_position(19,2);
    dip204_write_data(0xBB);
    dip204_set_cursor_position(1,4);
    dip204_write_string("  AT32UC3A Series   ");
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
  }
}
Exemple #7
0
__interrupt
#endif
static void dip204_example_PB_int_handler(void)
{
unsigned short i;

  /* display all available chars */
  if (gpio_get_pin_interrupt_flag(GPIO_CHARSET))
  {
    /* go to first column of 4th line */
    dip204_set_cursor_position(1,4);
    /* display 20 chars of charmap */
    for (i = current_char; i < current_char + 0x10; i++)
    {
      dip204_write_data(i);
    }
    dip204_write_string("    ");
    /* mark position in charmap */
    current_char = i;
    /* reset marker */
    if (current_char >= 0xFF)
    {
      current_char = 0x10;
    }
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_CHARSET);
  }
  /* increase backlight power */
  if (gpio_get_pin_interrupt_flag(GPIO_BACKLIGHT_PLUS))
  {
    dip204_set_backlight(backlight_power_increase);
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_BACKLIGHT_PLUS);
  }
  /* decrease backlight power */
  if (gpio_get_pin_interrupt_flag(GPIO_BACKLIGHT_MINUS))
  {
    dip204_set_backlight(backlight_power_decrease);
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_BACKLIGHT_MINUS);
  }
}
//Initialize LCD display
void init_disp (void)
{
	static const gpio_map_t DIP204_SPI_GPIO_MAP =
	{
		{DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
		{DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
		{DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
		{DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
	};
	

	// add the spi options driver structure for the LCD DIP204
	spi_options_t spiOptions =
	{
		.reg          = DIP204_SPI_NPCS,
		.baudrate     = 1000000,
		.bits         = 8,
		.spck_delay   = 0,
		.trans_delay  = 0,
		.stay_act     = 1,
		.spi_mode     = 0,
		.modfdis      = 1
	};

	// Assign I/Os to SPI
	gpio_enable_module(DIP204_SPI_GPIO_MAP,
	sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));

	// Initialize as master
	spi_initMaster(DIP204_SPI, &spiOptions);

	// Set selection mode: variable_ps, pcs_decode, delay
	spi_selectionMode(DIP204_SPI, 0, 0, 0);

	// Enable SPI
	spi_enable(DIP204_SPI);

	// setup chip registers
	spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);
	
	// initialize LCD
	dip204_init(backlight_IO, true);
	
	dip204_hide_cursor();
}


int main (void)
{		
	// Switch the CPU main clock to oscillator 0
	pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);	
	
	board_init();
	init_disp(); 


	U32 x = 12345678;
	U32 y = 87654321;
	U64 z =0;
	
	F32 a = 1234.5678;
	F32 b = 8765.4321;
	F32 c = 0;
	
	U32 calc_time_z = 0;
	U32 calc_time_c = 0;
	
	U32 cnt_1 = 0;
	U32 cnt_2 = 0;
	U32 cnt_3 = 0;
	U32 cnt_res_z = 0; 
	U32 cnt_res_c = 0; 
	
	char cycl_str_z[9];
	char cycl_str_c[9];
	char result[19];	
	char cycl_c[9];
	char cycl_z[9];
	
	//Calculation:
	
	//Cycle count 1
	cnt_1 = Get_sys_count();
	
	//Calculation part 1:
	z = x*y;
	
	//Cycle count 2
	cnt_2 = Get_sys_count();
	
	//Calculation part 2:
	c = a*b;
	
	//Cycle count 3
	cnt_3 = Get_sys_count();
	
	//Cycle count result
	cnt_res_z = cnt_2 - cnt_1 ;
	cnt_res_c = cnt_3 - cnt_2 ;
	
	//Use cycle count result to find calculation time
	calc_time_c = (cnt_res_c * 1000000 + FOSC0 - 1) / FOSC0;
	calc_time_z = (cnt_res_z * 1000000 + FOSC0 - 1) / FOSC0;
	
	//Compose strings for display output
	sprintf(result, "%f", c);
	sprintf(cycl_str_z, "%lu", calc_time_z);
	sprintf(cycl_str_c, "%lu", calc_time_c);
	sprintf(cycl_c, "%lu", cnt_res_c);
	sprintf(cycl_z, "%lu", cnt_res_z);
	
	//Display calculation time, cycles and multiplication result on monitor
	dip204_clear_display();

	dip204_set_cursor_position(1,1);
	dip204_write_string("x*y=z");
	dip204_set_cursor_position(1,2);
	dip204_write_string("Time:");
	dip204_set_cursor_position(7,2);
	dip204_write_string(cycl_str_z);
	dip204_set_cursor_position(1,3);
	dip204_write_string("Cycles:");
	dip204_set_cursor_position(9,3);
	dip204_write_string(cycl_z);

	dip204_set_cursor_position(11,1);
	dip204_write_string("a*b=c");
	dip204_set_cursor_position(11,2);
	dip204_write_string("Time:");
	dip204_set_cursor_position(17,2);
	dip204_write_string(cycl_str_c);
	dip204_set_cursor_position(11,3);
	dip204_write_string("Cycles:");
	dip204_set_cursor_position(19,3);
	dip204_write_string(cycl_c);

	while (1)
	{
		
	}
} 
int main(void)
{



	//-------------------------USART INTERRUPT REGISTRATION.------------//
	// Set Clock: Oscillator needs to initialized once: First
		 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

		 // --------------		USART INIT		-----------------------------------------------
		 static const gpio_map_t USART_GPIO_MAP =
		  {
			{AVR32_USART0_RXD_0_0_PIN, AVR32_USART0_RXD_0_0_FUNCTION},
			{AVR32_USART0_TXD_0_0_PIN, AVR32_USART0_TXD_0_0_FUNCTION}
		  };

		  // USART options.
		  static const usart_options_t USART_OPTIONS =
		  {
			.baudrate     = USART_BAUDRATE,
			.charlength   = 8,
			.paritytype   = USART_NO_PARITY,
			.stopbits     = USART_1_STOPBIT,
			.channelmode  = USART_NORMAL_CHMODE
		  };

		// Assign GPIO to USART
		gpio_enable_module(USART_GPIO_MAP, sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

		// Init USART
		usart_init_rs232(USART_0, &USART_OPTIONS, FOSC0);

		Disable_global_interrupt();
		INTC_init_interrupts();			// Init Interrupt Table: Once at first

		// Register USART Interrupt (hinzufügen)
		INTC_register_interrupt(&usart_int_handler, AVR32_USART0_IRQ, AVR32_INTC_INT0);

		USART_0->ier = AVR32_USART_IER_RXRDY_MASK; // Activate ISR on RX Line
		Enable_global_interrupt();
	// -----------------------------------------------------------------------------------

		// --------------------------		Display INIT		----------------------------------
			// Map SPI Pins
			static const gpio_map_t DIP204_SPI_GPIO_MAP =
			  {
				{DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
				{DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
				{DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
				{DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
			  };

			// add the spi options driver structure for the LCD DIP204
			  spi_options_t spiOptions =
			  {
				.reg          = DIP204_SPI_NPCS,
				.baudrate     = 1000000,
				.bits         = 8,
				.spck_delay   = 0,
				.trans_delay  = 0,
				.stay_act     = 1,
				.spi_mode     = 0,
				.modfdis      = 1
			  };


			// SPI Inits: Assign I/Os to SPI
			gpio_enable_module(DIP204_SPI_GPIO_MAP,
			                     sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));

			// Initialize as master
			spi_initMaster(DIP204_SPI, &spiOptions);

			// Set selection mode: variable_ps, pcs_decode, delay
			spi_selectionMode(DIP204_SPI, 0, 0, 0);

			// Enable SPI
			spi_enable(DIP204_SPI);

			// setup chip registers
			spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);

			// initialize delay driver: Muss vor dip204_init() ausgeführt werden
			delay_init( FOSC0 );

			// initialize LCD
			dip204_init(backlight_PWM, TRUE);
			// ---------------------------------------------------------------------------------------

			// -----------------			Timer Counter Init		---------------------------------
				// Timer Configs:  Options for waveform generation.
				static const tc_waveform_opt_t WAVEFORM_OPT =
				{
				.channel  = TC_CHANNEL,                        // Channel selection.

				.bswtrg   = TC_EVT_EFFECT_NOOP,                // Software trigger effect on TIOB.
				.beevt    = TC_EVT_EFFECT_NOOP,                // External event effect on TIOB.
				.bcpc     = TC_EVT_EFFECT_NOOP,                // RC compare effect on TIOB.
				.bcpb     = TC_EVT_EFFECT_NOOP,                // RB compare effect on TIOB.

				.aswtrg   = TC_EVT_EFFECT_NOOP,                // Software trigger effect on TIOA.
				.aeevt    = TC_EVT_EFFECT_NOOP,                // External event effect on TIOA.
				.acpc     = TC_EVT_EFFECT_NOOP,                // RC compare effect on TIOA: toggle.
				.acpa     = TC_EVT_EFFECT_NOOP,                // RA compare effect on TIOA: toggle

				.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,//  Count till RC and reset (S. 649): Waveform selection
				.enetrg   = FALSE,                             // External event trigger enable.
				.eevt     = 0,                                 // External event selection.
				.eevtedg  = TC_SEL_NO_EDGE,                    // External event edge selection.
				.cpcdis   = FALSE,                             // Counter disable when RC compare.
				.cpcstop  = FALSE,                             // Counter clock stopped with RC compare.

				.burst    = FALSE,                             // Burst signal selection.
				.clki     = FALSE,                             // Clock inversion.
				.tcclks   = TC_CLOCK_SOURCE_TC3                // Internal source clock 3, connected to fPBA / 8.
				};


				// TC Interrupt Enable Register
				static const tc_interrupt_t TC_INTERRUPT =
				{ .etrgs = 0, .ldrbs = 0, .ldras = 0, .cpcs  = 1, .cpbs  = 0, .cpas  = 0, .lovrs = 0, .covfs = 0
				};
				// 0 = No Effect | 1 = Enable ( CPCS = 1 enables the RC Compare Interrupt )

				// *****************   Timer Setup ***********************************************
				// Initialize the timer/counter.
				tc_init_waveform(tc, &WAVEFORM_OPT);         // Initialize the timer/counter waveform.

				// Set the compare triggers.
				tc_write_rc(tc, TC_CHANNEL, RC); // Set RC value.

				tc_configure_interrupts(tc, TC_CHANNEL, &TC_INTERRUPT);

				// Start the timer/counter.
				tc_start(tc, TC_CHANNEL);                    // And start the timer/counter.
				// *******************************************************************************

				Disable_global_interrupt();
				// Register TC Interrupt
				INTC_register_interrupt(&tc_irq, AVR32_TC_IRQ0, AVR32_INTC_INT3);

				Enable_global_interrupt();
				// ---------------------------------------------------------------------------------------



				imu_init();

//-------------------------------TWI R/W ---------------------------------------------------



  sensorDaten imu_data = {0};
  char disp1[30], disp2[30], disp3[30], disp4[30];
  short GX,GY,GZ, AX, AY, AZ;			//shifted comlete Data
  RPY currMoveRPY;
  Quaternion currQuat;
  currQuat.q0 = 1.0;
  currQuat.q1 = 0;
  currQuat.q2 = 0;
  currQuat.q3 = 0;
  Quaternion deltaQuat;
  RotMatrix rot = {0};
  RPY reconverted;


  calibrate_all(&imu_data);


  while(1){
	  if(exe){
		  exe = false;
		  read_sensor(&imu_data);




		  AX = imu_data.acc_x + imu_data.acc_x_bias;
		  AY = imu_data.acc_y + imu_data.acc_y_bias;
		  AZ = imu_data.acc_z + imu_data.acc_z_bias;

		  GX = imu_data.gyro_x + imu_data.gyro_x_bias;
		  GY = imu_data.gyro_y + imu_data.gyro_y_bias;
		  GZ = imu_data.gyro_z + imu_data.gyro_z_bias;




		  //convert to 1G
		  float ax = (float)AX * (-4.0);
		  float ay = (float)AY * (-4.0); //wegen 2^11= 2048, /2 = 1024 entspricht 4G -> 1G = (1024/4)
		  float az = (float)AZ * (-4.0);


		  //convert to 1°/s
		  gx = ((float)GX/ 14.375); // in °/s
		  gy = ((float)GY/ 14.375);
		  gz = ((float)GZ/ 14.375);

		  //Integration over time
		  dGx = (gx*0.03);
		  dGy = (gy*0.03);
		  dGz = (gz*0.03);

		  currMoveRPY.pitch = -dGx;
		  currMoveRPY.roll = dGy;
		  currMoveRPY.yaw = dGz;


		  //aufaddieren auf den aktuellen Winkel IN GRAD
			gxDeg += dGx;
			gyDeg += dGy;
			gzDeg += dGz;


			//RPY in Quaternion umwandeln
			RPYtoQuat(&deltaQuat, &currMoveRPY);


			//normieren
			normQuat(&deltaQuat);


			//aufmultiplizeiren
			quatMultiplication(&deltaQuat, &currQuat, &currQuat);



			//nochmal normieren
			normQuat(&currQuat);

			//rücktransformation nicht nötig!!


			char send[80];
			sprintf(send,"$,%f,%f,%f,%f,#", currQuat.q0, currQuat.q1, currQuat.q2, currQuat.q3);
		 	usart_write_line(USART_0,send);



		   sprintf(disp1,"q0:%.3f, GX:%3.0f",currQuat.q0,gxDeg);
		   sprintf(disp2,"q1:%.3f, GY:%3.0f",currQuat.q1, gyDeg);
		   sprintf(disp3,"q2:%.3f, GZ:%3.0f",currQuat.q2, gzDeg);
		   sprintf(disp4,"q3:%.3f",currQuat.q3);



		   dip204_clear_display();

		   dip204_set_cursor_position(1,1);
		   dip204_write_string(disp1);
		   dip204_set_cursor_position(1,2);
		   dip204_write_string(disp2);
		   dip204_set_cursor_position(1,3);
		   dip204_write_string(disp3);
		   dip204_set_cursor_position(1,4);
		   dip204_write_string(disp4);











			//sprintf(data,"TEST:%s",high);
		   //print_dbg(data);
	  }

  }
}
void init_LCD(void){
	 static const gpio_map_t DIP204_SPI_GPIO_MAP =
	 {
		 {DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
		 {DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
		 {DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
		 {DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
	 };
	 spi_options_t spiOptions =
	 {
		 .reg          = DIP204_SPI_NPCS,
		 .baudrate     = 1000000,
		 .bits         = 8,
		 .spck_delay   = 0,
		 .trans_delay  = 0,
		 .stay_act     = 1,
		 .spi_mode     = 0,
		 .modfdis      = 1
	 };
	 gpio_enable_module(DIP204_SPI_GPIO_MAP,
	 sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));
	  spi_initMaster(DIP204_SPI, &spiOptions);
	  spi_selectionMode(DIP204_SPI, 0, 0, 0);
	  spi_enable(DIP204_SPI);
	  spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);
	  dip204_init(backlight_PWM, true);
	  clear_Display();
	  dip204_hide_cursor();
}
void init_Potentiometer(void){
	const gpio_map_t ADC_GPIO_MAP = {
		{EXAMPLE_ADC_POTENTIOMETER_PIN, EXAMPLE_ADC_POTENTIOMETER_FUNCTION}
	};
	gpio_enable_module(ADC_GPIO_MAP, sizeof(ADC_GPIO_MAP) /
	sizeof(ADC_GPIO_MAP[0]));
	AVR32_ADC.mr |= 0x1 << AVR32_ADC_MR_PRESCAL_OFFSET;
	adc_configure(&AVR32_ADC);
	adc_enable(&AVR32_ADC, EXAMPLE_ADC_POTENTIOMETER_CHANNEL);
	adc_start(&AVR32_ADC);
}
void init_CurrentSensor(void){
	#define AVR32_ADC_AD_1_PIN 22
	const gpio_map_t ADC_GPIO_MAP = {
		{AVR32_ADC_AD_3_PIN, AVR32_ADC_AD_3_FUNCTION}
	};
	gpio_enable_module(ADC_GPIO_MAP, sizeof(ADC_GPIO_MAP) /
	sizeof(ADC_GPIO_MAP[0]));
	AVR32_ADC.mr |= 0x1 << AVR32_ADC_MR_PRESCAL_OFFSET;
	adc_configure(&AVR32_ADC);
	adc_enable(&AVR32_ADC, 3);
	adc_start(&AVR32_ADC);
}
void clear_Line(int line){
	for(int i = 0; i<21;i++){
		dip204_set_cursor_position(i,line);
		dip204_write_string(" ");
	}
}
void set_Direccion(int direccion){
	if(direccion == 1){
		clear_Line(2);
		dip204_set_cursor_position(1,2);
		dip204_write_string("Direccion:");
		dip204_set_cursor_position(12,2);
		dip204_write_string("Forward");
	}
	if(direccion == 0){
		clear_Line(2);
		dip204_set_cursor_position(1,2);
		dip204_write_string("Direccion:");
		dip204_set_cursor_position(12,2);
		dip204_write_string("Reverse");
	}
}
void set_Velocidad(int velocidad){
	clear_Line(3);
	dip204_set_cursor_position(1,3);
	dip204_write_string("Velocidad:");
	dip204_set_cursor_position(12,3);
	switch (velocidad){
		case 1:
			dip204_write_string("1");
			break;
		case 2:
			dip204_write_string("2");
			break;
		case 3:
			dip204_write_string("3");
			break;
		case 4:
			dip204_write_string("4");
			break;
		case 5:
			dip204_write_string("5");
			break;
		case 6:
			dip204_write_string("6");
			break;
		case 7:
			dip204_write_string("7");
			break;
		case 8:
			dip204_write_string("8");
			break;
		case 9:
			dip204_write_string("9");
			break;
		case 10:
		dip204_write_string("10");
		break;
	}//SWITCH
}
Exemple #11
0
void gui_draw(int force_draw) {
        int i;

        if (! mod) {
                return;
        }
        mod = 0;
#if BOARD != EVK1100
        // Draw title box
        et024006_DrawFilledRect(TITLE_X,
                                TITLE_Y,
                                TITLE_W,
                                TITLE_H,
                                TITLE_BG_COLOR);
        if (title_contents.title[0][0]) {
                et024006_PrintString(title_contents.title[0],
                                     (const unsigned char*)&FONT8x8,
                                     TITLE_X + 10,
                                     TITLE_Y + 5,
                                     TITLE_FG_COLOR,
                                     TITLE_BG_COLOR);
                et024006_PrintString(title_contents.title[1],
                                     (const unsigned char*)&FONT8x8,
                                     TITLE_X + 10,
                                     TITLE_Y + 5 + 12,
                                     TITLE_FG_COLOR,
                                     TITLE_BG_COLOR);
                et024006_PrintString(title_contents.title[2],
                                     (const unsigned char*)&FONT8x8,
                                     TITLE_X + 10,
                                     TITLE_Y + 5 + 12 + 12,
                                     TITLE_FG_COLOR,
                                     TITLE_BG_COLOR);

        }


        // Draw scroll box
        et024006_DrawFilledRect(SCROLL_X,
                                SCROLL_Y,
                                SCROLL_W,
                                SCROLL_H,
                                scroll_box_contents.bg_color);

#endif
        switch (display_mode)
        {
        case GUI_INFOBOX:
                gui_display_infobox();
                break;

        case GUI_GETSTRING:
                gui_display_getstring();
                break;

        case GUI_LIST:
        {
#if BOARD == EVK1100
                dip204_clear_display();
#endif
                for (i = 0; i <= SCROLL_DISP_LINES; i++)
                {

#if BOARD == EVK1100

                        dip204_set_cursor_position(1,i+1); /* col,line */

                        dip204_write_string(scroll_box_contents.lines[i+scroll_box_contents.dispstart]);

#else

                        if ((scroll_box_contents.cursor == i + scroll_box_contents.dispstart) &&
                            scroll_box_contents.cursor != 0)
                        {
                                /* Print cursor line. */
                                et024006_PrintString(scroll_box_contents.lines[i+scroll_box_contents.dispstart],
                                                     (const unsigned char*)&FONT8x8,
                                                     SCROLL_X + 10,
                                                     (i+1)*12+SCROLL_Y,
                                                     scroll_box_contents.bg_color,
                                                     CURSOR_BG_COLOR);
                        }
                        else
                        {
                                et024006_PrintString(scroll_box_contents.lines[i+scroll_box_contents.dispstart],
                                                     (const unsigned char*)&FONT8x8,
                                                     SCROLL_X + 10,
                                                     (i+1)*12+SCROLL_Y,
                                                     SCROLL_FG_COLOR,
                                                     scroll_box_contents.bg_color);
                        }
#endif
                }
#if BOARD == EVK1100
                dip204_set_cursor_position(1, scroll_box_contents.cursor - scroll_box_contents.dispstart+1);
                dip204_show_cursor();
#endif
        }
        } /* switch */
        // Draw buttons
#if BOARD != EVK1100
        et024006_DrawFilledRect(BUTTON_X,
                                BUTTON_Y,
                                BUTTON_W,
                                BUTTON_H,
                                BUTTON_BG_COLOR);
        for (i = 0; i < NUM_BUTTONS-1; i++) {
                et024006_DrawVertLine(i*BUTTON_W/NUM_BUTTONS,
                                      BUTTON_Y,
                                      BUTTON_H,
                                      BUTTON_FG_COLOR);
                // Display button labels
                if (button_contents.labels[i]) {
                        et024006_PrintString(button_contents.labels[i],
                                             (const unsigned char*)&FONT8x8,
                                             i*BUTTON_W/NUM_BUTTONS + 5,
                                             BUTTON_Y + 10,
                                             BUTTON_FG_COLOR,
                                             BUTTON_BG_COLOR);
                }
        }
#endif
}
Exemple #12
0
static void qt60168_resources_init(const pm_freq_param_t *pm_freq_param)
{
        static const gpio_map_t QT60168_SPI_GPIO_MAP =
                {
                        {QT60168_SPI_SCK_PIN,          QT60168_SPI_SCK_FUNCTION         },  // SPI Clock.
                        {QT60168_SPI_MISO_PIN,         QT60168_SPI_MISO_FUNCTION        },  // MISO.
                        {QT60168_SPI_MOSI_PIN,         QT60168_SPI_MOSI_FUNCTION        },  // MOSI.
                        {QT60168_SPI_NPCS0_PIN,        QT60168_SPI_NPCS0_FUNCTION}  // Chip Select NPCS.
                };

        // SPI options.
        spi_options_t spiOptions =
                {
                        .reg          = QT60168_SPI_NCPS,
                        .baudrate     = QT60168_SPI_MASTER_SPEED, // Defined in conf_qt60168.h.
                        .bits         = QT60168_SPI_BITS,         // Defined in conf_qt60168.h.
                        .spck_delay   = 0,
                        .trans_delay  = 0,
                        .stay_act     = 0,
                        .spi_mode     = 3,
                        .modfdis      = 1
                };

        // Assign I/Os to SPI.
        gpio_enable_module(QT60168_SPI_GPIO_MAP,
                           sizeof(QT60168_SPI_GPIO_MAP) / sizeof(QT60168_SPI_GPIO_MAP[0]));
#if EXT_BOARD != SPB105
        // Initialize as master.
        spi_initMaster(QT60168_SPI, &spiOptions);

        // Set selection mode: variable_ps, pcs_decode, delay.
        spi_selectionMode(QT60168_SPI, 0, 0, 0);

        // Enable SPI.
        spi_enable(QT60168_SPI);
#endif

        // Initialize QT60168 with SPI clock Osc0.
        spi_setupChipReg(QT60168_SPI, &spiOptions, pm_freq_param->cpu_f);
}
#endif



void gui_init(const pm_freq_param_t *pm_freq_param) {
#if BOARD == EVK1100
        static const gpio_map_t DIP204_SPI_GPIO_MAP =
                {
                        {DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
                        {DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
                        {DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
                        {DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
                };
        spi_options_t spiOptions =
                {
                        .reg          = DIP204_SPI_NPCS,
                        .baudrate     = 1000000,
                        .bits         = 8,
                        .spck_delay   = 0,
                        .trans_delay  = 0,
                        .stay_act     = 1,
                        .spi_mode     = 3,
                        .modfdis      = 1
                };
#endif

        memset(&scroll_box_contents, 0, sizeof scroll_box_contents);
        memset(&title_contents, 0, sizeof title_contents);
        memset(&button_contents, 0, sizeof button_contents);
        memset(&infobox_contents, 0, sizeof infobox_contents);
        memset(&info_bitmap, 0, sizeof info_bitmap);
#if BOARD == EVK1104
        // Init touch sensor resources: GPIO, SPI and QT60168.
        qt60168_resources_init(pm_freq_param);
        // Initialize QT60168 component.
        qt60168_init(pm_freq_param->cpu_f);
#endif
#if BOARD == EVK1100
        // Assign I/Os to SPI
        gpio_enable_module(DIP204_SPI_GPIO_MAP,
                           sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));
#if 0
        // Initialize as master
        spi_initMaster(DIP204_SPI, &spiOptions);

        // Set selection mode: variable_ps, pcs_decode, delay
        spi_selectionMode(DIP204_SPI, 0, 0, 0);

        // Enable SPI
        spi_enable(DIP204_SPI);
#endif
        // setup chip registers
        spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);

        // initialize LCD
        dip204_init(backlight_PWM, true);
        dip204_set_cursor_position(1,1);
        dip204_write_string("http server demo!");
#else
        // Init display
        et024006_Init(  pm_freq_param->cpu_f, pm_freq_param->cpu_f /*HSB*/);
        // Turn on the display backlight
        gpio_set_gpio_pin(ET024006DHU_BL_PIN);
#endif
        mod = 1;
}


void gui_set_title(const char *str, unsigned char line)
{
        int len;

        Assert(line < 3);

        memset(&title_contents.title[line], 0, sizeof title_contents.title[0]);
        len = strlen(str);

        if (len >= sizeof title_contents.title[0]) {
                len = sizeof title_contents.title[0] - 1;
        }
        strncpy(title_contents.title[line], str, len);

        mod = 1;
}

int gui_set_button(short id, const char *label, size_t len, button_cb_t cb)
{

        if (id >= NUM_BUTTONS) {
                return 0;
        }
        if (len >= sizeof button_contents.labels[id]) {
                len = sizeof button_contents.labels[id] - 1;
        }
        button_contents.cbs[id] = cb;
        strncpy(button_contents.labels[id], label, len);
        mod = 1;

        return 1;
}

void gui_clear_scroll_box(void)
{

        memset(&scroll_box_contents, 0, sizeof scroll_box_contents);
        scroll_box_contents.dispstart = 0;
}
Exemple #13
0
void gui_display_getstring(void)
{
        int j;
        int i;
#if BOARD != EVK1100
        int fg_color, bg_color;
#endif
        char str[22];

#if BOARD == EVK1100
        if (redisplay) {
                dip204_clear_display();
                for (j = 0; j <= SCROLL_DISP_LINES; j++) {
                        strncpy(str, &(char_array[get_string_data.rowstart+j][get_string_data.colstart]), MAX_LINE_LEN);
                        str[MAX_LINE_LEN] = '\0';
                        dip204_set_cursor_position(1,j+2); /* col,line */
                        dip204_write_string(str);
                }
        }
#else
        for (j = 0; j < GS_MAX_ROWS; j++) {
                for (i = 0; i < strlen(char_array[j]); i++) {
                        if (get_string_data.row == j && get_string_data.col == i) {
                                fg_color = CURSOR_FG_COLOR;
                                bg_color = CURSOR_BG_COLOR;
                        } else {
                                fg_color = SCROLL_FG_COLOR;
                                bg_color = SCROLL_BG_COLOR;
                        }
                        str[0] = char_array[j][i];
                        str[1] = 0;
                        et024006_PrintString(str,
                                             (const unsigned char*)&FONT8x8,
                                             (i+1)*10+SCROLL_X + 10,
                                             (j+1)*12+SCROLL_Y,
                                             fg_color,
                                             bg_color);
                }
        }
#endif

#if BOARD == EVK1100
        if (redisplay){
                if (get_string_data.rowstart == GS_MAX_ROWS - SCROLL_DISP_LINES) {
                        dip204_set_cursor_position(1,1); /* col,line */
                        dip204_write_string("                   ");
                        j = 1;
                        for (i = 0; i <  (sizeof func_row/sizeof func_row[0]); i++) {
                                dip204_set_cursor_position(j,get_string_data.rowstart + SCROLL_DISP_LINES); /* col,line */
                                dip204_write_string(func_row[i]);
                                j += strlen(func_row[i]);
                        }
                }
                redisplay = false;
        }

        dip204_set_cursor_position(1,1); /* col,line */
        dip204_write_string("                   ");
        dip204_set_cursor_position(1,1); /* col,line */
        dip204_write_string(getstring);
        if (get_string_data.row == GS_MAX_ROWS) {
                dip204_set_cursor_position(get_string_data.col * strlen(func_row[0]) + 2, GS_MAX_ROWS); /* col,line */
        } else {
                dip204_set_cursor_position(get_string_data.col + 1 - get_string_data.colstart,
                                           get_string_data.row + 2 - get_string_data.rowstart); /* col,line */
        }
        dip204_show_cursor();
#else
        j = 1;
        for (i = 0; i <  (sizeof func_row/sizeof func_row[0]); i++) {
                if (get_string_data.row == GS_MAX_ROWS && get_string_data.col == i) {
                        fg_color = CURSOR_FG_COLOR;
                        bg_color = CURSOR_BG_COLOR;
                } else {
                        fg_color = SCROLL_FG_COLOR;
                        bg_color = SCROLL_BG_COLOR;
                }
                et024006_PrintString(func_row[i],
                                     (const unsigned char*)&FONT8x8,
                                     j*10 + SCROLL_X + 10,
                                     5*12+SCROLL_Y,
                                     fg_color,
                                     bg_color);
                j += strlen(func_row[i])-1;
        }
#endif
}
Exemple #14
0
/*!
 * \brief main function : do init and loop (poll if configured so)
 */
int main(void)
{
  static const gpio_map_t DIP204_SPI_GPIO_MAP =
  {
    {DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
    {DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
    {DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
    {DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
  };

  // Switch the CPU main clock to oscillator 0
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Disable all interrupts.
  Disable_global_interrupt();

  // init the interrupts
  INTC_init_interrupts();

  // Enable all interrupts.
  Enable_global_interrupt();

  // add the spi options driver structure for the LCD DIP204
  spi_options_t spiOptions =
  {
    .reg          = DIP204_SPI_NPCS,
    .baudrate     = 1000000,
    .bits         = 8,
    .spck_delay   = 0,
    .trans_delay  = 0,
    .stay_act     = 1,
    .spi_mode     = 0,
    .modfdis      = 1
  };

  // Assign I/Os to SPI
  gpio_enable_module(DIP204_SPI_GPIO_MAP,
                     sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));

  // Initialize as master
  spi_initMaster(DIP204_SPI, &spiOptions);

  // Set selection mode: variable_ps, pcs_decode, delay
  spi_selectionMode(DIP204_SPI, 0, 0, 0);

  // Enable SPI
  spi_enable(DIP204_SPI);

  // setup chip registers
  spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);

  // configure local push buttons
  dip204_example_configure_push_buttons_IT();

  // configure local joystick
  dip204_example_configure_joystick_IT();

  // initialize LCD
  dip204_init(backlight_PWM, true);

  // reset marker
  current_char = 0x10;

  // Display default message.
  dip204_set_cursor_position(8,1);
  dip204_write_string("ATMEL");
  dip204_set_cursor_position(7,2);
  dip204_write_string("EVK1100");
  dip204_set_cursor_position(6,3);
  dip204_write_string("AVR32 UC3");
  dip204_set_cursor_position(3,4);
  dip204_write_string("AT32UC3A Series");
  dip204_hide_cursor();

  /* do a loop */
  while (1)
  {
    if (display)
    {
      delay_ms(400);  // A delay so that it is humanly possible to see the
                      // character(s) before they are cleared.
      // Clear line 1 column 19
      dip204_set_cursor_position(19,1);
      dip204_write_string(" ");
      // Clear line 2 from column 18 to column 20.
      dip204_set_cursor_position(18,2);
      dip204_write_string("   "); // 3 spaces
      // Clear line 3 column 19
      dip204_set_cursor_position(19,3);
      dip204_write_string(" ");
      display = 0;
    }
  }
}