+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief Master SPI Mode Serial USART Peripheral Driver (XMEGA)\r
- *\r
- * On-chip Master SPI mode USART driver for the XMEGA AVR microcontrollers.\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the SPI Master\r
- * Mode USART driver dispatch header located in LUFA/Drivers/Peripheral/Serial.h.\r
- */\r
-\r
-/** \ingroup Group_SerialSPI\r
- * \defgroup Group_SerialSPI_AVR8 Master SPI Mode Serial USART Peripheral Driver (AVR8)\r
- *\r
- * \section Sec_ModDescription Module Description\r
- * On-chip serial USART driver for the 8-bit AVR8 microcontrollers.\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the SPI Master\r
- * driver dispatch header located in LUFA/Drivers/Peripheral/SerialSPI.h.\r
- *\r
- * \section Sec_ExampleUsage Example Usage\r
- * The following snippet is an example of how this module may be used within a typical\r
- * application.\r
- *\r
- * \code\r
- * // Initialize the Master SPI mode USART driver before first use, with 1Mbit baud\r
- * SerialSPI_Init((USART_SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_ORDER_MSB_FIRST), 1000000);\r
- * \r
- * // Send several bytes, ignoring the returned data\r
- * SerialSPI_SendByte(0x01);\r
- * SerialSPI_SendByte(0x02);\r
- * SerialSPI_SendByte(0x03);\r
- * \r
- * // Receive several bytes, sending a dummy 0x00 byte each time\r
- * uint8_t Byte1 = SerialSPI_ReceiveByte();\r
- * uint8_t Byte2 = SerialSPI_ReceiveByte();\r
- * uint8_t Byte3 = SerialSPI_ReceiveByte();\r
- * \r
- * // Send a byte, and store the received byte from the same transaction\r
- * uint8_t ResponseByte = SerialSPI_TransferByte(0xDC);\r
- * \endcode\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __SERIAL_SPI_AVR8_H__\r
-#define __SERIAL_SPI_AVR8_H__\r
-\r
- /* Includes: */\r
- #include "../../../Common/Common.h"\r
-\r
- #include <stdio.h>\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_SERIAL_SPI_H)\r
- #error Do not include this file directly. Include LUFA/Drivers/Peripheral/Serial.h instead.\r
- #endif\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- #define SERIAL_SPI_UBBRVAL(Baud) ((Baud < (F_CPU / 2)) ? ((F_CPU / (2 * Baud)) - 1) : 0)\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** \name SPI SCK Polarity Configuration Masks */\r
- //@{\r
- /** SPI clock polarity mask for \ref SPI_Init(). Indicates that the SCK should lead on the rising edge. */\r
- #define USART_SPI_SCK_LEAD_RISING (0 << UCPOL)\r
-\r
- /** SPI clock polarity mask for \ref SPI_Init(). Indicates that the SCK should lead on the falling edge. */\r
- #define USART_SPI_SCK_LEAD_FALLING (1 << UCPOL)\r
- //@}\r
-\r
- /** \name SPI Sample Edge Configuration Masks */\r
- //@{\r
- /** SPI data sample mode mask for \ref SerialSPI_Init(). Indicates that the data should sampled on the leading edge. */\r
- #define USART_SPI_SAMPLE_LEADING (0 << UPCHA)\r
-\r
- /** SPI data sample mode mask for \ref SerialSPI_Init(). Indicates that the data should be sampled on the trailing edge. */\r
- #define USART_SPI_SAMPLE_TRAILING (1 << UPCHA)\r
- //@}\r
-\r
- /** \name SPI Data Ordering Configuration Masks */\r
- //@{\r
- /** SPI data order mask for \ref SerialSPI_Init(). Indicates that data should be shifted out MSB first. */\r
- #define USART_SPI_ORDER_MSB_FIRST (0 << UDORD)\r
-\r
- /** SPI data order mask for \ref SerialSPI_Init(). Indicates that data should be shifted out LSB first. */\r
- #define USART_SPI_ORDER_LSB_FIRST (1 << UDORD)\r
- //@} \r
-\r
- /* Inline Functions: */\r
- /** Initialize the USART module in Master SPI mode. \r
- *\r
- * \param[in] SPIOptions USART SPI Options, a mask consisting of one of each of the \c USART_SPI_SCK_*,\r
- * \c USART_SPI_SAMPLE_* and \c USART_SPI_ORDER_* masks.\r
- * \param[in] BaudRate SPI baud rate, in bits per second.\r
- */\r
- static inline void SerialSPI_Init(const uint8_t SPIOptions,\r
- const uint32_t BaudRate)\r
- {\r
- UBRR1 = SERIAL_SPI_UBBRVAL(BaudRate);\r
-\r
- UCSR1C = ((1 << UMSEL11) | (1 << UMSEL10) | SPIOptions);\r
- UCSR1B = ((1 << TXEN1) | (1 << RXEN1));\r
-\r
- DDRD |= (1 << 3);\r
- PORTD |= (1 << 2); \r
- }\r
-\r
- /** Turns off the USART driver, disabling and returning used hardware to their default configuration. */\r
- static inline void SerialSPI_Disable(void)\r
- {\r
- UCSR1B = 0;\r
- UCSR1A = 0;\r
- UCSR1C = 0;\r
-\r
- UBRR1 = 0;\r
-\r
- DDRD &= ~(1 << 3);\r
- PORTD &= ~(1 << 2);\r
- }\r
- \r
- /** Sends and receives a byte through the USART SPI interface, blocking until the transfer is complete.\r
- *\r
- * \param[in] DataByte Byte to send through the USART SPI interface.\r
- *\r
- * \return Response byte from the attached SPI device.\r
- */\r
- static inline uint8_t SerialSPI_TransferByte(const uint8_t DataByte)\r
- {\r
- UDR1 = DataByte;\r
- while (!(UCSR1A & (1 << TXC1)));\r
- UCSR1A = (1 << TXC1);\r
- return UDR1;\r
- }\r
-\r
- /** Sends a byte through the USART SPI interface, blocking until the transfer is complete. The response\r
- * byte sent to from the attached SPI device is ignored.\r
- *\r
- * \param[in] DataByte Byte to send through the USART SPI interface.\r
- */\r
- static inline void SerialSPI_SendByte(const uint8_t DataByte)\r
- {\r
- SerialSPI_TransferByte(DataByte);\r
- }\r
-\r
- /** Sends a dummy byte through the USART SPI interface, blocking until the transfer is complete. The response\r
- * byte from the attached SPI device is returned.\r
- *\r
- * \return The response byte from the attached SPI device.\r
- */\r
- static inline uint8_t SerialSPI_ReceiveByte(void)\r
- {\r
- return SerialSPI_TransferByte(0);\r
- }\r
- \r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r