00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 #include "board.h"
00044 #include "ui.h"
00045 #include "ctrl_access.h"
00046 #include "uhi_msc_mem.h"
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 static void ui_enable_asynchronous_interrupt(void);
00057 static void ui_disable_asynchronous_interrupt(void);
00058
00059
00060
00061
00062
00063 static void ui_wakeup_handler(uint32_t id, uint32_t mask)
00064 {
00065
00066
00067
00068
00069
00070
00071
00072
00073 }
00074
00075
00076
00077
00078 static void ui_enable_asynchronous_interrupt(void)
00079 {
00080
00081
00082
00083
00084
00085 }
00086
00087
00088
00089
00090 static void ui_disable_asynchronous_interrupt(void)
00091 {
00092
00093
00094
00095
00096
00097 }
00098
00099
00100
00101
00102
00103
00104
00105 void ui_init(void)
00106 {
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 LED_Configure( LED_YELLOW0 ) ;
00123 LED_Configure( LED_YELLOW1 ) ;
00124
00125 LED_Clear(LED_YELLOW0);
00126 LED_Clear(LED_YELLOW1);
00127
00128 }
00129
00130 void ui_usb_mode_change(bool b_host_mode)
00131 {
00132 UNUSED(b_host_mode);
00133 ui_init();
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 static USBH_enum_status_t ui_enum_status = UHC_ENUM_DISCONNECT;
00145
00146 static uint16_t ui_device_speed_blink;
00147
00148 static bool ui_hid_mouse_plug = false;
00149
00150 static bool ui_msc_plug = false;
00151
00152 static bool ui_test_done;
00153
00154 static bool ui_test_result;
00155
00156 static int8_t ui_x, ui_y, ui_scroll;
00157
00158 static uint8_t ui_nb_down = 0;
00159
00160 void ui_usb_vbus_change(bool b_vbus_present)
00161 {
00162
00163 }
00164
00165 void ui_usb_vbus_error(void)
00166 {
00167 }
00168
00169 void ui_usb_connection_event(USBH_device_t *dev, bool b_present)
00170 {
00171 UNUSED(dev);
00172 if (b_present) {
00173 LED_Set(LED_YELLOW0);
00174 } else {
00175 LED_Clear(LED_YELLOW0);
00176 ui_enum_status = UHC_ENUM_DISCONNECT;
00177 }
00178 }
00179
00180 void ui_usb_enum_event(USBH_device_t *dev, USBH_enum_status_t status)
00181 {
00182 UNUSED(dev);
00183 ui_enum_status = status;
00184 switch (dev->speed) {
00185 case UHD_SPEED_HIGH:
00186 ui_device_speed_blink = 250;
00187 break;
00188
00189 case UHD_SPEED_FULL:
00190 ui_device_speed_blink = 500;
00191 break;
00192
00193 case UHD_SPEED_LOW:
00194 default:
00195 ui_device_speed_blink = 1000;
00196 break;
00197 }
00198 ui_test_done = false;
00199 }
00200 void ui_uhi_hid_mouse_change(USBH_device_t * dev, bool b_plug)
00201 {
00202 UNUSED(dev);
00203 ui_hid_mouse_plug = b_plug;
00204 }
00205
00206 void ui_uhi_msc_change(USBH_device_t * dev, bool b_plug)
00207 {
00208 UNUSED(dev);
00209 ui_msc_plug = b_plug;
00210 }
00211
00212 void ui_usb_wakeup_event(void)
00213 {
00214 ui_disable_asynchronous_interrupt();
00215 }
00216
00217 void ui_usb_sof_event(void)
00218 {
00219 bool b_btn_state;
00220 static bool btn_suspend_and_remotewakeup = false;
00221 static uint16_t counter_sof = 0;
00222
00223 if (ui_enum_status == UHC_ENUM_SUCCESS) {
00224
00225 if (++counter_sof > ui_device_speed_blink) {
00226 counter_sof = 0;
00227 }
00228
00229
00230
00231
00232 b_btn_state = true ;
00233 if (b_btn_state != btn_suspend_and_remotewakeup) {
00234
00235 btn_suspend_and_remotewakeup = b_btn_state;
00236 if (b_btn_state) {
00237
00238 ui_enable_asynchronous_interrupt();
00239 USBH_suspend(true);
00240 return;
00241 }
00242 }
00243
00244
00245 if (!ui_x && !ui_y && !ui_scroll) {
00246 LED_Clear(LED_YELLOW1);
00247 } else {
00248 ui_x = ui_y = ui_scroll = 0;
00249 LED_Set(LED_YELLOW1);
00250 }
00251 }
00252 }
00253
00254
00255
00256 static void ui_uhi_hid_mouse_btn(bool b_state)
00257 {
00258 static uint8_t nb_down = 0;
00259 if (b_state) {
00260 nb_down++;
00261 } else {
00262 nb_down--;
00263 }
00264
00265 }
00266
00267 void ui_test_flag_reset(void)
00268 {
00269 ui_test_done = false;
00270 LED_Clear(LED_YELLOW0);
00271 }
00272
00273 void ui_test_finish(bool b_success)
00274 {
00275 ui_test_done = true;
00276 ui_test_result = b_success;
00277 if (b_success) {
00278 LED_Set(LED_YELLOW1);
00279 }
00280 }
00281
00282
00283
00284
00285
00286 void ui_uhi_hid_mouse_btn_left(bool b_state)
00287 {
00288 TRACE_INFO_WP("\r\t\t\t\tLeft Button clicked ");
00289 ui_uhi_hid_mouse_btn(b_state);
00290 }
00291
00292 void ui_uhi_hid_mouse_btn_right(bool b_state)
00293 {
00294 TRACE_INFO_WP("\r\t\t\t\tRight Button clicked ");
00295 ui_uhi_hid_mouse_btn(b_state);
00296 }
00297
00298 void ui_uhi_hid_mouse_btn_middle(bool b_state)
00299 {
00300 ui_uhi_hid_mouse_btn(b_state);
00301 }
00302
00303 void ui_uhi_hid_mouse_move(int8_t x, int8_t y, int8_t scroll)
00304 {
00305 ui_x = x;
00306 ui_y = y;
00307 TRACE_INFO_WP("\r Mouse at X:%d, Y:%d ", ui_x, ui_y);
00308 ui_scroll = scroll;
00309 }
00310
00311
00312
00313
00314 void ui_start_read(void)
00315 {
00316 LED_Set(LED_YELLOW1);
00317 }
00318
00319 void ui_stop_read(void)
00320 {
00321 LED_Clear(LED_YELLOW1);
00322 }
00323
00324 void ui_start_write(void)
00325 {
00326 LED_Set(LED_YELLOW1);
00327 }
00328
00329 void ui_stop_write(void)
00330 {
00331 LED_Clear(LED_YELLOW1);
00332 }
00333
00334