Commit | Line | Data |
---|---|---|
29104708 LOK |
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 | #if defined(HAVE_RPI_API) | |
35 | ||
36 | #include "lib/adapter/AdapterCommunication.h" | |
f60ee8b3 | 37 | #include "lib/platform/threads/threads.h" |
29104708 LOK |
38 | |
39 | extern "C" { | |
40 | #include <interface/vmcs_host/vc_cecservice.h> | |
41 | #include <interface/vchiq_arm/vchiq_if.h> | |
42 | } | |
43 | ||
44 | namespace CEC | |
45 | { | |
46 | class CRPiCECAdapterMessageQueue; | |
f60ee8b3 LOK |
47 | class CRPiCECAdapterCommunication; |
48 | ||
49 | class CRPiCECAdapterFindNewLogicalAddress : public PLATFORM::CThread | |
50 | { | |
51 | public: | |
52 | CRPiCECAdapterFindNewLogicalAddress(CRPiCECAdapterCommunication* communication, const cec_logical_address address); | |
53 | void *Process(void); | |
54 | private: | |
55 | CRPiCECAdapterCommunication* m_communication; | |
56 | cec_logical_address m_address; | |
57 | }; | |
29104708 LOK |
58 | |
59 | class CRPiCECAdapterCommunication : public IAdapterCommunication | |
60 | { | |
f60ee8b3 LOK |
61 | friend class CRPiCECAdapterFindNewLogicalAddress; |
62 | ||
29104708 LOK |
63 | public: |
64 | /*! | |
65 | * @brief Create a new USB-CEC communication handler. | |
66 | * @param callback The callback to use for incoming CEC commands. | |
67 | */ | |
68 | CRPiCECAdapterCommunication(IAdapterCommunicationCallback *callback); | |
69 | virtual ~CRPiCECAdapterCommunication(void); | |
70 | ||
71 | /** @name IAdapterCommunication implementation */ | |
72 | ///{ | |
73 | bool Open(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT, bool bSkipChecks = false, bool bStartListening = true); | |
74 | void Close(void); | |
75 | bool IsOpen(void) { return m_bInitialised; }; | |
76 | std::string GetError(void) const; | |
77 | cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout, bool bIsReply); | |
78 | ||
79 | bool SetLineTimeout(uint8_t UNUSED(iTimeout)) { return true; }; | |
80 | bool StartBootloader(void) { return false; }; | |
81 | bool SetLogicalAddresses(const cec_logical_addresses &addresses); | |
82 | cec_logical_addresses GetLogicalAddresses(void); | |
83 | bool PingAdapter(void) { return m_bInitialised; }; | |
84 | uint16_t GetFirmwareVersion(void); | |
85 | uint32_t GetFirmwareBuildDate(void) { return 0; }; | |
86 | bool IsRunningLatestFirmware(void) { return true; }; | |
87 | bool PersistConfiguration(const libcec_configuration & UNUSED(configuration)) { return false; }; | |
88 | bool GetConfiguration(libcec_configuration & UNUSED(configuration)) { return false; }; | |
89 | std::string GetPortName(void) { std::string strReturn("RPI"); return strReturn; }; | |
90 | uint16_t GetPhysicalAddress(void); | |
91 | bool SetControlledMode(bool UNUSED(controlled)) { return true; }; | |
92 | cec_vendor_id GetVendorId(void) { return CEC_VENDOR_BROADCOM; } | |
93 | bool SupportsSourceLogicalAddress(const cec_logical_address address) { return address > CECDEVICE_TV && address < CECDEVICE_BROADCAST; } | |
2d418322 | 94 | cec_adapter_type GetAdapterType(void) { return ADAPTERTYPE_RPI; }; |
29104708 LOK |
95 | ///} |
96 | ||
97 | bool IsInitialised(void); | |
98 | void OnDataReceived(uint32_t p0, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4); | |
99 | ||
100 | static void InitHost(void); | |
101 | ||
102 | private: | |
103 | cec_logical_address GetLogicalAddress(void); | |
104 | bool UnregisterLogicalAddress(void); | |
105 | bool RegisterLogicalAddress(const cec_logical_address address); | |
106 | int InitHostCEC(void); | |
107 | ||
108 | bool m_bInitialised; /**< true when the connection is initialised, false otherwise */ | |
109 | std::string m_strError; /**< current error message */ | |
110 | CRPiCECAdapterMessageQueue *m_queue; | |
111 | cec_logical_address m_logicalAddress; | |
112 | ||
113 | bool m_bLogicalAddressChanged; | |
114 | PLATFORM::CCondition<bool> m_logicalAddressCondition; | |
115 | PLATFORM::CMutex m_mutex; | |
116 | VCHI_INSTANCE_T m_vchi_instance; | |
117 | VCHI_CONNECTION_T * m_vchi_connection; | |
f60ee8b3 | 118 | CRPiCECAdapterFindNewLogicalAddress* m_laLost; |
29104708 LOK |
119 | }; |
120 | }; | |
121 | ||
122 | #endif |