[fix][usb]return data type as rt_ssize_t

rt_ssize_t can give negative error code, which follows the unix style correctly
This commit is contained in:
Z8MAN8 2023-10-11 21:39:30 +08:00 committed by Meco Man
parent a8249a28c6
commit 19bfdac891
10 changed files with 42 additions and 32 deletions

View File

@ -1,11 +1,12 @@
/* /*
* Copyright (c) 2006-2021, RT-Thread Development Team * Copyright (c) 2006-2023, RT-Thread Development Team
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2023-02-28 leo first version * 2023-02-28 leo first version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
*/ */
#include <rtthread.h> #include <rtthread.h>
@ -152,20 +153,20 @@ static rt_err_t _ep_disable(uep_t ep)
return RT_EOK; return RT_EOK;
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
RT_ASSERT(buffer != RT_NULL); RT_ASSERT(buffer != RT_NULL);
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
usbd_ept_recv(p_usbd_instance->p_usbd_core, address, buffer, size); usbd_ept_recv(p_usbd_instance->p_usbd_core, address, buffer, size);
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
usbd_ept_send(p_usbd_instance->p_usbd_core, address, buffer, size); usbd_ept_send(p_usbd_instance->p_usbd_core, address, buffer, size);
return size; return size;

View File

@ -1,11 +1,12 @@
/* /*
* Copyright (c) 2006-2021, RT-Thread Development Team * Copyright (c) 2006-2023, RT-Thread Development Team
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2023-02-28 leo first version * 2023-02-28 leo first version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
*/ */
#include <rtthread.h> #include <rtthread.h>
@ -175,20 +176,20 @@ static rt_err_t _ep_disable(uep_t ep)
return RT_EOK; return RT_EOK;
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
RT_ASSERT(buffer != RT_NULL); RT_ASSERT(buffer != RT_NULL);
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
usbd_ept_recv(&p_usbfs_instance->p_otg_core->dev, address, buffer, size); usbd_ept_recv(&p_usbfs_instance->p_otg_core->dev, address, buffer, size);
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
usbd_ept_send(&p_usbfs_instance->p_otg_core->dev, address, buffer, size); usbd_ept_send(&p_usbfs_instance->p_otg_core->dev, address, buffer, size);
return size; return size;

View File

@ -6,6 +6,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2017-12-04 ZYH first implementation * 2017-12-04 ZYH first implementation
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
*/ */
#include <usb/include/usb_device_config.h> #include <usb/include/usb_device_config.h>
#include <usb/include/usb.h> #include <usb/include/usb.h>
@ -161,7 +162,7 @@ static rt_err_t _ehci0_ep_disable(uep_t ep)
return RT_EOK; return RT_EOK;
} }
static rt_size_t _ehci0_ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ehci0_ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
@ -170,13 +171,13 @@ static rt_size_t _ehci0_ep_read(rt_uint8_t address, void *buffer)
return size; return size;
} }
static rt_size_t _ehci0_ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ehci0_ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
USB_DeviceRecvRequest(ehci0_handle, address, buffer, size); USB_DeviceRecvRequest(ehci0_handle, address, buffer, size);
return size; return size;
} }
static rt_size_t _ehci0_ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ehci0_ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
USB_DeviceSendRequest(ehci0_handle, address, buffer, size); USB_DeviceSendRequest(ehci0_handle, address, buffer, size);
return size; return size;

View File

@ -7,6 +7,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2021-02-24 klcheng First version * 2021-02-24 klcheng First version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
* *
******************************************************************************/ ******************************************************************************/
@ -192,7 +193,7 @@ static rt_err_t _ep_disable(uep_t ep)
return RT_EOK; return RT_EOK;
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
rt_uint8_t *buf; rt_uint8_t *buf;
@ -208,7 +209,7 @@ static rt_size_t _ep_read(rt_uint8_t address, void *buffer)
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT(!(address & USB_DIR_IN)); RT_ASSERT(!(address & USB_DIR_IN));
@ -217,7 +218,7 @@ static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t si
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT((address & USB_DIR_IN)); RT_ASSERT((address & USB_DIR_IN));

View File

@ -7,6 +7,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2020-09-17 CHChen First version * 2020-09-17 CHChen First version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
* *
******************************************************************************/ ******************************************************************************/
@ -229,7 +230,7 @@ static rt_err_t _ep_disable(uep_t ep)
return RT_EOK; return RT_EOK;
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
rt_uint8_t *buf; rt_uint8_t *buf;
@ -245,7 +246,7 @@ static rt_size_t _ep_read(rt_uint8_t address, void *buffer)
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT(!(address & USB_DIR_IN)); RT_ASSERT(!(address & USB_DIR_IN));
@ -254,7 +255,7 @@ static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t si
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT((address & USB_DIR_IN)); RT_ASSERT((address & USB_DIR_IN));

View File

@ -7,6 +7,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2022-3-15 Wayne First version * 2022-3-15 Wayne First version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
* *
******************************************************************************/ ******************************************************************************/
@ -276,7 +277,7 @@ static rt_err_t _ep_disable(uep_t ep)
return RT_EOK; return RT_EOK;
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
rt_uint8_t *buf; rt_uint8_t *buf;
@ -292,7 +293,7 @@ static rt_size_t _ep_read(rt_uint8_t address, void *buffer)
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT(!(address & USB_DIR_IN)); RT_ASSERT(!(address & USB_DIR_IN));
@ -301,7 +302,7 @@ static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t si
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT((address & USB_DIR_IN)); RT_ASSERT((address & USB_DIR_IN));

View File

@ -7,6 +7,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2020-3-25 Egbert First version * 2020-3-25 Egbert First version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
* *
******************************************************************************/ ******************************************************************************/
@ -210,7 +211,7 @@ static rt_err_t _ep_disable(uep_t ep)
return RT_EOK; return RT_EOK;
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
rt_uint8_t *buf; rt_uint8_t *buf;
@ -226,7 +227,7 @@ static rt_size_t _ep_read(rt_uint8_t address, void *buffer)
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT(!(address & USB_DIR_IN)); RT_ASSERT(!(address & USB_DIR_IN));
@ -235,7 +236,7 @@ static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t si
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT((address & USB_DIR_IN)); RT_ASSERT((address & USB_DIR_IN));

View File

@ -7,6 +7,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2021-03-16 Wayne First version * 2021-03-16 Wayne First version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
* *
******************************************************************************/ ******************************************************************************/
@ -436,7 +437,7 @@ __STATIC_INLINE void nu_buffer_cpy(rt_uint8_t address, void *buffer, rt_size_t s
} }
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
@ -464,7 +465,7 @@ static rt_size_t _ep_read(rt_uint8_t address, void *buffer)
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT(!(address & USB_DIR_IN)); RT_ASSERT(!(address & USB_DIR_IN));
@ -496,7 +497,7 @@ static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t si
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT((address & USB_DIR_IN)); RT_ASSERT((address & USB_DIR_IN));

View File

@ -7,6 +7,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2020-12-25 Wayne First version * 2020-12-25 Wayne First version
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
* *
******************************************************************************/ ******************************************************************************/
@ -437,7 +438,7 @@ __STATIC_INLINE void nu_buffer_cpy(rt_uint8_t address, void *buffer, rt_size_t s
} }
} }
static rt_size_t _ep_read(rt_uint8_t address, void *buffer) static rt_ssize_t _ep_read(rt_uint8_t address, void *buffer)
{ {
rt_size_t size = 0; rt_size_t size = 0;
@ -465,7 +466,7 @@ static rt_size_t _ep_read(rt_uint8_t address, void *buffer)
return size; return size;
} }
static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT(!(address & USB_DIR_IN)); RT_ASSERT(!(address & USB_DIR_IN));
@ -497,7 +498,7 @@ static rt_size_t _ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t si
return size; return size;
} }
static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size) static rt_ssize_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
{ {
RT_ASSERT((address & USB_DIR_IN)); RT_ASSERT((address & USB_DIR_IN));

View File

@ -9,6 +9,7 @@
* 2012-12-12 heyuanjie87 change endpoint and function handler * 2012-12-12 heyuanjie87 change endpoint and function handler
* 2013-04-26 aozima add DEVICEQUALIFIER support. * 2013-04-26 aozima add DEVICEQUALIFIER support.
* 2017-11-15 ZYH fix ep0 transform error * 2017-11-15 ZYH fix ep0 transform error
* 2023-10-11 ChuShicheng change rt_size_t to rt_ssize_t
*/ */
#ifndef __USB_DEVICE_H__ #ifndef __USB_DEVICE_H__
@ -86,9 +87,9 @@ struct udcd_ops
rt_err_t (*ep_clear_stall)(rt_uint8_t address); rt_err_t (*ep_clear_stall)(rt_uint8_t address);
rt_err_t (*ep_enable)(struct uendpoint* ep); rt_err_t (*ep_enable)(struct uendpoint* ep);
rt_err_t (*ep_disable)(struct uendpoint* ep); rt_err_t (*ep_disable)(struct uendpoint* ep);
rt_size_t (*ep_read_prepare)(rt_uint8_t address, void *buffer, rt_size_t size); rt_ssize_t (*ep_read_prepare)(rt_uint8_t address, void *buffer, rt_size_t size);
rt_size_t (*ep_read)(rt_uint8_t address, void *buffer); rt_ssize_t (*ep_read)(rt_uint8_t address, void *buffer);
rt_size_t (*ep_write)(rt_uint8_t address, void *buffer, rt_size_t size); rt_ssize_t (*ep_write)(rt_uint8_t address, void *buffer, rt_size_t size);
rt_err_t (*ep0_send_status)(void); rt_err_t (*ep0_send_status)(void);
rt_err_t (*suspend)(void); rt_err_t (*suspend)(void);
rt_err_t (*wakeup)(void); rt_err_t (*wakeup)(void);