libnx  v4.6.0
usb_comms.h
Go to the documentation of this file.
1 /**
2  * @file usb_comms.h
3  * @brief USB comms.
4  * @author yellows8
5  * @author plutoo
6  * @copyright libnx Authors
7  */
8 #pragma once
9 #include "../../types.h"
10 
11 typedef struct {
12  u8 bInterfaceClass;
13  u8 bInterfaceSubClass;
14  u8 bInterfaceProtocol;
16 
17 /// Initializes usbComms with the default number of interfaces (1)
19 
20 /// Initializes usbComms with a specific number of interfaces.
21 Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *infos, u16 idVendor, u16 idProduct);
22 
23 /// Exits usbComms.
24 void usbCommsExit(void);
25 
26 /// Sets whether to throw a fatal error in usbComms{Read/Write}* on failure, or just return the transferred size. By default (false) the latter is used.
27 void usbCommsSetErrorHandling(bool flag);
28 
29 ///@name Synchronous API
30 ///@{
31 
32 /// Read data with the default interface.
33 size_t usbCommsRead(void* buffer, size_t size);
34 
35 /// Write data with the default interface.
36 size_t usbCommsWrite(const void* buffer, size_t size);
37 
38 /// Same as usbCommsRead except with the specified interface.
39 size_t usbCommsReadEx(void* buffer, size_t size, u32 interface);
40 
41 /// Same as usbCommsWrite except with the specified interface.
42 size_t usbCommsWriteEx(const void* buffer, size_t size, u32 interface);
43 
44 ///@}
45 
46 ///@name Asynchronous API
47 ///@{
48 
49 /// Retrieve event used for read completion with the given interface.
51 
52 /// Start an asynchronous read. The completion event will be signaled when the read completes.
53 /// The buffer must be page-aligned and no larger than one page.
54 Result usbCommsReadAsync(void *buffer, size_t size, u32 *urbId, u32 interface);
55 
56 /// Complete an asynchronous read, clearing the completion event, and return the amount of data which was read.
57 Result usbCommsGetReadResult(u32 urbId, u32 *transferredSize, u32 interface);
58 
59 
60 /// Retrieve event used for write completion with the given interface.
62 
63 /// Start an asynchronous write. The completion event will be signaled when the write completes.
64 /// The buffer must be page-aligned and no larger than one page.
65 Result usbCommsWriteAsync(void *buffer, size_t size, u32 *urbId, u32 interface);
66 
67 /// Complete an asynchronous write, clearing the completion event, and return the amount of data which was written.
68 Result usbCommsGetWriteResult(u32 urbId, u32 *transferredSize, u32 interface);
69 
70 ///@}
Kernel-mode event structure.
Definition: event.h:13
Definition: usb_comms.h:11
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
u32 Result
Function error code result type.
Definition: types.h:44
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
Result usbCommsGetWriteResult(u32 urbId, u32 *transferredSize, u32 interface)
Complete an asynchronous write, clearing the completion event, and return the amount of data which wa...
Result usbCommsWriteAsync(void *buffer, size_t size, u32 *urbId, u32 interface)
Start an asynchronous write.
size_t usbCommsWriteEx(const void *buffer, size_t size, u32 interface)
Same as usbCommsWrite except with the specified interface.
Result usbCommsGetReadResult(u32 urbId, u32 *transferredSize, u32 interface)
Complete an asynchronous read, clearing the completion event, and return the amount of data which was...
Event * usbCommsGetWriteCompletionEvent(u32 interface)
Retrieve event used for write completion with the given interface.
void usbCommsExit(void)
Exits usbComms.
Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *infos, u16 idVendor, u16 idProduct)
Initializes usbComms with a specific number of interfaces.
size_t usbCommsReadEx(void *buffer, size_t size, u32 interface)
Same as usbCommsRead except with the specified interface.
size_t usbCommsWrite(const void *buffer, size_t size)
Write data with the default interface.
Result usbCommsInitialize(void)
Initializes usbComms with the default number of interfaces (1)
void usbCommsSetErrorHandling(bool flag)
Sets whether to throw a fatal error in usbComms{Read/Write}* on failure, or just return the transferr...
size_t usbCommsRead(void *buffer, size_t size)
Read data with the default interface.
Event * usbCommsGetReadCompletionEvent(u32 interface)
Retrieve event used for read completion with the given interface.
Result usbCommsReadAsync(void *buffer, size_t size, u32 *urbId, u32 interface)
Start an asynchronous read.