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
27bool Flash_Init();
28bool Flash_Write(uint16_t adr,uint16_t dat); // Writes or updates only if changed or missing
29bool Flash_Read(uint16_t adr,uint16_t *buf,bool checkempty = true); // returns true if found, false if error
30bool Flash_ReadWriteDefault(uint16_t adr,uint16_t *buf,uint16_t def); // returns and writes def if variable is missing
31void Flash_Dump(std::vector<std::tuple<uint16_t,uint16_t>> *result,bool includeAll = false);
32bool Flash_Format();
33
34bool OTP_Write(uint16_t adroffset,uint64_t dat);
35bool OTP_Read(uint16_t adroffset,uint64_t* dat);
36
37
38template<typename TVal>
39inline TVal Flash_ReadDefault(uint16_t adr, TVal def) {
40 uint16_t buf;
41
42 return Flash_Read(adr, &buf)
43 ? TVal(buf)
44 : def;
45}
46
47inline uint16_t pack(uint8_t hb, uint8_t lb) {
48 return (hb << 8) | lb;
49}
50
51inline std::tuple<uint8_t, uint8_t> unpack(uint16_t v) {
52 return { v >> 8, v & 0xFF };
53}
54
55#if defined(I2C_PORT_EEPROM)
56// i2c buffer
57#define I2C_EEPROM_TIMEOUT 100
58
59#endif
60
61#endif /* FLASH_HELPERS_H_ */
uint8_t adr
bool Flash_Init()
uint16_t pack(uint8_t hb, uint8_t lb)
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)
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)