This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
serial_common.c
145 lines (130 loc) · 4.93 KB
/
serial_common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
stmflasher - Open Source ST MCU flash program for *nix
Copyright (C) 2010 Geoffrey McRae <[email protected]>
Copyright (C) 2011 Steve Markgraf <[email protected]>
Copyright (C) 2012 Tormod Volden
Copyright (C) 2012-2013 Alatar <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "serial.h"
serial_baud_t serial_get_baud(const unsigned int baud) {
switch(baud) {
case 50: return SERIAL_BAUD_50 ;
case 75: return SERIAL_BAUD_75 ;
case 110: return SERIAL_BAUD_110 ;
case 134: return SERIAL_BAUD_134 ;
case 150: return SERIAL_BAUD_150 ;
case 200: return SERIAL_BAUD_200 ;
case 300: return SERIAL_BAUD_300 ;
case 600: return SERIAL_BAUD_600 ;
case 1200: return SERIAL_BAUD_1200 ;
case 1800: return SERIAL_BAUD_1800 ;
case 2400: return SERIAL_BAUD_2400 ;
case 4800: return SERIAL_BAUD_4800 ;
case 7200: return SERIAL_BAUD_7200 ;
case 9600: return SERIAL_BAUD_9600 ;
case 14400: return SERIAL_BAUD_14400 ;
case 19200: return SERIAL_BAUD_19200 ;
case 38400: return SERIAL_BAUD_38400 ;
case 57600: return SERIAL_BAUD_57600 ;
case 76800: return SERIAL_BAUD_76800 ;
case 115200: return SERIAL_BAUD_115200 ;
case 128000: return SERIAL_BAUD_128000 ;
case 230400: return SERIAL_BAUD_230400 ;
case 256000: return SERIAL_BAUD_256000 ;
case 460800: return SERIAL_BAUD_460800 ;
case 500000: return SERIAL_BAUD_500000 ;
case 576000: return SERIAL_BAUD_576000 ;
case 921600: return SERIAL_BAUD_921600 ;
case 1000000: return SERIAL_BAUD_1000000;
case 1152000: return SERIAL_BAUD_1152000;
case 1500000: return SERIAL_BAUD_1500000;
case 2000000: return SERIAL_BAUD_2000000;
case 2500000: return SERIAL_BAUD_2500000;
case 3000000: return SERIAL_BAUD_3000000;
case 3500000: return SERIAL_BAUD_3500000;
case 4000000: return SERIAL_BAUD_4000000;
default:
return SERIAL_BAUD_INVALID;
}
}
const unsigned int serial_get_baud_int(const serial_baud_t baud) {
switch(baud) {
case SERIAL_BAUD_50 : return 50;
case SERIAL_BAUD_75 : return 75;
case SERIAL_BAUD_110 : return 110;
case SERIAL_BAUD_134 : return 134;
case SERIAL_BAUD_150 : return 150;
case SERIAL_BAUD_200 : return 200;
case SERIAL_BAUD_300 : return 300;
case SERIAL_BAUD_600 : return 600;
case SERIAL_BAUD_1200 : return 1200;
case SERIAL_BAUD_1800 : return 1800;
case SERIAL_BAUD_2400 : return 2400;
case SERIAL_BAUD_4800 : return 4800;
case SERIAL_BAUD_7200 : return 7200;
case SERIAL_BAUD_9600 : return 9600;
case SERIAL_BAUD_14400 : return 14400;
case SERIAL_BAUD_19200 : return 19200;
case SERIAL_BAUD_28800 : return 28800;
case SERIAL_BAUD_38400 : return 38400;
case SERIAL_BAUD_57600 : return 57600;
case SERIAL_BAUD_76800 : return 76800;
case SERIAL_BAUD_115200 : return 115200;
case SERIAL_BAUD_128000 : return 128000;
case SERIAL_BAUD_230400 : return 230400;
case SERIAL_BAUD_256000 : return 256000;
case SERIAL_BAUD_460800 : return 460800;
case SERIAL_BAUD_500000 : return 500000;
case SERIAL_BAUD_576000 : return 576000;
case SERIAL_BAUD_921600 : return 921600;
case SERIAL_BAUD_1000000: return 1000000;
case SERIAL_BAUD_1152000: return 1152000;
case SERIAL_BAUD_1500000: return 1500000;
case SERIAL_BAUD_2000000: return 2000000;
case SERIAL_BAUD_2500000: return 2500000;
case SERIAL_BAUD_3000000: return 3000000;
case SERIAL_BAUD_3500000: return 3500000;
case SERIAL_BAUD_4000000: return 4000000;
case SERIAL_BAUD_INVALID:
default:
return 0;
}
}
const unsigned int serial_get_bits_int(const serial_bits_t bits) {
switch(bits) {
case SERIAL_BITS_5: return 5;
case SERIAL_BITS_6: return 6;
case SERIAL_BITS_7: return 7;
case SERIAL_BITS_8: return 8;
default:
return 0;
}
}
const char serial_get_parity_str(const serial_parity_t parity) {
switch(parity) {
case SERIAL_PARITY_NONE: return 'N';
case SERIAL_PARITY_EVEN: return 'E';
case SERIAL_PARITY_ODD : return 'O';
default:
return ' ';
}
}
const unsigned int serial_get_stopbit_int(const serial_stopbit_t stopbit) {
switch(stopbit) {
case SERIAL_STOPBIT_1: return 1;
case SERIAL_STOPBIT_2: return 2;
default:
return 0;
}
}