2012-11-27 17:51:59 +07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-12-07 17:59:46 +07:00
|
|
|
#include "boards/board.h"
|
2012-11-27 17:51:59 +07:00
|
|
|
#include "tusb.h"
|
|
|
|
|
2013-05-29 14:39:14 +07:00
|
|
|
void print_greeting(void);
|
|
|
|
|
2013-05-31 14:53:26 +07:00
|
|
|
void led_blinking_task(void * p_para);
|
|
|
|
void keyboard_device_app_task(void * p_para);
|
2013-06-03 14:37:41 +07:00
|
|
|
void mouse_device_app_task(void * p_para);
|
2013-05-31 14:53:26 +07:00
|
|
|
|
2013-01-18 14:39:42 +07:00
|
|
|
int main(void)
|
2012-11-27 17:51:59 +07:00
|
|
|
{
|
2012-12-18 15:08:30 +07:00
|
|
|
uint32_t current_tick = system_ticks;
|
2012-11-28 11:53:23 +07:00
|
|
|
|
2012-12-04 18:18:29 +07:00
|
|
|
board_init();
|
2012-11-27 17:51:59 +07:00
|
|
|
tusb_init();
|
|
|
|
|
2013-05-31 14:36:42 +07:00
|
|
|
print_greeting();
|
2012-11-27 17:51:59 +07:00
|
|
|
while (1)
|
|
|
|
{
|
2012-12-18 15:08:30 +07:00
|
|
|
if (current_tick + 1000 < system_ticks)
|
2012-11-28 11:53:23 +07:00
|
|
|
{
|
2012-12-07 17:59:46 +07:00
|
|
|
current_tick += 1000;
|
2012-11-28 11:53:23 +07:00
|
|
|
|
2013-05-31 14:53:26 +07:00
|
|
|
led_blinking_task(NULL);
|
|
|
|
|
|
|
|
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
|
|
|
keyboard_device_app_task(NULL);
|
|
|
|
#endif
|
2012-12-18 15:08:30 +07:00
|
|
|
|
2013-05-31 14:53:26 +07:00
|
|
|
#if TUSB_CFG_DEVICE_HID_MOUSE
|
2013-06-03 14:37:41 +07:00
|
|
|
mouse_device_app_task(NULL);
|
2013-05-31 14:53:26 +07:00
|
|
|
#endif
|
2012-11-28 11:53:23 +07:00
|
|
|
}
|
2012-11-29 17:52:57 +07:00
|
|
|
|
2013-06-03 14:31:17 +07:00
|
|
|
#if TUSB_CFG_DEVICE_CDC && 0
|
2013-06-04 10:43:58 +07:00
|
|
|
if (tusb_device_is_configured())
|
2012-12-07 10:53:52 +07:00
|
|
|
{
|
|
|
|
uint8_t cdc_char;
|
|
|
|
if( tusb_cdc_getc(&cdc_char) )
|
|
|
|
{
|
|
|
|
switch (cdc_char)
|
|
|
|
{
|
2012-12-20 16:59:43 +07:00
|
|
|
#ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
|
2012-12-07 10:53:52 +07:00
|
|
|
case '1' :
|
|
|
|
{
|
|
|
|
uint8_t keys[6] = {HID_USAGE_KEYBOARD_aA + 'e' - 'a'};
|
2013-05-29 14:39:14 +07:00
|
|
|
tusbd_hid_keyboard_send_report(0x08, keys, 1); // windows + E --> open explorer
|
2012-12-07 10:53:52 +07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-12-20 16:59:43 +07:00
|
|
|
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
|
2012-12-07 10:53:52 +07:00
|
|
|
case '2' :
|
|
|
|
tusb_hid_mouse_send(0, 10, 10);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default :
|
|
|
|
cdc_char = toupper(cdc_char);
|
|
|
|
tusb_cdc_putc(cdc_char);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-27 17:51:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-29 14:39:14 +07:00
|
|
|
|
2013-05-31 14:53:26 +07:00
|
|
|
void led_blinking_task(void * p_para)
|
|
|
|
{
|
|
|
|
static uint32_t led_on_mask = 0;
|
|
|
|
|
|
|
|
board_leds(led_on_mask, 1 - led_on_mask);
|
|
|
|
led_on_mask = 1 - led_on_mask; // toggle
|
|
|
|
}
|
|
|
|
|
|
|
|
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
2013-10-29 14:19:56 +07:00
|
|
|
hid_keyboard_report_t keyboard_report TUSB_CFG_ATTR_USBRAM;
|
2013-05-31 14:53:26 +07:00
|
|
|
void keyboard_device_app_task(void * p_para)
|
|
|
|
{
|
2013-10-29 15:09:16 +07:00
|
|
|
if (tusbd_is_configured(0))
|
|
|
|
{
|
|
|
|
static uint32_t count =0;
|
|
|
|
if (count++ < 10)
|
|
|
|
{
|
|
|
|
if (!tusbd_hid_keyboard_is_busy(0))
|
|
|
|
{
|
2013-10-30 12:20:00 +07:00
|
|
|
keyboard_report.keycode[0] = (count%2) ? 0x04 : 0x00;
|
2013-10-29 15:09:16 +07:00
|
|
|
tusbd_hid_keyboard_send(0, &keyboard_report );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-31 14:53:26 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-03 14:37:41 +07:00
|
|
|
#if TUSB_CFG_DEVICE_HID_MOUSE
|
2013-10-29 17:16:41 +07:00
|
|
|
hid_mouse_report_t mouse_report TUSB_CFG_ATTR_USBRAM;
|
2013-06-03 14:37:41 +07:00
|
|
|
void mouse_device_app_task(void * p_para)
|
|
|
|
{
|
2013-10-30 12:20:00 +07:00
|
|
|
if (tusbd_is_configured(0))
|
|
|
|
{
|
|
|
|
static uint32_t count =0;
|
|
|
|
if (count++ < 10)
|
|
|
|
{
|
|
|
|
if ( !tusbd_hid_mouse_is_busy(0) )
|
|
|
|
{
|
|
|
|
mouse_report.x = mouse_report.y = 20;
|
|
|
|
tusbd_hid_mouse_send(0, &mouse_report );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-03 14:37:41 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-29 14:39:14 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// HELPER FUNCTION
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
void print_greeting(void)
|
|
|
|
{
|
|
|
|
printf("\r\n\
|
|
|
|
--------------------------------------------------------------------\r\n\
|
|
|
|
- Device Demo (a tinyusb example)\r\n\
|
|
|
|
- if you find any bugs or get any questions, feel free to file an\r\n\
|
|
|
|
- issue at https://github.com/hathach/tinyusb\r\n\
|
|
|
|
--------------------------------------------------------------------\r\n\r\n"
|
|
|
|
);
|
|
|
|
}
|