1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SYSTEM_PERIPHERALMANAGER_DAEMON_PERIPHERAL_MANAGER_CLIENT_H_
#define SYSTEM_PERIPHERALMANAGER_DAEMON_PERIPHERAL_MANAGER_CLIENT_H_
#include <map>
#include <memory>
#include <string>
#include <base/macros.h>
#include <android/os/BnPeripheralManagerClient.h>
#include "gpio_manager.h"
#include "i2c_manager.h"
#include "led_manager.h"
#include "spi_manager.h"
using android::binder::Status;
using android::os::BnPeripheralManagerClient;
namespace android {
class PeripheralManagerClient : public BnPeripheralManagerClient {
public:
PeripheralManagerClient();
~PeripheralManagerClient();
// Gpio functions.
virtual Status ListGpio(std::vector<std::string>* gpios) override;
virtual Status OpenGpio(const std::string& name) override;
virtual Status ReleaseGpio(const std::string& name) override;
virtual Status SetGpioEdge(const std::string& name, int type) override;
virtual Status SetGpioActiveType(const std::string& name, int type) override;
virtual Status SetGpioDirection(const std::string& name,
int direction) override;
virtual Status SetGpioValue(const std::string& name, bool value) override;
virtual Status GetGpioValue(const std::string& name, bool* value) override;
virtual Status GetGpioPollingFd(const std::string& name,
::android::base::unique_fd* fd) override;
// Spi functions.
virtual Status ListSpiBuses(std::vector<std::string>* buses) override;
virtual Status OpenSpiDevice(const std::string& name) override;
virtual Status ReleaseSpiDevice(const std::string& name) override;
virtual Status SpiDeviceWriteByte(const std::string& name,
int8_t byte) override;
virtual Status SpiDeviceWriteBuffer(
const std::string& name,
const std::vector<uint8_t>& buffer) override;
virtual Status SpiDeviceTransfer(
const std::string& name,
const std::unique_ptr<std::vector<uint8_t>>& tx_data,
std::unique_ptr<std::vector<uint8_t>>* rx_data,
int len) override;
virtual Status SpiDeviceSetMode(const std::string& name, int mode) override;
virtual Status SpiDeviceSetFrequency(const std::string& name,
int frequency_hz) override;
virtual Status SpiDeviceSetBitJustification(const std::string& name,
bool lsb_first) override;
virtual Status SpiDeviceSetBitsPerWord(const std::string& name,
int nbits) override;
virtual Status SpiDeviceSetDelay(const std::string& name,
int delay_usecs) override;
// Led functions.
virtual Status ListLeds(std::vector<std::string>* leds) override;
virtual Status OpenLed(const std::string& name) override;
virtual Status ReleaseLed(const std::string& name) override;
virtual Status LedGetBrightness(const std::string& name,
int* brightness) override;
virtual Status LedGetMaxBrightness(const std::string& name,
int* max_brightness) override;
virtual Status LedSetBrightness(const std::string& name,
int brightness) override;
// I2c functions.
virtual Status ListI2cBuses(std::vector<std::string>* buses) override;
virtual Status OpenI2cDevice(const std::string& name,
int32_t address) override;
virtual Status ReleaseI2cDevice(const std::string& name,
int32_t address) override;
virtual Status I2cRead(const std::string& name,
int32_t address,
std::vector<uint8_t>* data,
int32_t size,
int32_t* bytes_read) override;
virtual Status I2cReadRegByte(const std::string& name,
int32_t address,
int32_t reg,
int32_t* val) override;
virtual Status I2cReadRegWord(const std::string& name,
int32_t address,
int32_t reg,
int32_t* val) override;
virtual Status I2cReadRegBuffer(const std::string& name,
int32_t address,
int32_t reg,
std::vector<uint8_t>* data,
int32_t size,
int32_t* bytes_read) override;
virtual Status I2cWrite(const std::string& name,
int32_t address,
const std::vector<uint8_t>& data,
int32_t* bytes_written) override;
virtual Status I2cWriteRegByte(const std::string& name,
int32_t address,
int32_t reg,
int8_t val) override;
virtual Status I2cWriteRegWord(const std::string& name,
int32_t address,
int32_t reg,
int32_t val) override;
virtual Status I2cWriteRegBuffer(const std::string& name,
int32_t address,
int32_t reg,
const std::vector<uint8_t>& data,
int32_t* bytes_written) override;
private:
std::map<std::string, std::unique_ptr<GpioPin>> gpios_;
std::map<std::pair<std::string, uint32_t>, std::unique_ptr<I2cDevice>>
i2c_devices_;
std::map<std::string, std::unique_ptr<SpiDevice>> spi_devices_;
std::map<std::string, std::unique_ptr<Led>> leds_;
DISALLOW_COPY_AND_ASSIGN(PeripheralManagerClient);
};
} // namespace android
#endif // SYSTEM_PERIPHERALMANAGER_DAEMON_PERIPHERAL_MANAGER_CLIENT_H_
|