mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-07 09:55:45 +00:00
support configurable UART baud rate on iPhone
This commit is contained in:
parent
f109cc1b60
commit
f4c198f489
@ -10,8 +10,8 @@
|
||||
9C46FBAF0FA8F31800ABEF05 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FBAE0FA8F31800ABEF05 /* main.c */; };
|
||||
9C46FC390FA906F700ABEF05 /* hci.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC340FA906F700ABEF05 /* hci.c */; };
|
||||
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */; };
|
||||
9C7ECB840FCC85650085DAC5 /* bt_control_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7ECB820FCC85650085DAC5 /* bt_control_iphone.c */; };
|
||||
9C88500E0FBF6702004980E4 /* l2cap.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C88500C0FBF6702004980E4 /* l2cap.c */; };
|
||||
9C8851E10FC3403F004980E4 /* bt_control_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C8851E00FC3403F004980E4 /* bt_control_iphone.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
@ -34,11 +34,11 @@
|
||||
9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = hci_transport_h4.c; path = src/hci_transport_h4.c; sourceTree = "<group>"; };
|
||||
9C46FC370FA906F700ABEF05 /* hci_transport_h4.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport_h4.h; path = src/hci_transport_h4.h; sourceTree = "<group>"; };
|
||||
9C46FC380FA906F700ABEF05 /* hci_transport.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport.h; path = src/hci_transport.h; sourceTree = "<group>"; };
|
||||
9C7ECB810FCC85650085DAC5 /* bt_control.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = bt_control.h; path = src/bt_control.h; sourceTree = "<group>"; };
|
||||
9C7ECB820FCC85650085DAC5 /* bt_control_iphone.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = bt_control_iphone.c; path = src/bt_control_iphone.c; sourceTree = "<group>"; };
|
||||
9C7ECB830FCC85650085DAC5 /* bt_control_iphone.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = bt_control_iphone.h; path = src/bt_control_iphone.h; sourceTree = "<group>"; };
|
||||
9C88500C0FBF6702004980E4 /* l2cap.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = l2cap.c; path = src/l2cap.c; sourceTree = "<group>"; };
|
||||
9C88500D0FBF6702004980E4 /* l2cap.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = l2cap.h; path = src/l2cap.h; sourceTree = "<group>"; };
|
||||
9C8851DF0FC3403E004980E4 /* bt_control_iphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bt_control_iphone.h; sourceTree = "<group>"; };
|
||||
9C8851E00FC3403F004980E4 /* bt_control_iphone.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bt_control_iphone.c; sourceTree = "<group>"; };
|
||||
9C8851E20FC340F8004980E4 /* bt_control.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bt_control.h; sourceTree = "<group>"; };
|
||||
9CA3C0900FB8B3C4005F48DE /* TODO.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TODO.txt; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -67,9 +67,9 @@
|
||||
08FB7795FE84155DC02AAC07 /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9C8851E20FC340F8004980E4 /* bt_control.h */,
|
||||
9C8851DF0FC3403E004980E4 /* bt_control_iphone.h */,
|
||||
9C8851E00FC3403F004980E4 /* bt_control_iphone.c */,
|
||||
9C7ECB810FCC85650085DAC5 /* bt_control.h */,
|
||||
9C7ECB820FCC85650085DAC5 /* bt_control_iphone.c */,
|
||||
9C7ECB830FCC85650085DAC5 /* bt_control_iphone.h */,
|
||||
9C46FC350FA906F700ABEF05 /* hci.h */,
|
||||
9C46FC340FA906F700ABEF05 /* hci.c */,
|
||||
9C46FC380FA906F700ABEF05 /* hci_transport.h */,
|
||||
@ -145,7 +145,7 @@
|
||||
9C46FC390FA906F700ABEF05 /* hci.c in Sources */,
|
||||
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */,
|
||||
9C88500E0FBF6702004980E4 /* l2cap.c in Sources */,
|
||||
9C8851E10FC3403F004980E4 /* bt_control_iphone.c in Sources */,
|
||||
9C7ECB840FCC85650085DAC5 /* bt_control_iphone.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "bt_control_iphone.h"
|
||||
|
||||
#include "hci_transport.h"
|
||||
|
||||
#include <sys/utsname.h> // uname
|
||||
#include <stdlib.h> // system
|
||||
#include <stdio.h> // sscanf, printf
|
||||
@ -42,8 +44,21 @@ static const char * iphone_name(void *config){
|
||||
return get_machine_name();
|
||||
}
|
||||
|
||||
static void iphone_set_pskey(int fd, int key, int value){
|
||||
sprintf(buffer, "csr -p 0x%04x=0x%04x\n", key, value);
|
||||
write(fd, buffer, 21);
|
||||
}
|
||||
|
||||
|
||||
static int iphone_write_initscript (void *config, int output){
|
||||
|
||||
// get uart config
|
||||
hci_uart_config_t * uart_config = (hci_uart_config_t *) config;
|
||||
|
||||
// calculate baud rate (assume rate is multiply of 100)
|
||||
uint32_t baud_key = (4096 * (uart_config->baudrate/100) + 4999) / 10000;
|
||||
printf("Baud key %u\n", baud_key);
|
||||
|
||||
// construct script path from device name
|
||||
strcpy(buffer, "/etc/bluetool/");
|
||||
char *machine = get_machine_name();
|
||||
@ -88,7 +103,7 @@ static int iphone_write_initscript (void *config, int output){
|
||||
pos++;
|
||||
}
|
||||
|
||||
// check for "csr -p 0x002a=0x0011" (20)
|
||||
// check for "csr -p 0x1234=0x5678" (20)
|
||||
if (store == 1 && pos == 20) {
|
||||
int pskey, value;
|
||||
store = 0;
|
||||
@ -98,10 +113,8 @@ static int iphone_write_initscript (void *config, int output){
|
||||
case 0x01c1: // Configure H5 mode
|
||||
mirror = 0;
|
||||
break;
|
||||
case 0x01be: // UART Baud
|
||||
// use own settings
|
||||
sprintf(buffer, "csr -p 0x01be=0x01d8\n"); // 115200 for now
|
||||
write(output, buffer, pos+1);
|
||||
case 0x01be: // PSKET_UART_BAUD_RATE
|
||||
iphone_set_pskey(output, 0x01be, baud_key);
|
||||
mirror = 0;
|
||||
break;
|
||||
default:
|
@ -24,7 +24,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
const char *device_name;
|
||||
int baudrate;
|
||||
uint32_t baudrate;
|
||||
int flowcontrol; //
|
||||
} hci_uart_config_t;
|
||||
|
||||
|
@ -24,8 +24,8 @@ hci_con_handle_t con_handle= 0;
|
||||
uint16_t dest_cid;
|
||||
|
||||
void event_handler(uint8_t *packet, int size){
|
||||
// bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
|
||||
bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9}; // MacBook Pro
|
||||
bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
|
||||
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9}; // MacBook Pro
|
||||
|
||||
// printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8);
|
||||
|
||||
@ -110,7 +110,8 @@ int main (int argc, const char * argv[]) {
|
||||
#else
|
||||
// iPhone
|
||||
config.device_name = "/dev/tty.bluetooth";
|
||||
config.baudrate = 115200;
|
||||
// config.baudrate = 115200;
|
||||
config.baudrate = 230400;
|
||||
config.flowcontrol = 1;
|
||||
control = &bt_control_iphone;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user