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
00051
00052
00053 #include <stdio.h>
00054 #include "usart.h"
00055
00056 #include "conf_usb.h"
00057
00058 #if USB_DEVICE_FEATURE == ENABLED
00059
00060 #include "board.h"
00061 #include "controller.h"
00062 #include "usb_drv.h"
00063 #include "usb_descriptors.h"
00064 #include "usb_standard_request.h"
00065 #include "device_hid_task.h"
00066 #include "audio_example.h"
00067 #include "cycle_counter.h"
00068 #include "debug.h"
00069 #include "hid.h"
00070 #include "et024006dhu.h"
00071
00072
00073
00074
00075
00076
00077 U8 key = 0;
00078
00079 #define TIMER_STARTUP 100
00080 t_cpu_time key_timer;
00081
00082
00083 #define HID_VOL_DN 2
00084 #define HID_VOL_UP 1
00085 #define HID_PLAY_PAUSE 4
00086 #define HID_NEXT 8
00087 #define HID_PREV 16
00088 #define HID_FAST_FWD 32
00089 #define HID_REWIND 64
00090
00091
00092
00093
00094
00098 Bool is_usb_hid_event(void) {
00099 static Bool b_on_off = FALSE;
00100 static Bool b_prev = FALSE;
00101 static Bool b_next = FALSE;
00102 static Bool b_vol_up = FALSE;
00103 static Bool b_vol_dn = FALSE;
00104
00105
00106
00107 if(is_joystick_pressed() && b_on_off==FALSE)
00108 {
00109 b_on_off = TRUE;
00110 key = HID_PLAY_PAUSE;
00111 et024006_PrintString("PLAY", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00112 return TRUE;
00113 }
00114 if(!is_joystick_pressed() && b_on_off==TRUE)
00115 {
00116 b_on_off = FALSE;
00117 key = 0;
00118 et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00119 return TRUE;
00120 }
00121
00122
00123
00124 if (is_joystick_left() && b_prev == FALSE)
00125 {
00126 b_prev = TRUE;
00127 key = HID_PREV;
00128
00129 et024006_PrintString("PREV", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00130 return TRUE;
00131 }
00132 if (!is_joystick_left() && b_prev == TRUE)
00133 {
00134 b_prev = FALSE;
00135 key = 0;
00136
00137 et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00138 return TRUE;
00139 }
00140
00141
00142
00143 if (is_joystick_right() && b_next == FALSE)
00144 {
00145 b_next = TRUE;
00146 key = HID_NEXT;
00147
00148 et024006_PrintString("NEXT", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00149 return TRUE;
00150 }
00151 if (!is_joystick_right() && b_next == TRUE)
00152 {
00153 b_next = FALSE;
00154 key = 0;
00155
00156 et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00157 return TRUE;
00158 }
00159
00160
00161
00162
00163 if (is_joystick_down() && b_vol_dn == FALSE)
00164 {
00165 key = HID_VOL_DN;
00166 b_vol_dn = TRUE;
00167
00168 et024006_PrintString("VOL-", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00169 return TRUE;
00170 }
00171 if (!is_joystick_down() && b_vol_dn == TRUE)
00172 {
00173 b_vol_dn = FALSE;
00174 key = 0;
00175
00176 et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00177 return TRUE;
00178 }
00179
00180
00181
00182 if (is_joystick_up() && b_vol_up == FALSE)
00183 {
00184 key = HID_VOL_UP;
00185 b_vol_up = TRUE;
00186
00187 et024006_PrintString("VOL+", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00188 return TRUE;
00189 }
00190 if (!is_joystick_up() && b_vol_up == TRUE)
00191 {
00192 b_vol_up = FALSE;
00193 key = 0;
00194
00195 et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE);
00196 return TRUE;
00197 }
00198
00199 return FALSE;
00200 }
00201
00206 void device_hid_task_init(void)
00207 {
00208 cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &key_timer );
00209
00210 #if USB_HOST_FEATURE == ENABLED
00211
00212
00213
00214 if (Is_usb_device())
00215 #endif // USB_HOST_FEATURE == ENABLED
00216 Usb_enable_sof_interrupt();
00217 }
00218
00219
00220
00224 void device_hid_task(void)
00225 {
00226
00227 if (!Is_device_enumerated()) {
00228 return;
00229 }
00230
00231 if (Is_usb_in_ready(EP_KBD_IN)) {
00232 if (is_usb_hid_event()) {
00233 Usb_reset_endpoint_fifo_access(EP_KBD_IN);
00234
00236 Usb_write_endpoint_data(EP_KBD_IN, 8, key);
00237 Usb_ack_in_ready_send(EP_KBD_IN);
00238 }
00239 }
00240 }
00241
00242 #endif // USB_DEVICE_FEATURE == ENABLED