gap.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <furi-hal-version.h>
  5. #define GAP_MAC_ADDR_SIZE (6)
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef enum {
  10. BleEventTypeConnected,
  11. BleEventTypeDisconnected,
  12. BleEventTypeStartAdvertising,
  13. BleEventTypeStopAdvertising,
  14. BleEventTypePinCodeShow,
  15. BleEventTypePinCodeVerify,
  16. BleEventTypeUpdateMTU,
  17. } BleEventType;
  18. typedef union {
  19. uint32_t pin_code;
  20. uint16_t max_packet_size;
  21. } BleEventData;
  22. typedef struct {
  23. BleEventType type;
  24. BleEventData data;
  25. } BleEvent;
  26. typedef bool(*BleEventCallback) (BleEvent event, void* context);
  27. typedef enum {
  28. GapStateIdle,
  29. GapStateStartingAdv,
  30. GapStateAdvFast,
  31. GapStateAdvLowPower,
  32. GapStateConnected,
  33. } GapState;
  34. typedef enum {
  35. GapPairingPinCodeShow,
  36. GapPairingPinCodeVerifyYesNo,
  37. } GapPairing;
  38. typedef struct {
  39. uint16_t adv_service_uuid;
  40. uint16_t appearance_char;
  41. bool bonding_mode;
  42. GapPairing pairing_method;
  43. uint8_t mac_address[GAP_MAC_ADDR_SIZE];
  44. char adv_name[FURI_HAL_VERSION_DEVICE_NAME_LENGTH];
  45. } GapConfig;
  46. bool gap_init(GapConfig* config, BleEventCallback on_event_cb, void* context);
  47. void gap_start_advertising();
  48. void gap_stop_advertising();
  49. GapState gap_get_state();
  50. void gap_thread_stop();
  51. #ifdef __cplusplus
  52. }
  53. #endif