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.0.3-cp312-abi3-win_amd64.whl (138.9 kB view details)

Uploaded CPython 3.12+Windows x86-64

pyfwfinder-0.0.3-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.0.3-cp312-abi3-macosx_10_15_universal2.whl (144.5 kB view details)

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

pyfwfinder-0.0.3-cp311-cp311-win_amd64.whl (140.4 kB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pyfwfinder-0.0.3-cp311-cp311-macosx_10_15_universal2.whl (151.5 kB view details)

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

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyfwfinder-0.0.3-cp310-cp310-macosx_10_15_universal2.whl (150.6 kB view details)

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

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pyfwfinder-0.0.3-cp39-cp39-macosx_10_15_universal2.whl (151.1 kB view details)

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

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

pyfwfinder-0.0.3-cp38-cp38-macosx_10_15_universal2.whl (149.0 kB view details)

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

File details

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

File metadata

  • Download URL: pyfwfinder-0.0.3-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.0.3-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 231c3de5cc7a92b7a9ea5b1e288e3da731e71db8e69dd9a21279f20103156508
MD5 423038614e23305315165871ccf5bc5c
BLAKE2b-256 03d589c47b218774c4ffb729090278fabdcf66d6b8f2ef63e569aaf4fb4af145

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c5f6b3b5599d414fa3c446e12903358ff3ad6274202fc6f1b968b5c6e05acaa0
MD5 8c8ff58e24b4a86416a64167ae93b89f
BLAKE2b-256 1e6ebb4f6d55f23d5e7400a292b06bbbd7e09dcee2fc262849984e03cdab5841

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 126b32820590823fbab4d54244ac829583b6aa8dec87dda74f8228afff0717b3
MD5 0a30d58076ca4a06c7a2cc0ba36e5cf6
BLAKE2b-256 aef8b1ebb202e79298767fa5f7fa56e4ea0046481945a7179b6afbb5f683b7d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 140.4 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.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 acb980cb4ede6aafbb024d243a51f8a5dbe1aaf37f2f76c4ba259edd1d787197
MD5 61360e5480b19e205488371145d21405
BLAKE2b-256 3a6b74c14b3e0f69a20870a8f3646949d9c8eba12803b978b6ff1f8a628d2bdf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0f0ce1685529555ca426e33d69a7251b0253e1545bb2d067ff1679160c2fcd90
MD5 06ec1a642a47eac4ca6b67d509b6a67c
BLAKE2b-256 4173e6767a0d5c3db592577bc64321e4de74453235173a7326f88a3d4e3f8b73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 48b1bfc496c5f1db31c8903e0dd1111845f546f56ea7793daae8c303c58fd82b
MD5 b60cf54c4ebe2ce0a2d7d6d5a14f05fb
BLAKE2b-256 990d038421cb7bde231dae6df9470388e09491b45f76a3a1847b00c5e9c4767c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.0.3-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.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d068cdb8ae93ec208a0783926c153e0978ecb1b3fe2382211acf3d9a7c7da942
MD5 145d4646c08a8885977fcf747be5a10e
BLAKE2b-256 73f5c418d72b25178f163fd8a9a6a6ad4ddeffc7638aa33bdbf28789db7e30e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d9785fd79d4c07894369d4ec2a87f7e6aa30228830efae78f98631ab534f844f
MD5 96b46b74c95960569182becf842f3c5a
BLAKE2b-256 414d83df2f14b8043ad258a8a154fd8b01d994819364a64047b9b3280f1aef17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 67ec2ef723b6f00c6afc77683b0cfff848e19799d13dfa8444729c2859988a71
MD5 2e096f46759f74e660050b395b247a10
BLAKE2b-256 174e1845f8b53edee5fd34eabc1580af3ee64d1e974cd714e2641ae0bb276f78

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.0.3-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.0.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1ba5f309f295afe5c63ef636c16266706fd24eab190ced120f4394774d09a52a
MD5 5a0e685be55a71bc2284672a8ef27f8c
BLAKE2b-256 bc83484d38d97feb7c56015a4760708c683da7fee1d8b59f43284f140a487a39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9844e23bf5a4178eafb550e42206ebae85139804577758652ff8f7ce9027f836
MD5 b92a0c6f5b1f145d6f5877d5794f79ed
BLAKE2b-256 efa66dfd6025ce8c7a082dc694d7ce2aab7de9078adc7328c95f6282f922b76c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 3e14322725596a2579f47c27f192fd82bd7fb7e0d4be128a9f816de97cea711b
MD5 55b9ac0189606284a2616f653c6b6388
BLAKE2b-256 4316f01794b9242ff644d10b6a28fc7a8c2187f265039af7b651d21631556170

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.0.3-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.0.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 654af0f18143884b9c92e05337bfc9262b6e44025f22f86c428da378eead79fe
MD5 248e220c09959509a45b4044d9ff66b3
BLAKE2b-256 6cf09068f9f80b8f774c826540864ae6c0d0a0841e7d8dec2c51f20420e10295

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 43c483820c1de5dc6ab79c2245b544456da96c8f120b0446af770f1180f63e3b
MD5 d96e68265ef5ca67e0ac46217e1ff822
BLAKE2b-256 3e743293d952014283b10a4f1ef6c31e942ce49f29daff1d5a4b0cd908f279ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.0.3-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 5a74384f07eef6c71cb06314d62f875a71add734e6afa02ce3b2a16ce23c1d5b
MD5 1cd94b9f4888f2e3769846bcdc24aaf4
BLAKE2b-256 4c1e763ba03fe2cc3ede382f64b762182d9210348954609dee722810e188612f

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