diff options
author | Manuel Reimer <manuel.reimer@gmx.de> | 2018-02-03 17:18:53 +0100 |
---|---|---|
committer | Manuel Reimer <manuel.reimer@gmx.de> | 2018-02-03 17:18:53 +0100 |
commit | 057856bd2bc642ca855b8be2f7e7a3802a5bd05d (patch) | |
tree | 06df8647560b3731a2dfd40a3c8cd3382deaaae3 | |
parent | 3bbe763488aa84fdf29047b6b38acd11f8274862 (diff) | |
download | graphlcd-base-057856bd2bc642ca855b8be2f7e7a3802a5bd05d.tar.gz graphlcd-base-057856bd2bc642ca855b8be2f7e7a3802a5bd05d.tar.bz2 |
Add variable baud rate for serial speed optimization
-rw-r--r-- | glcddrivers/port.c | 22 | ||||
-rw-r--r-- | glcddrivers/port.h | 20 | ||||
-rw-r--r-- | glcddrivers/usbserlcd.c | 2 |
3 files changed, 36 insertions, 8 deletions
diff --git a/glcddrivers/port.c b/glcddrivers/port.c index 26592c4..2c123e1 100644 --- a/glcddrivers/port.c +++ b/glcddrivers/port.c @@ -373,13 +373,23 @@ int cSerialPort::Close() return 0; } -void cSerialPort::SetBaudRate(speed_t speed) +void cSerialPort::SetBaudRate(int speed) { - struct termios options; - tcgetattr(fd, &options); - cfsetispeed(&options, speed); - cfsetospeed(&options, speed); - tcsetattr(fd, TCSANOW, &options); + struct termios2 tio; + if (ioctl(fd, TCGETS2, &tio) < 0) + { + printf("TCGETS2 ioctl failed!\n"); + return; + } + tio.c_cflag &= ~CBAUD; + tio.c_cflag |= BOTHER; + tio.c_ispeed = speed; + tio.c_ospeed = speed; + if (ioctl(fd, TCSETS2, &tio) < 0) + { + printf("TCSETS2 ioctl failed!\n"); + return; + } } int cSerialPort::ReadData(unsigned char * data) diff --git a/glcddrivers/port.h b/glcddrivers/port.h index ee851c8..fc97293 100644 --- a/glcddrivers/port.h +++ b/glcddrivers/port.h @@ -15,6 +15,24 @@ #include <string> #include <termios.h> +// The following block is copied from "asm/termbits.h" +// Has to be copied as the kernel header file conflicts with glibc termios.h +#define NCCS2 19 +struct termios2 { + tcflag_t c_iflag; /* input mode flags */ + tcflag_t c_oflag; /* output mode flags */ + tcflag_t c_cflag; /* control mode flags */ + tcflag_t c_lflag; /* local mode flags */ + cc_t c_line; /* line discipline */ + cc_t c_cc[NCCS2]; /* control characters */ + speed_t c_ispeed; /* input speed */ + speed_t c_ospeed; /* output speed */ +}; +#define TCGETS2 _IOR('T', 0x2A, struct termios2) +#define TCSETS2 _IOW('T', 0x2B, struct termios2) +#define BOTHER 0010000 + + namespace GLCD { @@ -72,7 +90,7 @@ public: int Open(const char * device); int Close(); - void SetBaudRate(speed_t speed); + void SetBaudRate(int speed); int ReadData(unsigned char * data); void WriteData(unsigned char data); diff --git a/glcddrivers/usbserlcd.c b/glcddrivers/usbserlcd.c index 680a035..47d1e7e 100644 --- a/glcddrivers/usbserlcd.c +++ b/glcddrivers/usbserlcd.c @@ -73,7 +73,7 @@ int cDriverUSBserLCD::Init() if (port->Open(config->device.c_str()) != 0) return -1; - port->SetBaudRate(B115200); + port->SetBaudRate(150000); *oldConfig = *config; |