libnx  v4.2.2
uart.h
Go to the documentation of this file.
1 /**
2  * @file uart.h
3  * @brief UART service IPC wrapper.
4  * @author yellows8
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 #include "../kernel/event.h"
10 #include "../sf/service.h"
11 
12 /// UartPort
13 typedef enum {
14  UartPort_Bluetooth = 1, ///< Bluetooth
15  UartPort_JoyConR = 2, ///< Joy-Con(R)
16  UartPort_JoyConL = 3, ///< Joy-Con(L)
17  UartPort_MCU = 4, ///< MCU
18 } UartPort;
19 
20 /// UartPortForDev
21 typedef enum {
22  UartPortForDev_JoyConR = 1, ///< Joy-Con(R)
23  UartPortForDev_JoyConL = 2, ///< Joy-Con(L)
24  UartPortForDev_Bluetooth = 3, ///< Bluetooth
26 
27 /// FlowControlMode
28 typedef enum {
29  UartFlowControlMode_None = 0, ///< None
30  UartFlowControlMode_Hardware = 1, ///< Hardware
32 
33 /// PortEventType
34 typedef enum {
35  UartPortEventType_SendBufferEmpty = 0, ///< SendBufferEmpty
36  UartPortEventType_SendBufferReady = 1, ///< SendBufferReady
37  UartPortEventType_ReceiveBufferReady = 2, ///< ReceiveBufferReady
38  UartPortEventType_ReceiveEnd = 3, ///< ReceiveEnd
40 
41 /// PortSession
42 typedef struct {
43  Service s; ///< IPortSession
45 
46 /// Initialize uart.
48 
49 /// Exit uart.
50 void uartExit(void);
51 
52 /// Gets the Service object for the actual uart service session.
54 
55 /**
56  * @brief HasPort
57  * @param[in] port \ref UartPort
58  * @param[out] out Output success flag.
59  */
60 Result uartHasPort(UartPort port, bool *out);
61 
62 /**
63  * @brief HasPortForDev
64  * @param[in] port \ref UartPortForDev
65  * @param[out] out Output success flag.
66  */
67 Result uartHasPortForDev(UartPortForDev port, bool *out);
68 
69 /**
70  * @brief IsSupportedBaudRate
71  * @param[in] port \ref UartPort
72  * @param[in] baud_rate BaudRate
73  * @param[out] out Output success flag.
74  */
75 Result uartIsSupportedBaudRate(UartPort port, u32 baud_rate, bool *out);
76 
77 /**
78  * @brief IsSupportedBaudRateForDev
79  * @param[in] port \ref UartPortForDev
80  * @param[in] baud_rate BaudRate
81  * @param[out] out Output success flag.
82  */
83 Result uartIsSupportedBaudRateForDev(UartPortForDev port, u32 baud_rate, bool *out);
84 
85 /**
86  * @brief IsSupportedFlowControlMode
87  * @param[in] port \ref UartPort
88  * @param[in] flow_control_mode \ref UartFlowControlMode
89  * @param[out] out Output success flag.
90  */
91 Result uartIsSupportedFlowControlMode(UartPort port, UartFlowControlMode flow_control_mode, bool *out);
92 
93 /**
94  * @brief IsSupportedFlowControlModeForDev
95  * @param[in] port \ref UartPortForDev
96  * @param[in] flow_control_mode \ref UartFlowControlMode
97  * @param[out] out Output success flag.
98  */
100 
101 /**
102  * @brief Creates an \ref UartPortSession.
103  * @note Use \ref uartPortSessionOpenPort or \ref uartPortSessionOpenPortForDev before using any other cmds.
104  * @param[out] s \ref UartPortSession
105  */
107 
108 /**
109  * @brief IsSupportedPortEvent
110  * @param[in] port \ref UartPort
111  * @param[in] port_event_type \ref UartPortEventType
112  * @param[out] out Output success flag.
113  */
114 Result uartIsSupportedPortEvent(UartPort port, UartPortEventType port_event_type, bool *out);
115 
116 /**
117  * @brief IsSupportedPortEventForDev
118  * @param[in] port \ref UartPortForDev
119  * @param[in] port_event_type \ref UartPortEventType
120  * @param[out] out Output success flag.
121  */
123 
124 /**
125  * @brief IsSupportedDeviceVariation
126  * @note Only available on [7.0.0+].
127  * @param[in] port \ref UartPort
128  * @param[in] device_variation DeviceVariation
129  * @param[out] out Output success flag.
130  */
131 Result uartIsSupportedDeviceVariation(UartPort port, u32 device_variation, bool *out);
132 
133 /**
134  * @brief IsSupportedDeviceVariationForDev
135  * @note Only available on [7.0.0+].
136  * @param[in] port \ref UartPortForDev
137  * @param[in] device_variation DeviceVariation
138  * @param[out] out Output success flag.
139  */
140 Result uartIsSupportedDeviceVariationForDev(UartPortForDev port, u32 device_variation, bool *out);
141 
142 ///@name IPortSession
143 ///@{
144 
145 /**
146  * @brief Close an \ref UartPortSession.
147  * @param s \ref UartPortSession
148  */
150 
151 /**
152  * @brief OpenPort
153  * @note This is not usable when the specified \ref UartPort is already being used.
154  * @param s \ref UartPortSession
155  * @param[out] out Output success flag.
156  * @param[in] port \ref UartPort
157  * @param[in] baud_rate BaudRate
158  * @param[in] flow_control_mode \ref UartFlowControlMode
159  * @param[in] device_variation [7.0.0+] DeviceVariation
160  * @param[in] is_invert_tx [6.0.0+] IsInvertTx
161  * @param[in] is_invert_rx [6.0.0+] IsInvertRx
162  * @param[in] is_invert_rts [6.0.0+] IsInvertRts
163  * @param[in] is_invert_cts [6.0.0+] IsInvertCts
164  * @param[in] send_buffer Send buffer, must be 0x1000-byte aligned.
165  * @param[in] send_buffer_length Send buffer size, must be 0x1000-byte aligned.
166  * @param[in] receive_buffer Receive buffer, must be 0x1000-byte aligned.
167  * @param[in] receive_buffer_length Receive buffer size, must be 0x1000-byte aligned.
168  */
169 Result uartPortSessionOpenPort(UartPortSession* s, bool *out, UartPort port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, void* send_buffer, u64 send_buffer_length, void* receive_buffer, u64 receive_buffer_length);
170 
171 /**
172  * @brief OpenPortForDev
173  * @note See the notes for \ref uartPortSessionOpenPort.
174  * @param s \ref UartPortSession
175  * @param[out] out Output success flag.
176  * @param[in] port \ref UartPortForDev
177  * @param[in] baud_rate BaudRate
178  * @param[in] flow_control_mode \ref UartFlowControlMode
179  * @param[in] device_variation [7.0.0+] DeviceVariation
180  * @param[in] is_invert_tx [6.0.0+] IsInvertTx
181  * @param[in] is_invert_rx [6.0.0+] IsInvertRx
182  * @param[in] is_invert_rts [6.0.0+] IsInvertRts
183  * @param[in] is_invert_cts [6.0.0+] IsInvertCts
184  * @param[in] send_buffer Send buffer, must be 0x1000-byte aligned.
185  * @param[in] send_buffer_length Send buffer size, must be 0x1000-byte aligned.
186  * @param[in] receive_buffer Receive buffer, must be 0x1000-byte aligned.
187  * @param[in] receive_buffer_length Receive buffer size, must be 0x1000-byte aligned.
188  */
189 Result uartPortSessionOpenPortForDev(UartPortSession* s, bool *out, UartPortForDev port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, void* send_buffer, u64 send_buffer_length, void* receive_buffer, u64 receive_buffer_length);
190 
191 /**
192  * @brief GetWritableLength
193  * @param s \ref UartPortSession
194  * @param[out] out Output WritableLength.
195  */
197 
198 /**
199  * @brief Send
200  * @param s \ref UartPortSession
201  * @param[in] in_data Input data buffer.
202  * @param[in] size Input data buffer size.
203  * @param[out] out Output size.
204  */
205 Result uartPortSessionSend(UartPortSession* s, const void* in_data, size_t size, u64 *out);
206 
207 /**
208  * @brief GetReadableLength
209  * @param s \ref UartPortSession
210  * @param[out] out Output ReadableLength.
211  */
213 
214 /**
215  * @brief Receive
216  * @param s \ref UartPortSession
217  * @param[out] out_data Output data buffer.
218  * @param[in] size Output data buffer size.
219  * @param[out] out Output size.
220  */
221 Result uartPortSessionReceive(UartPortSession* s, void* out_data, size_t size, u64 *out);
222 
223 /**
224  * @brief BindPortEvent
225  * @note The Event must be closed by the user after using \ref uartPortSessionUnbindPortEvent.
226  * @param s \ref UartPortSession
227  * @param[in] port_event_type \ref UartPortEventType
228  * @param[in] threshold Threshold
229  * @param[out] out Output success flag.
230  * @param[out] out_event Output Event with autoclear=false.
231  */
232 Result uartPortSessionBindPortEvent(UartPortSession* s, UartPortEventType port_event_type, s64 threshold, bool *out, Event *out_event);
233 
234 /**
235  * @brief UnbindPortEvent
236  * @param s \ref UartPortSession
237  * @param[in] port_event_type \ref UartPortEventType
238  * @param[out] out Output success flag.
239  */
241 
242 ///@}
243 
s64
int64_t s64
64-bit signed integer.
Definition: types.h:28
uartIsSupportedDeviceVariationForDev
Result uartIsSupportedDeviceVariationForDev(UartPortForDev port, u32 device_variation, bool *out)
IsSupportedDeviceVariationForDev.
UartPortForDev
UartPortForDev
UartPortForDev.
Definition: uart.h:21
UartFlowControlMode_None
@ UartFlowControlMode_None
None.
Definition: uart.h:29
uartPortSessionSend
Result uartPortSessionSend(UartPortSession *s, const void *in_data, size_t size, u64 *out)
Send.
uartInitialize
Result uartInitialize(void)
Initialize uart.
Event
Kernel-mode event structure.
Definition: event.h:13
uartPortSessionReceive
Result uartPortSessionReceive(UartPortSession *s, void *out_data, size_t size, u64 *out)
Receive.
uartCreatePortSession
Result uartCreatePortSession(UartPortSession *s)
Creates an UartPortSession.
uartPortSessionBindPortEvent
Result uartPortSessionBindPortEvent(UartPortSession *s, UartPortEventType port_event_type, s64 threshold, bool *out, Event *out_event)
BindPortEvent.
uartIsSupportedPortEventForDev
Result uartIsSupportedPortEventForDev(UartPortForDev port, UartPortEventType port_event_type, bool *out)
IsSupportedPortEventForDev.
UartPortEventType_SendBufferReady
@ UartPortEventType_SendBufferReady
SendBufferReady.
Definition: uart.h:36
uartPortSessionOpenPortForDev
Result uartPortSessionOpenPortForDev(UartPortSession *s, bool *out, UartPortForDev port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, void *send_buffer, u64 send_buffer_length, void *receive_buffer, u64 receive_buffer_length)
OpenPortForDev.
uartPortSessionClose
void uartPortSessionClose(UartPortSession *s)
Close an UartPortSession.
UartPortEventType
UartPortEventType
PortEventType.
Definition: uart.h:34
UartPortForDev_JoyConR
@ UartPortForDev_JoyConR
Joy-Con(R)
Definition: uart.h:22
UartPortEventType_ReceiveEnd
@ UartPortEventType_ReceiveEnd
ReceiveEnd.
Definition: uart.h:38
uartPortSessionGetWritableLength
Result uartPortSessionGetWritableLength(UartPortSession *s, u64 *out)
GetWritableLength.
UartPortEventType_ReceiveBufferReady
@ UartPortEventType_ReceiveBufferReady
ReceiveBufferReady.
Definition: uart.h:37
UartPort_Bluetooth
@ UartPort_Bluetooth
Bluetooth.
Definition: uart.h:14
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
UartPort_JoyConR
@ UartPort_JoyConR
Joy-Con(R)
Definition: uart.h:15
uartIsSupportedDeviceVariation
Result uartIsSupportedDeviceVariation(UartPort port, u32 device_variation, bool *out)
IsSupportedDeviceVariation.
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
UartPortSession
PortSession.
Definition: uart.h:42
UartPortForDev_JoyConL
@ UartPortForDev_JoyConL
Joy-Con(L)
Definition: uart.h:23
Result
u32 Result
Function error code result type.
Definition: types.h:44
UartFlowControlMode_Hardware
@ UartFlowControlMode_Hardware
Hardware.
Definition: uart.h:30
uartPortSessionGetReadableLength
Result uartPortSessionGetReadableLength(UartPortSession *s, u64 *out)
GetReadableLength.
uartGetServiceSession
Service * uartGetServiceSession(void)
Gets the Service object for the actual uart service session.
uartHasPortForDev
Result uartHasPortForDev(UartPortForDev port, bool *out)
HasPortForDev.
uartIsSupportedPortEvent
Result uartIsSupportedPortEvent(UartPort port, UartPortEventType port_event_type, bool *out)
IsSupportedPortEvent.
uartIsSupportedBaudRateForDev
Result uartIsSupportedBaudRateForDev(UartPortForDev port, u32 baud_rate, bool *out)
IsSupportedBaudRateForDev.
uartExit
void uartExit(void)
Exit uart.
UartPortEventType_SendBufferEmpty
@ UartPortEventType_SendBufferEmpty
SendBufferEmpty.
Definition: uart.h:35
uartIsSupportedFlowControlModeForDev
Result uartIsSupportedFlowControlModeForDev(UartPortForDev port, UartFlowControlMode flow_control_mode, bool *out)
IsSupportedFlowControlModeForDev.
Service
Service object structure.
Definition: service.h:13
UartPort_JoyConL
@ UartPort_JoyConL
Joy-Con(L)
Definition: uart.h:16
uartHasPort
Result uartHasPort(UartPort port, bool *out)
HasPort.
uartIsSupportedBaudRate
Result uartIsSupportedBaudRate(UartPort port, u32 baud_rate, bool *out)
IsSupportedBaudRate.
uartPortSessionOpenPort
Result uartPortSessionOpenPort(UartPortSession *s, bool *out, UartPort port, u32 baud_rate, UartFlowControlMode flow_control_mode, u32 device_variation, bool is_invert_tx, bool is_invert_rx, bool is_invert_rts, bool is_invert_cts, void *send_buffer, u64 send_buffer_length, void *receive_buffer, u64 receive_buffer_length)
OpenPort.
UartPort
UartPort
UartPort.
Definition: uart.h:13
UartPort_MCU
@ UartPort_MCU
MCU.
Definition: uart.h:17
UartFlowControlMode
UartFlowControlMode
FlowControlMode.
Definition: uart.h:28
uartPortSessionUnbindPortEvent
Result uartPortSessionUnbindPortEvent(UartPortSession *s, UartPortEventType port_event_type, bool *out)
UnbindPortEvent.
uartIsSupportedFlowControlMode
Result uartIsSupportedFlowControlMode(UartPort port, UartFlowControlMode flow_control_mode, bool *out)
IsSupportedFlowControlMode.
UartPortForDev_Bluetooth
@ UartPortForDev_Bluetooth
Bluetooth.
Definition: uart.h:24
UartPortSession::s
Service s
IPortSession.
Definition: uart.h:43