Files
DS18B20_Library/DS18B20/ow_port.c
Razvalyaev 59606978b2 Кучу всего, переструктурирован проект все должно работать
- onewire: модуль для отправик комманд в DS18B20
- ds18b20_driver: модуль для отправик комманд в DS18B20
- dallas_tools: модуль для общения с DS18B20
2025-02-12 13:23:37 +03:00

112 lines
2.6 KiB
C

/**
******************************************************************************
* @file ow_port.c
* @brief This file includes the driver for port for OneWire purposes
******************************************************************************
*/
#include "ow_port.h"
#include "onewire.h"
/**
* @brief The internal function is used as gpio pin mode
* @param OW OneWire HandleTypedef
* @param Mode Input or Output
*/
void OneWire_Pin_Mode(OneWire_t* OW, PinMode Mode)
{
#ifdef CMSIS_Driver
static uint32_t pin_cr_numb = 4;
static int get_pin_numb = 0;
if(get_pin_numb)
{
get_pin_numb = 0;
for(int i = 0; i < 8; i++)
{
if((OW->DataPin >> i) == 0x1)
pin_cr_numb = i*4;
}
for(int i = 8; i < 16; i++)
{
if((OW->DataPin >> i) == 0x1)
pin_cr_numb = (i-8)*4;
}
}
if(Mode == Input)
{
OW->DataPort->CRH &= ~((GPIO_CRL_CNF0 | GPIO_CRL_MODE0) << pin_cr_numb);
OW->DataPort->CRH |= (1 << (pin_cr_numb+2));
}else{
OW->DataPort->CRH &= ~((GPIO_CRL_CNF0 | GPIO_CRL_MODE0) << pin_cr_numb);
OW->DataPort->CRH |= (3 << pin_cr_numb);
}
#else
#ifdef LL_Driver
if(Mode == Input)
{
LL_GPIO_SetPinMode(OW->DataPort, OW->DataPin, LL_GPIO_MODE_INPUT);
}else{
LL_GPIO_SetPinMode(OW->DataPort, OW->DataPin, LL_GPIO_MODE_OUTPUT);
}
#else
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = OW->DataPin;
if(Mode == Input)
{
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
}else{
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
}
HAL_GPIO_Init(OW->DataPort, &GPIO_InitStruct);
#endif
#endif
}
/**
* @brief The internal function is used as gpio pin level
* @param OW OneWire HandleTypedef
* @param Mode Level: Set/High = 1, Reset/Low = 0
*/
void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level)
{
#ifdef CMSIS_Driver
if (Level != GPIO_PIN_RESET)
{
OW->DataPort->BSRR = OW->DataPin;
}
else
{
OW->DataPort->BSRR = (uint32_t)OW->DataPin << 16u;
}
#else
#ifdef LL_Driver
if(Level == 1)
{
LL_GPIO_SetOutputPin(OW->DataPort, OW->DataPin);
}else{
LL_GPIO_ResetOutputPin(OW->DataPort, OW->DataPin);
}
#else
HAL_GPIO_WritePin(OW->DataPort, OW->DataPin, Level);
#endif
#endif
}
/**
* @brief The internal function is used to read data pin
* @retval Pin level status
* @param OW OneWire HandleTypedef
*/
uint8_t OneWire_Pin_Read(OneWire_t* OW)
{
#ifdef CMSIS_Driver
return ((OW->DataPort->IDR & OW->DataPin) != 0x00U) ? 1 : 0;
#else
#ifdef LL_Driver
return ((OW->DataPort->IDR & OW->DataPin) != 0x00U) ? 1 : 0;
#else
return HAL_GPIO_ReadPin(OW->DataPort, OW->DataPin);
#endif
#endif
}