aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-08-23 08:37:11 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-08-23 08:37:11 +0000
commitf229502d9addacfbefe955a47931b980bfbb1a10 (patch)
tree17311a066348fa23088257d51a95354bdb152885 /LUFA
parent1e8df8951a3335e4b45ad0c25a82df3d90d785f3 (diff)
downloadlufa-f229502d9addacfbefe955a47931b980bfbb1a10.tar.gz
lufa-f229502d9addacfbefe955a47931b980bfbb1a10.tar.bz2
lufa-f229502d9addacfbefe955a47931b980bfbb1a10.zip
Fixed AVRISP programmer demo -- can now connect to a target and read/write Sig/Lock/Fuse/OSCCAL bytes successfully.
Changed SPI_Init() to allow for the clock polarity and data sample modes to be set. Changed Dataflash_Init() to no longer call SPI_Init() automatically.
Diffstat (limited to 'LUFA')
-rw-r--r--LUFA/Drivers/Board/Dataflash.h10
-rw-r--r--LUFA/Drivers/Peripheral/SPI.h31
-rw-r--r--LUFA/ManPages/ChangeLog.txt1
-rw-r--r--LUFA/ManPages/MigrationInformation.txt4
4 files changed, 32 insertions, 14 deletions
diff --git a/LUFA/Drivers/Board/Dataflash.h b/LUFA/Drivers/Board/Dataflash.h
index acdcc4c40..8c2b69d99 100644
--- a/LUFA/Drivers/Board/Dataflash.h
+++ b/LUFA/Drivers/Board/Dataflash.h
@@ -164,17 +164,13 @@
#endif
/* Inline Functions: */
- /** Initializes the dataflash driver (including the SPI driver) so that commands and data may be
- * sent to an attached dataflash IC.
- *
- * \param[in] PrescalerMask SPI prescaler mask, see SPI.h documentation
+ /** Initializes the dataflash driver so that commands and data may be sent to an attached dataflash IC.
+ * The AVR's SPI driver MUST be initialized before any of the dataflash commands are used.
*/
- static inline void Dataflash_Init(const uint8_t PrescalerMask)
+ static inline void Dataflash_Init(void)
{
DATAFLASH_CHIPCS_DDR |= DATAFLASH_CHIPCS_MASK;
DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;
-
- SPI_Init(PrescalerMask, true);
}
/** Toggles the select line of the currently selected dataflash IC, so that it is ready to receive
diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h
index df741d7b8..dcc58ce49 100644
--- a/LUFA/Drivers/Peripheral/SPI.h
+++ b/LUFA/Drivers/Peripheral/SPI.h
@@ -61,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: */
@@ -86,23 +86,40 @@
/** 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);
diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt
index 058d55c5c..da4c007f0 100644
--- a/LUFA/ManPages/ChangeLog.txt
+++ b/LUFA/ManPages/ChangeLog.txt
@@ -23,6 +23,7 @@
* - Added new CDC_Device_Flush() command to the device mode CDC Class driver
* - Added explicit attribute masks to the device mode demos' descriptors
* - Added return values to the CDC and MIDI class driver transmit functions
+ * - Added extra masks to the SPI driver, changed SPI_Init() so that the clock polarity and sample modes can be set
*
* <b>Fixed:</b>
* - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the
diff --git a/LUFA/ManPages/MigrationInformation.txt b/LUFA/ManPages/MigrationInformation.txt
index f65539d56..d83043182 100644
--- a/LUFA/ManPages/MigrationInformation.txt
+++ b/LUFA/ManPages/MigrationInformation.txt
@@ -14,6 +14,10 @@
*
* <b>Non-USB Library Components</b>
* - The ADC_Off() function has been renamed to \ref ADC_ShutDown() to be consistent with the rest of the library.
+ * - The Dataflash_Init() routine no longer initializes the SPI bus - the SPI bus should be initialized manually via a
+ * call to SPI_Init() before using the Dataflash driver
+ * - The SPI_Init() routine's parameters have changed, so that the clock polarity and data sampling modes can be set. See
+ * the SPI_Init() function documentation for more details
*
* \section Sec_Migration090810 Migrating from 090605 to 090810
*