usbd_enum.c 20.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
/*!
    \file    usbd_enum.c
    \brief   USB enumeration function

    \version 2020-08-01, V3.0.0, firmware for GD32F30x
    \version 2021-09-27, V3.0.1, firmware for GD32F30x
*/

/*
    Copyright (c) 2020, GigaDevice Semiconductor Inc.

    Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this 
       list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice, 
       this list of conditions and the following disclaimer in the documentation 
       and/or other materials provided with the distribution.
    3. Neither the name of the copyright holder nor the names of its contributors 
       may be used to endorse or promote products derived from this software without 
       specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
*/

#include "usbd_enum.h"
#include "usbd_transc.h"

/* USB enumeration handle functions */
static usb_reqsta _usb_std_getstatus        (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_clearfeature     (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_setfeature       (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_setaddress       (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_getdescriptor    (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_setdescriptor    (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_getconfiguration (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_setconfiguration (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_reserved         (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_getinterface     (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_setinterface     (usb_dev *udev, usb_req *req);
static usb_reqsta _usb_std_synchframe       (usb_dev *udev, usb_req *req);
static uint8_t* _usb_dev_desc_get           (usb_dev *udev, uint8_t index, uint16_t *len);
static uint8_t* _usb_config_desc_get        (usb_dev *udev, uint8_t index, uint16_t *len);
static uint8_t* _usb_str_desc_get           (usb_dev *udev, uint8_t index, uint16_t *len);
static uint8_t* _usb_bos_desc_get           (usb_dev *udev, uint8_t index, uint16_t *len);
static void int_to_unicode                  (uint32_t value, uint8_t *pbuf, uint8_t len);

/* standard device request handler */
static usb_reqsta (*_std_dev_req[]) (usb_dev *udev, usb_req *req) = {
    [USB_GET_STATUS]        = _usb_std_getstatus,
    [USB_CLEAR_FEATURE]     = _usb_std_clearfeature,
    [USB_RESERVED2]         = _usb_std_reserved,
    [USB_SET_FEATURE]       = _usb_std_setfeature,
    [USB_RESERVED4]         = _usb_std_reserved,
    [USB_SET_ADDRESS]       = _usb_std_setaddress,
    [USB_GET_DESCRIPTOR]    = _usb_std_getdescriptor,
    [USB_SET_DESCRIPTOR]    = _usb_std_setdescriptor,
    [USB_GET_CONFIGURATION] = _usb_std_getconfiguration,
    [USB_SET_CONFIGURATION] = _usb_std_setconfiguration,
    [USB_GET_INTERFACE]     = _usb_std_getinterface,
    [USB_SET_INTERFACE]     = _usb_std_setinterface,
    [USB_SYNCH_FRAME]       = _usb_std_synchframe,
};

/* get standard descriptor handler */
static uint8_t* (*std_desc_get[])(usb_dev *udev, uint8_t index, uint16_t *len) = {
    [USB_DESCTYPE_DEV - 1U]    = _usb_dev_desc_get,
    [USB_DESCTYPE_CONFIG - 1U] = _usb_config_desc_get,
    [USB_DESCTYPE_STR - 1U]    = _usb_str_desc_get
};

/*!
    \brief      handle USB standard device request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device operation cur_status
*/
usb_reqsta usbd_standard_request (usb_dev *udev, usb_req *req)
{
    /* call device request handle function */
    return (*_std_dev_req[req->bRequest]) (udev, req);
}

/*!
    \brief      handle USB device class request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device class request
    \param[out] none
    \retval     USB device request status
*/
usb_reqsta usbd_class_request (usb_dev *udev, usb_req *req)
{
    if ((uint8_t)USBD_CONFIGURED == udev->cur_status) {
        if (BYTE_LOW(req->wIndex) < USBD_ITF_MAX_NUM) {
            /* call device class handle function */
            return (usb_reqsta)udev->class_core->req_process(udev, req);
        }
    }

    return REQ_NOTSUPP;
}

/*!
    \brief      handle USB vendor request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB vendor request
    \param[out] none
    \retval     USB device request status
*/
usb_reqsta usbd_vendor_request (usb_dev *udev, usb_req *req)
{
    (void)udev;
    (void)req;

    /* added by user */

    return REQ_NOTSUPP;
}

/*!
    \brief      no operation, just for reserved
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_reserved (usb_dev *udev, usb_req *req)
{
    (void)udev;
    (void)req;

    /* no operation */
    return REQ_NOTSUPP;
}

/*!
    \brief      get the device descriptor
    \param[in]  udev: pointer to USB device instance
    \param[in]  index: no use
    \param[out] len: data length pointer
    \retval     descriptor buffer pointer
*/
static uint8_t* _usb_dev_desc_get (usb_dev *udev, uint8_t index, uint16_t *len)
{
    (void)index;

    *len = udev->desc->dev_desc[0];

    return udev->desc->dev_desc;
}

/*!
    \brief      get the configuration descriptor
    \brief[in]  udev: pointer to USB device instance
    \brief[in]  index: no use
    \param[out] len: data length pointer
    \retval     descriptor buffer pointer
*/
static uint8_t* _usb_config_desc_get (usb_dev *udev, uint8_t index, uint16_t *len)
{
    (void)index;

    *len = udev->desc->config_desc[2] | (udev->desc->config_desc[3]<< 8);

    return udev->desc->config_desc;
}

/*!
    \brief      get the BOS descriptor
    \brief[in]  udev: pointer to USB device instance
    \brief[in]  index: no use
    \param[out] len: data length pointer
    \retval     descriptor buffer pointer
*/
static uint8_t* _usb_bos_desc_get (usb_dev *udev, uint8_t index, uint16_t *len)
{
    if (NULL != udev->desc->bos_desc) {
        (void)index;

        *len = (uint16_t)udev->desc->bos_desc[2] | (uint16_t)((uint16_t)udev->desc->bos_desc[3] << 8);

        return udev->desc->bos_desc;
    } else {
        *len = 0U;

        return NULL;
    }
}

/*!
    \brief      get string descriptor
    \param[in]  udev: pointer to USB device instance
    \param[in]  index: string descriptor index
    \param[out] len: pointer to string length
    \retval     string descriptor
*/
static uint8_t* _usb_str_desc_get (usb_dev *udev, uint8_t index, uint16_t *len)
{
    uint8_t* desc = udev->desc->strings[index];

    *len = desc[0];

    return desc;
}

/*!
    \brief      handle Get_Status request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_getstatus (usb_dev *udev, usb_req *req)
{
    uint8_t recp = BYTE_LOW(req->wIndex);

    usb_reqsta req_status = REQ_NOTSUPP;

    static uint8_t status[2] = {0U};

    switch(req->bmRequestType & USB_RECPTYPE_MASK) {
    /* handle device get status request */
    case USB_RECPTYPE_DEV:
        switch (udev->cur_status) {
        case USBD_ADDRESSED:
        case USBD_CONFIGURED:
            if (udev->pm.power_mode) {
                status[0] = USB_STATUS_SELF_POWERED;
            } else {
                status[0] = 0U;
            }

            if (udev->pm.remote_wakeup) {
                status[0] |= USB_STATUS_REMOTE_WAKEUP;
            } else {
                status[0] = 0U;
            }

            req_status = REQ_SUPP;
            break;

        default:
            break;
        }
        break;
    /* handle interface get status request */
    case USB_RECPTYPE_ITF:
        if (((uint8_t)USBD_CONFIGURED == udev->cur_status) && (recp < USBD_ITF_MAX_NUM)) {
            req_status = REQ_SUPP;
        }
        break;
    /* handle endpoint get status request */
    case USB_RECPTYPE_EP:
        if ((uint8_t)USBD_CONFIGURED == udev->cur_status) {
            if (0x80U == (recp & 0x80U)) {
                status[0] = udev->transc_in[EP_ID(recp)].ep_stall;
            } else {
                status[0] = udev->transc_out[recp].ep_stall;
            }
            req_status = REQ_SUPP;
        }
        break;

    default:
        break;
    }

    if (REQ_SUPP == req_status) {
        usb_transc_config(&udev->transc_in[0], status, 2U, 2U);
    }

    return req_status;
}

/*!
    \brief      handle USB Clear_Feature request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_clearfeature (usb_dev *udev, usb_req *req)
{
    uint8_t ep = 0U;

    switch (req->bmRequestType & (uint8_t)USB_RECPTYPE_MASK) {
    case USB_RECPTYPE_DEV:
        switch (udev->cur_status) {
        case USBD_ADDRESSED:
        case USBD_CONFIGURED:
            /* clear device remote wakeup feature */
            if ((uint16_t)USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
                udev->pm.remote_wakeup = 0U;

                return REQ_SUPP;
            }
            break;

        default:
            break;
        }
        break;
 
    case USB_RECPTYPE_EP:
        /* get endpoint address */
        ep = BYTE_LOW(req->wIndex);

        if ((uint8_t)USBD_CONFIGURED == udev->cur_status) {
            /* clear endpoint halt feature */
            if (((uint16_t)USB_FEATURE_EP_HALT == req->wValue) && (!CTL_EP(ep))) {
                usbd_ep_clear_stall(udev, ep);
                
                udev->class_core->req_process(udev, req);

                return REQ_SUPP;
            }
        }
        break;

    case USB_RECPTYPE_ITF:
        break;

    default:
        break;
    }

    return REQ_NOTSUPP;
}

/*!
    \brief      handle USB Set_Feature request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_setfeature (usb_dev *udev, usb_req *req)
{
    uint8_t ep = 0U;

    switch (req->bmRequestType & (uint8_t)USB_RECPTYPE_MASK) {
    case USB_RECPTYPE_DEV:
        switch (udev->cur_status) {
        case USBD_ADDRESSED:
        case USBD_CONFIGURED:
            /* set device remote wakeup feature */
            if ((uint16_t)USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
                udev->pm.remote_wakeup = 1U;

                return REQ_SUPP;
            }
            break;

        default:
            break;
        }
        break;

    case USB_RECPTYPE_EP:
        /* get endpoint address */
        ep = BYTE_LOW(req->wIndex);

        if ((uint8_t)USBD_CONFIGURED == udev->cur_status) {
            /* set endpoint halt feature */
            if (((uint8_t)USB_FEATURE_EP_HALT == req->wValue) && (!CTL_EP(ep))) {
                usbd_ep_stall(udev, ep);

                return REQ_SUPP;
            }
        }
        break;

    case USB_RECPTYPE_ITF:
        break;

    default:
        break;
    }

    return REQ_NOTSUPP;
}

/*!
    \brief      handle USB Set_Address request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_setaddress (usb_dev *udev, usb_req *req)
{
    if ((0U == req->wIndex) && (0U == req->wLength)) {
        udev->dev_addr = (uint8_t)(req->wValue) & 0x7FU;

        if (udev->cur_status != (uint8_t)USBD_CONFIGURED) {
            if (udev->dev_addr) {
                udev->cur_status = (uint8_t)USBD_ADDRESSED;
            } else {
                udev->cur_status = (uint8_t)USBD_DEFAULT;
            }

            return REQ_SUPP;
        }
    }

    return REQ_NOTSUPP;
}

/*!
    \brief      handle USB Get_Descriptor request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_getdescriptor (usb_dev *udev, usb_req *req)
{
    uint8_t desc_type = 0U;
    uint8_t desc_index = 0U;

    usb_reqsta status = REQ_NOTSUPP;

    usb_transc *transc = &udev->transc_in[0];

    switch (req->bmRequestType & USB_RECPTYPE_MASK) {
    case USB_RECPTYPE_DEV:
        desc_type = BYTE_HIGH(req->wValue);
        desc_index = BYTE_LOW(req->wValue);

        switch (desc_type) {
        case USB_DESCTYPE_DEV:
            transc->xfer_buf = std_desc_get[desc_type - 1U](udev, desc_index, &transc->xfer_len);
            if (64U == req->wLength) {
                transc->xfer_len = 8U;
            }
            break;

        case USB_DESCTYPE_CONFIG:
            transc->xfer_buf = std_desc_get[desc_type - 1U](udev, desc_index, &transc->xfer_len);
            break;

        case USB_DESCTYPE_STR:
            if (desc_index < STR_IDX_MAX) {
                transc->xfer_buf = std_desc_get[desc_type - 1U](udev, desc_index, &transc->xfer_len);
            }
            break;

        case USB_DESCTYPE_ITF:
        case USB_DESCTYPE_EP:
        case USB_DESCTYPE_DEV_QUALIFIER:
        case USB_DESCTYPE_OTHER_SPD_CONFIG:
        case USB_DESCTYPE_ITF_POWER:
            break;

        case USB_DESCTYPE_BOS:
            transc->xfer_buf = _usb_bos_desc_get(udev, desc_index, &transc->xfer_len);
            break;

        default:
            break;
        }
        break;

    case USB_RECPTYPE_ITF:
        /* get device class special descriptor */
        status = (usb_reqsta)(udev->class_core->req_process(udev, req));
        break;

    case USB_RECPTYPE_EP:
        break;

    default:
        break;
    }

    if ((transc->xfer_len) && (req->wLength)) {
        transc->xfer_len = USB_MIN(transc->xfer_len, req->wLength);

        if ((transc->xfer_len < udev->control.req.wLength) &&
            (0U == transc->xfer_len % transc->max_len)) {
                udev->control.ctl_zlp = 1U;
        }

        status = REQ_SUPP;
    }

    return status;
}

/*!
    \brief      handle USB Set_Descriptor request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_setdescriptor (usb_dev *udev, usb_req *req)
{
    (void)udev;
    (void)req;

    /* no handle */
    return REQ_SUPP;
}

/*!
    \brief      handle USB Get_Configuration request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_getconfiguration (usb_dev *udev, usb_req *req)
{
    (void)req;

    usb_reqsta req_status = REQ_NOTSUPP;

    switch (udev->cur_status) {
    case USBD_ADDRESSED:
        if (0U == udev->config) {
            req_status = REQ_SUPP;
        }
        break;

    case USBD_CONFIGURED:
        if (udev->config) {
            req_status = REQ_SUPP;
        }
        break;

    default:
        break;
    }

    if (REQ_SUPP == req_status) {
        usb_transc_config(&udev->transc_in[0], &(udev->config), 1U, 1U);
    }

    return req_status;
}

/*!
    \brief      handle USB Set_Configuration request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device operation cur_status
*/
static usb_reqsta _usb_std_setconfiguration (usb_dev *udev, usb_req *req)
{
    static uint8_t config;
    usb_reqsta status = REQ_NOTSUPP;

    config = (uint8_t)(req->wValue);

    if (config <= USBD_CFG_MAX_NUM) {
        switch (udev->cur_status) {
        case USBD_ADDRESSED:
            if (config){
                (void)udev->class_core->init(udev, config);

                udev->config = config;
                udev->cur_status = (uint8_t)USBD_CONFIGURED;
            }
            status = REQ_SUPP;
            break; 

        case USBD_CONFIGURED:
            if (0U == config) {
                (void)udev->class_core->deinit(udev, config);

                udev->config = config;
                udev->cur_status = (uint8_t)USBD_ADDRESSED;
            } else if (config != udev->config) {
                /* clear old configuration */
                (void)udev->class_core->deinit(udev, udev->config);

                /* set new configuration */
                udev->config = config;

                (void)udev->class_core->init(udev, config);
            } else {
                /* no operation */
            }
            status = REQ_SUPP;
            break;

        case USBD_DEFAULT:
            break;

        default:
            break;
        }
    }

    return status;
}

/*!
    \brief      handle USB Get_Interface request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_getinterface (usb_dev *udev, usb_req *req)
{
    switch (udev->cur_status) {
    case USBD_DEFAULT:
        break;

    case USBD_ADDRESSED:
        break;

    case USBD_CONFIGURED:
        if (BYTE_LOW(req->wIndex) < USBD_ITF_MAX_NUM) {
            usb_transc_config(&udev->transc_in[0], &(udev->class_core->req_altset), 1U, 1U);

            return REQ_SUPP;
        }
        break;

    default:
        break;
    }

    return REQ_NOTSUPP;
}

/*!
    \brief      handle USB Set_Interface request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_setinterface (usb_dev *udev, usb_req *req)
{
    switch (udev->cur_status) {
    case USBD_DEFAULT:
        break;

    case USBD_ADDRESSED:
        break;

    case USBD_CONFIGURED:
        if (BYTE_LOW(req->wIndex) < USBD_ITF_MAX_NUM) {
            udev->class_core->req_altset = (uint8_t)req->wValue;

            return REQ_SUPP;
        }
        break;

    default:
        break;
    }

    return REQ_NOTSUPP;
}

/*!
    \brief      handle USB SynchFrame request
    \param[in]  udev: pointer to USB device instance
    \param[in]  req: pointer to USB device request
    \param[out] none
    \retval     USB device request status
*/
static usb_reqsta _usb_std_synchframe (usb_dev *udev, usb_req *req)
{
    (void)udev;
    (void)req;

    /* no handle */
    return REQ_SUPP;
}

/*!
    \brief      convert hex 32bits value into unicode char
    \param[in]  value: Hex 32bits value
    \param[in]  pbuf: buffer pointer to store unicode char
    \param[in]  len: value length
    \param[out] none
    \retval     none
*/
static void int_to_unicode (uint32_t value, uint8_t *pbuf, uint8_t len)
{
    uint8_t index = 0U;

    for (index = 0U; index < len; index++) {
        if ((value >> 28U) < 0x0AU) {
            pbuf[2U * index] = (uint8_t)((value >> 28) + '0');
        } else {
            pbuf[2U * index] = (uint8_t)((value >> 28) + 'A' - 10U);
        }

        value = value << 4U;

        pbuf[2U * index + 1U] = 0U;
    }
}

/*!
    \brief      convert hex 32bits value into unicode char
    \param[in]  none
    \param[out] none
    \retval     none
*/
void serial_string_get (uint16_t *unicode_str)
{
    if (6U != (unicode_str[0] & 0x00FFU)) {
        uint32_t DeviceSerial0, DeviceSerial1, DeviceSerial2;

        DeviceSerial0 = *(uint32_t*)DEVICE_ID1;
        DeviceSerial1 = *(uint32_t*)DEVICE_ID2;
        DeviceSerial2 = *(uint32_t*)DEVICE_ID3;

        DeviceSerial0 += DeviceSerial2;

        if (0U != DeviceSerial0) {
            int_to_unicode(DeviceSerial0, (uint8_t*)&(unicode_str[1]), 8U);
            int_to_unicode(DeviceSerial1, (uint8_t*)&(unicode_str[9]), 4U);
        }
    } else {
        uint32_t device_serial = *(uint32_t*)DEVICE_ID;

        if (0U != device_serial) {
            unicode_str[1] = (uint16_t)(device_serial & 0x0000FFFFU);
            unicode_str[2] = (uint16_t)((device_serial & 0xFFFF0000U) >> 16U);

        }
    }
}