3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
32 * \brief Master include file for the board dataflash IC driver.
34 * This file is the master dispatch header file for the board-specific dataflash driver, for boards containing
35 * dataflash ICs for external non-volatile storage.
37 * User code should include this file, which will in turn include the correct dataflash driver header file for
38 * the currently selected board.
40 * If the BOARD value is set to BOARD_USER, this will include the /Board/Dataflash.h file in the user project
44 /** \ingroup Group_BoardDrivers
45 * @defgroup Group_Dataflash Dataflash Driver - LUFA/Drivers/Board/Dataflash.h
47 * \section Sec_Dependencies Module Source Dependencies
48 * The following files must be built with any user project that uses this module:
51 * \section Module Description
52 * Dataflash driver. This module provides an easy to use interface for the Dataflash ICs located on many boards,
53 * for the storage of large amounts of data into the Dataflash's non-volatile memory.
55 * If the BOARD value is set to BOARD_USER, this will include the /Board/Dataflash.h file in the user project
56 * directory. Otherwise, it will include the appropriate built in board driver header file.
61 #ifndef __DATAFLASH_H__
62 #define __DATAFLASH_H__
65 #if !defined(__DOXYGEN__)
66 #define __INCLUDE_FROM_DATAFLASH_H
67 #define INCLUDE_FROM_DATAFLASH_H
71 #include "../Peripheral/SPI.h"
72 #include "../../Common/Common.h"
74 /* Enable C linkage for C++ Compilers: */
75 #if defined(__cplusplus)
79 /* Public Interface - May be used in end-application: */
81 #if !defined(__DOXYGEN__)
82 #define __GET_DATAFLASH_MASK2(x, y) x ## y
83 #define __GET_DATAFLASH_MASK(x) __GET_DATAFLASH_MASK2(DATAFLASH_CHIP,x)
86 /** Retrieves the Dataflash chip select mask for the given Dataflash chip index.
88 * \param[in] index Index of the dataflash chip mask to retrieve
90 * \return Mask for the given Dataflash chip's /CS pin
92 #define DATAFLASH_CHIP_MASK(index) __GET_DATAFLASH_MASK(index)
94 /* Inline Functions: */
95 /** Initialises the dataflash driver so that commands and data may be sent to an attached dataflash IC.
96 * The AVR's SPI driver MUST be initialized before any of the dataflash commands are used.
98 static inline void Dataflash_Init(void);
100 /** Determines the currently selected dataflash chip.
102 * \return Mask of the currently selected Dataflash chip, either \ref DATAFLASH_NO_CHIP if no chip is selected
103 * or a DATAFLASH_CHIPn mask (where n is the chip number).
105 static inline uint8_t Dataflash_GetSelectedChip(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
107 /** Selects the given dataflash chip.
109 * \param[in] ChipMask Mask of the Dataflash IC to select, in the form of DATAFLASH_CHIPn mask (where n is
112 static inline void Dataflash_SelectChip(const uint8_t ChipMask
) ATTR_ALWAYS_INLINE
;
114 /** Deselects the current dataflash chip, so that no dataflash is selected. */
115 static inline void Dataflash_DeselectChip(void) ATTR_ALWAYS_INLINE
;
117 /** Selects a dataflash IC from the given page number, which should range from 0 to
118 * ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one
119 * dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside
120 * the total number of pages contained in the boards dataflash ICs, all dataflash ICs
123 * \param[in] PageAddress Address of the page to manipulate, ranging from
124 * ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).
126 static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress
);
128 /** Toggles the select line of the currently selected dataflash IC, so that it is ready to receive
131 static inline void Dataflash_ToggleSelectedChipCS(void);
133 /** Spin-loops while the currently selected dataflash is busy executing a command, such as a main
134 * memory page program or main memory to buffer transfer.
136 static inline void Dataflash_WaitWhileBusy(void);
138 /** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with
139 * dataflash commands which require a complete 24-byte address.
141 * \param[in] PageAddress Page address within the selected dataflash IC
142 * \param[in] BufferByte Address within the dataflash's buffer
144 static inline void Dataflash_SendAddressBytes(uint16_t PageAddress
,
145 const uint16_t BufferByte
);
147 /** Sends a byte to the currently selected dataflash IC, and returns a byte from the dataflash.
149 * \param[in] Byte of data to send to the dataflash
151 * \return Last response byte from the dataflash
153 static inline uint8_t Dataflash_TransferByte(const uint8_t Byte
) ATTR_ALWAYS_INLINE
;
154 static inline uint8_t Dataflash_TransferByte(const uint8_t Byte
)
156 return SPI_TransferByte(Byte
);
159 /** Sends a byte to the currently selected dataflash IC, and ignores the next byte from the dataflash.
161 * \param[in] Byte of data to send to the dataflash
163 static inline void Dataflash_SendByte(const uint8_t Byte
) ATTR_ALWAYS_INLINE
;
164 static inline void Dataflash_SendByte(const uint8_t Byte
)
169 /** Sends a dummy byte to the currently selected dataflash IC, and returns the next byte from the dataflash.
171 * \return Last response byte from the dataflash
173 static inline uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
174 static inline uint8_t Dataflash_ReceiveByte(void)
176 return SPI_ReceiveByte();
180 #if (BOARD == BOARD_NONE)
181 #error The Board Buttons driver cannot be used if the makefile BOARD option is not set.
182 #elif (BOARD == BOARD_USBKEY)
183 #include "USBKEY/Dataflash.h"
184 #elif (BOARD == BOARD_STK525)
185 #include "STK525/Dataflash.h"
186 #elif (BOARD == BOARD_STK526)
187 #include "STK526/Dataflash.h"
188 #elif (BOARD == BOARD_XPLAIN)
189 #include "XPLAIN/Dataflash.h"
190 #elif (BOARD == BOARD_XPLAIN_REV1)
191 #include "XPLAIN/Dataflash.h"
192 #elif (BOARD == BOARD_EVK527)
193 #include "EVK527/Dataflash.h"
194 #elif (BOARD == BOARD_USER)
195 #include "Board/Dataflash.h"
197 #error The selected board does not contain a dataflash IC.
200 /* Disable C linkage for C++ Compilers: */
201 #if defined(__cplusplus)