27 #ifndef LPC17XX_SPI_H_
28 #define LPC17XX_SPI_H_
49 #define SPI_CPHA_FIRST ((uint32_t)(0))
50 #define SPI_CPHA_SECOND ((uint32_t)(1<<3))
53 #define SPI_CPOL_HI ((uint32_t)(0))
54 #define SPI_CPOL_LO ((uint32_t)(1<<4))
57 #define SPI_SLAVE_MODE ((uint32_t)(0))
58 #define SPI_MASTER_MODE ((uint32_t)(1<<5))
61 #define SPI_DATA_MSB_FIRST ((uint32_t)(0))
62 #define SPI_DATA_LSB_FIRST ((uint32_t)(1<<6))
65 #define SPI_DATABIT_16 SPI_SPCR_BITS(0)
66 #define SPI_DATABIT_8 SPI_SPCR_BITS(0x08)
67 #define SPI_DATABIT_9 SPI_SPCR_BITS(0x09)
68 #define SPI_DATABIT_10 SPI_SPCR_BITS(0x0A)
69 #define SPI_DATABIT_11 SPI_SPCR_BITS(0x0B)
70 #define SPI_DATABIT_12 SPI_SPCR_BITS(0x0C)
71 #define SPI_DATABIT_13 SPI_SPCR_BITS(0x0D)
72 #define SPI_DATABIT_14 SPI_SPCR_BITS(0x0E)
73 #define SPI_DATABIT_15 SPI_SPCR_BITS(0x0F)
79 #define SPI_STAT_ABRT SPI_SPSR_ABRT
81 #define SPI_STAT_MODF SPI_SPSR_MODF
83 #define SPI_STAT_ROVR SPI_SPSR_ROVR
85 #define SPI_STAT_WCOL SPI_SPSR_WCOL
87 #define SPI_STAT_SPIF SPI_SPSR_SPIF
90 #define SPI_STAT_DONE (1UL<<8)
91 #define SPI_STAT_ERROR (1UL<<9)
109 #define SPI_SPCR_BIT_EN ((uint32_t)(1<<2))
111 #define SPI_SPCR_CPHA_SECOND ((uint32_t)(1<<3))
113 #define SPI_SPCR_CPOL_LOW ((uint32_t)(1<<4))
115 #define SPI_SPCR_MSTR ((uint32_t)(1<<5))
117 #define SPI_SPCR_LSBF ((uint32_t)(1<<6))
119 #define SPI_SPCR_SPIE ((uint32_t)(1<<7))
122 #define SPI_SPCR_BITS(n) ((n==0) ? ((uint32_t)0) : ((uint32_t)((n&0x0F)<<8)))
124 #define SPI_SPCR_BITMASK ((uint32_t)(0xFFC))
130 #define SPI_SPSR_ABRT ((uint32_t)(1<<3))
132 #define SPI_SPSR_MODF ((uint32_t)(1<<4))
134 #define SPI_SPSR_ROVR ((uint32_t)(1<<5))
136 #define SPI_SPSR_WCOL ((uint32_t)(1<<6))
138 #define SPI_SPSR_SPIF ((uint32_t)(1<<7))
140 #define SPI_SPSR_BITMASK ((uint32_t)(0xF8))
146 #define SPI_SPDR_LO_MASK ((uint32_t)(0xFF))
148 #define SPI_SPDR_HI_MASK ((uint32_t)(0xFF00))
150 #define SPI_SPDR_BITMASK ((uint32_t)(0xFFFF))
156 #define SPI_SPCCR_COUNTER(n) ((uint32_t)(n&0xFF))
158 #define SPI_SPCCR_BITMASK ((uint32_t)(0xFF))
164 #define SPI_SPTCR_TEST_MASK ((uint32_t)(0xFE))
166 #define SPI_SPTCR_BITMASK ((uint32_t)(0xFE))
172 #define SPI_SPTSR_ABRT ((uint32_t)(1<<3))
174 #define SPI_SPTSR_MODF ((uint32_t)(1<<4))
176 #define SPI_SPTSR_ROVR ((uint32_t)(1<<5))
178 #define SPI_SPTSR_WCOL ((uint32_t)(1<<6))
180 #define SPI_SPTSR_SPIF ((uint32_t)(1<<7))
182 #define SPI_SPTSR_MASKBIT ((uint32_t)(0xF8))
188 #define SPI_SPINT_INTFLAG ((uint32_t)(1<<0))
190 #define SPI_SPINT_BITMASK ((uint32_t)(0x01))
195 #define PARAM_SPIx(n) (((uint32_t *)n)==((uint32_t *)LPC_SPI))
198 #define PARAM_SPI_CPHA(n) ((n==SPI_CPHA_FIRST) || (n==SPI_CPHA_SECOND))
201 #define PARAM_SPI_CPOL(n) ((n==SPI_CPOL_HI) || (n==SPI_CPOL_LO))
204 #define PARAM_SPI_MODE(n) ((n==SPI_SLAVE_MODE) || (n==SPI_MASTER_MODE))
207 #define PARAM_SPI_DATA_ORDER(n) ((n==SPI_DATA_MSB_FIRST) || (n==SPI_DATA_LSB_FIRST))
210 #define PARAM_SPI_DATABIT(n) ((n==SPI_DATABIT_16) || (n==SPI_DATABIT_8) \
211 || (n==SPI_DATABIT_9) || (n==SPI_DATABIT_10) \
212 || (n==SPI_DATABIT_11) || (n==SPI_DATABIT_12) \
213 || (n==SPI_DATABIT_13) || (n==SPI_DATABIT_14) \
214 || (n==SPI_DATABIT_15))
217 #define PARAM_SPI_STAT(n) ((n==SPI_STAT_ABRT) || (n==SPI_STAT_MODF) \
218 || (n==SPI_STAT_ROVR) || (n==SPI_STAT_WCOL) \
219 || (n==SPI_STAT_SPIF))