173 lines
2.9 KiB
C
173 lines
2.9 KiB
C
/*
|
|
* drv_dio.c
|
|
*
|
|
* Created on: Apr 28, 2024
|
|
* Author: gxms0
|
|
*/
|
|
|
|
|
|
//普通DIO设置
|
|
#include "drv_dio.h"
|
|
#include "string.h"
|
|
|
|
static diodef *root = NULL;
|
|
|
|
//diodef di_max;
|
|
//diodef di_min;
|
|
|
|
//diodef do_ms1;
|
|
//diodef do_ms2;
|
|
//diodef do_en;
|
|
//diodef do_dir;
|
|
//diodef do_step;
|
|
|
|
//diodef do_com;
|
|
|
|
|
|
void dio_init(void)
|
|
{
|
|
// dio_config(&di_max,"max",DI_MAX_GPIO_Port,DI_MAX_Pin,DIO_INPUT,0x00);
|
|
// dio_config(&di_max,"min",DI_MIN_GPIO_Port,DI_MIN_Pin,DIO_INPUT,0x00);
|
|
//
|
|
// dio_config(&do_ms1,"ms1",M_MS1_GPIO_Port,M_MS1_Pin,DIO_OUTPUT,0x00);
|
|
// dio_config(&do_ms2,"ms2",M_MS2_GPIO_Port,M_MS2_Pin,DIO_OUTPUT,0x00);
|
|
// dio_config(&do_en,"en",M_EN_GPIO_Port,M_EN_Pin,DIO_OUTPUT,0x00);
|
|
// dio_config(&do_dir,"dir",M_DIR_GPIO_Port,M_DIR_Pin,DIO_OUTPUT,0x00);
|
|
// dio_config(&do_step,"stp",M_STEP_GPIO_Port,M_STEP_Pin,DIO_OUTPUT,0x00);
|
|
//
|
|
// dio_config(&do_com,"com",COM_SEL_GPIO_Port,COM_SEL_Pin,DIO_OUTPUT,0x00);
|
|
|
|
}
|
|
|
|
void dio_config(diodef *e,char *name,GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin,uint8_t type,uint8_t state)
|
|
{
|
|
if(e == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
e->next_ptr = NULL;
|
|
e->name = name;
|
|
e->state = state;
|
|
e->GPIOx = GPIOx;
|
|
e->GPIO_Pin = GPIO_Pin;
|
|
e->type = (type > 0x00)?(DIO_OUTPUT):(DIO_INPUT);
|
|
|
|
|
|
HAL_GPIO_WritePin(e->GPIOx,e->GPIO_Pin,(e->state)?(GPIO_PIN_SET):(GPIO_PIN_RESET));
|
|
|
|
|
|
if (root)
|
|
{
|
|
diodef *last = root;
|
|
while (last->next_ptr)
|
|
{
|
|
last = last->next_ptr;
|
|
}
|
|
e->channel = last->channel + 1;
|
|
last->next_ptr = e;
|
|
}
|
|
else
|
|
{
|
|
e->channel = 0;
|
|
root = e;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void dio_set(uint16_t channel,uint8_t state)
|
|
{
|
|
if (root)
|
|
{
|
|
diodef *e = root;
|
|
while (e)
|
|
{
|
|
if(e->channel == channel)
|
|
{
|
|
e->state = state;
|
|
HAL_GPIO_WritePin(e->GPIOx,e->GPIO_Pin,(e->state)?(GPIO_PIN_SET):(GPIO_PIN_RESET));
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
e = e->next_ptr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
uint8_t dio_get(uint16_t channel)
|
|
{
|
|
uint8_t state = 0;
|
|
|
|
if (root)
|
|
{
|
|
diodef *e = root;
|
|
while (e)
|
|
{
|
|
if(e->channel == channel)
|
|
{
|
|
state = HAL_GPIO_ReadPin(e->GPIOx,e->GPIO_Pin);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
e = e->next_ptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
return state;
|
|
}
|
|
|
|
void dio_toggle()
|
|
{
|
|
|
|
}
|
|
|
|
//触发事件 一般用于输入触发
|
|
void dio_event()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIO_setByName(char *name,unsigned char state)
|
|
{
|
|
if (root)
|
|
{
|
|
diodef *e = root;
|
|
while (e)
|
|
{
|
|
if(strcmp(e->name,name) == 0)
|
|
{
|
|
e->state = state;
|
|
HAL_GPIO_WritePin(e->GPIOx,e->GPIO_Pin,(e->state)?(GPIO_PIN_SET):(GPIO_PIN_RESET));
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
e = e->next_ptr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void DIO_Poll()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|