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)
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/>.
27 #include "drivers/bus.h"
28 #include "drivers/dma.h"
36 } flashDeviceIoMode_e
;
38 typedef struct flashDeviceIO_s
{
40 extDevice_t
*dev
; // Device interface dependent handle (spi/i2c)
42 QUADSPI_TypeDef
*quadSpi
;
45 flashDeviceIoMode_e mode
;
48 typedef struct flashDevice_s
{
49 const struct flashVTable_s
*vTable
;
50 flashGeometry_t geometry
;
51 uint32_t currentWriteAddress
;
53 // Whether we've performed an action that could have made the device busy
54 // for writes. This allows us to avoid polling for writable status
55 // when it is definitely ready already.
59 void (*callback
)(uint32_t arg
);
63 typedef struct flashVTable_s
{
64 bool (*isReady
)(flashDevice_t
*fdevice
);
65 bool (*waitForReady
)(flashDevice_t
*fdevice
);
66 void (*eraseSector
)(flashDevice_t
*fdevice
, uint32_t address
);
67 void (*eraseCompletely
)(flashDevice_t
*fdevice
);
68 void (*pageProgramBegin
)(flashDevice_t
*fdevice
, uint32_t address
, void (*callback
)(uint32_t length
));
69 uint32_t (*pageProgramContinue
)(flashDevice_t
*fdevice
, uint8_t const **buffers
, uint32_t *bufferSizes
, uint32_t bufferCount
);
70 void (*pageProgramFinish
)(flashDevice_t
*fdevice
);
71 void (*pageProgram
)(flashDevice_t
*fdevice
, uint32_t address
, const uint8_t *data
, uint32_t length
, void (*callback
)(uint32_t length
));
72 void (*flush
)(flashDevice_t
*fdevice
);
73 int (*readBytes
)(flashDevice_t
*fdevice
, uint32_t address
, uint8_t *buffer
, uint32_t length
);
74 const flashGeometry_t
*(*getGeometry
)(flashDevice_t
*fdevice
);