]> git.donarmstrong.com Git - qmk_firmware.git/blob - lib/lufa/Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.h
Merge commit '60b30c036397cb5627fa374bb930794b225daa29' as 'lib/lufa'
[qmk_firmware.git] / lib / lufa / Demos / Device / LowLevel / MassStorage / Lib / DataflashManager.h
1 /*
2              LUFA Library
3      Copyright (C) Dean Camera, 2017.
4
5   dean [at] fourwalledcubicle [dot] com
6            www.lufa-lib.org
7 */
8
9 /*
10   Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
21   The author disclaims 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
28   this software.
29 */
30
31 /** \file
32  *
33  *  Header file for DataflashManager.c.
34  */
35
36 #ifndef _DATAFLASH_MANAGER_H_
37 #define _DATAFLASH_MANAGER_H_
38
39         /* Includes: */
40                 #include <avr/io.h>
41
42                 #include "../MassStorage.h"
43                 #include "../Descriptors.h"
44
45                 #include <LUFA/Common/Common.h>
46                 #include <LUFA/Drivers/USB/USB.h>
47                 #include <LUFA/Drivers/Board/Dataflash.h>
48
49         /* Preprocessor Checks: */
50                 #if (DATAFLASH_PAGE_SIZE % 16)
51                         #error Dataflash page size must be a multiple of 16 bytes.
52                 #endif
53
54         /* Defines: */
55                 /** Total number of bytes of the storage medium, comprised of one or more Dataflash ICs. */
56                 #define VIRTUAL_MEMORY_BYTES                ((uint32_t)DATAFLASH_PAGES * DATAFLASH_PAGE_SIZE * DATAFLASH_TOTALCHIPS)
57
58                 /** Block size of the device. This is kept at 512 to remain compatible with the OS despite the underlying
59                  *  storage media (Dataflash) using a different native block size. Do not change this value.
60                  */
61                 #define VIRTUAL_MEMORY_BLOCK_SIZE           512
62
63                 /** Total number of blocks of the virtual memory for reporting to the host as the device's total capacity. Do not
64                  *  change this value; change VIRTUAL_MEMORY_BYTES instead to alter the media size.
65                  */
66                 #define VIRTUAL_MEMORY_BLOCKS               (VIRTUAL_MEMORY_BYTES / VIRTUAL_MEMORY_BLOCK_SIZE)
67
68                 /** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */
69                 #define LUN_MEDIA_BLOCKS                    (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)
70
71         /* Function Prototypes: */
72                 void DataflashManager_WriteBlocks(const uint32_t BlockAddress,
73                                                   uint16_t TotalBlocks);
74                 void DataflashManager_ReadBlocks(const uint32_t BlockAddress,
75                                                  uint16_t TotalBlocks);
76                 void DataflashManager_WriteBlocks_RAM(const uint32_t BlockAddress,
77                                                       uint16_t TotalBlocks,
78                                                       uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);
79                 void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress,
80                                                      uint16_t TotalBlocks,
81                                                      uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);
82                 void DataflashManager_ResetDataflashProtections(void);
83                 bool DataflashManager_CheckDataflashOperation(void);
84
85 #endif
86