1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef MBED_CLASSES_H
17 #define MBED_CLASSES_H
23 class RpcDigitalOut : public RPC {
25 RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
27 void write(int a0) {o.write(a0);}
28 int read(void) {return o.read();}
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>},
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*> >},
43 static rpc_class c = {"DigitalOut", funcs, NULL};
50 class RpcDigitalIn : public RPC {
52 RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
54 int read(void) {return o.read();}
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>},
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*> >},
68 static rpc_class c = {"DigitalIn", funcs, NULL};
75 class RpcDigitalInOut : public RPC {
77 RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
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();}
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>},
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*> >},
99 static rpc_class c = {"DigitalInOut", funcs, NULL};
107 class RpcAnalogIn : public RPC {
109 RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
111 float read(void) {return o.read();}
112 unsigned short read_u16(void) {return o.read_u16();}
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)
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*> >},
127 static rpc_class c = {"AnalogIn", funcs, NULL};
136 class RpcAnalogOut : public RPC {
138 RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
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);}
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)
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*> >},
158 static rpc_class c = {"AnalogOut", funcs, NULL};
167 class RpcPwmOut : public RPC {
169 RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
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);}
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)
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*> >},
195 static rpc_class c = {"PwmOut", funcs, NULL};
204 class RpcSPI : public RPC {
206 RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
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);}
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)
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*> >},
226 static rpc_class c = {"SPI", funcs, NULL};
235 class RpcSerial : public RPC {
237 RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {}
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);}
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)
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*> >},
263 static rpc_class c = {"Serial", funcs, NULL};
271 class RpcTimer : public RPC {
273 RpcTimer(const char *name=NULL) : RPC(name), o() {}
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();}
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)
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*> >},
299 static rpc_class c = {"Timer", funcs, NULL};