ENI Developer Documentation v0.1.0
Embedded Neural Interface framework with provider contracts, event processing, safety policies, signal filtering, and Neuralink BCI integration. Headers: <eni/provider_contract.h>, <eni/event.h>, <eni/policy.h>, <eni_min/filter.h>, <eni_min/normalizer.h>, <eni/neuralink.h>
💡 Event System
Structured events for neural data, intents, and features. Header: <eni/event.h>
eni_event_t
id | uint32_t | Unique event ID (auto-assigned). |
version | uint32_t | Event schema version. |
type | eni_event_type_t | ENI_EVENT_INTENT, ENI_EVENT_FEATURES, ENI_EVENT_RAW, ENI_EVENT_CONTROL. |
timestamp | eni_timestamp_t | Event creation time (microseconds). |
source[64] | char | Provider name that generated this event. |
payload | union | Intent (.intent), features (.features), or raw data (.raw). |
eni_intent_t
name[64] | char | Intent name (e.g., "move_left", "select", "scroll_down"). |
confidence | float | Confidence score 0.0-1.0. |
eni_feature_t / eni_feature_set_t
name[32] | char | Feature name (e.g., "alpha_power", "beta_coherence"). |
value | float | Feature value. |
features[32] | eni_feature_t | Array of up to 32 features in a set. |
count | int | Number of features in the set. |
eni_event_type_t
ENI_EVENT_INTENT | 0 | Decoded user intent with confidence. |
ENI_EVENT_FEATURES | 1 | Extracted neural features (alpha, beta, gamma power). |
ENI_EVENT_RAW | 2 | Raw byte payload (up to 4096 bytes). |
ENI_EVENT_CONTROL | 3 | System control event (calibration, config change). |
eni_status_t eni_event_init(eni_event_t *ev, eni_event_type_t type, const char *source)Initialize an event with type, source name, auto-generated ID, current timestamp, and zeroed payload. Must be called before setting intent/features/raw data.
Parameters
ev | eni_event_t * | Event to initialize. |
type | eni_event_type_t | Event type. |
source | const char * | Provider name (max 63 chars). |
Returns
ENI_OK on success. ENI_ERR_INVALID if ev or source is NULL.
Example
eni_event_t ev;
eni_event_init(&ev, ENI_EVENT_INTENT, "neuralink_n1");
eni_event_set_intent(&ev, "move_cursor_left", 0.92f);
eni_event_print(&ev);eni_status_t eni_event_set_intent(eni_event_t *ev, const char *intent, float confidence)Set intent payload on an ENI_EVENT_INTENT event. Copies intent name and confidence score.
Parameters
ev | eni_event_t * | Event (must be type INTENT). |
intent | const char * | Intent name (max 63 chars). |
confidence | float | Confidence 0.0-1.0. |
Returns
ENI_OK on success.
eni_status_t eni_event_add_feature(eni_event_t *ev, const char *name, float value)Add a feature to an ENI_EVENT_FEATURES event. Up to ENI_EVENT_FEATURES_MAX (32) features per event.
Parameters
ev | eni_event_t * | Event (must be type FEATURES). |
name | const char * | Feature name (max 31 chars). |
value | float | Feature value. |
Returns
ENI_OK on success. ENI_ERR_FULL if 32 features reached.
eni_status_t eni_event_set_raw(eni_event_t *ev, const uint8_t *data, size_t len)Set raw byte payload on an ENI_EVENT_RAW event. Max ENI_EVENT_PAYLOAD_MAX (4096) bytes.
Parameters
ev | eni_event_t * | Event (must be type RAW). |
data | const uint8_t * | Raw data buffer. |
len | size_t | Data length in bytes. |
Returns
ENI_OK on success. ENI_ERR_INVALID if len exceeds 4096.
void eni_event_print(const eni_event_t *ev)Print event details to stdout for debugging: type, source, timestamp, and payload contents.
Parameters
ev | const eni_event_t * | Event to print. |
🔌 Provider Contract API
Interface for neural data providers. Header: <eni/provider_contract.h>
eni_provider_ops_t
Virtual function table that all providers must implement.
name | const char * | Provider name (e.g., "neuralink_n1", "emotiv_epoc"). |
init | fn(prov, config) → status | Initialize with device-specific config. |
poll | fn(prov, ev) → status | Poll for next event (non-blocking). |
start | fn(prov) → status | Start data acquisition. |
stop | fn(prov) → status | Stop data acquisition. |
shutdown | fn(prov) | Release all resources. |
eni_provider_t
name[64] | char | Instance name. |
ops | const eni_provider_ops_t * | Pointer to vtable. |
ctx | void * | Provider-specific context data. |
running | bool | Whether provider is actively streaming. |
transport | eni_transport_t | Communication transport (BLE, USB, SPI, etc.). |
eni_status_t eni_provider_init(eni_provider_t *prov, const eni_provider_ops_t *ops, const char *name, const void *config)Initialize a provider instance with its vtable, name, and device-specific configuration. Calls the provider's ops->init() callback.
Parameters
prov | eni_provider_t * | Provider instance to initialize. |
ops | const eni_provider_ops_t * | Provider vtable (must remain valid for lifetime). |
name | const char * | Instance name (max 63 chars). |
config | const void * | Device-specific config (cast inside init callback). |
Returns
ENI_OK on success. Provider-specific error codes.
Example
eni_provider_t prov;
eni_nl_config_t nl_cfg = {
.mode = ENI_NL_MODE_INTENT,
.channels = 256,
.sample_rate = 30000,
.device_addr = "NL-001-ABC",
.signal_threshold = 0.3f,
.auto_calibrate = 1
};
eni_provider_init(&prov, eni_neuralink_get_provider(),
"neuralink_primary", &nl_cfg);eni_status_t eni_provider_start(eni_provider_t *prov)Start the provider's data acquisition. After this call, eni_provider_poll() will return events.
Parameters
prov | eni_provider_t * | Initialized provider. |
Returns
ENI_OK on success.
eni_status_t eni_provider_poll(eni_provider_t *prov, eni_event_t *ev)Poll for the next available event. Non-blocking: returns ENI_ERR_EMPTY if no event is ready. Call in a loop from your main task or timer callback.
Parameters
prov | eni_provider_t * | Running provider. |
ev | eni_event_t * | Output event buffer. |
Returns
ENI_OK if event available. ENI_ERR_EMPTY if no event ready.
Example
// Main polling loop
eni_event_t ev;
while (running) {
if (eni_provider_poll(&prov, &ev) == ENI_OK) {
if (ev.type == ENI_EVENT_INTENT) {
printf("Intent: %s (%.1f%%)\n",
ev.payload.intent.name,
ev.payload.intent.confidence * 100.0f);
if (ev.payload.intent.confidence > 0.8f) {
execute_action(ev.payload.intent.name);
}
}
}
eos_task_delay_ms(10); // Yield to other tasks
}eni_status_t eni_provider_stop(eni_provider_t *prov)Stop data acquisition. Provider remains initialized and can be restarted.
Parameters
prov | eni_provider_t * | Running provider. |
Returns
ENI_OK on success.
void eni_provider_shutdown(eni_provider_t *prov)Fully shut down the provider and release all resources. Must not be used after this call.
Parameters
prov | eni_provider_t * | Provider to shut down. |
🛡 Safety Policy Engine
Action classification and permission control. Header: <eni/policy.h>
eni_action_class_t
ENI_ACTION_SAFE | 0 | Low-risk action (cursor movement, scrolling). |
ENI_ACTION_CONTROLLED | 1 | Medium-risk (typing, file operations). |
ENI_ACTION_RESTRICTED | 2 | High-risk (motor control, network access, system commands). |
eni_policy_verdict_t
ENI_POLICY_ALLOW | 0 | Action permitted. |
ENI_POLICY_DENY | 1 | Action blocked. |
ENI_POLICY_CONFIRM | 2 | Action requires user confirmation. |
eni_status_t eni_policy_init(eni_policy_engine_t *engine)Initialize policy engine with no rules and default_deny=false. Maximum ENI_POLICY_MAX_RULES (64) rules.
Parameters
engine | eni_policy_engine_t * | Policy engine to initialize. |
Returns
ENI_OK on success.
eni_status_t eni_policy_add_rule(eni_policy_engine_t *engine, const char *action, eni_policy_verdict_t verdict, eni_action_class_t action_class)Add a policy rule mapping an action name to a verdict and classification.
Parameters
engine | eni_policy_engine_t * | Policy engine. |
action | const char * | Action name (max 63 chars), e.g., "move_cursor", "emergency_stop". |
verdict | eni_policy_verdict_t | ALLOW, DENY, or CONFIRM. |
action_class | eni_action_class_t | SAFE, CONTROLLED, or RESTRICTED. |
Returns
ENI_OK on success. ENI_ERR_FULL if 64 rules reached.
Example
eni_policy_engine_t policy;
eni_policy_init(&policy);
eni_policy_set_default_deny(&policy, true);
// Safe actions - always allowed
eni_policy_add_rule(&policy, "move_cursor", ENI_POLICY_ALLOW, ENI_ACTION_SAFE);
eni_policy_add_rule(&policy, "scroll", ENI_POLICY_ALLOW, ENI_ACTION_SAFE);
// Controlled - require confirmation
eni_policy_add_rule(&policy, "click", ENI_POLICY_CONFIRM, ENI_ACTION_CONTROLLED);
eni_policy_add_rule(&policy, "type_text", ENI_POLICY_CONFIRM, ENI_ACTION_CONTROLLED);
// Restricted - denied by default
eni_policy_add_rule(&policy, "motor_start", ENI_POLICY_DENY, ENI_ACTION_RESTRICTED);eni_policy_verdict_t eni_policy_evaluate(const eni_policy_engine_t *engine, const char *action)Evaluate an action against the policy rules. Returns the verdict for the first matching rule, or DENY if default_deny is true and no rule matches, or ALLOW otherwise.
Parameters
engine | const eni_policy_engine_t * | Policy engine. |
action | const char * | Action name to evaluate. |
Returns
ENI_POLICY_ALLOW, ENI_POLICY_DENY, or ENI_POLICY_CONFIRM.
eni_status_t eni_policy_set_default_deny(eni_policy_engine_t *engine, bool deny)Set whether unmatched actions are denied (true) or allowed (false). Recommended: true for safety-critical applications.
Parameters
engine | eni_policy_engine_t * | Policy engine. |
deny | bool | Default deny flag. |
Returns
ENI_OK.
void eni_policy_dump(const eni_policy_engine_t *engine)Print all policy rules to stdout for debugging.
Parameters
engine | const eni_policy_engine_t * | Policy engine. |
Parameters
cfg | const eni_nl_config_t * | Configuration including mode, channels, sample rate, filters, and callbacks. |
Returns
0 on success. -1 on invalid config. -2 on resource allocation failure.
Example
void on_intent(const char *intent, float conf, void *ctx) {
printf("Intent: %s (%.0f%%)\n", intent, conf * 100);
}
eni_nl_config_t cfg = {
.mode = ENI_NL_MODE_INTENT,
.channels = 256,
.sample_rate = 30000,
.device_addr = "NL-001-ABC",
.signal_threshold = 0.3f,
.auto_calibrate = 1,
.filter_enabled = 1,
.bandpass_low_hz = 0.5f,
.bandpass_high_hz = 300.0f,
.notch_freq_hz = 60.0f,
.on_intent = on_intent,
.user_ctx = NULL
};
eni_neuralink_init(&cfg);