[287] | 1 | /*
|
---|
| 2 | * TOPPERS/ECNL Prototyping tool
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2017 Cores Co., Ltd. Japan
|
---|
| 5 | *
|
---|
| 6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 11 | * スコード中に含まれていること.
|
---|
| 12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 15 | * の無保証規定を掲載すること.
|
---|
| 16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 18 | * と.
|
---|
| 19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 22 | * 報告すること.
|
---|
| 23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 27 | * 免責すること.
|
---|
| 28 | *
|
---|
| 29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 33 | * の責任を負わない.
|
---|
| 34 | *
|
---|
| 35 | * @(#) $Id: I2cBlock.cs 287 2017-05-05 14:22:23Z coas-nagasima $
|
---|
| 36 | */
|
---|
| 37 | using System;
|
---|
[270] | 38 | using System.Collections.Generic;
|
---|
| 39 | using System.Linq;
|
---|
| 40 |
|
---|
| 41 | namespace WebMrbc
|
---|
| 42 | {
|
---|
| 43 | public class I2cNewBlock : Block
|
---|
| 44 | {
|
---|
| 45 | public const string type_name = "i2c_new";
|
---|
| 46 |
|
---|
| 47 | public I2cNewBlock()
|
---|
| 48 | : base(type_name)
|
---|
| 49 | {
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public void init()
|
---|
| 53 | {
|
---|
| 54 | this.appendDummyInput()
|
---|
| 55 | .appendField("I2Cの初期化")
|
---|
[273] | 56 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 57 | this.setInputsInline(true);
|
---|
| 58 | this.setPreviousStatement(true, null);
|
---|
| 59 | this.setNextStatement(true, null);
|
---|
| 60 | this.setColour(160);
|
---|
| 61 | this.setTooltip("");
|
---|
| 62 | this.setHelpUrl("http://www.example.com/");
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public class I2cWriteBlock : Block
|
---|
| 67 | {
|
---|
| 68 | public const string type_name = "i2c_write";
|
---|
| 69 |
|
---|
| 70 | public I2cWriteBlock()
|
---|
| 71 | : base(type_name)
|
---|
| 72 | {
|
---|
| 73 | }
|
---|
| 74 | public void init()
|
---|
| 75 | {
|
---|
| 76 | this.appendDummyInput()
|
---|
| 77 | .appendField("I2Cへの書き込み")
|
---|
[273] | 78 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 79 | this.appendValueInput("DEVICEID")
|
---|
| 80 | .setCheck("Number")
|
---|
| 81 | .appendField("デバイスID");
|
---|
| 82 | this.appendValueInput("ADDRESS")
|
---|
| 83 | .setCheck("Number")
|
---|
| 84 | .appendField("アドレス");
|
---|
| 85 | this.appendValueInput("DATA")
|
---|
| 86 | .setCheck("Number")
|
---|
| 87 | .appendField("データ");
|
---|
| 88 | this.setInputsInline(true);
|
---|
| 89 | this.setPreviousStatement(true, null);
|
---|
| 90 | this.setNextStatement(true, null);
|
---|
| 91 | this.setColour(160);
|
---|
| 92 | this.setTooltip("");
|
---|
| 93 | this.setHelpUrl("http://www.example.com/");
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | public class I2cReadBlock : Block
|
---|
| 98 | {
|
---|
| 99 | public const string type_name = "i2c_read";
|
---|
| 100 |
|
---|
| 101 | public I2cReadBlock()
|
---|
| 102 | : base(type_name)
|
---|
| 103 | {
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | public void init()
|
---|
| 107 | {
|
---|
| 108 | this.appendDummyInput()
|
---|
| 109 | .appendField("I2Cからの読み込み")
|
---|
[273] | 110 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 111 | this.appendValueInput("DEVICEID")
|
---|
| 112 | .setCheck("Number")
|
---|
| 113 | .appendField("デバイスID");
|
---|
| 114 | this.appendValueInput("ADDRESS_L")
|
---|
| 115 | .setCheck("Number")
|
---|
| 116 | .appendField("下位アドレス");
|
---|
| 117 | this.appendValueInput("ADDRESS_H")
|
---|
| 118 | .setCheck("Number")
|
---|
| 119 | .appendField("上位アドレス");
|
---|
| 120 | this.setInputsInline(true);
|
---|
| 121 | this.setOutput(true, "Number");
|
---|
| 122 | this.setColour(160);
|
---|
| 123 | this.setTooltip("");
|
---|
| 124 | this.setHelpUrl("http://www.example.com/");
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public class I2cBeginBlock : Block
|
---|
| 129 | {
|
---|
| 130 | public const string type_name = "i2c_begin";
|
---|
| 131 |
|
---|
| 132 | public I2cBeginBlock()
|
---|
| 133 | : base(type_name)
|
---|
| 134 | {
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | public void init()
|
---|
| 138 | {
|
---|
| 139 | this.appendDummyInput()
|
---|
| 140 | .appendField("I2Cの送信開始準備")
|
---|
[273] | 141 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 142 | this.appendValueInput("DEVICEID")
|
---|
| 143 | .setCheck("Number")
|
---|
| 144 | .appendField("デバイスID");
|
---|
| 145 | this.setInputsInline(true);
|
---|
| 146 | this.setPreviousStatement(true, null);
|
---|
| 147 | this.setNextStatement(true, null);
|
---|
| 148 | this.setColour(160);
|
---|
| 149 | this.setTooltip("");
|
---|
| 150 | this.setHelpUrl("http://www.example.com/");
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | public class I2cLwriteBlock : Block
|
---|
| 155 | {
|
---|
| 156 | public const string type_name = "i2c_lwrite";
|
---|
| 157 |
|
---|
| 158 | public I2cLwriteBlock()
|
---|
| 159 | : base(type_name)
|
---|
| 160 | {
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | public void init()
|
---|
| 164 | {
|
---|
| 165 | this.appendDummyInput()
|
---|
| 166 | .appendField("I2Cの送信バッファの末尾に数値を追加する")
|
---|
[273] | 167 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 168 | this.appendValueInput("DATA")
|
---|
| 169 | .setCheck("Number")
|
---|
| 170 | .appendField("データ");
|
---|
| 171 | this.setInputsInline(true);
|
---|
| 172 | this.setOutput(true, "Number");
|
---|
| 173 | this.setColour(160);
|
---|
| 174 | this.setTooltip("");
|
---|
| 175 | this.setHelpUrl("http://www.example.com/");
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | public class I2cEndBlock : Block
|
---|
| 180 | {
|
---|
| 181 | public const string type_name = "i2c_end";
|
---|
| 182 |
|
---|
| 183 | public I2cEndBlock()
|
---|
| 184 | : base(type_name)
|
---|
| 185 | {
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | public void init()
|
---|
| 189 | {
|
---|
| 190 | this.appendDummyInput()
|
---|
| 191 | .appendField("I2Cの送信シーケンスを発行する")
|
---|
[273] | 192 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 193 | this.appendDummyInput()
|
---|
| 194 | .appendField("ストップコンディション発生")
|
---|
| 195 | .appendField(new FieldCheckbox("TRUE"), "STOP");
|
---|
| 196 | this.setInputsInline(true);
|
---|
| 197 | this.setOutput(true, "Number");
|
---|
| 198 | this.setColour(160);
|
---|
| 199 | this.setTooltip("");
|
---|
| 200 | this.setHelpUrl("http://www.example.com/");
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | public class I2cRequestBlock : Block
|
---|
| 205 | {
|
---|
| 206 | public const string type_name = "i2c_request";
|
---|
| 207 |
|
---|
| 208 | public I2cRequestBlock()
|
---|
| 209 | : base(type_name)
|
---|
| 210 | {
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | public void init()
|
---|
| 214 | {
|
---|
| 215 | this.appendDummyInput()
|
---|
| 216 | .appendField("I2Cへ受信シーケンスを発行する")
|
---|
[273] | 217 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 218 | this.appendValueInput("ADDRESS")
|
---|
| 219 | .setCheck("Number")
|
---|
| 220 | .appendField("開始アドレス");
|
---|
| 221 | this.appendValueInput("COUNT")
|
---|
| 222 | .setCheck("Number")
|
---|
| 223 | .appendField("データ数");
|
---|
| 224 | this.setInputsInline(true);
|
---|
| 225 | this.setOutput(true, "Number");
|
---|
| 226 | this.setColour(160);
|
---|
| 227 | this.setTooltip("");
|
---|
| 228 | this.setHelpUrl("http://www.example.com/");
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | public class I2cLreadBlock : Block
|
---|
| 233 | {
|
---|
| 234 | public const string type_name = "i2c_lread";
|
---|
| 235 |
|
---|
| 236 | public I2cLreadBlock()
|
---|
| 237 | : base(type_name)
|
---|
| 238 | {
|
---|
| 239 | }
|
---|
| 240 | public void init()
|
---|
| 241 | {
|
---|
| 242 | this.appendDummyInput()
|
---|
| 243 | .appendField("I2Cへ受信シーケンスを発行しデータを読み出す")
|
---|
[273] | 244 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 245 | this.setInputsInline(true);
|
---|
| 246 | this.setOutput(true, "Number");
|
---|
| 247 | this.setColour(160);
|
---|
| 248 | this.setTooltip("");
|
---|
| 249 | this.setHelpUrl("http://www.example.com/");
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | public class I2cAvailableBlock : Block
|
---|
| 254 | {
|
---|
| 255 | public const string type_name = "i2c_available";
|
---|
| 256 |
|
---|
| 257 | public I2cAvailableBlock()
|
---|
| 258 | : base(type_name)
|
---|
| 259 | {
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | public void init()
|
---|
| 263 | {
|
---|
| 264 | this.appendDummyInput()
|
---|
| 265 | .appendField("I2Cの受信バッファ内にあるデータ数を調べる")
|
---|
[273] | 266 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 267 | this.setInputsInline(true);
|
---|
| 268 | this.setOutput(true, "Number");
|
---|
| 269 | this.setColour(160);
|
---|
| 270 | this.setTooltip("");
|
---|
| 271 | this.setHelpUrl("http://www.example.com/");
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | public class I2cFrequencyBlock : Block
|
---|
| 276 | {
|
---|
| 277 | public const string type_name = "i2c_frequency";
|
---|
| 278 |
|
---|
| 279 | public I2cFrequencyBlock()
|
---|
| 280 | : base(type_name)
|
---|
| 281 | {
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | public void init()
|
---|
| 285 | {
|
---|
| 286 | this.appendDummyInput()
|
---|
| 287 | .appendField("I2Cの周波数を変更する")
|
---|
[273] | 288 | .appendField(App.TargetBoard.I2CPorts(), "I2C_PORT_NO");
|
---|
[270] | 289 | this.appendValueInput("FREQUENCY")
|
---|
| 290 | .setCheck("Number")
|
---|
| 291 | .appendField("周波数");
|
---|
| 292 | this.setInputsInline(true);
|
---|
| 293 | this.setPreviousStatement(true, null);
|
---|
| 294 | this.setNextStatement(true, null);
|
---|
| 295 | this.setColour(160);
|
---|
| 296 | this.setTooltip("");
|
---|
| 297 | this.setHelpUrl("http://www.example.com/");
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | partial class Ruby
|
---|
| 302 | {
|
---|
| 303 | public node i2c_new(I2cNewBlock block)
|
---|
| 304 | {
|
---|
| 305 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 306 | // $i2c0 = I2c.new(0)
|
---|
[273] | 307 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 308 | var c = new const_node(this, intern("I2c"));
|
---|
| 309 | var p = new node[] {
|
---|
[273] | 310 | new int_node(this, App.TargetBoard.I2CPortNameToNum(dropdown_i2c_port_no))
|
---|
[270] | 311 | };
|
---|
| 312 | return new asgn_node(this, a, new call_node(this, c, intern("new"), p, null));
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | public node i2c_write(I2cWriteBlock block)
|
---|
| 316 | {
|
---|
| 317 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 318 | var value_deviceid = valueToCode(block, "DEVICEID");
|
---|
| 319 | var value_address = valueToCode(block, "ADDRESS");
|
---|
| 320 | var value_data = valueToCode(block, "DATA");
|
---|
| 321 | // $i2c0.write(0, 0x00, 0x00)
|
---|
[273] | 322 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 323 | var p = new node[] {
|
---|
| 324 | value_deviceid,
|
---|
| 325 | value_address,
|
---|
| 326 | value_data
|
---|
| 327 | };
|
---|
| 328 | return new call_node(this, a, intern("write"), p, null);
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | public node i2c_read(I2cReadBlock block)
|
---|
| 332 | {
|
---|
| 333 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 334 | var value_deviceid = valueToCode(block, "DEVICEID");
|
---|
| 335 | var value_address_l = valueToCode(block, "ADDRESS_L");
|
---|
| 336 | var value_address_h = valueToCode(block, "ADDRESS_H");
|
---|
| 337 | // $i2c0.read(0, 0x00, 0x00)
|
---|
[273] | 338 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 339 | var p = new node[] {
|
---|
| 340 | value_deviceid,
|
---|
| 341 | value_address_l
|
---|
| 342 | };
|
---|
| 343 | if (value_address_h != null) {
|
---|
| 344 | p.Push(value_address_h);
|
---|
| 345 | }
|
---|
| 346 | return new call_node(this, a, intern("write"), p, null);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | public node i2c_begin(I2cBeginBlock block)
|
---|
| 350 | {
|
---|
| 351 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 352 | var value_deviceid = valueToCode(block, "DEVICEID");
|
---|
| 353 | // $i2c0.begin(0)
|
---|
[273] | 354 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 355 | var p = new node[] {
|
---|
| 356 | value_deviceid,
|
---|
| 357 | };
|
---|
| 358 | return new call_node(this, a, intern("begin"), p, null);
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | public node i2c_lwrite(I2cLwriteBlock block)
|
---|
| 362 | {
|
---|
| 363 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 364 | var value_data = valueToCode(block, "DATA");
|
---|
| 365 | // $i2c0.lwrite(0x00)
|
---|
[273] | 366 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 367 | var p = new node[0];
|
---|
| 368 | if (value_data != null)
|
---|
| 369 | p.Push(value_data);
|
---|
| 370 | return new call_node(this, a, intern("lwrite"), p, null);
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | public node i2c_end(I2cEndBlock block)
|
---|
| 374 | {
|
---|
| 375 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 376 | var checkbox_stop = block.getFieldValue("STOP");
|
---|
| 377 | // $i2c0.lwrite(0x00)
|
---|
[273] | 378 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 379 | var p = new node[0];
|
---|
| 380 | if (checkbox_stop != null)
|
---|
| 381 | p.Push(checkbox_stop == "TRUE" ? (node)new true_node(this) : (node)new false_node(this));
|
---|
| 382 | return new call_node(this, a, intern("end"), p, null);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | public node i2c_request(I2cRequestBlock block)
|
---|
| 386 | {
|
---|
| 387 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 388 | var value_address = valueToCode(block, "ADDRESS");
|
---|
| 389 | var value_count = valueToCode(block, "COUNT");
|
---|
| 390 | // $i2c0.request(0x00, 1)
|
---|
[273] | 391 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 392 | var p = new node[] {
|
---|
| 393 | value_address,
|
---|
| 394 | value_count
|
---|
| 395 | };
|
---|
| 396 | return new call_node(this, a, intern("request"), p, null);
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | public node i2c_lread(I2cLreadBlock block)
|
---|
| 400 | {
|
---|
| 401 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 402 | // $i2c0.lread()
|
---|
[273] | 403 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 404 | var p = new node[0];
|
---|
| 405 | return new call_node(this, a, intern("lread"), p, null);
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | public node i2c_available(I2cAvailableBlock block)
|
---|
| 409 | {
|
---|
| 410 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 411 | // $i2c0.available()
|
---|
[273] | 412 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 413 | var p = new node[0];
|
---|
| 414 | return new call_node(this, a, intern("available"), p, null);
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | public node i2c_frequency(I2cFrequencyBlock block)
|
---|
| 418 | {
|
---|
| 419 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 420 | var value_frequency = valueToCode(block, "FREQUENCY");
|
---|
| 421 | // $i2c0.frequency(0)
|
---|
[273] | 422 | var a = new gvar_node(this, intern(App.TargetBoard.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
[270] | 423 | var p = new node[] {
|
---|
| 424 | value_frequency
|
---|
| 425 | };
|
---|
| 426 | return new call_node(this, a, intern("frequency"), p, null);
|
---|
| 427 | }
|
---|
| 428 | }
|
---|
| 429 | }
|
---|