добавлена реализация onewire через uart и переделана структуруа шины OneWire и инциализация

Теперь при выборе UART, в функцию Dallas_BusFirstInit передается hdallas, huart, ow, ds

А при выборе GPIO ножки: hdallas, gpiox, gpio_pin, ow, ds

но надо как-то структуруизировать дальше
This commit is contained in:
2025-06-30 18:34:17 +03:00
parent 175bcd539f
commit fa32d653e8
14 changed files with 373 additions and 61 deletions

View File

@@ -16,7 +16,8 @@ uint32_t pin_pos = (OW_Pin_Numb < 8) ? (OW_Pin_Numb * 4) : ((OW_Pin_Numb - 8) *
*/
void OneWire_Pin_Mode(OneWire_t* OW, PinMode Mode)
{
#ifdef CMSIS_Driver
#if defined(UART_Driver)
#elif defined(CMSIS_Driver)
volatile uint32_t *config_reg = (OW_Pin_Numb < 8) ? &(OW->DataPort->CRL) : &(OW->DataPort->CRH);
// —брос текущих 4 бит (CNF + MODE)
*config_reg &= ~(0xF << pin_pos);
@@ -33,8 +34,7 @@ volatile uint32_t *config_reg = (OW_Pin_Numb < 8) ? &(OW->DataPort->CRL) : &(OW-
// ¬ыход push-pull, 2 ћ√ц Ц MODE = 0b10, CNF = 0b00
*config_reg |= (0x2 << pin_pos);
}
#else
#ifdef LL_Driver
#elif defined(LL_Driver)
if(Mode == Input)
{
LL_GPIO_SetPinMode(OW->DataPort, OW->DataPin, LL_GPIO_MODE_INPUT);
@@ -53,7 +53,6 @@ volatile uint32_t *config_reg = (OW_Pin_Numb < 8) ? &(OW->DataPort->CRL) : &(OW-
}
HAL_GPIO_Init(OW->DataPort, &GPIO_InitStruct);
#endif
#endif
}
/**
@@ -63,7 +62,8 @@ volatile uint32_t *config_reg = (OW_Pin_Numb < 8) ? &(OW->DataPort->CRL) : &(OW-
*/
void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level)
{
#ifdef CMSIS_Driver
#if defined(UART_Driver)
#elif defined(CMSIS_Driver)
if (Level != GPIO_PIN_RESET)
{
OW->DataPort->BSRR = OW->DataPin;
@@ -72,8 +72,7 @@ void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level)
{
OW->DataPort->BSRR = (uint32_t)OW->DataPin << 16u;
}
#else
#ifdef LL_Driver
#elif defined(LL_Driver)
if(Level == 1)
{
LL_GPIO_SetOutputPin(OW->DataPort, OW->DataPin);
@@ -83,7 +82,6 @@ void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level)
#else
HAL_GPIO_WritePin(OW->DataPort, OW->DataPin, Level);
#endif
#endif
}
/**
@@ -93,15 +91,15 @@ void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level)
*/
uint8_t OneWire_Pin_Read(OneWire_t* OW)
{
#ifdef CMSIS_Driver
#if defined(UART_Driver)
return 0;
#elif defined(CMSIS_Driver)
return ((OW->DataPort->IDR & OW->DataPin) != 0x00U) ? 1 : 0;
#else
#ifdef LL_Driver
#elif defined(LL_Driver)
return ((OW->DataPort->IDR & OW->DataPin) != 0x00U) ? 1 : 0;
#else
return HAL_GPIO_ReadPin(OW->DataPort, OW->DataPin);
#endif
#endif
}
uint32_t tim_1us_period = OW_TIM_1US_PERIOD;