From 37f331b8424f93d8761a83bbb78b6e3f2e2379bb Mon Sep 17 00:00:00 2001 From: wangko <321640253@qq.com> Date: Wed, 18 Oct 2023 18:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=E4=B8=8E=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OLED显示屏/AbsDrive_OLED.c | 2 ++ OLED显示屏/AbsDrive_OLED.h | 4 +++ README.md | 8 ++--- 数据结构/栈/Stack.c | 68 ++++++++++++++++++++++++++++++++++++++ 数据结构/栈/Stack.h | 31 +++++++++++++++++ 数据结构/栈/main.c | 23 +++++++++++++ 数据结构/队列/queue.c | 2 +- 数据结构/队列/queue.h | 2 +- 8 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 数据结构/栈/Stack.c create mode 100644 数据结构/栈/Stack.h create mode 100644 数据结构/栈/main.c diff --git a/OLED显示屏/AbsDrive_OLED.c b/OLED显示屏/AbsDrive_OLED.c index cf43060..6029060 100644 --- a/OLED显示屏/AbsDrive_OLED.c +++ b/OLED显示屏/AbsDrive_OLED.c @@ -9,6 +9,7 @@ #include "AbsDrive_OLED.h" #include "AbsDriveOledFont.h" +#if (ABSDrive_OLED_ON) /**************************抽象实现区(BEGIN)************************************/ #if (defined ABSDrive_4SPI)||(defined ABSDrive_3SPI)||(defined ABSDrive_HardIIC)||(defined ABSDrive_SoftIIC) @@ -590,3 +591,4 @@ ABS_OLED_Drive Create_OLED(void){ return drive; } +#endif \ No newline at end of file diff --git a/OLED显示屏/AbsDrive_OLED.h b/OLED显示屏/AbsDrive_OLED.h index 3d41009..c360a71 100644 --- a/OLED显示屏/AbsDrive_OLED.h +++ b/OLED显示屏/AbsDrive_OLED.h @@ -12,7 +12,9 @@ #include "stdint.h" #include "stdlib.h" +#define ABSDrive_OLED_ON 0 +#if(ABSDrive_OLED_ON) /**************************配置区(BEGIN)***************************/ /*------------你的头文件(BEGIN)----------------*/ //#include "spi.h" @@ -22,6 +24,7 @@ #include "stdio.h" /*------------你的头文件(END)------------------*/ + /*----1、选择驱动芯片----*/ /* 根据你的OLED屏幕选择其中一种 @@ -147,6 +150,7 @@ ABS_OLED_Drive Create_OLED(void); //创建OLED设备 +#endif #endif //__ABS_DRIVE_OLED_H diff --git a/README.md b/README.md index 34a9693..62be9d2 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ # 简介 -## 开发的来龙去脉 +## **开发的来龙去脉** 每次做项目的时候,都会遇到一些重复的代码,这些代码都是相似的,但是又不能直接复用,因为它们之间存在一些差异。 就像以抽象的思想去实现绝大部分外设的驱动 只需要配置一下参数和实现一下底层接口就可以直接使用 -## 开发思路 +## **开发思路** 1. 定义一个配置区间,在这个区间内,可以配置一些参数,这些参数可以适配不同的硬件 2. 定义一个抽象实现区间,在这个区间内,可以实现一些底层接口,这些接口可以适配不同的硬件 -## 开发说明 +## **开发说明** 首先欢迎大家一起来参与开发,只要遵守以下开发规范,就可以提交代码,共同完善这个项目 -### 开发规范 +### **开发规范** 1. 文件夹的命名规范:以硬件类型的不同来建立文件夹,比如:OLED、LCD、温度传感器等等 2. 文件的命名规范:开头为”ABS_硬件“或者“ABSDrive_硬件”开头,比如:ABS_OLED、等等 3. 函数命名规范:以”ABS_“或者”ABSDrive_“开头,比如:ABS_Init、ABSDrive_Init等等 diff --git a/数据结构/栈/Stack.c b/数据结构/栈/Stack.c new file mode 100644 index 0000000..4058d90 --- /dev/null +++ b/数据结构/栈/Stack.c @@ -0,0 +1,68 @@ +/* +*@文件:Stack.c +*@作者:‘你遇了我’ +*@time:2023/10/18 +*@联系:QQ:321640253 +*@版本:V1.0 +*@描述:顺序泛型栈 +*/ +#include "Stack.h" + +/* + * @简介:初始化一个栈 + * @参数: + * *S:栈结构体指针 + * Maxsize:栈容器的长度 + * NodeSize:栈容器每个元素的空间大小 + * *container:容器指针 + * @返回值:无 + * */ +void InitStack(SqStack *S,uint16_t MaxSize,uint16_t NodeSize) { + S->container = calloc(MaxSize,NodeSize); + S->Top=-1; + S->MaxSize=MaxSize; + S->NodeSize=NodeSize; + S->size = 0; +} + +/* + * @简介:进栈 + * @参数: + * *S:栈结构体指针 + * @返回值:可进栈空间地址 + * */ +void *PushStack(SqStack *S) { + if(S->size>=S->MaxSize)return NULL; + S->Top++; + S->size++; + return S->container + S->Top*S->NodeSize; +} + +/* + * @简介:出栈 + * @参数: + * *S:栈结构体指针 + * @返回值:出栈元素地址空间 + * */ +void *PopStack(SqStack *S) { + if (S->size == 0) { + return NULL; + } + S->Top--; + S->size--; + return S->container+S->Top*S->NodeSize; +} + +/* + * @简介:销毁栈 + * @参数: + * *S:栈结构体指针 + * @返回值:无 + * */ +void DestroyStack(SqStack *S) { + free(S->container); + S->container = NULL; + S->Top = -1; + S->MaxSize = 0; + S->size = 0; +} \ No newline at end of file diff --git a/数据结构/栈/Stack.h b/数据结构/栈/Stack.h new file mode 100644 index 0000000..6341f94 --- /dev/null +++ b/数据结构/栈/Stack.h @@ -0,0 +1,31 @@ +/* +*@文件:Stack.h +*@作者:‘你遇了我’ +*@time:2023/10/18 +*@联系:QQ:321640253 +*@版本:V1.0 +*@描述:顺序泛型栈 +*/ +#ifndef _STACK_H_ +#define _STACK_H_ + +#include +#include + +typedef struct { + void *container; + uint16_t size; + uint16_t MaxSize; + uint16_t NodeSize; + int Top; +} SqStack; + + + +/**********************函数声明区************************/ +void InitStack(SqStack *S,uint16_t MaxSize,uint16_t NodeSize); //初始化栈 +void *PushStack(SqStack *S); //进栈 +void *PopStack(SqStack *S); //出栈 +void DestroyStack(SqStack *S); //销毁栈 + +#endif \ No newline at end of file diff --git a/数据结构/栈/main.c b/数据结构/栈/main.c new file mode 100644 index 0000000..2880990 --- /dev/null +++ b/数据结构/栈/main.c @@ -0,0 +1,23 @@ +#include +#include "Stack.h" + + + + +int main(){ + int *a; + SqStack stack; + InitStack(&stack,20,sizeof(int)); + + for(int i=0;i<20;i++){ + a=(int *)PushStack(&stack); + *a=i; + } + for(int i=0;i<20;i++){ + printf("%d ",*(int *)(stack.container+i*stack.NodeSize)); + } + + + + return 0; +} \ No newline at end of file diff --git a/数据结构/队列/queue.c b/数据结构/队列/queue.c index d3864ce..873995b 100644 --- a/数据结构/队列/queue.c +++ b/数据结构/队列/queue.c @@ -4,7 +4,7 @@ *@time:2022/11/13 *@联系:QQ:321640253 *@版本:V1.3 -*@描述:数组泛型队列。队列管理和容器空间分离 +*@描述:顺序泛型队列 使用案例: */ diff --git a/数据结构/队列/queue.h b/数据结构/队列/queue.h index 953a35c..b17f60d 100644 --- a/数据结构/队列/queue.h +++ b/数据结构/队列/queue.h @@ -4,7 +4,7 @@ *@time:2022/11/13 *@联系:QQ:321640253 *@版本:V1.3 -*@描述:数组泛型队列,队列管理和容器空间分离 +*@描述:顺序泛型队列 使用案例 int main(){