ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fsl_spi_hal.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: fsl_spi_hal.h
4 *
5 * Copyright (c) 2014, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file fsl_spi_hal.h
10 * @brief \b fsl_spi_hal.h defines structures and types for the spi master HAL layer.
11 */
12 #ifndef FSL_SPI_HAL_H_
13 #define FSL_SPI_HAL_H_
14 #include "isf_types.h"
15 #include <stdbool.h>
16 //#include "fsl_spi_features.h"
17 //#include "fsl_device_registers.h"
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include <assert.h>
21 
22 /*! @addtogroup spi_hal*/
23 /*! @{*/
24 
25 /*! @file*/
26 
27 /*******************************************************************************
28  * Definitions
29  ******************************************************************************/
30 
31 /*! @brief Error codes for the SPI driver.*/
32 typedef enum _spi_errors
33 {
35  kStatus_SPI_SlaveTxUnderrun, /*!< SPI Slave TX Underrun error.*/
36  kStatus_SPI_SlaveRxOverrun, /*!< SPI Slave RX Overrun error.*/
37  kStatus_SPI_Timeout, /*!< SPI tranfser timed out.*/
38  kStatus_SPI_Busy, /*!< SPI instance is already busy performing a transfer.*/
39  kStatus_SPI_NoTransferInProgress, /*!< Attempt to abort a transfer when no transfer was in progress.*/
40  kStatus_SPI_Error, /*!< SPI Error.*/
41 } spi_status_t;
42 
43 /*! @brief SPI master or slave configuration.*/
44 typedef enum _spi_master_slave_mode {
45  kSpiMaster = 1, /*!< SPI peripheral operates in master mode.*/
46  kSpiSlave = 0 /*!< SPI peripheral operates in slave mode.*/
48 
49 /*! @brief SPI clock polarity configuration.*/
50 typedef enum _spi_clock_polarity {
51  kSpiClockPolarity_ActiveHigh = 0, /*!< Active-high SPI clock (idles low).*/
52  kSpiClockPolarity_ActiveLow = 1 /*!< Active-low SPI clock (idles high).*/
54 
55 /*! @brief SPI clock phase configuration.*/
56 typedef enum _spi_clock_phase {
57  kSpiClockPhase_FirstEdge = 0, /*!< First edge on SPSCK occurs at the middle of the first cycle of a data transfer.*/
58  kSpiClockPhase_SecondEdge = 1 /*!< First edge on SPSCK occurs at the start of the first cycle of a data transfer.*/
60 
61 /*! @brief SPI data shifter direction options.*/
62 typedef enum _spi_shift_direction {
63  kSpiMsbFirst = 0, /*!< Data transfers start with most significant bit.*/
64  kSpiLsbFirst = 1 /*!< Data transfers start with least significant bit.*/
66 
67 /*! @brief SPI slave select output mode options.*/
68 typedef enum _spi_ss_output_mode {
69  kSpiSlaveSelect_AsGpio = 0, /*!< Slave select pin configured as GPIO.*/
70  kSpiSlaveSelect_FaultInput = 2, /*!< Slave select pin configured for fault detection.*/
71  kSpiSlaveSelect_AutomaticOutput = 3 /*!< Slave select pin configured for automatic SPI output.*/
73 
74 /*! @brief SPI pin mode options.*/
75 typedef enum _spi_pin_mode {
76  kSpiPinMode_Normal = 0, /*!< Pins operate in normal, single-direction mode.*/
77  kSpiPinMode_Input = 1, /*!< Bidirectional mode. Master: MOSI pin is input; Slave: MISO pin is input*/
78  kSpiPinMode_Output = 3 /*!< Bidirectional mode. Master: MOSI pin is output; Slave: MISO pin is output*/
80 
81 /*! @brief SPI hardware configuration settings.*/
82 /*!*/
83 /*! Use an instance of this struct with spi_hal_init(). This allows you to configure the*/
84 /*! most common settings of the SPI peripheral with a single function call.*/
85 /*!*/
86 /*! The @c kbitsPerSec member is handled specially. If this value is set to 0, then the baud is*/
87 /*! not set by spi_hal_init(), and must be set with a separate call to either spi_hal_set_baud()*/
88 /*! or spi_hal_set_baud_divisors(). This can be useful if you know the divisors in advance and*/
89 /*! don't want to spend the time to compute them for the provided rate in kilobits/sec.*/
90 typedef struct SpiConfig {
91  uint32_t kbitsPerSec; /*!< @brief Baud rate in kilobits per second.*/
92  spi_master_slave_mode_t masterOrSlave; /*!< Whether to put the peripheral in master or slave mode.*/
93  spi_clock_polarity_t polarity; /*!< Clock polarity setting.*/
94  spi_clock_phase_t phase; /*!< Clock phase setting.*/
95  spi_shift_direction_t shiftDirection; /*!< Direction in which data is shifted out.*/
96  spi_ss_output_mode_t ssOutputMode; /*!< Output mode for the slave select signal.*/
97  spi_pin_mode_t pinMode; /*!< Pin mode with bidirectional option.*/
98 
99 } spi_config_t;
100 
101 /*! @}*/
102 
103 
104 #endif /* FSL_SPI_HAL_H_ */
105 
106 
enum _spi_errors spi_status_t
Error codes for the SPI driver.
_spi_master_slave_mode
SPI master or slave configuration.
Definition: fsl_spi_hal.h:44
spi_pin_mode_t pinMode
Definition: fsl_spi_hal.h:97
enum _spi_pin_mode spi_pin_mode_t
SPI pin mode options.
enum _spi_shift_direction spi_shift_direction_t
SPI data shifter direction options.
spi_clock_polarity_t polarity
Definition: fsl_spi_hal.h:93
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
struct SpiConfig spi_config_t
SPI hardware configuration settings.
_spi_shift_direction
SPI data shifter direction options.
Definition: fsl_spi_hal.h:62
enum _spi_master_slave_mode spi_master_slave_mode_t
SPI master or slave configuration.
_spi_pin_mode
SPI pin mode options.
Definition: fsl_spi_hal.h:75
_spi_ss_output_mode
SPI slave select output mode options.
Definition: fsl_spi_hal.h:68
_spi_clock_phase
SPI clock phase configuration.
Definition: fsl_spi_hal.h:56
SPI hardware configuration settings.
Definition: fsl_spi_hal.h:90
enum _spi_clock_phase spi_clock_phase_t
SPI clock phase configuration.
enum _spi_clock_polarity spi_clock_polarity_t
SPI clock polarity configuration.
_spi_errors
Error codes for the SPI driver.
Definition: fsl_spi_hal.h:32
enum _spi_ss_output_mode spi_ss_output_mode_t
SPI slave select output mode options.
spi_clock_phase_t phase
Definition: fsl_spi_hal.h:94
spi_shift_direction_t shiftDirection
Definition: fsl_spi_hal.h:95
uint32_t kbitsPerSec
Baud rate in kilobits per second.
Definition: fsl_spi_hal.h:91
spi_master_slave_mode_t masterOrSlave
Definition: fsl_spi_hal.h:92
_spi_clock_polarity
SPI clock polarity configuration.
Definition: fsl_spi_hal.h:50
spi_ss_output_mode_t ssOutputMode
Definition: fsl_spi_hal.h:96