usb: device_next: rename usbd_class_iter to usbd_class_node
For the last dozen commits, the role of usbd_class_node has actually been taken over by usbd_class_iter. After cleaning up and merging usbd_class_node and usbd_class_data, we can rename usbd_class_iter to usbd_class_node to better reflect its role. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
2bc55f17ec
commit
0cfc15da2e
|
@ -287,11 +287,11 @@ struct usbd_class_data {
|
|||
* @cond INTERNAL_HIDDEN
|
||||
*
|
||||
* Variables necessary for per speed class management. For each speed (Full,
|
||||
* High) there is separate `struct usbd_class_iter` pointing to the same
|
||||
* High) there is separate `struct usbd_class_node` pointing to the same
|
||||
* `struct usbd_class_data` (because the class can only operate at one speed
|
||||
* at a time).
|
||||
*/
|
||||
struct usbd_class_iter {
|
||||
struct usbd_class_node {
|
||||
/** Node information for the slist. */
|
||||
sys_snode_t node;
|
||||
/** Pointer to public class node instance. */
|
||||
|
@ -495,11 +495,11 @@ static inline void *usbd_class_get_private(const struct usbd_class_data *const c
|
|||
.priv = class_priv, \
|
||||
}; \
|
||||
static STRUCT_SECTION_ITERABLE_ALTERNATE( \
|
||||
usbd_class_fs, usbd_class_iter, class_name##_fs) = { \
|
||||
usbd_class_fs, usbd_class_node, class_name##_fs) = { \
|
||||
.c_data = &class_name, \
|
||||
}; \
|
||||
static STRUCT_SECTION_ITERABLE_ALTERNATE( \
|
||||
usbd_class_hs, usbd_class_iter, class_name##_hs) = { \
|
||||
usbd_class_hs, usbd_class_node, class_name##_hs) = { \
|
||||
.c_data = &class_name, \
|
||||
}
|
||||
|
||||
|
|
|
@ -41,17 +41,17 @@ static int register_fs_classes(struct usbd_contex *uds_ctx)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs, usbd_class_iter, iter) {
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs, usbd_class_node, c_nd) {
|
||||
/* Pull everything that is enabled in our configuration. */
|
||||
err = usbd_register_class(uds_ctx, iter->c_data->name,
|
||||
err = usbd_register_class(uds_ctx, c_nd->c_data->name,
|
||||
USBD_SPEED_FS, 1);
|
||||
if (err) {
|
||||
LOG_ERR("Failed to register FS %s (%d)",
|
||||
iter->c_data->name, err);
|
||||
c_nd->c_data->name, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
LOG_DBG("Register FS %s", iter->c_data->name);
|
||||
LOG_DBG("Register FS %s", c_nd->c_data->name);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -61,17 +61,17 @@ static int register_hs_classes(struct usbd_contex *uds_ctx)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_hs, usbd_class_iter, iter) {
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_hs, usbd_class_node, c_nd) {
|
||||
/* Pull everything that is enabled in our configuration. */
|
||||
err = usbd_register_class(uds_ctx, iter->c_data->name,
|
||||
err = usbd_register_class(uds_ctx, c_nd->c_data->name,
|
||||
USBD_SPEED_HS, 1);
|
||||
if (err) {
|
||||
LOG_ERR("Failed to register HS %s (%d)",
|
||||
iter->c_data->name, err);
|
||||
c_nd->c_data->name, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
LOG_DBG("Register HS %s", iter->c_data->name);
|
||||
LOG_DBG("Register HS %s", c_nd->c_data->name);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
|
@ -209,10 +209,10 @@ static int sreq_set_interface(struct usbd_contex *const uds_ctx)
|
|||
static void sreq_feature_halt_notify(struct usbd_contex *const uds_ctx,
|
||||
const uint8_t ep, const bool halted)
|
||||
{
|
||||
struct usbd_class_iter *iter = usbd_class_get_by_ep(uds_ctx, ep);
|
||||
struct usbd_class_node *c_nd = usbd_class_get_by_ep(uds_ctx, ep);
|
||||
|
||||
if (iter != NULL) {
|
||||
usbd_class_feature_halt(iter->c_data, ep, halted);
|
||||
if (c_nd != NULL) {
|
||||
usbd_class_feature_halt(c_nd->c_data, ep, halted);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,7 +456,7 @@ static int sreq_get_desc_cfg(struct usbd_contex *const uds_ctx,
|
|||
struct usb_cfg_descriptor *cfg_desc;
|
||||
struct usbd_config_node *cfg_nd;
|
||||
enum usbd_speed get_desc_speed;
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
uint16_t len;
|
||||
|
||||
/*
|
||||
|
@ -496,10 +496,10 @@ static int sreq_get_desc_cfg(struct usbd_contex *const uds_ctx,
|
|||
|
||||
net_buf_add_mem(buf, cfg_desc, MIN(net_buf_tailroom(buf), cfg_desc->bLength));
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
struct usb_desc_header **dhp;
|
||||
|
||||
dhp = usbd_class_get_desc(iter->c_data, get_desc_speed);
|
||||
dhp = usbd_class_get_desc(c_nd->c_data, get_desc_speed);
|
||||
if (dhp == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
@ -728,28 +728,28 @@ static int nonstd_request(struct usbd_contex *const uds_ctx,
|
|||
struct net_buf *const dbuf)
|
||||
{
|
||||
struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx);
|
||||
struct usbd_class_iter *iter = NULL;
|
||||
struct usbd_class_node *c_nd = NULL;
|
||||
int ret = 0;
|
||||
|
||||
switch (setup->RequestType.recipient) {
|
||||
case USB_REQTYPE_RECIPIENT_ENDPOINT:
|
||||
iter = usbd_class_get_by_ep(uds_ctx, setup->wIndex);
|
||||
c_nd = usbd_class_get_by_ep(uds_ctx, setup->wIndex);
|
||||
break;
|
||||
case USB_REQTYPE_RECIPIENT_INTERFACE:
|
||||
iter = usbd_class_get_by_iface(uds_ctx, setup->wIndex);
|
||||
c_nd = usbd_class_get_by_iface(uds_ctx, setup->wIndex);
|
||||
break;
|
||||
case USB_REQTYPE_RECIPIENT_DEVICE:
|
||||
iter = usbd_class_get_by_req(uds_ctx, setup->bRequest);
|
||||
c_nd = usbd_class_get_by_req(uds_ctx, setup->bRequest);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (iter != NULL) {
|
||||
if (c_nd != NULL) {
|
||||
if (reqtype_is_to_device(setup)) {
|
||||
ret = usbd_class_control_to_dev(iter->c_data, setup, dbuf);
|
||||
ret = usbd_class_control_to_dev(c_nd->c_data, setup, dbuf);
|
||||
} else {
|
||||
ret = usbd_class_control_to_host(iter->c_data, setup, dbuf);
|
||||
ret = usbd_class_control_to_host(c_nd->c_data, setup, dbuf);
|
||||
}
|
||||
} else {
|
||||
errno = -ENOTSUP;
|
||||
|
|
|
@ -43,13 +43,13 @@ size_t usbd_class_desc_len(struct usbd_class_data *const c_data,
|
|||
return len;
|
||||
}
|
||||
|
||||
struct usbd_class_iter *
|
||||
struct usbd_class_node *
|
||||
usbd_class_get_by_config(struct usbd_contex *const uds_ctx,
|
||||
const enum usbd_speed speed,
|
||||
const uint8_t cnum,
|
||||
const uint8_t inum)
|
||||
{
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
struct usbd_config_node *cfg_nd;
|
||||
|
||||
cfg_nd = usbd_config_get(uds_ctx, speed, cnum);
|
||||
|
@ -57,20 +57,20 @@ usbd_class_get_by_config(struct usbd_contex *const uds_ctx,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
if (iter->iface_bm & BIT(inum)) {
|
||||
return iter;
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
if (c_nd->iface_bm & BIT(inum)) {
|
||||
return c_nd;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct usbd_class_iter *
|
||||
struct usbd_class_node *
|
||||
usbd_class_get_by_iface(struct usbd_contex *const uds_ctx,
|
||||
const uint8_t inum)
|
||||
{
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
struct usbd_config_node *cfg_nd;
|
||||
|
||||
cfg_nd = usbd_config_get_current(uds_ctx);
|
||||
|
@ -78,9 +78,9 @@ usbd_class_get_by_iface(struct usbd_contex *const uds_ctx,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
if (iter->iface_bm & BIT(inum)) {
|
||||
return iter;
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
if (c_nd->iface_bm & BIT(inum)) {
|
||||
return c_nd;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,12 +92,12 @@ static bool xfer_owner_exist(struct usbd_contex *const uds_ctx,
|
|||
struct net_buf *const buf)
|
||||
{
|
||||
struct udc_buf_info *bi = udc_get_buf_info(buf);
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
if (bi->owner == iter->c_data) {
|
||||
uint32_t ep_active = iter->ep_active;
|
||||
uint32_t ep_assigned = iter->ep_assigned;
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
if (bi->owner == c_nd->c_data) {
|
||||
uint32_t ep_active = c_nd->ep_active;
|
||||
uint32_t ep_assigned = c_nd->ep_assigned;
|
||||
|
||||
if (!usbd_ep_bm_is_set(&ep_active, bi->ep)) {
|
||||
LOG_DBG("ep 0x%02x is not active", bi->ep);
|
||||
|
@ -136,11 +136,11 @@ int usbd_class_handle_xfer(struct usbd_contex *const uds_ctx,
|
|||
return usbd_class_request(bi->owner, buf, err);
|
||||
}
|
||||
|
||||
struct usbd_class_iter *
|
||||
struct usbd_class_node *
|
||||
usbd_class_get_by_ep(struct usbd_contex *const uds_ctx,
|
||||
const uint8_t ep)
|
||||
{
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
struct usbd_config_node *cfg_nd;
|
||||
enum usbd_speed speed;
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
@ -165,39 +165,39 @@ usbd_class_get_by_ep(struct usbd_contex *const uds_ctx,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
if (iter->ep_assigned & ep_bm) {
|
||||
return iter;
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
if (c_nd->ep_assigned & ep_bm) {
|
||||
return c_nd;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct usbd_class_iter *
|
||||
struct usbd_class_node *
|
||||
usbd_class_get_by_req(struct usbd_contex *const uds_ctx,
|
||||
const uint8_t request)
|
||||
{
|
||||
struct usbd_config_node *cfg_nd;
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
|
||||
cfg_nd = usbd_config_get_current(uds_ctx);
|
||||
if (cfg_nd == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
if (iter->c_data->v_reqs == NULL) {
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
if (c_nd->c_data->v_reqs == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < iter->c_data->v_reqs->len; i++) {
|
||||
for (int i = 0; i < c_nd->c_data->v_reqs->len; i++) {
|
||||
/*
|
||||
* First instance always wins.
|
||||
* There is no other way to determine the recipient.
|
||||
*/
|
||||
if (iter->c_data->v_reqs->reqs[i] == request) {
|
||||
return iter;
|
||||
if (c_nd->c_data->v_reqs->reqs[i] == request) {
|
||||
return c_nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,21 +205,21 @@ usbd_class_get_by_req(struct usbd_contex *const uds_ctx,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct usbd_class_iter *
|
||||
usbd_class_iter_get(const char *name, const enum usbd_speed speed)
|
||||
static struct usbd_class_node *
|
||||
usbd_class_node_get(const char *name, const enum usbd_speed speed)
|
||||
{
|
||||
if (speed == USBD_SPEED_FS) {
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs,
|
||||
usbd_class_iter, iter) {
|
||||
if (strcmp(name, iter->c_data->name) == 0) {
|
||||
return iter;
|
||||
usbd_class_node, c_nd) {
|
||||
if (strcmp(name, c_nd->c_data->name) == 0) {
|
||||
return c_nd;
|
||||
}
|
||||
}
|
||||
} else if (speed == USBD_SPEED_HS) {
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_hs,
|
||||
usbd_class_iter, iter) {
|
||||
if (strcmp(name, iter->c_data->name) == 0) {
|
||||
return iter;
|
||||
usbd_class_node, c_nd) {
|
||||
if (strcmp(name, c_nd->c_data->name) == 0) {
|
||||
return c_nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ usbd_class_iter_get(const char *name, const enum usbd_speed speed)
|
|||
}
|
||||
|
||||
static int usbd_class_append(struct usbd_contex *const uds_ctx,
|
||||
struct usbd_class_iter *const iter,
|
||||
struct usbd_class_node *const c_nd,
|
||||
const enum usbd_speed speed,
|
||||
const uint8_t cfg)
|
||||
{
|
||||
|
@ -241,13 +241,13 @@ static int usbd_class_append(struct usbd_contex *const uds_ctx,
|
|||
return -ENODATA;
|
||||
}
|
||||
|
||||
sys_slist_append(&cfg_nd->class_list, &iter->node);
|
||||
sys_slist_append(&cfg_nd->class_list, &c_nd->node);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbd_class_remove(struct usbd_contex *const uds_ctx,
|
||||
struct usbd_class_iter *const iter,
|
||||
struct usbd_class_node *const c_nd,
|
||||
const enum usbd_speed speed,
|
||||
const uint8_t cfg)
|
||||
{
|
||||
|
@ -258,7 +258,7 @@ static int usbd_class_remove(struct usbd_contex *const uds_ctx,
|
|||
return -ENODATA;
|
||||
}
|
||||
|
||||
if (!sys_slist_find_and_remove(&cfg_nd->class_list, &iter->node)) {
|
||||
if (!sys_slist_find_and_remove(&cfg_nd->class_list, &c_nd->node)) {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ int usbd_class_remove_all(struct usbd_contex *const uds_ctx,
|
|||
const uint8_t cfg)
|
||||
{
|
||||
struct usbd_config_node *cfg_nd;
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
sys_snode_t *node;
|
||||
|
||||
cfg_nd = usbd_config_get(uds_ctx, speed, cfg);
|
||||
|
@ -279,10 +279,10 @@ int usbd_class_remove_all(struct usbd_contex *const uds_ctx,
|
|||
}
|
||||
|
||||
while ((node = sys_slist_get(&cfg_nd->class_list))) {
|
||||
iter = CONTAINER_OF(node, struct usbd_class_iter, node);
|
||||
atomic_clear_bit(&iter->state, USBD_CCTX_REGISTERED);
|
||||
usbd_class_shutdown(iter->c_data);
|
||||
LOG_DBG("Remove class node %p from configuration %u", iter, cfg);
|
||||
c_nd = CONTAINER_OF(node, struct usbd_class_node, node);
|
||||
atomic_clear_bit(&c_nd->state, USBD_CCTX_REGISTERED);
|
||||
usbd_class_shutdown(c_nd->c_data);
|
||||
LOG_DBG("Remove class node %p from configuration %u", c_nd, cfg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -296,12 +296,12 @@ int usbd_register_class(struct usbd_contex *const uds_ctx,
|
|||
const char *name,
|
||||
const enum usbd_speed speed, const uint8_t cfg)
|
||||
{
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
struct usbd_class_data *c_data;
|
||||
int ret;
|
||||
|
||||
iter = usbd_class_iter_get(name, speed);
|
||||
if (iter == NULL) {
|
||||
c_nd = usbd_class_node_get(name, speed);
|
||||
if (c_nd == NULL) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
@ -313,10 +313,10 @@ int usbd_register_class(struct usbd_contex *const uds_ctx,
|
|||
goto register_class_error;
|
||||
}
|
||||
|
||||
c_data = iter->c_data;
|
||||
c_data = c_nd->c_data;
|
||||
|
||||
/* TODO: does it still need to be atomic ? */
|
||||
if (atomic_test_bit(&iter->state, USBD_CCTX_REGISTERED)) {
|
||||
if (atomic_test_bit(&c_nd->state, USBD_CCTX_REGISTERED)) {
|
||||
LOG_WRN("Class instance already registered");
|
||||
ret = -EBUSY;
|
||||
goto register_class_error;
|
||||
|
@ -328,10 +328,10 @@ int usbd_register_class(struct usbd_contex *const uds_ctx,
|
|||
goto register_class_error;
|
||||
}
|
||||
|
||||
ret = usbd_class_append(uds_ctx, iter, speed, cfg);
|
||||
ret = usbd_class_append(uds_ctx, c_nd, speed, cfg);
|
||||
if (ret == 0) {
|
||||
/* Initialize pointer back to the device struct */
|
||||
atomic_set_bit(&iter->state, USBD_CCTX_REGISTERED);
|
||||
atomic_set_bit(&c_nd->state, USBD_CCTX_REGISTERED);
|
||||
c_data->uds_ctx = uds_ctx;
|
||||
}
|
||||
|
||||
|
@ -344,13 +344,13 @@ int usbd_unregister_class(struct usbd_contex *const uds_ctx,
|
|||
const char *name,
|
||||
const enum usbd_speed speed, const uint8_t cfg)
|
||||
{
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
struct usbd_class_data *c_data;
|
||||
bool can_release_data = true;
|
||||
int ret;
|
||||
|
||||
iter = usbd_class_iter_get(name, speed);
|
||||
if (iter == NULL) {
|
||||
c_nd = usbd_class_node_get(name, speed);
|
||||
if (c_nd == NULL) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
@ -362,9 +362,9 @@ int usbd_unregister_class(struct usbd_contex *const uds_ctx,
|
|||
goto unregister_class_error;
|
||||
}
|
||||
|
||||
c_data = iter->c_data;
|
||||
c_data = c_nd->c_data;
|
||||
/* TODO: does it still need to be atomic ? */
|
||||
if (!atomic_test_bit(&iter->state, USBD_CCTX_REGISTERED)) {
|
||||
if (!atomic_test_bit(&c_nd->state, USBD_CCTX_REGISTERED)) {
|
||||
LOG_WRN("Class instance not registered");
|
||||
ret = -EBUSY;
|
||||
goto unregister_class_error;
|
||||
|
@ -375,8 +375,8 @@ int usbd_unregister_class(struct usbd_contex *const uds_ctx,
|
|||
*/
|
||||
if (speed == USBD_SPEED_HS) {
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs,
|
||||
usbd_class_iter, i) {
|
||||
if ((i->c_data == iter->c_data) &&
|
||||
usbd_class_node, i) {
|
||||
if ((i->c_data == c_nd->c_data) &&
|
||||
atomic_test_bit(&i->state, USBD_CCTX_REGISTERED)) {
|
||||
can_release_data = false;
|
||||
break;
|
||||
|
@ -384,8 +384,8 @@ int usbd_unregister_class(struct usbd_contex *const uds_ctx,
|
|||
}
|
||||
} else {
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_hs,
|
||||
usbd_class_iter, i) {
|
||||
if ((i->c_data == iter->c_data) &&
|
||||
usbd_class_node, i) {
|
||||
if ((i->c_data == c_nd->c_data) &&
|
||||
atomic_test_bit(&i->state, USBD_CCTX_REGISTERED)) {
|
||||
can_release_data = false;
|
||||
break;
|
||||
|
@ -393,10 +393,10 @@ int usbd_unregister_class(struct usbd_contex *const uds_ctx,
|
|||
}
|
||||
}
|
||||
|
||||
ret = usbd_class_remove(uds_ctx, iter, speed, cfg);
|
||||
ret = usbd_class_remove(uds_ctx, c_nd, speed, cfg);
|
||||
if (ret == 0) {
|
||||
atomic_clear_bit(&iter->state, USBD_CCTX_REGISTERED);
|
||||
usbd_class_shutdown(iter->c_data);
|
||||
atomic_clear_bit(&c_nd->state, USBD_CCTX_REGISTERED);
|
||||
usbd_class_shutdown(c_nd->c_data);
|
||||
|
||||
if (can_release_data) {
|
||||
c_data->uds_ctx = NULL;
|
||||
|
|
|
@ -45,9 +45,9 @@ size_t usbd_class_desc_len(struct usbd_class_data *const c_data,
|
|||
* @param[in] uds_ctx Pointer to device context
|
||||
* @param[in] inum Interface number
|
||||
*
|
||||
* @return Class iter pointer or NULL
|
||||
* @return Class c_nd pointer or NULL
|
||||
*/
|
||||
struct usbd_class_iter *usbd_class_get_by_iface(struct usbd_contex *uds_ctx,
|
||||
struct usbd_class_node *usbd_class_get_by_iface(struct usbd_contex *uds_ctx,
|
||||
uint8_t i_n);
|
||||
|
||||
/**
|
||||
|
@ -58,9 +58,9 @@ struct usbd_class_iter *usbd_class_get_by_iface(struct usbd_contex *uds_ctx,
|
|||
* @param[in] cnum Configuration number
|
||||
* @param[in] inum Interface number
|
||||
*
|
||||
* @return Class iter pointer or NULL
|
||||
* @return Class c_nd pointer or NULL
|
||||
*/
|
||||
struct usbd_class_iter *usbd_class_get_by_config(struct usbd_contex *uds_ctx,
|
||||
struct usbd_class_node *usbd_class_get_by_config(struct usbd_contex *uds_ctx,
|
||||
const enum usbd_speed speed,
|
||||
uint8_t cnum,
|
||||
uint8_t inum);
|
||||
|
@ -73,9 +73,9 @@ struct usbd_class_iter *usbd_class_get_by_config(struct usbd_contex *uds_ctx,
|
|||
* @param[in] uds_ctx Pointer to device context
|
||||
* @param[in] ep Endpoint address
|
||||
*
|
||||
* @return Class iter pointer or NULL
|
||||
* @return Class c_nd pointer or NULL
|
||||
*/
|
||||
struct usbd_class_iter *usbd_class_get_by_ep(struct usbd_contex *uds_ctx,
|
||||
struct usbd_class_node *usbd_class_get_by_ep(struct usbd_contex *uds_ctx,
|
||||
uint8_t ep);
|
||||
|
||||
/**
|
||||
|
@ -90,9 +90,9 @@ struct usbd_class_iter *usbd_class_get_by_ep(struct usbd_contex *uds_ctx,
|
|||
* @param[in] uds_ctx Pointer to device context
|
||||
* @param[in] request bRequest value
|
||||
*
|
||||
* @return Class iter pointer or NULL
|
||||
* @return Class c_nd pointer or NULL
|
||||
*/
|
||||
struct usbd_class_iter *usbd_class_get_by_req(struct usbd_contex *uds_ctx,
|
||||
struct usbd_class_node *usbd_class_get_by_req(struct usbd_contex *uds_ctx,
|
||||
uint8_t request);
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,13 +59,13 @@ usbd_config_get_current(struct usbd_contex *const uds_ctx)
|
|||
static void usbd_config_classes_enable(struct usbd_config_node *const cfg_nd,
|
||||
const bool enable)
|
||||
{
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
if (enable) {
|
||||
usbd_class_enable(iter->c_data);
|
||||
usbd_class_enable(c_nd->c_data);
|
||||
} else {
|
||||
usbd_class_disable(iter->c_data);
|
||||
usbd_class_disable(c_nd->c_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ static void usbd_class_bcast_event(struct usbd_contex *const uds_ctx,
|
|||
struct udc_event *const event)
|
||||
{
|
||||
struct usbd_config_node *cfg_nd;
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
|
||||
if (!usbd_state_is_configured(uds_ctx)) {
|
||||
return;
|
||||
|
@ -75,16 +75,16 @@ static void usbd_class_bcast_event(struct usbd_contex *const uds_ctx,
|
|||
return;
|
||||
}
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
switch (event->type) {
|
||||
case UDC_EVT_SUSPEND:
|
||||
usbd_class_suspended(iter->c_data);
|
||||
usbd_class_suspended(c_nd->c_data);
|
||||
break;
|
||||
case UDC_EVT_RESUME:
|
||||
usbd_class_resumed(iter->c_data);
|
||||
usbd_class_resumed(c_nd->c_data);
|
||||
break;
|
||||
case UDC_EVT_SOF:
|
||||
usbd_class_sof(iter->c_data);
|
||||
usbd_class_sof(c_nd->c_data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -263,13 +263,13 @@ static int usbd_pre_init(void)
|
|||
k_thread_name_set(&usbd_thread_data, "usbd");
|
||||
|
||||
LOG_DBG("Available USB class iterators:");
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs, usbd_class_iter, iter) {
|
||||
atomic_set(&iter->state, 0);
|
||||
LOG_DBG("\t%p->%p, name %s", iter, iter->c_data, iter->c_data->name);
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs, usbd_class_node, c_nd) {
|
||||
atomic_set(&c_nd->state, 0);
|
||||
LOG_DBG("\t%p->%p, name %s", c_nd, c_nd->c_data, c_nd->c_data->name);
|
||||
}
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_hs, usbd_class_iter, iter) {
|
||||
atomic_set(&iter->state, 0);
|
||||
LOG_DBG("\t%p->%p, name %s", iter, iter->c_data, iter->c_data->name);
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_hs, usbd_class_node, c_nd) {
|
||||
atomic_set(&c_nd->state, 0);
|
||||
LOG_DBG("\t%p->%p, name %s", c_nd, c_nd->c_data, c_nd->c_data->name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -110,7 +110,7 @@ static int unassign_eps(struct usbd_contex *const uds_ctx,
|
|||
*/
|
||||
static int init_configuration_inst(struct usbd_contex *const uds_ctx,
|
||||
const enum usbd_speed speed,
|
||||
struct usbd_class_iter *const iter,
|
||||
struct usbd_class_node *const c_nd,
|
||||
uint32_t *const config_ep_bm,
|
||||
uint8_t *const nif)
|
||||
{
|
||||
|
@ -122,25 +122,25 @@ static int init_configuration_inst(struct usbd_contex *const uds_ctx,
|
|||
int ret;
|
||||
|
||||
LOG_DBG("Initializing configuration for %u speed", speed);
|
||||
dhp = usbd_class_get_desc(iter->c_data, speed);
|
||||
dhp = usbd_class_get_desc(c_nd->c_data, speed);
|
||||
if (dhp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmp_nif = *nif;
|
||||
iter->iface_bm = 0U;
|
||||
iter->ep_active = 0U;
|
||||
c_nd->iface_bm = 0U;
|
||||
c_nd->ep_active = 0U;
|
||||
|
||||
while (*dhp != NULL && (*dhp)->bLength != 0) {
|
||||
|
||||
if ((*dhp)->bDescriptorType == USB_DESC_INTERFACE) {
|
||||
ifd = (struct usb_if_descriptor *)(*dhp);
|
||||
|
||||
iter->ep_active |= class_ep_bm;
|
||||
c_nd->ep_active |= class_ep_bm;
|
||||
|
||||
if (ifd->bAlternateSetting == 0) {
|
||||
ifd->bInterfaceNumber = tmp_nif;
|
||||
iter->iface_bm |= BIT(tmp_nif);
|
||||
c_nd->iface_bm |= BIT(tmp_nif);
|
||||
tmp_nif++;
|
||||
} else {
|
||||
ifd->bInterfaceNumber = tmp_nif - 1;
|
||||
|
@ -178,10 +178,10 @@ static int init_configuration_inst(struct usbd_contex *const uds_ctx,
|
|||
}
|
||||
|
||||
*nif = tmp_nif;
|
||||
iter->ep_active |= class_ep_bm;
|
||||
c_nd->ep_active |= class_ep_bm;
|
||||
|
||||
LOG_INF("Instance iface-bm 0x%08x ep-bm 0x%08x",
|
||||
iter->iface_bm, iter->ep_active);
|
||||
c_nd->iface_bm, c_nd->ep_active);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -196,30 +196,30 @@ static int init_configuration(struct usbd_contex *const uds_ctx,
|
|||
struct usbd_config_node *const cfg_nd)
|
||||
{
|
||||
struct usb_cfg_descriptor *cfg_desc = cfg_nd->desc;
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
uint32_t config_ep_bm = 0;
|
||||
size_t cfg_len = 0;
|
||||
uint8_t nif = 0;
|
||||
int ret;
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
|
||||
ret = init_configuration_inst(uds_ctx, speed, iter,
|
||||
ret = init_configuration_inst(uds_ctx, speed, c_nd,
|
||||
&config_ep_bm, &nif);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to assign endpoint addresses");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usbd_class_init(iter->c_data);
|
||||
ret = usbd_class_init(c_nd->c_data);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to initialize class instance");
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOG_INF("Init class node %p, descriptor length %zu",
|
||||
iter->c_data, usbd_class_desc_len(iter->c_data, speed));
|
||||
cfg_len += usbd_class_desc_len(iter->c_data, speed);
|
||||
c_nd->c_data, usbd_class_desc_len(c_nd->c_data, speed));
|
||||
cfg_len += usbd_class_desc_len(c_nd->c_data, speed);
|
||||
}
|
||||
|
||||
/* Update wTotalLength and bNumInterfaces of configuration descriptor */
|
||||
|
@ -232,9 +232,9 @@ static int init_configuration(struct usbd_contex *const uds_ctx,
|
|||
cfg_desc->wTotalLength);
|
||||
|
||||
/* Finally reset configuration's endpoint assignment */
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
iter->ep_assigned = iter->ep_active;
|
||||
ret = unassign_eps(uds_ctx, &config_ep_bm, &iter->ep_active);
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
c_nd->ep_assigned = c_nd->ep_active;
|
||||
ret = unassign_eps(uds_ctx, &config_ep_bm, &c_nd->ep_active);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ static int handle_ep_op(struct usbd_contex *const uds_ctx,
|
|||
}
|
||||
|
||||
static int usbd_interface_modify(struct usbd_contex *const uds_ctx,
|
||||
struct usbd_class_iter *const iter,
|
||||
struct usbd_class_node *const c_nd,
|
||||
const enum ep_op op,
|
||||
const uint8_t iface,
|
||||
const uint8_t alt)
|
||||
|
@ -60,7 +60,7 @@ static int usbd_interface_modify(struct usbd_contex *const uds_ctx,
|
|||
bool found_iface = false;
|
||||
int ret;
|
||||
|
||||
dhp = usbd_class_get_desc(iter->c_data, usbd_bus_speed(uds_ctx));
|
||||
dhp = usbd_class_get_desc(c_nd->c_data, usbd_bus_speed(uds_ctx));
|
||||
if (dhp == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ static int usbd_interface_modify(struct usbd_contex *const uds_ctx,
|
|||
if (ifd->bInterfaceNumber == iface &&
|
||||
ifd->bAlternateSetting == alt) {
|
||||
found_iface = true;
|
||||
LOG_DBG("Found interface %u %p", iface, iter);
|
||||
LOG_DBG("Found interface %u %p", iface, c_nd);
|
||||
if (ifd->bNumEndpoints == 0) {
|
||||
LOG_INF("No endpoints, skip interface");
|
||||
break;
|
||||
|
@ -89,14 +89,14 @@ static int usbd_interface_modify(struct usbd_contex *const uds_ctx,
|
|||
|
||||
if ((*dhp)->bDescriptorType == USB_DESC_ENDPOINT && found_iface) {
|
||||
ed = (struct usb_ep_descriptor *)(*dhp);
|
||||
ret = handle_ep_op(uds_ctx, op, ed, &iter->ep_active);
|
||||
ret = handle_ep_op(uds_ctx, op, ed, &c_nd->ep_active);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOG_INF("Modify interface %u ep 0x%02x by op %u ep_bm %x",
|
||||
iface, ed->bEndpointAddress,
|
||||
op, iter->ep_active);
|
||||
op, c_nd->ep_active);
|
||||
}
|
||||
|
||||
dhp++;
|
||||
|
@ -110,10 +110,10 @@ static int usbd_interface_modify(struct usbd_contex *const uds_ctx,
|
|||
int usbd_interface_shutdown(struct usbd_contex *const uds_ctx,
|
||||
struct usbd_config_node *const cfg_nd)
|
||||
{
|
||||
struct usbd_class_iter *iter;
|
||||
struct usbd_class_node *c_nd;
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, iter, node) {
|
||||
uint32_t *ep_bm = &iter->ep_active;
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&cfg_nd->class_list, c_nd, node) {
|
||||
uint32_t *ep_bm = &c_nd->ep_active;
|
||||
|
||||
for (int idx = 1; idx < 16 && *ep_bm; idx++) {
|
||||
uint8_t ep_in = USB_EP_DIR_IN | idx;
|
||||
|
@ -148,7 +148,7 @@ int usbd_interface_default(struct usbd_contex *const uds_ctx,
|
|||
|
||||
/* Set default alternate for all interfaces */
|
||||
for (int i = 0; i < desc->bNumInterfaces; i++) {
|
||||
struct usbd_class_iter *class;
|
||||
struct usbd_class_node *class;
|
||||
int ret;
|
||||
|
||||
class = usbd_class_get_by_config(uds_ctx, speed, new_cfg, i);
|
||||
|
@ -169,7 +169,7 @@ int usbd_interface_set(struct usbd_contex *const uds_ctx,
|
|||
const uint8_t iface,
|
||||
const uint8_t alt)
|
||||
{
|
||||
struct usbd_class_iter *class;
|
||||
struct usbd_class_node *class;
|
||||
uint8_t cur_alt;
|
||||
int ret;
|
||||
|
||||
|
|
|
@ -400,11 +400,11 @@ static void class_node_name_lookup(size_t idx, struct shell_static_entry *entry)
|
|||
entry->help = NULL;
|
||||
entry->subcmd = NULL;
|
||||
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs, usbd_class_iter, iter) {
|
||||
if ((iter->c_data->name != NULL) &&
|
||||
(strlen(iter->c_data->name) != 0)) {
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs, usbd_class_node, c_nd) {
|
||||
if ((c_nd->c_data->name != NULL) &&
|
||||
(strlen(c_nd->c_data->name) != 0)) {
|
||||
if (match_idx == idx) {
|
||||
entry->syntax = iter->c_data->name;
|
||||
entry->syntax = c_nd->c_data->name;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue