You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.8 KiB
103 lines
3.8 KiB
/*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2017 David Antliff
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
/**
|
|
* @file ds18b20.h
|
|
* @brief Interface definitions for the Maxim Integrated DS18B20 Programmable
|
|
* Resolution 1-Wire Digital Thermometer device.
|
|
*
|
|
* This component provides structures and functions that are useful for communicating
|
|
* with DS18B20 devices connected via a Maxim Integrated 1-Wire® bus.
|
|
*/
|
|
|
|
#ifndef DS18B20_H
|
|
#define DS18B20_H
|
|
|
|
#include "owb.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* @brief Structure containing information related to a single DS18B20 device connected
|
|
* via a 1-Wire bus.
|
|
*/
|
|
typedef struct
|
|
{
|
|
bool init; ///< True if struct has been initialised, otherwise false.
|
|
bool use_crc; ///< True if CRC checks are to be used when retrieving information from a device on the bus
|
|
OneWireBus * bus; ///< Pointer to 1-Wire bus information relevant to this device.
|
|
OneWireBus_ROMCode rom_code; ///< The ROM code used to address this device on the bus.
|
|
} DS18B20_Info;
|
|
|
|
/**
|
|
* @brief Construct a new device info instance.
|
|
* New instance should be initialised before calling other functions.
|
|
* @return Pointer to new device info instance, or NULL if it cannot be created.
|
|
*/
|
|
DS18B20_Info * ds18b20_malloc(void);
|
|
|
|
/**
|
|
* @brief Delete an existing device info instance.
|
|
* @param[in] ds18b20_info Pointer to device info instance.
|
|
* @param[in,out] ds18b20_info Pointer to device info instance that will be freed and set to NULL.
|
|
*/
|
|
void ds18b20_free(DS18B20_Info ** ds18b20_info);
|
|
|
|
/**
|
|
* @brief Initialise a device info instance with the specified GPIO.
|
|
* @param[in] ds18b20_info Pointer to device info instance.
|
|
* @param[in] bus Pointer to initialised 1-Wire bus instance.
|
|
* @param[in] rom_code Device-specific ROM code to identify a device on the bus.
|
|
*/
|
|
void ds18b20_init(DS18B20_Info * ds18b20_info, OneWireBus * bus, OneWireBus_ROMCode rom_code);
|
|
|
|
/**
|
|
* @brief Enable or disable use of CRC checks on device communications.
|
|
* @param[in] ds18b20_info Pointer to device info instance.
|
|
* @param[in] use_crc True to enable CRC checks, false to disable.
|
|
*/
|
|
void ds18b20_use_crc(DS18B20_Info * ds18b20_info, bool use_crc);
|
|
|
|
/**
|
|
* @brief Read 64-bit ROM code from device - only works when there is a single device on the bus.
|
|
* @param[in] ds18b20_info Pointer to device info instance.
|
|
* @return The 64-bit value read from the device's ROM.
|
|
*/
|
|
OneWireBus_ROMCode ds18b20_read_rom(DS18B20_Info * ds18b20_info);
|
|
|
|
/**
|
|
* @brief Get current temperature from device.
|
|
* @param[in] ds18b20_info Pointer to device info instance. Must be initialised first.
|
|
* @return The current temperature returned by the device, in degrees Celsius.
|
|
*/
|
|
float ds18b20_get_temp(DS18B20_Info * ds18b20_info);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // DS18B20_H
|
|
|