Skip to main content

An example minimal project that compiles bindings using nanobind and scikit-build

Project description

FreeWili Finder

A cross-platform C/C++ library for discovering and interfacing with FreeWili devices connected to a host system.

Overview

The FreeWili Finder library provides both modern C++ and C APIs to:

  • Discover all connected FreeWili devices automatically
  • Enumerate USB devices associated with each FreeWili
  • Identify device types (Serial ports, Mass storage, FTDI/FPGA, etc.)
  • Access device information (VID/PID, serial numbers, port paths)

Features

  • Dual API Support: Modern C++23 API with std::expected error handling, plus C API for maximum compatibility
  • Cross-Platform: Supports Windows, macOS, and Linux
  • Type Safety: Strongly-typed USB device classification system
  • Error Handling: Comprehensive error reporting and handling
  • Memory Safe: RAII in C++, explicit memory management in C API
  • Testing: Full test suite with GoogleTest integration

Quick Start

C++ API Example

#include <fwfinder.hpp>
#include <iostream>

int main() {
    if (auto devices = Fw::find_all(); devices.has_value()) {
        for (const auto& device : devices.value()) {
            std::cout << "Found: " << device.name
                     << " (Serial: " << device.serial << ")\n";

            // Get serial ports
            auto serials = device.getUSBDevices(Fw::USBDeviceType::Serial);
            for (const auto& serial : serials) {
                std::cout << "  Port: " << serial.port.value_or("Unknown") << "\n";
            }
        }
    } else {
        std::cerr << "Error: " << devices.error() << "\n";
    }
    return 0;
}

C API Example

#include <cfwfinder.h>
#include <stdio.h>

int main(void) {
    fw_freewili_device_t* devices[16];
    uint32_t device_count = 16;
    char error_msg[256];
    uint32_t error_size = sizeof(error_msg);

    if (fw_device_find_all(devices, &device_count, error_msg, &error_size) == fw_error_success) {
        printf("Found %u device(s)\n", device_count);

        for (uint32_t i = 0; i < device_count; ++i) {
            char name[64];
            fw_device_get_str(devices[i], fw_stringtype_name, name, sizeof(name));
            printf("Device: %s\n", name);
        }

        fw_device_free(devices, device_count);
    }
    return 0;
}

Building

Prerequisites

  • CMake 3.20 or later
  • C++23 compatible compiler (GCC 11+, Clang 14+, MSVC 2022+)
  • Platform dependencies:
    • Linux: libudev-dev
    • macOS: Xcode command line tools
    • Windows: Windows SDK (SetupAPI, Cfgmgr32)

Build Instructions

# Clone the repository
git clone https://github.com/your-org/freewili-finder.git
cd freewili-finder

# Create build directory
mkdir build && cd build

# Configure
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build .

# Run tests
ctest --output-on-failure

CMake Options

  • FW_FINDER_BUILD_TESTS=ON/OFF - Build test suite (default: ON)
  • FW_BUILD_C_API=ON/OFF - Build C API library (default: ON)
  • FW_BUILD_STATIC=ON/OFF - Build static libraries (default: ON)
  • FW_BUILD_EXAMPLES=ON/OFF - Build example applications (default: ON)

API Reference

C++ API (fwfinder.hpp)

Core Functions

namespace Fw {
    // Find all connected FreeWili devices
    auto find_all() noexcept -> std::expected<FreeWiliDevices, std::string>;

    // USB device type detection
    auto getUSBDeviceTypeFrom(uint16_t vid, uint16_t pid) -> USBDeviceType;
    auto getUSBDeviceTypeName(USBDeviceType type) -> std::string;
}

Device Types

enum class USBDeviceType {
    Hub,              // USB Hub (parent device)
    Serial,           // Serial Port (general)
    SerialMain,       // MainCPU Serial Port
    SerialDisplay,    // DisplayCPU Serial Port
    MassStorage,      // Mass Storage Device
    ESP32,            // ESP32 USB (JTAG/RTT)
    FTDI,             // FTDI/FPGA Device
    Other             // Other USB device
};

Data Structures

struct USBDevice {
    USBDeviceType kind;
    uint16_t vid, pid;
    std::string name, serial;
    uint32_t location;
    std::optional<std::string> port;           // For serial devices
    std::optional<std::vector<std::string>> paths; // For mass storage
};

struct FreeWiliDevice {
    std::string name, serial;
    std::vector<USBDevice> usbDevices;

    auto getUSBDevices(USBDeviceType type) const -> std::vector<USBDevice>;
};

C API (cfwfinder.h)

Core Functions

// Find all devices
fw_error_t fw_device_find_all(fw_freewili_device_t** devices, uint32_t* count,
                              char* error_msg, uint32_t* error_size);

// Device validation and info
bool fw_device_is_valid(fw_freewili_device_t* device);
fw_error_t fw_device_get_str(fw_freewili_device_t* device, fw_stringtype_t type,
                             char* buffer, uint32_t buffer_size);

// USB device enumeration
fw_error_t fw_usb_device_begin(fw_freewili_device_t* device);
fw_error_t fw_usb_device_count(fw_freewili_device_t* device, uint32_t* count);
fw_error_t fw_usb_device_next(fw_freewili_device_t* device);
fw_error_t fw_usb_device_get_str(fw_freewili_device_t* device, fw_stringtype_t type,
                                 char* buffer, uint32_t buffer_size);
fw_error_t fw_usb_device_get_int(fw_freewili_device_t* device, fw_inttype_t type,
                                 uint32_t* value);

// Memory management
fw_error_t fw_device_free(fw_freewili_device_t** devices, uint32_t count);

Examples

Complete example applications are provided in the examples/ directory:

  • basic_usage.cpp - Modern C++ API demonstration
  • c_api_basic_usage.cpp - C API demonstration (compiled as C++)
  • c_api_basic_usage_pure_c.c - Pure C implementation

Build and run examples:

cd build
make basic_usage_cpp basic_usage_c
./examples/basic_usage_cpp
./examples/basic_usage_c

Project Structure

freewili-finder/
├── include/
│   ├── fwfinder.hpp          # Main C++ API header
│   └── usbdef.hpp            # USB device definitions
├── src/
│   ├── fwfinder.cpp          # Core implementation
│   ├── fwfinder_linux.cpp    # Linux-specific code
│   ├── fwfinder_mac.cpp      # macOS-specific code
│   ├── fwfinder_windows.cpp  # Windows-specific code
│   └── usbdef.cpp            # USB device type mappings
├── c_api/
│   ├── include/cfwfinder.h   # C API header
│   ├── src/cfwfinder.cpp     # C API implementation
│   └── test/                 # C API tests
├── test/                     # C++ API tests
├── examples/                 # Example applications
└── bindings/                 # Language bindings (Python, etc.)

Testing

The library includes comprehensive tests using GoogleTest:

cd build
ctest --output-on-failure

Tests cover:

  • Device discovery functionality
  • USB device type detection
  • C API functionality
  • Cross-platform compatibility
  • Error handling scenarios

Platform Support

Platform Status Requirements
Linux ✅ Supported libudev
macOS ✅ Supported IOKit framework
Windows ✅ Supported Windows SDK (SetupAPI, Cfgmgr32)

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please ensure all tests pass and add tests for new functionality.

License

Copyright Free-Wili

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyfwfinder-0.2.0-cp312-abi3-win_amd64.whl (138.9 kB view details)

Uploaded CPython 3.12+Windows x86-64

pyfwfinder-0.2.0-cp312-abi3-manylinux_2_34_x86_64.whl (232.9 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ x86-64

pyfwfinder-0.2.0-cp312-abi3-macosx_10_15_universal2.whl (145.5 kB view details)

Uploaded CPython 3.12+macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.2.0-cp311-cp311-win_amd64.whl (140.3 kB view details)

Uploaded CPython 3.11Windows x86-64

pyfwfinder-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl (237.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pyfwfinder-0.2.0-cp311-cp311-macosx_10_15_universal2.whl (152.6 kB view details)

Uploaded CPython 3.11macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.2.0-cp310-cp310-win_amd64.whl (140.1 kB view details)

Uploaded CPython 3.10Windows x86-64

pyfwfinder-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl (236.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyfwfinder-0.2.0-cp310-cp310-macosx_10_15_universal2.whl (151.7 kB view details)

Uploaded CPython 3.10macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.2.0-cp39-cp39-win_amd64.whl (140.4 kB view details)

Uploaded CPython 3.9Windows x86-64

pyfwfinder-0.2.0-cp39-cp39-manylinux_2_34_x86_64.whl (237.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pyfwfinder-0.2.0-cp39-cp39-macosx_10_15_universal2.whl (152.2 kB view details)

Uploaded CPython 3.9macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.2.0-cp38-cp38-win_amd64.whl (139.7 kB view details)

Uploaded CPython 3.8Windows x86-64

pyfwfinder-0.2.0-cp38-cp38-manylinux_2_34_x86_64.whl (235.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

pyfwfinder-0.2.0-cp38-cp38-macosx_10_15_universal2.whl (149.8 kB view details)

Uploaded CPython 3.8macOS 10.15+ universal2 (ARM64, x86-64)

File details

Details for the file pyfwfinder-0.2.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.2.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 138.9 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.2.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fec0a882db30c7e0bb0f59370e01036bf6fe096b4e38086c25da2a9035958ce0
MD5 117ccfaffc9c84616679f6e9a81ff458
BLAKE2b-256 ddcf984b314136c3e357832efdedfe4d5e58153a3a02df8bebaacc505bfe4a51

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp312-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4480a68b67ca536f15da34240bdfb5ee3a695e0d7c27eae84cb420f78045e9fb
MD5 874716a598a45018dfbf2a00f5846886
BLAKE2b-256 c28870c82c94dea6a66c387e7f9f64ace03c16492d2d8d3b308647fda1938a39

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp312-abi3-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 c962b86aafee15967caa31eafff3ba0799205cd37cbb2d5e5d882ebd232ea231
MD5 c306c28a1c6ae695c798ece29f1d51f5
BLAKE2b-256 4260167a264887144eaa1cd738283f812b648cd61fdd6365efd37aa80f3baf59

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 140.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9f90483f1ff868d46dbf6b59c6ade21fe3c1e954b46eac036701f65f2b30ba0e
MD5 702b27f30db89fb819bd9498b935bda4
BLAKE2b-256 cd59bdb89fe69dca2350a0580c9fdbc7dcc9ec001e0668786f070630a179c204

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 080787f48f781479190695e3756a63c1abd90d72593abdfbb7469083ad37f135
MD5 754445a21f7b2ff7f1cfde7e7ebaa684
BLAKE2b-256 e49deda7757df56a436fb015837c4ec99230ddaa4f8ff69f40dc4472ea273c2a

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp311-cp311-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 0a95bc0fd0412954f9d3c47e773b3544849f5e46cbc725a57d1368fcb6f5af61
MD5 2cf6b47fda0543723a3717723d617fef
BLAKE2b-256 926be397c47a157a541e37576f0bb71ee8bb6bb8d8c152cfed35a40f7a760049

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 140.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 32fd9e975a0534ae1766609fc8e4646abd0260f8fecbe1fef4937a82c15b9cdb
MD5 0021151214b53a4f91300b5fa802d59d
BLAKE2b-256 6051a0d45560eaff8acadbb42841f8e07295fad0a2d4e990641a7be20df8da36

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a8b587dab0cc9a7d75f350fd373595ee825fb0bb2dd40ec8c93e8fc18f5734e2
MD5 64574e00a6ca08e92dbdd4726987548b
BLAKE2b-256 1873a2572489374e15f757f88ce6aeb1bc5b1ca67a32722e6cf47cfad0bcdf56

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp310-cp310-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 e65f68a98df2b07d9c6e7d89a2d6416425d6bc0c77c3e9a2dd466fe826339729
MD5 b8bbcdce07feda861b05cc902ed3bf2f
BLAKE2b-256 eb41f30f75454c46c5928efb745b1dd80ca1765539ccfad6d714d9178e90b843

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 140.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3382eb09733f04c872ce4bd669435fe4fafb0d90a08d7424e53a71f29e2899f6
MD5 0a3bc15d3b8b4e0b8cef8c3b8f597323
BLAKE2b-256 1da0a5db33841de3558797adac7540467a2c59cc8d0f703ca983212493ed6b67

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 69bce8ea67b92f488c4ee72bd098c9387ab602c9eacc6393dc2bc84e9a2382bc
MD5 d6bc778a5b7a773363e71fc2cf5bc742
BLAKE2b-256 b4ea097bac1ac784ab0cc67d80cbc148130f481394fd5bf663e886f19936d9fd

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp39-cp39-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 bd70d8bffb43ed3b112e22f613942768c3bffafc9342356e4f238392ef5829ec
MD5 59efd2d660cfd57e86fe02a3949e39d4
BLAKE2b-256 7f4a1138335b66496499c8bc3e8163a2aadba9005f59877e554019fc98518f22

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 139.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 dc23b84c205bdf935eaceaf228a314c02b46d5d1d79da3abd1695f461a54c3c6
MD5 342027200b59294d21b45fa01d715a0d
BLAKE2b-256 da22e196d9a61bf66b9d1d7d86534acdb9f8fd87c2ab98922b1924e6a33f520b

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 31e2ab29e35646e384aead8509674c2fbe2e4db83a62d2c64a70d22811c4a208
MD5 cb94609edfda2ba35efe957249c21902
BLAKE2b-256 9c1834d75051c54777f54450e54e3b4e806037cad27a2dcf8de9fa94f453e8cf

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.2.0-cp38-cp38-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.2.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 c4b29cf0433f77bcb9e03147d9a12d6a5a57e48d7634bf0c081735807386bde4
MD5 120578daf22a8b0d8b851f1794529de7
BLAKE2b-256 7fd1ff44275cc53a28f3f1a0824a90b78c8ec90854c6e358dde4fdbc0f3bdfea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page