Board Dataflash driver now allows for dataflash ICs which use different shifts for...
[pub/USBasp.git] / LUFA / Drivers / Board / Dataflash.h
index 2b682d7..aa0c089 100644 (file)
        /* Includes: */\r
        #include "../AT90USBXXX/SPI.h"\r
        #include "../../Common/Common.h"\r
-       \r
-       #if !defined(BOARD)\r
-               #error BOARD must be set in makefile to a value specified in BoardTypes.h.\r
-       #elif (BOARD == BOARD_USBKEY)\r
-               #include "USBKEY/Dataflash.h"\r
-       #elif (BOARD == BOARD_STK525)\r
-               #include "STK525/Dataflash.h"\r
-       #elif (BOARD == BOARD_STK526)\r
-               #include "STK526/Dataflash.h"\r
-       #elif (BOARD == BOARD_USER)\r
-               #include "Board/Dataflash.h"\r
-       #else\r
-               #error The selected board does not contain a dataflash IC.\r
-       #endif\r
-       \r
+               \r
        /* Enable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
                        extern "C" {\r
                        #define Dataflash_DeselectChip()             Dataflash_SelectChip(DATAFLASH_NO_CHIP)\r
 \r
                /* Inline Functions: */\r
-                       /** Initializes the dataflash driver (including the SPI driver) so that commands and data may be\r
-                        *  sent to an attached dataflash IC.\r
-                        *\r
-                        *  \param PrescalerMask  SPI prescaler mask, see SPI.h documentation\r
-                        */\r
-                       static inline void Dataflash_Init(const uint8_t PrescalerMask)\r
-                       {\r
-                               DATAFLASH_CHIPCS_DDR  |= DATAFLASH_CHIPCS_MASK;\r
-                               DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;\r
-\r
-                               SPI_Init(PrescalerMask, true);\r
-                       }\r
-\r
                        /** Sends a byte to the currently selected dataflash IC, and returns a byte from the dataflash.\r
                         *\r
                         *  \param Byte of data to send to the dataflash\r
                        {\r
                                return SPI_ReceiveByte();\r
                        }\r
+\r
+               /* Includes: */\r
+                       #if !defined(BOARD)\r
+                               #error BOARD must be set in makefile to a value specified in BoardTypes.h.\r
+                       #elif (BOARD == BOARD_USBKEY)\r
+                               #include "USBKEY/Dataflash.h"\r
+                       #elif (BOARD == BOARD_STK525)\r
+                               #include "STK525/Dataflash.h"\r
+                       #elif (BOARD == BOARD_STK526)\r
+                               #include "STK526/Dataflash.h"\r
+                       #elif (BOARD == BOARD_USER)\r
+                               #include "Board/Dataflash.h"\r
+                       #else\r
+                               #error The selected board does not contain a dataflash IC.\r
+                       #endif\r
+\r
+               /* Inline Functions: */\r
+                       /** Initializes the dataflash driver (including the SPI driver) so that commands and data may be\r
+                        *  sent to an attached dataflash IC.\r
+                        *\r
+                        *  \param PrescalerMask  SPI prescaler mask, see SPI.h documentation\r
+                        */\r
+                       static inline void Dataflash_Init(const uint8_t PrescalerMask)\r
+                       {\r
+                               DATAFLASH_CHIPCS_DDR  |= DATAFLASH_CHIPCS_MASK;\r
+                               DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;\r
+\r
+                               SPI_Init(PrescalerMask, true);\r
+                       }\r
                        \r
                        /** Toggles the select line of the currently selected dataflash IC, so that it is ready to receive\r
                         *  a new command.\r
                         */\r
                        static inline void Dataflash_ToggleSelectedChipCS(void)\r
                        {\r
-                               #if (DATAFLASH_TOTALCHIPS == 2)\r
-                                       uint8_t SelectedChipMask = Dataflash_GetSelectedChip();\r
+                               uint8_t SelectedChipMask = Dataflash_GetSelectedChip();\r
                                        \r
-                                       Dataflash_DeselectChip();\r
-                                       Dataflash_SelectChip(SelectedChipMask);\r
-                               #else\r
-                                       Dataflash_DeselectChip();\r
-                                       Dataflash_SelectChip(DATAFLASH_CHIP1);  \r
-                               #endif\r
+                               Dataflash_DeselectChip();\r
+                               Dataflash_SelectChip(SelectedChipMask);\r
                        }\r
 \r
                        /** Spinloops while the currently selected dataflash is busy executing a command, such as a main\r
 \r
                        /** Selects a dataflash IC from the given page number, which should range from 0 to\r
                         *  ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one\r
-                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside the total number\r
-                        *  of pages contained in the boards dataflash ICs, all dataflash ICs are deselected.\r
+                        *  dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside\r
+                        *  the total number of pages contained in the boards dataflash ICs, all dataflash ICs\r
+                        *  are deselected.\r
                         *\r
                         *  \param PageAddress  Address of the page to manipulate, ranging from\r
                         *                      ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).\r
                         */\r
-                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)\r
-                       {\r
-                               Dataflash_DeselectChip();\r
-                               \r
-                               if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))\r
-                                 return;\r
-\r
-                               #if (DATAFLASH_TOTALCHIPS == 2)\r
-                                       if (PageAddress & 0x01)\r
-                                         Dataflash_SelectChip(DATAFLASH_CHIP2);\r
-                                       else\r
-                                         Dataflash_SelectChip(DATAFLASH_CHIP1);\r
-                               #else\r
-                                       Dataflash_SelectChip(DATAFLASH_CHIP1);\r
-                               #endif\r
-                       }\r
+                       static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress);\r
 \r
                        /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with\r
                         *  dataflash commands which require a complete 24-byte address.\r
                         *  \param PageAddress  Page address within the selected dataflash IC\r
                         *  \param BufferByte   Address within the dataflash's buffer\r
                         */\r
-                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)\r
-                       {       \r
-                               #if (DATAFLASH_TOTALCHIPS == 2)\r
-                                       PageAddress >>= 1;\r
-                               #endif\r
-\r
-                               Dataflash_SendByte(PageAddress >> 5);\r
-                               Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));\r
-                               Dataflash_SendByte(BufferByte);\r
-                       }\r
+                       static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte);\r
 \r
        /* Disable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r