cec: handle CEC_OPCODE_ACTIVE_SOURCE
[deb_libcec.git] / src / lib / platform / baudrate.h
1 #pragma once
2 /*
3 * This file is part of the libCEC(R) library.
4 *
5 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
7 *
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 *
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 *
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
27 *
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
32 */
33
34 //every baudrate I could find is in here in an #ifdef block
35 //so it should compile on everything
36
37 #include "os-dependent.h"
38
39 #ifndef __WINDOWS__
40 #include <termios.h>
41 #endif
42
43 namespace CEC
44 {
45 static struct sbaudrate
46 {
47 int32_t rate;
48 int32_t symbol;
49 }
50 baudrates[] =
51 {
52 #ifdef B50
53 { 50, B50 },
54 #endif
55 #ifdef B75
56 { 75, B75 },
57 #endif
58 #ifdef B110
59 { 110, B110 },
60 #endif
61 #ifdef B134
62 { 134, B134 },
63 #endif
64 #ifdef B150
65 { 150, B150 },
66 #endif
67 #ifdef B200
68 { 200, B200 },
69 #endif
70 #ifdef B300
71 { 300, B300 },
72 #endif
73 #ifdef B600
74 { 600, B600 },
75 #endif
76 #ifdef B1200
77 { 1200, B1200 },
78 #endif
79 #ifdef B1800
80 { 1800, B1800 },
81 #endif
82 #ifdef B2400
83 { 2400, B2400 },
84 #endif
85 #ifdef B4800
86 { 4800, B4800 },
87 #endif
88 #ifdef B9600
89 { 9600, B9600 },
90 #endif
91 #ifdef B14400
92 { 14400, B14400 },
93 #endif
94 #ifdef B19200
95 { 19200, B19200 },
96 #endif
97 #ifdef B28800
98 { 28800, B28800 },
99 #endif
100 #ifdef B38400
101 { 38400, B38400 },
102 #endif
103 #ifdef B57600
104 { 57600, B57600 },
105 #endif
106 #ifdef B76800
107 { 76800, B76800 },
108 #endif
109 #ifdef B115200
110 { 115200, B115200 },
111 #endif
112 #ifdef B230400
113 { 230400, B230400 },
114 #endif
115 #ifdef B250000
116 { 250000, B250000 },
117 #endif
118 #ifdef B460800
119 { 460800, B460800 },
120 #endif
121 #ifdef B500000
122 { 500000, B500000 },
123 #endif
124 #ifdef B576000
125 { 576000, B576000 },
126 #endif
127 #ifdef B921600
128 { 921600, B921600 },
129 #endif
130 #ifdef B1000000
131 { 1000000, B1000000 },
132 #endif
133 #ifdef B1152000
134 { 1152000, B1152000 },
135 #endif
136 #ifdef B1500000
137 { 1500000, B1500000 },
138 #endif
139 #ifdef B2000000
140 { 2000000, B2000000 },
141 #endif
142 #ifdef B2500000
143 { 2500000, B2500000 },
144 #endif
145 #ifdef B3000000
146 { 3000000, B3000000 },
147 #endif
148 #ifdef B3500000
149 { 3500000, B3500000 },
150 #endif
151 #ifdef B4000000
152 { 4000000, B4000000 },
153 #endif
154 #ifdef CBR_110
155 { 110, CBR_110 },
156 #endif
157 #ifdef CBR_300
158 { 300, CBR_300 },
159 #endif
160 #ifdef CBR_600
161 { 600, CBR_600 },
162 #endif
163 #ifdef CBR_1200
164 { 1200, CBR_1200 },
165 #endif
166 #ifdef CBR_2400
167 { 2400, CBR_2400 },
168 #endif
169 #ifdef CBR_4800
170 { 4800, CBR_4800 },
171 #endif
172 #ifdef CBR_9600
173 { 9600, CBR_9600 },
174 #endif
175 #ifdef CBR_11400
176 { 11400, CBR_14400 },
177 #endif
178 #ifdef CBR_19200
179 { 19200, CBR_19200 },
180 #endif
181 #ifdef CBR_38400
182 { 38400, CBR_38400 },
183 #endif
184 #ifdef CBR_56000
185 { 56000, CBR_56000 },
186 #endif
187 #ifdef CBR_57600
188 { 57600, CBR_57600 },
189 #endif
190 #ifdef CBR_115200
191 { 115200, CBR_115200 },
192 #endif
193 #ifdef CBR_128000
194 { 128000, CBR_128000 },
195 #endif
196 #ifdef CBR_256000
197 { 256000, CBR_256000 },
198 #endif
199 { -1, -1}
200 };
201
202 static int32_t IntToBaudrate(uint32_t baudrate)
203 {
204 for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(CEC::sbaudrate) - 1; i++)
205 {
206 if (baudrates[i].rate == (int32_t) baudrate)
207 return baudrates[i].symbol;
208 }
209
210 return -1;
211 };
212 };