1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15load("@rules_proto//proto:defs.bzl", "proto_library") 16load( 17 "//pw_build:pigweed.bzl", 18 "pw_cc_test", 19) 20load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT") 21load( 22 "//pw_protobuf_compiler:pw_proto_library.bzl", 23 "pw_proto_filegroup", 24 "pw_proto_library", 25) 26 27package(default_visibility = ["//visibility:public"]) 28 29licenses(["notice"]) 30 31cc_library( 32 name = "address", 33 srcs = [ 34 "address.cc", 35 ], 36 hdrs = [ 37 "public/pw_i2c/address.h", 38 ], 39 includes = ["public"], 40 deps = [ 41 "//pw_assert", 42 ], 43) 44 45cc_library( 46 name = "initiator", 47 hdrs = [ 48 "public/pw_i2c/initiator.h", 49 ], 50 includes = ["public"], 51 deps = [ 52 ":address", 53 "//pw_bytes", 54 "//pw_chrono:system_clock", 55 "//pw_status", 56 ], 57) 58 59cc_library( 60 name = "device", 61 hdrs = [ 62 "public/pw_i2c/device.h", 63 ], 64 includes = ["public"], 65 deps = [ 66 ":address", 67 ":initiator", 68 "//pw_bytes", 69 "//pw_chrono:system_clock", 70 "//pw_status", 71 ], 72) 73 74cc_library( 75 name = "register_device", 76 srcs = ["register_device.cc"], 77 hdrs = [ 78 "public/pw_i2c/register_device.h", 79 ], 80 includes = ["public"], 81 deps = [ 82 ":address", 83 ":device", 84 ":initiator", 85 "//pw_bytes", 86 "//pw_chrono:system_clock", 87 "//pw_result", 88 "//pw_status", 89 ], 90) 91 92pw_cc_test( 93 name = "address_test", 94 srcs = [ 95 "address_test.cc", 96 ], 97 deps = [ 98 ":address", 99 "//pw_unit_test", 100 ], 101) 102 103cc_library( 104 name = "initiator_mock", 105 testonly = True, 106 srcs = ["initiator_mock.cc"], 107 hdrs = ["public/pw_i2c/initiator_mock.h"], 108 includes = ["public"], 109 deps = [ 110 ":address", 111 ":initiator", 112 "//pw_assert", 113 "//pw_containers", 114 "//pw_containers:to_array", 115 "//pw_unit_test", 116 ], 117) 118 119cc_library( 120 name = "initiator_gmock", 121 testonly = True, 122 hdrs = [ 123 "public/pw_i2c/initiator_gmock.h", 124 ], 125 includes = ["public"], 126 # TODO: b/310957361 - gtest not supported on device 127 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT), 128 deps = [ 129 ":initiator", 130 "@com_google_googletest//:gtest", 131 ], 132) 133 134pw_cc_test( 135 name = "initiator_mock_test", 136 srcs = [ 137 "initiator_mock_test.cc", 138 ], 139 deps = [ 140 ":initiator_mock", 141 "//pw_bytes", 142 "//pw_containers", 143 "//pw_unit_test", 144 ], 145) 146 147pw_cc_test( 148 name = "device_test", 149 srcs = [ 150 "device_test.cc", 151 ], 152 deps = [ 153 ":device", 154 ":initiator_mock", 155 "//pw_containers", 156 "//pw_unit_test", 157 ], 158) 159 160pw_cc_test( 161 name = "register_device_test", 162 srcs = [ 163 "register_device_test.cc", 164 ], 165 deps = [ 166 ":register_device", 167 "//pw_unit_test", 168 ], 169) 170 171pw_proto_filegroup( 172 name = "i2c_proto_and_options", 173 srcs = ["i2c.proto"], 174 options_files = ["i2c.options"], 175) 176 177proto_library( 178 name = "i2c_proto", 179 srcs = [":i2c_proto_and_options"], 180) 181 182pw_proto_library( 183 name = "i2c_cc", 184 deps = [":i2c_proto"], 185) 186 187cc_library( 188 name = "i2c_service", 189 srcs = ["i2c_service.cc"], 190 hdrs = ["public/pw_i2c/i2c_service.h"], 191 includes = ["public"], 192 deps = [ 193 ":address", 194 ":i2c_cc.pwpb_rpc", 195 ":initiator", 196 "//pw_chrono:system_clock", 197 "//pw_containers:vector", 198 "//pw_status", 199 ], 200) 201 202pw_cc_test( 203 name = "i2c_service_test", 204 srcs = ["i2c_service_test.cc"], 205 deps = [ 206 ":i2c_service", 207 ":initiator_mock", 208 "//pw_containers:vector", 209 "//pw_rpc/pwpb:test_method_context", 210 "//pw_status", 211 ], 212) 213