The main header code of the C wrapper for libpruw1. More...
Go to the source code of this file.
Classes | |
struct | pruw1 |
The PruW1 C wrapper structure. More... | |
Macros | |
#define | pruw1_scanBus(W1) pruw1_scanBus(W1, 0xF0) |
Typedefs | |
typedef unsigned char | UInt8 |
8 bit unsigned integer data type. | |
typedef short | Int16 |
16 bit signed integer data type. | |
typedef int | Int32 |
32 bit signed integer data type. | |
typedef unsigned int | UInt32 |
32 bit unsigned integer data type. | |
typedef unsigned long long int | UInt64 |
64 bit unsigned integer data type. | |
typedef struct pruw1 | pruw1 |
forward declaration More... | |
Enumerations | |
enum | LineModus { PRUW1_PARPOW = &b01 , PRUW1_PULLUP = &b10 , PRUW1_PARPOW = 0x1 , PRUW1_PULLUP = 0x2 } |
Masks for line idle configuration. More... | |
Functions | |
Int16 | T_FAM10 (UInt8 *Rom) |
Compute the temperature for a series 10 sensor (old format). More... | |
Int16 | T_FAM20 (UInt8 *Rom) |
Compute the temperature for a series 20 sensor (new format). More... | |
pruw1 * | pruw1_new (pruIo *P, UInt8 B, UInt8 M) |
Wrapper function for the constructor PruW1::PruW1(). More... | |
void | pruw1_destroy (pruw1 *W1) |
Wrapper function for the destructor PruW1::~PruW1(). More... | |
char * | pruw1_scanBus (pruw1 *W1, UInt8 SearchType) |
Function to scan the bus for all devices. More... | |
void | pruw1_sendByte (pruw1 *W1, UInt8 V) |
Send a byte (eight bits) to the bus. More... | |
void | pruw1_sendRom (pruw1 *W1, UInt64 V) |
Send a ROM ID to the bus (to select a device). More... | |
UInt8 | pruw1_recvBlock (pruw1 *W1, UInt8 N) |
Receive a block of data (usually 9 bytes). More... | |
UInt8 | pruw1_recvByte (pruw1 *W1) |
Receive a single byte (8 bit). More... | |
UInt8 | pruw1_getIn (pruw1 *W1) |
Get the state of the data line. More... | |
UInt8 | pruw1_resetBus (pruw1 *W1) |
Send the reset signal to the bus. More... | |
UInt8 | pruw1_checkPara (pruw1 *W1) |
Check line for parasite powered device. More... | |
UInt8 | pruw1_calcCrc (pruw1 *W1, UInt8 N) |
Compute the CRC checksum for data package. More... | |
Int32 | pruw1_getSlotMax (pruw1 *W1) |
Property to get size of array PruW1::Slots from C. More... | |
void | pruw1_eraseSlots (pruw1 *W1) |
Function to empty the array PruW1::Slots from C. More... | |
UInt64 | pruw1_getId (pruw1 *W1, UInt32 N) |
Function to get ID from array PruW1::Slots from C. More... | |
The main header code of the C wrapper for libpruw1.
This file provides the declarations of macros, types and classes in C syntax. Include this file in your code to make use of libpruw1. This file contains a translation of the context of all FreeBASIC headers (pruw1.bi) in one file.
Feel free to translate this file in order to create language bindings for non-C languages in order to use libpruio in polyglot applications.
Licence: LGPLv2 (http://www.gnu.org/licenses/lgpl-2.0.html)
Copyright 2015-2023 by Thomas{ dOt ]Freiherr[ aT ]gmx[DoT}net
Definition in file pruw1.h.
enum LineModus |
Masks for line idle configuration.
This enumerators are for use in CTOR PruW1::PruW1() to configure the line idle modus, regarding parasite power support and the use of the internal pull up resistor.
Compute the CRC checksum for data package.
W1 | The driver instance. |
N | The length of the package in bytes. |
A data package (usually the 64-bit scratchpad context) is in the PRU DRam after a PruW1::readBlock() operation. This function computes the CRC checksum for a package with a given length. The length parameter specifies where to find the CRC byte, so in case of an 8 byte package length has to be 9 (= the same value as in the PruW1::readBlock() call).
Check line for parasite powered device.
This function triggers a broadscast READ POWER command. The returned value is the byte received. If the function returns FALSE (0) there's no parasite powered device on the bus (all VDD=3V3). In contrast, TRUE (1) means at least one device has no external power line (VDD=GND) and needs the strong pullup in idle mode.
void pruw1_destroy | ( | pruw1 * | W1 | ) |
void pruw1_eraseSlots | ( | pruw1 * | W1 | ) |
Function to empty the array PruW1::Slots from C.
W1 | The driver instance. |
Auxiliary function to work aroung a missing feature in C syntax.
Function to get ID from array PruW1::Slots from C.
W1 | The driver instance. |
N | The number of the slot entry. |
Auxiliary function to work aroung a missing feature in C syntax.
Get the state of the data line.
W1 | The driver instance. |
This function returns the current state of the GPIO line used for the bus. The function uses libpruio to fetch the state, so only use it after the PruIo::config() call.
Property to get size of array PruW1::Slots from C.
W1 | The driver instance. |
Auxiliary function to work aroung a missing feature in C syntax.
Wrapper function for the constructor PruW1::PruW1().
P | A pointer to the libpruio instance (for pinmuxing). |
B | The header pin to use as W1 bus data line. |
M | The operating modus (Parasite power, internal pull-up). |
The constructor is designed to
In case of success the variable PruW1::Errr is 0 (zero), ready for starting the communication on the bus. Otherwise the variable contains an error message. The string is owned by libpruw1 and should not be freed. In that case call the destructor (and do not start any communication).
The operating modus M is introduced in version 0.4 in order to influence power consumption (ie. for batterie powered systems):
Receive a block of data (usually 9 bytes).
W1 | The driver instance. |
N | The number of bytes to read. |
This function triggers the bus to receive a block of bytes. Parameter N
specifies the number of bytes to read. The return value is the number of bytes read, or 0 (zero) in case of an error (message text in PruW1::Errr). The received data bytes are in the PruW1::DRam, starting at byte offset &h10
(= DRam[4]).
Receive a single byte (8 bit).
W1 | The driver instance. |
This function triggers the bus to receive a single byte. The return value is the byte received.
Send the reset signal to the bus.
W1 | The driver instance. |
This function sends the reset signal to the bus. It uses special timing. After the reset signal all devices answer by a presence pulse, so that the master knows that slave devices are on the bus. In that case the return value is 0 (zero). Otherwise, in case of no devices are responding, the return value is 1.
Function to scan the bus for all devices.
W1 | The driver instance. |
SearchType | The search type (defaults to &hF0). |
0
(zero) on success.This function scans the bus and collects the IDs of the found devices (if any) in the array Slots. By default it uses the default search ROM command (&hF0
).
Find the number of devices by evaluating the upper bound of array Slots, using function getSlotsSize().
Send a byte (eight bits) to the bus.
W1 | The driver instance. |
V | The value to send. |
This procedure sends a byte to the bus. It's usually used to issue a ROM command.
Send a ROM ID to the bus (to select a device).
W1 | The driver instance. |
V | The ROM ID (8 btes) to send. |
This procedure sends a ROM ID to the bus. It's usually used to adress a single device, ie. to read its scratchpad.
Compute the temperature for a series 10 sensor (old format).
Rom | The pointer where to find the data received from the device. |
This function decodes the temperature value from a DS18S20 sensor (such sensors have &h10
in the lowest byte of their ID). The returned value contains the temperature in grad Celsius in the high byte and the decimal places in the low byte. Divide the value by 256 to get a real number containing the temperatur in grad Celsius.
Parameter Rom
is usually the adress of PruW1::DRam[4].
Compute the temperature for a series 20 sensor (new format).
Rom | The pointer where to find the data received from the device. |
This function decodes the temperature value from a DS18B20 sensor (such sensors have &h20
in the lowest byte of their ID). The returned value contains the temperature in grad Celsius in the high byte and the decimal places in the low byte. Divide the value by 256 to get a real number containing the temperatur in grad Celsius.
Parameter Rom
is usually the adress of PruW1::DRam[4].