Skip to content

Commit

Permalink
Extended virtual interface reduced to touch methods only
Browse files Browse the repository at this point in the history
  • Loading branch information
pstolarz committed Feb 2, 2025
1 parent e7f7b22 commit 4b8f73f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
34 changes: 9 additions & 25 deletions src/OneWireNg.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023 Piotr Stolarz
* Copyright (c) 2019-2023,2025 Piotr Stolarz
* OneWireNg: Arduino 1-wire service library
*
* Distributed under the 2-clause BSD License (the License)
Expand Down Expand Up @@ -167,10 +167,8 @@ class OneWireNg
* @param power If parasite powering is supported, setting the argument
* to @c true powers the bus after the operation finishes. See @ref
* powerBus() for details.
*
* @note This method is part of the extended virtual interface.
*/
EXT_VIRTUAL_INTF void writeBit(int bit, bool power = false) {
void writeBit(int bit, bool power = false) {
touchBit(bit, power);
}

Expand All @@ -179,10 +177,8 @@ class OneWireNg
*
* @param bit Byte to be written on the bus.
* @param power Same as for @ref writeBit().
*
* @note This method is part of the extended virtual interface.
*/
EXT_VIRTUAL_INTF void writeByte(uint8_t byte, bool power = false) {
void writeByte(uint8_t byte, bool power = false) {
touchByte(byte, power);
}

Expand All @@ -192,10 +188,8 @@ class OneWireNg
* @param bytes Array of bytes to be written on the bus.
* @param len Length of the array.
* @param power Same as for @ref writeBit().
*
* @note This method is part of the extended virtual interface.
*/
EXT_VIRTUAL_INTF void writeBytes(
void writeBytes(
const uint8_t *bytes, size_t len, bool power = false)
{
for (size_t i = 0; i < len; i++)
Expand All @@ -206,21 +200,17 @@ class OneWireNg
* Bit read.
*
* @return Reading result.
*
* @note This method is part of the extended virtual interface.
*/
EXT_VIRTUAL_INTF int readBit() {
int readBit() {
return touchBit(1);
}

/**
* Byte read with least significant bit transmitted first.
*
* @return Reading result.
*
* @note This method is part of the extended virtual interface.
*/
EXT_VIRTUAL_INTF uint8_t readByte() {
uint8_t readByte() {
return touchByte(0xff);
}

Expand All @@ -229,10 +219,8 @@ class OneWireNg
*
* @param bytes Array of bytes to store the reading result.
* @param len Number of bytes to read (length of the array).
*
* @note This method is part of the extended virtual interface.
*/
EXT_VIRTUAL_INTF void readBytes(uint8_t *bytes, size_t len) {
void readBytes(uint8_t *bytes, size_t len) {
for (size_t i = 0; i < len; i++)
bytes[i] = touchByte(0xff);
}
Expand Down Expand Up @@ -260,8 +248,6 @@ class OneWireNg
* - @c EC_BUS_ERROR: Bus error.
* - @c EC_CRC_ERROR: CRC error.
*
* @note This method is part of the extended virtual interface.
*
* @note It is possible to use C++11 range loop to iterate over connected
* slaves as in the following code snippet:
*
Expand All @@ -273,14 +259,12 @@ class OneWireNg
* }
* @endcode
*/
EXT_VIRTUAL_INTF ErrorCode search(Id& id, bool alarm = false);
ErrorCode search(Id& id, bool alarm = false);

/**
* Reset 1-wire search state for a subsequent search-scan process.
*
* @note This method is part of the extended virtual interface.
*/
EXT_VIRTUAL_INTF void searchReset() {
void searchReset() {
_lzero = -1;
}
#endif /* CONFIG_SEARCH_ENABLED */
Expand Down
14 changes: 7 additions & 7 deletions src/OneWireNg_Config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2024 Piotr Stolarz
* Copyright (c) 2019-2025 Piotr Stolarz
* OneWireNg: Arduino 1-wire service library
*
* Distributed under the 2-clause BSD License (the License)
Expand Down Expand Up @@ -262,19 +262,19 @@
/**
* Boolean parameter to enable extended virtual interface.
*
* The extended interface enables more advance 1-wire service drivers to be
* implemented in the future. The penalty is additional overhead needed for
* calling the virtual methods being part of this interface. Since current
* implementation doesn't leverage the interface it's recommended to disable
* this parameter for slower platforms.
* Extended virtual interface extends number of virtual methods OneWireNg class
* provides, enabling implementation of more advanced 1-wire service drivers.
* The penalty is additional overhead needed for calling the extra virtual
* methods. To avoid the overhead it's recommended to enable the extended
* interface only for drivers requiring it.
*/
# ifndef CONFIG_EXT_VIRTUAL_INTF
# define CONFIG_EXT_VIRTUAL_INTF 0
# endif

/**
* For C++11 range-loop used during search-scan process to detect slave devices
* connected to the bus, the parameter specifies number or the search command
* connected to the bus, the parameter specifies number of "Search" command
* resends in case of CRC or bus error. The parameter may be useful for error
* prone setups. If 0 - no retires.
*
Expand Down

0 comments on commit 4b8f73f

Please sign in to comment.