当前位置:网站首页>Migrating minini to littlefs
Migrating minini to littlefs
2022-06-11 10:47:00 【*_ Look up at the stars_*】
minIni
minIni Is a for reading and writing INI Document library .
github :
https://github.com/compuphase/minIni
minIni characteristic :
1、minIni It's about 950 Line code ( Including comments ), It's a real “ mini ” INI File parser , It is very easy to migrate to various embedded platforms .
2、minIni No standards required C/C++ In the library file I/O function , And it is allowed to configure the file to be selected through the macro I/O Interface .
3、minIni Use only stack , Do not use dynamic memory at all (malloc).
4、 Yes C++ binding, Can cooperate well C++ Use
Why use minIni :
Search for ini The file library will find many , Some also say that they support embedded systems , But when you look at the code, you will find that , Is to support complete C The standard file read / write interface can be used , In the use of RTOS and MCU The embedded system of can't be used at all , It will take a lot of time to transplant , Its file read / write interfaces are embedded in the function implementation , It's hard to transplant .
Through the above minIni The first 2 Just click minIni Yes ini file IO Interfaces are configured through macros , That is, transplantation , The portability is very good .
minIni Migration to littlefs
minIni There are many different files under the warehouse IO Good header file , Migration can refer to .
minGlue-bk.h
minGlue-ccs.h
minGlue-efsl.h
minGlue-FatFs.h
minGlue-ffs.h
minGlue-lfs.c
minGlue-Linux.h
minGlue-mdd.h
minGlue-stdio.h
minGlue.h
minIni.c
minIni.h
test.c
test.ini
test2.cc
testplain.ini
wxMinIni.h
in the light of littlefs Transplantation :
minGlue-lfs.h
/* Glue functions for the minIni library, based on the littlefs * libraries, see https://github.com/littlefs-project/littlefs * * By guangjieMVP, 2022 * This "glue file" is in the public domain. It is distributed without * warranties or conditions of any kind, either express or implied. * * (The littlefs libraries are copyright by ARM and licensed at * its own terms.) */
#ifndef _MINGLUE_LFS_H_
#define _MINGLUE_LFS_H_
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
/* You must set FF_USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h) * to enable the "string functions" fgets() and fputs(). */
#include "lfs.h" /* include lfs.h for littlefs */
#include "stdio.h"
#include "string.h"
/* Define a line of text Terminator */
#define INI_LINETERM "\n"
/* Use the library's own strnicmp*/
#define PORTABLE_STRNICMP
extern lfs_t lfs;
char *lfs_gets(char *s, int size, lfs_file_t *file);
#define INI_FILETYPE lfs_file_t
#define ini_openread(filename, file) (lfs_file_open(&lfs, (file), (filename), LFS_O_RDONLY | LFS_O_CREAT) == LFS_ERR_OK)
#define ini_openwrite(filename, file) (lfs_file_open(&lfs, (file), (filename), LFS_O_WRONLY | LFS_O_CREAT) == LFS_ERR_OK)
#define ini_close(file) (lfs_file_close(&lfs, file) == LFS_ERR_OK)
#define ini_read(buffer, size, file) (lfs_gets((buffer), (size), (file)))
#define ini_write(buffer, file) (lfs_file_write(&lfs, (file), (buffer), strlen(buffer)))
#define ini_remove(filename) (lfs_remove(&lfs, filename) == LFS_ERR_OK)
#define ini_rename(source, dest) (lfs_rename(&lfs, (source), (dest)) == LFS_ERR_OK)
#define INI_FILEPOS lfs_soff_t
#define ini_tell(file, pos) (*(pos) = lfs_file_tell(&lfs, (file)))
#define ini_seek(file, pos) (lfs_file_seek(&lfs, (file), *(pos), LFS_SEEK_SET) == LFS_ERR_OK)
#endif
minGlue-lfs.c
#include "lfs.h" /* include lfs.h for littlefs */
#include "string.h"
extern lfs_t lfs;
char *lfs_gets(char *s, int size, lfs_file_t *file)
{
char *ptr;
int32_t numBytes;
int32_t pos;
if ((s == 0) || (size <= 0))
{
return(NULL);
}
/* See the current position before reading */
pos = lfs_file_seek(&lfs, file, 0, LFS_SEEK_CUR);
/* Read from the current position */
numBytes = lfs_file_read(&lfs, file, (s), (size - 1));
if (numBytes > 0)
{
/* Find the first/next new line */
ptr = strchr(s, '\n');
if (ptr)
{
ptr++;
*ptr = 0;
numBytes = strlen(s);
}
}
else
{
return(NULL);
}
assert(numBytes <= size);
/* Set the new position for the next read */
lfs_file_seek(&lfs, file, (pos + numBytes), LFS_SEEK_SET);
return(s);
}
file IO Interface littlefs There are basically ready-made , But there is no interface to get one line of file data , You have to implement it yourself , in the light of littlefs The implementation of is as shown above ,lfs_gets function , A row of data is represented by "\n" End of character
notes :
Use the original minGlue.h Back it up minGlue-bk.h, And then minGlue-lfs.h Change to minGlue.h
边栏推荐
- NFT产品是有生命的
- Practical process of selecting DC-DC switching power supply controller
- Cas de rectification du CEM rayonné par des équipements électroniques
- Leetcode 1952. 三除数
- 以银行异业合作为例,浅谈小程序生态的建设
- &lt; Pytorch series 4 & gt;: Constructing neural network model
- NGUI,选择性别男女
- Safety related website recommendations
- NFT 2.0: 下一代的NFT将是精简且值得信赖的NFT
- 用真金做的电路板——金手指
猜你喜欢

Mn Monet pagoda host system v1.5 release

概率论:计算置信区间

電子設備輻射EMC整改案例

Cloud image quality assistant IAPP source code

使用 Hystrix 实现微服务的容错处理
![[machine learning theory] true positive, true negative, false positive, false negative concept](/img/59/8264d6cbd96480b59e5b8ff96320be.png)
[machine learning theory] true positive, true negative, false positive, false negative concept

Pyramidtnt: TNT with characteristic pyramid structure

以银行异业合作为例,浅谈小程序生态的建设

MySQL基础篇常用约束总结下篇

班组级安全培训,新员工入职培训教育课件,全内容PPT套用
随机推荐
远程监控项目离线日志说明书
Mxnet construction and implementation of alexnet model (comparison with lenet)
使用 Ribbon 实现客户端负载均衡
FPGA infrastructure [reference ug998]
Ngui, map zoom in and out
What is the SOA or ASO of MOSFET?
MOSFET的SOA或者ASO是什么?
PHP仿网易云原创音乐分享平台网站源码
NGUI,飘血
RxJs fromEvent 工作原理分析
Half of the property rights of the house are registered in the woman's name when they are in love, and they want to return after they break up
IPhone 15 forced to use type-C interface
Wechat cloud development al short video one click face changing applet source code
Fix the problem that uicollectionview does not reach the bottom security zone
解读USB3.0测试项目
数字藏品app系统源码
NGUI,选择性别男女
NFT产品是有生命的
Circuit board made of real gold -- golden finger
Update更新 bytea类型失败 PostGresql