Release 2.1.4: merge remote-tracking branch 'origin/master' into release
[deb_libcec.git] / src / lib / adapter / RPi / RPiCECAdapterCommunication.h
CommitLineData
29104708
LOK
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
16f47961 5 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
29104708
LOK
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
d1a2ed70 34#include "env.h"
29104708
LOK
35#if defined(HAVE_RPI_API)
36
37#include "lib/adapter/AdapterCommunication.h"
f60ee8b3 38#include "lib/platform/threads/threads.h"
29104708 39
8768aeca
LOK
40#define RPI_ADAPTER_VID 0x2708
41#define RPI_ADAPTER_PID 0x1001
42
29104708
LOK
43extern "C" {
44#include <interface/vmcs_host/vc_cecservice.h>
45#include <interface/vchiq_arm/vchiq_if.h>
46}
47
48namespace CEC
49{
50 class CRPiCECAdapterMessageQueue;
51
52 class CRPiCECAdapterCommunication : public IAdapterCommunication
53 {
54 public:
55 /*!
56 * @brief Create a new USB-CEC communication handler.
57 * @param callback The callback to use for incoming CEC commands.
58 */
59 CRPiCECAdapterCommunication(IAdapterCommunicationCallback *callback);
60 virtual ~CRPiCECAdapterCommunication(void);
61
62 /** @name IAdapterCommunication implementation */
63 ///{
64 bool Open(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT, bool bSkipChecks = false, bool bStartListening = true);
65 void Close(void);
66 bool IsOpen(void) { return m_bInitialised; };
67 std::string GetError(void) const;
68 cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout, bool bIsReply);
69
70 bool SetLineTimeout(uint8_t UNUSED(iTimeout)) { return true; };
71 bool StartBootloader(void) { return false; };
72 bool SetLogicalAddresses(const cec_logical_addresses &addresses);
73 cec_logical_addresses GetLogicalAddresses(void);
74 bool PingAdapter(void) { return m_bInitialised; };
75 uint16_t GetFirmwareVersion(void);
76 uint32_t GetFirmwareBuildDate(void) { return 0; };
77 bool IsRunningLatestFirmware(void) { return true; };
78 bool PersistConfiguration(const libcec_configuration & UNUSED(configuration)) { return false; };
79 bool GetConfiguration(libcec_configuration & UNUSED(configuration)) { return false; };
80 std::string GetPortName(void) { std::string strReturn("RPI"); return strReturn; };
81 uint16_t GetPhysicalAddress(void);
82 bool SetControlledMode(bool UNUSED(controlled)) { return true; };
83 cec_vendor_id GetVendorId(void) { return CEC_VENDOR_BROADCOM; }
84 bool SupportsSourceLogicalAddress(const cec_logical_address address) { return address > CECDEVICE_TV && address < CECDEVICE_BROADCAST; }
2d418322 85 cec_adapter_type GetAdapterType(void) { return ADAPTERTYPE_RPI; };
8768aeca
LOK
86 uint16_t GetAdapterVendorId(void) const { return RPI_ADAPTER_VID; }
87 uint16_t GetAdapterProductId(void) const { return RPI_ADAPTER_PID; }
a582c2bb 88 void SetActiveSource(bool UNUSED(bSetTo), bool UNUSED(bClientUnregistered)) {}
29104708
LOK
89 ///}
90
91 bool IsInitialised(void);
92 void OnDataReceived(uint32_t p0, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
49ba42d4 93 void OnTVServiceCallback(uint32_t reason, uint32_t p0, uint32_t p1);
29104708
LOK
94
95 static void InitHost(void);
96
97 private:
98 cec_logical_address GetLogicalAddress(void);
99 bool UnregisterLogicalAddress(void);
100 bool RegisterLogicalAddress(const cec_logical_address address);
101 int InitHostCEC(void);
102
103 bool m_bInitialised; /**< true when the connection is initialised, false otherwise */
104 std::string m_strError; /**< current error message */
105 CRPiCECAdapterMessageQueue *m_queue;
106 cec_logical_address m_logicalAddress;
107
108 bool m_bLogicalAddressChanged;
109 PLATFORM::CCondition<bool> m_logicalAddressCondition;
110 PLATFORM::CMutex m_mutex;
111 VCHI_INSTANCE_T m_vchi_instance;
112 VCHI_CONNECTION_T * m_vchi_connection;
d1a2ed70 113 cec_logical_address m_previousLogicalAddress;
057497c6 114 bool m_bLogicalAddressRegistered;
29104708
LOK
115 };
116};
117
118#endif