Skip to content

Commit 6da374c

Browse files
committed
hal: Add C++ API (hal.hh) and pybind11 bindings on the new HAL API
Reintroduce a C++ interface after the getter/setter transition, built strictly on the public C API and the user-land query API: - hal.hh: type-safe C++ layer. Typed pin/param handles via traits<T> (compile-time accessor selection), runtime-typed pin_t variant and anypin (stored-type-tag multiplexing for name-based access), port wrapper, component class, and ULAPI by-name query/set functions. No hal_priv.h, no direct shared memory access, no re-implemented library internals. Handles re-read the shmem slot on every access so hal_link() slot rewrites stay visible (C pointer-variable semantics). Query callback exceptions are captured and re-thrown after the library releases the HAL mutex, so a throwing setter cannot wedge the session. - halpybind.cc: pybind11 module (halpp.so) exposing component, Pin, hal_dir/hal_type_t enums and the by-name functions. Built alongside the existing _hal/hal.py, replacing nothing. - tests/halpp: Python and native C++ smoke suites covering component lifecycle, typed pins/params, signals, linking, by-name get/set with type coercion and range checks, port pins and error paths. Based on the pybind11 branch by rene-dev, re-based on the new HAL API.
1 parent 7f5b5ae commit 6da374c

6 files changed

Lines changed: 894 additions & 0 deletions

File tree

debian/control.top.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Build-Depends:
4040
psmisc,
4141
python3,
4242
python3-dev,
43+
python3-pybind11,
4344
python3-tk,
4445
python3-xlib,
4546
tcl,

src/hal/Submakefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ $(HALQUERY): $(call TOOBJS, $(HALQUERYSRCS)) $(HALLIB)
3636
$(ECHO) Linking python module $(notdir $@)
3737
$(Q)$(CC) $(LDFLAGS) -shared -o $@ $^
3838

39+
# pybind11 C++ bindings (hal.hh based)
40+
HALPPSRCS := hal/halpybind.cc
41+
PYSRCS += $(HALPPSRCS)
42+
43+
# pybind11 headers: python3-pybind11 (system include) or pip user site
44+
$(call TOOBJS, $(HALPPSRCS)): EXTRAFLAGS += $(shell python3 -m pybind11 --includes 2>/dev/null)
45+
46+
HALPP := ../lib/python/halpp.so
47+
$(HALPP): $(call TOOBJS, $(HALPPSRCS)) $(HALLIB)
48+
$(ECHO) Linking python module $(notdir $@)
49+
$(Q)$(CXX) $(LDFLAGS) -shared -o $@ $^
50+
3951
TARGETS += $(HALLIB) ../lib/liblinuxcnchal.so.0
4052
PYTARGETS += $(HALMODULE)
4153
PYTARGETS += $(HALQUERY)
54+
PYTARGETS += $(HALPP)

0 commit comments

Comments
 (0)