| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |  * The MIT License (MIT) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2019 Ha Thach (tinyusb.org) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
					
						
							|  |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bsp/board.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // MACRO CONSTANT TYPEDEF PROTYPES
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Blink pattern
 | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |  * - 250 ms  : button is not pressed | 
					
						
							|  |  |  |  * - 1000 ms : button is pressed (and hold) | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  |  */ | 
					
						
							|  |  |  | enum  { | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |   BLINK_PRESSED = 250, | 
					
						
							|  |  |  |   BLINK_UNPRESSED = 1000 | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-14 14:22:08 -04:00
										 |  |  | #define HELLO_STR   "Hello from TinyUSB\r\n"
 | 
					
						
							| 
									
										
										
										
											2019-10-18 17:50:29 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | int main(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   board_init(); | 
					
						
							| 
									
										
										
										
											2021-11-05 11:40:53 +07:00
										 |  |  |   board_led_write(true); | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |   uint32_t start_ms = 0; | 
					
						
							|  |  |  |   bool led_state = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  |   while (1) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |     uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED; | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |     // Blink every interval ms
 | 
					
						
							|  |  |  |     if ( !(board_millis() - start_ms < interval_ms) ) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-18 17:50:29 +07:00
										 |  |  |       board_uart_write(HELLO_STR, strlen(HELLO_STR)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |       start_ms = board_millis(); | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |       board_led_write(led_state); | 
					
						
							|  |  |  |       led_state = 1 - led_state; // toggle
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 17:39:47 +07:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2019-08-24 23:30:35 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-04-07 13:42:48 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 11:29:07 +01:00
										 |  |  | #if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
 | 
					
						
							| 
									
										
										
										
											2020-04-07 13:42:48 +07:00
										 |  |  | void app_main(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   main(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |