You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

RpcClasses.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. #include "rpc.h"
  19. namespace mbed {
  20. class RpcDigitalOut : public RPC {
  21. public:
  22. RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
  23. void write(int a0) {o.write(a0);}
  24. int read(void) {return o.read();}
  25. virtual const struct rpc_method *get_rpc_methods() {
  26. static const rpc_method rpc_methods[] = {
  27. {"write", rpc_method_caller<RpcDigitalOut, int, &RpcDigitalOut::write>},
  28. {"read", rpc_method_caller<int, RpcDigitalOut, &RpcDigitalOut::read>},
  29. RPC_METHOD_SUPER(RPC)
  30. };
  31. return rpc_methods;
  32. }
  33. static struct rpc_class *get_rpc_class() {
  34. static const rpc_function funcs[] = {
  35. {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalOut, PinName, const char*> >},
  36. RPC_METHOD_END
  37. };
  38. static rpc_class c = {"DigitalOut", funcs, NULL};
  39. return &c;
  40. }
  41. private:
  42. DigitalOut o;
  43. };
  44. class RpcDigitalIn : public RPC {
  45. public:
  46. RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
  47. int read(void) {return o.read();}
  48. virtual const struct rpc_method *get_rpc_methods() {
  49. static const rpc_method rpc_methods[] = {
  50. {"read", rpc_method_caller<int, RpcDigitalIn, &RpcDigitalIn::read>},
  51. RPC_METHOD_SUPER(RPC)
  52. };
  53. return rpc_methods;
  54. }
  55. static struct rpc_class *get_rpc_class() {
  56. static const rpc_function funcs[] = {
  57. {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalIn, PinName, const char*> >},
  58. RPC_METHOD_END
  59. };
  60. static rpc_class c = {"DigitalIn", funcs, NULL};
  61. return &c;
  62. }
  63. private:
  64. DigitalIn o;
  65. };
  66. class RpcDigitalInOut : public RPC {
  67. public:
  68. RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
  69. int read(void) {return o.read();}
  70. void write(int a0) {o.write(a0);}
  71. void input(void) {o.input();}
  72. void output(void) {o.output();}
  73. virtual const struct rpc_method *get_rpc_methods() {
  74. static const rpc_method rpc_methods[] = {
  75. {"read", rpc_method_caller<int, RpcDigitalInOut, &RpcDigitalInOut::read>},
  76. {"write", rpc_method_caller<RpcDigitalInOut, int, &RpcDigitalInOut::write>},
  77. {"input", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::input>},
  78. {"output", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::output>},
  79. RPC_METHOD_SUPER(RPC)
  80. };
  81. return rpc_methods;
  82. }
  83. static struct rpc_class *get_rpc_class() {
  84. static const rpc_function funcs[] = {
  85. {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalInOut, PinName, const char*> >},
  86. RPC_METHOD_END
  87. };
  88. static rpc_class c = {"DigitalInOut", funcs, NULL};
  89. return &c;
  90. }
  91. private:
  92. DigitalInOut o;
  93. };
  94. #if DEVICE_ANALOGIN
  95. class RpcAnalogIn : public RPC {
  96. public:
  97. RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
  98. float read(void) {return o.read();}
  99. unsigned short read_u16(void) {return o.read_u16();}
  100. virtual const struct rpc_method *get_rpc_methods() {
  101. static const rpc_method rpc_methods[] = {
  102. {"read", rpc_method_caller<float, RpcAnalogIn, &RpcAnalogIn::read>},
  103. {"read_u16", rpc_method_caller<unsigned short, RpcAnalogIn, &RpcAnalogIn::read_u16>},
  104. RPC_METHOD_SUPER(RPC)
  105. };
  106. return rpc_methods;
  107. }
  108. static struct rpc_class *get_rpc_class() {
  109. static const rpc_function funcs[] = {
  110. {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogIn, PinName, const char*> >},
  111. RPC_METHOD_END
  112. };
  113. static rpc_class c = {"AnalogIn", funcs, NULL};
  114. return &c;
  115. }
  116. private:
  117. AnalogIn o;
  118. };
  119. #endif
  120. #if DEVICE_ANALOGOUT
  121. class RpcAnalogOut : public RPC {
  122. public:
  123. RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
  124. float read(void) {return o.read();}
  125. void write(float a0) {o.write(a0);}
  126. void write_u16(unsigned short a0) {o.write_u16(a0);}
  127. virtual const struct rpc_method *get_rpc_methods() {
  128. static const rpc_method rpc_methods[] = {
  129. {"read", rpc_method_caller<float, RpcAnalogOut, &RpcAnalogOut::read>},
  130. {"write", rpc_method_caller<RpcAnalogOut, float, &RpcAnalogOut::write>},
  131. {"write_u16", rpc_method_caller<RpcAnalogOut, unsigned short, &RpcAnalogOut::write_u16>},
  132. RPC_METHOD_SUPER(RPC)
  133. };
  134. return rpc_methods;
  135. }
  136. static struct rpc_class *get_rpc_class() {
  137. static const rpc_function funcs[] = {
  138. {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogOut, PinName, const char*> >},
  139. RPC_METHOD_END
  140. };
  141. static rpc_class c = {"AnalogOut", funcs, NULL};
  142. return &c;
  143. }
  144. private:
  145. AnalogOut o;
  146. };
  147. #endif
  148. #if DEVICE_PWMOUT
  149. class RpcPwmOut : public RPC {
  150. public:
  151. RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
  152. float read(void) {return o.read();}
  153. void write(float a0) {o.write(a0);}
  154. void period(float a0) {o.period(a0);}
  155. void period_ms(int a0) {o.period_ms(a0);}
  156. void pulsewidth(float a0) {o.pulsewidth(a0);}
  157. void pulsewidth_ms(int a0) {o.pulsewidth_ms(a0);}
  158. virtual const struct rpc_method *get_rpc_methods() {
  159. static const rpc_method rpc_methods[] = {
  160. {"read", rpc_method_caller<float, RpcPwmOut, &RpcPwmOut::read>},
  161. {"write", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::write>},
  162. {"period", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::period>},
  163. {"period_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::period_ms>},
  164. {"pulsewidth", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::pulsewidth>},
  165. {"pulsewidth_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::pulsewidth_ms>},
  166. RPC_METHOD_SUPER(RPC)
  167. };
  168. return rpc_methods;
  169. }
  170. static struct rpc_class *get_rpc_class() {
  171. static const rpc_function funcs[] = {
  172. {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcPwmOut, PinName, const char*> >},
  173. RPC_METHOD_END
  174. };
  175. static rpc_class c = {"PwmOut", funcs, NULL};
  176. return &c;
  177. }
  178. private:
  179. PwmOut o;
  180. };
  181. #endif
  182. #if DEVICE_SPI
  183. class RpcSPI : public RPC {
  184. public:
  185. RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
  186. void format(int a0, int a1) {o.format(a0, a1);}
  187. void frequency(int a0) {o.frequency(a0);}
  188. int write(int a0) {return o.write(a0);}
  189. virtual const struct rpc_method *get_rpc_methods() {
  190. static const rpc_method rpc_methods[] = {
  191. {"format", rpc_method_caller<RpcSPI, int, int, &RpcSPI::format>},
  192. {"frequency", rpc_method_caller<RpcSPI, int, &RpcSPI::frequency>},
  193. {"write", rpc_method_caller<int, RpcSPI, int, &RpcSPI::write>},
  194. RPC_METHOD_SUPER(RPC)
  195. };
  196. return rpc_methods;
  197. }
  198. static struct rpc_class *get_rpc_class() {
  199. static const rpc_function funcs[] = {
  200. {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcSPI, PinName, PinName, PinName, const char*> >},
  201. RPC_METHOD_END
  202. };
  203. static rpc_class c = {"SPI", funcs, NULL};
  204. return &c;
  205. }
  206. private:
  207. SPI o;
  208. };
  209. #endif
  210. #if DEVICE_SERIAL
  211. class RpcSerial : public RPC {
  212. public:
  213. RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {}
  214. void baud(int a0) {o.baud(a0);}
  215. int readable(void) {return o.readable();}
  216. int writeable(void) {return o.writeable();}
  217. int putc(int a0) {return o.putc(a0);}
  218. int getc(void) {return o.getc();}
  219. int puts(const char * a0) {return o.puts(a0);}
  220. virtual const struct rpc_method *get_rpc_methods() {
  221. static const rpc_method rpc_methods[] = {
  222. {"baud", rpc_method_caller<RpcSerial, int, &RpcSerial::baud>},
  223. {"readable", rpc_method_caller<int, RpcSerial, &RpcSerial::readable>},
  224. {"writeable", rpc_method_caller<int, RpcSerial, &RpcSerial::writeable>},
  225. {"putc", rpc_method_caller<int, RpcSerial, int, &RpcSerial::putc>},
  226. {"getc", rpc_method_caller<int, RpcSerial, &RpcSerial::getc>},
  227. {"puts", rpc_method_caller<int, RpcSerial, const char *, &RpcSerial::puts>},
  228. RPC_METHOD_SUPER(RPC)
  229. };
  230. return rpc_methods;
  231. }
  232. static struct rpc_class *get_rpc_class() {
  233. static const rpc_function funcs[] = {
  234. {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcSerial, PinName, PinName, const char*> >},
  235. RPC_METHOD_END
  236. };
  237. static rpc_class c = {"Serial", funcs, NULL};
  238. return &c;
  239. }
  240. private:
  241. Serial o;
  242. };
  243. #endif
  244. class RpcTimer : public RPC {
  245. public:
  246. RpcTimer(const char *name=NULL) : RPC(name), o() {}
  247. void start(void) {o.start();}
  248. void stop(void) {o.stop();}
  249. void reset(void) {o.reset();}
  250. float read(void) {return o.read();}
  251. int read_ms(void) {return o.read_ms();}
  252. int read_us(void) {return o.read_us();}
  253. virtual const struct rpc_method *get_rpc_methods() {
  254. static const rpc_method rpc_methods[] = {
  255. {"start", rpc_method_caller<RpcTimer, &RpcTimer::start>},
  256. {"stop", rpc_method_caller<RpcTimer, &RpcTimer::stop>},
  257. {"reset", rpc_method_caller<RpcTimer, &RpcTimer::reset>},
  258. {"read", rpc_method_caller<float, RpcTimer, &RpcTimer::read>},
  259. {"read_ms", rpc_method_caller<int, RpcTimer, &RpcTimer::read_ms>},
  260. {"read_us", rpc_method_caller<int, RpcTimer, &RpcTimer::read_us>},
  261. RPC_METHOD_SUPER(RPC)
  262. };
  263. return rpc_methods;
  264. }
  265. static struct rpc_class *get_rpc_class() {
  266. static const rpc_function funcs[] = {
  267. {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcTimer, const char*> >},
  268. RPC_METHOD_END
  269. };
  270. static rpc_class c = {"Timer", funcs, NULL};
  271. return &c;
  272. }
  273. private:
  274. Timer o;
  275. };
  276. }
  277. #endif