X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/f1076ac4d6e56bff7fb6d2126746af1108211370..d11ed10c5314c44dc01c06954d1d73d4894cbff8:/LUFA/Drivers/Peripheral/SPI.h diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h index dc8661ad5..6416ceae6 100644 --- a/LUFA/Drivers/Peripheral/SPI.h +++ b/LUFA/Drivers/Peripheral/SPI.h @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, 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 + 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 @@ -41,7 +41,8 @@ * - None * * \section Module Description - * Functions, macros, variables, enums and types related to the setup of a the SPI port. + * 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. * * @{ */ @@ -60,7 +61,7 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ - #define SPI_USE_DOUBLESPEED (1 << 7) + #define SPI_USE_DOUBLESPEED (1 << SPE) #endif /* Public Interface - May be used in end-application: */ @@ -85,28 +86,55 @@ /** 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] PrescalerMask Prescaler mask to set the SPI clock speed - * \param[in] Master If true, sets the SPI system to use master mode, slave if false + * \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 PrescalerMask, const bool Master) + static inline void SPI_Init(const uint8_t SPIOptions) { DDRB |= ((1 << 1) | (1 << 2)); PORTB |= ((1 << 0) | (1 << 3)); - SPCR = ((1 << SPE) | (Master << MSTR) | (1 << CPOL) | (1 << CPHA) | - (PrescalerMask & ~SPI_USE_DOUBLESPEED)); + SPCR = ((1 << SPE) | SPIOptions); - if (PrescalerMask & SPI_USE_DOUBLESPEED) + 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