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

Usbc source #52993

Merged
merged 7 commits into from
Apr 28, 2023
Merged

Usbc source #52993

merged 7 commits into from
Apr 28, 2023

Conversation

sambhurst
Copy link
Contributor

Adds Power Delivery Source Support to the USB-C Stack. See Issue 38371 for details

@fabiobaltieri
Copy link
Member

Hey @sambhurst, do you think it would make sense to regroup the commints in smaller PRs? Looks like there's a mix of refactoring/preparation, board specific changes, bug fixes and then the main feature. Thinking having more small PRs may make it easier to review and hopefully get it merged faster, and also make it easier to maintain the stack through the reviews.

subsys/usb/usb_c/usbc_pe_common.c Show resolved Hide resolved
subsys/usb/usb_c/usbc_pe_common.c Outdated Show resolved Hide resolved
Comment on lines 174 to 181
* @brief Callback type used to get the Sink Capabilities
*
* @param dev dev Runtime device structure
* @param pdos pointer where pdos are stored
* @param num_pdos pointer where number of pdos is stored
* @return 0 on success
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit- put the callback descriptions for the SNK into a separate commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, please put the src/snk/common callbacks into their own doxygen groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add this group to the API reference section of ucds.rst.

@@ -14,7 +14,7 @@ It provides the following functionalities:
The APIs is described in
:zephyr_file:`include/zephyr/usb_c/usbc.h`

Currently the device stack only support implementation of Sink devices.
Currently the device stack supports implementation of Sink and Source devices.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Currently the device stack supports implementation of Sink and Source devices.
Currently the device stack supports implementation of Sink only and Source only devices. Dual Role Power (DRP) devices are not yet supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Transmit errors must be treated differently than Protocol Errors.
This change sets a flag that informs the stack of a Message
Transmit error.

Signed-off-by: Sam Hurst <[email protected]>
@sambhurst sambhurst force-pushed the usbc_source branch 2 times, most recently from e0c9c30 to e2e3a4e Compare April 24, 2023 01:51
Copy link
Contributor

@alevkoy alevkoy left a comment

Choose a reason for hiding this comment

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

I still have some comments open from my March 27 and 28 reviews. Mostly LGTM.

subsys/usb/usb_c/usbc_pe_common.c Outdated Show resolved Hide resolved
subsys/usb/usb_c/usbc_pe_common.c Outdated Show resolved Hide resolved
subsys/usb/usb_c/usbc_pe_common.c Show resolved Hide resolved
Comment on lines 174 to 181
* @brief Callback type used to get the Sink Capabilities
*
* @param dev dev Runtime device structure
* @param pdos pointer where pdos are stored
* @param num_pdos pointer where number of pdos is stored
* @return 0 on success
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add this group to the API reference section of ucds.rst.

/**
* @brief Callback type used to get the Sink Capabilities
*
* @param dev dev Runtime device structure
Copy link
Contributor

Choose a reason for hiding this comment

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

Please specify the type of device passed in for all these prototypes.

Suggested change
* @param dev dev Runtime device structure
* @param dev USB-C Connector Instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

include/zephyr/usb_c/usbc.h Show resolved Hide resolved
Comment on lines 289 to 291
typedef enum usbc_snk_req_reply_t (*policy_cb_check_sink_request_t)(
const struct device *dev,
const uint32_t request_msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this file needs clang-format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* @param dev dev Runtime device structure
* @return true if power supply is ready, else false
*/
typedef bool (*policy_cb_check_if_ps_ready_t)(const struct device *dev);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - you could name this policy_cb_is_ps_ready_t

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* @param present_contract present contract
* @return true if present contract is still valid
*/
typedef bool (*policy_cb_check_present_contract_t)(const struct device *dev,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - policy_cb_present_contract_is_valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

typedef bool (*policy_cb_change_src_caps_t)(const struct device *dev);

/**
* @brief Callback type used to store the Capabilities received from
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @brief Callback type used to store the Capabilities received from
* @brief Callback type used to report the Capabilities received from

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

subsys/usb/usb_c/usbc_pe_common.c Outdated Show resolved Hide resolved
subsys/usb/usb_c/usbc_pe_common.c Outdated Show resolved Hide resolved
/**
* @brief Callback type used to check a policy
*
* @param dev dev Runtime device structure
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param dev dev Runtime device structure
* @param dev USB-C Connector Instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

include/zephyr/usb_c/usbc.h Show resolved Hide resolved
* @brief Callback type used to get the Rp value that should be placed on
* the CC lines
*
* @param dev dev Runtime device structure
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param dev dev Runtime device structure
* @param dev USB-C Connector Instance

Replace all instances for the APIs your are introducing in this commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Document the sink callbacks

Signed-off-by: Sam Hurst <[email protected]>
Detect and flag the reception of the first AMS mesage

Signed-off-by: Sam Hurst <[email protected]>
Refactor soft reset code

Signed-off-by: Sam Hurst <[email protected]>
Copy link
Contributor

@keith-zephyr keith-zephyr left a comment

Choose a reason for hiding this comment

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

One last nit on the documentation from me.

* the CC lines
*
* @param dev USB-C Connector Instance
* @param rp
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing description for the rp parameter. I thought the CI had checks for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Add USB-C Power Delivery Source Support to USB-C
Subsystem

Signed-off-by: Sam Hurst <[email protected]>
Implementing USB-C Source functionality can be difficult.
This sample application serves as an example of how
to create an application with Power Delivery Source
functionality.

Signed-off-by: Sam Hurst <[email protected]>
Documents the USB-C Source Subsystem API.

Signed-off-by: Sam Hurst <[email protected]>
@carlescufi carlescufi merged commit 714eec8 into zephyrproject-rtos:main Apr 28, 2023
@sambhurst sambhurst deleted the usbc_source branch May 2, 2023 17:59
Comment on lines +247 to +263
* @brief Callback type used to get the Rp value that should be placed on
* the CC lines
*
* @param dev USB-C Connector Instance
* @param rp Rp value
* @return 0 on success
*/
typedef int (*policy_cb_get_src_rp_t)(const struct device *dev, enum tc_rp_value *rp);

/**
* @brief Callback type used to enable VBUS
*
* @param dev USB-C Connector Instance
* @param en true to enable VBUS, else disable it
* @return 0 on success
*/
typedef int (*policy_cb_src_en_t)(const struct device *dev, bool en);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sambhurst this is defined again in in L324-340. I am not sure why this wasn't caught by Doxygen (although I just had Doxygen 1.9.4 spit out a warning). I will submit a fix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus area: USB-C platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.