3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
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/
40 #if !defined(DECLSPEC)
41 #if defined(_WIN32) || defined(_WIN64)
43 #if defined DLL_EXPORT
44 #define DECLSPEC __declspec(dllexport)
46 #define DECLSPEC __declspec(dllimport)
57 #define CEC_MIN_VERSION 6
58 #define CEC_LIB_VERSION 6
59 #define CEC_SETTLE_DOWN_TIME 1000
60 #define CEC_BUTTON_TIMEOUT 500
62 typedef enum cec_user_control_code
64 CEC_USER_CONTROL_CODE_SELECT
= 0x00,
65 CEC_USER_CONTROL_CODE_UP
= 0x01,
66 CEC_USER_CONTROL_CODE_DOWN
= 0x02,
67 CEC_USER_CONTROL_CODE_LEFT
= 0x03,
68 CEC_USER_CONTROL_CODE_RIGHT
= 0x04,
69 CEC_USER_CONTROL_CODE_RIGHT_UP
= 0x05,
70 CEC_USER_CONTROL_CODE_RIGHT_DOWN
= 0x06,
71 CEC_USER_CONTROL_CODE_LEFT_UP
= 0x07,
72 CEC_USER_CONTROL_CODE_LEFT_DOWN
= 0x08,
73 CEC_USER_CONTROL_CODE_ROOT_MENU
= 0x09,
74 CEC_USER_CONTROL_CODE_SETUP_MENU
= 0x0A,
75 CEC_USER_CONTROL_CODE_CONTENTS_MENU
= 0x0B,
76 CEC_USER_CONTROL_CODE_FAVORITE_MENU
= 0x0C,
77 CEC_USER_CONTROL_CODE_EXIT
= 0x0D,
78 CEC_USER_CONTROL_CODE_NUMBER0
= 0x20,
79 CEC_USER_CONTROL_CODE_NUMBER1
= 0x21,
80 CEC_USER_CONTROL_CODE_NUMBER2
= 0x22,
81 CEC_USER_CONTROL_CODE_NUMBER3
= 0x23,
82 CEC_USER_CONTROL_CODE_NUMBER4
= 0x24,
83 CEC_USER_CONTROL_CODE_NUMBER5
= 0x25,
84 CEC_USER_CONTROL_CODE_NUMBER6
= 0x26,
85 CEC_USER_CONTROL_CODE_NUMBER7
= 0x27,
86 CEC_USER_CONTROL_CODE_NUMBER8
= 0x28,
87 CEC_USER_CONTROL_CODE_NUMBER9
= 0x29,
88 CEC_USER_CONTROL_CODE_DOT
= 0x2A,
89 CEC_USER_CONTROL_CODE_ENTER
= 0x2B,
90 CEC_USER_CONTROL_CODE_CLEAR
= 0x2C,
91 CEC_USER_CONTROL_CODE_NEXT_FAVORITE
= 0x2F,
92 CEC_USER_CONTROL_CODE_CHANNEL_UP
= 0x30,
93 CEC_USER_CONTROL_CODE_CHANNEL_DOWN
= 0x31,
94 CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL
= 0x32,
95 CEC_USER_CONTROL_CODE_SOUND_SELECT
= 0x33,
96 CEC_USER_CONTROL_CODE_INPUT_SELECT
= 0x34,
97 CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION
= 0x35,
98 CEC_USER_CONTROL_CODE_HELP
= 0x36,
99 CEC_USER_CONTROL_CODE_PAGE_UP
= 0x37,
100 CEC_USER_CONTROL_CODE_PAGE_DOWN
= 0x38,
101 CEC_USER_CONTROL_CODE_POWER
= 0x40,
102 CEC_USER_CONTROL_CODE_VOLUME_UP
= 0x41,
103 CEC_USER_CONTROL_CODE_VOLUME_DOWN
= 0x42,
104 CEC_USER_CONTROL_CODE_MUTE
= 0x43,
105 CEC_USER_CONTROL_CODE_PLAY
= 0x44,
106 CEC_USER_CONTROL_CODE_STOP
= 0x45,
107 CEC_USER_CONTROL_CODE_PAUSE
= 0x46,
108 CEC_USER_CONTROL_CODE_RECORD
= 0x47,
109 CEC_USER_CONTROL_CODE_REWIND
= 0x48,
110 CEC_USER_CONTROL_CODE_FAST_FORWARD
= 0x49,
111 CEC_USER_CONTROL_CODE_EJECT
= 0x4A,
112 CEC_USER_CONTROL_CODE_FORWARD
= 0x4B,
113 CEC_USER_CONTROL_CODE_BACKWARD
= 0x4C,
114 CEC_USER_CONTROL_CODE_STOP_RECORD
= 0x4D,
115 CEC_USER_CONTROL_CODE_PAUSE_RECORD
= 0x4E,
116 CEC_USER_CONTROL_CODE_ANGLE
= 0x50,
117 CEC_USER_CONTROL_CODE_SUB_PICTURE
= 0x51,
118 CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND
= 0x52,
119 CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE
= 0x53,
120 CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING
= 0x54,
121 CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION
= 0x55,
122 CEC_USER_CONTROL_CODE_PLAY_FUNCTION
= 0x60,
123 CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION
= 0x61,
124 CEC_USER_CONTROL_CODE_RECORD_FUNCTION
= 0x62,
125 CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION
= 0x63,
126 CEC_USER_CONTROL_CODE_STOP_FUNCTION
= 0x64,
127 CEC_USER_CONTROL_CODE_MUTE_FUNCTION
= 0x65,
128 CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION
= 0x66,
129 CEC_USER_CONTROL_CODE_TUNE_FUNCTION
= 0x67,
130 CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION
= 0x68,
131 CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION
= 0x69,
132 CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION
= 0x6A,
133 CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION
= 0x6B,
134 CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION
= 0x6C,
135 CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION
= 0x6D,
136 CEC_USER_CONTROL_CODE_F1_BLUE
= 0x71,
137 CEC_USER_CONTROL_CODE_F2_RED
= 0X72,
138 CEC_USER_CONTROL_CODE_F3_GREEN
= 0x73,
139 CEC_USER_CONTROL_CODE_F4_YELLOW
= 0x74,
140 CEC_USER_CONTROL_CODE_F5
= 0x75,
141 CEC_USER_CONTROL_CODE_DATA
= 0x76,
142 CEC_USER_CONTROL_CODE_MAX
= 0x76,
143 CEC_USER_CONTROL_CODE_UNKNOWN
144 } cec_user_control_code
;
146 typedef enum cec_logical_address
148 CECDEVICE_UNKNOWN
= -1, //not a valid logical address
150 CECDEVICE_RECORDINGDEVICE1
,
151 CECDEVICE_RECORDINGDEVICE2
,
153 CECDEVICE_PLAYBACKDEVICE1
,
154 CECDEVICE_AUDIOSYSTEM
,
157 CECDEVICE_PLAYBACKDEVICE2
,
158 CECDEVICE_RECORDINGDEVICE3
,
160 CECDEVICE_PLAYBACKDEVICE3
,
164 CECDEVICE_UNREGISTERED
= 15,
165 CECDEVICE_BROADCAST
= 15
166 } cec_logical_address
;
168 typedef enum cec_opcode
170 CEC_OPCODE_ACTIVE_SOURCE
= 0x82,
171 CEC_OPCODE_IMAGE_VIEW_ON
= 0x04,
172 CEC_OPCODE_TEXT_VIEW_ON
= 0x0D,
173 CEC_OPCODE_INACTIVE_SOURCE
= 0x9D,
174 CEC_OPCODE_REQUEST_ACTIVE_SOURCE
= 0x85,
175 CEC_OPCODE_ROUTING_CHANGE
= 0x80,
176 CEC_OPCODE_ROUTING_INFORMATION
= 0x81,
177 CEC_OPCODE_SET_STREAM_PATH
= 0x86,
178 CEC_OPCODE_STANDBY
= 0x36,
179 CEC_OPCODE_RECORD_OFF
= 0x0B,
180 CEC_OPCODE_RECORD_ON
= 0x09,
181 CEC_OPCODE_RECORD_STATUS
= 0x0A,
182 CEC_OPCODE_RECORD_TV_SCREEN
= 0x0F,
183 CEC_OPCODE_CLEAR_ANALOGUE_TIMER
= 0x33,
184 CEC_OPCODE_CLEAR_DIGITAL_TIMER
= 0x99,
185 CEC_OPCODE_CLEAR_EXTERNAL_TIMER
= 0xA1,
186 CEC_OPCODE_SET_ANALOGUE_TIMER
= 0x34,
187 CEC_OPCODE_SET_DIGITAL_TIMER
= 0x97,
188 CEC_OPCODE_SET_EXTERNAL_TIMER
= 0xA2,
189 CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
= 0x67,
190 CEC_OPCODE_TIMER_CLEARED_STATUS
= 0x43,
191 CEC_OPCODE_TIMER_STATUS
= 0x35,
192 CEC_OPCODE_CEC_VERSION
= 0x9E,
193 CEC_OPCODE_GET_CEC_VERSION
= 0x9F,
194 CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
= 0x83,
195 CEC_OPCODE_GET_MENU_LANGUAGE
= 0x91,
196 CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
= 0x84,
197 CEC_OPCODE_SET_MENU_LANGUAGE
= 0x32,
198 CEC_OPCODE_DECK_CONTROL
= 0x42,
199 CEC_OPCODE_DECK_STATUS
= 0x1B,
200 CEC_OPCODE_GIVE_DECK_STATUS
= 0x1A,
201 CEC_OPCODE_PLAY
= 0x41,
202 CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
= 0x08,
203 CEC_OPCODE_SELECT_ANALOGUE_SERVICE
= 0x92,
204 CEC_OPCODE_SELECT_DIGITAL_SERVICE
= 0x93,
205 CEC_OPCODE_TUNER_DEVICE_STATUS
= 0x07,
206 CEC_OPCODE_TUNER_STEP_DECREMENT
= 0x06,
207 CEC_OPCODE_TUNER_STEP_INCREMENT
= 0x05,
208 CEC_OPCODE_DEVICE_VENDOR_ID
= 0x87,
209 CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
= 0x8C,
210 CEC_OPCODE_VENDOR_COMMAND
= 0x89,
211 CEC_OPCODE_VENDOR_COMMAND_WITH_ID
= 0xA0,
212 CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
= 0x8A,
213 CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
= 0x8B,
214 CEC_OPCODE_SET_OSD_STRING
= 0x64,
215 CEC_OPCODE_GIVE_OSD_NAME
= 0x46,
216 CEC_OPCODE_SET_OSD_NAME
= 0x47,
217 CEC_OPCODE_MENU_REQUEST
= 0x8D,
218 CEC_OPCODE_MENU_STATUS
= 0x8E,
219 CEC_OPCODE_USER_CONTROL_PRESSED
= 0x44,
220 CEC_OPCODE_USER_CONTROL_RELEASE
= 0x45,
221 CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
= 0x8F,
222 CEC_OPCODE_REPORT_POWER_STATUS
= 0x90,
223 CEC_OPCODE_FEATURE_ABORT
= 0x00,
224 CEC_OPCODE_ABORT
= 0xFF,
225 CEC_OPCODE_GIVE_AUDIO_STATUS
= 0x71,
226 CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
= 0x7D,
227 CEC_OPCODE_REPORT_AUDIO_STATUS
= 0x7A,
228 CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
= 0x72,
229 CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
= 0x70,
230 CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
= 0x7E,
231 CEC_OPCODE_SET_AUDIO_RATE
= 0x9A
234 typedef enum cec_log_level
242 typedef struct cec_log_message
249 typedef struct cec_keypress
251 cec_user_control_code keycode
;
252 unsigned int duration
;
255 typedef struct cec_adapter
261 typedef enum cec_adapter_messagecode
265 MSGCODE_TIMEOUT_ERROR
,
270 MSGCODE_RECEIVE_FAILED
,
271 MSGCODE_COMMAND_ACCEPTED
,
272 MSGCODE_COMMAND_REJECTED
,
273 MSGCODE_SET_ACK_MASK
,
275 MSGCODE_TRANSMIT_EOM
,
276 MSGCODE_TRANSMIT_IDLETIME
,
277 MSGCODE_TRANSMIT_ACK_POLARITY
,
278 MSGCODE_TRANSMIT_LINE_TIMEOUT
,
279 MSGCODE_TRANSMIT_SUCCEEDED
,
280 MSGCODE_TRANSMIT_FAILED_LINE
,
281 MSGCODE_TRANSMIT_FAILED_ACK
,
282 MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA
,
283 MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE
,
284 MSGCODE_FIRMWARE_VERSION
,
285 MSGCODE_START_BOOTLOADER
,
286 MSGCODE_FRAME_EOM
= 0x80,
287 MSGCODE_FRAME_ACK
= 0x40,
288 } cec_adapter_messagecode
;
290 typedef struct cec_datapacket
295 bool empty(void) const { return size
== 0; }
296 bool full(void) const { return size
== 100; }
297 uint8_t operator[](uint8_t pos
) const { return pos
< size
? data
[pos
] : 0; }
298 uint8_t at(uint8_t pos
) const { return pos
< size
? data
[pos
] : 0; }
300 void shift(uint8_t iShiftBy
)
302 if (iShiftBy
>= size
)
308 for (uint8_t iPtr
= 0; iPtr
< size
; iPtr
++)
309 data
[iPtr
] = (iPtr
+ iShiftBy
< size
) ? data
[iPtr
+ iShiftBy
] : 0;
310 size
= (uint8_t) (size
- iShiftBy
);
314 void push_back(uint8_t add
)
322 memset(data
, 0, sizeof(data
));
328 typedef struct cec_adapter_message
330 cec_datapacket packet
;
332 bool empty(void) const { return packet
.empty(); }
333 uint8_t operator[](uint8_t pos
) const { return packet
[pos
]; }
334 uint8_t at(uint8_t pos
) const { return packet
[pos
]; }
335 uint8_t size(void) const { return packet
.size
; }
336 void clear(void) { packet
.clear(); }
337 void shift(uint8_t iShiftBy
) { packet
.shift(iShiftBy
); }
338 void push_back(uint8_t add
) { packet
.push_back(add
); }
339 cec_adapter_messagecode
message(void) const { return packet
.size
>= 1 ? (cec_adapter_messagecode
) (packet
.at(0) & ~(MSGCODE_FRAME_EOM
| MSGCODE_FRAME_ACK
)) : MSGCODE_NOTHING
; }
340 bool eom(void) const { return packet
.size
>= 1 ? (packet
.at(0) & MSGCODE_FRAME_EOM
) != 0 : false; }
341 bool ack(void) const { return packet
.size
>= 1 ? (packet
.at(0) & MSGCODE_FRAME_ACK
) != 0 : false; }
342 cec_logical_address
initiator(void) const { return packet
.size
>= 2 ? (cec_logical_address
) (packet
.at(1) >> 4) : CECDEVICE_UNKNOWN
; };
343 cec_logical_address
destination(void) const { return packet
.size
>= 2 ? (cec_logical_address
) (packet
.at(1) & 0xF) : CECDEVICE_UNKNOWN
; };
344 } cec_adapter_message
;
346 typedef struct cec_command
348 cec_logical_address initiator
;
349 cec_logical_address destination
;
353 cec_datapacket parameters
;
356 static void format(cec_command
&command
, cec_logical_address initiator
, cec_logical_address destination
, cec_opcode opcode
)
359 command
.initiator
= initiator
;
360 command
.destination
= destination
;
361 command
.opcode
= opcode
;
362 command
.opcode_set
= true;
365 void push_back(uint8_t data
)
370 opcode
= (cec_opcode
) data
;
373 parameters
.push_back(data
);
378 initiator
= CECDEVICE_UNKNOWN
;
379 destination
= CECDEVICE_UNKNOWN
;
383 opcode
= CEC_OPCODE_FEATURE_ABORT
;
388 typedef enum cec_vendor_id
390 CEC_VENDOR_SAMSUNG
= 240,
391 CEC_VENDOR_UNKNOWN
= 0
394 static const char *CECVendorIdToString(const uint64_t iVendorId
)
398 case CEC_VENDOR_SAMSUNG
:
405 //default physical address 1.0.0.0
406 #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000
411 #include "CECExportsCpp.h"
412 #include "CECExportsC.h"
415 #include "CECExportsC.h"
418 #endif /* CECEXPORTS_H_ */