aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers
diff options
context:
space:
mode:
Diffstat (limited to 'LUFA/Drivers')
-rw-r--r--LUFA/Drivers/Board/Dataflash.h6
-rw-r--r--LUFA/Drivers/Board/Temperature.c13
-rw-r--r--LUFA/Drivers/Board/Temperature.h4
-rw-r--r--LUFA/Drivers/Peripheral/ADC.h2
-rw-r--r--LUFA/Drivers/Peripheral/AVR32/SPI.h61
-rw-r--r--LUFA/Drivers/Peripheral/AVR8/ADC.h2
-rw-r--r--LUFA/Drivers/Peripheral/AVR8/SPI.h37
-rw-r--r--LUFA/Drivers/Peripheral/AVR8/TWI.h2
-rw-r--r--LUFA/Drivers/Peripheral/SPI.h4
-rw-r--r--LUFA/Drivers/Peripheral/Serial.h8
-rw-r--r--LUFA/Drivers/Peripheral/SerialStream.h2
-rw-r--r--LUFA/Drivers/Peripheral/TWI.h2
12 files changed, 93 insertions, 50 deletions
diff --git a/LUFA/Drivers/Board/Dataflash.h b/LUFA/Drivers/Board/Dataflash.h
index c0f314a3e..dfd8cd6e9 100644
--- a/LUFA/Drivers/Board/Dataflash.h
+++ b/LUFA/Drivers/Board/Dataflash.h
@@ -127,7 +127,7 @@
static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
static inline uint8_t Dataflash_TransferByte(const uint8_t Byte)
{
- return SPI_TransferByte(Byte);
+ return SPI_Transfer(Byte);
}
/** Sends a byte to the currently selected dataflash IC, and ignores the next byte from the dataflash.
@@ -137,7 +137,7 @@
static inline void Dataflash_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
static inline void Dataflash_SendByte(const uint8_t Byte)
{
- SPI_SendByte(Byte);
+ SPI_Send(Byte);
}
/** Sends a dummy byte to the currently selected dataflash IC, and returns the next byte from the dataflash.
@@ -147,7 +147,7 @@
static inline uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint8_t Dataflash_ReceiveByte(void)
{
- return SPI_ReceiveByte();
+ return SPI_Receive();
}
/* Includes: */
diff --git a/LUFA/Drivers/Board/Temperature.c b/LUFA/Drivers/Board/Temperature.c
index ea12bf766..09d705085 100644
--- a/LUFA/Drivers/Board/Temperature.c
+++ b/LUFA/Drivers/Board/Temperature.c
@@ -47,14 +47,25 @@ int8_t Temperature_GetTemperature(void)
{
uint16_t Temp_ADC = ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | TEMP_ADC_CHANNEL_MASK);
+ #if defined(__AVR32__)
+ if (Temp_ADC > Temperature_Lookup[0])
+ return TEMP_MIN_TEMP;
+
+ for (uint16_t Index = 0; Index < TEMP_TABLE_SIZE; Index++)
+ {
+ if (Temp_ADC > Temperature_Lookup[Index])
+ return (Index + TEMP_TABLE_OFFSET);
+ }
+ #elif defined(__AVR__)
if (Temp_ADC > pgm_read_word(&Temperature_Lookup[0]))
- return TEMP_MIN_TEMP;
+ return TEMP_MIN_TEMP;
for (uint16_t Index = 0; Index < TEMP_TABLE_SIZE; Index++)
{
if (Temp_ADC > pgm_read_word(&Temperature_Lookup[Index]))
return (Index + TEMP_TABLE_OFFSET);
}
+ #endif
return TEMP_MAX_TEMP;
}
diff --git a/LUFA/Drivers/Board/Temperature.h b/LUFA/Drivers/Board/Temperature.h
index 12e6df137..8700839b6 100644
--- a/LUFA/Drivers/Board/Temperature.h
+++ b/LUFA/Drivers/Board/Temperature.h
@@ -54,8 +54,10 @@
/* Includes: */
#if defined(__AVR32__)
+ #include <avr32/io.h>
#include <stdint.h>
- #else
+ #elif defined(__AVR__)
+ #include <avr/io.h>
#include <avr/pgmspace.h>
#endif
diff --git a/LUFA/Drivers/Peripheral/ADC.h b/LUFA/Drivers/Peripheral/ADC.h
index ef708b4ef..533f4d249 100644
--- a/LUFA/Drivers/Peripheral/ADC.h
+++ b/LUFA/Drivers/Peripheral/ADC.h
@@ -58,6 +58,8 @@
#endif
/* Includes: */
+ #include "../../Common/Common.h"
+
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \
defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \
defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \
diff --git a/LUFA/Drivers/Peripheral/AVR32/SPI.h b/LUFA/Drivers/Peripheral/AVR32/SPI.h
index b7484799a..4322eaa91 100644
--- a/LUFA/Drivers/Peripheral/AVR32/SPI.h
+++ b/LUFA/Drivers/Peripheral/AVR32/SPI.h
@@ -82,58 +82,69 @@
/** Initialises the SPI subsystem, ready for transfers. Must be called before calling any other
* SPI routines.
*
+ * \note The individual AVR32 chip select control registers are left at their defaults; it is up to the user
+ * to configure these seperately once the SPI module has been initialized.
+ *
+ * \note The physical GPIO pins for the AVR32's SPI are not altered; it is up to the user to
+ * configure these seperately to connect the SPI module to the desired GPIO pins via the
+ * GPIO MUX registers.
+ *
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the SPI_SPEED_*
* and SPI_MODE_* masks
*/
- static inline void SPI_Init(const uint8_t SPIOptions)
+ static inline void SPI_Init(const uintN_t SPIOptions)
{
- AVR32_SPI.cr = AVR32_SPI_CR_SPIEN_MASK | AVR32_SPI_CR_SWRST_MASK;
+ AVR32_SPI.cr = (AVR32_SPI_CR_SPIEN_MASK | AVR32_SPI_CR_SWRST_MASK);
AVR32_SPI.mr = SPIOptions;
}
-
+
/** Turns off the SPI driver, disabling and returning used hardware to their default configuration. */
static inline void SPI_ShutDown(void)
{
AVR32_SPI.cr = AVR32_SPI_CR_SPIDIS_MASK;
}
- /** Sends and receives a byte through the SPI interface, blocking until the transfer is complete.
+ /** Sends and receives a transfer through the SPI interface, blocking until the transfer is complete.
+ * The width of the data that is transferred is dependant on the settings of the currently selected
+ * peripheral.
*
- * \param[in] Byte Byte to send through the SPI interface
+ * \param[in] Data Data to send through the SPI interface
*
- * \return Response byte from the attached SPI device
+ * \return Response data from the attached SPI device
*/
- static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline uint8_t SPI_TransferByte(const uint8_t Byte)
+ static inline uint16_t SPI_Transfer(const uint16_t Data) ATTR_ALWAYS_INLINE;
+ static inline uint16_t SPI_Transfer(const uint16_t Data)
{
- AVR32_SPI.tdr = Byte;
- // TODO: Wait for receive
+ AVR32_SPI.TDR.td = Data;
+ while (!(AVR32_SPI.SR.tdre));
return AVR32_SPI.rdr;
}
- /** Sends a byte through the SPI interface, blocking until the transfer is complete. The response
- * byte sent to from the attached SPI device is ignored.
+ /** Sends a transfer through the SPI interface, blocking until the transfer is complete. The response
+ * data sent to from the attached SPI device is ignored. The width of the data that is transferred is
+ * dependant on the settings of the currently selected peripheral.
*
- * \param[in] Byte Byte to send through the SPI interface
+ * \param[in] Data Data to send through the SPI interface
*/
- static inline void SPI_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline void SPI_SendByte(const uint8_t Byte)
+ static inline void SPI_Send(const uint16_t Data) ATTR_ALWAYS_INLINE;
+ static inline void SPI_Send(const uint16_t Data)
{
- AVR32_SPI.tdr = Byte;
- // TODO: Wait for receive
+ AVR32_SPI.TDR.td = Data;
+ while (!(AVR32_SPI.SR.tdre));
}
- /** Sends a dummy byte through the SPI interface, blocking until the transfer is complete. The response
- * byte from the attached SPI device is returned.
+ /** Sends a dummy transfer through the SPI interface, blocking until the transfer is complete. The response
+ * data from the attached SPI device is returned. The width of the data that is transferred is dependant on
+ * the settings of the currently selected peripheral.
*
- * \return The response byte from the attached SPI device
+ * \return The response data from the attached SPI device
*/
- static inline uint8_t SPI_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
- static inline uint8_t SPI_ReceiveByte(void)
+ static inline uint16_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
+ static inline uint16_t SPI_Receive(void)
{
- AVR32_SPI.tdr = 0x00;
- // TODO: Wait for receive
- return AVR32_SPI.rdr;
+ AVR32_SPI.TDR.td = 0x0000;
+ while (!(AVR32_SPI.SR.tdre));
+ return AVR32_SPI.RDR.rd;
}
/* Disable C linkage for C++ Compilers: */
diff --git a/LUFA/Drivers/Peripheral/AVR8/ADC.h b/LUFA/Drivers/Peripheral/AVR8/ADC.h
index 06f9d3b28..eac7f9fb5 100644
--- a/LUFA/Drivers/Peripheral/AVR8/ADC.h
+++ b/LUFA/Drivers/Peripheral/AVR8/ADC.h
@@ -51,8 +51,6 @@
#define __ADC_AVR8_H__
/* Includes: */
- #include "../../../Common/Common.h"
-
#include <avr/io.h>
#include <stdbool.h>
diff --git a/LUFA/Drivers/Peripheral/AVR8/SPI.h b/LUFA/Drivers/Peripheral/AVR8/SPI.h
index f466162be..42ff8e7c3 100644
--- a/LUFA/Drivers/Peripheral/AVR8/SPI.h
+++ b/LUFA/Drivers/Peripheral/AVR8/SPI.h
@@ -118,7 +118,7 @@
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the SPI_SPEED_*,
* SPI_SCK_*, SPI_SAMPLE_* and SPI_MODE_* masks
*/
- static inline void SPI_Init(const uint8_t SPIOptions)
+ static inline void SPI_Init(const uintN_t SPIOptions)
{
DDRB |= ((1 << 1) | (1 << 2));
PORTB |= ((1 << 0) | (1 << 3));
@@ -143,14 +143,14 @@
/** Sends and receives a byte through the SPI interface, blocking until the transfer is complete.
*
- * \param[in] Byte Byte to send through the SPI interface
+ * \param[in] Data Byte to send through the SPI interface
*
* \return Response byte from the attached SPI device
*/
- static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline uint8_t SPI_TransferByte(const uint8_t Byte)
+ static inline uint8_t SPI_Transfer(const uint8_t Data) ATTR_ALWAYS_INLINE;
+ static inline uint8_t SPI_Transfer(const uint8_t Data)
{
- SPDR = Byte;
+ SPDR = Data;
while (!(SPSR & (1 << SPIF)));
return SPDR;
}
@@ -158,12 +158,12 @@
/** Sends a byte through the SPI interface, blocking until the transfer is complete. The response
* byte sent to from the attached SPI device is ignored.
*
- * \param[in] Byte Byte to send through the SPI interface
+ * \param[in] Data Byte to send through the SPI interface
*/
- static inline void SPI_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline void SPI_SendByte(const uint8_t Byte)
+ static inline void SPI_Send(const uint8_t Data) ATTR_ALWAYS_INLINE;
+ static inline void SPI_Send(const uint8_t Data)
{
- SPDR = Byte;
+ SPDR = Data;
while (!(SPSR & (1 << SPIF)));
}
@@ -172,13 +172,28 @@
*
* \return The response byte from the attached SPI device
*/
- static inline uint8_t SPI_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
- static inline uint8_t SPI_ReceiveByte(void)
+ static inline uint8_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
+ static inline uint8_t SPI_Receive(void)
{
SPDR = 0x00;
while (!(SPSR & (1 << SPIF)));
return SPDR;
}
+
+ #if defined(__DOXYGEN__)
+ /** Alias for \ref SPI_Transfer(), for compatibility with legacy LUFA applications. */
+ static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_DEPRECATED;
+
+ /** Alias for \ref SPI_Send(), for compatibility with legacy LUFA applications. */
+ static inline void SPI_SendByte(const uint8_t Byte) ATTR_DEPRECATED;
+
+ /** Alias for \ref SPI_Receive(), for compatibility with legacy LUFA applications. */
+ static inline uint8_t SPI_ReceiveByte(void) ATTR_DEPRECATED;
+ #else
+ #define SPI_TransferByte(x) SPI_Transfer(x)
+ #define SPI_SendByte(x) SPI_Send(x)
+ #define SPI_ReceiveByte() SPI_Receive()
+ #endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
diff --git a/LUFA/Drivers/Peripheral/AVR8/TWI.h b/LUFA/Drivers/Peripheral/AVR8/TWI.h
index d169b8230..43f70d9ac 100644
--- a/LUFA/Drivers/Peripheral/AVR8/TWI.h
+++ b/LUFA/Drivers/Peripheral/AVR8/TWI.h
@@ -51,8 +51,6 @@
#define __TWI_AVR8_H__
/* Includes: */
- #include "../../../Common/Common.h"
-
#include <avr/io.h>
#include <stdbool.h>
#include <util/twi.h>
diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h
index aac3d9556..6c4ac287f 100644
--- a/LUFA/Drivers/Peripheral/SPI.h
+++ b/LUFA/Drivers/Peripheral/SPI.h
@@ -59,9 +59,11 @@
#endif
/* Includes: */
+ #include "../../Common/Common.h"
+
#if defined(__AVR32__)
#include "AVR32/SPI.h"
- #else
+ #elif defined(__AVR__)
#include "AVR8/SPI.h"
#endif
diff --git a/LUFA/Drivers/Peripheral/Serial.h b/LUFA/Drivers/Peripheral/Serial.h
index a2e06fa85..838c1fd3c 100644
--- a/LUFA/Drivers/Peripheral/Serial.h
+++ b/LUFA/Drivers/Peripheral/Serial.h
@@ -60,15 +60,15 @@
#endif
/* Includes: */
+ #include "../../Common/Common.h"
+ #include "../Misc/TerminalCodes.h"
+
#if defined(__AVR32__)
#include "AVR32/Serial.h"
- #else
+ #elif defined(__AVR__)
#include "AVR8/Serial.h"
#endif
- #include "../../Common/Common.h"
- #include "../Misc/TerminalCodes.h"
-
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
diff --git a/LUFA/Drivers/Peripheral/SerialStream.h b/LUFA/Drivers/Peripheral/SerialStream.h
index feadd0a0f..e22dc42bb 100644
--- a/LUFA/Drivers/Peripheral/SerialStream.h
+++ b/LUFA/Drivers/Peripheral/SerialStream.h
@@ -57,6 +57,8 @@
#include <avr/io.h>
#include <stdio.h>
+ #include "../../Common/Common.h"
+
#include "Serial.h"
/* Enable C linkage for C++ Compilers: */
diff --git a/LUFA/Drivers/Peripheral/TWI.h b/LUFA/Drivers/Peripheral/TWI.h
index fbb95e464..a3d40879a 100644
--- a/LUFA/Drivers/Peripheral/TWI.h
+++ b/LUFA/Drivers/Peripheral/TWI.h
@@ -57,6 +57,8 @@
#endif
/* Includes: */
+ #include "../../Common/Common.h"
+
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \
defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \
defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \