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

CHCh Upgrade: Improved FTDI and CP210x support, add PL2303 support, bugfixes #2488

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

IngHK
Copy link

@IngHK IngHK commented Feb 22, 2024

This PR is the kick-off of the series of single commits, which should result in the following improvements:

  • Improved support of FTDI: support of all popular types (B/R/H, single and multiple channels), support of set line coding, data format, baudrate, line state
  • Improved support of CP210x: support of set line coding, data format, baudrate, line state
  • Added PL2303 support
  • Added continuation of enumeration after TU_ASSERT
  • Bugfix CH34x ch34x_set_line_coding() callback bug #2448 and several other bugfixes

I think, it's easier to review the changes commit for commit.
After review of each commit, I'll implement and commit it together with the next improvement.
So this PR should be first merged to master at the end.
OK?

@hathach
Copy link
Owner

hathach commented Feb 23, 2024

@IngHK thank you, though don't worry too much about the number of commits etc, just make it convenient for you. I don't always have time to review things (pending PRs is already long enough), but small change is indeed easier to review. So just group thing together as long as you think that make sense. The current PR only update comment, do you have anything to push more or you want to merge this as it is.

@IngHK
Copy link
Author

IngHK commented Feb 23, 2024

@IngHK thank you, though don't worry too much about the number of commits etc, just make it convenient for you. I don't always have time to review things (pending PRs is already long enough), but small change is indeed easier to review. So just group thing together as long as you think that make sense. The current PR only update comment, do you have anything to push more or you want to merge this as it is.

Yes, I know, the first commit is pretty small, only to warm up ;-)
The next commit sorts the diver functions into the sections Control Request, Driver API, Enumeration and Helper like the CH34x.
There are no functional changes, only code movement.

@IngHK
Copy link
Author

IngHK commented Feb 23, 2024

The last commit improves the TU_LOGs.
It standardizes the logs with a uniform beginning "[:dadr:itf_num] CHCh drivername ...".
And it moves the logs from the driver to the common cdc section.
Here an example output:

image

I think these are commits that need to be reviewed first.
After the review and, if necessary, my follow-up work, I will push further commits

@hathach
Copy link
Owner

hathach commented Feb 24, 2024

@IngHK I appreciated your effor to break it out, but please push everything you think work best. Otherwise this make take several months to complete this whole process. I would like to merge portion of code once it is reviewed, and I may only have time to review this 1 or 2 times a month or so. Last time, I could focus on the PR since I need to get ch34x driver running for another paid works.

@IngHK
Copy link
Author

IngHK commented Feb 24, 2024

@hathach OK, no problem, we'll do it the way that suits you best.
Now I've pushed everything.
I'm currently writing a small test suite to do the tests with hardware.

@@ -422,127 +421,6 @@ bool tuh_cdc_read_clear (uint8_t idx) {
// Control Endpoint API
//--------------------------------------------------------------------+

static void process_internal_control_complete(tuh_xfer_t* xfer, uint8_t itf_num) {
Copy link
Author

Choose a reason for hiding this comment

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

The intention here was to move the driver-specific code parts into the driver sections so that the general CDC section does not contain any driver code (as possible).
In addition, cdch_internal_control_complete() had become quite bloated and confusing.

bool (*const set_baudrate)(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
bool (*const set_data_format)(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
bool (*const set_line_coding)(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
bool (*const set_baudrate)(cdch_interface_t* p_cdc, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
Copy link
Author

Choose a reason for hiding this comment

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

The intention here was to simplify the parameter passing of the Control Endpoint API calls to the driver functions.
p_cdc->requested_line_coding was already available for FTDI, CP210X and CH34X anyway.
And it makes the internal control complete functions safe and easy.

@@ -421,115 +421,101 @@ bool tuh_cdc_read_clear (uint8_t idx) {
// Control Endpoint API
//--------------------------------------------------------------------+

bool tuh_cdc_set_control_line_state(uint8_t idx, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
Copy link
Author

@IngHK IngHK Feb 24, 2024

Choose a reason for hiding this comment

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

Since the central flow code of tuh_cdc_set_control_line_state(), tuh_cdc_set_baudrate(), tuh_cdc_set_data_format() and tuh_cdc_set_line_coding() is identical and very tricky, it was outsourced to the common subfunction set_function_call(), which calls the regarding driver's function.
Here you see, why I moved (among other things) the requested line coding and line state into p_cdc->requested..., because it also simplifies the parameter transfer from Control Endpoint API to Driver API independent of the upper mentoined API functions

TU_LOG_P_CDC("set config complete");
p_cdc->mounted = true;
if (tuh_cdc_mount_cb) tuh_cdc_mount_cb(idx);
static void set_config_complete(uint8_t idx, uint8_t itf_offset, bool success) {
Copy link
Author

Choose a reason for hiding this comment

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

now the enumeration will continue, even if a process config fails

@IngHK
Copy link
Author

IngHK commented Feb 24, 2024

I always see the IAR build fail, but with no relation to CDCh. Is it OK?

static uint16_t const pl2303_vid_pid_list[][2] = {CFG_TUH_CDC_PL2303_VID_PID_LIST};
static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {PL2303_TYPE_DATA};

CFG_TUH_MEM_SECTION CFG_TUH_MEM_ALIGN
Copy link
Collaborator

Choose a reason for hiding this comment

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

IAR built fail is due to this extra statement.

// TODO not implemented yet
return false;
static void ftdi_set_line_coding_stage1_complete(tuh_xfer_t * xfer) {
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
Copy link
Author

Choose a reason for hiding this comment

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

here is a bug.
will be fixed in a subsequent commit.

@hathach
Copy link
Owner

hathach commented Feb 28, 2024

thank you very much, I wil review this whenever I could.

@IngHK
Copy link
Author

IngHK commented Mar 14, 2024

If it's easier for you than one huge PR, then I can split it up into smaller PRs that only contain individual and self-contained feature changes

@IngHK
Copy link
Author

IngHK commented Apr 4, 2024

OK. I finished work for now.
It's ready for review and merge

@hathach
Copy link
Owner

hathach commented Apr 8, 2024

thank you, please give me a bit of time to review.

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.

None yet

4 participants