2021-09-10 02:19:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2024-02-16 07:20:45 +00:00
|
|
|
/*
|
|
|
|
* Serial service. Implements RPC over BLE, with flow control.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define BLE_SVC_SERIAL_DATA_LEN_MAX (486)
|
|
|
|
#define BLE_SVC_SERIAL_CHAR_VALUE_LEN_MAX (243)
|
2022-10-14 17:21:23 +00:00
|
|
|
|
2021-12-08 11:28:01 +00:00
|
|
|
typedef enum {
|
|
|
|
SerialServiceEventTypeDataReceived,
|
|
|
|
SerialServiceEventTypeDataSent,
|
2022-10-14 17:21:23 +00:00
|
|
|
SerialServiceEventTypesBleResetRequest,
|
2021-12-08 11:28:01 +00:00
|
|
|
} SerialServiceEventType;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t* buffer;
|
|
|
|
uint16_t size;
|
|
|
|
} SerialServiceData;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
SerialServiceEventType event;
|
|
|
|
SerialServiceData data;
|
|
|
|
} SerialServiceEvent;
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef uint16_t (*SerialServiceEventCallback)(SerialServiceEvent event, void* context);
|
2021-10-12 16:41:42 +00:00
|
|
|
|
2024-02-16 07:20:45 +00:00
|
|
|
typedef struct BleServiceSerial BleServiceSerial;
|
|
|
|
|
|
|
|
BleServiceSerial* ble_svc_serial_start(void);
|
2021-09-10 02:19:02 +00:00
|
|
|
|
2024-02-16 07:20:45 +00:00
|
|
|
void ble_svc_serial_stop(BleServiceSerial* service);
|
|
|
|
|
|
|
|
void ble_svc_serial_set_callbacks(
|
|
|
|
BleServiceSerial* service,
|
2022-01-05 16:10:18 +00:00
|
|
|
uint16_t buff_size,
|
|
|
|
SerialServiceEventCallback callback,
|
|
|
|
void* context);
|
2021-11-08 19:41:40 +00:00
|
|
|
|
2024-02-16 07:20:45 +00:00
|
|
|
void ble_svc_serial_set_rpc_active(BleServiceSerial* service, bool active);
|
2021-09-10 02:19:02 +00:00
|
|
|
|
2024-02-16 07:20:45 +00:00
|
|
|
void ble_svc_serial_notify_buffer_is_empty(BleServiceSerial* service);
|
2021-12-08 11:28:01 +00:00
|
|
|
|
2024-02-16 07:20:45 +00:00
|
|
|
bool ble_svc_serial_update_tx(BleServiceSerial* service, uint8_t* data, uint16_t data_len);
|
2021-09-10 02:19:02 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|