Update Temperature board driver to be AVR32 compatible when the ADC peripheral driver...
[pub/USBasp.git] / LUFA / Drivers / Peripheral / AVR32 / SPI.h
index b748479..4322eaa 100644 (file)
                        /** Initialises the SPI subsystem, ready for transfers. Must be called before calling any other\r
                         *  SPI routines.\r
                         *\r
+                        *  \note The individual AVR32 chip select control registers are left at their defaults; it is up to the user\r
+                        *        to configure these seperately once the SPI module has been initialized.\r
+                        *\r
+                        *  \note The physical GPIO pins for the AVR32's SPI are not altered; it is up to the user to\r
+                        *        configure these seperately to connect the SPI module to the desired GPIO pins via the\r
+                        *        GPIO MUX registers.\r
+                        *\r
                         *  \param[in] SPIOptions  SPI Options, a mask consisting of one of each of the SPI_SPEED_*\r
                         *                         and SPI_MODE_* masks\r
                         */\r
-                       static inline void SPI_Init(const uint8_t SPIOptions)\r
+                       static inline void SPI_Init(const uintN_t SPIOptions)\r
                        {\r
-                               AVR32_SPI.cr = AVR32_SPI_CR_SPIEN_MASK | AVR32_SPI_CR_SWRST_MASK;\r
+                               AVR32_SPI.cr = (AVR32_SPI_CR_SPIEN_MASK | AVR32_SPI_CR_SWRST_MASK);\r
                                AVR32_SPI.mr = SPIOptions;\r
                        }\r
-                       \r
+\r
                        /** Turns off the SPI driver, disabling and returning used hardware to their default configuration. */\r
                        static inline void SPI_ShutDown(void)\r
                        {\r
                                AVR32_SPI.cr = AVR32_SPI_CR_SPIDIS_MASK;\r
                        }\r
                        \r
-                       /** Sends and receives a byte through the SPI interface, blocking until the transfer is complete.\r
+                       /** Sends and receives a transfer through the SPI interface, blocking until the transfer is complete.\r
+                        *  The width of the data that is transferred is dependant on the settings of the currently selected\r
+                        *  peripheral.\r
                         *\r
-                        *  \param[in] Byte  Byte to send through the SPI interface\r
+                        *  \param[in] Data  Data to send through the SPI interface\r
                         *\r
-                        *  \return Response byte from the attached SPI device\r
+                        *  \return Response data from the attached SPI device\r
                         */\r
-                       static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;\r
-                       static inline uint8_t SPI_TransferByte(const uint8_t Byte)\r
+                       static inline uint16_t SPI_Transfer(const uint16_t Data) ATTR_ALWAYS_INLINE;\r
+                       static inline uint16_t SPI_Transfer(const uint16_t Data)\r
                        {\r
-                               AVR32_SPI.tdr = Byte;\r
-                               // TODO: Wait for receive\r
+                               AVR32_SPI.TDR.td = Data;\r
+                               while (!(AVR32_SPI.SR.tdre));\r
                                return AVR32_SPI.rdr;\r
                        }\r
 \r
-                       /** Sends a byte through the SPI interface, blocking until the transfer is complete. The response\r
-                        *  byte sent to from the attached SPI device is ignored.\r
+                       /** Sends a transfer through the SPI interface, blocking until the transfer is complete. The response\r
+                        *  data sent to from the attached SPI device is ignored. The width of the data that is transferred is\r
+                        *  dependant on the settings of the currently selected peripheral.\r
                         *\r
-                        *  \param[in] Byte Byte to send through the SPI interface\r
+                        *  \param[in] Data  Data to send through the SPI interface\r
                         */\r
-                       static inline void SPI_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;\r
-                       static inline void SPI_SendByte(const uint8_t Byte)\r
+                       static inline void SPI_Send(const uint16_t Data) ATTR_ALWAYS_INLINE;\r
+                       static inline void SPI_Send(const uint16_t Data)\r
                        {\r
-                               AVR32_SPI.tdr = Byte;\r
-                               // TODO: Wait for receive                               \r
+                               AVR32_SPI.TDR.td = Data;\r
+                               while (!(AVR32_SPI.SR.tdre));\r
                        }\r
 \r
-                       /** Sends a dummy byte through the SPI interface, blocking until the transfer is complete. The response\r
-                        *  byte from the attached SPI device is returned.\r
+                       /** Sends a dummy transfer through the SPI interface, blocking until the transfer is complete. The response\r
+                        *  data from the attached SPI device is returned. The width of the data that is transferred is dependant on\r
+                        *  the settings of the currently selected peripheral.\r
                         *\r
-                        *  \return The response byte from the attached SPI device\r
+                        *  \return The response data from the attached SPI device\r
                         */\r
-                       static inline uint8_t SPI_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;\r
-                       static inline uint8_t SPI_ReceiveByte(void)\r
+                       static inline uint16_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;\r
+                       static inline uint16_t SPI_Receive(void)\r
                        {\r
-                               AVR32_SPI.tdr = 0x00;\r
-                               // TODO: Wait for receive                               \r
-                               return AVR32_SPI.rdr;\r
+                               AVR32_SPI.TDR.td = 0x0000;\r
+                               while (!(AVR32_SPI.SR.tdre));\r
+                               return AVR32_SPI.RDR.rd;\r
                        }\r
 \r
        /* Disable C linkage for C++ Compilers: */\r