1 /**
2  * @file    spixf.h
3  * @brief   SPI Flash Controller driver header file.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_SPIXF_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_SPIXF_H_
29 
30 /* **** Includes **** */
31 #include "mxc_device.h"
32 #include "mxc_sys.h"
33 #include "spixfc_regs.h"
34 #include "spixfc_fifo_regs.h"
35 #include "spixfm_regs.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @defgroup spixf SPI External Flash (SPIXF)
43  * @ingroup periphlibs
44  * @{
45  */
46 
47 /* **** Definitions **** */
48 /**
49  * @brief      Active levels for slave select lines.
50  */
51 typedef enum {
52     MXC_SPIXF_SSEL0_HIGH = (0x1 << 0),
53     MXC_SPIXF_SSEL0_LOW = 0,
54     MXC_SPIXF_SSEL1_HIGH = (0x1 << 1),
55     MXC_SPIXF_SSEL1_LOW = 0,
56     MXC_SPIXF_SSEL2_HIGH = (0x1 << 2),
57     MXC_SPIXF_SSEL2_LOW = 0,
58     MXC_SPIXF_SSEL3_HIGH = (0x1 << 3),
59     MXC_SPIXF_SSEL3_LOW = 0
60 } mxc_spixf_ssel_t;
61 
62 /**
63  * @brief      Header direction.
64  */
65 typedef enum {
66     MXC_SPIXF_HEADER_DIR_NONE = 0,
67     MXC_SPIXF_HEADER_DIR_TX,
68     MXC_SPIXF_HEADER_DIR_RX,
69     MXC_SPIXF_HEADER_DIR_BOTH,
70 } mxc_spixf_hdr_direction_t;
71 
72 /**
73  * @brief      SPIXF Pin mode.
74  */
75 typedef enum {
76     MXC_SPIXF_ACTIVE_LOW = 0,
77     MXC_SPIXF_ACTIVE_HIGH,
78 } mxc_spixf_sspol_t;
79 
80 /**
81  * @brief      SPIXF set command.
82  */
83 typedef enum {
84     MXC_SPIXF_CMD_EVERY_TRANS = 0,
85     MXC_SPIXF_CMD_FIRST_TRANS,
86 } mxc_spixf_cmd_t;
87 
88 /**
89  * @brief      SPIXF mode.
90  * @note       modes 1 and 2 are not supported
91  */
92 typedef enum {
93     MXC_SPIXF_MODE_0 = 0,
94     MXC_SPIXF_MODE_3 = 3,
95 } mxc_spixf_mode_t;
96 
97 /**
98  * @brief      Select page size.
99  */
100 typedef enum {
101     MXC_SPIXF_4B = 0,
102     MXC_SPIXF_8B,
103     MXC_SPIXF_16B,
104     MXC_SPIXF_32B,
105 } mxc_spixf_page_size_t;
106 
107 /**
108  * @brief      Header units.
109  */
110 typedef enum {
111     MXC_SPIXF_HEADER_UNITS_BITS = 0,
112     MXC_SPIXF_HEADER_UNITS_BYTES,
113     MXC_SPIXF_HEADER_UNITS_PAGES,
114 } mxc_spixf_hdr_units_t;
115 
116 /**
117  * @brief      Number of data lines to use.
118  */
119 typedef enum {
120     MXC_SPIXF_WIDTH_1 = 0, ///< 1 Data Line.
121     MXC_SPIXF_WIDTH_2, ///< 2 Data Lines (x2).
122     MXC_SPIXF_WIDTH_4, ///< 4 Data Lines (x4).
123 } mxc_spixf_width_t;
124 
125 /**
126  * @brief      MXC_SPIXF configuration type.
127  */
128 typedef struct {
129     mxc_spixf_mode_t mode; ///< MXC_SPIXF mode to use, 0-3.
130     mxc_spixf_sspol_t
131         ssel_pol; ///< Mask of active levels for slave select signals, use mxc_spixf_ssel_t.
132     uint32_t hz; ///< SPI Frequency in Hz.
133 } mxc_spixf_cfg_t;
134 
135 /**
136  * @brief      Slave select active timing
137  */
138 typedef enum {
139     MXC_SPIXF_SYS_CLOCKS_0 = 0,
140     MXC_SPIXF_SYS_CLOCKS_2,
141     MXC_SPIXF_SYS_CLOCKS_4,
142     MXC_SPIXF_SYS_CLOCKS_8,
143 } mxc_spixf_ssact_t;
144 
145 /**
146  * @brief      Slave select Inactive timing
147  */
148 typedef enum {
149     MXC_SPIXF_SYS_CLOCKS_1 = 0, ///< 1 system clocks
150     MXC_SPIXF_SYS_CLOCKS_3, ///< 3 system clocks
151     MXC_SPIXF_SYS_CLOCKS_5, ///< 5 system clocks
152     MXC_SPIXF_SYS_CLOCKS_9, ///< 9 system clocks
153 } mxc_spixf_ssiact_t;
154 
155 /**
156  * @brief      Data Width, # of data I/O used to rcv data
157  */
158 typedef enum {
159     MXC_SPIXF_SINGLE_SDIO = 0,
160     MXC_SPIXF_DUAL_SDIO,
161     MXC_SPIXF_QUAD_SDIO,
162     MXC_SPIXF_INVALID,
163 } mxc_spixf_spiwidth_t;
164 
165 /**
166  * @brief      IO pullup/pulldown Control
167  */
168 typedef enum {
169     MXC_SPIXF_TRISTATE = MXC_S_SPIXFM_IOCTRL_PADCTRL_TRI_STATE,
170     MXC_SPIXF_PULL_UP = MXC_S_SPIXFM_IOCTRL_PADCTRL_PULL_UP,
171     MXC_SPIXF_PULL_DOWN = MXC_S_SPIXFM_IOCTRL_PADCTRL_PULL_DOWN,
172 } mxc_spixf_pup_t;
173 
174 /**
175  * @brief       SPIXF drive strentgh
176  *
177  */
178 typedef enum { MXC_SPIXF_LOW = 0, MXC_SPIXF_HIGH } mxc_spixf_ds_t;
179 
180 /**
181  * @brief      MXC_SPIXF Transaction request.
182  */
183 typedef struct mxc_spixf_req mxc_spixf_req_t;
184 
185 /**
186  * @brief   Callback for asynchronous request.
187  * @param   mxc_spixf_req_t*  Pointer to the transaction request.
188  * @param   int         Error code.
189  */
190 typedef void (*spixr_complete_cb_t)(mxc_spixf_req_t *, int);
191 
192 struct mxc_spixf_req {
193     uint8_t deass; ///< De-assert slave select at the end of the transaction.
194     uint8_t wait_tx; ///< Wait for the TX FIFO to be empty before returning.
195     const uint8_t *tx_data; ///< TX buffer.
196     uint8_t *rx_data; ///< RX buffer.
197     mxc_spixf_width_t width; ///< Number of data lines to use
198     unsigned len; ///< Number of bytes to send.
199     unsigned read_num; ///< Number of bytes read.
200     unsigned write_num; ///< Number of bytes written.
201     spixr_complete_cb_t callback; ///< callback function
202 };
203 
204 /***** Globals *****/
205 
206 /***** Function Prototypes *****/
207 /**
208  * @brief      Setup MXC_SPIXF for Execute in Place
209  *
210  * @param      cmdval       command for the external flash chip.
211  * @param      frequency    Frequency of transmission
212  *
213  * @return     None
214  */
215 int MXC_SPIXF_Init(uint32_t cmdval, uint32_t frequency);
216 
217 /**
218  * @brief      Shutdown MXC_SPIXF module.
219  */
220 void MXC_SPIXF_Shutdown(void);
221 
222 /**
223  * @brief      Setup Drive Strength on the I/O pins
224  *
225  * @param      sclk_ds   SCLK drive strength
226  * @param      ss_ds     Slave Select Drive Strength
227  * @param      sdio_ds   SDIO Drive Strength
228  * @param      pupdctrl  IO Pullup/Pulldown Control
229  */
230 void MXC_SPIXF_IOCtrl(mxc_spixf_ds_t sclk_ds, mxc_spixf_ds_t ss_ds, mxc_spixf_ds_t sdio_ds,
231                       mxc_spixf_pup_t pupdctrl);
232 
233 /**
234  * @brief      Send Clock cycles on SCK without reading or writing.
235  *
236  * @param      len    Number of clock cycles to send.
237  * @param      deass  De-assert slave select at the end of the transaction.
238  *
239  * @return     Cycles transacted if everything is successful, error if
240  *             unsuccessful.
241  */
242 int MXC_SPIXF_Clocks(uint32_t len, uint8_t deass);
243 
244 /**
245  * @brief      Read/write MXC_SPIXF data. Will block until transaction is
246  *             complete.
247  *
248  * @param      req   Request for a MXC_SPIXF transaction.
249  * @note       Callback is ignored.
250  *
251  * @return     Bytes transacted if everything is successful, error if
252  *             unsuccessful.
253  */
254 int MXC_SPIXF_Transaction(mxc_spixf_req_t *req);
255 
256 /**
257  * @brief      Asynchronously read/write MXC_SPIXF data.
258  *
259  * @param      req   Request for a MXC_SPIXF transaction.
260  * @note       Request structure must remain allocated until callback.
261  *
262  * @return     See \ref MXC_Error_Codes for the list of error return codes.
263  */
264 int MXC_SPIXF_TransactionAsync(mxc_spixf_req_t *req);
265 
266 /**
267  * @brief      Abort asynchronous request.
268  *
269  * @param      req   Pointer to request for a MXC_SPIXF transaction.
270  *
271  * @return     See \ref MXC_Error_Codes for the list of error return codes.
272  */
273 int MXC_SPIXF_AbortAsync(mxc_spixf_req_t *req);
274 
275 /**
276  * @brief      MXC_SPIXF interrupt handler.
277  * @details    This function should be called by the application from the
278  *             interrupt handler if MXC_SPIXF interrupts are enabled.
279  *             Alternately, this function can be periodically called by the
280  *             application if MXC_SPIXF interrupts are disabled.
281  */
282 void MXC_SPIXF_Handler(void);
283 
284 /**
285  * @brief      Attempt to prepare the MXC_SPIXF for sleep.
286  *
287  * @return     See \ref MXC_Error_Codes for the list of error return codes.
288  */
289 int MXC_SPIXF_ReadyForSleep(void);
290 
291 /**
292  * @brief      Enable Interrupts
293  *
294  * @param[in]  mask  The mask for the interrupts to enable
295  *
296  * @return     See \ref MXC_Error_Codes for the list of error return codes.
297  */
298 int MXC_SPIXF_EnableInt(uint32_t mask);
299 
300 /**
301  * @brief      Disable Interrupts
302  *
303  * @param[in]  mask  The mask for the interrupts to enable
304  *
305  * @return     See \ref MXC_Error_Codes for the list of error return codes.
306  */
307 int MXC_SPIXF_DisableInt(uint32_t mask);
308 
309 /**
310  * @brief      Clear Flags that have been set
311  *
312  * @param[in]  flags  The flags to be cleared
313  *
314  * @return     See \ref MXC_Error_Codes for the list of error return codes.
315  */
316 int MXC_SPIXF_ClearFlags(uint32_t flags);
317 
318 /**
319  * @brief      Get Flags of Interrupts of Flags that have been set.
320  *
321  * @return     the Flags that are set
322  */
323 int MXC_SPIXF_GetFlags(void);
324 
325 //Low level
326 
327 /**
328  * @brief      Sets the SPI Mode
329  *
330  * @param[in]  mode  The enum that corresponds to the SPI Mode
331  *
332  * @return     See \ref MXC_Error_Codes for the list of error return codes.
333  */
334 int MXC_SPIXF_SetMode(mxc_spixf_mode_t mode);
335 
336 /**
337  * @brief      Get which mode that spixf is currently set for
338  *
339  * @return     returns the enum for spi 0 or spi3
340  */
341 mxc_spixf_mode_t MXC_SPIXF_GetMode(void);
342 
343 /**
344  * @brief      Set the slave select polarity to high or low
345  *
346  * @return     See \ref MXC_Error_Codes for the list of error return codes.
347  */
348 int MXC_SPIXF_SetSSPolActiveHigh(void);
349 
350 /**
351  * @brief      Set the slave select polarity to high or low
352  *
353  * @return     See \ref MXC_Error_Codes for the list of error return codes.
354  */
355 int MXC_SPIXF_SetSSPolActiveLow(void);
356 
357 /**
358  * @brief      Get the current slave select polarity
359  *
360  * @return     Active High is (0), Active Low is (1)
361  */
362 int MXC_SPIXF_GetSSPolarity(void);
363 
364 /**
365  * @brief      Sets both the read and write SPI clock frequency to the given value.
366  *
367  * @param[in]  hz   The frequency the spi will communicating at.
368  *
369  * @return     See \ref MXC_Error_Codes for the list of error return codes.
370  */
371 int MXC_SPIXF_SetSPIFrequency(unsigned int hz);
372 
373 /**
374  * @brief      Sets the SPI clock frequency for read operations.
375  *
376  * @param[in]  hz   The frequency the spi will communicating at.
377  *
378  * @return     See \ref MXC_Error_Codes for the list of error return codes.
379  */
380 int MXC_SPIXF_SetSPIFrequencyRead(unsigned int hz);
381 
382 /**
383  * @brief      Sets the SPI clock frequency for write operations.
384  *
385  * @param[in]  hz   The frequency the spi will communicating at.
386  *
387  * @return     See \ref MXC_Error_Codes for the list of error return codes.
388  */
389 int MXC_SPIXF_SetSPIFrequencyWrite(unsigned int hz);
390 
391 /**
392  * @brief      Get the current SPI clock frequency.  If the read and write clock
393  *             frequencies have been set to different values, this function will
394  *             return the read frequency.
395  *
396  * @return     The current frequency that the SPI is communicating at.
397  */
398 uint32_t MXC_SPIXF_GetSPIFrequency(void);
399 
400 /**
401  * @brief      Get the current SPI clock frequency for read operations.
402  *
403  * @return     The current frequency that the SPI is communicating at.
404  */
405 uint32_t MXC_SPIXF_GetSPIFrequencyRead(void);
406 
407 /**
408  * @brief      Get the current SPI clock frequency for write operations.
409  *
410  * @return     The current frequency that the SPI is communicating at.
411  */
412 uint32_t MXC_SPIXF_GetSPIFrequencyWrite(void);
413 
414 /**
415  * @brief      Set the slave select active timing. This will control the delay from assertion of slave select to start
416  *             of the SCK pulse and delay from the end of SCK pulse to de-assertion of slave select.
417  *
418  * @param[in]  ssact  The enum that corresponds with 0,2,4,8 clocks of delay
419  *
420  * @return     See \ref MXC_Error_Codes for the list of error return codes.
421  *
422  */
423 int MXC_SPIXF_SetSSActiveTime(mxc_spixf_ssact_t ssact);
424 
425 /**
426  * @brief      Get the slave select active timing setting.
427  *
428  * @return     gives the enum value that corresponds to 0,2,4,8 clocks of delay
429  *             that ss is currently set at.
430  */
431 mxc_spixf_ssact_t MXC_SPIXF_GetSSActiveTime(void);
432 
433 /**
434  * @brief      Set slave select inactive timing to delay from de-assertion of
435  *             slave select to re-assertion of slave select for another spi
436  *             transaction.
437  *
438  * @param[in]  ssiact  The enum that corresponds to a 1,3,5,9 clock delay
439  *
440  * @return     See \ref MXC_Error_Codes for the list of error return codes.
441  */
442 int MXC_SPIXF_SetSSInactiveTime(mxc_spixf_ssiact_t ssiact);
443 
444 /**
445  * @brief      Get slave select inactive timing to delay from de-assertion of slave select to re-assertion of
446  *             slave select for another spi transaction.
447  *
448  * @return     The enum that corresponds to a 1,3,5,9 clock delay
449  */
450 mxc_spixf_ssiact_t MXC_SPIXF_GetSSInactiveTime(void);
451 
452 /**
453  * @brief      Set Number of data I/O used to send commands
454  *
455  * @param[in]  width  Enum that corresponds to single, dual, quad SDIO.
456  *
457  * @return     See \ref MXC_Error_Codes for the list of error return codes.
458  */
459 int MXC_SPIXF_SetCmdWidth(mxc_spixf_spiwidth_t width);
460 
461 /**
462  * @brief      Get number of data I/O expected to be used for commands
463  *
464  * @return     Enum that corresponds to single, dual, quad SDIO
465  */
466 mxc_spixf_spiwidth_t MXC_SPIXF_GetCmdWidth(void);
467 
468 /**
469  * @brief      Set Number of data I/O used to send address
470  *
471  * @param[in]  width  Enum that corresponds to single, dual, quad SDIO.
472  *
473  * @return     See \ref MXC_Error_Codes for the list of error return codes.
474  */
475 int MXC_SPIXF_SetAddrWidth(mxc_spixf_spiwidth_t width);
476 
477 /**
478  * @brief      Get number of data I/O expected to be used for address
479  *
480  * @return     Enum that corresponds to single, dual, quad SDIO
481  */
482 mxc_spixf_spiwidth_t MXC_SPIXF_GetAddrWidth(void);
483 
484 /**
485  * @brief      Set Number of data I/O used to send data
486  *
487  * @param[in]  width  Enum that corresponds to single, dual, quad SDIO.
488  *
489  * @return     See \ref MXC_Error_Codes for the list of error return codes.
490  */
491 int MXC_SPIXF_SetDataWidth(mxc_spixf_spiwidth_t width);
492 
493 /**
494  * @brief      Get number of data I/O expected to be used for data
495  *
496  * @return     Enum that corresponds to single, dual, quad SDIO
497  */
498 mxc_spixf_spiwidth_t MXC_SPIXF_GetDataWidth(void);
499 
500 /**
501  * @brief      Set address mode to be 4 byte address
502  *
503  * @return     See \ref MXC_Error_Codes for the list of error return codes.
504  */
505 int MXC_SPIXF_Set4ByteAddr(void);
506 
507 /**
508  * @brief      Set address mode to be 3 byte address
509  *
510  * @return     See \ref MXC_Error_Codes for the list of error return codes.
511  */
512 int MXC_SPIXF_Set3ByteAddr(void);
513 
514 /**
515  * @brief      Get number of bytes in address
516  *
517  * @return     3-byte address (3) or 4-byte address (4)
518  */
519 unsigned int MXC_SPIXF_GetBytesPerAddr(void);
520 
521 /**
522  * @brief      Set number of SPI clocks needed during the mode/dummy phase of
523  *             fetch
524  *
525  * @param[in]  mdclk  The number of clocks from 0-15
526  *
527  * @return     See \ref MXC_Error_Codes for the list of error return codes.
528  */
529 int MXC_SPIXF_SetModeClk(uint8_t mdclk);
530 
531 /**
532  * @brief      Get number of SPI clocks being used for the mode/dummy phase of
533  *             fetch
534  *
535  * @return     the number of clocks mode clock is set at.
536  */
537 uint8_t MXC_SPIXF_GetModeClk(void);
538 
539 /**
540  * @brief      Set command value for spi transaction
541  *
542  * @param[in]  cmdval
543  *
544  * @return     See \ref MXC_Error_Codes for the list of error return codes.
545  */
546 int MXC_SPIXF_SetCmdValue(uint8_t cmdval);
547 
548 /**
549  * @brief      Set command mode to send read a command every time a spi
550  *             transaction is initiated
551  *
552  * @return     See \ref MXC_Error_Codes for the list of error return codes.
553  */
554 int MXC_SPIXF_SetCmdModeEveryTrans(void);
555 
556 /**
557  * @brief      Set command mode to send a read a command the first transaction.
558  */
559 int MXC_SPIXF_SetCmdModeFirstTrans(void);
560 
561 /**
562  * @brief      Get Command mode
563  *
564  * @return     When the read command is sent.  It will be either every time (0) or First transaction only (1).
565  */
566 mxc_spixf_cmd_t MXC_SPIXF_GetCmdMode(void);
567 
568 /**
569  * @brief      Enable bits to be in bit bang output mode
570  *
571  * @param[in]  mask  Enable output bit bang on specific bits so bit 3 set will
572  *                   enable bit 3
573  *
574  * @return     See \ref MXC_Error_Codes for the list of error return codes.
575  */
576 int MXC_SPIXF_BBDataOutputEnable(uint8_t mask);
577 
578 /**
579  * @brief      Disable bits to not be in bit bang output mode
580  *
581  * @param[in]  mask  Disable output bit bang on specific bits so bit 3 set will
582  *                   disable bit 3
583  *
584  * @return     See \ref MXC_Error_Codes for the list of error return codes.
585  */
586 int MXC_SPIXF_BBDataOutputDisable(uint8_t mask);
587 
588 /**
589  * @brief      Get if bit bang output mode is enabled or disabled for all bits
590  *
591  * @return     Returns if Output bit bang is enabled (1) or disabled (0) in bits
592  *             0:3 corresponding with sdio0:sdio3
593  */
594 uint8_t MXC_SPIXF_BBDataOutputIsEnabled(void);
595 
596 /**
597  * @brief      Get Output data value
598  *
599  * @return     Returns output data value of a 1 or 0 in bits 0:3 corresponding with sdio0:sdio3
600  */
601 uint8_t MXC_SPIXF_GetBBDataOutputValue(void);
602 
603 /**
604  * @brief      Get Input data value
605  *
606  * @return     Returns input data value of a 1 or 0 in bits 0:3 corresponding with sdio0:sdio3
607  */
608 uint8_t MXC_SPIXF_GetBBDataInputValue(void);
609 
610 /**
611  * @brief      Set the data to send with the dummy clocks
612  *
613  * @param[in]  data  The data to send
614  *
615  * @return     See \ref MXC_Error_Codes for the list of error return codes.
616  */
617 int MXC_SPIXF_SetModeData(uint16_t data);
618 
619 /**
620  * @brief      Get the data that is supposed to send with the dummy clocks
621  *
622  * @return     the data being sent with dummy clocks
623  */
624 uint16_t MXC_SPIXF_GetModeData(void);
625 
626 /**
627  * @brief      Set SCK to be inverted
628  *
629  * @return     See \ref MXC_Error_Codes for the list of error return codes.
630  */
631 int MXC_SPIXF_SetSCKInverted(void);
632 
633 /**
634  * @brief      Set SCK to be non-inverted
635  *
636  * @return     See \ref MXC_Error_Codes for the list of error return codes.
637  */
638 int MXC_SPIXF_SetSCKNonInverted(void);
639 
640 /**
641  * @brief      Get weather SCK is inverted or non-inverted
642  *
643  * @return     Enum that corresponds to Inverted (1) or non-inverted (0)
644  */
645 int MXC_SPIXF_GetSCKInverted(void);
646 
647 /**
648  * @brief      Enable SCK Feedback
649  *
650  * @return     See \ref MXC_Error_Codes for the list of error return codes.
651  */
652 int MXC_SPIXF_SCKFeedbackEnable(void);
653 
654 /**
655  * @brief      Disable SCK Feedback
656  *
657  * @return     See \ref MXC_Error_Codes for the list of error return codes.
658  */
659 int MXC_SPIXF_SCKFeebackDisable(void);
660 
661 /**
662  * @brief      Get if SCK Feedback is enabled or disabled
663  *
664  * @return     Returns if feedback mode is Enabled (1) or disabled (0).
665  */
666 int MXC_SPIXF_SCKFeebackIsEnabled(void);
667 
668 /**
669  * @brief      Set SPI clock periods to delay before sampling SDIO input.  This
670  *             value must be less than or equal to HICLK
671  *
672  * @param[in]  delay  The number of clocks to delay between 0-15
673  *
674  * @return     See \ref MXC_Error_Codes for the list of error return codes.
675  */
676 int MXC_SPIXF_SetSCKSampleDelay(uint8_t delay);
677 
678 /**
679  * @brief      Get the Number of clocks being delayed before sampling SDIO
680  *
681  * @return     get number of clocks between 0-15.
682  */
683 uint8_t MXC_SPIXF_GetSCKSampleDelay(void);
684 
685 /**
686  * @brief      Set Page Size for transactions
687  *
688  * @param[in]  size  The size of a transaction in bytes
689  *
690  */
691 void MXC_SPIXF_SetPageSize(mxc_spixf_page_size_t size);
692 
693 /**
694  * @brief      Get the current page size for a transaction
695  *
696  * @return     The enum that corresponds with the current page size.
697  */
698 mxc_spixf_page_size_t MXC_SPIXF_GetPageSize(void);
699 
700 /**
701  * @brief      Set to Receive only in simple mode
702  *
703  * @return     See \ref MXC_Error_Codes for the list of error return codes.
704  */
705 int MXC_SPIXF_SimpleRXEnabled(void);
706 
707 /**
708  * @brief      Set to Receive only in simple mode
709  *
710  * @return     See \ref MXC_Error_Codes for the list of error return codes.
711  */
712 int MXC_SPIXF_SimpleRXDisable(void);
713 
714 /**
715  * @brief      Get Receive only mode setting
716  *
717  * @return     Returns if simple receive is enabled or disabled
718  */
719 int MXC_SPIXF_SimpleRXIsEnabled(void);
720 
721 /**
722  * @brief      Enable Simple Mode
723  *
724  * @return     See \ref MXC_Error_Codes for the list of error return codes.
725  */
726 int MXC_SPIXF_SimpleModeEnable(void);
727 
728 /**
729  * @brief      Disable Simple Mode
730  *
731  * @return     See \ref MXC_Error_Codes for the list of error return codes.
732  */
733 int MXC_SPIXF_SimpleModeDisable(void);
734 
735 /**
736  * @brief      Get if Simple mode is enabled or disabled
737  *
738  * @return     Returns if simple mode is enabled or disabled
739  */
740 int MXC_SPIXF_SimpleModeIsEnabled(void);
741 
742 /**
743  * @brief      Enable bit bang sample output mode on spefic bits
744  *
745  * @param[in]  mask  Enable sample output bit bang mode. so bit 3 set will
746  *                   enable bit 3
747  *
748  * @return     See \ref MXC_Error_Codes for the list of error return codes.
749  */
750 int MXC_SPIXF_SampleOutputEnable(uint8_t mask);
751 
752 /**
753  * @brief      Disable bit bang sample output mode on spefic bits
754  *
755  * @param[in]  mask  Disable sample output bit bang mode. so bit 3 set will
756  *                   disable bit 3
757  *
758  * @return     See \ref MXC_Error_Codes for the list of error return codes.
759  */
760 int MXC_SPIXF_SampleOutputDisable(uint8_t mask);
761 
762 /**
763  * @brief      Get if sample output bit bang is enabled or disabled
764  *
765  * @return     Returns sample output bit bang mode if a 1 (enabled) or 0
766  *             (disabled) in bits 0:3 corresponding with sdio0:sdio3
767  */
768 uint8_t MXC_SPIXF_SampleOutputIsEnabled(void);
769 
770 /**
771  * @brief      Get bit bang sample output value
772  *
773  * @return     Returns sample output bit bang value of a 1 or 0 in bits 0:3
774  *             corresponding with sdio0:sdio3
775  */
776 uint8_t MXC_SPIXF_GetSampleOutputValue(void);
777 
778 /**
779  * @brief      Drive SCK High
780  *
781  * @return     See \ref MXC_Error_Codes for the list of error return codes.
782  */
783 void MXC_SPIXF_SetSCKDriveHigh(void);
784 
785 /**
786  * @brief      Drive SCK Low
787  *
788  * @return     See \ref MXC_Error_Codes for the list of error return codes.
789  */
790 void MXC_SPIXF_SetSCKDriveLow(void);
791 
792 /**
793  * @brief      Get if SCK is high or low
794  *
795  * @return     returns 1 if High, 0 if  Low
796  */
797 uint8_t MXC_SPIXF_GetSCKDrive(void);
798 
799 /**
800  * @brief      Set Slave select in bit bang mode to a 1
801  */
802 void MXC_SPIXF_SetSSDriveOutputHigh(void);
803 
804 /**
805  * @brief      Set Slave select in bit bang mode to a 0
806  */
807 void MXC_SPIXF_SetSSDriveOutputLow(void);
808 
809 /**
810  * @brief      Get current slave select output
811  *
812  * @return     0 or 1 based on output of line.
813  */
814 uint8_t MXC_SPIXF_GetSSDriveOutput(void);
815 
816 /**
817  * @brief      Enable bit bang mode
818  *
819  * @return     See \ref MXC_Error_Codes for the list of error return codes.
820  */
821 int MXC_SPIXF_BitBangModeEnable(void);
822 
823 /**
824  * @brief      Disable bit bang mode
825  *
826  * @return     See \ref MXC_Error_Codes for the list of error return codes.
827  */
828 int MXC_SPIXF_BitBangModeDisable(void);
829 
830 /**
831  * @brief      Is Bit bang mode enabled or disabled
832  *
833  * @return     Bit bang mode is enabled (1) or disabled (0)
834  */
835 int MXC_SPIXF_BitBangModeIsEnabled(void);
836 
837 /**
838  * @brief      RX FIFO (results fifo) enable
839  *
840  * @return     See \ref MXC_Error_Codes for the list of error return codes.
841  */
842 int MXC_SPIXF_RXFIFOEnable(void);
843 
844 /**
845  * @brief      RX FIFO (results fifo) disable
846  *
847  * @return     See \ref MXC_Error_Codes for the list of error return codes.
848  */
849 int MXC_SPIXF_RXFIFODisable(void);
850 
851 /**
852  * @brief      Is RX FIFO (results fifo) enabled or disabled
853  *
854  * @return     RX FIFO is enabled (1) or disabled (0)
855  */
856 int MXC_SPIXF_RXFIFOIsEnabled(void);
857 
858 /**
859  * @brief      TX FIFO (Transaction FIFO) enable
860  *
861  * @return     See \ref MXC_Error_Codes for the list of error return codes.
862  */
863 int MXC_SPIXF_TXFIFOEnable(void);
864 
865 /**
866  * @brief      TX FIFO (Transaction FIFO) disable
867  *
868  * @return     See \ref MXC_Error_Codes for the list of error return codes.
869  */
870 int MXC_SPIXF_TXFIFODisable(void);
871 
872 /**
873  * @brief      Is TX FIFO (Transaction FIFO) Enabled or Disabled
874  *
875  * @return     TX FIFO is enabled (1) or disabled (0)
876  */
877 int MXC_SPIXF_TXFIFOIsEnabled(void);
878 
879 /**
880  * @brief      Enables SPIXF but doesnt change any configurations
881  *
882  * @return     See \ref MXC_Error_Codes for the list of error return codes.
883  */
884 int MXC_SPIXF_Enable(void);
885 
886 /**
887  * @brief      Disables SPIXF but doesnt change any configurations
888  *
889  * @return     See \ref MXC_Error_Codes for the list of error return codes.
890  */
891 int MXC_SPIXF_Disable(void);
892 
893 /**
894  * @brief      Is SPIXF Enabled or Disabled
895  *
896  * @return     SPIXF is enabled (1) or disabled (0)
897  */
898 int MXC_SPIXF_IsEnabled(void);
899 
900 /**
901  * @brief      Set IOCTRL SDIO Drive to High
902  */
903 void MXC_SPIXF_SetIoctrlSDIODriveHigh(void);
904 
905 /**
906  * @brief      Set IOCTRL SDIO Drive to Low
907  */
908 void MXC_SPIXF_SetIoctrlSDIODriveLow(void);
909 
910 /**
911  * @brief      Get IOCTRL SDIO Drive
912  *
913  * @return     1 = high or 0 = low
914  */
915 uint8_t MXC_SPIXF_GetIoctrlSDIODrive(void);
916 
917 /**
918  * @brief      Set IOCTRL SCLK Drive to High
919  */
920 void MXC_SPIXF_SetIoctrlSCLKDriveHigh(void);
921 
922 /**
923  * @brief      Set IOCTRL SCLK Drive to Low
924  */
925 void MXC_SPIXF_SetIoctrlSCLKDriveLow(void);
926 
927 /**
928  * @brief      Get IOCTRL SCLK Drive
929  *
930  * @return     1= high or 0 = low
931  */
932 uint8_t MXC_SPIXF_GetIoctrlSCLKDrive(void);
933 
934 /**
935  * @brief      Set IOCTRL SS Drive to High
936  */
937 void MXC_SPIXF_SetIoctrlSSDriveHigh(void);
938 
939 /**
940  * @brief      Set IOCTRL SS Drive to Low
941  */
942 void MXC_SPIXF_SetIoctrlSSDriveLow(void);
943 
944 /**
945  * @brief      Get IOCTRL SS Drive
946  *
947  * @return     1 = high or 0 = low
948  */
949 uint8_t MXC_SPIXF_GetIoctrlSSDrive(void);
950 
951 /**
952  * @brief      Set pull up pull down
953  *
954  * @param[in]  pupd  The enum corresponding to Pull up pull down states
955  */
956 void MXC_SPIXF_SetPuPdCtrl(mxc_spixf_pup_t pupd);
957 
958 /**
959  * @brief      Get what setting the pull up pull down is set to
960  *
961  * @return     the enum value for pull up pull down state
962  */
963 uint8_t MXC_SPIXF_GetPuPdCtrl(void);
964 
965 /**
966  * @brief      Set bus idle to a time where ss will be deactivated if timer runs out
967  *
968  * @param[in]  busidle  The time before the timer runs out
969  *
970  * @return     See \ref MXC_Error_Codes for the list of error return codes.
971  */
972 int MXC_SPIXF_SetBusIdle(unsigned int busidle);
973 
974 /**
975  * @brief      Get Bus Idle time
976  *
977  * @return     the time the bus will idle before deactivating slave select.
978  */
979 unsigned int MXC_SPIXF_GetBusIdle(void);
980 
981 /**
982  * @defgroup spixfm SPI External Flash Master (SPIXFM)
983  * @ingroup spixf
984  * @{
985  */
986 /**@} end of group spixfm */
987 
988 /**
989  * @defgroup spixfc SPI External Flash Controller (SPIXFC)
990  * @ingroup spixf
991  * @{
992  */
993 /**@} end of group spixfc */
994 /**
995  * @defgroup spixfc_fifo SPI External Flash Controller FIFO (SPIXFC_FIFO)
996  * @ingroup spixf
997  * @{
998  */
999 /**@} end of group spixfc_fifo */
1000 
1001 /**@} end of group spixf */
1002 
1003 #ifdef __cplusplus
1004 }
1005 #endif
1006 
1007 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_SPIXF_H_
1008