Advertisement
Guest User

USB-HID Main

a guest
Nov 14th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1.  
  2. #include <asf.h>
  3. void vbus_event(bool b_high);
  4. void usb_init(void);
  5.  
  6. int main (void)
  7. {
  8.     // Insert system clock initialization code here (sysclk_init()).
  9.  
  10.     sysclk_init();
  11.     irq_initialize_vectors();
  12.     cpu_irq_enable();
  13.     board_init();
  14.  
  15.     udc_start();
  16.     vbus_event(true);
  17.  
  18.     while(42) {
  19.        
  20.        
  21.     }
  22.     // Insert application code here, after the board has been initialized.
  23. }
  24.  
  25.  
  26. void vbus_event(bool b_high)
  27. {
  28.     if (b_high) {
  29.         // Attach USB Device
  30.         udc_attach();
  31.         } else {
  32.         // VBUS not present
  33.         udc_detach();
  34.     }
  35. }
  36.  
  37. void usb_init(void)
  38. {
  39.     udc_start();
  40. }
  41.  
  42. static bool my_flag_autorize_generic_events = false;
  43. bool my_callback_generic_enable(void)
  44. {
  45.     my_flag_autorize_generic_events = true;
  46.     return true;
  47. }
  48. void my_callback_generic_disable(void)
  49. {
  50.     my_flag_autorize_generic_events = false;
  51. }
  52. void my_button_press_event(void)
  53. {
  54.     if (!my_flag_autorize_generic_events) {
  55.         return;
  56.     }
  57.     uint8_t report[] = {0x00,0x01,0x02};
  58.     udi_hid_generic_send_report_in(report);
  59. }
  60. void my_callback_generic_report_out(uint8_t *report)
  61. {
  62.     /*if ((report[0] == MY_VALUE_0)
  63.     (report[1] == MY_VALUE_1)) {
  64.         // The report is correct
  65.     }*/
  66. }
  67. void my_callback_generic_set_feature(uint8_t *report_feature)
  68. {
  69. /*
  70.     if ((report_feature[0] == MY_VALUE_0)
  71.     (report_feature[1] == MY_VALUE_1)) {
  72.         // The report feature is correct
  73.     }*/
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement