vdr  1.7.27
hdffcmd_hdmi.c
Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  * HDFF firmware command interface library
00004  *
00005  * Copyright (C) 2011  Andreas Regel
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the
00019  * Free Software Foundation, Inc.,
00020  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021  *
00022  *********************************************************************/
00023 
00024 #include <stdint.h>
00025 #include <string.h>
00026 #include <sys/ioctl.h>
00027 
00028 #include "hdffcmd.h"
00029 #include "hdffcmd_base.h"
00030 #include "hdffcmd_defs.h"
00031 
00032 
00033 int HdffCmdHdmiSetVideoMode(int OsdDevice, HdffVideoMode_t VideoMode)
00034 {
00035     uint8_t cmdData[8];
00036     BitBuffer_t cmdBuf;
00037     osd_raw_cmd_t osd_cmd;
00038 
00039     BitBuffer_Init(&cmdBuf, cmdData, sizeof(cmdData));
00040     memset(&osd_cmd, 0, sizeof(osd_raw_cmd_t));
00041     osd_cmd.cmd_data = cmdData;
00042     HdffCmdBuildHeader(&cmdBuf, HDFF_MSG_TYPE_COMMAND, HDFF_MSG_GROUP_HDMI,
00043                        HDFF_MSG_HDMI_SET_VIDEO_MODE);
00044     BitBuffer_SetBits(&cmdBuf, 8, VideoMode);
00045     osd_cmd.cmd_len = HdffCmdSetLength(&cmdBuf);
00046     return ioctl(OsdDevice, OSD_RAW_CMD, &osd_cmd);
00047 }
00048 
00049 int HdffCmdHdmiConfigure(int OsdDevice, const HdffHdmiConfig_t * Config)
00050 {
00051     uint8_t cmdData[24];
00052     BitBuffer_t cmdBuf;
00053     osd_raw_cmd_t osd_cmd;
00054     size_t nameLen;
00055     int i;
00056 
00057     BitBuffer_Init(&cmdBuf, cmdData, sizeof(cmdData));
00058     memset(&osd_cmd, 0, sizeof(osd_raw_cmd_t));
00059     osd_cmd.cmd_data = cmdData;
00060     HdffCmdBuildHeader(&cmdBuf, HDFF_MSG_TYPE_COMMAND, HDFF_MSG_GROUP_HDMI,
00061                        HDFF_MSG_HDMI_CONFIGURE);
00062     BitBuffer_SetBits(&cmdBuf, 1, Config->TransmitAudio ? 1 : 0);
00063     BitBuffer_SetBits(&cmdBuf, 1, Config->ForceDviMode ? 1 : 0);
00064     BitBuffer_SetBits(&cmdBuf, 1, Config->CecEnabled ? 1 : 0);
00065     BitBuffer_SetBits(&cmdBuf, 3, Config->VideoModeAdaption);
00066     BitBuffer_SetBits(&cmdBuf, 6, 0); // reserved
00067     nameLen = strlen(Config->CecDeviceName);
00068     if (nameLen > 13)
00069         nameLen = 13;
00070     BitBuffer_SetBits(&cmdBuf, 4, nameLen);
00071     for (i = 0; i < nameLen; i++)
00072         BitBuffer_SetBits(&cmdBuf, 8, Config->CecDeviceName[i]);
00073 
00074     osd_cmd.cmd_len = HdffCmdSetLength(&cmdBuf);
00075     return ioctl(OsdDevice, OSD_RAW_CMD, &osd_cmd);
00076 }
00077 
00078 int HdffCmdHdmiSendCecCommand(int OsdDevice, HdffCecCommand_t Command)
00079 {
00080     uint8_t cmdData[8];
00081     BitBuffer_t cmdBuf;
00082     osd_raw_cmd_t osd_cmd;
00083 
00084     BitBuffer_Init(&cmdBuf, cmdData, sizeof(cmdData));
00085     memset(&osd_cmd, 0, sizeof(osd_raw_cmd_t));
00086     osd_cmd.cmd_data = cmdData;
00087     HdffCmdBuildHeader(&cmdBuf, HDFF_MSG_TYPE_COMMAND, HDFF_MSG_GROUP_HDMI,
00088                        HDFF_MSG_HDMI_SEND_CEC_COMMAND);
00089     BitBuffer_SetBits(&cmdBuf, 8, Command);
00090     osd_cmd.cmd_len = HdffCmdSetLength(&cmdBuf);
00091     return ioctl(OsdDevice, OSD_RAW_CMD, &osd_cmd);
00092 }
00093 
00094 int HdffCmdHdmiSendRawCecCommand(int OsdDevice, uint8_t Destination,
00095                                  uint8_t Opcode, const uint8_t * Operand,
00096                                  uint8_t OperandLength)
00097 {
00098     uint8_t cmdData[24];
00099     BitBuffer_t cmdBuf;
00100     osd_raw_cmd_t osd_cmd;
00101     int i;
00102 
00103     if (OperandLength > 14)
00104         OperandLength = 14;
00105 
00106     BitBuffer_Init(&cmdBuf, cmdData, sizeof(cmdData));
00107     memset(&osd_cmd, 0, sizeof(osd_raw_cmd_t));
00108     osd_cmd.cmd_data = cmdData;
00109     HdffCmdBuildHeader(&cmdBuf, HDFF_MSG_TYPE_COMMAND, HDFF_MSG_GROUP_HDMI,
00110                        HDFF_MSG_HDMI_SEND_RAW_CEC_COMMAND);
00111     BitBuffer_SetBits(&cmdBuf, 4, 0); // reserved
00112     BitBuffer_SetBits(&cmdBuf, 4, Destination);
00113     BitBuffer_SetBits(&cmdBuf, 8, Opcode);
00114     BitBuffer_SetBits(&cmdBuf, 8, OperandLength);
00115     for (i = 0; i < OperandLength; i++)
00116         BitBuffer_SetBits(&cmdBuf, 8, Operand[i]);
00117 
00118     osd_cmd.cmd_len = HdffCmdSetLength(&cmdBuf);
00119     return ioctl(OsdDevice, OSD_RAW_CMD, &osd_cmd);
00120 }