diff --git a/DS18B20/dallas_tools.c b/DS18B20/dallas_tools.c index 984264f..b12d232 100644 --- a/DS18B20/dallas_tools.c +++ b/DS18B20/dallas_tools.c @@ -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; diff --git a/DS18B20/dallas_tools.h b/DS18B20/dallas_tools.h index 0dff84a..8f90552 100644 --- a/DS18B20/dallas_tools.h +++ b/DS18B20/dallas_tools.h @@ -95,8 +95,8 @@ typedef struct __packed /** @brief Cтруктура обработчика DALLAS для общения с датчиком*/ struct _DallasHandleStruct { - OneWire_t *onewire; - DS18B20_Drv_t *ds_devices; + OneWire_t onewire; + DS18B20_Drv_t ds_devices; DALLAS_ScratchpadTypeDef scratchpad; }; extern DALLAS_HandleTypeDef hdallas; @@ -132,9 +132,9 @@ typedef enum /* Functions ---------------------------------------------------------------*/ /* Функция для иниицализации структуры dallas и шины OW для датчиков */ #ifndef UART_Driver -HAL_StatusTypeDef Dallas_BusFirstInit(DALLAS_HandleTypeDef *hdallas, GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, OneWire_t *OW, DS18B20_Drv_t *DS); +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, DS18B20_Drv_t *DS); +HAL_StatusTypeDef Dallas_BusFirstInit(DALLAS_HandleTypeDef *hdallas, UART_HandleTypeDef *huart); #endif /* Поиск датчиков на шине onewire */ HAL_StatusTypeDef Dallas_Search(DALLAS_HandleTypeDef *hdallas); diff --git a/DS18B20/ds18b20_driver.c b/DS18B20/ds18b20_driver.c index 416d8a4..f3f8dd0 100644 --- a/DS18B20/ds18b20_driver.c +++ b/DS18B20/ds18b20_driver.c @@ -7,8 +7,6 @@ */ #include "ds18b20_driver.h" -DS18B20_Drv_t DS; -OneWire_t OW; /** * @brief The function is used to check valid DS18B20 ROM diff --git a/DS18B20/ow_port.h b/DS18B20/ow_port.h index ca8cda9..f0c9cb2 100644 --- a/DS18B20/ow_port.h +++ b/DS18B20/ow_port.h @@ -13,7 +13,7 @@ #include "stm32f1xx_hal.h" /* I/O Port ------------------------------------------------------------------*/ -#define UART_Driver ///< использовтаь UART (onewire_uart.c/.h) +//#define UART_Driver ///< использовтаь UART (onewire_uart.c/.h) //#define LL_Driver ///< использовать CMSIS для управления ножкой #define CMSIS_Driver ///< использовать CMSIS для управления ножкой // если ничего не выбрано - используется HAL diff --git a/test/Core/Src/main.c b/test/Core/Src/main.c index 3ea936c..86be4de 100644 --- a/test/Core/Src/main.c +++ b/test/Core/Src/main.c @@ -92,9 +92,9 @@ int main(void) MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ #ifndef UART_Driver - Dallas_BusFirstInit(&hdallas, OW_GPIO_Port, OW_Pin, NULL, NULL); + Dallas_BusFirstInit(&hdallas, OW_GPIO_Port, OW_Pin); #else - Dallas_BusFirstInit(&hdallas, &huart1, NULL, NULL); + Dallas_BusFirstInit(&hdallas, &huart1); #endif sens.Init.InitParam.Ind = 0; sens.Init.init_func = &Dallas_SensorInitByInd;