| 
									
										
										
										
											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-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
 | 
					
						
							|  |  |  | void keyboard_device_app_task(void * p_para) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-04 10:43:58 +07:00
										 |  |  |   if (tusb_device_is_configured()) | 
					
						
							| 
									
										
										
										
											2013-05-31 14:53:26 +07:00
										 |  |  |   { | 
					
						
							|  |  |  |     static uint32_t count =0; | 
					
						
							|  |  |  |     if (count < 4) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       count++; | 
					
						
							| 
									
										
										
										
											2013-05-31 21:24:40 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       tusbd_hid_keyboard_send_report( | 
					
						
							|  |  |  |           &(tusb_keyboard_report_t) { | 
					
						
							|  |  |  |               .keycode = { 0x04 } } | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2013-05-31 14:53:26 +07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-03 14:37:41 +07:00
										 |  |  | #if TUSB_CFG_DEVICE_HID_MOUSE
 | 
					
						
							|  |  |  | void mouse_device_app_task(void * p_para) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-04 10:43:58 +07:00
										 |  |  |   if (tusb_device_is_configured()) | 
					
						
							| 
									
										
										
										
											2013-06-03 14:37:41 +07:00
										 |  |  |   { | 
					
						
							|  |  |  |     static uint32_t count =0; | 
					
						
							|  |  |  |     if (count < 8) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       count++; | 
					
						
							|  |  |  |       tusbd_hid_mouse_send_report( | 
					
						
							|  |  |  |           &(tusb_mouse_report_t) { | 
					
						
							|  |  |  |               .x = 20, | 
					
						
							|  |  |  |               .y = 20 } ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #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" | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } |