Add SPI driver aliases for the old function names in the AVR8 driver, so that existing code will still compile against the new version.
#include "Atomic.h"\r
\r
#define PROGMEM const\r
- #else\r
+ #elif defined(__AVR__)\r
#include <avr/io.h>\r
#endif\r
\r
\r
/** Type define for a signed native word-sized chunk of data. */\r
typedef int32_t intN_t;\r
- #else\r
+ #elif defined(__AVR__)\r
/** Type define for an unsigned native word-sized chunk of data. */\r
typedef uint8_t uintN_t;\r
\r
static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;\r
static inline uint8_t Dataflash_TransferByte(const uint8_t Byte)\r
{\r
- return SPI_TransferByte(Byte);\r
+ return SPI_Transfer(Byte);\r
}\r
\r
/** Sends a byte to the currently selected dataflash IC, and ignores the next byte from the dataflash.\r
static inline void Dataflash_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;\r
static inline void Dataflash_SendByte(const uint8_t Byte)\r
{\r
- SPI_SendByte(Byte);\r
+ SPI_Send(Byte);\r
}\r
\r
/** Sends a dummy byte to the currently selected dataflash IC, and returns the next byte from the dataflash.\r
static inline uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;\r
static inline uint8_t Dataflash_ReceiveByte(void)\r
{\r
- return SPI_ReceiveByte();\r
+ return SPI_Receive();\r
}\r
\r
/* Includes: */\r
{\r
uint16_t Temp_ADC = ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | TEMP_ADC_CHANNEL_MASK);\r
\r
+ #if defined(__AVR32__)\r
+ if (Temp_ADC > Temperature_Lookup[0])\r
+ return TEMP_MIN_TEMP; \r
+\r
+ for (uint16_t Index = 0; Index < TEMP_TABLE_SIZE; Index++)\r
+ {\r
+ if (Temp_ADC > Temperature_Lookup[Index])\r
+ return (Index + TEMP_TABLE_OFFSET);\r
+ }\r
+ #elif defined(__AVR__)\r
if (Temp_ADC > pgm_read_word(&Temperature_Lookup[0]))\r
- return TEMP_MIN_TEMP;\r
+ return TEMP_MIN_TEMP; \r
\r
for (uint16_t Index = 0; Index < TEMP_TABLE_SIZE; Index++)\r
{\r
if (Temp_ADC > pgm_read_word(&Temperature_Lookup[Index]))\r
return (Index + TEMP_TABLE_OFFSET);\r
}\r
+ #endif\r
\r
return TEMP_MAX_TEMP;\r
}\r
\r
/* Includes: */\r
#if defined(__AVR32__)\r
+ #include <avr32/io.h>\r
#include <stdint.h>\r
- #else\r
+ #elif defined(__AVR__)\r
+ #include <avr/io.h>\r
#include <avr/pgmspace.h>\r
#endif\r
\r
#endif\r
\r
/* Includes: */\r
+ #include "../../Common/Common.h" \r
+\r
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \\r
defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \\r
defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \\r
/** 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
#define __ADC_AVR8_H__\r
\r
/* Includes: */\r
- #include "../../../Common/Common.h"\r
- \r
#include <avr/io.h>\r
#include <stdbool.h>\r
\r
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the SPI_SPEED_*,\r
* SPI_SCK_*, SPI_SAMPLE_* 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
DDRB |= ((1 << 1) | (1 << 2));\r
PORTB |= ((1 << 0) | (1 << 3));\r
\r
/** Sends and receives a byte through the SPI interface, blocking until the transfer is complete.\r
*\r
- * \param[in] Byte Byte to send through the SPI interface\r
+ * \param[in] Data Byte to send through the SPI interface\r
*\r
* \return Response byte 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 uint8_t SPI_Transfer(const uint8_t Data) ATTR_ALWAYS_INLINE;\r
+ static inline uint8_t SPI_Transfer(const uint8_t Data)\r
{\r
- SPDR = Byte;\r
+ SPDR = Data;\r
while (!(SPSR & (1 << SPIF)));\r
return SPDR;\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
*\r
- * \param[in] Byte Byte to send through the SPI interface\r
+ * \param[in] Data Byte 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 uint8_t Data) ATTR_ALWAYS_INLINE;\r
+ static inline void SPI_Send(const uint8_t Data)\r
{\r
- SPDR = Byte;\r
+ SPDR = Data;\r
while (!(SPSR & (1 << SPIF)));\r
}\r
\r
*\r
* \return The response byte 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 uint8_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;\r
+ static inline uint8_t SPI_Receive(void)\r
{\r
SPDR = 0x00;\r
while (!(SPSR & (1 << SPIF)));\r
return SPDR;\r
}\r
+ \r
+ #if defined(__DOXYGEN__)\r
+ /** Alias for \ref SPI_Transfer(), for compatibility with legacy LUFA applications. */\r
+ static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_DEPRECATED;\r
+\r
+ /** Alias for \ref SPI_Send(), for compatibility with legacy LUFA applications. */\r
+ static inline void SPI_SendByte(const uint8_t Byte) ATTR_DEPRECATED;\r
+\r
+ /** Alias for \ref SPI_Receive(), for compatibility with legacy LUFA applications. */\r
+ static inline uint8_t SPI_ReceiveByte(void) ATTR_DEPRECATED;\r
+ #else\r
+ #define SPI_TransferByte(x) SPI_Transfer(x)\r
+ #define SPI_SendByte(x) SPI_Send(x)\r
+ #define SPI_ReceiveByte() SPI_Receive()\r
+ #endif\r
\r
/* Disable C linkage for C++ Compilers: */\r
#if defined(__cplusplus)\r
#define __TWI_AVR8_H__\r
\r
/* Includes: */\r
- #include "../../../Common/Common.h"\r
- \r
#include <avr/io.h>\r
#include <stdbool.h>\r
#include <util/twi.h>\r
#endif\r
\r
/* Includes: */\r
+ #include "../../Common/Common.h" \r
+\r
#if defined(__AVR32__)\r
#include "AVR32/SPI.h"\r
- #else\r
+ #elif defined(__AVR__)\r
#include "AVR8/SPI.h" \r
#endif\r
\r
#endif\r
\r
/* Includes: */\r
+ #include "../../Common/Common.h" \r
+ #include "../Misc/TerminalCodes.h"\r
+\r
#if defined(__AVR32__)\r
#include "AVR32/Serial.h"\r
- #else\r
+ #elif defined(__AVR__)\r
#include "AVR8/Serial.h" \r
#endif\r
\r
- #include "../../Common/Common.h"\r
- #include "../Misc/TerminalCodes.h"\r
-\r
/* Enable C linkage for C++ Compilers: */\r
#if defined(__cplusplus)\r
extern "C" {\r
#include <avr/io.h>\r
#include <stdio.h>\r
\r
+ #include "../../Common/Common.h" \r
+\r
#include "Serial.h"\r
\r
/* Enable C linkage for C++ Compilers: */\r
#endif\r
\r
/* Includes: */\r
+ #include "../../Common/Common.h" \r
+\r
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \\r
defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \\r
defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \\r
* - Joystick Board Driver\r
* - Buttons Board Driver\r
* - LEDs Board Driver\r
+ * - Simple Scheduler\r
+ * - Temperature Board Driver\r
*\r
* The following drivers have been partially ported:\r
* - SPI Peripheral Driver\r
*\r
* The following drivers have not yet been ported:\r
* - Dataflash Board Driver\r
- * - Temperature Board Driver\r
* - Serial Peripheral Driver\r
* - ADC Peripheral Driver\r
* - TWI Peripheral Driver\r
* \section Sec_MigrationXXXXXX Migrating from 100219 to XXXXXX\r
*\r
* \section Sec_Migration100219 Migrating from 091223 to 100219\r
- * - (None)\r
+ * <b>Non-USB Library Components</b>\r
+ * - The "Byte" suffix on the SPI peripheral driver's send and receive routines has been dropped, to make the interface consistant\r
+ * between the AVR8 driver and the new AVR32 driver, which supports variable width transfers.\r
*\r
* <b>Non-USB Library Components</b>\r
* - Due to some ADC channels not being identical to their ADC MUX selection masks for single-ended conversions on some AVR models,\r
* {\r
* { .Task = MyTask1, .TaskStatus = TASK_RUN, .GroupID = 1 },\r
* { .Task = MyTask2, .TaskStatus = TASK_RUN, .GroupID = 1 },\r
- * }\r
+ * };\r
*\r
* int main(void)\r
* {\r
#if defined(__AVR32__)\r
#include <avr32/io.h>\r
#include <stdbool.h>\r
- #else\r
+ #elif defined(__AVR__)\r
#include <avr/io.h>\r
#include <util/atomic.h>\r
#include <stdbool.h>\r
for (uint8_t RByte = 0; RByte < sizeof(ResponseBytes); RByte++)\r
{\r
ISPProtocol_DelayMS(Enter_ISP_Params.ByteDelay);\r
- ResponseBytes[RByte] = SPI_TransferByte(Enter_ISP_Params.EnterProgBytes[RByte]);\r
+ ResponseBytes[RByte] = SPI_Transfer(Enter_ISP_Params.EnterProgBytes[RByte]);\r
}\r
\r
/* Check if polling disabled, or if the polled value matches the expected value */\r
bool IsOddByte = (CurrentByte & 0x01);\r
uint8_t ByteToWrite = *(NextWriteByte++);\r
\r
- SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
- SPI_SendByte(CurrentAddress >> 8);\r
- SPI_SendByte(CurrentAddress & 0xFF);\r
- SPI_SendByte(ByteToWrite);\r
+ SPI_Send(Write_Memory_Params.ProgrammingCommands[0]);\r
+ SPI_Send(CurrentAddress >> 8);\r
+ SPI_Send(CurrentAddress & 0xFF);\r
+ SPI_Send(ByteToWrite);\r
\r
/* AVR FLASH addressing requires us to modify the write command based on if we are writing a high\r
* or low byte at the current word address */\r
/* If the current page must be committed, send the PROGRAM PAGE command to the target */\r
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_COMMIT_PAGE_MASK)\r
{\r
- SPI_SendByte(Write_Memory_Params.ProgrammingCommands[1]);\r
- SPI_SendByte(StartAddress >> 8);\r
- SPI_SendByte(StartAddress & 0xFF);\r
- SPI_SendByte(0x00);\r
+ SPI_Send(Write_Memory_Params.ProgrammingCommands[1]);\r
+ SPI_Send(StartAddress >> 8);\r
+ SPI_Send(StartAddress & 0xFF);\r
+ SPI_Send(0x00);\r
\r
/* Check if polling is possible, if not switch to timed delay mode */\r
if (!(PollAddress))\r
bool IsOddByte = (CurrentByte & 0x01);\r
uint8_t ByteToWrite = *(NextWriteByte++);\r
\r
- SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
- SPI_SendByte(CurrentAddress >> 8);\r
- SPI_SendByte(CurrentAddress & 0xFF);\r
- SPI_SendByte(ByteToWrite);\r
+ SPI_Send(Write_Memory_Params.ProgrammingCommands[0]);\r
+ SPI_Send(CurrentAddress >> 8);\r
+ SPI_Send(CurrentAddress & 0xFF);\r
+ SPI_Send(ByteToWrite);\r
\r
/* AVR FLASH addressing requires us to modify the write command based on if we are writing a high\r
* or low byte at the current word address */\r
for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++)\r
{\r
/* Read the next byte from the desired memory space in the device */\r
- SPI_SendByte(Read_Memory_Params.ReadMemoryCommand);\r
- SPI_SendByte(CurrentAddress >> 8);\r
- SPI_SendByte(CurrentAddress & 0xFF);\r
- Endpoint_Write_Byte(SPI_ReceiveByte());\r
+ SPI_Send(Read_Memory_Params.ReadMemoryCommand);\r
+ SPI_Send(CurrentAddress >> 8);\r
+ SPI_Send(CurrentAddress & 0xFF);\r
+ Endpoint_Write_Byte(SPI_Receive());\r
\r
/* Check if the endpoint bank is currently full, if so send the packet */\r
if (!(Endpoint_IsReadWriteAllowed()))\r
\r
/* Send the chip erase commands as given by the host to the device */\r
for (uint8_t SByte = 0; SByte < sizeof(Erase_Chip_Params.EraseCommandBytes); SByte++)\r
- SPI_SendByte(Erase_Chip_Params.EraseCommandBytes[SByte]);\r
+ SPI_Send(Erase_Chip_Params.EraseCommandBytes[SByte]);\r
\r
/* Use appropriate command completion check as given by the host (delay or busy polling) */\r
if (!(Erase_Chip_Params.PollMethod))\r
\r
/* Send the Fuse or Lock byte read commands as given by the host to the device, store response */\r
for (uint8_t RByte = 0; RByte < sizeof(ResponseBytes); RByte++)\r
- ResponseBytes[RByte] = SPI_TransferByte(Read_FuseLockSigOSCCAL_Params.ReadCommandBytes[RByte]);\r
+ ResponseBytes[RByte] = SPI_Transfer(Read_FuseLockSigOSCCAL_Params.ReadCommandBytes[RByte]);\r
\r
Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
\r
/* Send the Fuse or Lock byte program commands as given by the host to the device */\r
for (uint8_t SByte = 0; SByte < sizeof(Write_FuseLockSig_Params.WriteCommandBytes); SByte++)\r
- SPI_SendByte(Write_FuseLockSig_Params.WriteCommandBytes[SByte]);\r
+ SPI_Send(Write_FuseLockSig_Params.WriteCommandBytes[SByte]);\r
\r
Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
while (CurrTxPos < SPI_Multi_Params.RxStartAddr)\r
{\r
if (CurrTxPos < SPI_Multi_Params.TxBytes)\r
- SPI_SendByte(SPI_Multi_Params.TxData[CurrTxPos]);\r
+ SPI_Send(SPI_Multi_Params.TxData[CurrTxPos]);\r
else\r
- SPI_SendByte(0);\r
+ SPI_Send(0);\r
\r
CurrTxPos++;\r
}\r
while (CurrRxPos < SPI_Multi_Params.RxBytes)\r
{\r
if (CurrTxPos < SPI_Multi_Params.TxBytes)\r
- Endpoint_Write_Byte(SPI_TransferByte(SPI_Multi_Params.TxData[CurrTxPos++]));\r
+ Endpoint_Write_Byte(SPI_Transfer(SPI_Multi_Params.TxData[CurrTxPos++]));\r
else\r
- Endpoint_Write_Byte(SPI_ReceiveByte());\r
+ Endpoint_Write_Byte(SPI_Receive());\r
\r
/* Check to see if we have filled the endpoint bank and need to send the packet */\r
if (!(Endpoint_IsReadWriteAllowed()))\r
TimeoutMSRemaining--;\r
}\r
\r
- SPI_SendByte(ReadMemCommand);\r
- SPI_SendByte(PollAddress >> 8);\r
- SPI_SendByte(PollAddress & 0xFF);\r
+ SPI_Send(ReadMemCommand);\r
+ SPI_Send(PollAddress >> 8);\r
+ SPI_Send(PollAddress & 0xFF);\r
}\r
- while ((SPI_TransferByte(0x00) == PollValue) && TimeoutMSRemaining);\r
+ while ((SPI_Transfer(0x00) == PollValue) && TimeoutMSRemaining);\r
\r
if (!(TimeoutMSRemaining))\r
ProgrammingStatus = STATUS_CMD_TOUT;\r
TimeoutMSRemaining--;\r
} \r
\r
- SPI_SendByte(0xF0);\r
- SPI_SendByte(0x00);\r
- SPI_SendByte(0x00);\r
+ SPI_Send(0xF0);\r
+ SPI_Send(0x00);\r
+ SPI_Send(0x00);\r
}\r
- while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);\r
+ while ((SPI_Receive() & 0x01) && TimeoutMSRemaining);\r
\r
if (TimeoutMSRemaining)\r
{\r
*/\r
void ISPTarget_LoadExtendedAddress(void)\r
{\r
- SPI_SendByte(LOAD_EXTENDED_ADDRESS_CMD);\r
- SPI_SendByte(0x00);\r
- SPI_SendByte((CurrentAddress & 0x00FF0000) >> 16);\r
- SPI_SendByte(0x00); \r
+ SPI_Send(LOAD_EXTENDED_ADDRESS_CMD);\r
+ SPI_Send(0x00);\r
+ SPI_Send((CurrentAddress & 0x00FF0000) >> 16);\r
+ SPI_Send(0x00); \r
}\r
\r
#endif\r