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

Uploaded CPython 3.12+Windows x86-64

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

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

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

Uploaded CPython 3.11Windows x86-64

pyfwfinder-0.3.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.3.0-cp311-cp311-macosx_10_15_universal2.whl (162.2 kB view details)

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

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

Uploaded CPython 3.10Windows x86-64

pyfwfinder-0.3.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.3.0-cp310-cp310-macosx_10_15_universal2.whl (161.2 kB view details)

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

pyfwfinder-0.3.0-cp39-cp39-win_amd64.whl (140.5 kB view details)

Uploaded CPython 3.9Windows x86-64

pyfwfinder-0.3.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.3.0-cp39-cp39-macosx_10_15_universal2.whl (161.7 kB view details)

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

pyfwfinder-0.3.0-cp38-cp38-win_amd64.whl (139.8 kB view details)

Uploaded CPython 3.8Windows x86-64

pyfwfinder-0.3.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.3.0-cp38-cp38-macosx_10_15_universal2.whl (159.4 kB view details)

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

File details

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

File metadata

  • Download URL: pyfwfinder-0.3.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.3.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1ee61bc15021e54763b8126891caa503a7f8bc35db23072897a90f7bda311a7f
MD5 00ff2a9a9886c9441474085f90cdbac2
BLAKE2b-256 18a9a15468ee1ad9e5aa4dfa594fd828ddf3261f045f7e3868591421692866eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7fccf6f7be495f617b8a080ad5c1c59b5c1f81b1427f229c22142cc7fda49fc5
MD5 8bb8477992167ddb7d82fb347d4323e4
BLAKE2b-256 a804b21a85d6323a6dc6190c467b954bee77269c40c1dc6c1cc53f4ff4840ff4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 6a8ed7160a537b0ebc1619026cb1f4c3535f6a870fecf6ce1173907c30ce876e
MD5 451d7bb6cf6feba3c38701e9a95bcf2c
BLAKE2b-256 42b9b2c47cc867af40440b90fc017f3ce12de3c7bbc9c8d5ddf4e991d2550f0a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.3.0-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.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 90e28c62ea5ed13692706952013acfa3071f52adbed7eafebedbf067b6f32fb6
MD5 01adc7f8e607bf1c5e9f2853a20b2c33
BLAKE2b-256 60d3aea4a9e6c5021f749eba6f6090447bb2b4b0198b41eaf866084c993e93c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9b229a1a1a74e7d0655807a5d613e32187bb10d54de403b9653db21390a53068
MD5 f30844f87b39864ee3cf0e6e4c362307
BLAKE2b-256 cd9ce00998dce546565469e9eb33e260cf5ab70a3bae7d89b4c4c0dc63196d42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 0c5936f4bca63aafa8db3325347d7fb2f285b96be10e625cf985979caf3a0326
MD5 a1b7aad5634921107ab55691ec40d23b
BLAKE2b-256 f07fb80290b9be0012ef3f670fd26cf796811f2aefa93f804bac085e8186d60d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.3.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.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a9e41a6d73c233213125ac3035a6c9edd0b1c792fc1ccd3165a7d5c1d400ca11
MD5 d1a119d2a39526ca1794dffbbc39729b
BLAKE2b-256 42632a19ffa930c5fb434f8ea2b3ede0080da14dc44c5c18263ffca58abb397e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e02e456ce22d3b01fb305beffd9f1c77ffa02533054d9498af515ce5dd02b05a
MD5 9cb0d12a75a42f8b8f78f8285bd5ca9a
BLAKE2b-256 b9d55f676745b8803dd79b8976392c5fe9d49e83cb3c5ba9f53967d1fa6dc688

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 afeaf853128475bdad313151880c1cbe25193c8058bbafd86543c60fedc69fc5
MD5 4c7f0c9e4375b98e982900f8dc4ab5e1
BLAKE2b-256 993e0359075f0473e01e45add005cc2a962ed72e1b59d97258fd96c4d3765809

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 140.5 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.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 183a6273f1f4927b0b7aca2c3f57afe89453356e19ec71e20f7387bac48c4084
MD5 983d1159f3ba1e60cdcf02abda0f3fea
BLAKE2b-256 5c100a8e1c48004ab5df9cdc386489acad6576fd693fc091a268375a0359e17b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 276b461394de0f65a0e8640adf5e149735531c910991cbf1e463846295e02efd
MD5 09ec54e7dbd031d746a0608f17aa8174
BLAKE2b-256 a2af1d276e75ffed206d8b2e9cccc69ccce031f6452a48aa37ab2fa890bcd502

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 132480d8140e2238585f97a86e83915221cf3c2b15e3daefb08f34a59b5bf4cd
MD5 ca1566524116fa28429319270642a04d
BLAKE2b-256 11c0b1b50987dd36e8e0ed76e5af744db2feb48cb34539061e4853dda18569e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.3.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 139.8 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.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a735646f82305d5d98fc1aaa135e0149681f641ec618448f322cb3435ecaf69d
MD5 2919163eb7f4979e8d6b87eff8bb9cbd
BLAKE2b-256 7b02cd0e0f281a2ff4a0e0310fc9624544c349b3f22e8f7bb591d13b6932ed14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6d2d2165d91ecde72148070bf86013f58a784996e9a21fae0f0ec64d486f8c27
MD5 5db4b815eb941a16541b8e4b2dc6a236
BLAKE2b-256 9e83e762e60e3416f25fc77dbabe99bd63a80f0c00337232b21626475a93443b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.3.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 69cc1f9aff5b24ef78d8cece24130d518b5f0e332538c8da511dc1fc75c4edb5
MD5 8a61568cf5b7767905effb3c5767cdce
BLAKE2b-256 25551e8a5d977b97635730116f6f47bad14bb08ff103176fd7e58695b2f4b1ab

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