6 * @name mbedJS.SPISlave
\r
8 * <a href="https://mbed.org/handbook/SPISlave">mbed::SPISlave</a>と同等の機能を持ちます。
\r
10 * @param {mbedJS.Mcu} i_mcu
\r
11 * インスタンスをバインドするMCUオブジェクトです。
\r
12 * @param {[PinName,PinName,PinName]} i_params
\r
13 * SPIを構成する4つのPinNameを格納する配列です。
\r
14 * mosi, miso, sclkの順番で設定します。
\r
15 * @param {HashMap|Generator} i_event
\r
16 * 非同期イベントハンドラの連想配列、又はGeneratorです。
\r
18 * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。
\r
20 * <li>{function()} onNew -
\r
21 * インスタンスが使用可能になった時に呼び出されます。
\r
23 * <li>{function(v)} onFrequency -
\r
24 * frequency関数のコールバック関数です。
\r
26 * <li>{function(v)} onFormat -
\r
27 * format関数のコールバック関数です。
\r
29 * <li>{function(v)} onReceive -
\r
30 * receive関数のコールバック関数です。
\r
32 * <li>{function(v)} onRead -
\r
33 * read関数のコールバック関数です。
\r
35 * <li>{int} v - 受信した8BIT値です。</li>
\r
38 * <li>{function()} onReply -
\r
39 * reply関数のコールバック関数です。
\r
43 * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。
\r
45 * @return {mbedJS.SPI}
\r
48 var CLASS=function SPISlave(i_mcu,i_params,i_handler)
\r
54 if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
\r
55 else if(i_handler){_t._event=i_handler}
\r
58 _t._oid=j.result[0];
\r
59 if(_t._event.onNew){_t._event.onNew();}
\r
60 if(_t._gen){_t._gen.next(_t);}
\r
63 MI.assertInt(i_params);
\r
64 return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+i_params[3],cb);
\r
66 throw new MI.MiMicException(e);
\r
72 RPC_NS:"mbedJS:SPISlave",
\r
73 /** @private 最後にコールしたAPIです。*/
\r
75 /** @private Generatorモードの場合にGeneratorオブジェクトを保持します。*/
\r
77 /** @private コールバック関数の連想配列です。要素はコンストラクタを参照してください。*/
\r
79 /** @private リモートインスタンスのオブジェクトIDです。*/
\r
82 * @name mbedJS.SPISlave#waitForNew
\r
84 * Generatorモードのときに使用する関数です。
\r
85 * Generatorモードの時は、yieldと併用してnew SPISlave()の完了を待ちます。
\r
87 waitForNew:function SPISlave_waitForNew()
\r
90 if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
\r
91 this._lc=CLASS.waitForNew;
\r
93 throw new MI.MiMicException(e);
\r
98 * @name mbedJS.SPISlave#frequency
\r
101 * 関数の完了時にonFrequencyイベントが発生します。
\r
102 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
103 * @param {int} i_value
\r
105 * @return {int|none}
\r
106 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
107 * <p>Generatorモードの時は戻り値はありません。</p>
\r
109 frequency:function SPISlave_frequency(i_value)
\r
113 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
114 _t._lc=CLASS.frequency;
\r
115 MI.assertInt(i_value);
\r
116 return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value,
\r
118 if(_t._event.onFrequency){_t._event.onFrequency();}
\r
119 if(_t._gen){_t._gen.next();}
\r
123 throw new MI.MiMicException(e);
\r
127 * @name mbedJS.SPISlave#format
\r
130 * 関数の完了時にonFrequencyイベントが発生します。
\r
131 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
132 * @param {int} i_bits
\r
133 * @param {int} i_mode
\r
134 * 省略可能です。省略時は0になります。
\r
135 * @return {int|none}
\r
136 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
137 * <p>Generatorモードの時は戻り値はありません。</p>
\r
139 format:function SPISlave_format(i_bits,i_mode)
\r
143 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
144 _t._lc=CLASS.format;
\r
145 var mode=i_mode?i_mode:0;
\r
146 MI.assertInt([i_bits,mode]);
\r
147 return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode,
\r
149 if(_t._event.onFormat){_t._event.onFormat();}
\r
150 if(_t._gen){_t._gen.next();}
\r
154 throw new MI.MiMicException(e);
\r
158 * @name mbedJS.SPISlave#read
\r
161 * 関数の完了時にonReadイベントが発生します。
\r
162 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
163 * @return {int|int}
\r
164 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
165 * <p>Generatorモードの時はピンの値を返します。</p>
\r
167 read:function SPISlave_read()
\r
171 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
173 return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid,
\r
177 if(_t._event.onRead){_t._event.onRead(v);}
\r
178 if(_t._gen){_t._gen.next(v);}
\r
182 throw new MI.MiMicException(e);
\r
186 * @name mbedJS.SPISlave#receive
\r
189 * 関数の完了時にonReadイベントが発生します。
\r
190 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
191 * @return {int|int}
\r
192 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
193 * <p>Generatorモードの時はピンの値を返します。</p>
\r
195 receive:function SPISlave_receive()
\r
199 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
200 _t._lc=CLASS.receive;
\r
201 return _t._mcu.rpc(_t.RPC_NS+":receive",_t._oid,
\r
205 if(_t._event.onReceive){_t._event.onReceive(v);}
\r
206 if(_t._gen){_t._gen.next(v);}
\r
210 throw new MI.MiMicException(e);
\r
214 * @name mbedJS.SPISlave#reply
\r
217 * 関数の完了時にonReplyイベントが発生します。
\r
218 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
219 * @param {int} i_value
\r
221 * @return {int|none}
\r
222 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
224 reply:function SPISlave_reply(i_value)
\r
228 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
229 _t._lc=CLASS.reply;
\r
230 MI.assertInt(i_value);
\r
231 return _t._mcu.rpc(_t.RPC_NS+":reply",_t._oid+","+i_value,
\r
234 if(_t._event.onReply){_t._event.onReply();}
\r
235 if(_t._gen){_t._gen.next();}
\r
239 throw new MI.MiMicException(e);
\r