1 /* 2 * Copyright 2021 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __SERIAL_PORT_SPI_H__ 10 #define __SERIAL_PORT_SPI_H__ 11 12 #include "fsl_adapter_spi.h" 13 14 /*! 15 * @addtogroup serial_port_uart 16 * @ingroup serialmanager 17 * @{ 18 */ 19 20 /******************************************************************************* 21 * Definitions 22 ******************************************************************************/ 23 /*! @brief serial port uart handle size*/ 24 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U)) 25 #if (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U)) 26 #define SERIAL_PORT_SPI_MASTER_HANDLE_SIZE (36U + HAL_SPI_MASTER_HANDLE_SIZE + HAL_SPI_MASTER_DMA_HANDLE_SIZE) 27 #else 28 #define SERIAL_PORT_SPI_MASTER_HANDLE_SIZE (36U + HAL_SPI_MASTER_HANDLE_SIZE) 29 #endif 30 #else 31 #define SERIAL_PORT_SPI_MASTER_HANDLE_SIZE (HAL_SPI_MASTER_HANDLE_SIZE) 32 #endif 33 34 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U)) 35 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U)) 36 #define SERIAL_PORT_SPI_SLAVE_HANDLE_SIZE (36U + HAL_SPI_SLAVE_HANDLE_SIZE + HAL_SPI_SLAVE_DMA_HANDLE_SIZE) 37 #else 38 #define SERIAL_PORT_SPI_SLAVE_HANDLE_SIZE (36U + HAL_SPI_SLAVE_HANDLE_SIZE) 39 #endif 40 #else 41 #define SERIAL_PORT_SPI_SLAVE_HANDLE_SIZE (HAL_SPI_SLAVE_HANDLE_SIZE) 42 #endif 43 44 #ifndef SERIAL_USE_CONFIGURE_STRUCTURE 45 #define SERIAL_USE_CONFIGURE_STRUCTURE (0U) /*!< Enable or disable the confgure structure pointer */ 46 #endif 47 48 /*! @brief spi clock polarity configuration.*/ 49 typedef enum _serial_spi_clock_polarity 50 { 51 kSerial_SpiClockPolarityActiveHigh = 0x0U, /*!< Active-high spi clock (idles low). */ 52 kSerial_SpiClockPolarityActiveLow /*!< Active-low spi clock (idles high). */ 53 } serial_spi_clock_polarity_t; 54 55 /*! @brief spi clock phase configuration.*/ 56 typedef enum _serial_spi_clock_phase 57 { 58 kSerial_SpiClockPhaseFirstEdge = 0x0U, /*!< First edge on SPSCK occurs at the middle of the first 59 * cycle of a data transfer. */ 60 kSerial_SpiClockPhaseSecondEdge /*!< First edge on SPSCK occurs at the start of the 61 * first cycle of a data transfer. */ 62 } serial_spi_clock_phase_t; 63 64 /*! @brief spi data shifter direction options.*/ 65 typedef enum _serial_spi_shift_direction 66 { 67 kSerial_SpiMsbFirst = 0x0U, /*!< Data transfers start with most significant bit. */ 68 kSerial_SpiLsbFirst /*!< Data transfers start with least significant bit. */ 69 } serial_spi_shift_direction_t; 70 71 /*! @brief spi master user configure structure.*/ 72 typedef struct _serial_spi_master_config 73 { 74 uint32_t srcClock_Hz; /*!< Clock source for spi in Hz */ 75 uint32_t baudRate_Bps; /*!< Baud Rate for spi in Hz */ 76 serial_spi_clock_polarity_t polarity; /*!< Clock polarity */ 77 serial_spi_clock_phase_t phase; /*!< Clock phase */ 78 serial_spi_shift_direction_t direction; /*!< MSB or LSB */ 79 uint8_t instance; /*!< Instance of the spi */ 80 bool enableMaster; /*!< Enable spi at initialization time */ 81 uint32_t configFlags; /*!< Transfer config Flags */ 82 #if (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U)) 83 bool enableDMA; /*!< Enable DMA at initialization time */ 84 void *dmaConfig; /*!< DMA configure pointer */ 85 #endif 86 } serial_spi_master_config_t; 87 88 /*! @brief spi slave user configure structure.*/ 89 typedef struct _serial_spi_slave_config 90 { 91 hal_spi_clock_polarity_t polarity; /*!< Clock polarity */ 92 hal_spi_clock_phase_t phase; /*!< Clock phase */ 93 hal_spi_shift_direction_t direction; /*!< MSB or LSB */ 94 uint8_t instance; /*!< Instance of the spi */ 95 bool enableSlave; /*!< Enable spi at initialization time */ 96 uint32_t configFlags; /*!< Transfer config Flags */ 97 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U)) 98 bool enableDMA; /*!< Enable DMA at initialization time */ 99 void *dmaConfig; /*!< DMA configure pointer */ 100 #endif 101 } serial_spi_slave_config_t; 102 103 /*! @brief spi transfer structure */ 104 typedef struct _serial_spi_transfer 105 { 106 uint8_t *txData; /*!< Send buffer */ 107 uint8_t *rxData; /*!< Receive buffer */ 108 size_t dataSize; /*!< Transfer bytes */ 109 uint32_t flags; /*!< spi control flag.*/ 110 } serial_spi_transfer_t; 111 112 /*! @} */ 113 #endif /* __SERIAL_PORT_SPI_H__ */ 114