Browse Source

Remove _static headers as hidden structs don't work so well in an embedded environment. Add doxygen documentation.

main
David Antliff 8 years ago
parent
commit
ae0fb9a5a2
  1. 26
      README.md
  2. 3
      doc/.gitignore
  3. 2474
      doc/Doxyfile
  4. 4
      doc/getting_started.md
  5. 12
      main/ds18b20.c
  6. 24
      main/ds18b20.h
  7. 13
      main/ds18b20_main.c
  8. 53
      main/ds18b20_static.h
  9. 7
      main/owb.c
  10. 39
      main/owb.h
  11. 52
      main/owb_static.h

26
README.md

@ -1,4 +1,4 @@
# DS18B20 1-Wire
# ESP32-DS18B20
## Introduction
@ -15,14 +15,13 @@ It supports multiple devices on the same 1-Wire bus.
* CRC checks on ROM code and temperature data.
* Temperature convertion and retrieval.
## Roadmap
## Documentation
* Simultaneous temperature conversion from multiple devices.
* Device configuration including resolution.
* Alarm support.
* Single device optimisations - avoid ROM addressing when only one device exists.
* Parasitic power support.
* EEPROM support.
API documentation (doxygen) is available [here](https://...).
## Source Code
The source is available from [GitHub](https://www.github.com/DavidAntliff/ESP32-DS18B20).
## License
@ -41,3 +40,14 @@ Parts of this code are based on references provided to the public domain by Maxi
"1-Wire" is a registered trademark of Maxim Integrated.
## Roadmap
The following features are anticipated but not yet implemented:
* Simultaneous temperature conversion from multiple devices.
* Device configuration including resolution.
* Alarm support.
* Single device optimisations - avoid ROM addressing when only one device exists.
* Parasitic power support.
* EEPROM support.

3
doc/.gitignore

@ -0,0 +1,3 @@
html/
latex/

2474
doc/Doxyfile

File diff suppressed because it is too large

4
doc/getting_started.md

@ -0,0 +1,4 @@
# Getting Started
TODO...

12
main/ds18b20.c

@ -22,6 +22,10 @@
* SOFTWARE.
*/
/**
* @file ds18b20.c
*/
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
@ -51,14 +55,6 @@ static const char * TAG = "ds18b20";
#define DS18B20_FUNCTION_POWER_SUPPLY_READ 0xB4
struct _DS18B20_Info
{
bool init;
bool use_crc;
OneWireBus * bus;
OneWireBus_ROMCode rom_code;
};
static bool _is_init(const DS18B20_Info * ds18b20_info)
{
bool ok = false;

24
main/ds18b20.h

@ -22,6 +22,15 @@
* 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
@ -31,8 +40,17 @@
extern "C" {
#endif
typedef struct _DS18B20_Info DS18B20_Info;
/**
* @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.
@ -68,7 +86,7 @@ void ds18b20_use_crc(DS18B20_Info * ds18b20_info, bool use_crc);
* @param[in] ds18b20_info Pointer to device info instance.
* @return The 64-bit value read from the device's ROM.
*/
uint64_t ds18b20_read_rom(DS18B20_Info * ds18b20_info);
OneWireBus_ROMCode ds18b20_read_rom(DS18B20_Info * ds18b20_info);
/**
* @brief Get current temperature from device.

13
main/ds18b20_main.c

@ -32,13 +32,8 @@
// Uncomment to enable static (stack-based) allocation of instances and avoid malloc/free.
//#define USE_STATIC 1
#ifdef USE_STATIC
# include "owb_static.h"
# include "ds18b20_static.h"
#else
# include "owb.h"
# include "ds18b20.h"
#endif
#include "owb.h"
#include "ds18b20.h"
#define GPIO_DS18B20_0 (GPIO_NUM_4)
@ -51,7 +46,7 @@ void app_main()
// Create a 1-Wire bus
#ifdef USE_STATIC
OneWireBus_Static owb_static; // static allocation
OneWireBus owb_static; // static allocation
OneWireBus * owb = &owb_static;
#else
OneWireBus * owb = owb_malloc(); // heap allocation
@ -90,7 +85,7 @@ void app_main()
// Create a DS18B20 device on the 1-Wire bus
#ifdef USE_STATIC
DS18B20_Info_Static ds18b20_info_static; // static allocation
DS18B20_Info ds18b20_info_static; // static allocation
DS18B20_Info * ds18b20_info = &ds18b20_info_static;
DS18B20_Info devices_static[MAX_DEVICES] = {0};
DS18B20_Info * devices[MAX_DEVICES] = {0};

53
main/ds18b20_static.h

@ -1,53 +0,0 @@
/*
* 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.
*/
// Expose structure for stack-based (static) allocation.
#ifndef DS18B20_STATIC_H
#define DS18B20_STATIC_H
#include <stdbool.h>
#include <stdint.h>
#include "ds18b20.h"
#ifdef __cplusplus
extern "C" {
#endif
struct _DS18B20_Info
{
bool init;
bool use_crc;
OneWireBus * bus;
uint64_t rom_code;
};
typedef struct _DS18B20_Info DS18B20_Info_Static;
#ifdef __cplusplus
}
#endif
#endif // DS18B20_STATIC_H

7
main/owb.c

@ -22,6 +22,10 @@
* SOFTWARE.
*/
/**
* @file owb.c
*/
#include <stddef.h>
#include <stdbool.h>
#include <inttypes.h>
@ -32,14 +36,15 @@
#include "driver/gpio.h"
#include "owb.h"
#include "owb_static.h"
static const char * TAG = "owb";
/// @cond ignore
struct _OneWireBus_Timing
{
int A, B, C, D, E, F, G, H, I, J;
};
//// @endcond
// 1-Wire timing delays (standard) in ticks (quarter-microseconds).
static const struct _OneWireBus_Timing _StandardTiming = {

39
main/owb.h

@ -22,6 +22,16 @@
* SOFTWARE.
*/
/**
* @file owb.h
* @brief Interface definitions for the 1-Wire bus component.
*
* This component provides structures and functions that are useful for communicating
* with devices connected to a Maxim Integrated 1-Wire® bus via a single GPIO.
*
* Currently only externally powered devices are supported. Parasitic power is not supported.
*/
#ifndef ONE_WIRE_BUS_H
#define ONE_WIRE_BUS_H
@ -40,7 +50,16 @@ extern "C" {
#define OWB_ROM_SKIP 0xCC
#define OWB_ROM_SEARCH_ALARM 0xEC
typedef struct _OneWireBus OneWireBus;
/**
* @brief Structure containing 1-Wire bus information relevant to a single instance.
*/
typedef struct
{
bool init; ///< True if struct has been initialised, otherwise false.
int gpio; ///< Value of GPIO connected to 1-Wire bus
const struct _OneWireBus_Timing * timing; ///< Pointer to timing information
bool use_crc; ///< True if CRC checks are to be used when retrieving information from a device on the bus
} OneWireBus;
/**
* @brief Represents a 1-Wire ROM Code. This is a sequence of eight bytes, where
@ -49,14 +68,15 @@ typedef struct _OneWireBus OneWireBus;
*/
typedef union
{
/// Provides access via field names
struct fields
{
uint8_t family[1]; // LSB - read/write first
uint8_t serial_number[6];
uint8_t crc[1]; // MSB
} fields;
uint8_t family[1]; ///< family identifier (1 byte, LSB - read/write first)
uint8_t serial_number[6]; ///< serial number (6 bytes)
uint8_t crc[1]; ///< CRC check byte (1 byte, MSB - read/write last)
} fields; ///< Provides access via field names
uint8_t bytes[8];
uint8_t bytes[8]; ///< Provides raw byte access
} OneWireBus_ROMCode;
@ -172,9 +192,10 @@ uint8_t owb_crc8_bytes(uint8_t crc, const uint8_t * data, size_t len);
// Search API
/**
* @brief Represents the state of a device search on the 1-Wire bus. Pass a pointer to
* this structure to `owb_search_first` and `owb_search_next` to iterate through
* detected devices on the bus.
* @brief Represents the state of a device search on the 1-Wire bus.
*
* Pass a pointer to this structure to owb_search_first() and
* owb_search_next() to iterate through detected devices on the bus.
*/
typedef struct
{

52
main/owb_static.h

@ -1,52 +0,0 @@
/*
* 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.
*/
// Expose structure for stack-based (static) allocation.
#ifndef ONE_WIRE_BUS_STATIC_H
#define ONE_WIRE_BUS_STATIC_H
#include <stdbool.h>
#include "owb.h"
#ifdef __cplusplus
extern "C" {
#endif
struct _OneWireBus
{
bool init;
int gpio;
const struct _OneWireBus_Timing * timing;
bool use_crc;
};
typedef struct _OneWireBus OneWireBus_Static;
#ifdef __cplusplus
}
#endif
#endif // ONE_WIRE_BUS_STATIC_H
Loading…
Cancel
Save