Compare commits
2 Commits
b85fc4bdf1
...
37f331b842
| Author | SHA1 | Date | |
|---|---|---|---|
| 37f331b842 | |||
| bd56fdcd73 |
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
# 简介
|
||||
## 开发的来龙去脉
|
||||
## **开发的来龙去脉**
|
||||
每次做项目的时候,都会遇到一些重复的代码,这些代码都是相似的,但是又不能直接复用,因为它们之间存在一些差异。
|
||||
|
||||
就像以抽象的思想去实现绝大部分外设的驱动
|
||||
|
||||
只需要配置一下参数和实现一下底层接口就可以直接使用
|
||||
|
||||
## 开发思路
|
||||
## **开发思路**
|
||||
1. 定义一个配置区间,在这个区间内,可以配置一些参数,这些参数可以适配不同的硬件
|
||||
2. 定义一个抽象实现区间,在这个区间内,可以实现一些底层接口,这些接口可以适配不同的硬件
|
||||
|
||||
|
||||
## 开发说明
|
||||
## **开发说明**
|
||||
首先欢迎大家一起来参与开发,只要遵守以下开发规范,就可以提交代码,共同完善这个项目
|
||||
|
||||
### 开发规范
|
||||
### **开发规范**
|
||||
1. 文件夹的命名规范:以硬件类型的不同来建立文件夹,比如:OLED、LCD、温度传感器等等
|
||||
2. 文件的命名规范:开头为”ABS_硬件“或者“ABSDrive_硬件”开头,比如:ABS_OLED、等等
|
||||
3. 函数命名规范:以”ABS_“或者”ABSDrive_“开头,比如:ABS_Init、ABSDrive_Init等等
|
||||
|
||||
68
数据结构/栈/Stack.c
Normal file
68
数据结构/栈/Stack.c
Normal file
@@ -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;
|
||||
}
|
||||
31
数据结构/栈/Stack.h
Normal file
31
数据结构/栈/Stack.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
*@文件:Stack.h
|
||||
*@作者:‘你遇了我’
|
||||
*@time:2023/10/18
|
||||
*@联系:QQ:321640253
|
||||
*@版本:V1.0
|
||||
*@描述:顺序泛型栈
|
||||
*/
|
||||
#ifndef _STACK_H_
|
||||
#define _STACK_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
23
数据结构/栈/main.c
Normal file
23
数据结构/栈/main.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
||||
@@ -3,24 +3,23 @@
|
||||
|
||||
int main(){
|
||||
|
||||
int a[10]; //创建队列容器
|
||||
SqQuecu a_quecu; //初始化队列
|
||||
InitQuecu(&a_quecu,10,sizeof(int),(void*)a);
|
||||
//出队进队测试
|
||||
int *tmep;//临时存储进对的返回值
|
||||
for (size_t i = 0; i < 50; i++)
|
||||
{
|
||||
tmep = (int*)enQueue(&a_quecu);
|
||||
if(tmep!=NULL){ //返回值为空指针则对满
|
||||
if(tmep!=NULL){ //返回值为空指针则队满
|
||||
*tmep=i;
|
||||
}
|
||||
else{
|
||||
printf("出队元素:%d\n",*(int*)deQueue(&a_quecu));
|
||||
*(int*)enQueue(&a_quecu)=i; //出队后重新进队
|
||||
}
|
||||
for(int i=0;i<10;i++)
|
||||
printf("%d\n",a[i]);
|
||||
|
||||
/*******遍历队列**********/
|
||||
for(int i=0;i<a_quecu.Maxsize;i++)
|
||||
printf("%d\n",*(int*)(a_quecu.container+i*a_quecu.NodeSize));
|
||||
/*******遍历队列**********/
|
||||
printf("-------------------------\n");
|
||||
|
||||
}
|
||||
@@ -30,7 +29,7 @@ int main(){
|
||||
printf("出队元素:%d\n",*(int*)deQueue(&a_quecu));
|
||||
printf("当前队列长度:%d\n",a_quecu.size);
|
||||
}
|
||||
|
||||
DestroyQueue(&a_quecu);
|
||||
printf("队列已销毁\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
*@作者:‘你遇了我’
|
||||
*@time:2022/11/13
|
||||
*@联系:QQ:321640253
|
||||
*@版本:V1.2
|
||||
*@描述:数组泛型队列。队列管理和容器空间分离
|
||||
*@版本:V1.3
|
||||
*@描述:顺序泛型队列
|
||||
使用案例:
|
||||
|
||||
*/
|
||||
@@ -23,12 +23,12 @@
|
||||
* *container:容器数组指针
|
||||
* @返回值:无
|
||||
* */
|
||||
void InitQuecu(SqQuecu *Q,uint16_t Maxsize,uint16_t NodeSize,void *container){
|
||||
void InitQuecu(SqQuecu *Q,uint16_t Maxsize,uint16_t NodeSize){
|
||||
Q->front=Q->rear=-1;
|
||||
Q->size=0;
|
||||
Q->Maxsize=Maxsize;
|
||||
Q->NodeSize=NodeSize;
|
||||
Q->container=container;
|
||||
Q->container=calloc(Maxsize,Q->NodeSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,3 +80,12 @@ void *deQueue(SqQuecu *Q){
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @简介:销毁队列
|
||||
* @参数:队列指针
|
||||
*/
|
||||
void DestroyQueue(SqQuecu *Q){
|
||||
free(Q->container);
|
||||
Q->front=Q->rear=Q->size=Q->Maxsize=Q->NodeSize=0;
|
||||
Q->container=NULL;
|
||||
}
|
||||
@@ -3,28 +3,29 @@
|
||||
*@作者:‘你遇了我’
|
||||
*@time:2022/11/13
|
||||
*@联系:QQ:321640253
|
||||
*@版本:V1.2
|
||||
*@描述:数组泛型队列,队列管理和容器空间分离
|
||||
*@版本:V1.3
|
||||
*@描述:顺序泛型队列
|
||||
使用案例
|
||||
int a[10]; //创建队列容器
|
||||
SqQuecu a_quecu; //初始化队列
|
||||
InitQuecu(&a_quecu,10,sizeof(int),(void*)a);
|
||||
int main(){
|
||||
|
||||
SqQuecu a_quecu; //初始化队列
|
||||
InitQuecu(&a_quecu,10,sizeof(int));
|
||||
//出队进队测试
|
||||
int *tmep;//临时存储进对的返回值
|
||||
for (size_t i = 0; i < 50; i++)
|
||||
{
|
||||
tmep = (int*)enQueue(&a_quecu);
|
||||
if(tmep!=NULL){ //返回值为空指针则对满
|
||||
if(tmep!=NULL){ //返回值为空指针则队满
|
||||
*tmep=i;
|
||||
}
|
||||
else{
|
||||
printf("出队元素:%d\n",*(int*)deQueue(&a_quecu));
|
||||
*(int*)enQueue(&a_quecu)=i; //出队后重新进队
|
||||
}
|
||||
//*******遍历队列**********
|
||||
for(int i=0;i<10;i++)
|
||||
printf("%d\n",a[i]);
|
||||
|
||||
printf("%d\n",*(int*)(a_quecu.container+i*a_quecu.NodeSize));
|
||||
//*******遍历队列**********
|
||||
printf("-------------------------\n");
|
||||
|
||||
}
|
||||
@@ -34,6 +35,10 @@
|
||||
printf("出队元素:%d\n",*(int*)deQueue(&a_quecu));
|
||||
printf("当前队列长度:%d\n",a_quecu.size);
|
||||
}
|
||||
DestroyQueue(&a_quecu);
|
||||
printf("队列已销毁\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifndef LIST_QUEUE_H
|
||||
@@ -52,11 +57,11 @@ typedef struct{
|
||||
uint16_t size; //队列长度
|
||||
} SqQuecu;
|
||||
|
||||
void InitQuecu(SqQuecu *Q,uint16_t Maxsize,uint16_t NodeSize,void *container);
|
||||
void *enQueue(SqQuecu *Q);
|
||||
void *deQueue(SqQuecu *Q);
|
||||
bool QueueEmpty(SqQuecu *Q);
|
||||
bool QueueFull(SqQuecu *Q);
|
||||
|
||||
void InitQuecu(SqQuecu *Q,uint16_t Maxsize,uint16_t NodeSize); //初始化队列
|
||||
void *enQueue(SqQuecu *Q); //进队
|
||||
void *deQueue(SqQuecu *Q); //出队
|
||||
bool QueueEmpty(SqQuecu *Q); //判断队空
|
||||
bool QueueFull(SqQuecu *Q); //判断队满
|
||||
void DestroyQueue(SqQuecu *Q); //销毁队列(只销毁队列容器,队列指针本身还在)
|
||||
|
||||
#endif //LIST_QUEUE_H
|
||||
|
||||
Reference in New Issue
Block a user