Unit Bluetooth

From Ultibo.org
Revision as of 04:34, 10 November 2025 by Ultibo (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Return to Unit Reference


Description


Ultibo Bluetooth interface unit

Constants



Bluetooth device, driver and host specific constants BLUETOOTH_*
BLUETOOTH_DEVICE_PREFIX = 'Bluetooth'; Name prefix for Bluetooth Devices
BLUETOOTH_DRIVER_PREFIX = 'Bluetooth'; Name prefix for Bluetooth Drivers
BLUETOOTH_HOST_PREFIX = 'BluetoothHost'; Name prefix for Bluetooth Hosts
BLUETOOTH_DRIVER_NAME = 'Bluetooth USB HCI Driver'; Name of Bluetooth USB driver


Bluetooth device types BLUETOOTH_TYPE_*
BLUETOOTH_TYPE_NONE = 0;  
BLUETOOTH_TYPE_MAX = 0;  
 
BLUETOOTH_TYPE_NAMES:array[BLUETOOTH_TYPE_NONE..BLUETOOTH_TYPE_MAX] of String = ('BLUETOOTH_TYPE_NONE');


Bluetooth device states BLUETOOTH_STATE_*
BLUETOOTH_STATE_DETACHED = 0;  
BLUETOOTH_STATE_DETACHING = 1;  
BLUETOOTH_STATE_ATTACHING = 2;  
BLUETOOTH_STATE_ATTACHED = 3;  
 
BLUETOOTH_STATE_MAX = 3;  
 
BLUETOOTH_STATE_NAMES:array[BLUETOOTH_STATE_DETACHED..BLUETOOTH_STATE_MAX] of String = ('BLUETOOTH_STATE_DETACHED', 'BLUETOOTH_STATE_DETACHING', 'BLUETOOTH_STATE_ATTACHING', 'BLUETOOTH_STATE_ATTACHED');


Bluetooth device status BLUETOOTH_STATUS_*
BLUETOOTH_STATUS_UNBOUND = 0;  
BLUETOOTH_STATUS_BOUND = 1;  
 
BLUETOOTH_STATUS_MAX = 1;  
 
BLUETOOTH_STATUS_NAMES:array[BLUETOOTH_STATUS_UNBOUND..BLUETOOTH_STATUS_MAX] of String = ('BLUETOOTH_STATUS_UNBOUND', 'BLUETOOTH_STATUS_BOUND');


Bluetooth device flags BLUETOOTH_FLAG_*
BLUETOOTH_FLAG_NONE = $00000000;  


Bluetooth host types BLUETOOTHHOST_TYPE_*
BLUETOOTHHOST_TYPE_NONE = 0;  
BLUETOOTHHOST_TYPE_UART = 1; Bluetooth HCI over RS232 with RTS/CTS flow control for reliable delivery
BLUETOOTHHOST_TYPE_USB = 2; Bluetooth HCI over USB
BLUETOOTHHOST_TYPE_SDIO = 3; Bluetooth HCI over SDIO
BLUETOOTHHOST_TYPE_3WIRE = 4; Bluetooth HCI over 3 wire UART (TX/RX/GND only with RTS/CTS optional)
 
BLUETOOTHHOST_TYPE_MAX = 4;  
 
BLUETOOTHHOST_TYPE_NAMES:array[BLUETOOTHHOST_TYPE_NONE..BLUETOOTHHOST_TYPE_MAX] of String = ('BLUETOOTHHOST_TYPE_NONE', 'BLUETOOTHHOST_TYPE_UART', 'BLUETOOTHHOST_TYPE_USB', 'BLUETOOTHHOST_TYPE_SDIO', 'BLUETOOTHHOST_TYPE_3WIRE');


Bluetooth host states BLUETOOTHHOST_STATE_*
BLUETOOTHHOST_STATE_DISABLED = 0;  
BLUETOOTHHOST_STATE_ENABLED = 1;  
 
BLUETOOTHHOST_STATE_MAX = 1;  
 
BLUETOOTHHOST_STATE_NAMES:array[BLUETOOTHHOST_STATE_DISABLED..BLUETOOTHHOST_STATE_MAX] of String = ('BLUETOOTHHOST_STATE_DISABLED', 'BLUETOOTHHOST_STATE_ENABLED');


Bluetooth host flags BLUETOOTHHOST_FLAG_*
BLUETOOTHHOST_FLAG_NONE = $00000000;  
BLUETOOTHHOST_FLAG_SHARED = $00000001;  
BLUETOOTHHOST_FLAG_NOCACHE = $00000002;  


Bluetooth status codes BLUETOOTH_STATUS_*
BLUETOOTH_STATUS_SUCCESS = 0; Function successful
BLUETOOTH_STATUS_DEVICE_DETACHED = 1; Bluetooth device was detached
BLUETOOTH_STATUS_DEVICE_UNSUPPORTED = 2; Bluetooth device is unsupported by the driver
BLUETOOTH_STATUS_HARDWARE_ERROR = 3; Hardware error of some form occurred
BLUETOOTH_STATUS_INVALID_DATA = 4; Invalid data was received
BLUETOOTH_STATUS_INVALID_PARAMETER = 5; An invalid parameter was passed to the function


Bluetooth logging BLUETOOTH_LOG_*
BLUETOOTH_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG; Bluetooth debugging messages
BLUETOOTH_LOG_LEVEL_INFO = LOG_LEVEL_INFO; Bluetooth informational messages, such as a device being attached or detached
BLUETOOTH_LOG_LEVEL_WARN = LOG_LEVEL_WARN; Bluetooth warning messages
BLUETOOTH_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; Bluetooth error messages
BLUETOOTH_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No Bluetooth messages


Type definitions



Bluetooth device

PBluetoothDevice = ^TBluetoothDevice;

TBluetoothDevice = record

Device Properties
Device:TDevice; The Device entry for this Bluetooth device
Bluetooth Properties
BluetoothId:LongWord; Unique Id of this Bluetooth in the Bluetooth device table
BluetoothState:LongWord; Bluetooth device state (eg BLUETOOTH_STATE_ATTACHED)
BluetoothStatus:LongWord; Bluetooth device status (eg BLUETOOTH_STATUS_BOUND)
Host:PBluetoothHost; Host controller this Bluetooth device is connected to (Set by Bluetooth core)
Driver:PBluetoothDriver; Driver this Bluetooth device is bound to, if any (Set by Bluetooth core)
Driver Properties
Lock:TMutexHandle; Bluetooth device lock
Internal Properties
Prev:PBluetoothDevice; Previous entry in Bluetooth device table
Next:PBluetoothDevice; Next entry in Bluetooth device table

Bluetooth device bind callback

TBluetoothDeviceBind = function(Device:PBluetoothDevice):LongWord;

Bluetooth device unbind callback

TBluetoothDeviceUnbind = function(Device:PBluetoothDevice; Driver:PBluetoothDriver):LongWord;

Bluetooth device enumeration callback

TBluetoothDeviceEnumerate = function(Device:PBluetoothDevice; Data:Pointer):LongWord;

Bluetooth device notification callback

TBluetoothDeviceNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

Bluetooth driver enumeration callback

TBluetoothDriverEnumerate = function(Driver:PBluetoothDriver; Data:Pointer):LongWord;

Bluetooth driver bind callback

TBluetoothDriverBind = function(Device:PBluetoothDevice):LongWord;

Bluetooth driver unbind callback

TBluetoothDriverUnbind = function(Device:PBluetoothDevice):LongWord;

Bluetooth driver

PBluetoothDriver = ^TBluetoothDriver;

TBluetoothDriver = record

Driver Properties
Driver:TDriver; The Driver entry for this Bluetooth Driver
Bluetooth Properties
DriverBind:TBluetoothDriverBind; A Driver specific DriverBind method implementing the standard Bluetooth driver interface
DriverUnbind:TBluetoothDriverUnbind; A Driver specific DriverUnbind method implementing the standard Bluetooth driver interface
Interface Properties
Lock:TMutexHandle; Driver lock
Internal Properties
Prev:PBluetoothDriver; Previous entry in Driver table
Next:PBluetoothDriver; Next entry in Driver table

Bluetooth host enumeration callback

TBluetoothHostEnumerate = function(Host:PBluetoothHost; Data:Pointer):LongWord;

Bluetooth host notification callback

TBluetoothHostNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

Bluetooth host start

TBluetoothHostStart = function(Host:PBluetoothHost):LongWord;

Bluetooth host stop

TBluetoothHostStop = function(Host:PBluetoothHost):LongWord;

Bluetooth host reset

TBluetoothHostReset = function(Host:PBluetoothHost):LongWord;

Bluetooth host

PBluetoothHost = ^TBluetoothHost;

TBluetoothHost = record

Device Properties
Device:TDevice; The Device entry for this Bluetooth Host
Bluetooth Properties
HostId:LongWord; Unique Id of this Host in the Host table
HostState:LongWord; Host state (eg BLUETOOTHHOST_STATE_ENABLED)
HostStart:TBluetoothHostStart; A Host specific HostStart method implementing the standard Bluetooth host interface
HostStop:TBluetoothHostStop; A Host specific HostStop method implementing the standard Bluetooth host interface
HostReset:TBluetoothHostReset; A Host specific HostReset method implementing the standard Bluetooth host interface
Driver Properties
Lock:TMutexHandle; Host lock
Internal Properties
Prev:PBluetoothHost; Previous entry in Host table
Next:PBluetoothHost; Next entry in Host table

Bluetooth log output

TBluetoothLogOutput = procedure(const AText:String; Data:Pointer);


Public variables


Bluetooth specific variables

BluetoothInitialized:Boolean;

Bluetooth logging

BLUETOOTH_DEFAULT_LOG_LEVEL:LongWord = BLUETOOTH_LOG_LEVEL_DEBUG; Minimum level for Bluetooth messages. Only messages with level greater than or equal to this will be printed.
BLUETOOTH_LOG_ENABLED:Boolean;


Function declarations



Initialization functions

procedure BluetoothInit;
Description: Performs basic initialization of the Bluetooth core driver, after this devices, hosts and drivers can be registered however nothing will work until BluetoothStart is called
Note Called only during system startup


function BluetoothStart:LongWord;
Description: Starts all registered Bluetooth hosts and begins the Bluetooth discovery process
Note None documented


function BluetoothStop:LongWord;
Description: To be documented
Note None documented


procedure BluetoothAsyncStart(Host:PBluetoothHost);
Description: To be documented
Note None documented


Bluetooth device, driver and host functions

function BluetoothDeviceAllocate(Host:PBluetoothHost):PBluetoothDevice;
Description: Create and Register a new Device entry in the Device table
Host The Host this device is attached to
Parent The Parent device this device is attached to (nil if this device has no parent)
Return Pointer to new Device entry or nil if device could not be created


function BluetoothDeviceRelease(Device:PBluetoothDevice):LongWord;
Description: Deregister and Destroy a Device from the Device table
Device The device to deregister and destroy
Return ERROR_SUCCESS if completed or another error code on failure


function BluetoothDeviceFind(BluetoothId:LongWord):PBluetoothDevice;
Description: To be documented
Note None documented


function BluetoothDeviceFindByName(const Name:String):PBluetoothDevice; inline;
Description: To be documented
Note None documented


function BluetoothDeviceFindByDescription(const Description:String):PBluetoothDevice; inline;
Description: To be documented
Note None documented


function BluetoothDeviceEnumerate(Callback:TBluetoothDeviceEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function BluetoothDeviceNotification(Device:PBluetoothDevice; Callback:TBluetoothDeviceNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented
Note None documented


function BluetoothDriverCreate:PBluetoothDriver;
Description: Create a new Bluetooth Driver entry
Return Pointer to new Driver entry or nil if driver could not be created


function BluetoothDriverCreateEx(Size:LongWord):PBluetoothDriver;
Description: Create a new Bluetooth Driver entry
Size Size in bytes to allocate for new driver (Including the driver entry)
Return Pointer to new Driver entry or nil if driver could not be created


function BluetoothDriverDestroy(Driver:PBluetoothDriver):LongWord;
Description: Destroy an existing Bluetooth Driver entry
Note None documented


function BluetoothDriverRegister(Driver:PBluetoothDriver):LongWord;
Description: Register a new Driver in the Bluetooth Driver table
Note None documented


function BluetoothDriverDeregister(Driver:PBluetoothDriver):LongWord;
Description: Deregister a Driver from the Bluetooth Driver table
Note None documented


function BluetoothDriverFind(DriverId:LongWord):PBluetoothDriver;
Description: Find a driver by Id in the Bluetooth Driver table
Note None documented


function BluetoothDriverFindByName(const Name:String):PBluetoothDriver; inline;
Description: Find a driver by name in the Driver table
Note None documented


function BluetoothDriverEnumerate(Callback:TBluetoothDriverEnumerate; Data:Pointer):LongWord;
Description: Enumerate all drivers in the Bluetooth Driver table
Note None documented


function BluetoothHostCreate:PBluetoothHost;
Description: Create a new Host entry
Return Pointer to new Host entry or nil if host could not be created


function BluetoothHostCreateEx(Size:LongWord):PBluetoothHost;
Description: Create a new Host entry
Size Size in bytes to allocate for new host (Including the host entry)
Return Pointer to new Host entry or nil if host could not be created


function BluetoothHostDestroy(Host:PBluetoothHost):LongWord;
Description: Destroy an existing Host entry
Note None documented


function BluetoothHostRegister(Host:PBluetoothHost):LongWord;
Description: Register a new Host in the Host table
Note None documented


function BluetoothHostDeregister(Host:PBluetoothHost):LongWord;
Description: Deregister a Host from the Host table
Note None documented


function BluetoothHostFind(HostId:LongWord):PBluetoothHost;
Description: To be documented
Note None documented


function BluetoothHostFindByName(const Name:String):PBluetoothHost; inline;
Description: To be documented
Note None documented


function BluetoothHostFindByDescription(const Description:String):PBluetoothHost; inline;
Description: To be documented
Note None documented


function BluetoothHostEnumerate(Callback:TBluetoothHostEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function BluetoothHostNotification(Host:PBluetoothHost; Callback:TBluetoothHostNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented
Note None documented


Bluetooth device, driver and host helper functions

function BluetoothDeviceGetCount:LongWord;
Description: Get the current device count
Note None documented


function BluetoothDeviceCheck(Device:PBluetoothDevice):PBluetoothDevice;
Description: Check if the supplied Device is in the device table
Note None documented


function BluetoothDriverGetCount:LongWord;
Description: Get the current Bluetooth driver count
Note None documented


function BluetoothDriverCheck(Driver:PBluetoothDriver):PBluetoothDriver;
Description: Check if the supplied Bluetooth Driver is in the driver table
Note None documented


function BluetoothHostGetCount:LongWord;
Description: Get the current host count
Note None documented


function BluetoothHostCheck(Host:PBluetoothHost):PBluetoothHost;
Description: Check if the supplied Host is in the host table
Note None documented


function BluetoothStatusToString(Status:LongWord):String;
Description: Translates a Bluetooth status code into a string
Note None documented


function BluetoothDeviceTypeToString(BluetoothType:LongWord):String;
Description: To be documented
Note None documented


function BluetoothDeviceStateToString(BluetoothState:LongWord):String;
Description: To be documented
Note None documented


function BluetoothDeviceStatusToString(BluetoothStatus:LongWord):String;
Description: To be documented
Note None documented


function BluetoothDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Device state value into the notification code for device notifications
Note None documented


function BluetoothDeviceStatusToNotification(Status:LongWord):LongWord;
Description: Convert a Device status value into the notification code for device notifications
Note None documented


function BluetoothHostTypeToString(HostType:LongWord):String;
Description: To be documented
Note None documented


function BluetoothHostStateToString(HostState:LongWord):String;
Description: To be documented
Note None documented


function BluetoothHostStateToNotification(State:LongWord):LongWord;
Description: Convert a Host state value into the notification code for device notifications
Note None documented


procedure BluetoothLog(Level:LongWord; Device:PBluetoothDevice; const AText:String);
Description: To be documented
Note None documented


procedure BluetoothLogInfo(Device:PBluetoothDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure BluetoothLogWarn(Device:PBluetoothDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure BluetoothLogError(Device:PBluetoothDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure BluetoothLogDebug(Device:PBluetoothDevice; const AText:String); inline;
Description: To be documented
Note None documented


Return to Unit Reference