mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-20 18:40:31 +00:00
windows: support set_flowcontrol
This commit is contained in:
parent
79d9f1ed77
commit
6ae5f6886d
@ -229,6 +229,19 @@ static void btstack_uart_windows_receive_block(uint8_t *buffer, uint16_t len){
|
||||
btstack_run_loop_enable_data_source_callbacks(&transport_data_source_read, DATA_SOURCE_CALLBACK_READ);
|
||||
}
|
||||
|
||||
static void btstack_uart_windows_set_baudrate_option(DCB * serial_params, uint32_t baudrate){
|
||||
serial_params->BaudRate = baudrate;
|
||||
}
|
||||
|
||||
static void btstack_uart_windows_set_parity_option(DCB * serial_params, uint32_t parity){
|
||||
serial_params->Parity = baudrate;
|
||||
}
|
||||
|
||||
static void btstack_uart_windows_set_flowcontrol_option(DCB * serial_params, uint32_t flowcontrol){
|
||||
// Flowcontrol
|
||||
serial_params->fOutxCtsFlow = flowcontrol;
|
||||
serial_params->fRtsControl = flowcontrol ? RTS_CONTROL_HANDSHAKE : 0;
|
||||
}
|
||||
|
||||
static int btstack_uart_windows_set_baudrate(uint32_t baudrate){
|
||||
DCB serial_params;
|
||||
@ -236,14 +249,11 @@ static int btstack_uart_windows_set_baudrate(uint32_t baudrate){
|
||||
serial_params.DCBlength = sizeof(DCB);
|
||||
|
||||
int ok = GetCommState(serial_port_handle, &serial_params);
|
||||
|
||||
if (!ok){
|
||||
log_error("windows_set_baudrate: Couldn't get serial parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
serial_params.BaudRate = baudrate;
|
||||
|
||||
btstack_uart_windows_set_baudrate_option(&serial_params, baudrate);
|
||||
ok = SetCommState(serial_port_handle, &serial_params);
|
||||
if (!ok){
|
||||
log_error("windows_set_baudrate: Couldn't serial parameters");
|
||||
@ -253,21 +263,17 @@ static int btstack_uart_windows_set_baudrate(uint32_t baudrate){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int btstack_uart_windows_set_parity(int parity){
|
||||
DCB serial_params;
|
||||
memset(&serial_params, 0, sizeof(DCB));
|
||||
serial_params.DCBlength = sizeof(DCB);
|
||||
|
||||
int ok = GetCommState(serial_port_handle, &serial_params);
|
||||
|
||||
if (!ok){
|
||||
log_error("windows_set_parity: Couldn't get serial parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
serial_params.Parity = parity;
|
||||
|
||||
btstack_uart_windows_set_parity_option(&serial_params, parity);
|
||||
ok = SetCommState(serial_port_handle, &serial_params);
|
||||
if (!ok){
|
||||
log_error("windows_set_parity: Couldn't serial parameters");
|
||||
@ -276,6 +282,25 @@ static int btstack_uart_windows_set_parity(int parity){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btstack_uart_windows_set_flowcontrol(int flowcontrol){
|
||||
DCB serial_params;
|
||||
memset(&serial_params, 0, sizeof(DCB));
|
||||
serial_params.DCBlength = sizeof(DCB);
|
||||
|
||||
int ok = GetCommState(serial_port_handle, &serial_params);
|
||||
if (!ok){
|
||||
log_error("windows_set_parity: Couldn't get serial parameters");
|
||||
return -1;
|
||||
}
|
||||
btstack_uart_windows_set_flowcontrol_option(&serial_params, flowcontrol);
|
||||
ok = SetCommState(serial_port_handle, &serial_params);
|
||||
if (!ok){
|
||||
log_error("windows_set_flowcontrol: Couldn't serial parameters");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btstack_uart_windows_open(void){
|
||||
|
||||
const char * device_name = uart_config->device_name;
|
||||
@ -334,21 +359,22 @@ static int btstack_uart_windows_open(void){
|
||||
serial_params.StopBits = ONESTOPBIT;
|
||||
serial_params.Parity = NOPARITY;
|
||||
|
||||
// Flowcontrol
|
||||
serial_params.fOutxCtsFlow = flowcontrol;
|
||||
serial_params.fRtsControl = flowcontrol ? RTS_CONTROL_HANDSHAKE : 0;
|
||||
// baudrate
|
||||
btstack_uart_windows_set_baudrate_option(&serial_params, baudrate);
|
||||
|
||||
// flow control
|
||||
btstack_uart_windows_set_flowcontrol_option(&serial_params, flowcontrol);
|
||||
|
||||
// parity none
|
||||
btstack_uart_windows_set_parity_option(&serial_params, 0);
|
||||
|
||||
// commit changes
|
||||
ok = SetCommState(serial_port_handle, &serial_params);
|
||||
if (!ok){
|
||||
log_error("windows_open: Couldn't serial parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// also set baudrate
|
||||
if (btstack_uart_windows_set_baudrate(baudrate) < 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
// setup overlapped structures for async io
|
||||
memset(&overlapped_read, 0, sizeof(overlapped_read));
|
||||
memset(&overlapped_write, 0, sizeof(overlapped_write));
|
||||
@ -408,7 +434,7 @@ static const btstack_uart_block_t btstack_uart_windows = {
|
||||
/* void (*set_block_sent)(void (*handler)(void)); */ &btstack_uart_windows_set_block_sent,
|
||||
/* int (*set_baudrate)(uint32_t baudrate); */ &btstack_uart_windows_set_baudrate,
|
||||
/* int (*set_parity)(int parity); */ &btstack_uart_windows_set_parity,
|
||||
/* int (*set_flowcontrol)(int flowcontrol); */ NULL,
|
||||
/* int (*set_flowcontrol)(int flowcontrol); */ &btstack_uart_windows_set_flowcontrol,
|
||||
/* void (*receive_block)(uint8_t *buffer, uint16_t len); */ &btstack_uart_windows_receive_block,
|
||||
/* void (*send_block)(const uint8_t *buffer, uint16_t length); */ &btstack_uart_windows_send_block,
|
||||
/* int (*get_supported_sleep_modes); */ NULL,
|
||||
|
Loading…
x
Reference in New Issue
Block a user