|
|
|
|
@@ -93,35 +93,28 @@ DALLAS_HandleTypeDef hdallas;
|
|
|
|
|
* @retval HAL Status
|
|
|
|
|
*/
|
|
|
|
|
#ifndef UART_Driver
|
|
|
|
|
HAL_StatusTypeDef Dallas_BusFirstInit(DALLAS_HandleTypeDef *hdallas, GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, OneWire_t *OW_Ptr, DS18B20_Drv_t *DS_Ptr)
|
|
|
|
|
HAL_StatusTypeDef Dallas_BusFirstInit(DALLAS_HandleTypeDef *hdallas, GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
|
|
|
|
#else
|
|
|
|
|
HAL_StatusTypeDef Dallas_BusFirstInit(DALLAS_HandleTypeDef *hdallas, UART_HandleTypeDef *huart, OneWire_t *OW_Ptr, DS18B20_Drv_t *DS_Ptr)
|
|
|
|
|
HAL_StatusTypeDef Dallas_BusFirstInit(DALLAS_HandleTypeDef *hdallas, UART_HandleTypeDef *huart)
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
if(hdallas == NULL)
|
|
|
|
|
return HAL_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(OW_Ptr == NULL)
|
|
|
|
|
hdallas->onewire = &OW;
|
|
|
|
|
|
|
|
|
|
if(DS_Ptr == NULL)
|
|
|
|
|
hdallas->ds_devices = &DS;
|
|
|
|
|
|
|
|
|
|
#ifndef UART_Driver
|
|
|
|
|
if(GPIOx == NULL)
|
|
|
|
|
return HAL_ERROR;
|
|
|
|
|
|
|
|
|
|
OW_TIM->CR1 |= TIM_CR1_CEN;
|
|
|
|
|
hdallas->onewire->DataPin = GPIO_Pin;
|
|
|
|
|
hdallas->onewire->DataPort = GPIOx;
|
|
|
|
|
hdallas->onewire.DataPin = GPIO_Pin;
|
|
|
|
|
hdallas->onewire.DataPort = GPIOx;
|
|
|
|
|
#else
|
|
|
|
|
if(huart == NULL)
|
|
|
|
|
return HAL_ERROR;
|
|
|
|
|
hdallas->onewire->huart = huart;
|
|
|
|
|
hdallas->onewire.huart = huart;
|
|
|
|
|
#endif
|
|
|
|
|
/* Инициализация onewire и поиск датчиков*/
|
|
|
|
|
OneWire_Init(hdallas->onewire);
|
|
|
|
|
OneWire_Init(&hdallas->onewire);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Dallas_Search(hdallas);
|
|
|
|
|
@@ -137,7 +130,7 @@ HAL_StatusTypeDef Dallas_Search(DALLAS_HandleTypeDef *hdallas)
|
|
|
|
|
if(hdallas == NULL)
|
|
|
|
|
return HAL_ERROR;
|
|
|
|
|
|
|
|
|
|
return DS18B20_Search(hdallas->ds_devices, hdallas->onewire) != HAL_OK;
|
|
|
|
|
return DS18B20_Search(&hdallas->ds_devices, &hdallas->onewire) != HAL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -215,7 +208,7 @@ HAL_StatusTypeDef Dallas_StartConvertTAll(DALLAS_HandleTypeDef *hdallas, DALLAS_
|
|
|
|
|
return HAL_ERROR;
|
|
|
|
|
|
|
|
|
|
// Отправка команды начала преобразования температуры
|
|
|
|
|
result = DS18B20_StartConvTAll(hdallas->onewire);
|
|
|
|
|
result = DS18B20_StartConvTAll(&hdallas->onewire);
|
|
|
|
|
if(result != HAL_OK)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
@@ -227,7 +220,7 @@ HAL_StatusTypeDef Dallas_StartConvertTAll(DALLAS_HandleTypeDef *hdallas, DALLAS_
|
|
|
|
|
// Ожидание завершения преобразования, путем проверки шины
|
|
|
|
|
if (waitCondition == DALLAS_WAIT_BUS)
|
|
|
|
|
{
|
|
|
|
|
result = DS18B20_WaitForEndConvertion(hdallas->onewire);
|
|
|
|
|
result = DS18B20_WaitForEndConvertion(&hdallas->onewire);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -286,7 +279,7 @@ HAL_StatusTypeDef Dallas_ConvertT(DALLAS_SensorHandleTypeDef *sensor, DALLAS_Wai
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
// Отправка команды начала преобразования температуры
|
|
|
|
|
result = DS18B20_StartConvT(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM);
|
|
|
|
|
result = DS18B20_StartConvT(&sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM);
|
|
|
|
|
if(result != HAL_OK)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
@@ -295,7 +288,7 @@ HAL_StatusTypeDef Dallas_ConvertT(DALLAS_SensorHandleTypeDef *sensor, DALLAS_Wai
|
|
|
|
|
// Ожидание завершения преобразования, путем проверки шины
|
|
|
|
|
if (waitCondition == DALLAS_WAIT_BUS)
|
|
|
|
|
{
|
|
|
|
|
result = DS18B20_WaitForEndConvertion(sensor->hdallas->onewire);
|
|
|
|
|
result = DS18B20_WaitForEndConvertion(&sensor->hdallas->onewire);
|
|
|
|
|
if(result == HAL_TIMEOUT)
|
|
|
|
|
{
|
|
|
|
|
sensor->f.timeout_convertion_cnt++;
|
|
|
|
|
@@ -365,7 +358,7 @@ HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_SensorHandleTypeDef *sensor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = DS18B20_CalcTemperature(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad, &sensor->temperature);
|
|
|
|
|
result = DS18B20_CalcTemperature(&sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad, &sensor->temperature);
|
|
|
|
|
|
|
|
|
|
if (result != HAL_OK)
|
|
|
|
|
{
|
|
|
|
|
@@ -433,7 +426,7 @@ HAL_StatusTypeDef Dallas_WriteUserBytes(DALLAS_SensorHandleTypeDef *sensor, uint
|
|
|
|
|
if (result != HAL_OK)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
result = DS18B20_WriteUserBytes(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, UserBytes12, UserBytes34, UserBytesMask);
|
|
|
|
|
result = DS18B20_WriteUserBytes(&sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, UserBytes12, UserBytes34, UserBytesMask);
|
|
|
|
|
if (result != HAL_OK)
|
|
|
|
|
{
|
|
|
|
|
sensor->f.write_err_cnt++;
|
|
|
|
|
@@ -453,7 +446,7 @@ HAL_StatusTypeDef Dallas_ReadScratchpad(DALLAS_SensorHandleTypeDef *sensor)
|
|
|
|
|
{
|
|
|
|
|
if(sensor == NULL)
|
|
|
|
|
return HAL_ERROR;
|
|
|
|
|
return DS18B20_ReadScratchpad(sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad);
|
|
|
|
|
return DS18B20_ReadScratchpad(&sensor->hdallas->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->hdallas->scratchpad);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -486,12 +479,12 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
|
|
|
|
|
|
|
|
|
uint8_t comparebytes = DALLAS_ROM_SIZE;
|
|
|
|
|
int ROM_ind = 0;
|
|
|
|
|
for(int i = 0; i < hdallas->onewire->RomCnt; i++)
|
|
|
|
|
for(int i = 0; i < hdallas->onewire.RomCnt; i++)
|
|
|
|
|
{
|
|
|
|
|
comparebytes = DALLAS_ROM_SIZE;
|
|
|
|
|
for(int rom_byte = 0; rom_byte < DALLAS_ROM_SIZE; rom_byte++)
|
|
|
|
|
{
|
|
|
|
|
if(hdallas->ds_devices->DevAddr[i][rom_byte] == ROM[rom_byte])
|
|
|
|
|
if(hdallas->ds_devices.DevAddr[i][rom_byte] == ROM[rom_byte])
|
|
|
|
|
comparebytes--;
|
|
|
|
|
}
|
|
|
|
|
if(comparebytes == 0)
|
|
|
|
|
@@ -505,7 +498,7 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
|
|
|
|
if(comparebytes == 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[ROM_ind]);
|
|
|
|
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices.DevAddr[ROM_ind]);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
@@ -540,10 +533,10 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DA
|
|
|
|
|
uint8_t UserByte12Cmp = 0;
|
|
|
|
|
uint8_t UserByte34Cmp = 0;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < hdallas->onewire->RomCnt; i++)
|
|
|
|
|
for(int i = 0; i < hdallas->onewire.RomCnt; i++)
|
|
|
|
|
{
|
|
|
|
|
/* Проверка присутствует ли выбранный датчик на линии */
|
|
|
|
|
result = DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)&hdallas->ds_devices->DevAddr[i], (uint8_t *)&hdallas->scratchpad);
|
|
|
|
|
result = DS18B20_ReadScratchpad(&hdallas->onewire, (uint8_t *)&hdallas->ds_devices.DevAddr[i], (uint8_t *)&hdallas->scratchpad);
|
|
|
|
|
if (result != HAL_OK)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
@@ -578,7 +571,7 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DA
|
|
|
|
|
{
|
|
|
|
|
// sensor->isInitialized = 1;
|
|
|
|
|
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
|
|
|
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[i]);
|
|
|
|
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices.DevAddr[i]);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -605,7 +598,7 @@ HAL_StatusTypeDef Dallas_SensorInitByInd(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
|
|
|
|
if(sensor == NULL)
|
|
|
|
|
return HAL_ERROR;
|
|
|
|
|
|
|
|
|
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[sensor->Init.InitParam.Ind]);
|
|
|
|
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices.DevAddr[sensor->Init.InitParam.Ind]);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
@@ -637,7 +630,7 @@ HAL_StatusTypeDef Dallas_SensorInit(DALLAS_HandleTypeDef *hdallas, DALLAS_Sensor
|
|
|
|
|
if (result == HAL_OK)
|
|
|
|
|
{
|
|
|
|
|
/* Установка разрешения */
|
|
|
|
|
result = DS18B20_SetResolution(hdallas->onewire, (uint8_t *)ROM, sensor->Init.Resolution);
|
|
|
|
|
result = DS18B20_SetResolution(&hdallas->onewire, (uint8_t *)ROM, sensor->Init.Resolution);
|
|
|
|
|
if (result == HAL_OK)
|
|
|
|
|
{
|
|
|
|
|
sensor->isInitialized = 1;
|
|
|
|
|
|