123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #ifndef __DATAFLASH_USER_H__
- #define __DATAFLASH_USER_H__
-
-
-
- #if !defined(__INCLUDE_FROM_DATAFLASH_H)
- #error Do not include this file directly. Include LUFA/Drivers/Board/Dataflash.h instead.
- #endif
-
- #if !defined(__DOXYGEN__)
-
- #define DATAFLASH_CHIPCS_MASK
- #define DATAFLASH_CHIPCS_DDR
- #define DATAFLASH_CHIPCS_PORT
- #endif
-
-
-
- #define DATAFLASH_TOTALCHIPS 1
-
- #define DATAFLASH_NO_CHIP 0
-
- #define DATAFLASH_CHIP1
-
- #define DATAFLASH_CHIP2
-
- #define DATAFLASH_PAGE_SIZE
-
- #define DATAFLASH_PAGES
-
- #if !defined(__DOXYGEN__)
-
- static inline void Dataflash_Init(void)
- {
- DATAFLASH_CHIPCS_DDR |= DATAFLASH_CHIPCS_MASK;
- DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;
- }
-
- static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline uint8_t Dataflash_TransferByte(const uint8_t Byte)
- {
-
- }
-
- static inline void Dataflash_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline void Dataflash_SendByte(const uint8_t Byte)
- {
-
- }
-
- static inline uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
- static inline uint8_t Dataflash_ReceiveByte(void)
- {
-
- }
-
- static inline uint8_t Dataflash_GetSelectedChip(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
- static inline uint8_t Dataflash_GetSelectedChip(void)
- {
- return (~DATAFLASH_CHIPCS_PORT & DATAFLASH_CHIPCS_MASK);
- }
-
- static inline void Dataflash_SelectChip(const uint8_t ChipMask) ATTR_ALWAYS_INLINE;
- static inline void Dataflash_SelectChip(const uint8_t ChipMask)
- {
- DATAFLASH_CHIPCS_PORT = ((DATAFLASH_CHIPCS_PORT | DATAFLASH_CHIPCS_MASK) & ~ChipMask);
- }
-
- static inline void Dataflash_DeselectChip(void) ATTR_ALWAYS_INLINE;
- static inline void Dataflash_DeselectChip(void)
- {
- Dataflash_SelectChip(DATAFLASH_NO_CHIP);
- }
-
- static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)
- {
- Dataflash_DeselectChip();
- if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))
- return;
- #if (DATAFLASH_TOTALCHIPS == 2)
- if (PageAddress & 0x01)
- Dataflash_SelectChip(DATAFLASH_CHIP2);
- else
- Dataflash_SelectChip(DATAFLASH_CHIP1);
- #else
- Dataflash_SelectChip(DATAFLASH_CHIP1);
- #endif
- }
-
- static inline void Dataflash_ToggleSelectedChipCS(void)
- {
- uint8_t SelectedChipMask = Dataflash_GetSelectedChip();
- Dataflash_DeselectChip();
- Dataflash_SelectChip(SelectedChipMask);
- }
-
- static inline void Dataflash_WaitWhileBusy(void)
- {
- Dataflash_ToggleSelectedChipCS();
- Dataflash_SendByte(DF_CMD_GETSTATUS);
- while (!(Dataflash_ReceiveByte() & DF_STATUS_READY));
- Dataflash_ToggleSelectedChipCS();
- }
-
- static inline void Dataflash_SendAddressBytes(uint16_t PageAddress,
- const uint16_t BufferByte)
- {
- #if (DATAFLASH_TOTALCHIPS == 2)
- PageAddress >>= 1;
- #endif
- Dataflash_SendByte(PageAddress >> 5);
- Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));
- Dataflash_SendByte(BufferByte);
- }
- #endif
- #endif
|