Open FFBoard
Open source force feedback firmware
Loading...
Searching...
No Matches
flash_helpers.h
Go to the documentation of this file.
1/*
2 * flash_helpers.h
3 *
4 * Created on: 31.01.2020
5 * Author: Yannick
6 */
7
8#ifndef FLASH_HELPERS_H_
9#define FLASH_HELPERS_H_
10#include "constants.h"
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15#include "main.h"
16#ifdef USE_EEPROM_EMULATION
17#include "eeprom.h"
18#endif
19
20#ifdef __cplusplus
21}
22#endif
23
24#include <tuple>
25#include <vector>
26#include <span>
27
28bool Flash_Init();
29bool Flash_Write(uint16_t adr,uint16_t dat); // Writes or updates only if changed or missing
30bool Flash_Read(uint16_t adr,uint16_t *buf,bool checkempty = true); // returns true if found, false if error
31bool Flash_ReadWriteDefault(uint16_t adr,uint16_t *buf,uint16_t def); // returns and writes def if variable is missing
32void Flash_Dump(std::vector<std::tuple<uint16_t,uint16_t>> *result,bool includeAll = false);
33bool Flash_Format();
34
35bool OTP_Write(uint16_t adroffset,uint64_t dat);
36bool OTP_Read(uint16_t adroffset,uint64_t* dat);
37
38
39template<typename TVal>
40inline TVal Flash_ReadDefault(uint16_t adr, TVal def) {
41 uint16_t buf;
42
43 return Flash_Read(adr, &buf)
44 ? TVal(buf)
45 : def;
46}
47
48inline uint16_t pack(uint8_t hb, uint8_t lb) {
49 return (hb << 8) | lb;
50}
51
52inline std::tuple<uint8_t, uint8_t> unpack(uint16_t v) {
53 return { v >> 8, v & 0xFF };
54}
55
56#if defined(I2C_PORT_EEPROM)
57// i2c buffer
58#define I2C_EEPROM_TIMEOUT 100
59
60#endif
61
62extern const std::span<const std::pair<uint16_t,uint16_t>> flash_factory_defaults; // address,value pair
64
65#endif /* FLASH_HELPERS_H_ */
uint8_t adr
bool Flash_Init()
uint16_t pack(uint8_t hb, uint8_t lb)
const std::span< const std::pair< uint16_t, uint16_t > > flash_factory_defaults
TVal Flash_ReadDefault(uint16_t adr, TVal def)
bool Flash_Format()
void Flash_Dump(std::vector< std::tuple< uint16_t, uint16_t > > *result, bool includeAll=false)
std::tuple< uint8_t, uint8_t > unpack(uint16_t v)
bool Flash_Write(uint16_t adr, uint16_t dat)
bool OTP_Read(uint16_t adroffset, uint64_t *dat)
void Flash_Write_Defaults()
bool Flash_ReadWriteDefault(uint16_t adr, uint16_t *buf, uint16_t def)
bool Flash_Read(uint16_t adr, uint16_t *buf, bool checkempty=true)
bool OTP_Write(uint16_t adroffset, uint64_t dat)