Merge pull request #2571 from hathach/fix-max3421-rp2040-build

fix build with rp2040 + max3421
This commit is contained in:
Ha Thach 2024-04-04 14:35:29 +07:00 committed by GitHub
commit 177b388be0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 46 deletions

View File

@ -113,6 +113,7 @@ CFLAGS += -DBOARD_$(BOARD_UPPER)
ifeq (${MAX3421_HOST},1)
SRC_C += src/portable/analog/max3421/hcd_max3421.c
CFLAGS += -DCFG_TUH_MAX3421=1
CMAKE_DEFSYM += -DMAX3421_HOST=1
endif
# Log level is mapped to TUSB DEBUG option

View File

@ -0,0 +1 @@
mcu:RP2040

View File

@ -79,17 +79,27 @@ set(WARNING_FLAGS_IAR "")
function(family_filter RESULT DIR)
get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if (EXISTS "${DIR}/only.txt")
file(READ "${DIR}/only.txt" ONLYS)
# Replace newlines with semicolon so that it is treated as a list by CMake
string(REPLACE "\n" ";" ONLYS_LINES ${ONLYS})
if (EXISTS "${DIR}/skip.txt")
file(STRINGS "${DIR}/skip.txt" SKIPS_LINES)
foreach(MCU IN LISTS FAMILY_MCUS)
# For each line in only.txt
foreach(_line ${SKIPS_LINES})
# If mcu:xxx exists for this mcu then skip
if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}" OR ${_line} STREQUAL "family:${FAMILY}")
set(${RESULT} 0 PARENT_SCOPE)
return()
endif()
endforeach()
endforeach()
endif ()
# For each mcu
if (EXISTS "${DIR}/only.txt")
file(STRINGS "${DIR}/only.txt" ONLYS_LINES)
foreach(MCU IN LISTS FAMILY_MCUS)
# For each line in only.txt
foreach(_line ${ONLYS_LINES})
# If mcu:xxx exists for this mcu or board:xxx then include
if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}")
if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}" OR ${_line} STREQUAL "family:${FAMILY}")
set(${RESULT} 1 PARENT_SCOPE)
return()
endif()
@ -98,29 +108,8 @@ function(family_filter RESULT DIR)
# Didn't find it in only file so don't build
set(${RESULT} 0 PARENT_SCOPE)
elseif (EXISTS "${DIR}/skip.txt")
file(READ "${DIR}/skip.txt" SKIPS)
# Replace newlines with semicolon so that it is treated as a list by CMake
string(REPLACE "\n" ";" SKIPS_LINES ${SKIPS})
# For each mcu
foreach(MCU IN LISTS FAMILY_MCUS)
# For each line in only.txt
foreach(_line ${SKIPS_LINES})
# If mcu:xxx exists for this mcu then skip
if (${_line} STREQUAL "mcu:${MCU}")
set(${RESULT} 0 PARENT_SCOPE)
return()
endif()
endforeach()
endforeach()
# Didn't find in skip file so build
set(${RESULT} 1 PARENT_SCOPE)
else()
# Didn't find skip or only file so build
# only.txt not exist so build
set(${RESULT} 1 PARENT_SCOPE)
endif()
endfunction()

View File

@ -0,0 +1,4 @@
set(PICO_BOARD adafruit_feather_rp2040)
# Enable MAX3421E USB Host
set(MAX3421_HOST 1)

View File

@ -654,7 +654,7 @@ static void xact_generic(uint8_t rhport, max3421_ep_t *ep, bool switch_ep, bool
// status
if (ep->buf == NULL || ep->total_len == 0) {
uint8_t const hxfr = HXFR_HS | (ep->hxfr_bm.is_out ? HXFR_OUT_NIN : 0);
uint8_t const hxfr = (uint8_t) (HXFR_HS | (ep->hxfr & HXFR_OUT_NIN));
peraddr_write(rhport, ep->daddr, in_isr);
hxfr_write(rhport, hxfr, in_isr);
return;
@ -676,19 +676,18 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buf
max3421_ep_t* ep = find_opened_ep(daddr, ep_num, ep_dir);
TU_VERIFY(ep);
// control transfer can switch direction
ep->hxfr_bm.is_out = ep_dir ? 0u : 1u;
if (ep_num == 0) {
// control transfer can switch direction
ep->hxfr_bm.is_out = ep_dir ? 0 : 1;
ep->hxfr_bm.is_setup = 0;
ep->data_toggle = 1;
}
ep->buf = buffer;
ep->total_len = buflen;
ep->xferred_len = 0;
ep->state = EP_STATE_ATTEMPT_1;
if (ep_num == 0) {
ep->hxfr_bm.is_setup = 0;
ep->data_toggle = 1;
}
// carry out transfer if not busy
if (!atomic_flag_test_and_set(&_hcd_data.busy)) {
xact_generic(rhport, ep, true, false);

View File

@ -64,18 +64,19 @@ def skip_example(example, board):
skip_file = ex_dir / "skip.txt"
only_file = ex_dir / "only.txt"
if skip_file.exists() and only_file.exists():
raise RuntimeError("Only have a skip or only file. Not both.")
elif skip_file.exists():
if skip_file.exists():
skips = skip_file.read_text().split()
return ("mcu:" + mcu in skips or
"board:" + board in skips or
"family:" + family in skips)
elif only_file.exists():
if ("mcu:" + mcu in skips or
"board:" + board in skips or
"family:" + family in skips):
return True
if only_file.exists():
onlys = only_file.read_text().split()
return not ("mcu:" + mcu in onlys or
"board:" + board in onlys or
"family:" + family in onlys)
if not ("mcu:" + mcu in onlys or
"board:" + board in onlys or
"family:" + family in onlys):
return True
return False