blob: 2892e2c57b928cba2bba92563b9351f00a3c026f [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_S_ASYNC_H_INCLUDED
35#define _HPL_SPI_S_ASYNC_H_INCLUDED
36
37#include <hpl_spi_async.h>
38
39/**
40 * \addtogroup hpl_spi HPL SPI
41 *
42 *
43 *@{
44 */
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/** Uses common SPI async device driver. */
51#define _spi_s_async_dev _spi_async_dev
52
53#define _spi_s_async_dev_cb_type _spi_async_dev_cb_type
54
55/** Uses common SPI async device driver complete callback type. */
56#define _spi_m_async_dev_cb_error_t _spi_async_dev_cb_error_t
57
58/** Uses common SPI async device driver transfer callback type. */
59#define _spi_s_async_dev_cb_xfer_t _spi_async_dev_cb_xfer_t
60
61/**
62 * \brief Initialize SPI for access with interrupts
63 * It will load default hardware configuration and software struct.
64 * \param[in, out] dev Pointer to the SPI device instance.
65 * \param[in] hw Pointer to the hardware base.
66 * \return Operation status.
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_s_async_init(struct _spi_s_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_s_async_deinit(struct _spi_s_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_s_async_enable(struct _spi_s_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_s_async_disable(struct _spi_s_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_s_async_set_mode(struct _spi_s_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] char_size The character size, see \ref spi_char_size.
124 * \return Operation status.
125 * \retval ERR_INVALID_ARG The character size is not supported.
126 * \retval ERR_BUSY SPI is not ready to accept new setting.
127 * \retval 0 Operation done successfully.
128 */
129int32_t _spi_s_async_set_char_size(struct _spi_s_async_dev *dev, const enum spi_char_size char_size);
130
131/**
132 * \brief Set SPI data order
133 * \param[in, out] dev Pointer to the SPI device instance.
134 * \param[in] dord SPI data order (LSB/MSB first).
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_s_async_set_data_order(struct _spi_s_async_dev *dev, const enum spi_data_order dord);
141
142/**
143 * \brief Enable interrupt on character output
144 *
145 * Enable interrupt when a new character can be written
146 * to the SPI device.
147 *
148 * \param[in] dev Pointer to the SPI device instance
149 * \param[in] state true = enable output interrupt
150 * false = disable output interrupt
151 *
152 * \return Status code
153 * \retval 0 Ok status
154 */
155int32_t _spi_s_async_enable_tx(struct _spi_s_async_dev *dev, bool state);
156
157/**
158 * \brief Enable interrupt on character input
159 *
160 * Enable interrupt when a new character is ready to be
161 * read from the SPI device.
162 *
163 * \param[in] dev Pointer to the SPI device instance
164 * \param[in] state true = enable input interrupts
165 * false = disable input interrupt
166 *
167 * \return Status code
168 * \retvat 0 OK Status
169 */
170int32_t _spi_s_async_enable_rx(struct _spi_s_async_dev *dev, bool state);
171
172/**
173 * \brief Enable interrupt on Slave Select (SS) rising
174 *
175 * \param[in] dev Pointer to the SPI device instance
176 * \param[in] state true = enable input interrupts
177 * false = disable input interrupt
178 *
179 * \return Status code
180 * \retvat 0 OK Status
181 */
182int32_t _spi_s_async_enable_ss_detect(struct _spi_s_async_dev *dev, bool state);
183
184/**
185 * \brief Read one character to SPI device instance
186 * \param[in, out] dev Pointer to the SPI device instance.
187 *
188 * \return Character read from SPI module
189 */
190uint16_t _spi_s_async_read_one(struct _spi_s_async_dev *dev);
191
192/**
193 * \brief Write one character to assigned buffer
194 * \param[in, out] dev Pointer to the SPI device instance.
195 * \param[in] data
196 *
197 * \return Status code of write operation
198 * \retval 0 Write operation OK
199 */
200int32_t _spi_s_async_write_one(struct _spi_s_async_dev *dev, uint16_t data);
201
202/**
203 * \brief Register the SPI device callback
204 * \param[in, out] dev Pointer to the SPI device instance.
205 * \param[in] cb_type The callback type.
206 * \param[in] func The callback function to register. NULL to disable callback.
207 * \return Always 0.
208 */
209int32_t _spi_s_async_register_callback(struct _spi_s_async_dev *dev, const enum _spi_s_async_dev_cb_type cb_type,
210 const FUNC_PTR func);
211
212/**
213 * \brief Enable/disable SPI slave interrupt
214 *
215 * param[in] device The pointer to SPI slave device instance
216 * param[in] type The type of interrupt to disable/enable if applicable
217 * param[in] state Enable or disable
218 */
219void _spi_s_async_set_irq_state(struct _spi_s_async_dev *const device, const enum _spi_async_dev_cb_type type,
220 const bool state);
221
222#ifdef __cplusplus
223}
224#endif
225
226/**@}*/
227#endif /* ifndef _HPL_SPI_S_ASYNC_H_INCLUDED */