2 * @brief LPC18xx/43xx SSP driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __SSP_18XX_43XX_H_
\r
33 #define __SSP_18XX_43XX_H_
\r
39 /** @defgroup SSP_18XX_43XX CHIP: LPC18xx/43xx SSP driver
\r
40 * @ingroup CHIP_18XX_43XX_Drivers
\r
45 * @brief SSP clock format
\r
47 typedef enum CHIP_SSP_CLOCK_FORMAT {
\r
48 SSP_CLOCK_CPHA0_CPOL0 = (0 << 6), /**< CPHA = 0, CPOL = 0 */
\r
49 SSP_CLOCK_CPHA0_CPOL1 = (1u << 6), /**< CPHA = 0, CPOL = 1 */
\r
50 SSP_CLOCK_CPHA1_CPOL0 = (2u << 6), /**< CPHA = 1, CPOL = 0 */
\r
51 SSP_CLOCK_CPHA1_CPOL1 = (3u << 6), /**< CPHA = 1, CPOL = 1 */
\r
52 SSP_CLOCK_MODE0 = SSP_CLOCK_CPHA0_CPOL0,/**< alias */
\r
53 SSP_CLOCK_MODE1 = SSP_CLOCK_CPHA1_CPOL0,/**< alias */
\r
54 SSP_CLOCK_MODE2 = SSP_CLOCK_CPHA0_CPOL1,/**< alias */
\r
55 SSP_CLOCK_MODE3 = SSP_CLOCK_CPHA1_CPOL1,/**< alias */
\r
56 } CHIP_SSP_CLOCK_MODE_T;
\r
59 * @brief SSP frame format
\r
61 typedef enum CHIP_SSP_FRAME_FORMAT {
\r
62 SSP_FRAMEFORMAT_SPI = (0 << 4), /**< Frame format: SPI */
\r
63 CHIP_SSP_FRAME_FORMAT_TI = (1u << 4), /**< Frame format: TI SSI */
\r
64 SSP_FRAMEFORMAT_MICROWIRE = (2u << 4), /**< Frame format: Microwire */
\r
65 } CHIP_SSP_FRAME_FORMAT_T;
\r
68 * @brief Number of bits per frame
\r
70 typedef enum CHIP_SSP_BITS {
\r
71 SSP_BITS_4 = (3u << 0), /**< 4 bits/frame */
\r
72 SSP_BITS_5 = (4u << 0), /**< 5 bits/frame */
\r
73 SSP_BITS_6 = (5u << 0), /**< 6 bits/frame */
\r
74 SSP_BITS_7 = (6u << 0), /**< 7 bits/frame */
\r
75 SSP_BITS_8 = (7u << 0), /**< 8 bits/frame */
\r
76 SSP_BITS_9 = (8u << 0), /**< 9 bits/frame */
\r
77 SSP_BITS_10 = (9u << 0), /**< 10 bits/frame */
\r
78 SSP_BITS_11 = (10u << 0), /**< 11 bits/frame */
\r
79 SSP_BITS_12 = (11u << 0), /**< 12 bits/frame */
\r
80 SSP_BITS_13 = (12u << 0), /**< 13 bits/frame */
\r
81 SSP_BITS_14 = (13u << 0), /**< 14 bits/frame */
\r
82 SSP_BITS_15 = (14u << 0), /**< 15 bits/frame */
\r
83 SSP_BITS_16 = (15u << 0), /**< 16 bits/frame */
\r
87 * @brief SSP config format
\r
89 typedef struct SSP_ConfigFormat {
\r
90 CHIP_SSP_BITS_T bits; /**< Format config: bits/frame */
\r
91 CHIP_SSP_CLOCK_MODE_T clockMode;/**< Format config: clock phase/polarity */
\r
92 CHIP_SSP_FRAME_FORMAT_T frameFormat;/**< Format config: SPI/TI/Microwire */
\r
98 typedef enum CHIP_SSP_MODE {
\r
99 SSP_MODE_MASTER = (0 << 2), /**< Master mode */
\r
100 SSP_MODE_SLAVE = (1u << 2), /**< Slave mode */
\r
104 * @brief SPI address
\r
112 * @brief SSP data setup structure
\r
115 void *tx_data; /**< Pointer to transmit data */
\r
116 uint32_t tx_cnt; /**< Transmit counter */
\r
117 void *rx_data; /**< Pointer to transmit data */
\r
118 uint32_t rx_cnt; /**< Receive counter */
\r
119 uint32_t length; /**< Length of transfer data */
\r
120 } Chip_SSP_DATA_SETUP_T;
\r
122 /** SSP configuration parameter defines */
\r
123 /** Clock phase control bit */
\r
124 #define SSP_CPHA_FIRST SSP_CR0_CPHA_FIRST
\r
125 #define SSP_CPHA_SECOND SSP_CR0_CPHA_SECOND
\r
127 /** Clock polarity control bit */
\r
128 /* There's no bug here!!!
\r
129 * - If bit[6] in SSPnCR0 is 0: SSP controller maintains the bus clock low between frames.
\r
130 * That means the active clock is in HI state.
\r
131 * - If bit[6] in SSPnCR0 is 1 (SSP_CR0_CPOL_HI): SSP controller maintains the bus clock
\r
132 * high between frames. That means the active clock is in LO state.
\r
134 #define SSP_CPOL_HI SSP_CR0_CPOL_LO
\r
135 #define SSP_CPOL_LO SSP_CR0_CPOL_HI
\r
137 /** SSP master mode enable */
\r
138 #define SSP_SLAVE_MODE SSP_CR1_SLAVE_EN
\r
139 #define SSP_MASTER_MODE SSP_CR1_MASTER_EN
\r
142 * @brief Get the current status of SSP controller
\r
143 * @param pSSP : The base of SSP peripheral on the chip
\r
144 * @param Stat : Type of status, should be :
\r
150 * @return SSP controller status, SET or RESET
\r
152 STATIC INLINE FlagStatus Chip_SSP_GetStatus(LPC_SSP_T *pSSP, IP_SSP_STATUS_T Stat)
\r
154 return IP_SSP_GetStatus(pSSP, Stat);
\r
158 * @brief Enable SSP operation
\r
159 * @param pSSP : The base of SSP peripheral on the chip
\r
162 STATIC INLINE void Chip_SSP_Enable(LPC_SSP_T *pSSP)
\r
164 IP_SSP_Enable(pSSP);
\r
168 * @brief Disable SSP operation
\r
169 * @param pSSP : The base of SSP peripheral on the chip
\r
172 STATIC INLINE void Chip_SSP_Disable(LPC_SSP_T *pSSP)
\r
174 IP_SSP_Disable(pSSP);
\r
178 * @brief Enable SSP DMA
\r
179 * @param pSSP : The base of SSP peripheral on the chip
\r
182 STATIC INLINE void Chip_SSP_DMA_Enable(LPC_SSP_T *pSSP)
\r
184 IP_SSP_DMA_Enable(pSSP, SSP_DMA_BITMASK);
\r
188 * @brief Disable SSP DMA
\r
189 * @param pSSP : The base of SSP peripheral on the chip
\r
192 STATIC INLINE void Chip_SSP_DMA_Disable(LPC_SSP_T *pSSP)
\r
194 IP_SSP_DMA_Disable(pSSP, SSP_DMA_BITMASK);
\r
198 * @brief Enable loopback mode
\r
199 * @param pSSP : The base of SSP peripheral on the chip
\r
201 * @note Serial input is taken from the serial output (MOSI or MISO) rather
\r
202 * than the serial input pin
\r
204 STATIC INLINE void Chip_SSP_EnableLoopBack(LPC_SSP_T *pSSP)
\r
206 IP_SSP_EnableLoopBack(pSSP);
\r
210 * @brief Disable loopback mode
\r
211 * @param pSSP : The base of SSP peripheral on the chip
\r
213 * @note Serial input is taken from the serial output (MOSI or MISO) rather
\r
214 * than the serial input pin
\r
216 STATIC INLINE void Chip_SSP_DisableLoopBack(LPC_SSP_T *pSSP)
\r
218 IP_SSP_DisableLoopBack(pSSP);
\r
222 * @brief Clean all data in RX FIFO of SSP
\r
223 * @param pSSP : The base SSP peripheral on the chip
\r
226 void Chip_SSP_Int_FlushData(LPC_SSP_T *pSSP);
\r
229 * @brief SSP Interrupt Read/Write with 8-bit frame width
\r
230 * @param pSSP : The base SSP peripheral on the chip
\r
231 * @param xf_setup : Pointer to a SSP_DATA_SETUP_T structure that contains specified
\r
232 * information about transmit/receive data configuration
\r
233 * @return SUCCESS or ERROR
\r
235 Status Chip_SSP_Int_RWFrames8Bits(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup);
\r
238 * @brief SSP Interrupt Read/Write with 16-bit frame width
\r
239 * @param pSSP : The base SSP peripheral on the chip
\r
240 * @param xf_setup : Pointer to a SSP_DATA_SETUP_T structure that contains specified
\r
241 * information about transmit/receive data configuration
\r
242 * @return SUCCESS or ERROR
\r
244 Status Chip_SSP_Int_RWFrames16Bits(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup);
\r
247 * @brief SSP Polling Read/Write in blocking mode
\r
248 * @param pSSP : The base SSP peripheral on the chip
\r
249 * @param xf_setup : Pointer to a SSP_DATA_SETUP_T structure that contains specified
\r
250 * information about transmit/receive data configuration
\r
251 * @return Actual data length has been transferred
\r
253 * This function can be used in both master and slave mode. It starts with writing phase and after that,
\r
254 * a reading phase is generated to read any data available in RX_FIFO. All needed information is prepared
\r
255 * through xf_setup param.
\r
257 uint32_t Chip_SSP_RWFrames_Blocking(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup);
\r
260 * @brief SSP Polling Write in blocking mode
\r
261 * @param pSSP : The base SSP peripheral on the chip
\r
262 * @param buffer : Buffer address
\r
263 * @param buffer_len : Buffer length
\r
264 * @return Actual data length has been transferred
\r
266 * This function can be used in both master and slave mode. First, a writing operation will send
\r
267 * the needed data. After that, a dummy reading operation is generated to clear data buffer
\r
269 uint32_t Chip_SSP_WriteFrames_Blocking(LPC_SSP_T *pSSP, uint8_t *buffer, uint32_t buffer_len);
\r
273 * @param pSSP : The base SSP peripheral on the chip
\r
274 * @param buffer : Buffer address
\r
275 * @param buffer_len : The length of buffer
\r
276 * @return Actual data length has been transferred
\r
278 * This function can be used in both master and slave mode. First, a dummy writing operation is generated
\r
279 * to clear data buffer. After that, a reading operation will receive the needed data
\r
281 uint32_t Chip_SSP_ReadFrames_Blocking(LPC_SSP_T *pSSP, uint8_t *buffer, uint32_t buffer_len);
\r
284 * @brief Initialize the SSP
\r
285 * @param pSSP : The base SSP peripheral on the chip
\r
288 void Chip_SSP_Init(LPC_SSP_T *pSSP);
\r
291 * @brief Shutdown the SSP
\r
292 * @param pSSP : The base SSP peripheral on the chip
\r
295 void Chip_SSP_DeInit(LPC_SSP_T *pSSP);
\r
298 * @brief Set the SSP operating modes, master or slave
\r
299 * @param pSSP : The base SSP peripheral on the chip
\r
300 * @param master : 1 to set master, 0 to set slave
\r
303 void Chip_SSP_SetMaster(LPC_SSP_T *pSSP, bool master);
\r
306 * @brief Set the clock frequency for SSP interface
\r
307 * @param pSSP : The base SSP peripheral on the chip
\r
308 * @param bitRate : The SSP bit rate
\r
311 void Chip_SSP_SetBitRate(LPC_SSP_T *pSSP, uint32_t bitRate);
\r
314 * @brief Set up the SSP frame format
\r
315 * @param pSSP : The base SSP peripheral on the chip
\r
316 * @param format : Structure used to format frame
\r
319 STATIC INLINE void Chip_SSP_SetFormat(LPC_SSP_T *pSSP, SSP_ConfigFormat *format)
\r
321 IP_SSP_SetFormat(pSSP, format->bits, format->frameFormat, format->clockMode);
\r
325 * @brief Enable SSP interrupt
\r
326 * @param pSSP : The base SSP peripheral on the chip
\r
329 STATIC INLINE void Chip_SSP_Int_Enable(LPC_SSP_T *pSSP)
\r
331 IP_SSP_Int_Enable(pSSP, SSP_TXIM);
\r
335 * @brief Disable SSP interrupt
\r
336 * @param pSSP : The base SSP peripheral on the chip
\r
339 STATIC INLINE void Chip_SSP_Int_Disable(LPC_SSP_T *pSSP)
\r
341 IP_SSP_Int_Disable(pSSP, SSP_TXIM);
\r
352 #endif /* __SSP_18XX_43XX_H_ */
\r