X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/a2d18e46f8c30391cf3c06f1f93c50cb24d5e1ae..0da99447d3e88e83f9977501bee56af5c7aa56c0:/LUFA/Drivers/Board/XMEGA/B1_XPLAINED/Dataflash.h diff --git a/LUFA/Drivers/Board/XMEGA/B1_XPLAINED/Dataflash.h b/LUFA/Drivers/Board/XMEGA/B1_XPLAINED/Dataflash.h index 74a215b6c..d7ad64a5c 100644 --- a/LUFA/Drivers/Board/XMEGA/B1_XPLAINED/Dataflash.h +++ b/LUFA/Drivers/Board/XMEGA/B1_XPLAINED/Dataflash.h @@ -42,6 +42,11 @@ * * Board specific Dataflash driver header for the Atmel XMEGA A3BU Xplained board. * + * + * + * + *
NameInfoSelect PinSPI Port
DATAFLASH_CHIP1AT45DB642D (8MB)PORTD.2USARTC0 (In SPI Mode, Remapped)
+ * * @{ */ @@ -51,6 +56,7 @@ /* Includes: */ #include "../../../../Common/Common.h" #include "../../../Misc/AT45DB642D.h" + #include "../../../Peripheral/SerialSPI.h" /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_DATAFLASH_H) @@ -70,10 +76,10 @@ #define DATAFLASH_TOTALCHIPS 1 /** Mask for no dataflash chip selected. */ - #define DATAFLASH_NO_CHIP DATAFLASH_CHIPCS_MASK + #define DATAFLASH_NO_CHIP 0 /** Mask for the first dataflash chip selected. */ - #define DATAFLASH_CHIP1 0 + #define DATAFLASH_CHIP1 (1 << 2) /** Internal main memory page size for the board's dataflash ICs. */ #define DATAFLASH_PAGE_SIZE 1024 @@ -87,8 +93,12 @@ */ static inline void Dataflash_Init(void) { - DATAFLASH_CHIPCS_PORT.DIRSET = DATAFLASH_CHIPCS_MASK; - DATAFLASH_CHIPCS_PORT.OUTSET = DATAFLASH_CHIPCS_MASK; + DATAFLASH_CHIPCS_PORT.DIRSET = DATAFLASH_CHIPCS_MASK; + + PORTCFG.MPCMASK = DATAFLASH_CHIPCS_MASK; + DATAFLASH_CHIPCS_PORT.PIN0CTRL = PORT_INVEN_bm; + + PORTC.REMAP |= PORT_USART0_bm; } /** Sends a byte to the currently selected dataflash IC, and returns a byte from the dataflash. @@ -100,9 +110,7 @@ static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE; static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) { - // TODO: USART in SPI mode on PORT C - #warning The Dataflash driver for the selected board is currently incomplete and non-functional. - return 0; + return SerialSPI_TransferByte(&USARTC0, Byte); } /** Sends a byte to the currently selected dataflash IC, and ignores the next byte from the dataflash. @@ -112,7 +120,7 @@ static inline void Dataflash_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE; static inline void Dataflash_SendByte(const uint8_t Byte) { - return; // TODO + SerialSPI_SendByte(&USARTC0, Byte); } /** Sends a dummy byte to the currently selected dataflash IC, and returns the next byte from the dataflash. @@ -122,7 +130,7 @@ static inline uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; static inline uint8_t Dataflash_ReceiveByte(void) { - return 0; // TODO + return SerialSPI_ReceiveByte(&USARTC0); } /** Determines the currently selected dataflash chip. @@ -144,7 +152,8 @@ static inline void Dataflash_SelectChip(const uint8_t ChipMask) ATTR_ALWAYS_INLINE; static inline void Dataflash_SelectChip(const uint8_t ChipMask) { - DATAFLASH_CHIPCS_PORT.OUT = ((DATAFLASH_CHIPCS_PORT.OUT & ~DATAFLASH_CHIPCS_MASK) | ChipMask); + DATAFLASH_CHIPCS_PORT.OUTCLR = DATAFLASH_CHIPCS_MASK; + DATAFLASH_CHIPCS_PORT.OUTSET = (ChipMask & DATAFLASH_CHIPCS_MASK); } /** Deselects the current dataflash chip, so that no dataflash is selected. */ @@ -170,10 +179,7 @@ if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS)) return; - if (PageAddress & 0x01) - Dataflash_SelectChip(DATAFLASH_CHIP2); - else - Dataflash_SelectChip(DATAFLASH_CHIP1); + Dataflash_SelectChip(DATAFLASH_CHIP1); } /** Toggles the select line of the currently selected dataflash IC, so that it is ready to receive @@ -207,8 +213,6 @@ static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte) { - PageAddress >>= 1; - Dataflash_SendByte(PageAddress >> 5); Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8)); Dataflash_SendByte(BufferByte);