/* mbed Microcontroller Library * Copyright (c) 2006-2013 ARM Limited * * 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 MBED_CLASSES_H #define MBED_CLASSES_H #include "rpc.h" namespace mbed { class RpcDigitalOut : public RPC { public: RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} void write(int a0) {o.write(a0);} int read(void) {return o.read();} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"write", rpc_method_caller}, {"read", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"DigitalOut", funcs, NULL}; return &c; } private: DigitalOut o; }; class RpcDigitalIn : public RPC { public: RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} int read(void) {return o.read();} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"read", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"DigitalIn", funcs, NULL}; return &c; } private: DigitalIn o; }; class RpcDigitalInOut : public RPC { public: RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} int read(void) {return o.read();} void write(int a0) {o.write(a0);} void input(void) {o.input();} void output(void) {o.output();} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"read", rpc_method_caller}, {"write", rpc_method_caller}, {"input", rpc_method_caller}, {"output", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"DigitalInOut", funcs, NULL}; return &c; } private: DigitalInOut o; }; #if DEVICE_ANALOGIN class RpcAnalogIn : public RPC { public: RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} float read(void) {return o.read();} unsigned short read_u16(void) {return o.read_u16();} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"read", rpc_method_caller}, {"read_u16", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"AnalogIn", funcs, NULL}; return &c; } private: AnalogIn o; }; #endif #if DEVICE_ANALOGOUT class RpcAnalogOut : public RPC { public: RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} float read(void) {return o.read();} void write(float a0) {o.write(a0);} void write_u16(unsigned short a0) {o.write_u16(a0);} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"read", rpc_method_caller}, {"write", rpc_method_caller}, {"write_u16", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"AnalogOut", funcs, NULL}; return &c; } private: AnalogOut o; }; #endif #if DEVICE_PWMOUT class RpcPwmOut : public RPC { public: RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} float read(void) {return o.read();} void write(float a0) {o.write(a0);} void period(float a0) {o.period(a0);} void period_ms(int a0) {o.period_ms(a0);} void pulsewidth(float a0) {o.pulsewidth(a0);} void pulsewidth_ms(int a0) {o.pulsewidth_ms(a0);} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"read", rpc_method_caller}, {"write", rpc_method_caller}, {"period", rpc_method_caller}, {"period_ms", rpc_method_caller}, {"pulsewidth", rpc_method_caller}, {"pulsewidth_ms", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"PwmOut", funcs, NULL}; return &c; } private: PwmOut o; }; #endif #if DEVICE_SPI class RpcSPI : public RPC { public: RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {} void format(int a0, int a1) {o.format(a0, a1);} void frequency(int a0) {o.frequency(a0);} int write(int a0) {return o.write(a0);} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"format", rpc_method_caller}, {"frequency", rpc_method_caller}, {"write", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"SPI", funcs, NULL}; return &c; } private: SPI o; }; #endif #if DEVICE_SERIAL class RpcSerial : public RPC { public: RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {} void baud(int a0) {o.baud(a0);} int readable(void) {return o.readable();} int writeable(void) {return o.writeable();} int putc(int a0) {return o.putc(a0);} int getc(void) {return o.getc();} int puts(const char * a0) {return o.puts(a0);} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"baud", rpc_method_caller}, {"readable", rpc_method_caller}, {"writeable", rpc_method_caller}, {"putc", rpc_method_caller}, {"getc", rpc_method_caller}, {"puts", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"Serial", funcs, NULL}; return &c; } private: Serial o; }; #endif class RpcTimer : public RPC { public: RpcTimer(const char *name=NULL) : RPC(name), o() {} void start(void) {o.start();} void stop(void) {o.stop();} void reset(void) {o.reset();} float read(void) {return o.read();} int read_ms(void) {return o.read_ms();} int read_us(void) {return o.read_us();} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"start", rpc_method_caller}, {"stop", rpc_method_caller}, {"reset", rpc_method_caller}, {"read", rpc_method_caller}, {"read_ms", rpc_method_caller}, {"read_us", rpc_method_caller}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller >}, RPC_METHOD_END }; static rpc_class c = {"Timer", funcs, NULL}; return &c; } private: Timer o; }; } #endif