]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/rpc/RpcClasses.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / rpc / RpcClasses.h
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef MBED_CLASSES_H
17 #define MBED_CLASSES_H
18
19 #include "rpc.h"
20
21 namespace mbed {
22
23 class RpcDigitalOut : public RPC {
24 public:
25 RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
26
27 void write(int a0) {o.write(a0);}
28 int read(void) {return o.read();}
29
30 virtual const struct rpc_method *get_rpc_methods() {
31 static const rpc_method rpc_methods[] = {
32 {"write", rpc_method_caller<RpcDigitalOut, int, &RpcDigitalOut::write>},
33 {"read", rpc_method_caller<int, RpcDigitalOut, &RpcDigitalOut::read>},
34 RPC_METHOD_SUPER(RPC)
35 };
36 return rpc_methods;
37 }
38 static struct rpc_class *get_rpc_class() {
39 static const rpc_function funcs[] = {
40 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalOut, PinName, const char*> >},
41 RPC_METHOD_END
42 };
43 static rpc_class c = {"DigitalOut", funcs, NULL};
44 return &c;
45 }
46 private:
47 DigitalOut o;
48 };
49
50 class RpcDigitalIn : public RPC {
51 public:
52 RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
53
54 int read(void) {return o.read();}
55
56 virtual const struct rpc_method *get_rpc_methods() {
57 static const rpc_method rpc_methods[] = {
58 {"read", rpc_method_caller<int, RpcDigitalIn, &RpcDigitalIn::read>},
59 RPC_METHOD_SUPER(RPC)
60 };
61 return rpc_methods;
62 }
63 static struct rpc_class *get_rpc_class() {
64 static const rpc_function funcs[] = {
65 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalIn, PinName, const char*> >},
66 RPC_METHOD_END
67 };
68 static rpc_class c = {"DigitalIn", funcs, NULL};
69 return &c;
70 }
71 private:
72 DigitalIn o;
73 };
74
75 class RpcDigitalInOut : public RPC {
76 public:
77 RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
78
79 int read(void) {return o.read();}
80 void write(int a0) {o.write(a0);}
81 void input(void) {o.input();}
82 void output(void) {o.output();}
83
84 virtual const struct rpc_method *get_rpc_methods() {
85 static const rpc_method rpc_methods[] = {
86 {"read", rpc_method_caller<int, RpcDigitalInOut, &RpcDigitalInOut::read>},
87 {"write", rpc_method_caller<RpcDigitalInOut, int, &RpcDigitalInOut::write>},
88 {"input", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::input>},
89 {"output", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::output>},
90 RPC_METHOD_SUPER(RPC)
91 };
92 return rpc_methods;
93 }
94 static struct rpc_class *get_rpc_class() {
95 static const rpc_function funcs[] = {
96 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalInOut, PinName, const char*> >},
97 RPC_METHOD_END
98 };
99 static rpc_class c = {"DigitalInOut", funcs, NULL};
100 return &c;
101 }
102 private:
103 DigitalInOut o;
104 };
105
106 #if DEVICE_ANALOGIN
107 class RpcAnalogIn : public RPC {
108 public:
109 RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
110
111 float read(void) {return o.read();}
112 unsigned short read_u16(void) {return o.read_u16();}
113
114 virtual const struct rpc_method *get_rpc_methods() {
115 static const rpc_method rpc_methods[] = {
116 {"read", rpc_method_caller<float, RpcAnalogIn, &RpcAnalogIn::read>},
117 {"read_u16", rpc_method_caller<unsigned short, RpcAnalogIn, &RpcAnalogIn::read_u16>},
118 RPC_METHOD_SUPER(RPC)
119 };
120 return rpc_methods;
121 }
122 static struct rpc_class *get_rpc_class() {
123 static const rpc_function funcs[] = {
124 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogIn, PinName, const char*> >},
125 RPC_METHOD_END
126 };
127 static rpc_class c = {"AnalogIn", funcs, NULL};
128 return &c;
129 }
130 private:
131 AnalogIn o;
132 };
133 #endif
134
135 #if DEVICE_ANALOGOUT
136 class RpcAnalogOut : public RPC {
137 public:
138 RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
139
140 float read(void) {return o.read();}
141 void write(float a0) {o.write(a0);}
142 void write_u16(unsigned short a0) {o.write_u16(a0);}
143
144 virtual const struct rpc_method *get_rpc_methods() {
145 static const rpc_method rpc_methods[] = {
146 {"read", rpc_method_caller<float, RpcAnalogOut, &RpcAnalogOut::read>},
147 {"write", rpc_method_caller<RpcAnalogOut, float, &RpcAnalogOut::write>},
148 {"write_u16", rpc_method_caller<RpcAnalogOut, unsigned short, &RpcAnalogOut::write_u16>},
149 RPC_METHOD_SUPER(RPC)
150 };
151 return rpc_methods;
152 }
153 static struct rpc_class *get_rpc_class() {
154 static const rpc_function funcs[] = {
155 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogOut, PinName, const char*> >},
156 RPC_METHOD_END
157 };
158 static rpc_class c = {"AnalogOut", funcs, NULL};
159 return &c;
160 }
161 private:
162 AnalogOut o;
163 };
164 #endif
165
166 #if DEVICE_PWMOUT
167 class RpcPwmOut : public RPC {
168 public:
169 RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
170
171 float read(void) {return o.read();}
172 void write(float a0) {o.write(a0);}
173 void period(float a0) {o.period(a0);}
174 void period_ms(int a0) {o.period_ms(a0);}
175 void pulsewidth(float a0) {o.pulsewidth(a0);}
176 void pulsewidth_ms(int a0) {o.pulsewidth_ms(a0);}
177
178 virtual const struct rpc_method *get_rpc_methods() {
179 static const rpc_method rpc_methods[] = {
180 {"read", rpc_method_caller<float, RpcPwmOut, &RpcPwmOut::read>},
181 {"write", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::write>},
182 {"period", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::period>},
183 {"period_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::period_ms>},
184 {"pulsewidth", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::pulsewidth>},
185 {"pulsewidth_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::pulsewidth_ms>},
186 RPC_METHOD_SUPER(RPC)
187 };
188 return rpc_methods;
189 }
190 static struct rpc_class *get_rpc_class() {
191 static const rpc_function funcs[] = {
192 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcPwmOut, PinName, const char*> >},
193 RPC_METHOD_END
194 };
195 static rpc_class c = {"PwmOut", funcs, NULL};
196 return &c;
197 }
198 private:
199 PwmOut o;
200 };
201 #endif
202
203 #if DEVICE_SPI
204 class RpcSPI : public RPC {
205 public:
206 RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
207
208 void format(int a0, int a1) {o.format(a0, a1);}
209 void frequency(int a0) {o.frequency(a0);}
210 int write(int a0) {return o.write(a0);}
211
212 virtual const struct rpc_method *get_rpc_methods() {
213 static const rpc_method rpc_methods[] = {
214 {"format", rpc_method_caller<RpcSPI, int, int, &RpcSPI::format>},
215 {"frequency", rpc_method_caller<RpcSPI, int, &RpcSPI::frequency>},
216 {"write", rpc_method_caller<int, RpcSPI, int, &RpcSPI::write>},
217 RPC_METHOD_SUPER(RPC)
218 };
219 return rpc_methods;
220 }
221 static struct rpc_class *get_rpc_class() {
222 static const rpc_function funcs[] = {
223 {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcSPI, PinName, PinName, PinName, const char*> >},
224 RPC_METHOD_END
225 };
226 static rpc_class c = {"SPI", funcs, NULL};
227 return &c;
228 }
229 private:
230 SPI o;
231 };
232 #endif
233
234 #if DEVICE_SERIAL
235 class RpcSerial : public RPC {
236 public:
237 RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {}
238
239 void baud(int a0) {o.baud(a0);}
240 int readable(void) {return o.readable();}
241 int writeable(void) {return o.writeable();}
242 int putc(int a0) {return o.putc(a0);}
243 int getc(void) {return o.getc();}
244 int puts(const char * a0) {return o.puts(a0);}
245
246 virtual const struct rpc_method *get_rpc_methods() {
247 static const rpc_method rpc_methods[] = {
248 {"baud", rpc_method_caller<RpcSerial, int, &RpcSerial::baud>},
249 {"readable", rpc_method_caller<int, RpcSerial, &RpcSerial::readable>},
250 {"writeable", rpc_method_caller<int, RpcSerial, &RpcSerial::writeable>},
251 {"putc", rpc_method_caller<int, RpcSerial, int, &RpcSerial::putc>},
252 {"getc", rpc_method_caller<int, RpcSerial, &RpcSerial::getc>},
253 {"puts", rpc_method_caller<int, RpcSerial, const char *, &RpcSerial::puts>},
254 RPC_METHOD_SUPER(RPC)
255 };
256 return rpc_methods;
257 }
258 static struct rpc_class *get_rpc_class() {
259 static const rpc_function funcs[] = {
260 {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcSerial, PinName, PinName, const char*> >},
261 RPC_METHOD_END
262 };
263 static rpc_class c = {"Serial", funcs, NULL};
264 return &c;
265 }
266 private:
267 Serial o;
268 };
269 #endif
270
271 class RpcTimer : public RPC {
272 public:
273 RpcTimer(const char *name=NULL) : RPC(name), o() {}
274
275 void start(void) {o.start();}
276 void stop(void) {o.stop();}
277 void reset(void) {o.reset();}
278 float read(void) {return o.read();}
279 int read_ms(void) {return o.read_ms();}
280 int read_us(void) {return o.read_us();}
281
282 virtual const struct rpc_method *get_rpc_methods() {
283 static const rpc_method rpc_methods[] = {
284 {"start", rpc_method_caller<RpcTimer, &RpcTimer::start>},
285 {"stop", rpc_method_caller<RpcTimer, &RpcTimer::stop>},
286 {"reset", rpc_method_caller<RpcTimer, &RpcTimer::reset>},
287 {"read", rpc_method_caller<float, RpcTimer, &RpcTimer::read>},
288 {"read_ms", rpc_method_caller<int, RpcTimer, &RpcTimer::read_ms>},
289 {"read_us", rpc_method_caller<int, RpcTimer, &RpcTimer::read_us>},
290 RPC_METHOD_SUPER(RPC)
291 };
292 return rpc_methods;
293 }
294 static struct rpc_class *get_rpc_class() {
295 static const rpc_function funcs[] = {
296 {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcTimer, const char*> >},
297 RPC_METHOD_END
298 };
299 static rpc_class c = {"Timer", funcs, NULL};
300 return &c;
301 }
302 private:
303 Timer o;
304 };
305
306 }
307
308 #endif
Imprint / Impressum