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 }
//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) { } }
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 }
/*! * \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; } } }