max3421 communication work with esp32 up to enumeration, seems still have a bit of issue

This commit is contained in:
hathach 2023-09-27 12:33:36 +07:00
parent 2f6592de7f
commit 6dc64eaa28
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
4 changed files with 20 additions and 7 deletions

7
.idea/cmake.xml generated
View File

@ -56,6 +56,13 @@
<configuration PROFILE_NAME="portenta_c33" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=portenta_c33 -DLOG=3" />
<configuration PROFILE_NAME="metro_m4_express" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=metro_m4_express -DLOG=3 -DLOGGER=RTT -DMAX3421_HOST=1" />
<configuration PROFILE_NAME="metro_m0_express" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=metro_m0_express -DLOG=3 -DLOGGER=RTT -DMAX3421_HOST=1" />
<configuration PROFILE_NAME="metro esp32s2" ENABLED="false" TOOLCHAIN_NAME="ESP-IDF" GENERATION_OPTIONS="-DBOARD=adafruit_metro_esp32s2 -DMAX3421_HOST=1 -DLOG=2">
<ADDITIONAL_GENERATION_ENVIRONMENT>
<envs>
<env name="ESPBAUD" value="1500000" />
</envs>
</ADDITIONAL_GENERATION_ENVIRONMENT>
</configuration>
</configurations>
</component>
</project>

View File

@ -68,7 +68,7 @@ void cdc_app_task(void* param) {
}
}
taskYIELD();
vTaskDelay(1);
}
}

View File

@ -40,6 +40,7 @@
#include "freertos/timers.h"
#define USBH_STACK_SIZE 4096
#define CDC_STACK_SZIE 2048
#else
#include "FreeRTOS.h"
#include "semphr.h"
@ -49,9 +50,9 @@
// Increase stack size when debug log is enabled
#define USBH_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
#define CDC_STACK_SZIE (3*configMINIMAL_STACK_SIZE/2)
#endif
#define CDC_STACK_SZIE (3*configMINIMAL_STACK_SIZE/2)
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTOTYPES

View File

@ -83,7 +83,6 @@ void board_init(void) {
gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
gpio_set_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY);
#if CFG_TUD_ENABLED
// USB Controller Hal init
periph_module_reset(PERIPH_USB_MODULE);
periph_module_enable(PERIPH_USB_MODULE);
@ -93,7 +92,6 @@ void board_init(void) {
};
usb_hal_init(&hal);
configure_pins(&hal);
#endif
#if CFG_TUH_ENABLED && CFG_TUH_MAX3421
max3421_init();
@ -157,8 +155,9 @@ int board_uart_write(void const *buf, int len) {
}
int board_getchar(void) {
char c;
return (uart_read_bytes(UART_NUM_0, &c, 1, 0) > 0) ? (int) c : (-1);
// char c;
// return (uart_read_bytes(UART_NUM_0, &c, 1, 0) > 0) ? (int) c : (-1);
return -1;
}
//--------------------------------------------------------------------+
@ -187,7 +186,7 @@ static void max3421_intr_task(void* param) {
while (1) {
xSemaphoreTake(max3421_intr_sem, portMAX_DELAY);
tuh_int_handler(BOARD_TUH_RHPORT);
hcd_int_handler_ext(BOARD_TUH_RHPORT, false);
}
}
@ -251,6 +250,12 @@ void tuh_max3421_spi_cs_api(uint8_t rhport, bool active) {
bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf, size_t tx_len, uint8_t *rx_buf, size_t rx_len) {
(void) rhport;
if (tx_len == 0) {
// fifo read, transmit rx_buf as dummy
tx_buf = rx_buf;
tx_len = rx_len;
}
spi_transaction_t xact = {
.length = tx_len << 3, // length in bits
.rxlength = rx_len << 3, // length in bits