mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 12:35:25 +00:00
posix: implement set_flowcontrol in btstack_uart_block interface
This commit is contained in:
parent
f71711bb0a
commit
cde6b088be
@ -237,6 +237,50 @@ static int btstack_uart_posix_set_baudrate(uint32_t baudrate){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btstack_uart_posix_set_parity(int parity){
|
||||
|
||||
int fd = transport_data_source.fd;
|
||||
|
||||
struct termios toptions;
|
||||
if (tcgetattr(fd, &toptions) < 0) {
|
||||
log_error("btstack_uart_posix_set_parity: Couldn't get term attributes");
|
||||
return -1;
|
||||
}
|
||||
if (parity){
|
||||
toptions.c_cflag |= PARENB; // enable even parity
|
||||
} else {
|
||||
toptions.c_cflag &= ~PARENB; // disable even parity
|
||||
}
|
||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||
log_error("posix_set_parity: Couldn't set term attributes");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btstack_uart_posix_set_flowcontrol(int flowcontrol){
|
||||
|
||||
int fd = transport_data_source.fd;
|
||||
|
||||
struct termios toptions;
|
||||
if (tcgetattr(fd, &toptions) < 0) {
|
||||
log_error("btstack_uart_posix_set_parity: Couldn't get term attributes");
|
||||
return -1;
|
||||
}
|
||||
if (flowcontrol) {
|
||||
// with flow control
|
||||
toptions.c_cflag |= CRTSCTS;
|
||||
} else {
|
||||
// no flow control
|
||||
toptions.c_cflag &= ~CRTSCTS;
|
||||
}
|
||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||
log_error("posix_set_flowcontrol: Couldn't set term attributes");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btstack_uart_posix_open(void){
|
||||
|
||||
const char * device_name = uart_config->device_name;
|
||||
@ -262,18 +306,6 @@ static int btstack_uart_posix_open(void){
|
||||
toptions.c_cflag &= ~CSTOPB;
|
||||
toptions.c_cflag |= CS8;
|
||||
|
||||
// 8E1
|
||||
// toptions.c_cflag |= PARENB; // enable even parity
|
||||
//
|
||||
|
||||
if (flowcontrol) {
|
||||
// with flow control
|
||||
toptions.c_cflag |= CRTSCTS;
|
||||
} else {
|
||||
// no flow control
|
||||
toptions.c_cflag &= ~CRTSCTS;
|
||||
}
|
||||
|
||||
toptions.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
|
||||
toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl
|
||||
|
||||
@ -294,6 +326,11 @@ static int btstack_uart_posix_open(void){
|
||||
return -1;
|
||||
}
|
||||
|
||||
// also set flow control
|
||||
if (btstack_uart_posix_set_flowcontrol(flowcontrol) < 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
// set up data_source
|
||||
btstack_run_loop_set_data_source_fd(&transport_data_source, fd);
|
||||
btstack_run_loop_set_data_source_handler(&transport_data_source, &hci_transport_h5_process);
|
||||
@ -324,27 +361,6 @@ static void btstack_uart_posix_set_block_sent( void (*block_handler)(void)){
|
||||
block_sent = block_handler;
|
||||
}
|
||||
|
||||
static int btstack_uart_posix_set_parity(int parity){
|
||||
|
||||
int fd = transport_data_source.fd;
|
||||
|
||||
struct termios toptions;
|
||||
if (tcgetattr(fd, &toptions) < 0) {
|
||||
log_error("btstack_uart_posix_set_parity: Couldn't get term attributes");
|
||||
return -1;
|
||||
}
|
||||
if (parity){
|
||||
toptions.c_cflag |= PARENB; // enable even parity
|
||||
} else {
|
||||
toptions.c_cflag &= ~PARENB; // enable even parity
|
||||
}
|
||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||
log_error("posix_set_parity: Couldn't set term attributes");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void btstack_uart_posix_send_block(const uint8_t *data, uint16_t size){
|
||||
// setup async write
|
||||
write_bytes_data = data;
|
||||
@ -377,7 +393,7 @@ static const btstack_uart_block_t btstack_uart_posix = {
|
||||
/* void (*set_block_sent)(void (*handler)(void)); */ &btstack_uart_posix_set_block_sent,
|
||||
/* int (*set_baudrate)(uint32_t baudrate); */ &btstack_uart_posix_set_baudrate,
|
||||
/* int (*set_parity)(int parity); */ &btstack_uart_posix_set_parity,
|
||||
/* int (*set_flowcontrol)(int flowcontrol); */ NULL,
|
||||
/* int (*set_flowcontrol)(int flowcontrol); */ &btstack_uart_posix_set_flowcontrol,
|
||||
/* void (*receive_block)(uint8_t *buffer, uint16_t len); */ &btstack_uart_posix_receive_block,
|
||||
/* void (*send_block)(const uint8_t *buffer, uint16_t length); */ &btstack_uart_posix_send_block,
|
||||
/* int (*get_supported_sleep_modes); */ NULL,
|
||||
|
Loading…
x
Reference in New Issue
Block a user