generated from sirlilpanda/kicad-project-template-actionless
Added the zig_main project to software for zig based implementation of code for robot
This commit is contained in:
30
software/zig_main/include/bt_stubs.h
Normal file
30
software/zig_main/include/bt_stubs.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/* bt_stubs.h — Static inline wrappers for BT macros that zig translate-c
|
||||
* cannot handle directly.
|
||||
*
|
||||
* Included by stubs.h AFTER bindings.h (which pulls in esp_bt.h).
|
||||
* The translate-c pipeline converts these into callable Zig functions
|
||||
* inside idf-sys.zig.
|
||||
*/
|
||||
|
||||
#ifndef BT_STUBS_H
|
||||
#define BT_STUBS_H
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32S2 /* No BT in ESP32-S2 */
|
||||
#ifdef CONFIG_BT_ENABLED
|
||||
|
||||
/*
|
||||
* BT_CONTROLLER_INIT_CONFIG_DEFAULT() is a macro that expands to a
|
||||
* designated-initialiser struct literal — translate-c chokes on it.
|
||||
* Wrapping it in a static inline function lets the C preprocessor
|
||||
* expand the macro before translate-c sees the AST.
|
||||
*/
|
||||
static inline esp_bt_controller_config_t zig_bt_controller_default_cfg(void)
|
||||
{
|
||||
esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
return cfg;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* !CONFIG_IDF_TARGET_ESP32S2 */
|
||||
|
||||
#endif /* BT_STUBS_H */
|
||||
@@ -0,0 +1,15 @@
|
||||
/* Redirect wrapper — fixes Windows mixed-separator translate-c issue (issue #50).
|
||||
*
|
||||
* On Windows, clang joins include dirs with '\' when building resolved paths.
|
||||
* Having both `-I"include"` and `-I"include/freertos"` produces two different
|
||||
* path strings for the same physical file:
|
||||
* include\freertos/portmacro.h (via "freertos/portmacro.h")
|
||||
* include/freertos\portmacro.h (via "portmacro.h")
|
||||
* #pragma once fails because these look like different files to clang's VFS.
|
||||
*
|
||||
* Fix: redirect all "freertos/portmacro.h" (prefixed) includes through this
|
||||
* single wrapper. Angle-bracket include avoids same-dir lookup, finding the
|
||||
* real portmacro.h via -I"portable/ARCH/include/freertos" as the sole path.
|
||||
*/
|
||||
#pragma once
|
||||
#include <portmacro.h>
|
||||
30
software/zig_main/include/matter_closure_patch.h
Normal file
30
software/zig_main/include/matter_closure_patch.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
// CHIP SDK closure-control cluster structs are missing operator==(const T&) required
|
||||
// by std::optional<T> comparison in GCC 14 C++23 mode.
|
||||
// This header adds free-function operators via ADL so the types satisfy
|
||||
// std::equality_comparable without touching managed_components sources.
|
||||
// Applied via -include CMake file property to the specific failing TUs only.
|
||||
#ifdef __cplusplus
|
||||
#include "app/clusters/closure-control-server/closure-control-cluster-objects.h"
|
||||
|
||||
namespace chip {
|
||||
namespace app {
|
||||
namespace Clusters {
|
||||
namespace ClosureControl {
|
||||
|
||||
inline bool operator==(const GenericOverallCurrentState & a, const GenericOverallCurrentState & b)
|
||||
{
|
||||
return a.position == b.position && a.latch == b.latch &&
|
||||
a.speed == b.speed && a.secureState == b.secureState;
|
||||
}
|
||||
|
||||
inline bool operator==(const GenericOverallTargetState & a, const GenericOverallTargetState & b)
|
||||
{
|
||||
return a.position == b.position && a.latch == b.latch && a.speed == b.speed;
|
||||
}
|
||||
|
||||
} // namespace ClosureControl
|
||||
} // namespace Clusters
|
||||
} // namespace app
|
||||
} // namespace chip
|
||||
#endif // __cplusplus
|
||||
305
software/zig_main/include/matter_stubs.h
Normal file
305
software/zig_main/include/matter_stubs.h
Normal file
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* matter_stubs.h — C wrapper interface for esp_matter (CHIP SDK C++ API)
|
||||
*
|
||||
* This header is included by stubs.h and processed by zig translate-c.
|
||||
* It provides a pure-C interface over the C++ esp_matter API.
|
||||
*
|
||||
* The actual implementations are in main/matter_wrappers.cpp (compiled as C++
|
||||
* by the ESP-IDF CMake build, with full access to CHIP SDK headers).
|
||||
*
|
||||
* NOTE: esp_matter_val_type_t, esp_matter_val_t, esp_matter_attr_val_t and
|
||||
* esp_matter_attr_bounds_t are also defined in the real esp_matter_attribute_utils.h.
|
||||
* Those definitions are guarded with #ifndef __cplusplus so that they are only
|
||||
* visible to zig translate-c (pure C mode). In C++ compilation the real header
|
||||
* definitions are used, avoiding redefinition conflicts.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* ── Opaque handle types ─────────────────────────────────────────────────── */
|
||||
/* These names do not exist in the real esp_matter C++ headers (which use
|
||||
* node_t / endpoint_t inside namespaces), so they are safe to define in
|
||||
* both C and C++ compilation contexts. */
|
||||
|
||||
typedef size_t esp_matter_node_t;
|
||||
typedef size_t esp_matter_endpoint_t;
|
||||
typedef size_t esp_matter_cluster_t;
|
||||
typedef size_t esp_matter_attribute_t;
|
||||
|
||||
/* ── Endpoint flags ──────────────────────────────────────────────────────── */
|
||||
/* Real esp_matter uses ENDPOINT_FLAG_* (no prefix); these names are unique. */
|
||||
|
||||
typedef enum esp_matter_ep_flags {
|
||||
ESP_MATTER_EP_FLAG_NONE = 0x00,
|
||||
ESP_MATTER_EP_FLAG_DESTROYABLE = 0x01,
|
||||
ESP_MATTER_EP_FLAG_BRIDGE = 0x02,
|
||||
} esp_matter_ep_flags_t;
|
||||
|
||||
/* ── Types that ALSO exist in esp_matter_attribute_utils.h ───────────────── */
|
||||
/* Guarded so the real header wins in C++ compilation. */
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
typedef enum esp_matter_val_type {
|
||||
ESP_MATTER_VAL_TYPE_INVALID = 0,
|
||||
ESP_MATTER_VAL_TYPE_BOOLEAN = 1,
|
||||
ESP_MATTER_VAL_TYPE_INTEGER = 2,
|
||||
ESP_MATTER_VAL_TYPE_FLOAT = 3,
|
||||
ESP_MATTER_VAL_TYPE_ARRAY = 4,
|
||||
ESP_MATTER_VAL_TYPE_CHAR_STRING = 5,
|
||||
ESP_MATTER_VAL_TYPE_OCTET_STRING = 6,
|
||||
ESP_MATTER_VAL_TYPE_INT8 = 7,
|
||||
ESP_MATTER_VAL_TYPE_UINT8 = 8,
|
||||
ESP_MATTER_VAL_TYPE_INT16 = 9,
|
||||
ESP_MATTER_VAL_TYPE_UINT16 = 10,
|
||||
ESP_MATTER_VAL_TYPE_INT32 = 11,
|
||||
ESP_MATTER_VAL_TYPE_UINT32 = 12,
|
||||
ESP_MATTER_VAL_TYPE_INT64 = 13,
|
||||
ESP_MATTER_VAL_TYPE_UINT64 = 14,
|
||||
ESP_MATTER_VAL_TYPE_ENUM8 = 15,
|
||||
ESP_MATTER_VAL_TYPE_BITMAP8 = 16,
|
||||
ESP_MATTER_VAL_TYPE_BITMAP16 = 17,
|
||||
ESP_MATTER_VAL_TYPE_BITMAP32 = 18,
|
||||
ESP_MATTER_VAL_TYPE_ENUM16 = 19,
|
||||
ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING = 20,
|
||||
ESP_MATTER_VAL_TYPE_LONG_OCTET_STRING = 21,
|
||||
} esp_matter_val_type_t;
|
||||
|
||||
/** Attribute value union — binary-compatible with esp_matter_val_t */
|
||||
typedef union esp_matter_val {
|
||||
bool b;
|
||||
int i;
|
||||
float f;
|
||||
int8_t i8;
|
||||
uint8_t u8;
|
||||
int16_t i16;
|
||||
uint16_t u16;
|
||||
int32_t i32;
|
||||
uint32_t u32;
|
||||
int64_t i64;
|
||||
uint64_t u64;
|
||||
struct {
|
||||
uint8_t *b; /* buffer pointer */
|
||||
uint16_t s; /* data size */
|
||||
uint16_t n; /* element count */
|
||||
uint16_t t; /* total allocated size */
|
||||
} a; /* array / string */
|
||||
void *p;
|
||||
} esp_matter_val_t;
|
||||
|
||||
/** Attribute value struct — binary-compatible with esp_matter_attr_val_t */
|
||||
typedef struct esp_matter_attr_val {
|
||||
esp_matter_val_type_t type;
|
||||
esp_matter_val_t val;
|
||||
} esp_matter_attr_val_t;
|
||||
|
||||
/** Attribute bounds */
|
||||
typedef struct esp_matter_attr_bounds {
|
||||
esp_matter_attr_val_t min;
|
||||
esp_matter_attr_val_t max;
|
||||
} esp_matter_attr_bounds_t;
|
||||
|
||||
#endif /* !__cplusplus */
|
||||
|
||||
/* ── Attribute callback ──────────────────────────────────────────────────── */
|
||||
/* These types are unique to our C wrapper (not in real esp_matter headers).
|
||||
* They must be visible in both C and C++ so the extern "C" function
|
||||
* declarations below can use them. In C++ mode esp_matter_attr_val_t is
|
||||
* provided by the previously-included real esp_matter_attribute_utils.h. */
|
||||
|
||||
typedef enum esp_matter_attr_cb_type {
|
||||
ESP_MATTER_ATTR_CB_PRE_UPDATE = 0,
|
||||
ESP_MATTER_ATTR_CB_POST_UPDATE,
|
||||
ESP_MATTER_ATTR_CB_READ,
|
||||
ESP_MATTER_ATTR_CB_WRITE,
|
||||
} esp_matter_attr_cb_type_t;
|
||||
|
||||
/**
|
||||
* Attribute update callback — called before/after every attribute change.
|
||||
* Return ESP_OK to allow the update; return error from PRE_UPDATE to block it.
|
||||
*/
|
||||
typedef esp_err_t (*esp_matter_attr_callback_t)(
|
||||
esp_matter_attr_cb_type_t type,
|
||||
uint16_t endpoint_id,
|
||||
uint32_t cluster_id,
|
||||
uint32_t attribute_id,
|
||||
esp_matter_attr_val_t *val,
|
||||
void *priv_data);
|
||||
|
||||
/* ── Identification (Identify cluster) callback ──────────────────────────── */
|
||||
|
||||
typedef enum esp_matter_identify_cb_type {
|
||||
ESP_MATTER_IDENTIFY_CB_START = 0,
|
||||
ESP_MATTER_IDENTIFY_CB_STOP,
|
||||
ESP_MATTER_IDENTIFY_CB_EFFECT,
|
||||
} esp_matter_identify_cb_type_t;
|
||||
|
||||
typedef esp_err_t (*esp_matter_identify_callback_t)(
|
||||
esp_matter_identify_cb_type_t type,
|
||||
uint16_t endpoint_id,
|
||||
uint8_t effect_id,
|
||||
uint8_t effect_variant,
|
||||
void *priv_data);
|
||||
|
||||
/* ── Function declarations ───────────────────────────────────────────────── */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Start the Matter stack (call after building node + endpoints). */
|
||||
esp_err_t esp_matter_wrapper_start(
|
||||
esp_matter_attr_callback_t attr_cb,
|
||||
esp_matter_identify_callback_t identify_cb);
|
||||
|
||||
/** Perform a factory reset (erases NVS, then reboots). */
|
||||
esp_err_t esp_matter_wrapper_factory_reset(void);
|
||||
|
||||
/** Return true if Matter has been started. */
|
||||
bool esp_matter_wrapper_is_started(void);
|
||||
|
||||
/* ── Node ────────────────────────────────────────────────────────────────── */
|
||||
|
||||
/**
|
||||
* Create a root node (endpoint 0) with default config.
|
||||
* attr_cb and identify_cb are stored for the lifetime of the node.
|
||||
* priv_data is forwarded to both callbacks.
|
||||
*/
|
||||
esp_matter_node_t *esp_matter_wrapper_node_create(
|
||||
esp_matter_attr_callback_t attr_cb,
|
||||
esp_matter_identify_callback_t identify_cb,
|
||||
void *priv_data);
|
||||
|
||||
/* ── Endpoint ────────────────────────────────────────────────────────────── */
|
||||
|
||||
/** Create a generic endpoint on the node. */
|
||||
esp_matter_endpoint_t *esp_matter_wrapper_endpoint_create(
|
||||
esp_matter_node_t *node,
|
||||
uint8_t flags,
|
||||
void *priv_data);
|
||||
|
||||
/** Destroy an endpoint (only valid if ENDPOINT_FLAG_DESTROYABLE was set). */
|
||||
esp_err_t esp_matter_wrapper_endpoint_destroy(
|
||||
esp_matter_node_t *node,
|
||||
esp_matter_endpoint_t *endpoint);
|
||||
|
||||
/** Return the endpoint ID assigned by the stack. */
|
||||
uint16_t esp_matter_wrapper_endpoint_get_id(esp_matter_endpoint_t *endpoint);
|
||||
|
||||
/** Associate a device type with an endpoint. */
|
||||
esp_err_t esp_matter_wrapper_endpoint_add_device_type(
|
||||
esp_matter_endpoint_t *endpoint,
|
||||
uint32_t device_type_id,
|
||||
uint8_t version);
|
||||
|
||||
/** Enable a dynamically-created endpoint (call after esp_matter::start()). */
|
||||
esp_err_t esp_matter_wrapper_endpoint_enable(esp_matter_endpoint_t *endpoint);
|
||||
|
||||
/* ── Pre-built device-type endpoints ─────────────────────────────────────── */
|
||||
|
||||
/** Create an On/Off Light endpoint (EP_FLAG_NONE recommended). */
|
||||
esp_matter_endpoint_t *esp_matter_wrapper_add_on_off_light(
|
||||
esp_matter_node_t *node,
|
||||
uint8_t flags,
|
||||
void *priv_data);
|
||||
|
||||
/** Create an On/Off Switch endpoint. */
|
||||
esp_matter_endpoint_t *esp_matter_wrapper_add_on_off_switch(
|
||||
esp_matter_node_t *node,
|
||||
uint8_t flags,
|
||||
void *priv_data);
|
||||
|
||||
/** Create a Dimmable Light endpoint. */
|
||||
esp_matter_endpoint_t *esp_matter_wrapper_add_dimmable_light(
|
||||
esp_matter_node_t *node,
|
||||
uint8_t flags,
|
||||
void *priv_data);
|
||||
|
||||
/** Create a Color Temperature Light endpoint. */
|
||||
esp_matter_endpoint_t *esp_matter_wrapper_add_color_temperature_light(
|
||||
esp_matter_node_t *node,
|
||||
uint8_t flags,
|
||||
void *priv_data);
|
||||
|
||||
/* ── Cluster ─────────────────────────────────────────────────────────────── */
|
||||
|
||||
/** Create a cluster on an endpoint. */
|
||||
esp_matter_cluster_t *esp_matter_wrapper_cluster_create(
|
||||
esp_matter_endpoint_t *endpoint,
|
||||
uint32_t cluster_id,
|
||||
uint8_t flags);
|
||||
|
||||
/* ── Attribute ───────────────────────────────────────────────────────────── */
|
||||
|
||||
/** Create an attribute on a cluster. */
|
||||
esp_matter_attribute_t *esp_matter_wrapper_attribute_create(
|
||||
esp_matter_cluster_t *cluster,
|
||||
uint32_t attribute_id,
|
||||
uint16_t flags,
|
||||
esp_matter_attr_val_t val);
|
||||
|
||||
/** Update an attribute value (use after esp_matter::start()). */
|
||||
esp_err_t esp_matter_wrapper_attribute_update(
|
||||
uint16_t endpoint_id,
|
||||
uint32_t cluster_id,
|
||||
uint32_t attribute_id,
|
||||
esp_matter_attr_val_t *val);
|
||||
|
||||
/** Get an attribute value. */
|
||||
esp_err_t esp_matter_wrapper_attribute_get_val(
|
||||
esp_matter_attribute_t *attribute,
|
||||
esp_matter_attr_val_t *val);
|
||||
|
||||
/** Set an attribute value (use before esp_matter::start()). */
|
||||
esp_err_t esp_matter_wrapper_attribute_set_val(
|
||||
esp_matter_attribute_t *attribute,
|
||||
esp_matter_attr_val_t *val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* ── Convenience attribute constructors (C-only; use real esp_matter_* in C++) */
|
||||
#ifndef __cplusplus
|
||||
|
||||
static inline esp_matter_attr_val_t esp_matter_val_bool(bool val) {
|
||||
esp_matter_attr_val_t v;
|
||||
v.type = ESP_MATTER_VAL_TYPE_BOOLEAN;
|
||||
v.val.b = val;
|
||||
return v;
|
||||
}
|
||||
static inline esp_matter_attr_val_t esp_matter_val_uint8(uint8_t val) {
|
||||
esp_matter_attr_val_t v;
|
||||
v.type = ESP_MATTER_VAL_TYPE_UINT8;
|
||||
v.val.u8 = val;
|
||||
return v;
|
||||
}
|
||||
static inline esp_matter_attr_val_t esp_matter_val_uint16(uint16_t val) {
|
||||
esp_matter_attr_val_t v;
|
||||
v.type = ESP_MATTER_VAL_TYPE_UINT16;
|
||||
v.val.u16 = val;
|
||||
return v;
|
||||
}
|
||||
static inline esp_matter_attr_val_t esp_matter_val_uint32(uint32_t val) {
|
||||
esp_matter_attr_val_t v;
|
||||
v.type = ESP_MATTER_VAL_TYPE_UINT32;
|
||||
v.val.u32 = val;
|
||||
return v;
|
||||
}
|
||||
static inline esp_matter_attr_val_t esp_matter_val_int16(int16_t val) {
|
||||
esp_matter_attr_val_t v;
|
||||
v.type = ESP_MATTER_VAL_TYPE_INT16;
|
||||
v.val.i16 = val;
|
||||
return v;
|
||||
}
|
||||
static inline esp_matter_attr_val_t esp_matter_val_nullable(void) {
|
||||
esp_matter_attr_val_t v;
|
||||
v.type = ESP_MATTER_VAL_TYPE_INVALID;
|
||||
v.val.u64 = 0;
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* !__cplusplus */
|
||||
121
software/zig_main/include/pthread_stubs.h
Normal file
121
software/zig_main/include/pthread_stubs.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/* pthread_stubs.h — Minimal POSIX pthread declarations for zig translate-c.
|
||||
*
|
||||
* The system pthread.h (newlib) fails translate-c because it includes
|
||||
* <sys/types.h>, <time.h>, and <sched.h> — all of which are blocked by
|
||||
* header guards in stubs.h. This file provides the exact types and function
|
||||
* prototypes that ESP-IDF's FreeRTOS-backed pthread implementation exposes,
|
||||
* expressed in a form translate-c can digest without those dependencies.
|
||||
*/
|
||||
|
||||
#ifndef PTHREAD_STUBS_H
|
||||
#define PTHREAD_STUBS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* ── Opaque handle types ──────────────────────────────────────────────────── */
|
||||
|
||||
typedef unsigned int pthread_t;
|
||||
typedef unsigned int pthread_mutex_t;
|
||||
typedef unsigned int pthread_cond_t;
|
||||
typedef unsigned int pthread_key_t;
|
||||
|
||||
/* ── Attribute structs ───────────────────────────────────────────────────── */
|
||||
|
||||
typedef struct {
|
||||
int is_initialized;
|
||||
void *stackaddr;
|
||||
int stacksize;
|
||||
int contentionscope;
|
||||
int inheritsched;
|
||||
int schedpolicy;
|
||||
int sched_priority; /* inline sched_param to avoid sched.h dependency */
|
||||
int detachstate;
|
||||
} pthread_attr_t;
|
||||
|
||||
typedef struct {
|
||||
int is_initialized;
|
||||
int type;
|
||||
int recursive;
|
||||
} pthread_mutexattr_t;
|
||||
|
||||
typedef struct {
|
||||
int is_initialized;
|
||||
unsigned long clock;
|
||||
} pthread_condattr_t;
|
||||
|
||||
typedef struct {
|
||||
int is_initialized;
|
||||
int init_executed;
|
||||
} pthread_once_t;
|
||||
|
||||
/* ── timespec (needed for timedlock / timedwait) ─────────────────────────── */
|
||||
|
||||
/* Define struct timespec once and mark all known system guards to prevent
|
||||
sys/_timespec.h from redefining it with an incompatible layout. */
|
||||
#if !defined(_TIMESPEC_DEFINED) && !defined(_SYS__TIMESPEC_H_)
|
||||
#define _TIMESPEC_DEFINED
|
||||
#define _SYS__TIMESPEC_H_
|
||||
struct timespec {
|
||||
long tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* ── Thread lifecycle ────────────────────────────────────────────────────── */
|
||||
|
||||
int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg);
|
||||
int pthread_join(pthread_t thread, void **value_ptr);
|
||||
int pthread_detach(pthread_t thread);
|
||||
void pthread_exit(void *value_ptr);
|
||||
pthread_t pthread_self(void);
|
||||
int pthread_equal(pthread_t t1, pthread_t t2);
|
||||
void pthread_yield(void);
|
||||
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
|
||||
int pthread_cancel(pthread_t thread);
|
||||
int pthread_setcancelstate(int state, int *oldstate);
|
||||
int pthread_setcanceltype(int type, int *oldtype);
|
||||
void pthread_testcancel(void);
|
||||
|
||||
/* ── Thread attributes ───────────────────────────────────────────────────── */
|
||||
|
||||
int pthread_attr_init(pthread_attr_t *attr);
|
||||
int pthread_attr_destroy(pthread_attr_t *attr);
|
||||
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
|
||||
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
|
||||
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
|
||||
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
|
||||
|
||||
/* ── Mutex ───────────────────────────────────────────────────────────────── */
|
||||
|
||||
int pthread_mutexattr_init(pthread_mutexattr_t *attr);
|
||||
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
|
||||
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *kind);
|
||||
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind);
|
||||
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
|
||||
int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_lock(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_trylock(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_timedlock(pthread_mutex_t *mutex,
|
||||
const struct timespec *timeout);
|
||||
|
||||
/* ── Condition variable ──────────────────────────────────────────────────── */
|
||||
|
||||
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
|
||||
int pthread_cond_destroy(pthread_cond_t *cond);
|
||||
int pthread_cond_signal(pthread_cond_t *cond);
|
||||
int pthread_cond_broadcast(pthread_cond_t *cond);
|
||||
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
|
||||
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
const struct timespec *abstime);
|
||||
|
||||
/* ── Thread-local storage (TLS) keys ─────────────────────────────────────── */
|
||||
|
||||
int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
|
||||
int pthread_key_delete(pthread_key_t key);
|
||||
int pthread_setspecific(pthread_key_t key, const void *value);
|
||||
void *pthread_getspecific(pthread_key_t key);
|
||||
|
||||
#endif /* PTHREAD_STUBS_H */
|
||||
168
software/zig_main/include/stubs.h
Normal file
168
software/zig_main/include/stubs.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* stubs.h - Stubs file for zig translate-c with ESP-IDF */
|
||||
|
||||
#ifndef STUBS_H
|
||||
#define STUBS_H
|
||||
|
||||
/* Prevent inclusion of problematic cstdlib headers */
|
||||
#define _STDIO_H_
|
||||
#define _STDLIB_H_
|
||||
#define _STRING_H_
|
||||
#define _WCHAR_H_
|
||||
#define _SYS_STAT_H
|
||||
#define _SYS_REENT_H
|
||||
#define _SYS_TYPES_H
|
||||
#define _SYS_SIGNAL_H
|
||||
#define _SYS_TIME_H_
|
||||
#define _SYS__DEFAULT_FCNTL_H_
|
||||
#define _MBSTATE_T
|
||||
#define _SYS_LOCK_H
|
||||
#define _SYS_UNISTD_H
|
||||
#define _UNISTD_H
|
||||
#define _TIME_H_
|
||||
/* Block system pthread.h — fails translate-c due to _SYS_TYPES_H conflicts;
|
||||
our pthread_stubs.h provides clean, translate-c-compatible declarations. */
|
||||
#define __PTHREAD_h
|
||||
#define _PTHREAD_H
|
||||
|
||||
/* Prevent real header from redefining them */
|
||||
#define __ESP_ASSERT_H__
|
||||
#define __ESP_VFS_H__
|
||||
|
||||
/* Avoid redefining types that exist in real headers */
|
||||
#undef _mbstate_t
|
||||
#undef __mbstate_t_defined
|
||||
|
||||
/* Define only what's strictly necessary without conflicting */
|
||||
typedef void *FILE;
|
||||
// typedef int _LOCK_T;
|
||||
typedef void *__VALIST;
|
||||
typedef long off_t;
|
||||
typedef long _off_t;
|
||||
typedef unsigned int wint_t;
|
||||
typedef unsigned int mode_t;
|
||||
|
||||
/* Disable macros and attributes that confuse zig translate-c */
|
||||
#define __restrict
|
||||
#define __extension__
|
||||
#define __attribute__(x)
|
||||
#define __THROW
|
||||
#define __wur
|
||||
#define __volatile__
|
||||
#define __inline
|
||||
|
||||
/* Disable IDF-specific attributes */
|
||||
#define IRAM_ATTR
|
||||
#define DRAM_ATTR
|
||||
#define RTC_DATA_ATTR
|
||||
#define SECTION_ATTR_IMPL(x, y)
|
||||
#ifdef ESP_STATIC_ASSERT
|
||||
#undef ESP_STATIC_ASSERT
|
||||
#endif
|
||||
#define ESP_STATIC_ASSERT(expr, msg)
|
||||
|
||||
/* Block multibyte functions from stdlib */
|
||||
#define mblen
|
||||
#define mbtowc
|
||||
#define wctomb
|
||||
#define mbstowcs
|
||||
#define wcstombs
|
||||
|
||||
/* Workaround for FreeRTOS TLS dummy field (prevents struct _reent usage) */
|
||||
#define configTLS_BLOCK_TYPE int
|
||||
#define portTLS_BLOCK_TYPE int
|
||||
|
||||
/* ────────────────────────────────────────────────────────────────────────────
|
||||
IDF component guards – mirror sdkconfig.h / bindings.h logic
|
||||
Enable ONLY what your project actually uses
|
||||
────────────────────────────────────────────────────────────────────────────
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
/* Always available basics */
|
||||
#define ESP_IDF_COMP_SOC_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_GPIO_ENABLED // almost always needed
|
||||
|
||||
/* Commonly used – uncomment what you need */
|
||||
#define ESP_IDF_COMP_ESP_WIFI_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_NETIF_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_EVENT_ENABLED
|
||||
#define ESP_IDF_COMP_NVS_FLASH_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_TIMER_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_PM_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_TLS_ENABLED
|
||||
#define ESP_IDF_COMP_MBEDTLS_ENABLED
|
||||
#define ESP_IDF_COMP_LWIP_ENABLED
|
||||
#define ESP_IDF_COMP_VFS_ENABLED
|
||||
|
||||
/* Drivers (split since ~v5.1–5.3) – enable per driver you use */
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_UART_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_I2C_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_SPI_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_RMT_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_LEDC_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_GPTIMER_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_ADC_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_TWAI_ENABLED
|
||||
|
||||
#define ESP_IDF_COMP_PTHREAD_ENABLED
|
||||
|
||||
/* Optional / advanced – enable only if used */
|
||||
#define ESP_IDF_COMP_ESP_HTTP_CLIENT_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_HTTP_SERVER_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_HTTPS_OTA_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_NOW_ENABLED
|
||||
#define ESP_IDF_COMP_WPA_SUPPLICANT_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_COEX_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_PSRAM_ENABLED // himem/psram
|
||||
#define ESP_IDF_COMP_ESP_LCD_ENABLED
|
||||
|
||||
// #define ESP_IDF_COMP_ESPRESSIF__ESP_TINYUSB_ENABLED
|
||||
|
||||
/* Conditional component defines used in bindings.h */
|
||||
#ifdef ESP_IDF_COMP_ESP_WIFI_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_NETIF_ENABLED
|
||||
#endif
|
||||
#ifdef ESP_IDF_COMP_WPA_SUPPLICANT_ENABLED
|
||||
#define ESP_IDF_COMP_ESP_WIFI_ENABLED
|
||||
#endif
|
||||
|
||||
/* Version-aware stubs */
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
#define ESP_IDF_COMP_ESP_DRIVER_ENABLED 0 // drivers are now per-component
|
||||
#else
|
||||
#define ESP_IDF_COMP_DRIVER_ENABLED
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5 && ESP_IDF_VERSION_MINOR >= 1
|
||||
#define ESP_IDF_COMP_ESP_COEX_ENABLED // coexist moved
|
||||
#endif
|
||||
|
||||
#if HAS_ESP_WIFI_REMOTE
|
||||
#define ESP_IDF_COMP_ESP_WIFI_REMOTE_ENABLED
|
||||
#endif
|
||||
#if HAS_ESP_HOSTED
|
||||
#define ESP_IDF_COMP_ESP_HOSTED_ENABLED
|
||||
#endif
|
||||
|
||||
#include <stddef.h> // for size_t, ptrdiff_t, NULL
|
||||
#include <stdint.h> // for uint8_t, uint32_t, etc.
|
||||
#include <sys/types.h> // for additional POSIX types
|
||||
|
||||
/* Include AFTER all the protections */
|
||||
#include "pthread_stubs.h"
|
||||
#include "bindings.h"
|
||||
#include "bt_stubs.h"
|
||||
#include "wifi_stubs.h"
|
||||
|
||||
// Optional/Managed Components
|
||||
// check cmake/extra-components.cmake
|
||||
#if HAS_LED_STRIP
|
||||
#include "led_strip.h"
|
||||
#endif
|
||||
#if HAS_ESP_DSP
|
||||
#include "esp_dsp.h"
|
||||
#endif
|
||||
#if HAS_ESP_MATTER
|
||||
#include "matter_stubs.h"
|
||||
#endif
|
||||
|
||||
#endif // STUBS_H
|
||||
47
software/zig_main/include/wifi_stubs.h
Normal file
47
software/zig_main/include/wifi_stubs.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* The examples use WiFi configuration that you can set via project
|
||||
configuration menu
|
||||
|
||||
If you'd rather not, just change the below entries to strings with
|
||||
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
#if CONFIG_ESP_WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
#define EXAMPLE_H2E_IDENTIFIER ""
|
||||
#elif CONFIG_ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HASH_TO_ELEMENT
|
||||
#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
|
||||
#elif CONFIG_ESP_WPA3_SAE_PWE_BOTH
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
|
||||
#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
|
||||
#endif
|
||||
#if CONFIG_ESP_WIFI_AUTH_OPEN
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WEP
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||
#endif
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about
|
||||
* two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
Reference in New Issue
Block a user