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