extend valid baudrates
also use a single table for baudrates and baudspeedbits, so it's easier to update Closes: https://git.iem.at/pd/comport/-/issues/8
This commit is contained in:
parent
56df49f8a5
commit
53f49d7004
1 changed files with 84 additions and 55 deletions
139
comport.c
139
comport.c
|
|
@ -171,58 +171,85 @@ static long baudspeedbittable[] =
|
||||||
#define BAUDRATE_38400 B38400
|
#define BAUDRATE_38400 B38400
|
||||||
#endif /* else IRIX */
|
#endif /* else IRIX */
|
||||||
|
|
||||||
|
typedef struct baudbits_ {
|
||||||
|
long rate;
|
||||||
|
long speedbits;
|
||||||
|
} baudbits_t;
|
||||||
|
|
||||||
static
|
static
|
||||||
long baudspeedbittable[] =
|
baudbits_t baudbitstable[] = {
|
||||||
{
|
#ifdef B4000000
|
||||||
BAUDRATE_230400,
|
{4000000, B4000000},
|
||||||
BAUDRATE_115200, /* CPU SPECIFIC */
|
#endif
|
||||||
BAUDRATE_57600, /* CPU SPECIFIC */
|
#ifdef B3500000
|
||||||
BAUDRATE_38400, /* CPU SPECIFIC */
|
{3500000, B3500000},
|
||||||
B19200,
|
#endif
|
||||||
B9600,
|
#ifdef B3000000
|
||||||
B4800,
|
{3000000, B3000000},
|
||||||
B2400,
|
#endif
|
||||||
B1800,
|
#ifdef B2500000
|
||||||
B1200,
|
{2500000, B2500000},
|
||||||
B600,
|
#endif
|
||||||
B300,
|
#ifdef B2000000
|
||||||
B200,
|
{2000000, B2000000},
|
||||||
B150,
|
#endif
|
||||||
B134,
|
#ifdef B1500000
|
||||||
B110,
|
{1500000, B1500000},
|
||||||
B75,
|
#endif
|
||||||
B50,
|
#ifdef B1152000
|
||||||
B0
|
{1152000, B1152000},
|
||||||
|
#endif
|
||||||
|
#ifdef B1000000
|
||||||
|
{1000000, B1000000},
|
||||||
|
#endif
|
||||||
|
#ifdef B921600
|
||||||
|
{921600, B921600},
|
||||||
|
#endif
|
||||||
|
#ifdef B576000
|
||||||
|
{576000, B576000},
|
||||||
|
#endif
|
||||||
|
#ifdef B500000
|
||||||
|
{500000, B500000},
|
||||||
|
#endif
|
||||||
|
#ifdef B460800
|
||||||
|
{460800, B460800},
|
||||||
|
#endif
|
||||||
|
#ifdef B230400
|
||||||
|
{230400, B230400},
|
||||||
|
#else
|
||||||
|
/* previously, this was supported without an #ifdef */
|
||||||
|
# warning baudrate 230400 not supported (anymore)?
|
||||||
|
#endif
|
||||||
|
#ifdef B115200
|
||||||
|
{115200, B115200},
|
||||||
|
#endif
|
||||||
|
#ifdef B57600
|
||||||
|
{57600, B57600},
|
||||||
|
#endif
|
||||||
|
#ifdef B38400
|
||||||
|
{38400, B38400},
|
||||||
|
#endif
|
||||||
|
{19200, B19200},
|
||||||
|
{9600, B9600},
|
||||||
|
{4800, B4800},
|
||||||
|
{2400, B2400},
|
||||||
|
{1800, B1800},
|
||||||
|
{1200, B1200},
|
||||||
|
{600, B600},
|
||||||
|
{300, B300},
|
||||||
|
{200, B200},
|
||||||
|
{150, B150},
|
||||||
|
{134, B134},
|
||||||
|
{110, B110},
|
||||||
|
{75, B75},
|
||||||
|
{50, B50},
|
||||||
|
{0, B0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct timeval null_tv;
|
struct timeval null_tv;
|
||||||
|
|
||||||
#define BAUDRATETABLE_LEN 19
|
|
||||||
|
|
||||||
static long baudratetable[] =
|
|
||||||
{
|
|
||||||
230400L,
|
|
||||||
115200L,
|
|
||||||
57600L,
|
|
||||||
38400L,
|
|
||||||
19200L,
|
|
||||||
9600L,
|
|
||||||
4800L,
|
|
||||||
2400L,
|
|
||||||
1800L,
|
|
||||||
1200L,
|
|
||||||
600L,
|
|
||||||
300L,
|
|
||||||
200L,
|
|
||||||
150L,
|
|
||||||
134L,
|
|
||||||
110L,
|
|
||||||
75L,
|
|
||||||
50L,
|
|
||||||
0L
|
|
||||||
|
|
||||||
}; /* holds the baud rate selections */
|
|
||||||
|
|
||||||
#endif /* else _WIN32 */
|
#endif /* else _WIN32 */
|
||||||
|
|
||||||
/* From man cfsetospeed:
|
/* From man cfsetospeed:
|
||||||
|
|
@ -713,22 +740,24 @@ int comport_get_cts(t_comport *x)
|
||||||
|
|
||||||
static long get_baud_ratebits(t_comport *x, long *baud)
|
static long get_baud_ratebits(t_comport *x, long *baud)
|
||||||
{
|
{
|
||||||
int i = 0;
|
unsigned int i = 0;
|
||||||
|
const unsigned int tablelen = sizeof(baudbitstable) / sizeof(*baudbitstable);
|
||||||
|
|
||||||
while(i < BAUDRATETABLE_LEN && baudratetable[i] > *baud) i++;
|
while(i < tablelen && baudbitstable[i].rate > *baud) i++;
|
||||||
|
|
||||||
if(baudratetable[i] != *baud)
|
if(baudbitstable[i].rate != *baud)
|
||||||
pd_error(x, "[comport]: %ld not valid, using closest value: %ld", *baud, baudratetable[i]);
|
pd_error(x, "[comport]: %ld not valid, using closest value: %ld", *baud, baudbitstable[i].rate);
|
||||||
|
|
||||||
/* nearest Baudrate finding */
|
/* nearest Baudrate finding */
|
||||||
if(i==BAUDRATETABLE_LEN || baudspeedbittable[i] < 0)
|
if(i==tablelen || baudbitstable[i].rate < 0)
|
||||||
{
|
{
|
||||||
pd_error(x, "*Warning* The baud rate %ld is not supported or out of range, using 9600\n",*baud);
|
pd_error(x, "*Warning* The baud rate %ld is not supported or out of range, using 9600\n",*baud);
|
||||||
i = 8;
|
*baud = 9600;
|
||||||
|
return B9600;
|
||||||
}
|
}
|
||||||
*baud = baudratetable[i];
|
|
||||||
|
|
||||||
return baudspeedbittable[i];
|
*baud = baudbitstable[i].rate;
|
||||||
|
return baudbitstable[i].speedbits;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_baudrate(t_comport *x, int ibaud)
|
static int set_baudrate(t_comport *x, int ibaud)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue