//! @brief This function manages the HOST mass storage application //! void host_ms_task(void) { if( Is_host_ready() ) { // Here, Enumeration successfull, device is operationnal if(Is_new_device_connection_event()) { // Update MS driver in case of if( host_mem_install() ) { #if (HOST_UPGRADE_MODE==ENABLE) b_new_msc_connected = TRUE; #endif Led1_on(); } } #if (HOST_SYNC_MODE==ENABLE) // Sync operating mode(if available) if( 0 != host_mem_get_lun() ) { if(Is_joy_right()) // Sync device to host stream { Led0_on(); sync_on_going=1; copy_dir( (U8 code *)dir_usb_out_name, (U8 code *)dir_local_in_name, 1 ); sync_on_going=0; Led3_off(); Led0_off(); } if(Is_joy_left()) // Sync host to device stream { Led0_on(); sync_on_going=1; copy_dir( (U8 code *)dir_local_out_name, (U8 code *)dir_usb_in_name, 1 ); sync_on_going=0; Led0_off(); Led3_off(); } } #endif #if (HOST_UPGRADE_MODE==ENABLE) if( b_new_msc_connected ) { // A new MSC is connected then start upgrade routine b_new_msc_connected = FALSE; firm_upgrade_run(); } #endif } // Device disconnection... if( Is_device_disconnection_event() ) { // Update MS driver in case of host_mem_uninstall(); Led1_off(); } }
//! This function initializes the hardware/software resources required for mouse task. //! void mouse_task_init(void) { // Init SOF g_u8_cpt_sof=0; Usb_enable_sof_interrupt(); // Init interface board Joy_init(); Hwb_button_init(); Leds_init(); Led1_on(); Led0_off(); #if (TARGET_BOARD==STK525) init_adc(); g_u16_pos_scroll=Get_adc_pot_val(); #endif // Send a ack report at startup g_b_send_report = FALSE; g_b_send_ack_report = TRUE; // Set first zerovalue for calibrating sensor reading U8 i = 0; for(i = ADC_START_CHANNEL; i <= ADC_END_CHANNEL; i++) { if(i != 3) { Zerovalue[i] = adc_reader(i); } } }
//! Task which links mouse events with the USB HID mouse device //! void mouse_task(void) { if(Is_usb_vbus_low()) { Setup_power_down_mode(); Sleep_instruction(); } if(!Is_device_enumerated()) return; // Device not ready #if (USB_LOW_SPEED_DEVICE==DISABLE) // The SOF is used to schedule the task at the same frequency that Endpoint Interrupt frequency // This check allow to win a CPU time if(g_u8_cpt_sof<NB_IDLE_POLLING_SOF) return; // Wait a delay g_u8_cpt_sof=0; #endif if(!g_b_send_report) { // No report sending on going, then check mouse event to eventualy fill a new report if(is_mouse_event()) { // Enable sending of report g_b_send_report = TRUE; } } if((!g_b_send_report)&&(!g_b_send_ack_report)) return; // No report and ack to send //** A report or ack must be send Usb_select_endpoint(EP_MOUSE_IN); if(!Is_usb_write_enabled()) return; // Endpoint no free Led0_on(); if( g_b_send_report ) { g_b_send_report = FALSE; // Send an ack after a "clic" report only g_b_send_ack_report = (0!=g_hid_mouse_report[0]); } else { Hid_mouse_report_reset(); // Reset report to have a ack report g_b_send_ack_report = FALSE; } // Send report Usb_write_byte(g_hid_mouse_report[0]); Usb_write_byte(g_hid_mouse_report[1]); Usb_write_byte(g_hid_mouse_report[2]); Usb_write_byte(g_hid_mouse_report[3]); Usb_ack_in_ready(); Led0_off(); }