mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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