-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathbluetooth.h
More file actions
104 lines (82 loc) · 3.61 KB
/
bluetooth.h
File metadata and controls
104 lines (82 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
// Internal common bluetooth functions.
#ifndef _INTERNAL_PBDRV_BLUETOOTH_H_
#define _INTERNAL_PBDRV_BLUETOOTH_H_
#include <pbdrv/config.h>
#if PBDRV_CONFIG_BLUETOOTH
#include <pbio/os.h>
#include <pbdrv/bluetooth.h>
#include <stdbool.h>
#include <stdint.h>
void pbdrv_bluetooth_init_hci(void);
pbio_error_t pbdrv_bluetooth_controller_reset(pbio_os_state_t *state, pbio_os_timer_t *timer);
pbio_error_t pbdrv_bluetooth_controller_initialize(pbio_os_state_t *state, pbio_os_timer_t *timer);
pbio_error_t pbdrv_bluetooth_disconnect_all(pbio_os_state_t *state);
pbio_error_t pbdrv_bluetooth_start_broadcasting_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_start_advertising_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_stop_advertising_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_start_observing_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_stop_observing_func(pbio_os_state_t *state, void *context);
pbdrv_bluetooth_peripheral_t *pbdrv_bluetooth_peripheral_get_by_index(uint8_t index);
pbio_error_t pbdrv_bluetooth_peripheral_disconnect_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_peripheral_discover_characteristic_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_peripheral_read_characteristic_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_peripheral_scan_and_connect_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_peripheral_write_characteristic_func(pbio_os_state_t *state, void *context);
pbio_error_t pbdrv_bluetooth_send_pybricks_value_notification(pbio_os_state_t *state, const uint8_t *data, uint16_t size);
void pbdrv_bluetooth_host_connection_changed(void);
extern pbdrv_bluetooth_receive_handler_t pbdrv_bluetooth_receive_handler;
extern uint8_t pbdrv_bluetooth_broadcast_data[PBDRV_BLUETOOTH_MAX_ADV_SIZE];
extern uint8_t pbdrv_bluetooth_broadcast_data_size;
typedef enum {
PBDRV_BLUETOOTH_ADVERTISING_STATE_NONE,
PBDRV_BLUETOOTH_ADVERTISING_STATE_ADVERTISING_PYBRICKS,
PBDRV_BLUETOOTH_ADVERTISING_STATE_BROADCASTING,
} pbdrv_bluetooth_advertising_state_t;
extern pbdrv_bluetooth_advertising_state_t pbdrv_bluetooth_advertising_state;
extern bool pbdrv_bluetooth_is_observing;
extern pbdrv_bluetooth_start_observing_callback_t pbdrv_bluetooth_observe_callback;
pbio_error_t pbdrv_bluetooth_process_thread(pbio_os_state_t *state, void *context);
/**
* Context for an ongoing classic Bluetooth task.
*
* Not all fields are used by all functions. Only one function runs at a time.
*/
typedef struct {
/**
* The currently active function.
*/
pbio_os_process_func_t func;
/**
* The most recent result of calling above function from main process.
*/
pbio_error_t err;
/**
* Cancellation requested.
*/
bool cancel;
/**
* Watchdog for above operation so it can be cancelled on inactivity.
*/
pbio_os_timer_t watchdog;
/**
* Inquiry scan results.
*/
pbdrv_bluetooth_inquiry_result_t *inq_results;
/**
* Number of scan results found so far.
*/
uint32_t *inq_count;
/**
* Maximum number of scan results to find.
*/
uint32_t *inq_count_max;
/**
* Inquiry duration in units of 1.28 seconds.
*/
uint8_t inq_duration;
} pbdrv_bluetooth_classic_task_context_t;
pbio_error_t pbdrv_bluetooth_inquiry_scan_func(pbio_os_state_t *state, void *context);
#endif // PBDRV_CONFIG_BLUETOOTH
#endif // _INTERNAL_PBDRV_BLUETOOTH_H_