Update FrSky SPI RX.md
[betaflight.git] / src / main / drivers / flash.h
blobd811e77f1e68721f2905c539ba9d94e030b95203
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include <stdint.h>
25 #include "pg/flash.h"
26 #include "drivers/io.h"
28 // Maximum page size of all supported SPI flash devices.
29 // Used to detect flashfs allocation size being too small.
30 #define FLASH_MAX_PAGE_SIZE 2048
32 #define SPIFLASH_INSTRUCTION_RDID 0x9F
34 typedef enum {
35 FLASH_TYPE_NOR = 0,
36 FLASH_TYPE_NAND
37 } flashType_e;
39 typedef struct flashGeometry_s {
40 uint16_t sectors; // Count of the number of erasable blocks on the device
41 uint16_t pageSize; // In bytes
42 uint32_t sectorSize; // This is just pagesPerSector * pageSize
43 uint32_t totalSize; // This is just sectorSize * sectors
44 uint16_t pagesPerSector;
45 flashType_e flashType;
46 } flashGeometry_t;
48 void flashPreInit(const flashConfig_t *flashConfig);
49 bool flashInit(const flashConfig_t *flashConfig);
51 bool flashIsReady(void);
52 bool flashWaitForReady(uint32_t timeoutMillis);
53 void flashEraseSector(uint32_t address);
54 void flashEraseCompletely(void);
55 void flashPageProgramBegin(uint32_t address);
56 void flashPageProgramContinue(const uint8_t *data, int length);
57 void flashPageProgramFinish(void);
58 void flashPageProgram(uint32_t address, const uint8_t *data, int length);
59 int flashReadBytes(uint32_t address, uint8_t *buffer, int length);
60 void flashFlush(void);
61 const flashGeometry_t *flashGetGeometry(void);