Revert changes made for the partial port to the AVR32 architecture.
This commit is contained in:
parent
a7aaa45ec4
commit
071fd8ce53
79 changed files with 739 additions and 1727 deletions
|
|
@ -58,13 +58,11 @@
|
|||
#endif
|
||||
|
||||
/* Includes: */
|
||||
#include "../../Common/Common.h"
|
||||
|
||||
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \
|
||||
defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \
|
||||
defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \
|
||||
defined(__AVR_ATmega32U6__))
|
||||
#include "AVR8/ADC.h"
|
||||
#include "AVRU4U6U7/ADC.h"
|
||||
#else
|
||||
#error "ADC is not available for the currently selected AVR model."
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,174 +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
|
||||
*
|
||||
* SPI driver for the 32-bit AVRs.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the SPI driver
|
||||
* dispatch header located in LUFA/Drivers/Peripheral/SPI.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_SPI
|
||||
* @defgroup Group_SPI_AVR32 32-Bit AVR SPI Driver
|
||||
*
|
||||
* SPI driver for the 32-bit AVRs.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the ADC driver
|
||||
* dispatch header located in LUFA/Drivers/Peripheral/SPI.h.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __SPI_AVR32_H__
|
||||
#define __SPI_AVR32_H__
|
||||
|
||||
/* Includes: */
|
||||
#include <avr32/io.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
#if !defined(__INCLUDE_FROM_SPI_H)
|
||||
#error Do not include this file directly. Include LUFA/Drivers/Peripheral/SPI.h instead.
|
||||
#endif
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 1. */
|
||||
#define SPI_SPEED_FCPU_DIV_1 0
|
||||
|
||||
/** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */
|
||||
#define SPI_SPEED_FCPU_DIV_32 AVR32_SPI_MR_FDIV_MASK
|
||||
|
||||
/** SPI chip selection mode for direct peripheral-to-CS pin connections. */
|
||||
#define SPI_CS_4BITDECODER AVR32_SPI_MR_PSDEC_MASK
|
||||
|
||||
/** SPI chip selection mode for peripheral CS pin connections through a 4-bit decoder. */
|
||||
#define SPI_CS_DIRECT 0
|
||||
|
||||
/** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into slave mode. */
|
||||
#define SPI_MODE_SLAVE 0
|
||||
|
||||
/** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into master mode. */
|
||||
#define SPI_MODE_MASTER AVR32_SPI_MR_MSTR_MASK
|
||||
|
||||
/* Inline Functions: */
|
||||
/** Initialises the SPI subsystem, ready for transfers. Must be called before calling any other
|
||||
* SPI routines.
|
||||
*
|
||||
* \note The individual AVR32 chip select control registers are left at their defaults; it is up to the user
|
||||
* to configure these seperately once the SPI module has been initialized.
|
||||
*
|
||||
* \note The physical GPIO pins for the AVR32's SPI are not altered; it is up to the user to
|
||||
* configure these seperately to connect the SPI module to the desired GPIO pins via the
|
||||
* GPIO MUX registers.
|
||||
*
|
||||
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the SPI_SPEED_*,
|
||||
* SPI_CS_* and SPI_MODE_* masks
|
||||
*/
|
||||
static inline void SPI_Init(const uintN_t SPIOptions)
|
||||
{
|
||||
AVR32_PM.pbamask = (1 << 5);
|
||||
|
||||
AVR32_SPI.CR.swrst = true;
|
||||
AVR32_SPI.CR.spien = true;
|
||||
AVR32_SPI.mr = SPIOptions;
|
||||
}
|
||||
|
||||
/** Turns off the SPI driver, disabling and returning used hardware to their default configuration. */
|
||||
static inline void SPI_ShutDown(void)
|
||||
{
|
||||
AVR32_SPI.cr = AVR32_SPI_CR_SPIDIS_MASK;
|
||||
|
||||
AVR32_PM.pbamask &= ~(1 << 5);
|
||||
}
|
||||
|
||||
/** Sends and receives a transfer through the SPI interface, blocking until the transfer is complete.
|
||||
* The width of the data that is transferred is dependant on the settings of the currently selected
|
||||
* peripheral.
|
||||
*
|
||||
* \param[in] Data Data to send through the SPI interface
|
||||
*
|
||||
* \return Response data from the attached SPI device
|
||||
*/
|
||||
static inline uint16_t SPI_Transfer(const uint16_t Data) ATTR_ALWAYS_INLINE;
|
||||
static inline uint16_t SPI_Transfer(const uint16_t Data)
|
||||
{
|
||||
while (!(AVR32_SPI.SR.tdre));
|
||||
AVR32_SPI.TDR.td = Data;
|
||||
|
||||
while ((AVR32_SPI.sr & (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) !=
|
||||
(AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK));
|
||||
return AVR32_SPI.RDR.rd;
|
||||
}
|
||||
|
||||
/** Sends a transfer through the SPI interface, blocking until the transfer is complete. The response
|
||||
* data sent to from the attached SPI device is ignored. The width of the data that is transferred is
|
||||
* dependant on the settings of the currently selected peripheral.
|
||||
*
|
||||
* \param[in] Data Data to send through the SPI interface
|
||||
*/
|
||||
static inline void SPI_Send(const uint16_t Data) ATTR_ALWAYS_INLINE;
|
||||
static inline void SPI_Send(const uint16_t Data)
|
||||
{
|
||||
while (!(AVR32_SPI.SR.tdre));
|
||||
AVR32_SPI.TDR.td = Data;
|
||||
}
|
||||
|
||||
/** Sends a dummy transfer through the SPI interface, blocking until the transfer is complete. The response
|
||||
* data from the attached SPI device is returned. The width of the data that is transferred is dependant on
|
||||
* the settings of the currently selected peripheral.
|
||||
*
|
||||
* \return The response data from the attached SPI device
|
||||
*/
|
||||
static inline uint16_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint16_t SPI_Receive(void)
|
||||
{
|
||||
while (!(AVR32_SPI.SR.tdre));
|
||||
AVR32_SPI.TDR.td = 0x0000;
|
||||
|
||||
while ((AVR32_SPI.sr & (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) !=
|
||||
(AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK));
|
||||
return AVR32_SPI.RDR.rd;
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
@ -30,16 +30,16 @@
|
|||
|
||||
/** \file
|
||||
*
|
||||
* ADC driver for the 8-Bit AVRs containing a hardware ADC module.
|
||||
* ADC driver for the AT90USB1287, AT90USB1286, AT90USB647, AT90USB646, ATMEGA16U4 and ATMEGA32U4 AVRs.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the ADC driver
|
||||
* dispatch header located in LUFA/Drivers/Peripheral/ADC.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_ADC
|
||||
* @defgroup Group_ADC_AVR8 8-Bit AVR ADC Driver
|
||||
* @defgroup Group_ADC_AVRU4U6U7 Series U4, U6 and U7 Model ADC Driver
|
||||
*
|
||||
* ADC driver for 8-Bit AVRs containing a hardware ADC module.
|
||||
* ADC driver for the AT90USB1287, AT90USB1286, AT90USB647, AT90USB646, ATMEGA16U4 and ATMEGA32U4 AVRs.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the ADC driver
|
||||
* dispatch header located in LUFA/Drivers/Peripheral/ADC.h.
|
||||
|
|
@ -47,10 +47,12 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __ADC_AVR8_H__
|
||||
#define __ADC_AVR8_H__
|
||||
#ifndef __ADC_AVRU4U6U7_H__
|
||||
#define __ADC_AVRU4U6U7_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
|
@ -51,7 +51,6 @@
|
|||
#define __SPI_AVR8_H__
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Preprocessor Checks: */
|
||||
|
|
@ -118,7 +117,7 @@
|
|||
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the SPI_SPEED_*,
|
||||
* SPI_SCK_*, SPI_SAMPLE_* and SPI_MODE_* masks
|
||||
*/
|
||||
static inline void SPI_Init(const uintN_t SPIOptions)
|
||||
static inline void SPI_Init(const uint8_t SPIOptions)
|
||||
{
|
||||
DDRB |= ((1 << 1) | (1 << 2));
|
||||
PORTB |= ((1 << 0) | (1 << 3));
|
||||
|
|
@ -143,14 +142,14 @@
|
|||
|
||||
/** Sends and receives a byte through the SPI interface, blocking until the transfer is complete.
|
||||
*
|
||||
* \param[in] Data Byte to send through the SPI interface
|
||||
* \param[in] Byte Byte to send through the SPI interface
|
||||
*
|
||||
* \return Response byte from the attached SPI device
|
||||
*/
|
||||
static inline uint8_t SPI_Transfer(const uint8_t Data) ATTR_ALWAYS_INLINE;
|
||||
static inline uint8_t SPI_Transfer(const uint8_t Data)
|
||||
static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
|
||||
static inline uint8_t SPI_TransferByte(const uint8_t Byte)
|
||||
{
|
||||
SPDR = Data;
|
||||
SPDR = Byte;
|
||||
while (!(SPSR & (1 << SPIF)));
|
||||
return SPDR;
|
||||
}
|
||||
|
|
@ -158,12 +157,12 @@
|
|||
/** Sends a byte through the SPI interface, blocking until the transfer is complete. The response
|
||||
* byte sent to from the attached SPI device is ignored.
|
||||
*
|
||||
* \param[in] Data Byte to send through the SPI interface
|
||||
* \param[in] Byte Byte to send through the SPI interface
|
||||
*/
|
||||
static inline void SPI_Send(const uint8_t Data) ATTR_ALWAYS_INLINE;
|
||||
static inline void SPI_Send(const uint8_t Data)
|
||||
static inline void SPI_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
|
||||
static inline void SPI_SendByte(const uint8_t Byte)
|
||||
{
|
||||
SPDR = Data;
|
||||
SPDR = Byte;
|
||||
while (!(SPSR & (1 << SPIF)));
|
||||
}
|
||||
|
||||
|
|
@ -172,28 +171,13 @@
|
|||
*
|
||||
* \return The response byte from the attached SPI device
|
||||
*/
|
||||
static inline uint8_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
static inline uint8_t SPI_Receive(void)
|
||||
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;
|
||||
}
|
||||
|
||||
#if defined(__DOXYGEN__)
|
||||
/** Alias for \ref SPI_Transfer(), for compatibility with legacy LUFA applications. */
|
||||
static inline uint8_t SPI_TransferByte(const uint8_t Byte) ATTR_DEPRECATED;
|
||||
|
||||
/** Alias for \ref SPI_Send(), for compatibility with legacy LUFA applications. */
|
||||
static inline void SPI_SendByte(const uint8_t Byte) ATTR_DEPRECATED;
|
||||
|
||||
/** Alias for \ref SPI_Receive(), for compatibility with legacy LUFA applications. */
|
||||
static inline uint8_t SPI_ReceiveByte(void) ATTR_DEPRECATED;
|
||||
#else
|
||||
#define SPI_TransferByte(x) SPI_Transfer(x)
|
||||
#define SPI_SendByte(x) SPI_Send(x)
|
||||
#define SPI_ReceiveByte() SPI_Receive()
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
|
|
@ -30,16 +30,16 @@
|
|||
|
||||
/** \file
|
||||
*
|
||||
* Master mode TWI driver for the 8-Bit AVRs containing a hardware TWI module.
|
||||
* Master mode TWI driver for the AT90USB1287, AT90USB1286, AT90USB647, AT90USB646, ATMEGA16U4 and ATMEGA32U4 AVRs.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the TWI driver
|
||||
* dispatch header located in LUFA/Drivers/Peripheral/TWI.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_TWI
|
||||
* @defgroup Group_TWI_AVR8 8-Bit AVR TWI Driver
|
||||
* @defgroup Group_TWI_AVRU4U6U7 Series U4, U6 and U7 Model TWI Driver
|
||||
*
|
||||
* Master mode TWI driver for the 8-Bit AVRs containing a hardware TWI module.
|
||||
* Master mode TWI driver for the AT90USB1287, AT90USB1286, AT90USB647, AT90USB646, ATMEGA16U4 and ATMEGA32U4 AVRs.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the TWI driver
|
||||
* dispatch header located in LUFA/Drivers/Peripheral/TWI.h.
|
||||
|
|
@ -47,10 +47,12 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __TWI_AVR8_H__
|
||||
#define __TWI_AVR8_H__
|
||||
#ifndef __TWI_AVRU4U6U7_H__
|
||||
#define __TWI_AVRU4U6U7_H__
|
||||
|
||||
/* Includes: */
|
||||
#include "../../../Common/Common.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <stdbool.h>
|
||||
#include <util/twi.h>
|
||||
|
|
@ -30,10 +30,7 @@
|
|||
|
||||
/** \file
|
||||
*
|
||||
* This file is the master dispatch header file for the device-specific SPI driver, for AVRs containing a SPI.
|
||||
*
|
||||
* User code should include this file, which will in turn include the correct SPI driver header file for the
|
||||
* currently selected AVR model.
|
||||
* Hardware SPI subsystem driver for the supported USB AVRs models.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PeripheralDrivers
|
||||
|
|
@ -53,18 +50,133 @@
|
|||
#ifndef __SPI_H__
|
||||
#define __SPI_H__
|
||||
|
||||
/* Macros: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
#define __INCLUDE_FROM_SPI_H
|
||||
#endif
|
||||
|
||||
/* Includes: */
|
||||
#include "../../Common/Common.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(__AVR32__)
|
||||
#include "AVR32/SPI.h"
|
||||
#elif defined(__AVR__)
|
||||
#include "AVR8/SPI.h"
|
||||
/* 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
|
||||
|
|
|
|||
|
|
@ -30,11 +30,7 @@
|
|||
|
||||
/** \file
|
||||
*
|
||||
* This file is the master dispatch header file for the device-specific USART driver, for AVRs containing a
|
||||
* USART.
|
||||
*
|
||||
* User code should include this file, which will in turn include the correct USART driver header file for
|
||||
* the currently selected AVR model.
|
||||
* Driver for the USART subsystem on supported USB AVRs.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_PeripheralDrivers
|
||||
|
|
@ -54,27 +50,42 @@
|
|||
#ifndef __SERIAL_H__
|
||||
#define __SERIAL_H__
|
||||
|
||||
/* Macros: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
#define __INCLUDE_FROM_SERIAL_H
|
||||
#endif
|
||||
|
||||
/* Includes: */
|
||||
#include "../../Common/Common.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../../Common/Common.h"
|
||||
#include "../Misc/TerminalCodes.h"
|
||||
|
||||
#if defined(__AVR32__)
|
||||
#include "AVR32/Serial.h"
|
||||
#elif defined(__AVR__)
|
||||
#include "AVR8/Serial.h"
|
||||
#endif
|
||||
|
||||
/* 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.
|
||||
*
|
||||
|
|
@ -88,6 +99,58 @@
|
|||
*/
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,8 +57,6 @@
|
|||
#include <avr/io.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../Common/Common.h"
|
||||
|
||||
#include "Serial.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
|
|
|
|||
|
|
@ -57,13 +57,11 @@
|
|||
#endif
|
||||
|
||||
/* Includes: */
|
||||
#include "../../Common/Common.h"
|
||||
|
||||
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || \
|
||||
defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB647__) || \
|
||||
defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || \
|
||||
defined(__AVR_ATmega32U6__))
|
||||
#include "AVR8/TWI.h"
|
||||
#include "AVRU4U6U7/TWI.h"
|
||||
#else
|
||||
#error "TWI is not available for the currently selected AVR model."
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue