Skip to content

Commit 258748e

Browse files
authored
Merge pull request #20 from teamfinalmouse/tinyusb
2 parents 0ea682f + 784569f commit 258748e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4294
-7997
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
steps:
1616
- name: Checkout code
1717
uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
1820

1921
- name: Install arm-none-eabi-gcc toolchain
2022
run: |

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "libs/tinyusb"]
2+
path = libs/tinyusb
3+
url = https://github.com/hathach/tinyusb.git
4+
[submodule "libs/lv_drivers"]
5+
path = libs/lv_drivers
6+
url = https://github.com/lvgl/lv_drivers.git

CMakeLists.txt

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ set(CMAKE_C_FLAGS_RELEASE "-Os")
1919
set(CMAKE_CXX_FLAGS_RELEASE "-Os")
2020
set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s)
2121

22-
# Define the application version
23-
set(APP_VERSION_MAJOR 1)
24-
set(APP_VERSION_MINOR 4)
25-
set(APP_VERSION_PATCH 0) # patch level 99 = work-in-progress for next release
26-
set(APP_VERSION_STRING "${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_PATCH}")
22+
# Include version definitions
23+
include(version.cmake)
2724

2825
add_compile_options(
2926
${CPU_OPTIONS}
@@ -55,6 +52,7 @@ include_directories(
5552
${CMAKE_SOURCE_DIR}/libs/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1
5653
${CMAKE_SOURCE_DIR}/libs/lufa
5754
${CMAKE_SOURCE_DIR}/libs/lvgl
55+
${CMAKE_SOURCE_DIR}/libs/tinyusb/include
5856
${CMAKE_SOURCE_DIR}/libs/RTT/RTT
5957
${CMAKE_SOURCE_DIR}/src
6058
${CMAKE_SOURCE_DIR}/src/config
@@ -133,17 +131,6 @@ set(LUFA_Sources
133131
libs/lufa/Drivers/USB/Class/Common/HIDParser.c
134132
)
135133

136-
set(USB_Sources
137-
src/usb/usbh_conf.c
138-
src/usb/usb_host.c
139-
src/usb/usbh_core.c
140-
src/usb/usbh_ctlreq.c
141-
src/usb/usbh_ioreq.c
142-
src/usb/usbh_pipes.c
143-
src/usb/usbh_hid.c
144-
src/usb/usbh_hid_mouse.c
145-
)
146-
147134
add_definitions(
148135
-DSTM32
149136
-DSTM32F7
@@ -157,6 +144,15 @@ add_definitions(
157144
)
158145

159146
add_subdirectory(libs/lvgl)
147+
add_subdirectory(libs/tinyusb/src)
148+
149+
set(TINYUSB_Sources
150+
src/usb_task.c
151+
src/tinyusb_hid_app.c
152+
libs/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c
153+
libs/tinyusb/src/portable/synopsys/dwc2/hcd_dwc2.c
154+
libs/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
155+
)
160156

161157
target_compile_options(lvgl PRIVATE -DSTM32F7)
162158

@@ -175,6 +171,7 @@ add_executable(${PROJECT_NAME}
175171
src/syscalls.c
176172
src/system_stm32f7xx.c
177173
src/xlat.c
174+
src/xlat_config.c
178175
src/theme/xlat_fm_logo_130px.c
179176
drivers/tft/tft.c
180177
drivers/touchpad/touchpad.c
@@ -183,23 +180,10 @@ add_executable(${PROJECT_NAME}
183180
${LUFA_Sources}
184181
${FREERTOS_Sources}
185182
${RTT_Sources}
186-
${USB_Sources}
183+
${TINYUSB_Sources}
187184
)
188185

189-
# Get the GIT SHA
190-
execute_process(
191-
COMMAND git rev-parse --short HEAD
192-
OUTPUT_VARIABLE GIT_SHA
193-
OUTPUT_STRIP_TRAILING_WHITESPACE
194-
)
195-
196-
target_compile_definitions(${PROJECT_NAME} PRIVATE -DGIT_SHA="${GIT_SHA}")
197-
198-
target_compile_definitions(${PROJECT_NAME} PRIVATE -DAPP_VERSION_MAJOR=${APP_VERSION_MAJOR})
199-
target_compile_definitions(${PROJECT_NAME} PRIVATE -DAPP_VERSION_MINOR=${APP_VERSION_MINOR})
200-
target_compile_definitions(${PROJECT_NAME} PRIVATE -DAPP_VERSION_PATCH=${APP_VERSION_PATCH})
201-
target_compile_definitions(${PROJECT_NAME} PRIVATE -DAPP_VERSION="${APP_VERSION_STRING}")
202-
target_compile_definitions(${PROJECT_NAME} PRIVATE -DAPP_VERSION_FULL="${APP_VERSION_STRING}-${GIT_SHA}")
186+
tinyusb_target_add(${PROJECT_NAME})
203187

204188
target_link_libraries(${PROJECT_NAME}
205189
${CPU_OPTIONS}
@@ -219,7 +203,19 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
219203
)
220204

221205
add_custom_target(${PROJECT_NAME}.bin ALL DEPENDS ${PROJECT_NAME})
222-
add_custom_command(TARGET ${PROJECT_NAME}.bin
206+
add_custom_command(TARGET ${PROJECT_NAME}.bin POST_BUILD
223207
COMMAND ${CMAKE_C_OBJCOPY} ARGS -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.bin)
224208

209+
# Test target configuration
210+
add_custom_target(test
211+
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/test
212+
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/test ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}/test
213+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/test
214+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
215+
COMMENT "Building and running tests"
216+
)
217+
218+
# Add test target as a dependency to the main target
219+
# add_dependencies(${PROJECT_NAME} test)
220+
225221
set_property(TARGET ${PROJECT_NAME} PROPERTY LINK_DEPENDS ${CMAKE_SOURCE_DIR}/${LINKER_SCRIPT})

libs/lv_drivers

Submodule lv_drivers added at 49c4b17

libs/tinyusb

Submodule tinyusb added at 0c58188

src/config/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#define configTICK_RATE_HZ ((TickType_t)1000)
6666
#define configMAX_PRIORITIES ( 7 )
6767
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
68-
#define configTOTAL_HEAP_SIZE ((size_t)32768 / 2)
68+
#define configTOTAL_HEAP_SIZE ((size_t)32768)
6969
#define configMAX_TASK_NAME_LEN ( 16 )
7070
#define configUSE_16_BIT_TICKS 0
7171
#define configUSE_MUTEXES 1

src/config/lv_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#define LV_MEM_CUSTOM 0
5050
#if LV_MEM_CUSTOM == 0
5151
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
52-
# define LV_MEM_SIZE (16U * 1024U) /*[bytes]*/
52+
# define LV_MEM_SIZE (32U * 1024U) /*[bytes]*/
5353

5454
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
5555
# define LV_MEM_ADR 0 /*0: unused*/

src/config/tusb_config.h

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
*/
25+
26+
#ifndef _TUSB_CONFIG_H_
27+
#define _TUSB_CONFIG_H_
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
//--------------------------------------------------------------------
34+
// Override Assert Handler
35+
//--------------------------------------------------------------------
36+
#include "stm32f7xx_hal.h"
37+
#include <stdio.h>
38+
39+
#define CUSTOM_TU_ASSERT_DEFINE(_cond, _ret) \
40+
do { \
41+
if ( !(_cond) ) { \
42+
printf("ASSERT FAILED in %s at line %d\r\n", __func__, __LINE__); \
43+
TU_BREAKPOINT(); /* break if in debugger */ \
44+
HAL_Delay(1000); /* 1 second delay before reboot */ \
45+
NVIC_SystemReset(); /* Reboot the system */ \
46+
} \
47+
} while(0)
48+
49+
#define CUSTOM_TU_ASSERT_1ARGS(_cond) CUSTOM_TU_ASSERT_DEFINE(_cond, false)
50+
#define CUSTOM_TU_ASSERT_2ARGS(_cond, _ret) CUSTOM_TU_ASSERT_DEFINE(_cond, _ret)
51+
#define CUSTOM_TU_GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
52+
53+
// Override the default TU_ASSERT macro to print the assert message and reboot
54+
#undef TU_ASSERT
55+
#define TU_ASSERT(...) CUSTOM_TU_GET_3RD_ARG(__VA_ARGS__, CUSTOM_TU_ASSERT_2ARGS, CUSTOM_TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
56+
57+
58+
//--------------------------------------------------------------------
59+
// Common Configuration
60+
//--------------------------------------------------------------------
61+
62+
// defined by compiler flags for flexibility
63+
#ifndef CFG_TUSB_MCU
64+
#define CFG_TUSB_MCU OPT_MCU_STM32F7
65+
#endif
66+
67+
/* -DCFG_TUSB_MCU=OPT_MCU_STM32H7 \
68+
* -DBOARD_TUD_RHPORT=${RHPORT_DEVICE} \
69+
* -DBOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} \
70+
* -DBOARD_TUH_RHPORT=${RHPORT_HOST} \
71+
* -DBOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} \
72+
*/
73+
74+
#ifndef CFG_TUSB_OS
75+
#define CFG_TUSB_OS OPT_OS_FREERTOS
76+
#endif
77+
78+
#ifndef CFG_TUSB_DEBUG
79+
#define CFG_TUSB_DEBUG 0
80+
#endif
81+
82+
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
83+
* Tinyusb use follows macros to declare transferring memory so that they can be put
84+
* into those specific section.
85+
* e.g
86+
* - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
87+
* - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
88+
*/
89+
#ifndef CFG_TUH_MEM_SECTION
90+
#define CFG_TUH_MEM_SECTION
91+
#endif
92+
93+
#ifndef CFG_TUH_MEM_ALIGN
94+
#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4)))
95+
#endif
96+
97+
//--------------------------------------------------------------------
98+
// Host Configuration
99+
//--------------------------------------------------------------------
100+
101+
// Enable Host stack
102+
#define CFG_TUH_ENABLED 1
103+
104+
// Default is max speed that hardware controller could support with on-chip PHY
105+
#define CFG_TUH_MAX_SPEED OPT_MODE_HIGH_SPEED
106+
107+
//------------------------- Board Specific --------------------------
108+
109+
// RHPort number used for host can be defined by board.mk, default to port 1 (HS port)
110+
#ifndef BOARD_TUH_RHPORT
111+
#define BOARD_TUH_RHPORT 1
112+
#endif
113+
114+
// RHPort max operational speed can defined by board.mk
115+
#ifndef BOARD_TUH_MAX_SPEED
116+
#define BOARD_TUH_MAX_SPEED OPT_MODE_HIGH_SPEED
117+
#endif
118+
119+
//--------------------------------------------------------------------
120+
// Driver Configuration
121+
//--------------------------------------------------------------------
122+
123+
// Size of buffer to hold descriptors and other data used for enumeration
124+
#define CFG_TUH_ENUMERATION_BUFSIZE 512
125+
126+
#define CFG_TUH_HUB 1 // number of supported hubs
127+
#define CFG_TUH_CDC 0 // CDC ACM
128+
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
129+
#define CFG_TUH_MSC 0
130+
#define CFG_TUH_VENDOR 0
131+
132+
// max device support (excluding hub device): 1 hub typically has 4 ports
133+
#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
134+
135+
//------------- HID -------------//
136+
#define CFG_TUH_HID_EPIN_BUFSIZE 64
137+
#define CFG_TUH_HID_EPOUT_BUFSIZE 64
138+
139+
140+
#ifdef __cplusplus
141+
}
142+
#endif
143+
144+
#endif /* _TUSB_CONFIG_H_ */

0 commit comments

Comments
 (0)