w1_search(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

okay bestie, gather round, because this is w1_search(9) straight out of the Kernel API Manual and it is, lowkey, one of the prettiest little algorithms in the whole kernel. no cap. let's get into it πŸ¦‹


✨ NAME ✨

w1_search β€” Performs a ROM Search & registers any devices found. that's it, that's the whole job. she searches, she registers, she slays πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

void w1_search (struct w1_master *dev , u8 search_type ,
w1_slave_found_callback cb );

like, exactly that. copy it character for character, i am begging you πŸ™ˆ


🌸 ARGUMENTS 🌸

  • dev β€” The master device to search. this is your main character, the one doing the looking πŸ‘‘
  • search_type β€” ok so you got two moods here: pass W1_SEARCH to search all devices, or pass W1_ALARM_SEARCH to return only devices in the alarmed state. choose your vibe wisely ✨
  • cb β€” Function to call when a device is found. like a little notification ping but, you know, a callback 🫢

🧚 DESCRIPTION 🧚

The 1-wire search is a simple binary tree search. literally a binary tree, bestie, it's giving data structures 101 but make it hardware 🌈

So for each bit of the address, we read two bits and write one bit. the bit we write puts to sleep all the devices that don't match that bit 😴 (not mean, just efficient, i promise).

When the two reads differ, the direction choice is obvious β€” no thoughts needed, head empty, path chosen πŸ’€

When both bits are 0, we must choose a path to take. this is the actual decision moment, the main character moment, the "which way do we go" of it all πŸ¦‹

And when we can scan all 64 bits without having to choose a path, we are done. sixty-four bits. all of them. no choices. finished. periodt ✨

also go read "Application note 187 1-wire search algorithm" at www.maxim-ic.com β€” it's the source material, the lore, iykyk πŸ“–

πŸ”₯ SEE ALSO πŸ”₯


okay that's the whole page bestie, go forth and search πŸ’œ

signing off from ./drivers/w1, dated October 2026, filed under w1_search(9) β€” mwah, love u, bye πŸŽ€πŸ’–

πŸ“¦ where this page comes from