From aae20139b90521cf1d1b17fdcb3ff9d42ecdf937 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 22 Feb 2010 11:44:34 +0000 Subject: Add drivers for the EVK1101 - begin full port to the AVR32 UC3B line of AVRs. --- LUFA/Drivers/Board/BUMBLEB/Joystick.h | 4 +- LUFA/Drivers/Board/Buttons.h | 4 +- LUFA/Drivers/Board/Dataflash.h | 2 + LUFA/Drivers/Board/EVK1101/Buttons.h | 99 ++++++++++++++++ LUFA/Drivers/Board/EVK1101/Joystick.h | 117 ++++++++++++++++++ LUFA/Drivers/Board/EVK1101/LEDs.h | 138 ++++++++++++++++++++++ LUFA/Drivers/Board/Joystick.h | 4 +- LUFA/Drivers/Board/LEDs.h | 16 +-- LUFA/Drivers/Board/Temperature.h | 6 +- LUFA/Drivers/Peripheral/AVRU4U6U7/SPI.h | 184 +++++++++++++++++++++++++++++ LUFA/Drivers/Peripheral/AVRU4U6U7/Serial.h | 161 +++++++++++++++++++++++++ LUFA/Drivers/Peripheral/SPI.h | 184 ----------------------------- LUFA/Drivers/Peripheral/Serial.h | 161 ------------------------- 13 files changed, 723 insertions(+), 357 deletions(-) create mode 100644 LUFA/Drivers/Board/EVK1101/Buttons.h create mode 100644 LUFA/Drivers/Board/EVK1101/Joystick.h create mode 100644 LUFA/Drivers/Board/EVK1101/LEDs.h create mode 100644 LUFA/Drivers/Peripheral/AVRU4U6U7/SPI.h create mode 100644 LUFA/Drivers/Peripheral/AVRU4U6U7/Serial.h delete mode 100644 LUFA/Drivers/Peripheral/SPI.h delete mode 100644 LUFA/Drivers/Peripheral/Serial.h (limited to 'LUFA/Drivers') diff --git a/LUFA/Drivers/Board/BUMBLEB/Joystick.h b/LUFA/Drivers/Board/BUMBLEB/Joystick.h index 5d57ec559..180967759 100644 --- a/LUFA/Drivers/Board/BUMBLEB/Joystick.h +++ b/LUFA/Drivers/Board/BUMBLEB/Joystick.h @@ -30,7 +30,7 @@ /** \file * - * Board specific joystick driver header for the USBKEY. The BUMBLEB third-party board does not include any on-board + * Board specific joystick driver header for the BUMBLEB. The BUMBLEB third-party board does not include any on-board * peripherals, but does have an officially recommended external peripheral layout for buttons, LEDs and a Joystick. * * \note This file should not be included directly. It is automatically included as needed by the joystick driver @@ -40,7 +40,7 @@ /** \ingroup Group_Joystick * @defgroup Group_Joystick_BUMBLEB BUMBLEB * - * Board specific joystick driver header for the USBKEY. The BUMBLEB third-party board does not include any on-board + * Board specific joystick driver header for the BUMBLEB. The BUMBLEB third-party board does not include any on-board * peripherals, but does have an officially recommended external peripheral layout for buttons, LEDs and a Joystick. * * \note This file should not be included directly. It is automatically included as needed by the joystick driver diff --git a/LUFA/Drivers/Board/Buttons.h b/LUFA/Drivers/Board/Buttons.h index d908fd43a..f50977706 100644 --- a/LUFA/Drivers/Board/Buttons.h +++ b/LUFA/Drivers/Board/Buttons.h @@ -86,6 +86,8 @@ #include "EVK527/Buttons.h" #elif (BOARD == BOARD_USER) #include "Board/Buttons.h" + #elif (BOARD == BOARD_EVK1101) + #include "EVK1101/Buttons.h" #else #error The selected board does not contain any GPIO buttons. #endif @@ -103,7 +105,7 @@ * * \return Mask indicating which board buttons are currently pressed */ - static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uintN_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; #endif #endif diff --git a/LUFA/Drivers/Board/Dataflash.h b/LUFA/Drivers/Board/Dataflash.h index 762142c33..c0f314a3e 100644 --- a/LUFA/Drivers/Board/Dataflash.h +++ b/LUFA/Drivers/Board/Dataflash.h @@ -167,6 +167,8 @@ #include "EVK527/Dataflash.h" #elif (BOARD == BOARD_USER) #include "Board/Dataflash.h" + #elif (BOARD = BOARD_EVK1101) + #include "EVK1101/Dataflash.h" #else #error The selected board does not contain a dataflash IC. #endif diff --git a/LUFA/Drivers/Board/EVK1101/Buttons.h b/LUFA/Drivers/Board/EVK1101/Buttons.h new file mode 100644 index 000000000..b827787c7 --- /dev/null +++ b/LUFA/Drivers/Board/EVK1101/Buttons.h @@ -0,0 +1,99 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Board specific Buttons driver header for the EVK1101. + * + * \note This file should not be included directly. It is automatically included as needed by the Buttons driver + * dispatch header located in LUFA/Drivers/Board/Buttons.h. + */ + +/** \ingroup Group_Buttons + * @defgroup Group_Buttons_EVK1101 EVK1101 + * + * Board specific Buttons driver header for the EVK1101. + * + * \note This file should not be included directly. It is automatically included as needed by the Buttons driver + * dispatch header located in LUFA/Drivers/Board/Buttons.h. + * + * @{ + */ + +#ifndef __BUTTONS_EVK1101_H__ +#define __BUTTONS_EVK1101_H__ + + /* Includes: */ + #include + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_BUTTONS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Button mask for the first button on the board. */ + #define BUTTONS_BUTTON1 (1UL << 2) + + /** Button mask for the second button on the board. */ + #define BUTTONS_BUTTON2 (1UL << 3) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Buttons_Init(void) + { + AVR32_GPIO.port[1].gpers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2); + AVR32_GPIO.port[1].puers = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2); + } + + static inline uint32_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint32_t Buttons_GetStatus(void) + { + return (~AVR32_GPIO.port[1].pvr & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2)); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/LUFA/Drivers/Board/EVK1101/Joystick.h b/LUFA/Drivers/Board/EVK1101/Joystick.h new file mode 100644 index 000000000..0bcc59c94 --- /dev/null +++ b/LUFA/Drivers/Board/EVK1101/Joystick.h @@ -0,0 +1,117 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Board specific joystick driver header for the EVK1101. + * + * \note This file should not be included directly. It is automatically included as needed by the joystick driver + * dispatch header located in LUFA/Drivers/Board/Joystick.h. + */ + +/** \ingroup Group_Joystick + * @defgroup Group_Joystick_EVK1101 EVK1101 + * + * Board specific joystick driver header for the EVK1101. + * + * \note This file should not be included directly. It is automatically included as needed by the joystick driver + * dispatch header located in LUFA/Drivers/Board/Joystick.h. + * + * @{ + */ + +#ifndef __JOYSTICK_EVK1101_H__ +#define __JOYSTICK_EVK1101_H__ + + /* Includes: */ + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_JOYSTICK_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead. + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define JOY_MASK_PA (1 << 13) + #define JOY_MASK_PB ((1 << 6) | (1 << 7) | (1 << 8) | (1 << 9)) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mask for the joystick being pushed in the left direction. */ + #define JOY_LEFT (1UL << 6) + + /** Mask for the joystick being pushed in the upward direction. */ + #define JOY_UP (1UL << 7) + + /** Mask for the joystick being pushed in the right direction. */ + #define JOY_RIGHT (1UL << 8) + + /** Mask for the joystick being pushed in the downward direction. */ + #define JOY_DOWN (1UL << 9) + + /** Mask for the joystick being pushed inward. */ + #define JOY_PRESS (1UL << 13) + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void Joystick_Init(void) + { + AVR32_GPIO.port[0].gpers = JOY_MASK_PA; + AVR32_GPIO.port[0].puers = JOY_MASK_PA; + AVR32_GPIO.port[1].gpers = JOY_MASK_PB; + AVR32_GPIO.port[1].puers = JOY_MASK_PB; + } + + static inline uint32_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uint32_t Joystick_GetStatus(void) + { + return ((~AVR32_GPIO.port[1].pvr & JOY_MASK_PB) | + (~AVR32_GPIO.port[0].pvr & JOY_MASK_PA)); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/LUFA/Drivers/Board/EVK1101/LEDs.h b/LUFA/Drivers/Board/EVK1101/LEDs.h new file mode 100644 index 000000000..f19e464d7 --- /dev/null +++ b/LUFA/Drivers/Board/EVK1101/LEDs.h @@ -0,0 +1,138 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Board specific LED driver header for the EVK1101. + * + * \note This file should not be included directly. It is automatically included as needed by the LEDs driver + * dispatch header located in LUFA/Drivers/Board/LEDs.h. + */ + +/** \ingroup Group_LEDs + * @defgroup Group_LEDs_EVK1101 EVK1101 + * + * Board specific LED driver header for the EVK1101. + * + * \note This file should not be included directly. It is automatically included as needed by the LEDs driver + * dispatch header located in LUFA/Drivers/Board/LEDs.h. + * + * @{ + */ + +#ifndef __LEDS_EVK1101_H__ +#define __LEDS_EVK1101_H__ + + /* Includes: */ + #include + + #include "../../../Common/Common.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_LEDS_H) + #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** LED mask for the first LED on the board. */ + #define LEDS_LED1 (1UL << 7) + + /** LED mask for the second LED on the board. */ + #define LEDS_LED2 (1UL << 8) + + /** LED mask for the third LED on the board. */ + #define LEDS_LED3 (1UL << 21) + + /** LED mask for the fourth LED on the board. */ + #define LEDS_LED4 (1UL << 22) + + /** LED mask for all the LEDs on the board. */ + #define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4) + + /** LED mask for the none of the board LEDs */ + #define LEDS_NO_LEDS 0 + + /* Inline Functions: */ + #if !defined(__DOXYGEN__) + static inline void LEDs_Init(void) + { + AVR32_GPIO.port[0].gpers = LEDS_ALL_LEDS; + AVR32_GPIO.port[0].oders = LEDS_ALL_LEDS; + AVR32_GPIO.port[0].ovrs = LEDS_ALL_LEDS; + } + + static inline void LEDs_TurnOnLEDs(const uint32_t LEDMask) + { + AVR32_GPIO.port[0].ovrc = LEDMask; + } + + static inline void LEDs_TurnOffLEDs(const uint32_t LEDMask) + { + AVR32_GPIO.port[0].ovrs = LEDMask; + } + + static inline void LEDs_SetAllLEDs(const uint32_t LEDMask) + { + AVR32_GPIO.port[0].ovrs = LEDS_ALL_LEDS; + AVR32_GPIO.port[0].ovrc = LEDMask; + } + + static inline void LEDs_ChangeLEDs(const uint32_t LEDMask, const uint32_t ActiveMask) + { + AVR32_GPIO.port[0].ovrs = LEDMask; + AVR32_GPIO.port[0].ovrc = ActiveMask; + } + + static inline void LEDs_ToggleLEDs(const uint32_t LEDMask) + { + AVR32_GPIO.port[0].ovrt = LEDMask; + } + + static inline uint32_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; + static inline uint32_t LEDs_GetLEDs(void) + { + return (AVR32_GPIO.port[0].ovr & LEDS_ALL_LEDS); + } + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/LUFA/Drivers/Board/Joystick.h b/LUFA/Drivers/Board/Joystick.h index 39375a265..b14e98986 100644 --- a/LUFA/Drivers/Board/Joystick.h +++ b/LUFA/Drivers/Board/Joystick.h @@ -83,6 +83,8 @@ #include "EVK527/Joystick.h" #elif (BOARD == BOARD_USER) #include "Board/Joystick.h" + #elif (BOARD == BOARD_EVK1101) + #include "EVK1101/Joystick.h" #else #error The selected board does not contain a joystick. #endif @@ -100,7 +102,7 @@ * \return Mask indicating the joystick direction - see corresponding board specific Joystick.h file * for direction masks */ - static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; + static inline uintN_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; #endif #endif diff --git a/LUFA/Drivers/Board/LEDs.h b/LUFA/Drivers/Board/LEDs.h index 94fbf3cf7..1def9ea90 100644 --- a/LUFA/Drivers/Board/LEDs.h +++ b/LUFA/Drivers/Board/LEDs.h @@ -84,7 +84,7 @@ static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) {}; static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask) {}; static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) {}; - static inline uint8_t LEDs_GetLEDs(void) { return 0; } + static inline uintN_t LEDs_GetLEDs(void) { return 0; } #elif (BOARD == BOARD_USBKEY) #include "USBKEY/LEDs.h" #elif (BOARD == BOARD_STK525) @@ -105,6 +105,8 @@ #include "EVK527/LEDs.h" #elif (BOARD == BOARD_USER) #include "Board/LEDs.h" + #elif (BOARD == BOARD_EVK1101) + #include "EVK1101/LEDs.h" #endif #if !defined(LEDS_LED1) @@ -134,20 +136,20 @@ * * \param[in] LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) */ - static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask); + static inline void LEDs_TurnOnLEDs(const uintN_t LEDMask); /** Turns off the LEDs specified in the given LED mask. * * \param[in] LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) */ - static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask); + static inline void LEDs_TurnOffLEDs(const uintN_t LEDMask); /** Turns off all LEDs not specified in the given LED mask, and turns on all the LEDs in the given LED * mask. * * \param[in] LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) */ - static inline void LEDs_SetAllLEDs(const uint8_t LEDMask); + static inline void LEDs_SetAllLEDs(const uintN_t LEDMask); /** Turns off all LEDs in the LED mask that are not set in the active mask, and turns on all the LEDs * specified in both the LED and active masks. @@ -155,20 +157,20 @@ * \param[in] LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) * \param[in] ActiveMask Mask of whether the LEDs in the LED mask should be turned on or off */ - static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask); + static inline void LEDs_ChangeLEDs(const uintN_t LEDMask, const uintN_t ActiveMask); /** Toggles all LEDs in the LED mask, leaving all others in their current states. * * \param[in] LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file) */ - static inline void LEDs_ToggleLEDs(const uint8_t LEDMask); + static inline void LEDs_ToggleLEDs(const uintN_t LEDMask); /** Returns the status of all the board LEDs; set LED masks in the return value indicate that the * corresponding LED is on. * * \return Mask of the board LEDs which are currently turned on */ - static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; + static inline uintN_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; #endif #endif diff --git a/LUFA/Drivers/Board/Temperature.h b/LUFA/Drivers/Board/Temperature.h index 7a5af367b..12e6df137 100644 --- a/LUFA/Drivers/Board/Temperature.h +++ b/LUFA/Drivers/Board/Temperature.h @@ -53,7 +53,11 @@ #define __TEMPERATURE_H__ /* Includes: */ - #include + #if defined(__AVR32__) + #include + #else + #include + #endif #include "../../Common/Common.h" #include "../Peripheral/ADC.h" diff --git a/LUFA/Drivers/Peripheral/AVRU4U6U7/SPI.h b/LUFA/Drivers/Peripheral/AVRU4U6U7/SPI.h new file mode 100644 index 000000000..25503b6c3 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRU4U6U7/SPI.h @@ -0,0 +1,184 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Hardware SPI subsystem driver for the supported USB AVRs models. + */ + +/** \ingroup Group_PeripheralDrivers + * @defgroup Group_SPI SPI Driver - LUFA/Drivers/Peripheral/SPI.h + * + * \section Sec_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - None + * + * \section Module Description + * Driver for the hardware SPI port available on most AVR models. This module provides + * an easy to use driver for the setup of and transfer of data over the AVR's SPI port. + * + * @{ + */ + +#ifndef __SPI_H__ +#define __SPI_H__ + + /* Includes: */ + #include + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define SPI_USE_DOUBLESPEED (1 << SPE) + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 2. */ + #define SPI_SPEED_FCPU_DIV_2 SPI_USE_DOUBLESPEED + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 4. */ + #define SPI_SPEED_FCPU_DIV_4 0 + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 8. */ + #define SPI_SPEED_FCPU_DIV_8 (SPI_USE_DOUBLESPEED | (1 << SPR0)) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 16. */ + #define SPI_SPEED_FCPU_DIV_16 (1 << SPR0) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */ + #define SPI_SPEED_FCPU_DIV_32 (SPI_USE_DOUBLESPEED | (1 << SPR1)) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 64. */ + #define SPI_SPEED_FCPU_DIV_64 (SPI_USE_DOUBLESPEED | (1 << SPR1) | (1 << SPR0)) + + /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 128. */ + #define SPI_SPEED_FCPU_DIV_128 ((1 << SPR1) | (1 << SPR0)) + + /** SPI clock polarity mask for SPI_Init(). Indicates that the SCK should lead on the rising edge. */ + #define SPI_SCK_LEAD_RISING (0 << CPOL) + + /** SPI clock polarity mask for SPI_Init(). Indicates that the SCK should lead on the falling edge. */ + #define SPI_SCK_LEAD_FALLING (1 << CPOL) + + /** SPI data sample mode mask for SPI_Init(). Indicates that the data should sampled on the leading edge. */ + #define SPI_SAMPLE_LEADING (0 << CPHA) + + /** SPI data sample mode mask for SPI_Init(). Indicates that the data should be sampled on the trailing edge. */ + #define SPI_SAMPLE_TRAILING (1 << CPHA) + + /** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into slave mode. */ + #define SPI_MODE_SLAVE (0 << MSTR) + + /** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into master mode. */ + #define SPI_MODE_MASTER (1 << MSTR) + + /* Inline Functions: */ + /** Initialises the SPI subsystem, ready for transfers. Must be called before calling any other + * SPI routines. + * + * \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) + { + DDRB |= ((1 << 1) | (1 << 2)); + PORTB |= ((1 << 0) | (1 << 3)); + + SPCR = ((1 << SPE) | SPIOptions); + + if (SPIOptions & SPI_USE_DOUBLESPEED) + SPSR |= (1 << SPI2X); + else + SPSR &= ~(1 << SPI2X); + } + + /** Turns off the SPI driver, disabling and returning used hardware to their default configuration. */ + static inline void SPI_ShutDown(void) + { + DDRB &= ~((1 << 1) | (1 << 2)); + PORTB &= ~((1 << 0) | (1 << 3)); + + SPCR = 0; + SPSR = 0; + } + + /** 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 + * + * \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) + { + SPDR = Byte; + while (!(SPSR & (1 << SPIF))); + return SPDR; + } + + /** 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 + */ + static inline void SPI_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE; + static inline void SPI_SendByte(const uint8_t Byte) + { + SPDR = Byte; + while (!(SPSR & (1 << SPIF))); + } + + /** Sends a dummy byte through the SPI interface, blocking until the transfer is complete. The response + * byte from the attached SPI device is returned. + * + * \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) + { + SPDR = 0x00; + while (!(SPSR & (1 << SPIF))); + return SPDR; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/LUFA/Drivers/Peripheral/AVRU4U6U7/Serial.h b/LUFA/Drivers/Peripheral/AVRU4U6U7/Serial.h new file mode 100644 index 000000000..d00f9c1c0 --- /dev/null +++ b/LUFA/Drivers/Peripheral/AVRU4U6U7/Serial.h @@ -0,0 +1,161 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Driver for the USART subsystem on supported USB AVRs. + */ + +/** \ingroup Group_PeripheralDrivers + * @defgroup Group_Serial Serial USART Driver - LUFA/Drivers/Peripheral/Serial.h + * + * \section Sec_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - LUFA/Drivers/Peripheral/Serial.c + * + * \section Module Description + * Hardware serial USART driver. This module provides an easy to use driver for + * the setup of and transfer of data over the AVR's USART port. + * + * @{ + */ + +#ifndef __SERIAL_H__ +#define __SERIAL_H__ + + /* Includes: */ + #include + #include + #include + + #include "../../Common/Common.h" + #include "../Misc/TerminalCodes.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is + * not set. + */ + #define SERIAL_UBBRVAL(baud) ((((F_CPU / 16) + (baud / 2)) / (baud)) - 1) + + /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is + * set. + */ + #define SERIAL_2X_UBBRVAL(baud) ((((F_CPU / 8) + (baud / 2)) / (baud)) - 1) + + /* Pseudo-Function Macros: */ + #if defined(__DOXYGEN__) + /** Indicates whether a character has been received through the USART. + * + * \return Boolean true if a character has been received, false otherwise + */ + static inline bool Serial_IsCharReceived(void); + #else + #define Serial_IsCharReceived() ((UCSR1A & (1 << RXC1)) ? true : false) + #endif + + /* Function Prototypes: */ + /** Transmits a given string located in program space (FLASH) through the USART. + * + * \param[in] FlashStringPtr Pointer to a string located in program space + */ + void Serial_TxString_P(const char *FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1); + + /** Transmits a given string located in SRAM memory through the USART. + * + * \param[in] StringPtr Pointer to a string located in SRAM space + */ + void Serial_TxString(const char *StringPtr) ATTR_NON_NULL_PTR_ARG(1); + + /* Inline Functions: */ + /** Initializes the USART, ready for serial data transmission and reception. This initializes the interface to + * standard 8-bit, no parity, 1 stop bit settings suitable for most applications. + * + * \param[in] BaudRate Serial baud rate, in bits per second + * \param[in] DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate + */ + static inline void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed) + { + UCSR1A = (DoubleSpeed ? (1 << U2X1) : 0); + UCSR1B = ((1 << TXEN1) | (1 << RXEN1)); + UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10)); + + DDRD |= (1 << 3); + PORTD |= (1 << 2); + + UBRR1 = (DoubleSpeed ? SERIAL_2X_UBBRVAL(BaudRate) : SERIAL_UBBRVAL(BaudRate)); + } + + /** Turns off the USART driver, disabling and returning used hardware to their default configuration. */ + static inline void Serial_ShutDown(void) + { + UCSR1A = 0; + UCSR1B = 0; + UCSR1C = 0; + + DDRD &= ~(1 << 3); + PORTD &= ~(1 << 2); + + UBRR1 = 0; + } + + /** Transmits a given byte through the USART. + * + * \param[in] DataByte Byte to transmit through the USART + */ + static inline void Serial_TxByte(const char DataByte) + { + while (!(UCSR1A & (1 << UDRE1))); + UDR1 = DataByte; + } + + /** Receives a byte from the USART. + * + * \return Byte received from the USART + */ + static inline char Serial_RxByte(void) + { + while (!(UCSR1A & (1 << RXC1))); + return UDR1; + } + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h deleted file mode 100644 index 6416ceae6..000000000 --- a/LUFA/Drivers/Peripheral/SPI.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Hardware SPI subsystem driver for the supported USB AVRs models. - */ - -/** \ingroup Group_PeripheralDrivers - * @defgroup Group_SPI SPI Driver - LUFA/Drivers/Peripheral/SPI.h - * - * \section Sec_Dependencies Module Source Dependencies - * The following files must be built with any user project that uses this module: - * - None - * - * \section Module Description - * Driver for the hardware SPI port available on most AVR models. This module provides - * an easy to use driver for the setup of and transfer of data over the AVR's SPI port. - * - * @{ - */ - -#ifndef __SPI_H__ -#define __SPI_H__ - - /* Includes: */ - #include - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - /* Macros: */ - #define SPI_USE_DOUBLESPEED (1 << SPE) - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 2. */ - #define SPI_SPEED_FCPU_DIV_2 SPI_USE_DOUBLESPEED - - /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 4. */ - #define SPI_SPEED_FCPU_DIV_4 0 - - /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 8. */ - #define SPI_SPEED_FCPU_DIV_8 (SPI_USE_DOUBLESPEED | (1 << SPR0)) - - /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 16. */ - #define SPI_SPEED_FCPU_DIV_16 (1 << SPR0) - - /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */ - #define SPI_SPEED_FCPU_DIV_32 (SPI_USE_DOUBLESPEED | (1 << SPR1)) - - /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 64. */ - #define SPI_SPEED_FCPU_DIV_64 (SPI_USE_DOUBLESPEED | (1 << SPR1) | (1 << SPR0)) - - /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 128. */ - #define SPI_SPEED_FCPU_DIV_128 ((1 << SPR1) | (1 << SPR0)) - - /** SPI clock polarity mask for SPI_Init(). Indicates that the SCK should lead on the rising edge. */ - #define SPI_SCK_LEAD_RISING (0 << CPOL) - - /** SPI clock polarity mask for SPI_Init(). Indicates that the SCK should lead on the falling edge. */ - #define SPI_SCK_LEAD_FALLING (1 << CPOL) - - /** SPI data sample mode mask for SPI_Init(). Indicates that the data should sampled on the leading edge. */ - #define SPI_SAMPLE_LEADING (0 << CPHA) - - /** SPI data sample mode mask for SPI_Init(). Indicates that the data should be sampled on the trailing edge. */ - #define SPI_SAMPLE_TRAILING (1 << CPHA) - - /** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into slave mode. */ - #define SPI_MODE_SLAVE (0 << MSTR) - - /** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into master mode. */ - #define SPI_MODE_MASTER (1 << MSTR) - - /* Inline Functions: */ - /** Initializes the SPI subsystem, ready for transfers. Must be called before calling any other - * SPI routines. - * - * \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) - { - DDRB |= ((1 << 1) | (1 << 2)); - PORTB |= ((1 << 0) | (1 << 3)); - - SPCR = ((1 << SPE) | SPIOptions); - - if (SPIOptions & SPI_USE_DOUBLESPEED) - SPSR |= (1 << SPI2X); - else - SPSR &= ~(1 << SPI2X); - } - - /** Turns off the SPI driver, disabling and returning used hardware to their default configuration. */ - static inline void SPI_ShutDown(void) - { - DDRB &= ~((1 << 1) | (1 << 2)); - PORTB &= ~((1 << 0) | (1 << 3)); - - SPCR = 0; - SPSR = 0; - } - - /** 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 - * - * \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) - { - SPDR = Byte; - while (!(SPSR & (1 << SPIF))); - return SPDR; - } - - /** 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 - */ - static inline void SPI_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE; - static inline void SPI_SendByte(const uint8_t Byte) - { - SPDR = Byte; - while (!(SPSR & (1 << SPIF))); - } - - /** Sends a dummy byte through the SPI interface, blocking until the transfer is complete. The response - * byte from the attached SPI device is returned. - * - * \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) - { - SPDR = 0x00; - while (!(SPSR & (1 << SPIF))); - return SPDR; - } - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ diff --git a/LUFA/Drivers/Peripheral/Serial.h b/LUFA/Drivers/Peripheral/Serial.h deleted file mode 100644 index d00f9c1c0..000000000 --- a/LUFA/Drivers/Peripheral/Serial.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Driver for the USART subsystem on supported USB AVRs. - */ - -/** \ingroup Group_PeripheralDrivers - * @defgroup Group_Serial Serial USART Driver - LUFA/Drivers/Peripheral/Serial.h - * - * \section Sec_Dependencies Module Source Dependencies - * The following files must be built with any user project that uses this module: - * - LUFA/Drivers/Peripheral/Serial.c - * - * \section Module Description - * Hardware serial USART driver. This module provides an easy to use driver for - * the setup of and transfer of data over the AVR's USART port. - * - * @{ - */ - -#ifndef __SERIAL_H__ -#define __SERIAL_H__ - - /* Includes: */ - #include - #include - #include - - #include "../../Common/Common.h" - #include "../Misc/TerminalCodes.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is - * not set. - */ - #define SERIAL_UBBRVAL(baud) ((((F_CPU / 16) + (baud / 2)) / (baud)) - 1) - - /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is - * set. - */ - #define SERIAL_2X_UBBRVAL(baud) ((((F_CPU / 8) + (baud / 2)) / (baud)) - 1) - - /* Pseudo-Function Macros: */ - #if defined(__DOXYGEN__) - /** Indicates whether a character has been received through the USART. - * - * \return Boolean true if a character has been received, false otherwise - */ - static inline bool Serial_IsCharReceived(void); - #else - #define Serial_IsCharReceived() ((UCSR1A & (1 << RXC1)) ? true : false) - #endif - - /* Function Prototypes: */ - /** Transmits a given string located in program space (FLASH) through the USART. - * - * \param[in] FlashStringPtr Pointer to a string located in program space - */ - void Serial_TxString_P(const char *FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1); - - /** Transmits a given string located in SRAM memory through the USART. - * - * \param[in] StringPtr Pointer to a string located in SRAM space - */ - void Serial_TxString(const char *StringPtr) ATTR_NON_NULL_PTR_ARG(1); - - /* Inline Functions: */ - /** Initializes the USART, ready for serial data transmission and reception. This initializes the interface to - * standard 8-bit, no parity, 1 stop bit settings suitable for most applications. - * - * \param[in] BaudRate Serial baud rate, in bits per second - * \param[in] DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate - */ - static inline void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed) - { - UCSR1A = (DoubleSpeed ? (1 << U2X1) : 0); - UCSR1B = ((1 << TXEN1) | (1 << RXEN1)); - UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10)); - - DDRD |= (1 << 3); - PORTD |= (1 << 2); - - UBRR1 = (DoubleSpeed ? SERIAL_2X_UBBRVAL(BaudRate) : SERIAL_UBBRVAL(BaudRate)); - } - - /** Turns off the USART driver, disabling and returning used hardware to their default configuration. */ - static inline void Serial_ShutDown(void) - { - UCSR1A = 0; - UCSR1B = 0; - UCSR1C = 0; - - DDRD &= ~(1 << 3); - PORTD &= ~(1 << 2); - - UBRR1 = 0; - } - - /** Transmits a given byte through the USART. - * - * \param[in] DataByte Byte to transmit through the USART - */ - static inline void Serial_TxByte(const char DataByte) - { - while (!(UCSR1A & (1 << UDRE1))); - UDR1 = DataByte; - } - - /** Receives a byte from the USART. - * - * \return Byte received from the USART - */ - static inline char Serial_RxByte(void) - { - while (!(UCSR1A & (1 << RXC1))); - return UDR1; - } - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ -- cgit v1.2.3