8 * <a href="https://mbed.org/handbook/SPI">mbed::SPI</a>と同等の機能を持ちます。
\r
10 * @param {mbedJS.Mcu} i_mcu
\r
11 * インスタンスをバインドするMCUオブジェクトです。
\r
12 * @param {[PinName,PinName,PinName]} i_params
\r
13 * SPIを構成する3つのPinNameを格納する配列です。mosi,miso,sclkの順番です。
\r
14 * @param {HashMap|Generator} i_event
\r
15 * 非同期イベントハンドラの連想配列、又はGeneratorです。
\r
17 * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。
\r
19 * <li>{function()} onNew -
\r
20 * インスタンスが使用可能になった時に呼び出されます。
\r
22 * <li>{function(v)} onWrite -
\r
23 * write関数のコールバック関数です。
\r
25 * <li>{int} v - 受信した8BIT値です。</li>
\r
28 * <li>{function(v)} onFrequency -
\r
29 * frequency関数のコールバック関数です。
\r
31 * <li>{function(v)} onFormat -
\r
32 * format関数のコールバック関数です。
\r
36 * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。
\r
38 * @return {mbedJS.SPI}
\r
41 var CLASS=function SPI(i_mcu,i_params,i_handler)
\r
47 if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
\r
48 else if(i_handler){_t._event=i_handler}
\r
51 _t._oid=j.result[0];
\r
52 if(_t._event.onNew){_t._event.onNew();}
\r
53 if(_t._gen){_t._gen.next(_t);}
\r
56 MI.assertInt(i_params);
\r
57 return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC,cb);
\r
59 throw new MI.MiMicException(e);
\r
66 RPC_NS:"mbedJS:SPI",
\r
67 /** @private 最後にコールしたAPIです。*/
\r
69 /** @private Generatorモードの場合にGeneratorオブジェクトを保持します。*/
\r
71 /** @private コールバック関数の連想配列です。要素はコンストラクタを参照してください。*/
\r
73 /** @private リモートインスタンスのオブジェクトIDです。*/
\r
76 * @name mbedJS.SPI#waitForNew
\r
78 * Generatorモードのときに使用する関数です。
\r
79 * Generatorモードの時は、yieldと併用してnew SPI()の完了を待ちます。
\r
81 waitForNew:function SPI_waitForNew()
\r
84 if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
\r
85 this._lc=CLASS.waitForNew;
\r
87 throw new MI.MiMicException(e);
\r
91 * @name mbedJS.SPI#write
\r
94 * 関数の完了時にonWriteイベントが発生します。
\r
95 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
96 * @param {int} i_value
\r
97 * @return {int|none}
\r
98 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
99 * <p>Generatorモードの時は戻り値はありません。</p>
\r
101 write:function SPI_write(i_value)
\r
105 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
106 _t._lc=CLASS.write;
\r
107 MI.assertInt(i_value);
\r
108 return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value,
\r
111 if(_t._event.onWrite){_t._event.onWrite(v);}
\r
112 if(_t._gen){_t._gen.next(v);}
\r
116 throw new MI.MiMicException(e);
\r
120 * @name mbedJS.SPI#frequency
\r
123 * 関数の完了時にonFrequencyイベントが発生します。
\r
124 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
125 * @param {int} i_value
\r
127 * @return {int|none}
\r
128 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
129 * <p>Generatorモードの時は戻り値はありません。</p>
\r
131 frequency:function SPI_frequency(i_value)
\r
135 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
136 _t._lc=CLASS.frequency;
\r
137 MI.assertInt(i_value);
\r
138 return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value,
\r
140 if(_t._event.onFrequency){_t._event.onFrequency();}
\r
141 if(_t._gen){_t._gen.next();}
\r
145 throw new MI.MiMicException(e);
\r
149 * @name mbedJS.SPI#format
\r
152 * 関数の完了時にonFrequencyイベントが発生します。
\r
153 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
154 * @param {int} i_bits
\r
155 * @param {int} i_mode
\r
156 * 省略可能です。省略時は0になります。
\r
157 * @return {int|none}
\r
158 * <p>Callbackモードの時はRPCメソッドのインデクスを返します。</p>
\r
159 * <p>Generatorモードの時は戻り値はありません。</p>
\r
161 format:function SPI_format(i_bits,i_mode)
\r
165 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
166 _t._lc=CLASS.format;
\r
167 var mode=i_mode?i_mode:0;
\r
168 MI.assertInt([i_bits,mode]);
\r
169 return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode,
\r
171 if(_t._event.onFormat){_t._event.onFormat();}
\r
172 if(_t._gen){_t._gen.next();}
\r
176 throw new MI.MiMicException(e);
\r