Merge pull request #11494 from haslinghuis/dshot_gpio
[betaflight.git] / src / main / config / config_streamer.h
blob20b3861a2a93f6b564ac3d8b9c3c4e52162aee57
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>
24 #include <stdbool.h>
26 // Streams data out to the EEPROM, padding to the write size as
27 // needed, and updating the checksum as it goes.
29 #ifdef CONFIG_IN_EXTERNAL_FLASH
30 #define CONFIG_STREAMER_BUFFER_SIZE 8 // Must not be greater than the smallest flash page size of all compiled-in flash devices.
31 typedef uint32_t config_streamer_buffer_align_type_t;
32 #elif defined(STM32H743xx) || defined(STM32H750xx) || defined(STM32H723xx) || defined(STM32H725xx)
33 #define CONFIG_STREAMER_BUFFER_SIZE 32 // Flash word = 256-bits
34 typedef uint64_t config_streamer_buffer_align_type_t;
35 #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ)
36 #define CONFIG_STREAMER_BUFFER_SIZE 16 // Flash word = 128-bits
37 typedef uint64_t config_streamer_buffer_align_type_t;
38 #elif defined(STM32G4)
39 #define CONFIG_STREAMER_BUFFER_SIZE 8 // Flash word = 64-bits
40 typedef uint64_t config_streamer_buffer_align_type_t;
41 #else
42 #define CONFIG_STREAMER_BUFFER_SIZE 4
43 typedef uint32_t config_streamer_buffer_align_type_t;
44 #endif
46 typedef struct config_streamer_s {
47 uintptr_t address;
48 int size;
49 union {
50 uint8_t b[CONFIG_STREAMER_BUFFER_SIZE];
51 config_streamer_buffer_align_type_t w;
52 } buffer;
53 int at;
54 int err;
55 bool unlocked;
56 } config_streamer_t;
58 void config_streamer_init(config_streamer_t *c);
60 void config_streamer_start(config_streamer_t *c, uintptr_t base, int size);
61 int config_streamer_write(config_streamer_t *c, const uint8_t *p, uint32_t size);
62 int config_streamer_flush(config_streamer_t *c);
64 int config_streamer_finish(config_streamer_t *c);
65 int config_streamer_status(config_streamer_t *c);