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-01-18 14:39:42 +07:00
|
|
|
#if defined(__CODE_RED)
|
|
|
|
#include <cr_section_macros.h>
|
|
|
|
#include <NXP/crp.h>
|
|
|
|
// Variable to store CRP value in. Will be placed automatically
|
|
|
|
// by the linker when "Enable Code Read Protect" selected.
|
|
|
|
// See crp.h header for more information
|
|
|
|
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
|
|
|
|
#endif
|
2012-11-27 17:51:59 +07:00
|
|
|
|
2013-05-29 14:39:14 +07:00
|
|
|
void print_greeting(void);
|
|
|
|
|
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
|
|
|
{
|
2013-05-25 17:19:18 +07:00
|
|
|
static uint32_t led_on_mask = 0;
|
|
|
|
|
2012-12-07 17:59:46 +07:00
|
|
|
current_tick += 1000;
|
2012-11-28 11:53:23 +07:00
|
|
|
|
2013-05-25 17:19:18 +07:00
|
|
|
board_leds(led_on_mask, 1 - led_on_mask);
|
|
|
|
led_on_mask = 1 - led_on_mask; // toggle
|
2012-12-18 15:08:30 +07:00
|
|
|
|
2012-11-28 11:53:23 +07:00
|
|
|
if (usb_isConfigured())
|
|
|
|
{
|
2013-05-29 14:39:14 +07:00
|
|
|
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
2013-05-31 13:57:57 +07:00
|
|
|
static uint32_t count =0;
|
|
|
|
if (count < 4)
|
|
|
|
{
|
2013-05-29 14:39:14 +07:00
|
|
|
uint8_t keys[6] = {0x04}; // A character
|
|
|
|
tusbd_hid_keyboard_send_report(0x00, keys, 1);
|
2013-05-31 13:57:57 +07:00
|
|
|
count++;
|
|
|
|
}
|
2012-11-28 11:53:23 +07:00
|
|
|
#endif
|
2012-11-27 17:51:59 +07:00
|
|
|
|
2013-05-29 14:39:14 +07:00
|
|
|
#if TUSB_CFG_DEVICE_HID_MOUSE
|
2012-11-29 17:52:57 +07:00
|
|
|
tusb_hid_mouse_send(0, 10, 10);
|
2012-11-28 11:53:23 +07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2012-11-29 17:52:57 +07:00
|
|
|
|
2013-01-17 14:40:46 +07:00
|
|
|
#if defined TUSB_CFG_DEVICE_CDC && 0
|
2012-12-07 10:53:52 +07:00
|
|
|
if (usb_isConfigured())
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// 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"
|
|
|
|
);
|
|
|
|
}
|