当前位置:网站首页>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
边栏推荐
- NGUI,聊天滚动框,UI TextList
- Development and source code construction of digital collection system
- Xilinx pin constraint file xdc
- 新西兰是道路安全做的最好的国家之一
- NFT产品是有生命的
- 基于C语言实现比赛评分系统
- 网上开户是安全的吗?普通人可以开吗?
- Global pooling – pytoch
- Metro roadmap cloud development applet source code and configuration tutorial
- Leetcode 1952. Triple divisor
猜你喜欢

EMC rectification cases of electronic equipment radiation

Sys in kingbasees_ Checksums bad block detection function

Jedislock redis distributed lock implementation

Fix the problem that uicollectionview does not reach the bottom security zone
![[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

使用 Hystrix 实现微服务的容错处理

Dimension types for different CV tasks

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

MN梦奈宝塔主机系统V1.5版本发布

Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
随机推荐
金仓数据库KingbaseES中的PL/SQL 编译检查
MySQL基础篇常用约束总结上篇
使用 Ribbon 实现客户端负载均衡
详解2.5G/5G/10G Base-T以太网接口物理层一致性测试!
beginning一款非常优秀的emlog主题
EMC rectification cases of electronic equipment radiation
Some understanding of inductive bias
[audio and video] Introduction to SEI
数字藏品系统开发源码搭建
Pl/sql compilation check in kingbasees
[machine learning theory] true positive, true negative, false positive, false negative concept
使用RSA与base64对字符串进行加密解密
Ngui, backpack drag and drop, and random cloning of picture knowledge points
NGUI,聊天滚动框,UI TextList
電子設備輻射EMC整改案例
Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
Ngui, cooling effect
Preview component packaging graphic tutorial in cadence OrCAD capture schematic design interface
About CI framework batch export to compressed file
Leetcode 1995. 统计特殊四元组(暴力枚举)