-
Notifications
You must be signed in to change notification settings - Fork 8
USBD add core-power and Vbus handle #50
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
21d87c3
84012d3
65231b0
5624172
c1cda4f
114158f
d9d1cf9
aff4105
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,16 @@ enum usbd_speed { | |
|
||
typedef enum usbd_speed usbd_speed; | ||
|
||
/** Optional features */ | ||
enum usbd_backend_features{ | ||
USBD_FEATURE_NONE = 0, | ||
USBD_PHY_EXT = (1 << 0), | ||
USBD_VBUS_SENSE = (1 << 1), | ||
USBD_VBUS_EXT = (1 << 2) | ||
//* provide usb-core auto power-up/down on connect/disconnect | ||
, USBD_USE_POWERDOWN = (1<<3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (IHMO) ", USBD_USE_POWERDOWN" code consistancy. "," not placed there. @brabo @danielinux Can you please give me a hand at code style / consistancy work. |
||
}; | ||
|
||
struct usbd_backend_config { | ||
/** Number of endpoints. (Including control endpoint) */ | ||
uint8_t ep_count; | ||
|
@@ -145,13 +155,8 @@ struct usbd_backend_config { | |
/** Device speed */ | ||
usbd_speed speed; | ||
|
||
/** Optional features */ | ||
enum { | ||
USBD_FEATURE_NONE = 0, | ||
USBD_PHY_EXT = (1 << 0), | ||
USBD_VBUS_SENSE = (1 << 1), | ||
USBD_VBUS_EXT = (1 << 2) | ||
} feature; | ||
/** Optional features see usbd_backend_features*/ | ||
unsigned int feature; | ||
}; | ||
|
||
typedef struct usbd_backend_config usbd_backend_config; | ||
|
@@ -279,7 +284,7 @@ enum usbd_transfer_flags { | |
USBD_FLAG_PACKET_PER_FRAME_MASK = (0x3 << 5) | ||
}; | ||
|
||
typedef enum usbd_transfer_flags usbd_transfer_flags; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly i There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, i know about namespaces, and that code was compiled succesfully. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you forgot to denote |
||
typedef unsigned char usbd_transfer_flags; | ||
|
||
/** | ||
* USB Transfer status | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,9 +153,19 @@ void usbd_poll(usbd_device *dev, uint32_t us) | |
|
||
void usbd_disconnect(usbd_device *dev, bool disconnect) | ||
{ | ||
if (!disconnect) { | ||
// power-up on connect | ||
if ((dev->config->feature & USBD_USE_POWERDOWN) != 0) | ||
usbd_enable(dev, true); | ||
} | ||
if (dev->backend->disconnect) { | ||
dev->backend->disconnect(dev, disconnect); | ||
} | ||
if (disconnect) { | ||
// power-down after disconnect | ||
if ((dev->config->feature & USBD_USE_POWERDOWN) != 0) | ||
usbd_enable(dev, false); | ||
} | ||
} | ||
|
||
void usbd_ep_prepare(usbd_device *dev, uint8_t addr, usbd_ep_type type, | ||
|
@@ -224,6 +234,8 @@ bool usbd_is_vbus(usbd_device *dev){ | |
} | ||
|
||
void usbd_enable(usbd_device *dev, bool onoff){ | ||
if (!onoff) | ||
usbd_disconnect(dev, false); | ||
if (dev->backend->power_control) | ||
dev->backend->power_control(dev, (onoff)? usbd_paActivate : usbd_paShutdown ); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Look at the flow of control. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don`t understand you - enable(false) MUST not shutdown? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, i see, thank you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for your new code.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, see alredy. more trouble now bother me - cant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, resolve it. but not preferable way - not like what i write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this was confused me too. disconnection MUST be provided before powerdown. but fro stm DWC core it is mean that USB enter to non-connectable state. imho, name 'disconnect' - not very suitable for this operation. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,10 +179,11 @@ struct usbd_device { | |
#endif | ||
}; | ||
|
||
typedef enum { | ||
enum _usbd_power_action{ | ||
usbd_paShutdown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
, usbd_paActivate | ||
} usbd_power_action; | ||
}; | ||
typedef enum _usbd_power_action usbd_power_action; | ||
|
||
/* Functions provided by the hardware abstraction. */ | ||
struct usbd_backend { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"//*" (IMO) Please C style comment only (code consistancy).
@danielinux @brabo what do you think?