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