PowerBlocks SDK
 
Loading...
Searching...
No Matches
hci.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <stdbool.h>
18#include <stddef.h>
19#include <stdint.h>
20
21#include "FreeRTOS.h"
22#include "semphr.h"
23
26
27typedef struct {
28 uint8_t address[6];
29 uint8_t page_scan_repetition_mode;
30 uint32_t class_of_device;
31 uint16_t clock_offset;
33
34typedef struct {
35 uint16_t acl_data_packet_length;
36 uint8_t synchronous_data_packet_length;
37 uint16_t total_num_acl_data_packets; // Total ACL packets the hardware can store.
38 uint16_t total_num_synchronous_data_packets; // Total Sync packets the hardware can store.
40
41
42// Tired of coding
43// Felt like being evil with these names
44// Feel free to refactor. I am sorry
45typedef enum {
46 HCI_ACL_PACKET_BOUNDARY_FLAG_FIRST_NON_AUTOMATICALLY_FLUSHABLE_PACKET,
47 HCI_ACL_PACKET_BOUNDARY_FLAG_CONTINUING_FRAGMENT,
48 HCI_ACL_PACKET_BOUNDARY_FLAG_FIRST_AUTOMATICALLY_FLUSHABLE_PACKET
49} hci_acl_packet_boundary_flag_t;
50
51typedef enum {
52 HCI_ACL_PACKET_BROADCAST_FLAG_PTP,
53 HCI_ACL_PACKET_BROADCAST_FLAG_ACTIVE_DEVICE,
54 HCI_ACL_PACKET_BROADCAST_FLAG_PARKED_DEVICE,
55} hci_acl_packet_broadcast_flag_t;
56
57// HCI Defines multiple inquiry modes. We will probably ever use one.
58#define HCI_INQUIRY_MODE_GENERAL_ACCESS 0x9E8B33
59
60// Max size of a name from name request
61#define HCI_MAX_NAME_REQUEST_LENGTH 254
62
63// Max size of a ACL data section
64// This must be at least greater than the max size
65// Reported by the hardware. On the wii it reports 339 bytes.
66#define HCI_MAX_ACL_DATA_LENGTH 512
67
68// Defines the amount of data on the stack needed for the ACL receive, used to be kept around for async
69#define HCI_ACL_RECEIVE_IPC_BUFFER_SIZE (32 + 32 + 32 + 32 + sizeof(ipc_message))
70
71typedef struct {
72 uint16_t handle;
73 uint16_t size;
74 uint8_t data[HCI_MAX_ACL_DATA_LENGTH];
76
77// Exposed HCI Buffer Sizes
78// These are read from the controller when HCI is initialized.
79// Used for knowing how big and how many ACL/SCL buffers you can send
80extern hci_buffer_sizes_t hci_buffer_sizes;
81
82
89typedef void (*hci_discovered_device_handler)(void* user_data, const hci_discovered_device_info_t* device);
90
97typedef void (*hci_discovery_complete_handler)(void* user_data, uint8_t error);
98
108extern int hci_initialize(const char* device);
109
119extern void hci_close();
120
127extern int hci_reset();
128
154extern int hci_begin_discovery(
155 uint32_t lap, uint8_t length, uint8_t responses,
156 hci_discovered_device_handler on_discovered, hci_discovery_complete_handler on_complete, void *user_data);
157
166extern int hci_cancel_discovery();
167
181extern int hci_get_remote_name(const hci_discovered_device_info_t* device, uint8_t* name);
182
191extern int hci_create_connection(const hci_discovered_device_info_t* device, uint16_t* handle);
192
193// These 2 buffers have been statically allocated so that
194// You can lower the amount of memcpys in ACL transactions
195extern SemaphoreHandle_t hcl_acl_packet_out_lock;
196extern hci_acl_packet_t hci_acl_packet_out ALIGN(32) MEM2;
197extern hci_acl_packet_t hci_acl_packet_in_0 ALIGN(32) MEM2;
198extern hci_acl_packet_t hci_acl_packet_in_1 ALIGN(32) MEM2;
199
216extern int hci_send_acl(uint16_t handle, hci_acl_packet_boundary_flag_t pb, hci_acl_packet_broadcast_flag_t bc, uint16_t length);
217
238extern int hci_receive_acl_async(hci_acl_packet_t* acl_buffer, uint8_t* ipc_buffer, ipc_async_handler_t handler, void* params);
239
240
253extern void hci_decode_received_acl(uint16_t *handle, hci_acl_packet_boundary_flag_t *pb, hci_acl_packet_broadcast_flag_t *bc, uint16_t* length, const hci_acl_packet_t* acl_buffer);
int hci_send_acl(uint16_t handle, hci_acl_packet_boundary_flag_t pb, hci_acl_packet_broadcast_flag_t bc, uint16_t length)
Sends a ACL Packet.
Definition hci.c:839
void hci_decode_received_acl(uint16_t *handle, hci_acl_packet_boundary_flag_t *pb, hci_acl_packet_broadcast_flag_t *bc, uint16_t *length, const hci_acl_packet_t *acl_buffer)
Decodes a received ACL packet.
Definition hci.c:856
int hci_receive_acl_async(hci_acl_packet_t *acl_buffer, uint8_t *ipc_buffer, ipc_async_handler_t handler, void *params)
Receives a ACL Packet Asynchronously.
Definition hci.c:852
int hci_reset()
Resets the HCI Interface.
Definition hci.c:679
int hci_begin_discovery(uint32_t lap, uint8_t length, uint8_t responses, hci_discovered_device_handler on_discovered, hci_discovery_complete_handler on_complete, void *user_data)
Begins looking for bluetooth devices.
Definition hci.c:686
void hci_close()
Closes the HCI driver.
Definition hci.c:649
void(* hci_discovery_complete_handler)(void *user_data, uint8_t error)
Callback invoked when device discovery completes.
Definition hci.h:97
int hci_cancel_discovery()
Stops a discovery session.
Definition hci.c:720
int hci_create_connection(const hci_discovered_device_info_t *device, uint16_t *handle)
Creates a connection to a device for you to use.
Definition hci.c:763
int hci_initialize(const char *device)
Initializes the HCI interface.
Definition hci.c:571
int hci_get_remote_name(const hci_discovered_device_info_t *device, uint8_t *name)
Returns the remote name of a device.
Definition hci.c:733
void(* hci_discovered_device_handler)(void *user_data, const hci_discovered_device_info_t *device)
Callback for handling a discovered device during inquiry.
Definition hci.h:89
Input Output System.
Definition hci.h:71
Definition hci.h:34
Definition hci.h:27
Access parts of the base system.
#define ALIGN(x)
Add an alignment attribute to some data.
Definition system.h:243