Rename Drivers/AT90USBXXX to Drivers/Peripheral.
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 17 Apr 2009 00:12:31 +0000 (00:12 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 17 Apr 2009 00:12:31 +0000 (00:12 +0000)
14 files changed:
LUFA/Drivers/AT90USBXXX/ADC.h [deleted file]
LUFA/Drivers/AT90USBXXX/AT90USBXXX67/ADC.h [deleted file]
LUFA/Drivers/AT90USBXXX/SPI.h [deleted file]
LUFA/Drivers/AT90USBXXX/Serial.c [deleted file]
LUFA/Drivers/AT90USBXXX/Serial.h [deleted file]
LUFA/Drivers/AT90USBXXX/Serial_Stream.c [deleted file]
LUFA/Drivers/AT90USBXXX/Serial_Stream.h [deleted file]
LUFA/Drivers/Peripheral/ADC.h [new file with mode: 0644]
LUFA/Drivers/Peripheral/AT90USBXXX67/ADC.h [new file with mode: 0644]
LUFA/Drivers/Peripheral/SPI.h [new file with mode: 0644]
LUFA/Drivers/Peripheral/Serial.c [new file with mode: 0644]
LUFA/Drivers/Peripheral/Serial.h [new file with mode: 0644]
LUFA/Drivers/Peripheral/Serial_Stream.c [new file with mode: 0644]
LUFA/Drivers/Peripheral/Serial_Stream.h [new file with mode: 0644]

diff --git a/LUFA/Drivers/AT90USBXXX/ADC.h b/LUFA/Drivers/AT90USBXXX/ADC.h
deleted file mode 100644 (file)
index 02d2d08..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  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
- *\r
- *  This file is the master dispatch header file for the device-specific ADC driver, for AVRs containing an ADC.\r
- *\r
- *  User code should include this file, which will in turn include the correct ADC driver header file for the\r
- *  currently selected AVR model.\r
- */\r
-\r
-/** \ingroup Group_SubsystemDrivers\r
- *  @defgroup Group_ADC ADC Driver - LUFA/Drivers/Peripheral/ADC.h\r
- */\r
\r
-#ifndef __ADC_H__\r
-#define __ADC_H__\r
-\r
-       /* Macros: */\r
-       #if !defined(__DOXYGEN__)\r
-               #define INCLUDE_FROM_ADC_H\r
-               #define INCLUDE_FROM_CHIP_DRIVER\r
-       #endif\r
-\r
-       /* Includes: */\r
-               #if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \\r
-                    defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \\r
-                        defined(__AVR_ATmega16U4__)  || defined(__AVR_ATmega32U4__) || \\r
-                        defined(__AVR_ATmega32U6__))\r
-                       #include "AT90USBXXX67/ADC.h"\r
-               #else\r
-                       #error "ADC is not available for the currently selected AVR model."\r
-               #endif\r
-\r
-       /* Public Interface - May be used in end-application: */\r
-               /* Inline Functions: */\r
-                       /** Starts the reading of the given channel, but does not wait until the conversion has completed.\r
-                        *  Once executed, the conversion status can be determined via the ADC_IsReadingComplete() macro and\r
-                        *  the result read via the ADC_GetResult() macro.\r
-                        *\r
-                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
-                        */\r
-                       static inline void ADC_StartReading(const uint8_t MUXMask);\r
-\r
-                       /** Performs a complete single reading from channel, including a polling spinloop to wait for the\r
-                        *  conversion to complete, and the returning of the converted value.\r
-                        *\r
-                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
-                        */\r
-                       static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) ATTR_WARN_UNUSED_RESULT;\r
-\r
-                       /** Configures the given ADC channel, ready for ADC conversions. This function sets the\r
-                        *  associated port pin as an input and disables the digital portion of the I/O to reduce\r
-                        *  power consumption.\r
-                        *\r
-                        *  \param Channel  ADC channel number to set up for conversions\r
-                        */\r
-                       static inline void ADC_SetupChannel(const uint8_t Channel);\r
-                       \r
-#endif\r
diff --git a/LUFA/Drivers/AT90USBXXX/AT90USBXXX67/ADC.h b/LUFA/Drivers/AT90USBXXX/AT90USBXXX67/ADC.h
deleted file mode 100644 (file)
index a5bf037..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  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
- *\r
- *  ADC driver for the AT90USB1287, AT90USB1286, AT90USB647, AT90USB646, ATMEGA16U4 and ATMEGA32U4 AVRs.\r
- *\r
- *  \note This file should not be included directly. It is automatically included as needed by the ADC driver\r
- *        dispatch header located in LUFA/Drivers/Peripheral/ADC.h.\r
- */\r
-\r
-/** \ingroup Group_ADC\r
- *  @defgroup Group_ADC_AT90USBXXX67 AT90USBXXX6 and AT90USBXXX7 Models\r
- *\r
- *  @{\r
- */\r
\r
-#ifndef __ADC_AT90USBXXX67_H__\r
-#define __ADC_AT90USBXXX67_H__\r
-\r
-       /* Includes: */\r
-               #include "../../../Common/Common.h"\r
-               \r
-               #include <avr/io.h>\r
-               #include <stdbool.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_ADC_H)\r
-                       #error Do not include this file directly. Include LUFA/Drivers/Peripheral/ADC.h instead.\r
-               #endif\r
-\r
-       /* Public Interface - May be used in end-application: */\r
-               /* Macros: */\r
-                       /** Initializes the ADC, ready for conversions. This must be called before any other ADC operations.\r
-                        *  The "mode" parameter should be a mask comprised of a conversion mode (free running or single) and\r
-                        *  prescaler masks.\r
-                        */\r
-                       #define  ADC_Init(mode)          MACROS{ ADCSRA = ((1 << ADEN) | mode);         }MACROE\r
-\r
-                       /** Turns off the ADC. If this is called, any further ADC operations will require a call to the\r
-                        *  ADC_Init() macro before the ADC can be used again.\r
-                        */\r
-                       #define  ADC_Off()               MACROS{ ADCSRA = 0;                            }MACROE\r
-                       \r
-                       /** Indicates if the ADC is enabled. This macro will return boolean true if the ADC subsystem is\r
-                        *  currently enabled, or false otherwise.\r
-                        */\r
-                       #define  ADC_GetStatus()               ((ADCSRA & (1 << ADEN)) ? true : false)\r
-\r
-                       /** Indicates if the current ADC conversion is completed, or still in progress. This returns boolean\r
-                        *  false if the reading is still taking place, or true if the conversion is complete and ready to be\r
-                        *  read out with ADC_GetResult().\r
-                        */\r
-                       #define  ADC_IsReadingComplete()         (!(ADCSRA & (1 << ADSC)))\r
-                       \r
-                       /** Returns the result of the last conversion, as a 16-bit wide integer. */\r
-                       #define  ADC_GetResult()                 ADC\r
-                       \r
-                       /** Reference mask, for using the voltage present at the AVR's AREF pin for the ADC reference. */\r
-                       #define  ADC_REFERENCE_AREF              0\r
-\r
-                       /** Reference mask, for using the voltage present at the AVR's AVCC pin for the ADC reference. */\r
-                       #define  ADC_REFERENCE_AVCC              (1 << REFS0)\r
-\r
-                       /** Reference mask, for using the internally generated 2.56V reference voltage as the ADC reference. */\r
-                       #define  ADC_REFERENCE_INT2560MV         ((1 << REFS1)| (1 << REFS0))\r
-                       \r
-                       /** Left-adjusts the 10-bit ADC result, so that the upper 8 bits of the value returned by the\r
-                        *  ADC_GetResult() macro contain the 8 most significant bits of the result. */\r
-                       #define  ADC_LEFT_ADJUSTED               (1 << ADLAR)\r
-\r
-                       /** Right-adjusts the 10-bit ADC result, so that the lower 8 bits of the value returned by the\r
-                        *  ADC_GetResult() macro contain the 8 least significant bits of the result. */\r
-                       #define  ADC_RIGHT_ADJUSTED              (0 << ADLAR)\r
-                       \r
-                       /** Sets the ADC mode to free running, so that conversions take place continuously as fast as the ADC\r
-                        *  is capable of at the given input clock speed. */\r
-                       #define  ADC_FREE_RUNNING                (1 << ADATE)\r
-\r
-                       /** Sets the ADC mode to single conversion, so that only a single conversion will take place before\r
-                        *  the ADC returns to idle. */\r
-                       #define  ADC_SINGLE_CONVERSION           (0 << ADATE)\r
-                       \r
-                       /** Sets the ADC input clock to prescale by a factor of 2 the AVR's system clock. */\r
-                       #define  ADC_PRESCALE_2                  (1 << ADPS0)\r
-\r
-                       /** Sets the ADC input clock to prescale by a factor of 4 the AVR's system clock. */\r
-                       #define  ADC_PRESCALE_4                  (1 << ADPS1)\r
-\r
-                       /** Sets the ADC input clock to prescale by a factor of 8 the AVR's system clock. */\r
-                       #define  ADC_PRESCALE_8                  ((1 << ADPS0) | (1 << ADPS1))\r
-\r
-                       /** Sets the ADC input clock to prescale by a factor of 16 the AVR's system clock. */\r
-                       #define  ADC_PRESCALE_16                 (1 << ADPS2)\r
-\r
-                       /** Sets the ADC input clock to prescale by a factor of 32 the AVR's system clock. */\r
-                       #define  ADC_PRESCALE_32                 ((1 << ADPS2) | (1 << ADPS0))\r
-\r
-                       /** Sets the ADC input clock to prescale by a factor of 64 the AVR's system clock. */\r
-                       #define  ADC_PRESCALE_64                 ((1 << ADPS2) | (1 << ADPS1))\r
-\r
-                       /** Sets the ADC input clock to prescale by a factor of 128 the AVR's system clock. */\r
-                       #define  ADC_PRESCALE_128                ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))\r
-\r
-               /* Inline Functions: */\r
-                       /** Configures the given ADC channel, ready for ADC conversions. This function sets the\r
-                        *  associated port pin as an input and disables the digital portion of the I/O to reduce\r
-                        *  power consumption.\r
-                        *\r
-                        *  \param Channel  ADC channel number to set up for conversions\r
-                        */\r
-                       static inline void ADC_SetupChannel(const uint8_t Channel)\r
-                       {\r
-                               DDRF  &= ~(1 << Channel);\r
-                               DIDR0 |=  (1 << Channel);\r
-                       }\r
-                       \r
-                       /** Starts the reading of the given channel, but does not wait until the conversion has completed.\r
-                        *  Once executed, the conversion status can be determined via the ADC_IsReadingComplete() macro and\r
-                        *  the result read via the ADC_GetResult() macro.\r
-                        *\r
-                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
-                        */\r
-                       static inline void ADC_StartReading(const uint8_t MUXMask)\r
-                       {\r
-                               ADMUX = MUXMask;\r
-                       \r
-                               ADCSRA |= (1 << ADSC);\r
-                       }\r
-\r
-                       /** Performs a complete single reading from channel, including a polling spinloop to wait for the\r
-                        *  conversion to complete, and the returning of the converted value.\r
-                        *\r
-                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
-                        */\r
-                       static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) ATTR_WARN_UNUSED_RESULT;\r
-                       static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask)\r
-                       {\r
-                               ADC_StartReading(MUXMask);\r
-       \r
-                               while (!(ADC_IsReadingComplete()));\r
-       \r
-                               return ADC_GetResult();\r
-                       }\r
-\r
-       /* Disable C linkage for C++ Compilers: */\r
-               #if defined(__cplusplus)\r
-                       }\r
-               #endif\r
-               \r
-#endif\r
-\r
-/** @} */\r
diff --git a/LUFA/Drivers/AT90USBXXX/SPI.h b/LUFA/Drivers/AT90USBXXX/SPI.h
deleted file mode 100644 (file)
index 4ada793..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  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
- *\r
- *  Hardware SPI subsystem driver for the supported USB AVRs models.\r
- */\r
-\r
-/** \ingroup Group_SubsystemDrivers\r
- *  @defgroup Group_SPI SPI Driver - LUFA/Drivers/Peripheral/SPI.h\r
- *\r
- *  Functions, macros, variables, enums and types related to the setup of a the SPI port.\r
- *\r
- *  @{\r
- */\r
-\r
-#ifndef __SPI_H__\r
-#define __SPI_H__\r
-\r
-       /* Includes: */\r
-               #include <stdbool.h>\r
-\r
-       /* Enable C linkage for C++ Compilers: */\r
-               #if defined(__cplusplus)\r
-                       extern "C" {\r
-               #endif\r
-\r
-       /* Private Interface - For use in library only: */\r
-       #if !defined(__DOXYGEN__)\r
-               /* Macros: */\r
-                       #define SPI_USE_DOUBLESPEED            (1 << 7)\r
-       #endif\r
-       \r
-       /* Public Interface - May be used in end-application: */\r
-               /* Macros: */\r
-                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 2. */\r
-                       #define SPI_SPEED_FCPU_DIV_2           SPI_USE_DOUBLESPEED\r
-\r
-                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 4. */\r
-                       #define SPI_SPEED_FCPU_DIV_4           0\r
-\r
-                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 8. */\r
-                       #define SPI_SPEED_FCPU_DIV_8           (SPI_USE_DOUBLESPEED | (1 << SPR0))\r
-\r
-                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 16. */\r
-                       #define SPI_SPEED_FCPU_DIV_16          (1 << SPR0)\r
-\r
-                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */\r
-                       #define SPI_SPEED_FCPU_DIV_32          (SPI_USE_DOUBLESPEED | (1 << SPR1))\r
-\r
-                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 64. */\r
-                       #define SPI_SPEED_FCPU_DIV_64          (SPI_USE_DOUBLESPEED | (1 << SPR1) | (1 << SPR0))\r
-\r
-                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 128. */\r
-                       #define SPI_SPEED_FCPU_DIV_128         ((1 << SPR1) | (1 << SPR0))\r
-\r
-               /* Inline Functions: */\r
-                       /** Initializes the SPI subsystem, ready for transfers. Must be called before calling any other\r
-                        *  SPI routines.\r
-                        *\r
-                        *  \param PrescalerMask  Prescaler mask to set the SPI clock speed\r
-                        *  \param Master         If true, sets the SPI system to use master mode, slave if false\r
-                        */\r
-                       static inline void SPI_Init(const uint8_t PrescalerMask, const bool Master)\r
-                       {\r
-                               DDRB  |= ((1 << 1) | (1 << 2));\r
-                               PORTB |= ((1 << 0) | (1 << 3));\r
-                               \r
-                               SPCR   = ((1 << SPE) | (Master << MSTR) | (1 << CPOL) | (1 << CPHA) |\r
-                                         (PrescalerMask & ~SPI_USE_DOUBLESPEED));\r
-                               \r
-                               if (PrescalerMask & SPI_USE_DOUBLESPEED)\r
-                                 SPSR = (1 << SPI2X);\r
-                       }\r
-                       \r
-                       /** Sends and receives a byte through the SPI interface, blocking until the transfer is complete.\r
-                        *\r
-                        *  \param Byte  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
-                       {\r
-                               SPDR = Byte;\r
-                               while (!(SPSR & (1 << SPIF)));\r
-                               return SPDR;\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
-                        *\r
-                        *  \param Byte 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
-                       {\r
-                               SPDR = Byte;\r
-                               while (!(SPSR & (1 << SPIF)));\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
-                        *\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
-                       {\r
-                               SPDR = 0x00;\r
-                               while (!(SPSR & (1 << SPIF)));\r
-                               return SPDR;\r
-                       }\r
-\r
-       /* Disable C linkage for C++ Compilers: */\r
-               #if defined(__cplusplus)\r
-                       }\r
-               #endif\r
-               \r
-#endif\r
-\r
-/** @} */\r
diff --git a/LUFA/Drivers/AT90USBXXX/Serial.c b/LUFA/Drivers/AT90USBXXX/Serial.c
deleted file mode 100644 (file)
index e1c7449..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  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
-#include "Serial.h"\r
-\r
-void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed)\r
-{\r
-       UCSR1A = ((DoubleSpeed) ? (1 << U2X1) : 0);\r
-       UCSR1B = ((1 << RXEN1)  | (1 << TXEN1));\r
-       UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10));\r
-       \r
-       DDRD  |= (1 << 3);      \r
-       PORTD |= (1 << 2);\r
-       \r
-       UBRR1  = SERIAL_UBBRVAL(BaudRate);\r
-}\r
-\r
-void Serial_TxString_P(const char *FlashStringPtr)\r
-{\r
-       uint8_t CurrByte;\r
-\r
-       while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00)\r
-       {\r
-               Serial_TxByte(CurrByte);\r
-               FlashStringPtr++;\r
-       }\r
-}\r
-\r
-void Serial_TxString(const char *StringPtr)\r
-{\r
-       uint8_t CurrByte;\r
-\r
-       while ((CurrByte = *StringPtr) != 0x00)\r
-       {\r
-               Serial_TxByte(CurrByte);\r
-               StringPtr++;\r
-       }\r
-}\r
diff --git a/LUFA/Drivers/AT90USBXXX/Serial.h b/LUFA/Drivers/AT90USBXXX/Serial.h
deleted file mode 100644 (file)
index d83761f..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  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
- *\r
- *  Driver for the USART subsystem on supported USB AVRs.\r
- */\r
\r
-/** \ingroup Group_SubsystemDrivers\r
- *  @defgroup Group_Serial Serial USART Driver - LUFA/Drivers/Peripheral/Serial.h\r
- *\r
- *  Functions, macros, variables, enums and types related to the setup of the USART for serial communications.\r
- *\r
- *  @{\r
- */\r
\r
-#ifndef __SERIAL_H__\r
-#define __SERIAL_H__\r
-\r
-       /* Includes: */\r
-               #include <avr/io.h>\r
-               #include <avr/pgmspace.h>\r
-               #include <stdbool.h>\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
-               #endif\r
-\r
-       /* Public Interface - May be used in end-application: */\r
-               /* Macros: */   \r
-                       /** Indicates whether a character has been received through the USART - boolean false if no character\r
-                        *  has been received, or non-zero if a character is waiting to be read from the reception buffer.\r
-                        */\r
-                       #define Serial_IsCharReceived() ((UCSR1A & (1 << RXC1)) ? true : false)\r
-\r
-                       /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is\r
-                        *  not set.\r
-                        */\r
-                       #define SERIAL_UBBRVAL(baud)    (((F_CPU / 16) / baud) - 1)\r
-\r
-                       /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is\r
-                        *  set.\r
-                        */\r
-                       #define SERIAL_2X_UBBRVAL(baud) (((F_CPU / 8) / baud) - 1)\r
-\r
-               /* Function Prototypes: */\r
-                       /** Initializes the USART, ready for serial data transmission and reception.\r
-                        *\r
-                        *  \param BaudRate     Baud rate to configure the USART to\r
-                        *  \param DoubleSpeed  Enables double speed mode when set, halving the sample time to double the baud rate\r
-                        */\r
-                       void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed);\r
-\r
-                       /** Transmits a given string located in program space (FLASH) through the USART.\r
-                        *\r
-                        *  \param FlashStringPtr  Pointer to a string located in program space\r
-                        */\r
-                       void Serial_TxString_P(const char *FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
-                       /** Transmits a given string located in SRAM memory through the USART.\r
-                        *\r
-                        *  \param StringPtr  Pointer to a string located in SRAM space\r
-                        */\r
-                       void Serial_TxString(const char *StringPtr) ATTR_NON_NULL_PTR_ARG(1);\r
-\r
-               /* Inline Functions: */\r
-                       /** Transmits a given byte through the USART.\r
-                        *\r
-                        *  \param DataByte  Byte to transmit through the USART\r
-                        */\r
-                       static inline void Serial_TxByte(const char DataByte)\r
-                       {\r
-                               while (!(UCSR1A & (1 << UDRE1)));\r
-                               UDR1 = DataByte;\r
-                       }\r
-\r
-                       /** Receives a byte from the USART.\r
-                        *\r
-                        *  \return Byte received from the USART\r
-                        */\r
-                       static inline char Serial_RxByte(void)\r
-                       {\r
-                               while (!(UCSR1A & (1 << RXC1)));\r
-                               return UDR1; \r
-                       }\r
-\r
-       /* Disable C linkage for C++ Compilers: */\r
-               #if defined(__cplusplus)\r
-                       }\r
-               #endif\r
-               \r
-#endif\r
-\r
-/** @} */\r
diff --git a/LUFA/Drivers/AT90USBXXX/Serial_Stream.c b/LUFA/Drivers/AT90USBXXX/Serial_Stream.c
deleted file mode 100644 (file)
index d986af4..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  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
-#include "Serial_Stream.h"\r
-\r
-FILE USARTStream = FDEV_SETUP_STREAM(SerialStream_TxByte, SerialStream_RxByte, _FDEV_SETUP_RW);\r
-\r
-int SerialStream_TxByte(char DataByte, FILE *Stream)\r
-{\r
-       Serial_TxByte(DataByte);\r
-\r
-       return 0;\r
-}\r
-\r
-int SerialStream_RxByte(FILE *Stream)\r
-{\r
-       return Serial_RxByte();\r
-}\r
diff --git a/LUFA/Drivers/AT90USBXXX/Serial_Stream.h b/LUFA/Drivers/AT90USBXXX/Serial_Stream.h
deleted file mode 100644 (file)
index 406cbed..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  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
- *\r
- *  Serial stream driver for the USART subsystem on supported USB AVRs. This makes use of the functions in the\r
- *  regular USART driver, but allows the avr-libc standard stream functions (printf, puts, etc.) to work with the\r
- *  USART.\r
- **/\r
-\r
-/** \ingroup Group_SubsystemDrivers\r
- *  @defgroup Group_SerialStream Serial Stream Driver - LUFA/Drivers/Peripheral/Serial_Stream.h\r
- *\r
- *  Functions, macros, variables, enums and types related to the setup of a serial stream, so that standard printf and other\r
- *  C stream functions can be used on the serial port.\r
- *\r
- *  @{\r
- */\r
-\r
-#ifndef __SERIAL_STREAM_H__\r
-#define __SERIAL_STREAM_H__\r
-\r
-       /* Includes: */\r
-               #include <avr/io.h>\r
-               #include <stdio.h>\r
-               \r
-               #include "Serial.h"\r
-       \r
-       /* Enable C linkage for C++ Compilers: */\r
-               #if defined(__cplusplus)\r
-                       extern "C" {\r
-               #endif\r
-\r
-       /* Private Interface - For use in library only: */      \r
-       #if !defined(__DOXYGEN__)\r
-               /* External Variables: */\r
-                       extern FILE USARTStream;\r
-\r
-               /* Function Prototypes: */\r
-                       int SerialStream_TxByte(char DataByte, FILE *Stream) ATTR_NON_NULL_PTR_ARG(2);\r
-                       int SerialStream_RxByte(FILE *Stream) ATTR_NON_NULL_PTR_ARG(1);\r
-       #endif\r
-\r
-       /* Public Interface - May be used in end-application: */\r
-               /* Inline Functions: */\r
-                       /** Initializes the serial stream (and regular USART driver) so that both the stream and regular\r
-                        *  USART driver functions can be used. Must be called before any stream or regular USART functions.\r
-                        *\r
-                        *  \param BaudRate     Baud rate to configure the USART to\r
-                        *  \param DoubleSpeed  Enables double speed mode when set, halving the sample time to double the baud rate\r
-                        */\r
-                       static inline void SerialStream_Init(const uint32_t BaudRate, const bool DoubleSpeed)\r
-                       {\r
-                               Serial_Init(BaudRate, DoubleSpeed);\r
-                               \r
-                               stdout = &USARTStream;\r
-                       }\r
-\r
-       /* Disable C linkage for C++ Compilers: */\r
-               #if defined(__cplusplus)\r
-                       }\r
-               #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
diff --git a/LUFA/Drivers/Peripheral/ADC.h b/LUFA/Drivers/Peripheral/ADC.h
new file mode 100644 (file)
index 0000000..02d2d08
--- /dev/null
@@ -0,0 +1,87 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2009.\r
+              \r
+  dean [at] fourwalledcubicle [dot] com\r
+      www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, and distribute this software\r
+  and its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  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
+ *\r
+ *  This file is the master dispatch header file for the device-specific ADC driver, for AVRs containing an ADC.\r
+ *\r
+ *  User code should include this file, which will in turn include the correct ADC driver header file for the\r
+ *  currently selected AVR model.\r
+ */\r
+\r
+/** \ingroup Group_SubsystemDrivers\r
+ *  @defgroup Group_ADC ADC Driver - LUFA/Drivers/Peripheral/ADC.h\r
+ */\r
\r
+#ifndef __ADC_H__\r
+#define __ADC_H__\r
+\r
+       /* Macros: */\r
+       #if !defined(__DOXYGEN__)\r
+               #define INCLUDE_FROM_ADC_H\r
+               #define INCLUDE_FROM_CHIP_DRIVER\r
+       #endif\r
+\r
+       /* Includes: */\r
+               #if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \\r
+                    defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \\r
+                        defined(__AVR_ATmega16U4__)  || defined(__AVR_ATmega32U4__) || \\r
+                        defined(__AVR_ATmega32U6__))\r
+                       #include "AT90USBXXX67/ADC.h"\r
+               #else\r
+                       #error "ADC is not available for the currently selected AVR model."\r
+               #endif\r
+\r
+       /* Public Interface - May be used in end-application: */\r
+               /* Inline Functions: */\r
+                       /** Starts the reading of the given channel, but does not wait until the conversion has completed.\r
+                        *  Once executed, the conversion status can be determined via the ADC_IsReadingComplete() macro and\r
+                        *  the result read via the ADC_GetResult() macro.\r
+                        *\r
+                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+                        */\r
+                       static inline void ADC_StartReading(const uint8_t MUXMask);\r
+\r
+                       /** Performs a complete single reading from channel, including a polling spinloop to wait for the\r
+                        *  conversion to complete, and the returning of the converted value.\r
+                        *\r
+                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+                        */\r
+                       static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) ATTR_WARN_UNUSED_RESULT;\r
+\r
+                       /** Configures the given ADC channel, ready for ADC conversions. This function sets the\r
+                        *  associated port pin as an input and disables the digital portion of the I/O to reduce\r
+                        *  power consumption.\r
+                        *\r
+                        *  \param Channel  ADC channel number to set up for conversions\r
+                        */\r
+                       static inline void ADC_SetupChannel(const uint8_t Channel);\r
+                       \r
+#endif\r
diff --git a/LUFA/Drivers/Peripheral/AT90USBXXX67/ADC.h b/LUFA/Drivers/Peripheral/AT90USBXXX67/ADC.h
new file mode 100644 (file)
index 0000000..a5bf037
--- /dev/null
@@ -0,0 +1,185 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2009.\r
+              \r
+  dean [at] fourwalledcubicle [dot] com\r
+      www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, and distribute this software\r
+  and its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  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
+ *\r
+ *  ADC driver for the AT90USB1287, AT90USB1286, AT90USB647, AT90USB646, ATMEGA16U4 and ATMEGA32U4 AVRs.\r
+ *\r
+ *  \note This file should not be included directly. It is automatically included as needed by the ADC driver\r
+ *        dispatch header located in LUFA/Drivers/Peripheral/ADC.h.\r
+ */\r
+\r
+/** \ingroup Group_ADC\r
+ *  @defgroup Group_ADC_AT90USBXXX67 AT90USBXXX6 and AT90USBXXX7 Models\r
+ *\r
+ *  @{\r
+ */\r
\r
+#ifndef __ADC_AT90USBXXX67_H__\r
+#define __ADC_AT90USBXXX67_H__\r
+\r
+       /* Includes: */\r
+               #include "../../../Common/Common.h"\r
+               \r
+               #include <avr/io.h>\r
+               #include <stdbool.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_ADC_H)\r
+                       #error Do not include this file directly. Include LUFA/Drivers/Peripheral/ADC.h instead.\r
+               #endif\r
+\r
+       /* Public Interface - May be used in end-application: */\r
+               /* Macros: */\r
+                       /** Initializes the ADC, ready for conversions. This must be called before any other ADC operations.\r
+                        *  The "mode" parameter should be a mask comprised of a conversion mode (free running or single) and\r
+                        *  prescaler masks.\r
+                        */\r
+                       #define  ADC_Init(mode)          MACROS{ ADCSRA = ((1 << ADEN) | mode);         }MACROE\r
+\r
+                       /** Turns off the ADC. If this is called, any further ADC operations will require a call to the\r
+                        *  ADC_Init() macro before the ADC can be used again.\r
+                        */\r
+                       #define  ADC_Off()               MACROS{ ADCSRA = 0;                            }MACROE\r
+                       \r
+                       /** Indicates if the ADC is enabled. This macro will return boolean true if the ADC subsystem is\r
+                        *  currently enabled, or false otherwise.\r
+                        */\r
+                       #define  ADC_GetStatus()               ((ADCSRA & (1 << ADEN)) ? true : false)\r
+\r
+                       /** Indicates if the current ADC conversion is completed, or still in progress. This returns boolean\r
+                        *  false if the reading is still taking place, or true if the conversion is complete and ready to be\r
+                        *  read out with ADC_GetResult().\r
+                        */\r
+                       #define  ADC_IsReadingComplete()         (!(ADCSRA & (1 << ADSC)))\r
+                       \r
+                       /** Returns the result of the last conversion, as a 16-bit wide integer. */\r
+                       #define  ADC_GetResult()                 ADC\r
+                       \r
+                       /** Reference mask, for using the voltage present at the AVR's AREF pin for the ADC reference. */\r
+                       #define  ADC_REFERENCE_AREF              0\r
+\r
+                       /** Reference mask, for using the voltage present at the AVR's AVCC pin for the ADC reference. */\r
+                       #define  ADC_REFERENCE_AVCC              (1 << REFS0)\r
+\r
+                       /** Reference mask, for using the internally generated 2.56V reference voltage as the ADC reference. */\r
+                       #define  ADC_REFERENCE_INT2560MV         ((1 << REFS1)| (1 << REFS0))\r
+                       \r
+                       /** Left-adjusts the 10-bit ADC result, so that the upper 8 bits of the value returned by the\r
+                        *  ADC_GetResult() macro contain the 8 most significant bits of the result. */\r
+                       #define  ADC_LEFT_ADJUSTED               (1 << ADLAR)\r
+\r
+                       /** Right-adjusts the 10-bit ADC result, so that the lower 8 bits of the value returned by the\r
+                        *  ADC_GetResult() macro contain the 8 least significant bits of the result. */\r
+                       #define  ADC_RIGHT_ADJUSTED              (0 << ADLAR)\r
+                       \r
+                       /** Sets the ADC mode to free running, so that conversions take place continuously as fast as the ADC\r
+                        *  is capable of at the given input clock speed. */\r
+                       #define  ADC_FREE_RUNNING                (1 << ADATE)\r
+\r
+                       /** Sets the ADC mode to single conversion, so that only a single conversion will take place before\r
+                        *  the ADC returns to idle. */\r
+                       #define  ADC_SINGLE_CONVERSION           (0 << ADATE)\r
+                       \r
+                       /** Sets the ADC input clock to prescale by a factor of 2 the AVR's system clock. */\r
+                       #define  ADC_PRESCALE_2                  (1 << ADPS0)\r
+\r
+                       /** Sets the ADC input clock to prescale by a factor of 4 the AVR's system clock. */\r
+                       #define  ADC_PRESCALE_4                  (1 << ADPS1)\r
+\r
+                       /** Sets the ADC input clock to prescale by a factor of 8 the AVR's system clock. */\r
+                       #define  ADC_PRESCALE_8                  ((1 << ADPS0) | (1 << ADPS1))\r
+\r
+                       /** Sets the ADC input clock to prescale by a factor of 16 the AVR's system clock. */\r
+                       #define  ADC_PRESCALE_16                 (1 << ADPS2)\r
+\r
+                       /** Sets the ADC input clock to prescale by a factor of 32 the AVR's system clock. */\r
+                       #define  ADC_PRESCALE_32                 ((1 << ADPS2) | (1 << ADPS0))\r
+\r
+                       /** Sets the ADC input clock to prescale by a factor of 64 the AVR's system clock. */\r
+                       #define  ADC_PRESCALE_64                 ((1 << ADPS2) | (1 << ADPS1))\r
+\r
+                       /** Sets the ADC input clock to prescale by a factor of 128 the AVR's system clock. */\r
+                       #define  ADC_PRESCALE_128                ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))\r
+\r
+               /* Inline Functions: */\r
+                       /** Configures the given ADC channel, ready for ADC conversions. This function sets the\r
+                        *  associated port pin as an input and disables the digital portion of the I/O to reduce\r
+                        *  power consumption.\r
+                        *\r
+                        *  \param Channel  ADC channel number to set up for conversions\r
+                        */\r
+                       static inline void ADC_SetupChannel(const uint8_t Channel)\r
+                       {\r
+                               DDRF  &= ~(1 << Channel);\r
+                               DIDR0 |=  (1 << Channel);\r
+                       }\r
+                       \r
+                       /** Starts the reading of the given channel, but does not wait until the conversion has completed.\r
+                        *  Once executed, the conversion status can be determined via the ADC_IsReadingComplete() macro and\r
+                        *  the result read via the ADC_GetResult() macro.\r
+                        *\r
+                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+                        */\r
+                       static inline void ADC_StartReading(const uint8_t MUXMask)\r
+                       {\r
+                               ADMUX = MUXMask;\r
+                       \r
+                               ADCSRA |= (1 << ADSC);\r
+                       }\r
+\r
+                       /** Performs a complete single reading from channel, including a polling spinloop to wait for the\r
+                        *  conversion to complete, and the returning of the converted value.\r
+                        *\r
+                        *  \param MUXMask  Mask comprising of an ADC channel number, reference mask and adjustment mask\r
+                        */\r
+                       static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask) ATTR_WARN_UNUSED_RESULT;\r
+                       static inline uint16_t ADC_GetChannelReading(const uint8_t MUXMask)\r
+                       {\r
+                               ADC_StartReading(MUXMask);\r
+       \r
+                               while (!(ADC_IsReadingComplete()));\r
+       \r
+                               return ADC_GetResult();\r
+                       }\r
+\r
+       /* Disable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       }\r
+               #endif\r
+               \r
+#endif\r
+\r
+/** @} */\r
diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h
new file mode 100644 (file)
index 0000000..4ada793
--- /dev/null
@@ -0,0 +1,149 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2009.\r
+              \r
+  dean [at] fourwalledcubicle [dot] com\r
+      www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, and distribute this software\r
+  and its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  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
+ *\r
+ *  Hardware SPI subsystem driver for the supported USB AVRs models.\r
+ */\r
+\r
+/** \ingroup Group_SubsystemDrivers\r
+ *  @defgroup Group_SPI SPI Driver - LUFA/Drivers/Peripheral/SPI.h\r
+ *\r
+ *  Functions, macros, variables, enums and types related to the setup of a the SPI port.\r
+ *\r
+ *  @{\r
+ */\r
+\r
+#ifndef __SPI_H__\r
+#define __SPI_H__\r
+\r
+       /* Includes: */\r
+               #include <stdbool.h>\r
+\r
+       /* Enable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       extern "C" {\r
+               #endif\r
+\r
+       /* Private Interface - For use in library only: */\r
+       #if !defined(__DOXYGEN__)\r
+               /* Macros: */\r
+                       #define SPI_USE_DOUBLESPEED            (1 << 7)\r
+       #endif\r
+       \r
+       /* Public Interface - May be used in end-application: */\r
+               /* Macros: */\r
+                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 2. */\r
+                       #define SPI_SPEED_FCPU_DIV_2           SPI_USE_DOUBLESPEED\r
+\r
+                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 4. */\r
+                       #define SPI_SPEED_FCPU_DIV_4           0\r
+\r
+                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 8. */\r
+                       #define SPI_SPEED_FCPU_DIV_8           (SPI_USE_DOUBLESPEED | (1 << SPR0))\r
+\r
+                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 16. */\r
+                       #define SPI_SPEED_FCPU_DIV_16          (1 << SPR0)\r
+\r
+                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */\r
+                       #define SPI_SPEED_FCPU_DIV_32          (SPI_USE_DOUBLESPEED | (1 << SPR1))\r
+\r
+                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 64. */\r
+                       #define SPI_SPEED_FCPU_DIV_64          (SPI_USE_DOUBLESPEED | (1 << SPR1) | (1 << SPR0))\r
+\r
+                       /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 128. */\r
+                       #define SPI_SPEED_FCPU_DIV_128         ((1 << SPR1) | (1 << SPR0))\r
+\r
+               /* Inline Functions: */\r
+                       /** Initializes the SPI subsystem, ready for transfers. Must be called before calling any other\r
+                        *  SPI routines.\r
+                        *\r
+                        *  \param PrescalerMask  Prescaler mask to set the SPI clock speed\r
+                        *  \param Master         If true, sets the SPI system to use master mode, slave if false\r
+                        */\r
+                       static inline void SPI_Init(const uint8_t PrescalerMask, const bool Master)\r
+                       {\r
+                               DDRB  |= ((1 << 1) | (1 << 2));\r
+                               PORTB |= ((1 << 0) | (1 << 3));\r
+                               \r
+                               SPCR   = ((1 << SPE) | (Master << MSTR) | (1 << CPOL) | (1 << CPHA) |\r
+                                         (PrescalerMask & ~SPI_USE_DOUBLESPEED));\r
+                               \r
+                               if (PrescalerMask & SPI_USE_DOUBLESPEED)\r
+                                 SPSR = (1 << SPI2X);\r
+                       }\r
+                       \r
+                       /** Sends and receives a byte through the SPI interface, blocking until the transfer is complete.\r
+                        *\r
+                        *  \param Byte  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
+                       {\r
+                               SPDR = Byte;\r
+                               while (!(SPSR & (1 << SPIF)));\r
+                               return SPDR;\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
+                        *\r
+                        *  \param Byte 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
+                       {\r
+                               SPDR = Byte;\r
+                               while (!(SPSR & (1 << SPIF)));\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
+                        *\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
+                       {\r
+                               SPDR = 0x00;\r
+                               while (!(SPSR & (1 << SPIF)));\r
+                               return SPDR;\r
+                       }\r
+\r
+       /* Disable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       }\r
+               #endif\r
+               \r
+#endif\r
+\r
+/** @} */\r
diff --git a/LUFA/Drivers/Peripheral/Serial.c b/LUFA/Drivers/Peripheral/Serial.c
new file mode 100644 (file)
index 0000000..e1c7449
--- /dev/null
@@ -0,0 +1,65 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2009.\r
+              \r
+  dean [at] fourwalledcubicle [dot] com\r
+      www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, and distribute this software\r
+  and its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  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
+#include "Serial.h"\r
+\r
+void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed)\r
+{\r
+       UCSR1A = ((DoubleSpeed) ? (1 << U2X1) : 0);\r
+       UCSR1B = ((1 << RXEN1)  | (1 << TXEN1));\r
+       UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10));\r
+       \r
+       DDRD  |= (1 << 3);      \r
+       PORTD |= (1 << 2);\r
+       \r
+       UBRR1  = SERIAL_UBBRVAL(BaudRate);\r
+}\r
+\r
+void Serial_TxString_P(const char *FlashStringPtr)\r
+{\r
+       uint8_t CurrByte;\r
+\r
+       while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00)\r
+       {\r
+               Serial_TxByte(CurrByte);\r
+               FlashStringPtr++;\r
+       }\r
+}\r
+\r
+void Serial_TxString(const char *StringPtr)\r
+{\r
+       uint8_t CurrByte;\r
+\r
+       while ((CurrByte = *StringPtr) != 0x00)\r
+       {\r
+               Serial_TxByte(CurrByte);\r
+               StringPtr++;\r
+       }\r
+}\r
diff --git a/LUFA/Drivers/Peripheral/Serial.h b/LUFA/Drivers/Peripheral/Serial.h
new file mode 100644 (file)
index 0000000..d83761f
--- /dev/null
@@ -0,0 +1,125 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2009.\r
+              \r
+  dean [at] fourwalledcubicle [dot] com\r
+      www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, and distribute this software\r
+  and its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  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
+ *\r
+ *  Driver for the USART subsystem on supported USB AVRs.\r
+ */\r
\r
+/** \ingroup Group_SubsystemDrivers\r
+ *  @defgroup Group_Serial Serial USART Driver - LUFA/Drivers/Peripheral/Serial.h\r
+ *\r
+ *  Functions, macros, variables, enums and types related to the setup of the USART for serial communications.\r
+ *\r
+ *  @{\r
+ */\r
\r
+#ifndef __SERIAL_H__\r
+#define __SERIAL_H__\r
+\r
+       /* Includes: */\r
+               #include <avr/io.h>\r
+               #include <avr/pgmspace.h>\r
+               #include <stdbool.h>\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
+               #endif\r
+\r
+       /* Public Interface - May be used in end-application: */\r
+               /* Macros: */   \r
+                       /** Indicates whether a character has been received through the USART - boolean false if no character\r
+                        *  has been received, or non-zero if a character is waiting to be read from the reception buffer.\r
+                        */\r
+                       #define Serial_IsCharReceived() ((UCSR1A & (1 << RXC1)) ? true : false)\r
+\r
+                       /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is\r
+                        *  not set.\r
+                        */\r
+                       #define SERIAL_UBBRVAL(baud)    (((F_CPU / 16) / baud) - 1)\r
+\r
+                       /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is\r
+                        *  set.\r
+                        */\r
+                       #define SERIAL_2X_UBBRVAL(baud) (((F_CPU / 8) / baud) - 1)\r
+\r
+               /* Function Prototypes: */\r
+                       /** Initializes the USART, ready for serial data transmission and reception.\r
+                        *\r
+                        *  \param BaudRate     Baud rate to configure the USART to\r
+                        *  \param DoubleSpeed  Enables double speed mode when set, halving the sample time to double the baud rate\r
+                        */\r
+                       void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed);\r
+\r
+                       /** Transmits a given string located in program space (FLASH) through the USART.\r
+                        *\r
+                        *  \param FlashStringPtr  Pointer to a string located in program space\r
+                        */\r
+                       void Serial_TxString_P(const char *FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1);\r
+\r
+                       /** Transmits a given string located in SRAM memory through the USART.\r
+                        *\r
+                        *  \param StringPtr  Pointer to a string located in SRAM space\r
+                        */\r
+                       void Serial_TxString(const char *StringPtr) ATTR_NON_NULL_PTR_ARG(1);\r
+\r
+               /* Inline Functions: */\r
+                       /** Transmits a given byte through the USART.\r
+                        *\r
+                        *  \param DataByte  Byte to transmit through the USART\r
+                        */\r
+                       static inline void Serial_TxByte(const char DataByte)\r
+                       {\r
+                               while (!(UCSR1A & (1 << UDRE1)));\r
+                               UDR1 = DataByte;\r
+                       }\r
+\r
+                       /** Receives a byte from the USART.\r
+                        *\r
+                        *  \return Byte received from the USART\r
+                        */\r
+                       static inline char Serial_RxByte(void)\r
+                       {\r
+                               while (!(UCSR1A & (1 << RXC1)));\r
+                               return UDR1; \r
+                       }\r
+\r
+       /* Disable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       }\r
+               #endif\r
+               \r
+#endif\r
+\r
+/** @} */\r
diff --git a/LUFA/Drivers/Peripheral/Serial_Stream.c b/LUFA/Drivers/Peripheral/Serial_Stream.c
new file mode 100644 (file)
index 0000000..d986af4
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2009.\r
+              \r
+  dean [at] fourwalledcubicle [dot] com\r
+      www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, and distribute this software\r
+  and its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  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
+#include "Serial_Stream.h"\r
+\r
+FILE USARTStream = FDEV_SETUP_STREAM(SerialStream_TxByte, SerialStream_RxByte, _FDEV_SETUP_RW);\r
+\r
+int SerialStream_TxByte(char DataByte, FILE *Stream)\r
+{\r
+       Serial_TxByte(DataByte);\r
+\r
+       return 0;\r
+}\r
+\r
+int SerialStream_RxByte(FILE *Stream)\r
+{\r
+       return Serial_RxByte();\r
+}\r
diff --git a/LUFA/Drivers/Peripheral/Serial_Stream.h b/LUFA/Drivers/Peripheral/Serial_Stream.h
new file mode 100644 (file)
index 0000000..406cbed
--- /dev/null
@@ -0,0 +1,93 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2009.\r
+              \r
+  dean [at] fourwalledcubicle [dot] com\r
+      www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, and distribute this software\r
+  and its documentation for any purpose and without fee is hereby\r
+  granted, provided that the above copyright notice appear in all\r
+  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
+ *\r
+ *  Serial stream driver for the USART subsystem on supported USB AVRs. This makes use of the functions in the\r
+ *  regular USART driver, but allows the avr-libc standard stream functions (printf, puts, etc.) to work with the\r
+ *  USART.\r
+ **/\r
+\r
+/** \ingroup Group_SubsystemDrivers\r
+ *  @defgroup Group_SerialStream Serial Stream Driver - LUFA/Drivers/Peripheral/Serial_Stream.h\r
+ *\r
+ *  Functions, macros, variables, enums and types related to the setup of a serial stream, so that standard printf and other\r
+ *  C stream functions can be used on the serial port.\r
+ *\r
+ *  @{\r
+ */\r
+\r
+#ifndef __SERIAL_STREAM_H__\r
+#define __SERIAL_STREAM_H__\r
+\r
+       /* Includes: */\r
+               #include <avr/io.h>\r
+               #include <stdio.h>\r
+               \r
+               #include "Serial.h"\r
+       \r
+       /* Enable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       extern "C" {\r
+               #endif\r
+\r
+       /* Private Interface - For use in library only: */      \r
+       #if !defined(__DOXYGEN__)\r
+               /* External Variables: */\r
+                       extern FILE USARTStream;\r
+\r
+               /* Function Prototypes: */\r
+                       int SerialStream_TxByte(char DataByte, FILE *Stream) ATTR_NON_NULL_PTR_ARG(2);\r
+                       int SerialStream_RxByte(FILE *Stream) ATTR_NON_NULL_PTR_ARG(1);\r
+       #endif\r
+\r
+       /* Public Interface - May be used in end-application: */\r
+               /* Inline Functions: */\r
+                       /** Initializes the serial stream (and regular USART driver) so that both the stream and regular\r
+                        *  USART driver functions can be used. Must be called before any stream or regular USART functions.\r
+                        *\r
+                        *  \param BaudRate     Baud rate to configure the USART to\r
+                        *  \param DoubleSpeed  Enables double speed mode when set, halving the sample time to double the baud rate\r
+                        */\r
+                       static inline void SerialStream_Init(const uint32_t BaudRate, const bool DoubleSpeed)\r
+                       {\r
+                               Serial_Init(BaudRate, DoubleSpeed);\r
+                               \r
+                               stdout = &USARTStream;\r
+                       }\r
+\r
+       /* Disable C linkage for C++ Compilers: */\r
+               #if defined(__cplusplus)\r
+                       }\r
+               #endif\r
+\r
+#endif\r
+\r
+/** @} */\r