| 1 | #pragma once |
| 2 | /* |
| 3 | * This file is part of the libCEC(R) library. |
| 4 | * |
| 5 | * libCEC(R) is Copyright (C) 2011-2012 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 | #ifndef __WINDOWS__ |
| 38 | #include <termios.h> |
| 39 | #endif |
| 40 | |
| 41 | namespace PLATFORM |
| 42 | { |
| 43 | static struct sbaudrate |
| 44 | { |
| 45 | int32_t rate; |
| 46 | int32_t symbol; |
| 47 | } |
| 48 | |
| 49 | baudrates[] = |
| 50 | { |
| 51 | #ifdef B50 |
| 52 | { 50, B50 }, |
| 53 | #endif |
| 54 | #ifdef B75 |
| 55 | { 75, B75 }, |
| 56 | #endif |
| 57 | #ifdef B110 |
| 58 | { 110, B110 }, |
| 59 | #endif |
| 60 | #ifdef B134 |
| 61 | { 134, B134 }, |
| 62 | #endif |
| 63 | #ifdef B150 |
| 64 | { 150, B150 }, |
| 65 | #endif |
| 66 | #ifdef B200 |
| 67 | { 200, B200 }, |
| 68 | #endif |
| 69 | #ifdef B300 |
| 70 | { 300, B300 }, |
| 71 | #endif |
| 72 | #ifdef B600 |
| 73 | { 600, B600 }, |
| 74 | #endif |
| 75 | #ifdef B1200 |
| 76 | { 1200, B1200 }, |
| 77 | #endif |
| 78 | #ifdef B1800 |
| 79 | { 1800, B1800 }, |
| 80 | #endif |
| 81 | #ifdef B2400 |
| 82 | { 2400, B2400 }, |
| 83 | #endif |
| 84 | #ifdef B4800 |
| 85 | { 4800, B4800 }, |
| 86 | #endif |
| 87 | #ifdef B9600 |
| 88 | { 9600, B9600 }, |
| 89 | #endif |
| 90 | #ifdef B14400 |
| 91 | { 14400, B14400 }, |
| 92 | #endif |
| 93 | #ifdef B19200 |
| 94 | { 19200, B19200 }, |
| 95 | #endif |
| 96 | #ifdef B28800 |
| 97 | { 28800, B28800 }, |
| 98 | #endif |
| 99 | #ifdef B38400 |
| 100 | { 38400, B38400 }, |
| 101 | #endif |
| 102 | #ifdef B57600 |
| 103 | { 57600, B57600 }, |
| 104 | #endif |
| 105 | #ifdef B76800 |
| 106 | { 76800, B76800 }, |
| 107 | #endif |
| 108 | #ifdef B115200 |
| 109 | { 115200, B115200 }, |
| 110 | #endif |
| 111 | #ifdef B230400 |
| 112 | { 230400, B230400 }, |
| 113 | #endif |
| 114 | #ifdef B250000 |
| 115 | { 250000, B250000 }, |
| 116 | #endif |
| 117 | #ifdef B460800 |
| 118 | { 460800, B460800 }, |
| 119 | #endif |
| 120 | #ifdef B500000 |
| 121 | { 500000, B500000 }, |
| 122 | #endif |
| 123 | #ifdef B576000 |
| 124 | { 576000, B576000 }, |
| 125 | #endif |
| 126 | #ifdef B921600 |
| 127 | { 921600, B921600 }, |
| 128 | #endif |
| 129 | #ifdef B1000000 |
| 130 | { 1000000, B1000000 }, |
| 131 | #endif |
| 132 | #ifdef B1152000 |
| 133 | { 1152000, B1152000 }, |
| 134 | #endif |
| 135 | #ifdef B1500000 |
| 136 | { 1500000, B1500000 }, |
| 137 | #endif |
| 138 | #ifdef B2000000 |
| 139 | { 2000000, B2000000 }, |
| 140 | #endif |
| 141 | #ifdef B2500000 |
| 142 | { 2500000, B2500000 }, |
| 143 | #endif |
| 144 | #ifdef B3000000 |
| 145 | { 3000000, B3000000 }, |
| 146 | #endif |
| 147 | #ifdef B3500000 |
| 148 | { 3500000, B3500000 }, |
| 149 | #endif |
| 150 | #ifdef B4000000 |
| 151 | { 4000000, B4000000 }, |
| 152 | #endif |
| 153 | #ifdef CBR_110 |
| 154 | { 110, CBR_110 }, |
| 155 | #endif |
| 156 | #ifdef CBR_300 |
| 157 | { 300, CBR_300 }, |
| 158 | #endif |
| 159 | #ifdef CBR_600 |
| 160 | { 600, CBR_600 }, |
| 161 | #endif |
| 162 | #ifdef CBR_1200 |
| 163 | { 1200, CBR_1200 }, |
| 164 | #endif |
| 165 | #ifdef CBR_2400 |
| 166 | { 2400, CBR_2400 }, |
| 167 | #endif |
| 168 | #ifdef CBR_4800 |
| 169 | { 4800, CBR_4800 }, |
| 170 | #endif |
| 171 | #ifdef CBR_9600 |
| 172 | { 9600, CBR_9600 }, |
| 173 | #endif |
| 174 | #ifdef CBR_11400 |
| 175 | { 11400, CBR_14400 }, |
| 176 | #endif |
| 177 | #ifdef CBR_19200 |
| 178 | { 19200, CBR_19200 }, |
| 179 | #endif |
| 180 | #ifdef CBR_38400 |
| 181 | { 38400, CBR_38400 }, |
| 182 | #endif |
| 183 | #ifdef CBR_56000 |
| 184 | { 56000, CBR_56000 }, |
| 185 | #endif |
| 186 | #ifdef CBR_57600 |
| 187 | { 57600, CBR_57600 }, |
| 188 | #endif |
| 189 | #ifdef CBR_115200 |
| 190 | { 115200, CBR_115200 }, |
| 191 | #endif |
| 192 | #ifdef CBR_128000 |
| 193 | { 128000, CBR_128000 }, |
| 194 | #endif |
| 195 | #ifdef CBR_256000 |
| 196 | { 256000, CBR_256000 }, |
| 197 | #endif |
| 198 | { -1, -1} |
| 199 | }; |
| 200 | |
| 201 | inline int32_t IntToBaudrate(uint32_t baudrate) |
| 202 | { |
| 203 | for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(PLATFORM::sbaudrate) - 1; i++) |
| 204 | { |
| 205 | if (baudrates[i].rate == (int32_t) baudrate) |
| 206 | return baudrates[i].symbol; |
| 207 | } |
| 208 | |
| 209 | return -1; |
| 210 | }; |
| 211 | }; |