| 
									
										
										
										
											2019-03-20 16:11:42 +07:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |  * The MIT License (MIT) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2018, hathach (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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is part of the TinyUSB stack. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-02 13:41:35 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** \ingroup group_demo
 | 
					
						
							|  |  |  |  * \defgroup group_board Boards Abstraction Layer | 
					
						
							|  |  |  |  *  @{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-13 12:32:15 +07:00
										 |  |  | #ifndef _BSP_BOARD_H_
 | 
					
						
							|  |  |  | #define _BSP_BOARD_H_
 | 
					
						
							| 
									
										
										
										
											2018-03-02 13:41:35 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  |  extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | #include <stdbool.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ansi_escape.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 22:31:07 +07:00
										 |  |  | #include "tusb.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-13 12:32:15 +07:00
										 |  |  | #define CFG_UART_BAUDRATE    115200
 | 
					
						
							| 
									
										
										
										
											2019-03-23 22:31:07 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 22:06:48 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // Board Porting API
 | 
					
						
							| 
									
										
										
										
											2019-04-01 18:31:20 +07:00
										 |  |  | // For simplicity, only one LED and one Button are used
 | 
					
						
							| 
									
										
										
										
											2019-03-22 22:06:48 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2018-03-02 13:41:35 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 22:06:48 +07:00
										 |  |  | // Initialize on-board peripherals : led, button, uart and USB
 | 
					
						
							| 
									
										
										
										
											2018-03-02 13:41:35 +07:00
										 |  |  | void board_init(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 22:06:48 +07:00
										 |  |  | // Turn LED on or off
 | 
					
						
							| 
									
										
										
										
											2019-04-02 18:16:04 +07:00
										 |  |  | void board_led_write(bool state); | 
					
						
							| 
									
										
										
										
											2018-03-13 16:30:53 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-01 18:31:20 +07:00
										 |  |  | // Get the current state of button
 | 
					
						
							|  |  |  | // a '1' means active (pressed), a '0' means inactive.
 | 
					
						
							|  |  |  | uint32_t board_button_read(void); | 
					
						
							| 
									
										
										
										
											2019-03-22 22:06:48 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Get characters from UART
 | 
					
						
							|  |  |  | int board_uart_read(uint8_t* buf, int len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Send characters to UART
 | 
					
						
							|  |  |  | int board_uart_write(void const * buf, int len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 22:31:07 +07:00
										 |  |  | #if CFG_TUSB_OS == OPT_OS_NONE
 | 
					
						
							| 
									
										
										
										
											2019-04-01 18:31:20 +07:00
										 |  |  |   // Get current milliseconds, must be implemented when no RTOS is used
 | 
					
						
							|  |  |  |   uint32_t board_millis(void); | 
					
						
							| 
									
										
										
										
											2019-03-23 22:31:07 +07:00
										 |  |  | #elif CFG_TUSB_OS == OPT_OS_FREERTOS
 | 
					
						
							| 
									
										
										
										
											2019-04-01 18:31:20 +07:00
										 |  |  |   static inline uint32_t board_millis(void) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     return ( ( ((uint64_t) xTaskGetTickCount()) * 1000) / configTICK_RATE_HZ ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-23 22:31:07 +07:00
										 |  |  | #elif CFG_TUSB_OS == OPT_OS_MYNEWT
 | 
					
						
							| 
									
										
										
										
											2019-04-01 18:31:20 +07:00
										 |  |  |   static inline uint32_t board_millis(void) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     return os_time_ticks_to_ms32( os_time_get() ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-24 01:19:32 +07:00
										 |  |  | #elif
 | 
					
						
							| 
									
										
										
										
											2019-04-01 18:31:20 +07:00
										 |  |  |   #error "Need to implement board_millis() for this OS"
 | 
					
						
							| 
									
										
										
										
											2019-03-23 22:31:07 +07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-03-23 16:51:07 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 22:06:48 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // Helper functions
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2018-12-03 18:48:43 +07:00
										 |  |  | static inline void board_led_on(void) | 
					
						
							| 
									
										
										
										
											2018-03-13 16:30:53 +07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-02 18:16:04 +07:00
										 |  |  |   board_led_write(true); | 
					
						
							| 
									
										
										
										
											2018-03-13 16:30:53 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 18:48:43 +07:00
										 |  |  | static inline void board_led_off(void) | 
					
						
							| 
									
										
										
										
											2018-03-13 16:30:53 +07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-02 18:16:04 +07:00
										 |  |  |   board_led_write(false); | 
					
						
							| 
									
										
										
										
											2018-03-13 16:30:53 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 22:31:35 +07:00
										 |  |  | static inline void board_delay(uint32_t ms) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uint32_t start_ms = board_millis(); | 
					
						
							|  |  |  |   while( board_millis() < start_ms + ms) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-20 20:58:27 +07:00
										 |  |  | static inline int8_t board_uart_getchar(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uint8_t c; | 
					
						
							|  |  |  |   return board_uart_read(&c, 1) ? c : (-1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline int board_uart_putchar(uint8_t c) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return board_uart_write(&c, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 13:41:35 +07:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  |  } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-13 12:32:15 +07:00
										 |  |  | #endif /* _BSP_BOARD_H_ */
 | 
					
						
							| 
									
										
										
										
											2018-03-02 13:41:35 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @} */ |