diff --git a/make/source.mk b/make/source.mk index 0cdc394aff..21454264df 100644 --- a/make/source.mk +++ b/make/source.mk @@ -62,6 +62,7 @@ COMMON_SRC = \ msp/msp_serial.c \ pg/adc.c \ pg/bus_i2c.c \ + pg/flash.c \ pg/pg.c \ scheduler/scheduler.c \ sensors/battery.c \ diff --git a/src/main/drivers/flash.h b/src/main/drivers/flash.h index cd304946f5..7b7dfc78a7 100644 --- a/src/main/drivers/flash.h +++ b/src/main/drivers/flash.h @@ -27,8 +27,3 @@ typedef struct flashGeometry_s { uint32_t totalSize; // This is just sectorSize * sectors uint16_t pagesPerSector; } flashGeometry_t; - -typedef struct flashConfig_s { - ioTag_t csTag; - uint8_t spiDevice; -} flashConfig_t; diff --git a/src/main/drivers/flash_m25p16.c b/src/main/drivers/flash_m25p16.c index 3dbb6dae24..8f986d16f9 100644 --- a/src/main/drivers/flash_m25p16.c +++ b/src/main/drivers/flash_m25p16.c @@ -22,12 +22,15 @@ #ifdef USE_FLASH_M25P16 -#include "flash.h" -#include "flash_m25p16.h" #include "drivers/bus_spi.h" +#include "drivers/flash.h" #include "drivers/io.h" #include "drivers/time.h" +#include "pg/flash.h" + +#include "flash_m25p16.h" + #define M25P16_INSTRUCTION_RDID 0x9F #define M25P16_INSTRUCTION_READ_BYTES 0x03 #define M25P16_INSTRUCTION_READ_STATUS_REG 0x05 @@ -229,6 +232,7 @@ static bool m25p16_readIdentification(void) * Attempts to detect a connected m25p16. If found, true is returned and device capacity can be fetched with * m25p16_getGeometry(). */ + bool m25p16_init(const flashConfig_t *flashConfig) { /* diff --git a/src/main/drivers/flash_m25p16.h b/src/main/drivers/flash_m25p16.h index 60099be8da..1fa8cb7a9d 100644 --- a/src/main/drivers/flash_m25p16.h +++ b/src/main/drivers/flash_m25p16.h @@ -22,7 +22,8 @@ #define M25P16_PAGESIZE 256 -bool m25p16_init(const flashConfig_t *flashConfig); +struct flashConfig_s; +bool m25p16_init(const struct flashConfig_s *flashConfig); void m25p16_eraseSector(uint32_t address); void m25p16_eraseCompletely(void); diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 90200a19d8..5a154e96c6 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -151,20 +151,6 @@ PG_REGISTER_WITH_RESET_FN(pwmConfig_t, pwmConfig, PG_PWM_CONFIG, 0); PG_REGISTER_WITH_RESET_FN(ppmConfig_t, ppmConfig, PG_PPM_CONFIG, 0); #endif -#ifdef USE_FLASHFS -PG_REGISTER_WITH_RESET_FN(flashConfig_t, flashConfig, PG_FLASH_CONFIG, 0); - -void pgResetFn_flashConfig(flashConfig_t *flashConfig) -{ -#ifdef M25P16_CS_PIN - flashConfig->csTag = IO_TAG(M25P16_CS_PIN); -#else - flashConfig->csTag = IO_TAG_NONE; -#endif - flashConfig->spiDevice = SPI_DEV_TO_CFG(spiDeviceByInstance(M25P16_SPI_INSTANCE)); -} -#endif // USE_FLASH_FS - #ifdef USE_SDCARD PG_REGISTER_WITH_RESET_TEMPLATE(sdcardConfig_t, sdcardConfig, PG_SDCARD_CONFIG, 0); diff --git a/src/main/fc/config.h b/src/main/fc/config.h index 9673e329cd..12c29f29f4 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -84,7 +84,6 @@ typedef struct systemConfig_s { PG_DECLARE(pilotConfig_t, pilotConfig); PG_DECLARE(systemConfig_t, systemConfig); PG_DECLARE(beeperDevConfig_t, beeperDevConfig); -PG_DECLARE(flashConfig_t, flashConfig); PG_DECLARE(ppmConfig_t, ppmConfig); PG_DECLARE(pwmConfig_t, pwmConfig); PG_DECLARE(vcdProfile_t, vcdProfile); diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index 832658773c..ff916233a4 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -81,6 +81,7 @@ #include "pg/adc.h" #include "pg/bus_i2c.h" +#include "pg/flash.h" #include "rx/rx.h" #include "rx/rx_spi.h" diff --git a/src/main/pg/flash.c b/src/main/pg/flash.c new file mode 100644 index 0000000000..347395ea73 --- /dev/null +++ b/src/main/pg/flash.c @@ -0,0 +1,44 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#include +#include + +#include "platform.h" + +#ifdef USE_FLASHFS + +#include "drivers/bus_spi.h" +#include "drivers/io.h" + +#include "pg/pg.h" +#include "pg/pg_ids.h" + +#include "flash.h" + +PG_REGISTER_WITH_RESET_FN(flashConfig_t, flashConfig, PG_FLASH_CONFIG, 0); + +void pgResetFn_flashConfig(flashConfig_t *flashConfig) +{ +#ifdef M25P16_CS_PIN + flashConfig->csTag = IO_TAG(M25P16_CS_PIN); +#else + flashConfig->csTag = IO_TAG_NONE; +#endif + flashConfig->spiDevice = SPI_DEV_TO_CFG(spiDeviceByInstance(M25P16_SPI_INSTANCE)); +} +#endif diff --git a/src/main/pg/flash.h b/src/main/pg/flash.h new file mode 100644 index 0000000000..fe3c564d9e --- /dev/null +++ b/src/main/pg/flash.h @@ -0,0 +1,31 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#pragma once + +#include + +#include "drivers/io_types.h" + +#include "pg/pg.h" + +typedef struct flashConfig_s { + ioTag_t csTag; + uint8_t spiDevice; +} flashConfig_t; + +PG_DECLARE(flashConfig_t, flashConfig); diff --git a/src/main/target/BLUEJAYF4/hardware_revision.c b/src/main/target/BLUEJAYF4/hardware_revision.c index ca1511413d..d952fbed16 100644 --- a/src/main/target/BLUEJAYF4/hardware_revision.c +++ b/src/main/target/BLUEJAYF4/hardware_revision.c @@ -28,6 +28,8 @@ #include "drivers/io.h" #include "drivers/time.h" +#include "pg/flash.h" + #include "hardware_revision.h" uint8_t hardwareRevision = UNKNOWN;