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("@rules_python//python:proto.bzl", "py_proto_library") 17load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 18load( 19 "//pw_protobuf_compiler:pw_proto_library.bzl", 20 "pw_proto_filegroup", 21 "pwpb_proto_library", 22 "pwpb_rpc_proto_library", 23) 24load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 25 26package(default_visibility = ["//visibility:public"]) 27 28licenses(["notice"]) 29 30cc_library( 31 name = "address", 32 srcs = [ 33 "address.cc", 34 ], 35 hdrs = [ 36 "public/pw_i2c/address.h", 37 ], 38 strip_include_prefix = "public", 39 deps = [ 40 "//pw_assert", 41 ], 42) 43 44cc_library( 45 name = "initiator", 46 hdrs = [ 47 "public/pw_i2c/initiator.h", 48 ], 49 strip_include_prefix = "public", 50 deps = [ 51 ":address", 52 "//pw_bytes", 53 "//pw_chrono:system_clock", 54 "//pw_status", 55 ], 56) 57 58cc_library( 59 name = "device", 60 hdrs = [ 61 "public/pw_i2c/device.h", 62 ], 63 strip_include_prefix = "public", 64 deps = [ 65 ":address", 66 ":initiator", 67 "//pw_bytes", 68 "//pw_chrono:system_clock", 69 "//pw_status", 70 ], 71) 72 73cc_library( 74 name = "register_device", 75 srcs = ["register_device.cc"], 76 hdrs = [ 77 "public/pw_i2c/register_device.h", 78 ], 79 strip_include_prefix = "public", 80 deps = [ 81 ":address", 82 ":device", 83 ":initiator", 84 "//pw_bytes", 85 "//pw_chrono:system_clock", 86 "//pw_result", 87 "//pw_status", 88 ], 89) 90 91pw_cc_test( 92 name = "address_test", 93 srcs = [ 94 "address_test.cc", 95 ], 96 deps = [ 97 ":address", 98 "//pw_unit_test", 99 ], 100) 101 102cc_library( 103 name = "initiator_mock", 104 testonly = True, 105 srcs = ["initiator_mock.cc"], 106 hdrs = ["public/pw_i2c/initiator_mock.h"], 107 strip_include_prefix = "public", 108 deps = [ 109 ":address", 110 ":initiator", 111 "//pw_assert", 112 "//pw_containers", 113 "//pw_containers:to_array", 114 "//pw_unit_test", 115 ], 116) 117 118cc_library( 119 name = "initiator_gmock", 120 testonly = True, 121 hdrs = [ 122 "public/pw_i2c/initiator_gmock.h", 123 ], 124 strip_include_prefix = "public", 125 # TODO: b/310957361 - gtest not supported on device 126 target_compatible_with = incompatible_with_mcu(), 127 deps = [ 128 ":initiator", 129 "@com_google_googletest//:gtest", 130 ], 131) 132 133pw_cc_test( 134 name = "initiator_mock_test", 135 srcs = [ 136 "initiator_mock_test.cc", 137 ], 138 deps = [ 139 ":initiator_mock", 140 "//pw_bytes", 141 "//pw_containers", 142 "//pw_unit_test", 143 ], 144) 145 146pw_cc_test( 147 name = "device_test", 148 srcs = [ 149 "device_test.cc", 150 ], 151 deps = [ 152 ":device", 153 ":initiator_mock", 154 "//pw_containers", 155 "//pw_unit_test", 156 ], 157) 158 159pw_cc_test( 160 name = "register_device_test", 161 srcs = [ 162 "register_device_test.cc", 163 ], 164 deps = [ 165 ":register_device", 166 "//pw_unit_test", 167 ], 168) 169 170pw_proto_filegroup( 171 name = "i2c_proto_and_options", 172 srcs = ["i2c.proto"], 173 options_files = ["i2c.pwpb_options"], 174) 175 176proto_library( 177 name = "i2c_proto", 178 srcs = [":i2c_proto_and_options"], 179) 180 181pwpb_proto_library( 182 name = "i2c_pwpb", 183 deps = [":i2c_proto"], 184) 185 186pwpb_rpc_proto_library( 187 name = "i2c_pwpb_rpc", 188 pwpb_proto_library_deps = [":i2c_pwpb"], 189 deps = [":i2c_proto"], 190) 191 192py_proto_library( 193 name = "i2c_py_pb2", 194 deps = [":i2c_proto"], 195) 196 197cc_library( 198 name = "i2c_service", 199 srcs = ["i2c_service.cc"], 200 hdrs = ["public/pw_i2c/i2c_service.h"], 201 strip_include_prefix = "public", 202 deps = [ 203 ":address", 204 ":i2c_pwpb_rpc", 205 ":initiator", 206 "//pw_chrono:system_clock", 207 "//pw_containers:vector", 208 "//pw_status", 209 ], 210) 211 212pw_cc_test( 213 name = "i2c_service_test", 214 srcs = ["i2c_service_test.cc"], 215 deps = [ 216 ":i2c_service", 217 ":initiator_mock", 218 "//pw_containers:vector", 219 "//pw_rpc/pwpb:test_method_context", 220 "//pw_status", 221 ], 222) 223 224filegroup( 225 name = "doxygen", 226 srcs = [ 227 "public/pw_i2c/address.h", 228 "public/pw_i2c/device.h", 229 "public/pw_i2c/i2c_service.h", 230 "public/pw_i2c/initiator.h", 231 "public/pw_i2c/initiator_gmock.h", 232 "public/pw_i2c/initiator_mock.h", 233 "public/pw_i2c/register_device.h", 234 ], 235) 236