ble_drv.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2016 Glenn Ruben Bakke
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef BLUETOOTH_LE_DRIVER_H__
  27. #define BLUETOOTH_LE_DRIVER_H__
  28. #if BLUETOOTH_SD
  29. #include <stdint.h>
  30. #include <stdbool.h>
  31. #include "modubluepy.h"
  32. typedef struct {
  33. uint8_t addr[6];
  34. uint8_t addr_type;
  35. } ble_drv_addr_t;
  36. typedef struct {
  37. uint8_t * p_peer_addr;
  38. uint8_t addr_type;
  39. bool is_scan_resp;
  40. int8_t rssi;
  41. uint8_t data_len;
  42. uint8_t * p_data;
  43. uint8_t adv_type;
  44. } ble_drv_adv_data_t;
  45. typedef struct {
  46. uint16_t uuid;
  47. uint8_t uuid_type;
  48. uint16_t start_handle;
  49. uint16_t end_handle;
  50. } ble_drv_service_data_t;
  51. typedef struct {
  52. uint16_t uuid;
  53. uint8_t uuid_type;
  54. uint8_t props;
  55. uint16_t decl_handle;
  56. uint16_t value_handle;
  57. } ble_drv_char_data_t;
  58. typedef void (*ble_drv_gap_evt_callback_t)(mp_obj_t self, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data);
  59. typedef void (*ble_drv_gatts_evt_callback_t)(mp_obj_t self, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
  60. typedef void (*ble_drv_gattc_evt_callback_t)(mp_obj_t self, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
  61. typedef void (*ble_drv_adv_evt_callback_t)(mp_obj_t self, uint16_t event_id, ble_drv_adv_data_t * data);
  62. typedef void (*ble_drv_disc_add_service_callback_t)(mp_obj_t self, ble_drv_service_data_t * p_service_data);
  63. typedef void (*ble_drv_disc_add_char_callback_t)(mp_obj_t self, ble_drv_char_data_t * p_desc_data);
  64. typedef void (*ble_drv_gattc_char_data_callback_t)(mp_obj_t self, uint16_t length, uint8_t * p_data);
  65. uint32_t ble_drv_stack_enable(void);
  66. void ble_drv_stack_disable(void);
  67. uint8_t ble_drv_stack_enabled(void);
  68. void ble_drv_address_get(ble_drv_addr_t * p_addr);
  69. bool ble_drv_uuid_add_vs(uint8_t * p_uuid, uint8_t * idx);
  70. bool ble_drv_service_add(ubluepy_service_obj_t * p_service_obj);
  71. bool ble_drv_characteristic_add(ubluepy_characteristic_obj_t * p_char_obj);
  72. bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params);
  73. void ble_drv_advertise_stop(void);
  74. void ble_drv_gap_event_handler_set(mp_obj_t obs, ble_drv_gap_evt_callback_t evt_handler);
  75. void ble_drv_gatts_event_handler_set(mp_obj_t obj, ble_drv_gatts_evt_callback_t evt_handler);
  76. void ble_drv_gattc_event_handler_set(mp_obj_t obj, ble_drv_gattc_evt_callback_t evt_handler);
  77. void ble_drv_attr_s_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data);
  78. void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, mp_obj_t obj, ble_drv_gattc_char_data_callback_t cb);
  79. void ble_drv_attr_s_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data);
  80. void ble_drv_attr_s_notify(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data);
  81. void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data, bool w_response);
  82. void ble_drv_scan_start(bool cont);
  83. void ble_drv_scan_stop(void);
  84. void ble_drv_adv_report_handler_set(mp_obj_t obj, ble_drv_adv_evt_callback_t evt_handler);
  85. void ble_drv_connect(uint8_t * p_addr, uint8_t addr_type);
  86. bool ble_drv_discover_services(mp_obj_t obj, uint16_t conn_handle, uint16_t start_handle, ble_drv_disc_add_service_callback_t cb);
  87. bool ble_drv_discover_characteristic(mp_obj_t obj,
  88. uint16_t conn_handle,
  89. uint16_t start_handle,
  90. uint16_t end_handle,
  91. ble_drv_disc_add_char_callback_t cb);
  92. void ble_drv_discover_descriptors(void);
  93. #endif // BLUETOOTH_SD
  94. #endif // BLUETOOTH_LE_DRIVER_H__