Open FFBoard
Open source force feedback firmware
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
34
35template<typename TVal>
36inline TVal Flash_ReadDefault(uint16_t adr, TVal def) {
37 uint16_t buf;
38
39 return Flash_Read(adr, &buf)
40 ? TVal(buf)
41 : def;
42}
43
44inline uint16_t pack(uint8_t hb, uint8_t lb) {
45 return (hb << 8) | lb;
46}
47
48inline std::tuple<uint8_t, uint8_t> unpack(uint16_t v) {
49 return { v >> 8, v & 0xFF };
50}
51
52#if defined(I2C_PORT_EEPROM)
53// i2c buffer
54#define I2C_EEPROM_TIMEOUT 100
55
56#endif
57
58#endif /* FLASH_HELPERS_H_ */
uint8_t adr
bool Flash_Init()
uint16_t pack(uint8_t hb, uint8_t lb)
Definition: flash_helpers.h:44
TVal Flash_ReadDefault(uint16_t adr, TVal def)
Definition: flash_helpers.h:36
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)
Definition: flash_helpers.h:48
bool Flash_Write(uint16_t adr, uint16_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)