Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max3421e host driver #2251

Merged
merged 35 commits into from
Sep 11, 2023
Merged

Add max3421e host driver #2251

merged 35 commits into from
Sep 11, 2023

Conversation

hathach
Copy link
Owner

@hathach hathach commented Sep 11, 2023

Describe the PR

  • Add support driver for Analog MAX3421e usb host controller via SPI aka Arduino USB Host shield. The driver requires 3 api implmented by application
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 tuh_max3421_int_api(uint8_t rhport, bool enabled);
  • tested on feather nrf52840 express, metro m0/m4 (samd21 samd51)
  • To enable max3421 driver for host examples, MAX3421_HOST=1 must be added to makefile and cmake build command e.g
    • make BOARD=feather_nrf52840_express MAX3421_HOST=1 all
    • cmake .. -DBOARD=feather_nrf52840_express -DMAX3421_HOST=1
  • For ci purpose, max3421 host driver is always enabled for feather nrf52840 express board (to test compipling driver)
  • also add cmake support for nrf
  • Other clean up
    • Remove TU_LOG_PTR, rename TU_LOG_ARR to TU_LOG_BUF
    • add hcd_template.c
    • define tuh_int_handler/tud_int_handler to empty when corressponding stack not enabled.

TODO: more ports to be tested with later on: esp32

- add empty tuh_int_handler/tud_int_handler if corresponidng stack not enabled
- add hcd_template.c
- rename max3421e to max3421
- fix incorrect bitmask for HCTL, fix initial device connect
- fix bus reset cause connect IRQ
- merge addr0 ep to pool
- add control status to xact in/out
- use atomic flag busy to ensure only 1 transfer is active at any time
- execute pending transfer after one is complete (or clear busy flag)
- change rtt mode to block if full
- hcd_int_disable/enable is software only to reduce interrupt lag
- xact_inout() to support send setup
…e when CONDETIRQ occurs but we are disabled interrupt (for osal queue access).
@hathach hathach merged commit 6d922de into master Sep 11, 2023
79 checks passed
@hathach hathach deleted the add-max3421e-hcd branch September 11, 2023 15:22
Copy link
Collaborator

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we dynamically initialize this? In CP, we'll want the code but not the data structures until we know we need it. Maybe a struct with all needed buffers/data and function pointers to the SPI API?

@hathach hathach mentioned this pull request Sep 12, 2023
1 task
@hathach
Copy link
Owner Author

hathach commented Sep 12, 2023

For now, you need to enable the host driver with CFG_TUH_MAX3421=1, this will also include driver internal data https://github.com/hathach/tinyusb/blob/master/src/portable/analog/max3421/hcd_max3421.c#L205. If you want to supply the internal data when needed we probably need some kind of malloc-like callback (malloc when init host stack, free when de-init). It will probably need its own PR since there is a few request for more dyanmic memory for class drivers (since not all enabled driveres are included in the descritpors)

The driver requires 3 api implmented by application

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 tuh_max3421_int_api(uint8_t rhport, bool enabled);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants