summaryrefslogtreecommitdiff
path: root/mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.h
blob: 9c477c01adb4618eaff2f3135ceed4976d8ff367 (plain)
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
/**
 * USBPERIPHERALREADWRITE Peripheral Read/Write Header File
 * @file usb_peripheral_read_write.h
 * @defgroup usb_peripheral_read_write USB Peripheral Read/Write
 * @ingroup usb_peripheral
 * @brief API module for usb_peripheral covering low-level USB transaction functions.
 * @version USB Device Stack HAL Driver Version 1.0.0
 */
/*
    (c) 2021 Microchip Technology Inc. and its subsidiaries.

    Subject to your compliance with these terms, you may use Microchip software and any
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party
    license terms applicable to your use of third party software (including open source software) that
    may accompany Microchip software.

    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
    FOR A PARTICULAR PURPOSE.

    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
    SOFTWARE.
 */

#ifndef USB_PERIPHERAL_READ_WRITE_H
// cppcheck-suppress misra-c2012-2.5
#define USB_PERIPHERAL_READ_WRITE_H

#include <stdbool.h>
#include <stdint.h>

#include "usb_common_elements.h"
#include "usb_protocol_headers.h"

/**
 * @ingroup usb_peripheral_read_write
 * @brief Starts sending or receiving data on an endpoint by clearing BUSNACK.
 * Used as a final step while setting up a transaction on the bus.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_TransactionStart(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Aborts the next transaction on an endpoint by setting BUSNACK.
 * Used to stop exchanging data on an endpoint. The device will start NAKing requests from the host after calling this API.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_TransactionAbort(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Acknowledges the Transaction Complete status condition by clearing the Transaction Complete status bit.
 * Used to clear the Transaction Complete status bit after a transaction has successfully completed.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_TransactionCompleteAck(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Helper function to return the endpoint transaction complete condition.
 * @param None.
 * @retval 0 - Transaction not complete or pipe address is out of bounds
 * @retval 1 - Transaction is complete
 */
bool USB_TransactionIsCompleted(void);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Returns the pipe address and direction for the latest completed transaction.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_TransactionCompletedPipeGet(USB_PIPE_t *pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Resets the pipe.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_PipeReset(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Gets the current status of pipe.
 * @param pipe - A combination of endpoint address and direction
 * @return USB_PIPE_TRANSFER_OK or an Error code according to USB_TRANSFER_STATUS_t
 */
USB_TRANSFER_STATUS_t USB_PipeStatusGet(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Checks if the pipe status is busy.
 * @param pipe - A combination of endpoint address and direction
 * @retval 0  -  Pipe status not busy
 * @retval 1  -  Pipe status is busy
 */
bool USB_PipeStatusIsBusy(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Configures the pointer for the data transfer in a given pipe.
 * @param pipe - A combination of endpoint address and direction
 * @param *dataPtr - The pointer to the data location
 * @return None.
 */
void USB_PipeDataPtrSet(USB_PIPE_t pipe, uint8_t *dataPtr);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Gets the current data pointer for a given pipe.
 * @param pipe - A combination of endpoint address and direction
 * @return The pointer to the data location
 */
uint8_t *USB_PipeDataPtrGet(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Sets the size of pipe data to transfer.
 * @param pipe - A combination of endpoint address and direction
 * @param dataSize - The size of pipe data to transfer
 * @return None.
 */
void USB_PipeDataToTransferSizeSet(USB_PIPE_t pipe, uint16_t dataSize);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Gets the size of pipe data to transfer.
 * @param pipe - A combination of endpoint address and direction
 * @return The size of pipe data to transfer
 */
uint16_t USB_PipeDataToTransferSizeGet(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Gets the size of the transferred pipe data.
 * @param pipe - A combination of endpoint address and direction
 * @return The size of transferred pipe data
 */
uint16_t USB_PipeDataTransferredSizeGet(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Sets the size of the transferred pipe data.
 * @param pipe - A combination of endpoint address and direction
 * @param dataSize - The size of pipe data transferred
 * @return None.
 */
void USB_PipeDataTransferredSizeSet(USB_PIPE_t pipe, uint16_t dataSize);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Resets the size of transferred pipe data.
 * @param pipe - A combination of endpoint address and direction
 * @return None.
 */
void USB_PipeDataTransferredSizeReset(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Enables a ZLP on a transfer.
 * It is enabled by default if the AZLP static config is enabled for the pipe.
 * @param pipe - A combination of endpoint address and direction
 * @return None.
 */
void USB_PipeTransferZLP_Enable(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Sets the callback for transfer end.
 * @param pipe - A combination of endpoint address and direction
 * @param callback - A combination of pipe, status and transferred bytes
 * @return None.
 */
void USB_PipeTransferEndCallbackRegister(USB_PIPE_t pipe, USB_TRANSFER_END_CALLBACK_t callback);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Calls the callback for transfer end.
 * @param pipe - A combination of endpoint address and direction
 * @return None.
 */
void USB_PipeTransferEndCallback(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Checks the correctness of IN transactions and runs them.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_InTransactionRun(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Checks the correctness OUT transactions and runs them.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_OutTransactionRun(USB_PIPE_t pipe);

/**
 * @ingroup usb_peripheral_read_write
 * @brief Handles completed IN and OUT transactions.
 * Processes the completed transaction and either completes the transfer or runs the next transaction.
 * Will call the pipe transferEndCallback at the end of transfer, if configured.
 * @param pipe - A combination of endpoint address and direction
 * @return SUCCESS or an Error code according to RETURN_CODE_t
 */
RETURN_CODE_t USB_PipeTransactionComplete(USB_PIPE_t pipe);

#endif /* USB_PERIPHERAL_READ_WRITE_H */