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 #include "board.h"
00042 #include "ui.h"
00043
00044
00045 #define RESUME_PMC_FSTT (PMC_FSMR_FSTT14)
00046 #define RESUME_PIN (GPIO_PUSH_BUTTON_2)
00047 #define RESUME_PIO (PIN_PUSHBUTTON_2_PIO)
00048 #define RESUME_PIO_ID (PIN_PUSHBUTTON_2_ID)
00049 #define RESUME_PIO_MASK (PIN_PUSHBUTTON_2_MASK)
00050 #define RESUME_PIO_ATTR (PIN_PUSHBUTTON_2_ATTR)
00051
00052
00053
00054
00055
00056
00057
00058
00059 static void ui_enable_asynchronous_interrupt(void);
00060 static void ui_disable_asynchronous_interrupt(void);
00061
00062
00063
00064
00065
00066 static void ui_enable_asynchronous_interrupt(void)
00067 {
00068
00069 }
00070
00071
00072
00073
00074 static void ui_disable_asynchronous_interrupt(void)
00075 {
00076
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 void ui_init(void)
00086 {
00087
00088 LED_Configure(LED_YELLOW0);
00089 #if 2 == LED_NUM
00090 LED_Configure(LED_YELLOW1);
00091 #endif
00092 }
00093
00094 void ui_usb_mode_change(bool b_host_mode)
00095 {
00096 (void)b_host_mode;
00097 ui_init();
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 static USBH_enum_status_t ui_enum_status = UHC_ENUM_DISCONNECT;
00109
00110 static uint16_t ui_device_speed_blink;
00111
00112 static int8_t ui_x, ui_y, ui_scroll;
00113
00114 void ui_usb_vbus_change(bool b_vbus_present)
00115 {
00116 b_vbus_present = b_vbus_present;
00117
00118 }
00119
00120 void ui_usb_vbus_error(void)
00121 {
00122 }
00123
00124 void ui_usb_connection_event(USBH_device_t *pDev, bool b_present)
00125 {
00126 (void)pDev;
00127
00128 if (b_present)
00129 LED_Set(LED_YELLOW0);
00130 else {
00131 LED_Clear(LED_YELLOW0);
00132 ui_enum_status = UHC_ENUM_DISCONNECT;
00133 }
00134 }
00135
00136 void ui_usb_enum_event(USBH_device_t *pDev, USBH_enum_status_t status)
00137 {
00138 (void)pDev;
00139 ui_enum_status = status;
00140
00141 if (ui_enum_status == UHC_ENUM_SUCCESS) {
00142 ui_x = 0, ui_y = 0, ui_scroll = 0;
00143
00144 switch (pDev->speed) {
00145 case UHD_SPEED_HIGH:
00146 ui_device_speed_blink = 250;
00147 break;
00148
00149 case UHD_SPEED_FULL:
00150 ui_device_speed_blink = 500;
00151 break;
00152
00153 case UHD_SPEED_LOW:
00154 default:
00155 ui_device_speed_blink = 1000;
00156 break;
00157 }
00158 }
00159 }
00160
00161 void ui_usb_wakeup_event(void)
00162 {
00163 ui_disable_asynchronous_interrupt();
00164 }
00165
00166 void ui_usb_sof_event(void)
00167 {
00168 bool b_btn_state;
00169 static bool btn_suspend_and_remotewakeup = false;
00170 static uint16_t counter_sof = 0;
00171
00172 if (ui_enum_status == UHC_ENUM_SUCCESS) {
00173
00174 if (++counter_sof > ui_device_speed_blink) {
00175 counter_sof = 0;
00176 LED_Toggle(LED_YELLOW0);
00177 }
00178
00179
00180
00181
00182 b_btn_state = true;
00183
00184 if (b_btn_state != btn_suspend_and_remotewakeup) {
00185
00186 btn_suspend_and_remotewakeup = b_btn_state;
00187
00188 if (b_btn_state) {
00189
00190 ui_enable_asynchronous_interrupt();
00191 USBH_suspend(true);
00192 return;
00193 }
00194 }
00195
00196
00197 if (!ui_x && !ui_y && !ui_scroll) {
00198 #if 2 == LED_NUM
00199 LED_Clear(LED_YELLOW1);
00200 #endif
00201 } else {
00202 ui_x = ui_y = ui_scroll = 0;
00203 #if 2 == LED_NUM
00204 LED_Set(LED_YELLOW1);
00205 #endif
00206 }
00207 }
00208 }
00209
00210 static void ui_uhi_hid_mouse_btn(bool b_state)
00211 {
00212 static uint8_t nb_down = 0;
00213
00214 if (b_state)
00215 nb_down++;
00216 else
00217 nb_down--;
00218
00219 if (nb_down) {
00220
00221 } else {
00222
00223 }
00224 }
00225
00226 void ui_uhi_hid_mouse_btn_left(bool b_state)
00227 {
00228 TRACE_INFO_WP("\r\t\t\t\tLeft Button clicked ");
00229 ui_uhi_hid_mouse_btn(b_state);
00230 }
00231
00232 void ui_uhi_hid_mouse_btn_right(bool b_state)
00233 {
00234 TRACE_INFO_WP("\r\t\t\t\tRight Button clicked ");
00235 ui_uhi_hid_mouse_btn(b_state);
00236 }
00237
00238 void ui_uhi_hid_mouse_btn_middle(bool b_state)
00239 {
00240 ui_uhi_hid_mouse_btn(b_state);
00241 }
00242
00243 void ui_uhi_hid_mouse_move(int8_t x, int8_t y, int8_t scroll)
00244 {
00245 ui_x = x;
00246 ui_y = y;
00247 TRACE_INFO_WP("\r Mouse at X:%d, Y:%d ", ui_x, ui_y);
00248 ui_scroll = scroll;
00249 }
00250
00251
00252