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 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/target_types.gni") 18import("$dir_pw_chrono/backend.gni") 19import("$dir_pw_docgen/docs.gni") 20import("$dir_pw_protobuf_compiler/proto.gni") 21import("$dir_pw_unit_test/test.gni") 22 23config("public_include_path") { 24 include_dirs = [ "public" ] 25} 26 27pw_source_set("address") { 28 public_configs = [ ":public_include_path" ] 29 public = [ "public/pw_i2c/address.h" ] 30 deps = [ "$dir_pw_assert" ] 31 sources = [ "address.cc" ] 32} 33 34pw_source_set("initiator") { 35 public_configs = [ ":public_include_path" ] 36 public = [ "public/pw_i2c/initiator.h" ] 37 public_deps = [ 38 ":address", 39 "$dir_pw_bytes", 40 "$dir_pw_chrono:system_clock", 41 "$dir_pw_status", 42 ] 43} 44 45pw_source_set("device") { 46 public_configs = [ ":public_include_path" ] 47 public = [ "public/pw_i2c/device.h" ] 48 public_deps = [ 49 ":address", 50 ":initiator", 51 "$dir_pw_bytes", 52 "$dir_pw_chrono:system_clock", 53 "$dir_pw_status", 54 dir_pw_span, 55 ] 56} 57 58pw_source_set("register_device") { 59 public_configs = [ ":public_include_path" ] 60 public = [ "public/pw_i2c/register_device.h" ] 61 public_deps = [ 62 ":address", 63 ":device", 64 ":initiator", 65 "$dir_pw_bytes", 66 "$dir_pw_chrono:system_clock", 67 "$dir_pw_result", 68 "$dir_pw_status", 69 ] 70 sources = [ "register_device.cc" ] 71 deps = [ "$dir_pw_assert" ] 72} 73 74pw_proto_library("protos") { 75 sources = [ "i2c.proto" ] 76 inputs = [ "i2c.pwpb_options" ] 77 prefix = "pw_i2c" 78} 79 80pw_source_set("i2c_service") { 81 public = [ "public/pw_i2c/i2c_service.h" ] 82 sources = [ "i2c_service.cc" ] 83 public_deps = [ 84 ":protos.pwpb_rpc", 85 "$dir_pw_chrono:system_clock", 86 "$dir_pw_i2c:initiator", 87 ] 88 deps = [ 89 "$dir_pw_containers:vector", 90 "$dir_pw_i2c:address", 91 "$dir_pw_status", 92 ] 93} 94 95pw_source_set("mock") { 96 public_configs = [ ":public_include_path" ] 97 public = [ "public/pw_i2c/initiator_mock.h" ] 98 sources = [ "initiator_mock.cc" ] 99 public_deps = [ 100 ":initiator", 101 "$dir_pw_bytes", 102 "$dir_pw_containers", 103 "$dir_pw_containers:to_array", 104 ] 105 deps = [ 106 "$dir_pw_assert", 107 "$dir_pw_unit_test", 108 ] 109} 110 111pw_source_set("gmock") { 112 public_configs = [ ":public_include_path" ] 113 public_deps = [ 114 ":initiator", 115 "$dir_pw_third_party/googletest", 116 ] 117 public = [ "public/pw_i2c/initiator_gmock.h" ] 118} 119 120# TODO: add mock_test here once chrono backend is supported for stm32f429i-disc1 121pw_test_group("tests") { 122 tests = [ 123 ":address_test", 124 ":device_test", 125 ":initiator_mock_test", 126 ":register_device_test", 127 ":i2c_service_test", 128 ] 129} 130 131pw_test("address_test") { 132 sources = [ "address_test.cc" ] 133 deps = [ ":address" ] 134} 135 136pw_test("device_test") { 137 enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != "" 138 sources = [ "device_test.cc" ] 139 deps = [ 140 ":device", 141 ":mock", 142 "$dir_pw_chrono:system_clock", 143 "$dir_pw_containers", 144 ] 145} 146 147pw_test("register_device_test") { 148 enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != "" 149 sources = [ "register_device_test.cc" ] 150 deps = [ 151 ":register_device", 152 "$dir_pw_assert", 153 ] 154 155 # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs 156 # indefinitely. 157 if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { 158 enable_if = false 159 } 160} 161 162pw_test("initiator_mock_test") { 163 enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != "" 164 sources = [ "initiator_mock_test.cc" ] 165 deps = [ 166 ":mock", 167 "$dir_pw_chrono:system_clock", 168 "$dir_pw_containers", 169 ] 170} 171 172pw_test("i2c_service_test") { 173 enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != "" 174 sources = [ "i2c_service_test.cc" ] 175 deps = [ 176 ":i2c_service", 177 "$dir_pw_chrono:system_clock", 178 "$dir_pw_containers:vector", 179 "$dir_pw_i2c:mock", 180 "$dir_pw_rpc/pwpb:test_method_context", 181 "$dir_pw_status", 182 ] 183 184 # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs 185 # indefinitely. 186 if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { 187 enable_if = false 188 } 189} 190 191pw_doc_group("docs") { 192 sources = [ 193 "backends.rst", 194 "docs.rst", 195 "guides.rst", 196 "reference.rst", 197 ] 198} 199