blob: 69dd435b103e1f29013cd171b6878a01fae4108e [file] [log] [blame]
Kévin Redon4cd3f7d2019-01-24 17:57:13 +01001/**
2 * \file
3 *
4 * \brief SPI Slave Async related functionality declaration.
5 *
6 * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
7 *
8 * \asf_license_start
9 *
10 * \page License
11 *
12 * Subject to your compliance with these terms, you may use Microchip
13 * software and any derivatives exclusively with Microchip products.
14 * It is your responsibility to comply with third party license terms applicable
15 * to your use of third party software (including open source software) that
16 * may accompany Microchip software.
17 *
18 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
19 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
20 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
21 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
22 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
23 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
24 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
25 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
26 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
27 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29 *
30 * \asf_license_stop
31 *
32 */
33
34#ifndef _HPL_SPI_M_ASYNC_H_INCLUDED
35#define _HPL_SPI_M_ASYNC_H_INCLUDED
36
37#include <hpl_spi.h>
38#include <hpl_spi_async.h>
39
40/**
41 * \addtogroup hpl_spi HPL SPI
42 *
43 *
44 *@{
45 */
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/** Uses common SPI async device driver. */
52#define _spi_m_async_dev _spi_async_dev
53
54#define _spi_m_async_dev_cb_type _spi_async_dev_cb_type
55
56/** Uses common SPI async device driver complete callback type. */
57#define _spi_m_async_dev_cb_error_t _spi_async_dev_cb_error_t
58
59/** Uses common SPI async device driver transfer callback type. */
60#define _spi_m_async_dev_cb_xfer_t _spi_async_dev_cb_xfer_t
61
62/**
63 * \brief Initialize SPI for access with interrupts
64 * It will load default hardware configuration and software struct.
65 * \param[in, out] dev Pointer to the SPI device instance.
66 * \param[in] hw Pointer to the hardware base.
67 * \retval ERR_INVALID_ARG Input parameter problem.
68 * \retval ERR_BUSY SPI hardware not ready (resetting).
69 * \retval ERR_DENIED SPI has been enabled.
70 * \retval 0 Operation done successfully.
71 */
72int32_t _spi_m_async_init(struct _spi_m_async_dev *dev, void *const hw);
73
74/**
75 * \brief Initialize SPI for access with interrupts
76 * Disable, reset the hardware and the software struct.
77 * \param[in, out] dev Pointer to the SPI device instance.
78 * \return Operation status.
79 * \retval 0 Operation done successfully.
80 */
81int32_t _spi_m_async_deinit(struct _spi_m_async_dev *dev);
82
83/**
84 * \brief Enable SPI for access with interrupts
85 * Enable the SPI and enable callback generation of receive and error
86 * interrupts.
87 * \param[in, out] dev Pointer to the SPI device instance.
88 * \return Operation status.
89 * \retval ERR_INVALID_ARG Input parameter problem.
90 * \retval ERR_BUSY SPI hardware not ready (resetting).
91 * \retval 0 Operation done successfully.
92 */
93int32_t _spi_m_async_enable(struct _spi_m_async_dev *dev);
94
95/**
96 * \brief Disable SPI for access without interrupts
97 * Disable SPI and interrupts. Deactivate all CS pins if works as master.
98 * \param[in, out] dev Pointer to the SPI device instance.
99 * \return Operation status.
100 * \retval 0 Operation done successfully.
101 */
102int32_t _spi_m_async_disable(struct _spi_m_async_dev *dev);
103
104/**
105 * \brief Set SPI transfer mode
106 * Set SPI transfer mode (\ref spi_transfer_mode),
107 * which controls clock polarity and clock phase.
108 * Mode 0: leading edge is rising edge, data sample on leading edge.
109 * Mode 1: leading edge is rising edge, data sample on trailing edge.
110 * Mode 2: leading edge is falling edge, data sample on leading edge.
111 * Mode 3: leading edge is falling edge, data sample on trailing edge.
112 * \param[in, out] dev Pointer to the SPI device instance.
113 * \param[in] mode The SPI transfer mode.
114 * \return Operation status.
115 * \retval ERR_BUSY SPI is not ready to accept new setting.
116 * \retval 0 Operation done successfully.
117 */
118int32_t _spi_m_async_set_mode(struct _spi_m_async_dev *dev, const enum spi_transfer_mode mode);
119
120/**
121 * \brief Set SPI baudrate
122 * \param[in, out] dev Pointer to the SPI device instance.
123 * \param[in] baud_val The SPI baudrate value, see \ref _spi_calc_baud_val() on
124 * how it's generated.
125 * \return Operation status.
126 * \retval ERR_BUSY SPI is not ready to accept new setting.
127 * \retval 0 Operation done successfully.
128 */
129int32_t _spi_m_async_set_baudrate(struct _spi_m_async_dev *dev, const uint32_t baud_val);
130
131/**
132 * \brief Set SPI baudrate
133 * \param[in, out] dev Pointer to the SPI device instance.
134 * \param[in] char_size The character size, see \ref spi_char_size.
135 * \return Operation status.
136 * \retval ERR_INVALID_ARG The character size is not supported.
137 * \retval ERR_BUSY SPI is not ready to accept new setting.
138 * \retval 0 Operation done successfully.
139 */
140int32_t _spi_m_async_set_char_size(struct _spi_m_async_dev *dev, const enum spi_char_size char_size);
141
142/**
143 * \brief Set SPI data order
144 * \param[in, out] dev Pointer to the SPI device instance.
145 * \param[in] dord SPI data order (LSB/MSB first).
146 * \return Operation status.
147 * \retval ERR_INVALID_ARG The character size is not supported.
148 * \retval ERR_BUSY SPI is not ready to accept new setting.
149 * \retval 0 Operation done successfully.
150 */
151int32_t _spi_m_async_set_data_order(struct _spi_m_async_dev *dev, const enum spi_data_order dord);
152
153/**
154 * \brief Enable interrupt on character output
155 *
156 * Enable interrupt when a new character can be written
157 * to the SPI device.
158 *
159 * \param[in] dev Pointer to the SPI device instance
160 * \param[in] state true = enable output interrupt
161 * false = disable output interrupt
162 *
163 * \return Status code
164 * \retval 0 Ok status
165 */
166int32_t _spi_m_async_enable_tx(struct _spi_m_async_dev *dev, bool state);
167
168/**
169 * \brief Enable interrupt on character input
170 *
171 * Enable interrupt when a new character is ready to be
172 * read from the SPI device.
173 *
174 * \param[in] dev Pointer to the SPI device instance
175 * \param[in] state true = enable input interrupts
176 * false = disable input interrupt
177 *
178 * \return Status code
179 * \retvat 0 OK Status
180 */
181int32_t _spi_m_async_enable_rx(struct _spi_m_async_dev *dev, bool state);
182
183/**
184 * \brief Enable interrupt on after data transmission complate
185 *
186 * \param[in] dev Pointer to the SPI device instance
187 * \param[in] state true = enable input interrupts
188 * false = disable input interrupt
189 *
190 * \return Status code
191 * \retvat 0 OK Status
192 */
193int32_t _spi_m_async_enable_tx_complete(struct _spi_m_async_dev *dev, bool state);
194
195/**
196 * \brief Read one character to SPI device instance
197 * \param[in, out] dev Pointer to the SPI device instance.
198 *
199 * \return Character read from SPI module
200 */
201uint16_t _spi_m_async_read_one(struct _spi_m_async_dev *dev);
202
203/**
204 * \brief Write one character to assigned buffer
205 * \param[in, out] dev Pointer to the SPI device instance.
206 * \param[in] data
207 *
208 * \return Status code of write operation
209 * \retval 0 Write operation OK
210 */
211int32_t _spi_m_async_write_one(struct _spi_m_async_dev *dev, uint16_t data);
212
213/**
214 * \brief Register the SPI device callback
215 * \param[in, out] dev Pointer to the SPI device instance.
216 * \param[in] cb_type The callback type.
217 * \param[in] func The callback function to register. NULL to disable callback.
218 * \return Always 0.
219 */
220int32_t _spi_m_async_register_callback(struct _spi_m_async_dev *dev, const enum _spi_m_async_dev_cb_type cb_type,
221 const FUNC_PTR func);
222
223/**
224 * \brief Enable/disable SPI master interrupt
225 *
226 * param[in] device The pointer to SPI master device instance
227 * param[in] type The type of interrupt to disable/enable if applicable
228 * param[in] state Enable or disable
229 */
230void _spi_m_async_set_irq_state(struct _spi_m_async_dev *const device, const enum _spi_m_async_dev_cb_type type,
231 const bool state);
232
233#ifdef __cplusplus
234}
235#endif
236
237/**@}*/
238#endif /* ifndef _HPL_SPI_M_ASYNC_H_INCLUDED */