Skip to content

Commit

Permalink
pw_i2c: Add RegisterDevice class
Browse files Browse the repository at this point in the history
The RegisterDevice class contains helpers for reading and writing
register data to and from the device. The helpers allow the user to
easily read and write 1 register worth of data or a set of registers.

Testing:
Host test -- OK

Change-Id: Idaa9db764654103f2a068f3facaa90f96aea95df
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/41164
Commit-Queue: Kevin Zeng <[email protected]>
Reviewed-by: Ewout van Bekkum <[email protected]>
  • Loading branch information
zengkw authored and CQ Bot Account committed Apr 21, 2021
1 parent 67cf06d commit 58b43d3
Show file tree
Hide file tree
Showing 6 changed files with 1,373 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pw_i2c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ pw_cc_library(
],
)

pw_cc_library(
name = "register_device",
hdrs = [
"public/pw_i2c/register_device.h",
],
includes = ["public"],
srcs = [ "register_device.cc" ],
deps = [
":address",
":device",
":initiator",
"//pw_bytes",
"//pw_chrono:system_clock",
"//pw_result",
"//pw_status",
],
)

pw_cc_test(
name = "address_test",
srcs = [
Expand All @@ -85,3 +103,15 @@ pw_cc_test(
"//pw_unit_test",
],
)

pw_cc_test(
name = "register_device_test",
srcs = [
"register_device_test.cc",
],
deps = [
":register_device",
"//pw_assert",
"//pw_unit_test",
],
)
27 changes: 27 additions & 0 deletions pw_i2c/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,28 @@ pw_source_set("device") {
"$dir_pw_status",
]
}

pw_source_set("register_device") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_i2c/register_device.h" ]
public_deps = [
":address",
":device",
":initiator",
"$dir_pw_bytes",
"$dir_pw_chrono:system_clock",
"$dir_pw_result",
"$dir_pw_status",
]
sources = [ "register_device.cc" ]
deps = [ "$dir_pw_assert" ]
}

pw_test_group("tests") {
tests = [
":address_test",
":device_test",
":register_device_test",
]
}

Expand All @@ -70,6 +88,15 @@ pw_test("device_test") {
deps = [ ":device" ]
}

pw_test("register_device_test") {
enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != ""
sources = [ "register_device_test.cc" ]
deps = [
":register_device",
"$dir_pw_assert",
]
}

pw_doc_group("docs") {
sources = [ "docs.rst" ]
}
8 changes: 8 additions & 0 deletions pw_i2c/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ The common interface for interfacing with generic I2C devices. This object
contains ``pw::i2c::Address`` and wraps the ``pw::i2c::Initiator`` API.
Common use case includes streaming arbitrary data (Read/Write). Only works
with devices with a single device address.

pw::i2c::RegisterDevice
-----------------------
The common interface for interfacing with register devices. Contains methods
to help read and write registers from and to the device. Users should have a
understanding of the capabilities of their device such as register address
sizes, register data sizes, byte addressability, bulk transactions, etc in
order to effectively use this interface.
Loading

0 comments on commit 58b43d3

Please sign in to comment.