Files
ZephCore/zephcore/adapters/ble/ZephyrBLE.h
T
2026-03-28 20:53:59 +01:00

86 lines
2.4 KiB
C

/*
* SPDX-License-Identifier: Apache-2.0
* ZephCore BLE Adapter — NUS service, advertising, security, TX/RX
*/
#pragma once
#include <zephyr/kernel.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Callbacks from BLE adapter to main */
struct ble_callbacks {
/* RX frame received; runs on system work queue — must not block */
void (*on_rx_frame)(const uint8_t *data, uint16_t len);
/* TX queue drained */
void (*on_tx_idle)(void);
/* BLE connected */
void (*on_connected)(void);
/* BLE disconnected */
void (*on_disconnected)(void);
};
enum zephcore_iface {
ZEPHCORE_IFACE_NONE,
ZEPHCORE_IFACE_BLE,
ZEPHCORE_IFACE_USB,
};
/** Register callbacks and auth handlers. Call before bt_enable(). */
void zephcore_ble_init(const struct ble_callbacks *cbs);
/** Load settings, build adv data, start advertising. Call from bt_ready(). */
void zephcore_ble_start(const char *device_name);
/** Queue a frame for BLE TX. Returns bytes queued, or 0 on failure. */
size_t zephcore_ble_send(const uint8_t *data, uint16_t len);
/** Enable/disable BLE. Disabling disconnects and stops advertising. */
void zephcore_ble_set_enabled(bool enable);
/** True if BLE is the active transport and ready to send. */
bool zephcore_ble_is_active(void);
/** True if BLE has an active connection (regardless of interface state). */
bool zephcore_ble_is_connected(void);
/** True if TX queue is full and overflow retry is active. */
bool zephcore_ble_is_congested(void);
void zephcore_ble_set_passkey(uint32_t passkey);
uint32_t zephcore_ble_get_passkey(void);
/** Get/set active interface (BLE/USB coexistence). */
enum zephcore_iface zephcore_ble_get_active_iface(void);
void zephcore_ble_set_active_iface(enum zephcore_iface iface);
/** Get recv/send queues for USB path sharing. */
struct k_msgq *zephcore_ble_get_recv_queue(void);
struct k_msgq *zephcore_ble_get_send_queue(void);
/** Kick the TX drain work. Call after putting frames in the send queue. */
void zephcore_ble_kick_tx(void);
/**
* Disconnect the current BLE connection (if any).
* Used by USB when it takes over as active interface.
*/
void zephcore_ble_disconnect(void);
/**
* Apply deferred connection parameters.
* Call after the initial app sync is complete (channels + contacts +
* offline messages) so the param negotiation doesn't disrupt throughput
* during the sync burst.
*/
void zephcore_ble_conn_params_ready(void);
#ifdef __cplusplus
}
#endif