1 /**************************************************************************//** 2 * @file lpspi.h 3 * @version V3.00 4 * @brief M2L31 series LPSPI driver header file 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved. 8 *****************************************************************************/ 9 #ifndef __LPSPI_H__ 10 #define __LPSPI_H__ 11 12 #ifdef __cplusplus 13 extern "C" 14 { 15 #endif 16 17 18 /** @addtogroup Standard_Driver Standard Driver 19 @{ 20 */ 21 22 /** @addtogroup LPSPI_Driver LPSPI Driver 23 @{ 24 */ 25 26 /** @addtogroup LPSPI_EXPORTED_CONSTANTS LPSPI Exported Constants 27 @{ 28 */ 29 30 #define LPSPI_MODE_0 (LPSPI_CTL_TXNEG_Msk) /*!< CLKPOL=0; RXNEG=0; TXNEG=1 \hideinitializer */ 31 #define LPSPI_MODE_1 (LPSPI_CTL_RXNEG_Msk) /*!< CLKPOL=0; RXNEG=1; TXNEG=0 \hideinitializer */ 32 #define LPSPI_MODE_2 (LPSPI_CTL_CLKPOL_Msk | LPSPI_CTL_RXNEG_Msk) /*!< CLKPOL=1; RXNEG=1; TXNEG=0 \hideinitializer */ 33 #define LPSPI_MODE_3 (LPSPI_CTL_CLKPOL_Msk | LPSPI_CTL_TXNEG_Msk) /*!< CLKPOL=1; RXNEG=0; TXNEG=1 \hideinitializer */ 34 35 #define LPSPI_SLAVE (LPSPI_CTL_SLAVE_Msk) /*!< Set as slave \hideinitializer */ 36 #define LPSPI_MASTER (0x0U) /*!< Set as master \hideinitializer */ 37 38 #define LPSPI_SS (LPSPI_SSCTL_SS_Msk) /*!< Set SS \hideinitializer */ 39 #define LPSPI_SS_ACTIVE_HIGH (LPSPI_SSCTL_SSACTPOL_Msk) /*!< SS active high \hideinitializer */ 40 #define LPSPI_SS_ACTIVE_LOW (0x0U) /*!< SS active low \hideinitializer */ 41 42 /* LPSPI Interrupt Mask */ 43 #define LPSPI_UNIT_INT_MASK (0x001U) /*!< Unit transfer interrupt mask \hideinitializer */ 44 #define LPSPI_SSACT_INT_MASK (0x002U) /*!< Slave selection signal active interrupt mask \hideinitializer */ 45 #define LPSPI_SSINACT_INT_MASK (0x004U) /*!< Slave selection signal inactive interrupt mask \hideinitializer */ 46 #define LPSPI_SLVUR_INT_MASK (0x008U) /*!< Slave under run interrupt mask \hideinitializer */ 47 #define LPSPI_SLVBE_INT_MASK (0x010U) /*!< Slave bit count error interrupt mask \hideinitializer */ 48 #define LPSPI_TXUF_INT_MASK (0x040U) /*!< Slave TX underflow interrupt mask \hideinitializer */ 49 #define LPSPI_FIFO_TXTH_INT_MASK (0x080U) /*!< FIFO TX threshold interrupt mask \hideinitializer */ 50 #define LPSPI_FIFO_RXTH_INT_MASK (0x100U) /*!< FIFO RX threshold interrupt mask \hideinitializer */ 51 #define LPSPI_FIFO_RXOV_INT_MASK (0x200U) /*!< FIFO RX overrun interrupt mask \hideinitializer */ 52 #define LPSPI_FIFO_RXTO_INT_MASK (0x400U) /*!< FIFO RX time-out interrupt mask \hideinitializer */ 53 54 /* LPSPI Status Mask */ 55 #define LPSPI_BUSY_MASK (0x01U) /*!< Busy status mask \hideinitializer */ 56 #define LPSPI_RX_EMPTY_MASK (0x02U) /*!< RX empty status mask \hideinitializer */ 57 #define LPSPI_RX_FULL_MASK (0x04U) /*!< RX full status mask \hideinitializer */ 58 #define LPSPI_TX_EMPTY_MASK (0x08U) /*!< TX empty status mask \hideinitializer */ 59 #define LPSPI_TX_FULL_MASK (0x10U) /*!< TX full status mask \hideinitializer */ 60 #define LPSPI_TXRX_RESET_MASK (0x20U) /*!< TX or RX reset status mask \hideinitializer */ 61 #define LPSPI_SPIEN_STS_MASK (0x40U) /*!< SPIEN status mask \hideinitializer */ 62 #define LPSPI_SSLINE_STS_MASK (0x80U) /*!< SPIx_SS line status mask \hideinitializer */ 63 64 /* LPSPI AUTOCTL Trigger Source */ 65 #define LPSPI_AUTOCTL_TRIGSEL_LPTMR0 (0UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is LPTMR0 \hideinitializer */ 66 #define LPSPI_AUTOCTL_TRIGSEL_LPTMR1 (1UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is LPTMR1 \hideinitializer */ 67 #define LPSPI_AUTOCTL_TRIGSEL_TTMR0 (2UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is TTMR0 \hideinitializer */ 68 #define LPSPI_AUTOCTL_TRIGSEL_TTMR1 (3UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is TTMR1 \hideinitializer */ 69 #define LPSPI_AUTOCTL_TRIGSEL_WKIOA0 (4UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is WKIOA0 \hideinitializer */ 70 #define LPSPI_AUTOCTL_TRIGSEL_WKIOB0 (5UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is WKIOB0 \hideinitializer */ 71 #define LPSPI_AUTOCTL_TRIGSEL_WKIOC0 (6UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is WKIOC0 \hideinitializer */ 72 #define LPSPI_AUTOCTL_TRIGSEL_WKIOD0 (7UL<<LPSPI_AUTOCTL_TRIGSEL_Pos) /*!< LPSPI Automatic Operation Trigger Source Select is WKIOD0 \hideinitializer */ 73 74 75 /*@}*/ /* end of group LPSPI_EXPORTED_CONSTANTS */ 76 77 78 /** @addtogroup LPSPI_EXPORTED_FUNCTIONS LPSPI Exported Functions 79 @{ 80 */ 81 82 /** 83 * @brief Clear the unit transfer interrupt flag. 84 * @param[in] lpspi The pointer of the specified LPSPI module. 85 * @return None. 86 * @details Write 1 to UNITIF bit of LPSPI_STATUS register to clear the unit transfer interrupt flag. 87 * \hideinitializer 88 */ 89 #define LPSPI_CLR_UNIT_TRANS_INT_FLAG(lpspi) ((lpspi)->STATUS = LPSPI_STATUS_UNITIF_Msk) 90 91 /** 92 * @brief Trigger RX PDMA function. 93 * @param[in] lpspi The pointer of the specified LPSPI module. 94 * @return None. 95 * @details Set RXPDMAEN bit of LPSPI_PDMACTL register to enable RX PDMA transfer function. 96 * \hideinitializer 97 */ 98 #define LPSPI_TRIGGER_RX_PDMA(lpspi) ((lpspi)->PDMACTL |= LPSPI_PDMACTL_RXPDMAEN_Msk) 99 100 /** 101 * @brief Trigger TX PDMA function. 102 * @param[in] lpspi The pointer of the specified LPSPI module. 103 * @return None. 104 * @details Set TXPDMAEN bit of LPSPI_PDMACTL register to enable TX PDMA transfer function. 105 * \hideinitializer 106 */ 107 #define LPSPI_TRIGGER_TX_PDMA(lpspi) ((lpspi)->PDMACTL |= LPSPI_PDMACTL_TXPDMAEN_Msk) 108 109 /** 110 * @brief Trigger TX and RX PDMA function. 111 * @param[in] lpspi The pointer of the specified LPSPI module. 112 * @return None. 113 * @details Set TXPDMAEN bit and RXPDMAEN bit of LPSPI_PDMACTL register to enable TX and RX PDMA transfer function. 114 * \hideinitializer 115 */ 116 #define LPSPI_TRIGGER_TX_RX_PDMA(lpspi) ((lpspi)->PDMACTL |= (LPSPI_PDMACTL_TXPDMAEN_Msk | LPSPI_PDMACTL_RXPDMAEN_Msk)) 117 118 /** 119 * @brief Disable RX PDMA transfer. 120 * @param[in] lpspi The pointer of the specified LPSPI module. 121 * @return None. 122 * @details Clear RXPDMAEN bit of LPSPI_PDMACTL register to disable RX PDMA transfer function. 123 * \hideinitializer 124 */ 125 #define LPSPI_DISABLE_RX_PDMA(lpspi) ( (lpspi)->PDMACTL &= ~LPSPI_PDMACTL_RXPDMAEN_Msk ) 126 127 /** 128 * @brief Disable TX PDMA transfer. 129 * @param[in] lpspi The pointer of the specified LPSPI module. 130 * @return None. 131 * @details Clear TXPDMAEN bit of LPSPI_PDMACTL register to disable TX PDMA transfer function. 132 * \hideinitializer 133 */ 134 #define LPSPI_DISABLE_TX_PDMA(lpspi) ( (lpspi)->PDMACTL &= ~LPSPI_PDMACTL_TXPDMAEN_Msk ) 135 136 /** 137 * @brief Disable TX and RX PDMA transfer. 138 * @param[in] lpspi The pointer of the specified LPSPI module. 139 * @return None. 140 * @details Clear TXPDMAEN bit and RXPDMAEN bit of LPSPI_PDMACTL register to disable TX and RX PDMA transfer function. 141 * \hideinitializer 142 */ 143 #define LPSPI_DISABLE_TX_RX_PDMA(lpspi) ( (lpspi)->PDMACTL &= ~(LPSPI_PDMACTL_TXPDMAEN_Msk | LPSPI_PDMACTL_RXPDMAEN_Msk) ) 144 145 /** 146 * @brief Get the count of available data in RX FIFO. 147 * @param[in] lpspi The pointer of the specified LPSPI module. 148 * @return The count of available data in RX FIFO. 149 * @details Read RXCNT (LPSPI_STATUS[27:24]) to get the count of available data in RX FIFO. 150 * \hideinitializer 151 */ 152 #define LPSPI_GET_RX_FIFO_COUNT(lpspi) (((lpspi)->STATUS & LPSPI_STATUS_RXCNT_Msk) >> LPSPI_STATUS_RXCNT_Pos) 153 154 /** 155 * @brief Get the RX FIFO empty flag. 156 * @param[in] lpspi The pointer of the specified LPSPI module. 157 * @retval 0 RX FIFO is not empty. 158 * @retval 1 RX FIFO is empty. 159 * @details Read RXEMPTY bit of LPSPI_STATUS register to get the RX FIFO empty flag. 160 * \hideinitializer 161 */ 162 #define LPSPI_GET_RX_FIFO_EMPTY_FLAG(lpspi) (((lpspi)->STATUS & LPSPI_STATUS_RXEMPTY_Msk)>>LPSPI_STATUS_RXEMPTY_Pos) 163 164 /** 165 * @brief Get the TX FIFO empty flag. 166 * @param[in] lpspi The pointer of the specified LPSPI module. 167 * @retval 0 TX FIFO is not empty. 168 * @retval 1 TX FIFO is empty. 169 * @details Read TXEMPTY bit of LPSPI_STATUS register to get the TX FIFO empty flag. 170 * \hideinitializer 171 */ 172 #define LPSPI_GET_TX_FIFO_EMPTY_FLAG(lpspi) (((lpspi)->STATUS & LPSPI_STATUS_TXEMPTY_Msk)>>LPSPI_STATUS_TXEMPTY_Pos) 173 174 /** 175 * @brief Get the TX FIFO full flag. 176 * @param[in] lpspi The pointer of the specified LPSPI module. 177 * @retval 0 TX FIFO is not full. 178 * @retval 1 TX FIFO is full. 179 * @details Read TXFULL bit of LPSPI_STATUS register to get the TX FIFO full flag. 180 * \hideinitializer 181 */ 182 #define LPSPI_GET_TX_FIFO_FULL_FLAG(lpspi) (((lpspi)->STATUS & LPSPI_STATUS_TXFULL_Msk)>>LPSPI_STATUS_TXFULL_Pos) 183 184 /** 185 * @brief Get the datum read from RX register. 186 * @param[in] lpspi The pointer of the specified LPSPI module. 187 * @return Data in RX register. 188 * @details Read LPSPI_RX register to get the received datum. 189 * \hideinitializer 190 */ 191 #define LPSPI_READ_RX(lpspi) ((lpspi)->RX) 192 193 /** 194 * @brief Write datum to TX register. 195 * @param[in] lpspi The pointer of the specified LPSPI module. 196 * @param[in] u32TxData The datum which user attempt to transfer through LPSPI bus. 197 * @return None. 198 * @details Write u32TxData to LPSPI_TX register. 199 * \hideinitializer 200 */ 201 #define LPSPI_WRITE_TX(lpspi, u32TxData) ((lpspi)->TX = (u32TxData)) 202 203 /** 204 * @brief Set SPIx_SS pin to high state. 205 * @param[in] lpspi The pointer of the specified LPSPI module. 206 * @return None. 207 * @details Disable automatic slave selection function and set SPIx_SS pin to high state. 208 * \hideinitializer 209 */ 210 #define LPSPI_SET_SS_HIGH(lpspi) ((lpspi)->SSCTL = ((lpspi)->SSCTL & (~LPSPI_SSCTL_AUTOSS_Msk)) | (LPSPI_SSCTL_SSACTPOL_Msk | LPSPI_SSCTL_SS_Msk)) 211 212 /** 213 * @brief Set SPIx_SS pin to low state. 214 * @param[in] lpspi The pointer of the specified LPSPI module. 215 * @return None. 216 * @details Disable automatic slave selection function and set SPIx_SS pin to low state. 217 * \hideinitializer 218 */ 219 #define LPSPI_SET_SS_LOW(lpspi) ((lpspi)->SSCTL = ((lpspi)->SSCTL & (~(LPSPI_SSCTL_AUTOSS_Msk | LPSPI_SSCTL_SSACTPOL_Msk))) | LPSPI_SSCTL_SS_Msk) 220 221 /** 222 * @brief Enable Byte Reorder function. 223 * @param[in] lpspi The pointer of the specified LPSPI module. 224 * @return None. 225 * @details Enable Byte Reorder function. The suspend interval depends on the setting of SUSPITV (LPSPI_CTL[7:4]). 226 * \hideinitializer 227 */ 228 #define LPSPI_ENABLE_BYTE_REORDER(lpspi) ((lpspi)->CTL |= LPSPI_CTL_REORDER_Msk) 229 230 /** 231 * @brief Disable Byte Reorder function. 232 * @param[in] lpspi The pointer of the specified LPSPI module. 233 * @return None. 234 * @details Clear REORDER bit field of LPSPI_CTL register to disable Byte Reorder function. 235 * \hideinitializer 236 */ 237 #define LPSPI_DISABLE_BYTE_REORDER(lpspi) ((lpspi)->CTL &= ~LPSPI_CTL_REORDER_Msk) 238 239 /** 240 * @brief Set the length of suspend interval. 241 * @param[in] lpspi The pointer of the specified LPSPI module. 242 * @param[in] u32SuspCycle Decides the length of suspend interval. It could be 0 ~ 15. 243 * @return None. 244 * @details Set the length of suspend interval according to u32SuspCycle. 245 * The length of suspend interval is ((u32SuspCycle + 0.5) * the length of one LPSPI bus clock cycle). 246 * \hideinitializer 247 */ 248 #define LPSPI_SET_SUSPEND_CYCLE(lpspi, u32SuspCycle) ((lpspi)->CTL = ((lpspi)->CTL & ~LPSPI_CTL_SUSPITV_Msk) | ((u32SuspCycle) << LPSPI_CTL_SUSPITV_Pos)) 249 250 /** 251 * @brief Set the LPSPI transfer sequence with LSB first. 252 * @param[in] lpspi The pointer of the specified LPSPI module. 253 * @return None. 254 * @details Set LSB bit of LPSPI_CTL register to set the LPSPI transfer sequence with LSB first. 255 * \hideinitializer 256 */ 257 #define LPSPI_SET_LSB_FIRST(lpspi) ((lpspi)->CTL |= LPSPI_CTL_LSB_Msk) 258 259 /** 260 * @brief Set the LPSPI transfer sequence with MSB first. 261 * @param[in] lpspi The pointer of the specified LPSPI module. 262 * @return None. 263 * @details Clear LSB bit of LPSPI_CTL register to set the LPSPI transfer sequence with MSB first. 264 * \hideinitializer 265 */ 266 #define LPSPI_SET_MSB_FIRST(lpspi) ((lpspi)->CTL &= ~LPSPI_CTL_LSB_Msk) 267 268 /** 269 * @brief Set the data width of a LPSPI transaction. 270 * @param[in] lpspi The pointer of the specified LPSPI module. 271 * @param[in] u32Width The bit width of one transaction. 272 * @return None. 273 * @details The data width can be 8 ~ 32 bits. 274 * \hideinitializer 275 */ 276 #define LPSPI_SET_DATA_WIDTH(lpspi, u32Width) ((lpspi)->CTL = ((lpspi)->CTL & ~LPSPI_CTL_DWIDTH_Msk) | (((u32Width)&0x1F) << LPSPI_CTL_DWIDTH_Pos)) 277 278 /** 279 * @brief Get the LPSPI busy state. 280 * @param[in] lpspi The pointer of the specified LPSPI module. 281 * @retval 0 LPSPI controller is not busy. 282 * @retval 1 LPSPI controller is busy. 283 * @details This macro will return the busy state of LPSPI controller. 284 * \hideinitializer 285 */ 286 #define LPSPI_IS_BUSY(lpspi) (((lpspi)->STATUS & LPSPI_STATUS_BUSY_Msk)>>LPSPI_STATUS_BUSY_Pos ) 287 288 /** 289 * @brief Enable LPSPI controller. 290 * @param[in] lpspi The pointer of the specified LPSPI module. 291 * @return None. 292 * @details Set SPIEN (LPSPI_CTL[0]) to enable LPSPI controller. 293 * \hideinitializer 294 */ 295 #define LPSPI_ENABLE(lpspi) ((lpspi)->CTL |= LPSPI_CTL_SPIEN_Msk) 296 297 /** 298 * @brief Disable LPSPI controller. 299 * @param[in] lpspi The pointer of the specified LPSPI module. 300 * @return None. 301 * @details Clear SPIEN (LPSPI_CTL[0]) to disable LPSPI controller. 302 * \hideinitializer 303 */ 304 #define LPSPI_DISABLE(lpspi) ((lpspi)->CTL &= ~LPSPI_CTL_SPIEN_Msk) 305 306 /** 307 * @brief Set Auto Operation RX transfer count. 308 * @param[in] lpspi The pointer of the specified LPSPI module. 309 * @param[in] u32Tcnt The transfer count specified in RX phase. 310 * @return None. 311 * @details Set RX transfer count (LPSPI_AUTOCTL[23:16]). 312 * \hideinitializer 313 */ 314 #define LPSPI_SET_AUTO_RX_TCNT(lpspi, u32Tcnt) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_TCNT_Msk); \ 315 ((lpspi)->AUTOCTL |= ((u32Tcnt&0xFF) << LPSPI_AUTOCTL_TCNT_Pos)) 316 317 /** 318 * @brief Enable RX TCNT count match wake up. 319 * @param[in] lpspi The pointer of the specified LPSPI module. 320 * @return None. 321 * @details Set CNTWKEN (LPSPI_AUTOCTL[10]) to enable RX TCNT count match wake up function. 322 * \hideinitializer 323 */ 324 #define LPSPI_ENABLE_AUTO_CNT_WAKEUP(lpspi) ((lpspi)->AUTOCTL |= LPSPI_AUTOCTL_CNTWKEN_Msk) 325 326 /** 327 * @brief Disable RX TCNT count match wake up. 328 * @param[in] lpspi The pointer of the specified LPSPI module. 329 * @return None. 330 * @details Clear CNTWKEN (LPSPI_AUTOCTL[10]) to disable RX TCNT count match wake up function. 331 * \hideinitializer 332 */ 333 #define LPSPI_DISABLE_AUTO_CNT_WAKEUP(lpspi) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_CNTWKEN_Msk) 334 335 /** 336 * @brief Enable Software Trigger for Auto Operation. 337 * @param[in] lpspi The pointer of the specified LPSPI module. 338 * @return None. 339 * @details Set SWTRIG (LPSPI_AUTOCTL[9], Write Only bit) to enable Software Trigger in Auto Operation Mode. 340 * \hideinitializer 341 */ 342 #define LPSPI_ENABLE_AUTO_SW_TRIG(lpspi) ((lpspi)->AUTOCTL |= LPSPI_AUTOCTL_SWTRIG_Msk) 343 344 /** 345 * @brief Disable Software Trigger for Auto Operation. 346 * @param[in] lpspi The pointer of the specified LPSPI module. 347 * @return None. 348 * @details Clear SWTRIG (LPSPI_AUTOCTL[9], Write Only bit) to disable Software Trigger in Auto Operation Mode. 349 * \hideinitializer 350 */ 351 #define LPSPI_DISABLE_AUTO_SW_TRIG(lpspi) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_SWTRIG_Msk) 352 353 /** 354 * @brief Enable LPSPI Auto Operation Mode. 355 * @param[in] lpspi The pointer of the specified LPSPI module. 356 * @return None. 357 * @details Set AUTOEN (LPSPI_AUTOCTL[8]) to enable Auto Operation Mode. 358 * \hideinitializer 359 */ 360 #define LPSPI_ENABLE_AUTO(lpspi) ((lpspi)->AUTOCTL |= LPSPI_AUTOCTL_AUTOEN_Msk) 361 362 /** 363 * @brief Disable LPSPI Auto Operation Mode. 364 * @param[in] lpspi The pointer of the specified LPSPI module. 365 * @return None. 366 * @details Clear AUTOEN (LPSPI_AUTOCTL[8]) to disable Auto Operation Mode. 367 * \hideinitializer 368 */ 369 #define LPSPI_DISABLE_AUTO(lpspi) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_AUTOEN_Msk) 370 371 /** 372 * @brief Enable Slave Selection wake up. 373 * @param[in] lpspi The pointer of the specified LPSPI module. 374 * @return None. 375 * @details Set SSWKEN (LPSPI_AUTOCTL[7]) to enable Slave Selection wake up function. This bit is not related to Auto Operation. 376 * \hideinitializer 377 */ 378 #define LPSPI_ENABLE_SS_WAKEUP(lpspi) ((lpspi)->AUTOCTL |= LPSPI_AUTOCTL_SSWKEN_Msk) 379 380 /** 381 * @brief Disable Slave Selection wake up. 382 * @param[in] lpspi The pointer of the specified LPSPI module. 383 * @return None. 384 * @details Clear SSWKEN (LPSPI_AUTOCTL[7]) to disable Slave Selection wake up function. This bit is not related to Auto Operation. 385 * \hideinitializer 386 */ 387 #define LPSPI_DISABLE_SS_WAKEUP(lpspi) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_SSWKEN_Msk) 388 389 /** 390 * @brief Enable RX function in Auto Opertion TX phase. 391 * @param[in] lpspi The pointer of the specified LPSPI module. 392 * @return None. 393 * @details Set FULLRXEN (LPSPI_AUTOCTL[6]) to enable RX function in Auto Operation TX phase. 394 * \hideinitializer 395 */ 396 #define LPSPI_ENABLE_AUTO_FULLRX(lpspi) ((lpspi)->AUTOCTL |= LPSPI_AUTOCTL_FULLRXEN_Msk) 397 398 /** 399 * @brief Disable RX function in Auto Opertion TX phase. 400 * @param[in] lpspi The pointer of the specified LPSPI module. 401 * @return None. 402 * @details Clear FULLRXEN (LPSPI_AUTOCTL[6]) to disable RX function in Auto Operation TX phase. 403 * \hideinitializer 404 */ 405 #define LPSPI_DISABLE_AUTO_FULLRX(lpspi) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_FULLRXEN_Msk) 406 407 /** 408 * @brief Enable RX TCNT count match Interrupt. 409 * @param[in] lpspi The pointer of the specified LPSPI module. 410 * @return None. 411 * @details Set CNTIEN (LPSPI_AUTOCTL[5]) to enable RX TCNT count match interrpu up function. 412 * \hideinitializer 413 */ 414 #define LPSPI_ENABLE_AUTO_CNT_INT(lpspi) ((lpspi)->AUTOCTL |= LPSPI_AUTOCTL_CNTIEN_Msk) 415 416 /** 417 * @brief Disable RX TCNT count match Interrupt. 418 * @param[in] lpspi The pointer of the specified LPSPI module. 419 * @return None. 420 * @details Clear CNTIEN (LPSPI_AUTOCTL[5]) to disable RX TCNT count match interrpu up function. 421 * \hideinitializer 422 */ 423 #define LPSPI_DISABLE_AUTO_CNT_INT(lpspi) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_CNTIEN_Msk) 424 425 /** 426 * @brief Enable Trigger function in Auto Opertion Mode. 427 * @param[in] lpspi The pointer of the specified LPSPI module. 428 * @return None. 429 * @details Set TRIGEN (LPSPI_AUTOCTL[4]) to enable Trigger function for Trigger source from LPTMR0/1, TTMR0/1 and LPGPIO0/1/2/3 430 * in Auto Operation Mode. 431 * \hideinitializer 432 */ 433 #define LPSPI_ENABLE_AUTO_TRIG(lpspi) ((lpspi)->AUTOCTL |= LPSPI_AUTOCTL_TRIGEN_Msk) 434 435 /** 436 * @brief Disable Trigger function in Auto Opertion Mode. 437 * @param[in] lpspi The pointer of the specified LPSPI module. 438 * @return None. 439 * @details Clear TRIGEN (LPSPI_AUTOCTL[4]) to disable Trigger function for Trigger source from LPTMR0/1, TTMR0/1 and LPGPIO0/1/2/3 440 * in Auto Operation Mode. 441 * \hideinitializer 442 */ 443 #define LPSPI_DISABLE_AUTO_TRIG(lpspi) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_TRIGEN_Msk) 444 445 /** 446 * @brief Set Trigger Source Selection for Auto Operation Mode. 447 * @param[in] lpspi The pointer of the specified LPSPI module. 448 * @param[in] u32TrigSrc The triggered source specified in Auto Operation Mode. 449 * This parameter could be only one of these following selections: 450 * - \ref LPSPI_AUTOCTL_TRIGSEL_LPTMR0 451 * - \ref LPSPI_AUTOCTL_TRIGSEL_LPTMR1 452 * - \ref LPSPI_AUTOCTL_TRIGSEL_TTMR0 453 * - \ref LPSPI_AUTOCTL_TRIGSEL_TTMR1 454 * - \ref LPSPI_AUTOCTL_TRIGSEL_WKIOA0 455 * - \ref LPSPI_AUTOCTL_TRIGSEL_WKIOB0 456 * - \ref LPSPI_AUTOCTL_TRIGSEL_WKIOC0 457 * - \ref LPSPI_AUTOCTL_TRIGSEL_WKIOD0 458 * @return None. 459 * @details Set Trigger Souce Selection (LPSPI_AUTOCTL[3:0]). 460 * \hideinitializer 461 */ 462 #define LPSPI_SET_AUTO_TRIG_SOURCE(lpspi, u32TrigSrc) ((lpspi)->AUTOCTL &= ~LPSPI_AUTOCTL_TRIGSEL_Msk); \ 463 ((lpspi)->AUTOCTL |= ((u32TrigSrc&0x0F) << LPSPI_AUTOCTL_TRIGSEL_Pos)) 464 465 /** 466 * @brief Get TCNT count match wake up flag in Auto Operation Mode. 467 * @param[in] lpspi The pointer of the specified LPSPI module. 468 * @retval 0 System is not woken up by CNT match in Auto Operation Mode. 469 * @retval 1 System is woken up by CNT match in Auto Operation Mode. 470 * @details Read CNTWKF (LPSPI_AUTOSTS[3]) register to get the CNTWK flag. 471 * \hideinitializer 472 */ 473 #define LPSPI_GET_AUTO_CNTWK_FLAG(lpspi) (((lpspi)->AUTOSTS & LPSPI_AUTOSTS_CNTWKF_Msk)>>LPSPI_AUTOSTS_CNTWKF_Pos) 474 475 /** 476 * @brief Clear TCNT count match wake up flag in Auto Operation Mode 477 * @param[in] lpspi The pointer of the specified LPSPI module. 478 * @return None. 479 * @details Write 1 to CNTWKF bit of LPSPI_AUTOSTATUS register to clear CNTWK flag. 480 * \hideinitializer 481 */ 482 #define LPSPI_CLR_AUTO_CNTWK_FLAG(lpspi) ((lpspi)->AUTOSTS = LPSPI_AUTOSTS_CNTWKF_Msk) 483 484 /** 485 * @brief Get Auto Busy flag in Auto Operation Mode. 486 * @param[in] lpspi The pointer of the specified LPSPI module. 487 * @retval 0 No more request from triiger source during Auto Operation Mode 488 * @retval 1 One more request from triiger source during Auto Operation Mode 489 * @details Read AOBUSY (LPSPI_AUTOSTS[2]) register to get the AOBUSY flag. 490 * \hideinitializer 491 */ 492 #define LPSPI_GET_AUTO_AOBUSY_FLAG(lpspi) (((lpspi)->AUTOSTS & LPSPI_AUTOSTS_AOBUSY_Msk)>>LPSPI_AUTOSTS_AOBUSY_Pos) 493 494 /** 495 * @brief Clear Auto Busy flag in Auto Operation Mode. 496 * @param[in] lpspi The pointer of the specified LPSPI module. 497 * @return None. 498 * @details Write 1 to AOBUSY bit of LPSPI_AUTOSTATUS register to clear AOBUSY flag. 499 * \hideinitializer 500 */ 501 #define LPSPI_CLR_AUTO_AOBUSY_FLAG(lpspi) ((lpspi)->AUTOSTS = LPSPI_AUTOSTS_AOBUSY_Msk) 502 503 /** 504 * @brief Get SS wake up flag. 505 * @param[in] lpspi The pointer of the specified LPSPI module. 506 * @retval 0 System is not woken up by Slave Select flag. 507 * @retval 1 System is woken up by Slave Select flag. 508 * @details Read SSWKF (LPSPI_AUTOSTS[1]) register to get the SSWKF flag. 509 * \hideinitializer 510 */ 511 #define LPSPI_GET_SSWK_FLAG(lpspi) (((lpspi)->AUTOSTS & LPSPI_AUTOSTS_SSWKF_Msk)>>LPSPI_AUTOSTS_SSWKF_Pos) 512 513 /** 514 * @brief Clear SS wake up flag. 515 * @param[in] lpspi The pointer of the specified LPSPI module. 516 * @return None. 517 * @details Write 1 to SSWKF bit of LPSPI_AUTOSTATUS register to clear SSWKF flag. 518 * \hideinitializer 519 */ 520 #define LPSPI_CLR_SSWK_FLAG(lpspi) ((lpspi)->AUTOSTS = LPSPI_AUTOSTS_SSWKF_Msk) 521 522 /** 523 * @brief Get TCNT count match interrupt flag in Auto Operation Mode. 524 * @param[in] lpspi The pointer of the specified LPSPI module. 525 * @retval 0 RX CNT is not matched in Auto Operation Mode. 526 * @retval 1 RX CNT is matched in Auto Operation Mode. 527 * @details Read CNTIF (LPSPI_AUTOSTS[0]) register to get the CNTIF flag. 528 * \hideinitializer 529 */ 530 #define LPSPI_GET_AUTO_CNT_INT_FLAG(lpspi) (((lpspi)->AUTOSTS & LPSPI_AUTOSTS_CNTIF_Msk)>>LPSPI_AUTOSTS_CNTIF_Pos) 531 532 /** 533 * @brief Clear TCNT count match interrupt flag in Auto Operation Mode 534 * @param[in] lpspi The pointer of the specified LPSPI module. 535 * @return None. 536 * @details Write 1 to CNTIF bit of LPSPI_AUTOSTATUS register to clear CNTIF flag. 537 * \hideinitializer 538 */ 539 #define LPSPI_CLR_AUTO_CNT_INT_FLAG(lpspi) ((lpspi)->AUTOSTS = LPSPI_AUTOSTS_CNTIF_Msk) 540 541 542 /* Function prototype declaration */ 543 uint32_t LPSPI_Open(LPSPI_T *lpspi, uint32_t u32MasterSlave, uint32_t u32SPIMode, uint32_t u32DataWidth, uint32_t u32BusClock); 544 void LPSPI_Close(LPSPI_T *lpspi); 545 void LPSPI_ClearRxFIFO(LPSPI_T *lpspi); 546 void LPSPI_ClearTxFIFO(LPSPI_T *lpspi); 547 void LPSPI_DisableAutoSS(LPSPI_T *lpspi); 548 void LPSPI_EnableAutoSS(LPSPI_T *lpspi, uint32_t u32SSPinMask, uint32_t u32ActiveLevel); 549 uint32_t LPSPI_SetBusClock(LPSPI_T *lpspi, uint32_t u32BusClock); 550 void LPSPI_SetFIFO(LPSPI_T *lpspi, uint32_t u32TxThreshold, uint32_t u32RxThreshold); 551 uint32_t LPSPI_GetBusClock(LPSPI_T *lpspi); 552 void LPSPI_EnableInt(LPSPI_T *lpspi, uint32_t u32Mask); 553 void LPSPI_DisableInt(LPSPI_T *lpspi, uint32_t u32Mask); 554 uint32_t LPSPI_GetIntFlag(LPSPI_T *lpspi, uint32_t u32Mask); 555 void LPSPI_ClearIntFlag(LPSPI_T *lpspi, uint32_t u32Mask); 556 uint32_t LPSPI_GetStatus(LPSPI_T *lpspi, uint32_t u32Mask); 557 558 /*@}*/ /* end of group LPSPI_EXPORTED_FUNCTIONS */ 559 560 /*@}*/ /* end of group LPSPI_Driver */ 561 562 /*@}*/ /* end of group Standard_Driver */ 563 564 #ifdef __cplusplus 565 } 566 #endif 567 568 #endif 569 570 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/ 571