1 /* 2 * Copyright (c) 2022 Caspar Friedrich <c.s.w.friedrich@gmail.com> 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/device.h> 8 #include <zephyr/devicetree.h> 9 #include <zephyr/drivers/w1.h> 10 #include <zephyr/logging/log.h> 11 12 LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); 13 w1_search_callback(struct w1_rom rom,void * user_data)14void w1_search_callback(struct w1_rom rom, void *user_data) 15 { 16 LOG_INF("Device found; family: 0x%02x, serial: 0x%016llx", rom.family, 17 w1_rom_to_uint64(&rom)); 18 } 19 main(void)20int main(void) 21 { 22 const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(w1)); 23 24 if (!device_is_ready(dev)) { 25 LOG_ERR("Device not ready"); 26 return 0; 27 } 28 29 int num_devices = w1_search_rom(dev, w1_search_callback, NULL); 30 31 LOG_INF("Number of devices found on bus: %d", num_devices); 32 return 0; 33 } 34