00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include "usb_drv.h"
00051 #include "board.h"
00052 #include "gpio.h"
00053 #include "et024006dhu.h"
00054 #include "cycle_counter.h"
00055 #include "avr32_logo.h"
00056 #include "ms_key_logo.h"
00057 #include "main.h"
00058 #include "sd_mmc_mci.h"
00059 #include <stdio.h>
00060
00061
00062
00063
00064
00065
00066
00067 typedef enum {
00068 MMI_IDLE =0
00069 , MMI_TOP_MENU
00070 , MMI_TOP_MENU_START
00071 , MMI_MASS_STORAGE_START
00072 , MMI_MASS_STORAGE
00073 }s_mmi_state;
00074 s_mmi_state mmi_state;
00075
00076
00077
00078
00079
00084 void mmi_task_init(U32 cpu_f, U32 pba_f)
00085 {
00086
00087 et024006_Init( cpu_f, cpu_f );
00088
00089
00090 et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, BLACK );
00091
00092
00093 gpio_set_gpio_pin(ET024006DHU_BL_PIN);
00094
00095 mmi_state = MMI_TOP_MENU_START;
00096 }
00097
00098
00099 #define TIMER_MS_PROGRESS_BAR_UPDATE 555 // Unit is in ms.
00100 #define TIMER_MS_PROGRESS_BAR_CLEAR 220 // Unit is in ms.
00101 #define MS_N_PROGRESS_BAR 8 // Number of bars.
00102 t_cpu_time ms_activity_timer;
00103 t_cpu_time ms_clear_timer;
00104 volatile U32 ms_cnt_read;
00105 volatile U32 ms_cnt_write;
00106 U32 ms_old_cnt_read;
00107 U32 ms_old_cnt_write;
00108 U8 ms_cnt_screen;
00109 U8 ms_progress_bar_level[MS_N_PROGRESS_BAR];
00110 U16 ms_progress_bar_type[ MS_N_PROGRESS_BAR];
00111 U32 perf_write;
00112 U32 perf_read;
00113 char string[64];
00114
00115 static void display_box( U32 x, U32 y, U32 size_x, U32 size_y, U16 color, U16 edge_color )
00116 {
00117 et024006_DrawFilledRect(x, y, size_x, size_y, color);
00118 et024006_DrawHorizLine(x, y, size_x, edge_color);
00119 et024006_DrawVertLine(x+size_x-1, y, size_y, edge_color);
00120 et024006_DrawHorizLine(x, y+size_y-1, size_x, edge_color);
00121 et024006_DrawVertLine(x, y, size_y, edge_color);
00122 }
00123
00124 static void display_perf(U32 x, U32 y, Bool b_clear, U32 perf_kBps, U16 string_color)
00125 {
00126 display_box(x, y, 50, 18, WHITE, BLACK);
00127 if( !b_clear )
00128 {
00129 sprintf(string, "%5ld", perf_kBps);
00130 et024006_PrintString(string, (const unsigned char *)&FONT8x8, x+5, y+6, string_color, -1);
00131 }
00132 else
00133 {
00134 et024006_PrintString("KByte/s", (const unsigned char *)&FONT8x8, x+55, y+6, BLACK, -1);
00135 }
00136 }
00137
00138 static void mmi_ms_display( void )
00139 {
00140 U32 i;
00141 for( i=0 ; i<MS_N_PROGRESS_BAR ; i++ )
00142 {
00143 if( ms_progress_bar_level[i] != 0 )
00144 {
00145 if( ms_progress_bar_type[i] == BLUE )
00146 et024006_DrawFilledRect(80+3 + i*(17+2), 180+3, 17, 10, BLUE_LEV(ms_progress_bar_level[i]) );
00147 else
00148 et024006_DrawFilledRect(80+3 + i*(17+2), 180+3, 17, 10, RED_LEV(ms_progress_bar_level[i]) );
00149 ms_progress_bar_level[i] -= 1;
00150 }
00151 }
00152 }
00153
00154
00158 void mmi_task(void)
00159 {
00160 U32 i;
00161 switch( mmi_state )
00162 {
00163 case MMI_TOP_MENU_START:
00164
00165 et024006_PutPixmap(avr32_logo, 320, 0, 0, 0, 0, 320, 240);
00166
00167
00168 et024006_PrintString("EVK1104 Demo", (const unsigned char *)&FONT8x8, 110, 220, BLACK, -1);
00169
00170 mmi_state = MMI_TOP_MENU;
00171 break;
00172
00173 case MMI_TOP_MENU:
00174 if( Is_usb_vbus_high() )
00175 {
00176 mmi_state = MMI_MASS_STORAGE_START;
00177 }
00178 break;
00179
00180 case MMI_MASS_STORAGE_START:
00181
00182 et024006_PutPixmap(avr32_logo, 320, 0, 0, 0, 0, 320, 240);
00183
00184
00185 et024006_DrawFilledRect(220-1, 20-1, 80+2, 42+2, BLACK );
00186 et024006_PutPixmap(ms_key_logo, 80, 0, 0, 220, 20, 80, 42);
00187
00188
00189 et024006_PrintString("U-Disk", (const unsigned char *)&FONT6x8, 240, 65, BLACK, -1);
00190
00191
00192 display_box(80, 180, 156, 16, WHITE, BLACK);
00193
00194
00195 display_perf(120, 201, TRUE, 0, 0);
00196
00197 ms_old_cnt_read = ms_cnt_read =0;
00198 ms_old_cnt_write = ms_cnt_write =0;
00199 mmi_state = MMI_MASS_STORAGE;
00200 ms_cnt_screen = 0;
00201 for( i=0 ; i<MS_N_PROGRESS_BAR ; i++ )
00202 {
00203 ms_progress_bar_level[i] = 1;
00204 ms_progress_bar_type[i] = BLACK;
00205 }
00206 mmi_ms_display();
00207
00208 cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_UPDATE, pm_freq_param.cpu_f), &ms_activity_timer);
00209 cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_CLEAR, pm_freq_param.cpu_f), &ms_clear_timer);
00210 break;
00211
00212 case MMI_MASS_STORAGE:
00213
00214
00215 if( cpu_is_timeout(&ms_clear_timer) )
00216 {
00217 cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_CLEAR, pm_freq_param.cpu_f), &ms_clear_timer);
00218 mmi_ms_display();
00219 }
00220
00221
00222
00223 if( cpu_is_timeout(&ms_activity_timer) )
00224 {
00225 cpu_set_timeout( cpu_ms_2_cy(TIMER_MS_PROGRESS_BAR_UPDATE, pm_freq_param.cpu_f), &ms_activity_timer);
00226 if( ms_old_cnt_write != ms_cnt_write )
00227 {
00228 ms_cnt_screen = (unsigned char)(ms_cnt_screen-1)%MS_N_PROGRESS_BAR;
00229 ms_progress_bar_type[ms_cnt_screen] = RED;
00230
00231
00232
00233 perf_write = (U64)(ms_cnt_write - ms_old_cnt_write)*SD_MMC_SECTOR_SIZE/TIMER_MS_PROGRESS_BAR_UPDATE;
00234 display_perf(120, 201, FALSE, perf_write, RED);
00235 ms_old_cnt_write = ms_cnt_write;
00236 ms_progress_bar_level[ms_cnt_screen] = (perf_write>10000) ? 31 :
00237 (perf_write> 7500) ? 29 :
00238 (perf_write> 5000) ? 27 : 25 ;
00239 }
00240 else if( ms_old_cnt_read != ms_cnt_read )
00241 {
00242 ms_cnt_screen = (unsigned char)(ms_cnt_screen+1)%MS_N_PROGRESS_BAR;
00243 ms_progress_bar_type[ms_cnt_screen] = BLUE;
00244
00245
00246
00247 perf_read = (U64)(ms_cnt_read - ms_old_cnt_read)*SD_MMC_SECTOR_SIZE/TIMER_MS_PROGRESS_BAR_UPDATE;
00248 display_perf(120, 201, FALSE, perf_read, BLUE);
00249 ms_old_cnt_read = ms_cnt_read;
00250 ms_progress_bar_level[ms_cnt_screen] = (perf_read>10000) ? 31 :
00251 (perf_read> 7500) ? 29 :
00252 (perf_read> 5000) ? 27 : 25 ;
00253 }
00254 else
00255 {
00256 display_perf(120, 201, TRUE, 0, 0);
00257 }
00258 }
00259
00260
00261
00262 if( Is_usb_vbus_low() )
00263 {
00264 mmi_state = MMI_TOP_MENU_START;
00265 }
00266 break;
00267
00268 default:
00269 break;
00270 }
00271
00272 }