OSDN Git Service

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@106 47198e57-cb75-475f-84c4-a814cd...
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Wed, 23 Nov 2011 08:57:37 +0000 (08:57 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Wed, 23 Nov 2011 08:57:37 +0000 (08:57 +0000)
misc/MiMicVM/api.js/LPCXPresso1769.All-mini.js
misc/MiMicVM/api.js/LPCXPresso1769.All.js
misc/MiMicVM/api.js/LPCXPresso1769.Gpio.js
misc/MiMicVM/api.js/LPCXpresso1769.Adc.js
misc/MiMicVM/api.js/LPCXpresso1769.Mcu.js
misc/MiMicVM/api.js/LPCXpresso1769.Pwm.js
misc/MiMicVM/api.js/demo/ad_port.html
misc/MiMicVM/api.js/test.html

index 12be33e..882c3a4 100644 (file)
@@ -1 +1 @@
-var LPCXpresso1769;(function(){var g=MiMicLib.isUndef;var a={_EE:function(n){return{NG:[n|0,"Unknown exception in LPCXpresso1769"],INVALID_ARG:[n|1,"Invalid argument"],INVALID_PIN:[n|2,"Invalid pin"],INVALID_CFG:[n|3,"Invalid configulation"],VM_RUNTIME:[n|4,"MVM runtime error"],}}(MiMicError.NG[0]|MiMicError.MID_MiMic|MiMicError.CAID_LPCXPresso1769),_BCF:{setBit:function m(p,r,o,q,n){try{n.push(p);n.push(~(r<<q));n.push((r&o)<<q);return"EA00EA01EA02DB0700AA0701AE0702DF0700"}catch(s){throw new MiMicException(s)}},setMem:function b(p,o,n){try{n.push(p);n.push(o);return"EA00EA01DF0100"}catch(q){throw new MiMicException(q)}},getMem:function i(o,n){try{n.push(o);return"EA00DB0000EE00"}catch(p){throw new MiMicException(p)}},READMEM:"EA00DB0000EE00",END:"ZZ.E"},FUNC_NAME:["GPIO","AD","DA","PWM"],PHL_NAME:["GPIO","ADC","DAC","PWM"],PHL:{WDT:[0,0,null],TIMER0:[0,2,1],TIMER1:[0,4,2],UART0:[0,6,3],UART1:[0,8,4],PWM1:[0,12,6],I2C0:[0,14,7],SPI:[0,16,8],RTC:[null,null,9],SSPI1:[0,20,10],DAC:[0,22,null],ADC:[0,24,12],CAN1:[0,26,13],CAN2:[0,28,14],ACF:[0,30,null],QEI:[1,0,18],GPIOINT:[1,2,15],PCB:[1,4,null],I2C1:[1,6,19],SSP0:[1,10,21],TIMER2:[1,12,22],TIMER3:[1,14,23],UART2:[1,16,24],UART3:[1,18,25],I2C2:[1,20,26],I2S:[1,22,27],RIT:[1,26,16],SYSCON:[1,28,null],PWM_MC:[1,30,17],GPDMA:[null,null,29],ENET:[null,null,30],USB:[null,null,31]},P0:[[0,0,0,0,["GPIO0.0","RD1","TXD3","SDA1"]],[0,0,0,1,["GPIO0.1","TD1","RXD3","SCL1"]],[0,0,0,2,["GPIO0.2","TXD0","AD0.7",null]],[0,0,0,3,["GPIO0.3","RXD0","AD0.6",null]],[0,0,0,4,["GPIO0.4","I2SRX_CLK","RD2","CAP2.0"]],[0,0,0,5,["GPIO0.5","I2SRX_WS","TD2","CAP2.1"]],[0,0,0,6,["GPIO0.6","I2SRX_SDA","SSEL1","MAT2.0"]],[0,0,0,7,["GPIO0.7","I2STX_CLK","SCK1","MAT2.1"]],[0,0,0,8,["GPIO0.8","I2STX_WS","MISO1","MAT2.2"]],[0,0,0,9,["GPIO0.9","I2STX_SDA","MOSI1","MAT2.3"]],[0,0,0,10,["GPIO0.10","TXD2","SDA2","MAT3.0"]],[0,0,0,11,["GPIO0.11","RXD2","SCL2","MAT3.1"]],null,null,null,[0,0,0,15,["GPIO0.15","TXD1","SCK0","SCK"]],[1,1,0,16,["GPIO0.16","RXD1","SSEL0","SSEL"]],[1,1,0,17,["GPIO0.17","CTS1","MISO0","MISO"]],[1,1,0,18,["GPIO0.18","DCD1","MOSI0","MOSI"]],[1,1,0,19,["GPIO0.19","DSR1",null,"SDA1"]],[1,1,0,20,["GPIO0.20","DTR1",null,"SCL1"]],[1,1,0,21,["GPIO0.21","RI1",null,"RD1"]],[1,1,0,22,["GPIO0.22","RTS1",null,"TD1"]],[1,1,0,23,["GPIO0.23","AD0.0","I2SRX_CLK","CAP3.0"]],[1,1,0,24,["GPIO0.24","AD0.1","I2SRX_WS","CAP3.1"]],[1,1,0,25,["GPIO0.25","AD0.2","I2SRX_SDA","TXD3"]],[1,1,0,26,["GPIO0.26","AD0.3","AOUT","RXD3"]],[1,null,null,22,["GPIO0.27","SDA0","USB_SDA",null]],[1,null,null,24,["GPIO0.28","SCL0","USB_SCL",null]],[1,null,0,29,["GPIO0.29","USB_D+",null,null]],[1,null,0,30,["GPIO0.30","USB_D-",null,null]],],P1:[[2,2,1,0,["GPIO1.0","ENET_TXD0",null,null]],[2,2,1,1,["GPIO1.1","ENET_TXD1",null,null]],null,null,[2,2,1,4,["GPIO1.4","ENET_TX_EN",null,null]],null,null,null,[2,2,1,8,["GPIO1.8","ENET_CRS",null,null]],[2,2,1,9,["GPIO1.9","ENET_RXD0",null,null]],[2,2,1,10,["GPIO1.10","ENET_RXD1",null,null]],null,null,null,[2,2,1,14,["GPIO1.14","ENET_RX_ER",null,null]],[2,2,1,15,["GPIO1.15","ENET_REF_CLK",null,null]],[3,3,1,16,["GPIO1.16","ENET_MDC",null,null]],[3,3,1,17,["GPIO1.17","ENET_MDIO",null,null]],[3,3,1,18,["GPIO1.18","USB_UP_LED","PWM1.1","CAP1.0"]],[3,3,1,19,["GPIO1.19","MCOA0","USB_PPWR","CAP1.1"]],[3,3,1,20,["GPIO1.20","MCI0","PWM1.2","SCK0"]],[3,3,1,21,["GPIO1.21","MCABORT","PWM1.3","SSEL0"]],[3,3,1,22,["GPIO1.22","MCOB0","USB_PWRD","MAT1.0"]],[3,3,1,23,["GPIO1.23","MCI1","PWM1.4","MISO0"]],[3,3,1,24,["GPIO1.24","MCI2","PWM1.5","MOSI0"]],[3,3,1,25,["GPIO1.25","MCOA1",null,"MAT1.1"]],[3,3,1,26,["GPIO1.26","MCOB1","PWM1.6","CAP0.0"]],[3,3,1,27,["GPIO1.27","CLKOUT","USB_OVRCR","CAP0.1"]],[3,3,1,28,["GPIO1.28","MCOA2","PCAP1.0","MAT0.0"]],[3,3,1,29,["GPIO1.29","MCOB2","PCAP1.1","MAT0.1"]],[3,3,1,30,["GPIO1.30",null,"VBUS","AD0.4"]],[3,3,1,31,["GPIO1.31",null,"SCK1","AD0.5"]],],P2:[[4,4,2,0,["GPIO2.0","PWM1.1","TXD1",null]],[4,4,2,1,["GPIO2.1","PWM1.2","RXD1",null]],[4,4,2,2,["GPIO2.2","PWM1.3","CTS1",null]],[4,4,2,3,["GPIO2.3","PWM1.4","DCD1",null]],[4,4,2,4,["GPIO2.4","PWM1.5","DSR1",null]],[4,4,2,5,["GPIO2.5","PWM1.6","DTR1",null]],[4,4,2,6,["GPIO2.6","PCAP1.0","RI1",null]],[4,4,2,7,["GPIO2.7","RD2","RTS1",null]],[4,4,2,8,["GPIO2.8","TD2","TXD2","ENET_MDC"]],[4,4,2,9,["GPIO2.9","USB_CONNECT","RXD2","ENET_MDIO"]],[4,4,2,10,["GPIO2.10","EINT0","NMI",null]],[4,4,2,11,["GPIO2.11","EINT1",null,"I2STX_CLK"]],[4,4,2,12,["GPIO2.12","EINT2",null,"I2STX_WS"]],[4,4,2,13,["GPIO2.13","EINT3",null,"I2STX_SDA"]],],P3:[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[7,7,3,25,["GPIO3.25",null,"MAT0.0","PWM1.2"]],[7,7,3,26,["GPIO3.26","STCLK","MAT0.1","PWM1.3"]],],P4:[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[9,9,4,28,["GPIO4.28","RX_MCLK","MAT2.0","TXD3"]],[9,9,4,29,["GPIO4.29","TX_MCLK","MAT2.1","RXD3"]]],completePinFunctionName:function j(p,o){try{for(var n=0;n<p[4].length;n++){if(p[4][n].indexOf(o)==0){return p[4][n]}}throw new MiMicException("The function name '"+o+"' is not unknown.")}catch(q){throw new MiMicException(q)}},getPinRegInfo:function d(n){try{return{s:n[0],m:n[1],o:n[2],smb:(n[3]%16)*2,ob:n[3]}}catch(o){throw new MiMicException(o)}},getPinSelByFunctionName:function h(o,q){try{for(var n=0;n<o[4].length;n++){if(o[4][n]==q){return n}}throw new MiMicException("The function name '"+q+"' has not function.")}catch(p){throw new MiMicException(p)}},hasPinFunctionName:function l(n,o){return n[4].indexOf(o)>=0}};a.I2c=function c(){throw new MiMicException("Not imprement.")};a.Dma=function k(){throw new MiMicException("Not imprement.")};a.Uart=function f(){throw new MiMicException("Not imprement.")};a.Usb=function e(){throw new MiMicException("Not imprement.")};LPCXpresso1769=a}());(function(){var f=LPCXpresso1769;var p=f._BCF;var a=f._EE;var e=MiMicLib.isUndef;function b(t){try{var v="";for(var s=0;s<t.length;s++){v+=MiMicLib.hexout(t[s],8)}return v}catch(u){throw new MiMicException(u)}}function h(w){try{function x(A,z){for(var y=0;y<A.length;y++){if(A[y]==null){continue}if(f.hasPinFunctionName(A[y],z)){return A[y]}}return null}var v=[f.P0,f.P1,f.P2,f.P3,f.P4];for(var t=0;t<v.length;t++){var s=x(v[t],w);if(s!=null){return s}}throw new MiMicException("pin function '"+w+"' not found")}catch(u){throw new MiMicException(u)}}function n(v){try{var t={GPIO:"GPIO",AD:"ADC",DA:"DAC"};for(var s in t){if(v.indexOf(s)==0){return t[s]}}throw new MiMicException("Peripheral for "+i_pinfunction+" not found.")}catch(u){throw new MiMicException(u)}}f.Mcu=function o(v,t){try{this.events={onActivateChanged:null};this._phl_holder=[];this._mif=new MiMicRemoteMcuInterface(v);var s=e(t)?true:t;if(s){this.activate()}}catch(u){throw new MiMicException(u)}};f.Mcu.prototype={_mif:null,isActive:function m(){try{return this._mif.isConnected()}catch(s){throw new MiMicException(s)}},events:null,_phl_holder:null,getClockInfo:function g(){return{cclk:100*1000*1000}},activate:function d(){try{var s=this;if(this.isActive()){throw new MiMicException("Already activated!")}this._mif.connect(function(u){if(!u){if(s.events.onActivateChanged!=null){s.events.onActivateChanged(false)}}});if(this.events.onActivateChanged!=null){this.events.onActivateChanged(true)}}catch(t){throw new MiMicException(t)}},deactivate:function c(){try{if(!this.isActive()){throw new MiMicException("Already activated!")}this._mif.disconnect();if(this.events.onActivateChanged!=null){this.events.onActivateChanged(false)}}catch(s){throw new MiMicException(s)}},callMiMic:function l(){try{var t;switch(arguments.length){case 1:t=arguments[0];break;case 2:t=arguments[0]+b(arguments[1]);break;default:throw new MiMicException(s)}return this._mif.execBc(t)}catch(s){throw new MiMicException(s)}},callMiMicWithCheck:function k(){try{var s=this.callMiMic.apply(this,arguments);if(s.result!=0){throw new MiMicException(a.VM_RUNTIME,"Result="+s.toString())}return s}catch(t){throw new MiMicException(t)}},getPin:function q(){switch(arguments.length){case 1:var s=h(arguments[0]);var t=n(arguments[0]);return this.getPeripheral(t).getPin(s);case 2:var t=n(arguments[1]);return this.getPeripheral(t).getPin(arguments[0]);default:throw new MiMicException()}},getPort:function r(s){throw new MiMicException("Not implemented.")},getPeripheral:function i(s,t){if(e(this._phl_holder[s])){switch(s){case"GPIO":new f.Gpio(this,t);break;case"ADC":new f.Adc(this,t);break;case"PWM":new f.Pwm(this,t);break;default:throw new MiMicException("Unknown peripheral symbol "+s)}}else{if(!e(t)){throw new MiMicException()}}return this._phl_holder[s]},registerPhl:function j(t,s){try{if(!e(this._phl_holder[s])){throw new MiMicException("Peripheral symbol "+s+" is already exist on mcu.")}this._phl_holder[s]=t}catch(u){throw new MiMicException(u)}}}}());(function(){var f=LPCXpresso1769;var d=f._BCF;var a=f._EE;var b=MiMicLib.isUndef;f.Memory=function e(g,h){if(!b(h)){this._base=h}this._mcu=g};f.Memory.prototype={_base:0,_mcu:null,read32:function c(){try{function o(i){if(i%4!=0){throw new MiMicException(a.INVALID_ARG,"An alignment is not 32bit unit.")}}var n="";var h=new Array();var p=arguments[0];switch(arguments.length){case 1:if(!isNaN(p)){o(p);n=d.READMEM;h.push(this._base+p)}else{for(var k=0;k<p.length;k++){o(p[k]);n+=d.getMem(this._base+p[k],h)}}break;case 2:o(p);o(arguments[1]);var g=arguments[1]/4;for(var k=0;k<g;k++){n+=d.READMEM;h.push(this._base+p+k*4)}break;default:break}var j=this._mcu.callMiMicWithCheck(n+d.END,h).stream;return j.length==1?j[0]:j}catch(m){throw new MiMicException(m)}}}}());(function(){var g=LPCXpresso1769;var f=g._BCF;var c=g._EE;var e=MiMicLib.isUndef;g.Peripheral=function(h,i,k){try{if(e(i)){throw new MiMicException(c.INVALID_PHL)}this._mcu=h;this._phl=i;if(!e(k)){this.setOpt(k)}}catch(j){throw new MiMicException(j)}};g.Peripheral.prototype={_PCLKSEL:[1074774440,1074774444],_PCONP:1074774212,_phl:null,_mcu:null,_cache:{pclk:0},BCF_setOpt:function a(k,h){try{var j="";if(!e(k.power)){if(this._phl[2]==null){throw new MiMicException(c.INVALID_CFG,"The pin does not support PCONP.")}j+=f.setBit(this._PCONP,1,k.power,this._phl[2],h)}if(!e(k.clock)){if(this._phl[0]==null){throw new MiMicException(c.INVALID_CFG,"The pin does not support PCLKSEL.")}this._cache.pclk=k.clock;j+=f.setBit(this._PCLKSEL[this._phl[0]],3,k.clock,this._phl[1],h)}return j}catch(i){throw new MiMicException(i)}},setOpt:function b(k){try{var h=new Array();var j=this.BCF_setOpt(k,h);if(j.length==0){throw new MiMicException("i_opt is empty or invalid.")}this._mcu.callMiMicWithCheck(j+f.END,h)}catch(i){throw new MiMicException(i)}return},getPCLK:function d(){try{var h=[4,1,2,0];var i=h[this._cache.pclk];var j;if(i==0){if(this._phl===g.PHL.CAN1||this._phl===g.PHL.CAN2){j=this._mcu.getClockInfo().cclk/6}else{j=this._mcu.getClockInfo().cclk/8}}else{j=this._mcu.getClockInfo().cclk/i}return Math.round(j)}catch(k){throw new MiMicException(k)}}}}());(function(){var a=LPCXpresso1769;var i=a._BCF;var j=a._EE;var d=MiMicLib.isUndef;var h={_PINSEL:[1073922048,1073922052,1073922056,1073922060,1073922064,null,null,1073922240,null,1073922084,1073922088],_PINMODE:[1073922112,1073922116,1073922120,1073922124,1073922128,1073922132,1073922136,1073922140,null,1073922148],_PINMODE_OD:[1073922152,1073922156,1073922160,1073922164,1073922168],};a.Port=function f(l,m,k){try{this._mcu=l;this._pininfo=new Array();for(var n=0;n<m.length;n++){this._pininfo.push(a.getPinRegInfo(m[n]))}if(!d(k)){this.setOpts(k)}}catch(o){throw new MiMicException(o)}};a.Port.prototype={_mcu:null,BCF_setOpts:function c(l,k){try{var r={selr:[0,0,0,0,0,0,0,0,0,0],selr_mask:[0,0,0,0,0,0,0,0,0,0],modr:[0,0,0,0,0,0,0,0,0,0],modr_mask:[0,0,0,0,0,0,0,0,0,0],odr:[0,0,0,0,0],odr_mask:[0,0,0,0,0]};if(this._pininfo.length!=l.length){throw new MiMicException()}for(var n=0;n<l.length;n++){var q=this._pininfo[n];var m=l[n];if(!d(m.sel)){r.selr[q.s]|=(m.sel<<q.smb);r.selr_mask[q.s]|=(3<<q.smb)}if(!d(m.mode)){r.modr[q.m]|=(m.mode<<q.smb);r.modr_mask[q.m]|=(3<<q.smb)}if(!d(m.od)){r.odr[q.o]|=(m.od<<q.ob);r.odr_mask[q.o]|=(1<<q.ob)}}var p="";for(var n=0;n<10;n++){if(r.selr_mask[n]!=0){p+=i.setBit(h._PINSEL[n],r.selr_mask[n],r.selr[n],0,k)}if(r.modr_mask[n]!=0){p+=i.setBit(h._PINMODE[n],r.modr_mask[n],r.modr[n],0,k)}}for(var n=0;n<5;n++){if(r.odr_mask[n]!=0){p+=i.setBit(h._PINMODE_OD[n],r.odr_mask[n],r.odr[n],0,k)}}return p}catch(o){throw new MiMicException(o)}},setOpts:function g(k){try{var l=new Array();var n=this.BCF_setOpts(k,l);if(n.length==0){throw new MiMicException("i_opt is empty or invalid.")}this._mcu.callMiMicWithCheck(n+i.END,l)}catch(m){throw new MiMicException(m)}return}};a.Pin=function b(k,l,n){try{if(d(l)){throw new MiMicException(j.INVALID_PIN)}this._port=new a.Port(k,[l],d(n)?undefined:[n])}catch(m){throw new MiMicException(m)}};a.Pin.prototype={_port:null,setOpt:function e(l){try{this._port.setOpts([l])}catch(k){throw new MiMicException(k)}return}}}());(function(){var a=LPCXpresso1769;var p=a._BCF;var q=a._EE;var d=MiMicLib.isUndef;var k=MiMicLib.cloneAssoc;a.Adc=function b(r,w){try{this._mcu=r;this._phl=new a.Peripheral(r,a.PHL.ADC);var t=d(w)?{phl:{}}:{phl:d(w.phl)?{}:k(w.phl),};if(d(t.phl.power)){t.phl.power=1}var v="";var s=new Array();v+=this.BCF_setOpt(t,s);v+=p.setMem(this._AD0CR,2098176,s);v+=p.setMem(this._AD0CR,2163712,s);this._mcu.callMiMicWithCheck(v+p.END,s);this._mcu.registerPhl(this,"ADC")}catch(u){throw new MiMicException(u)}};a.Adc.prototype={_PHL_DEF:{power:1},_AD0CR:1073954816,_AD0DR:[1073954832,1073954836,1073954840,1073954844,1073954848,1073954852,1073954856,1073954860],_phl:null,_mcu:null,BCF_setOpt:function m(u,r){try{var t="";if(!d(u.phl)){t+=this._phl.BCF_setOpt(u.phl,r)}return t}catch(s){throw new MiMicException(s)}},BCF_setSels:function j(t,s,r){try{return p.setBit(this._AD0CR,t,s*t,0,r)}catch(u){throw new MiMicException(u)}},BCF_getAD0DR:function l(s,r){try{return p.getMem(this._AD0DR[s],r)}catch(t){throw new MiMicException(t)}},setOpt:function h(u){try{var r=new Array();var t=this.BCF_setOpt(u,r);this._mcu.callMiMicWithCheck(t+p.END,r)}catch(s){throw new MiMicException(s)}},getPin:function n(r,t){try{return new a.AdcPin(this,r,t)}catch(s){throw new MiMicException(s)}},getPort:function c(r,t){try{return new a.AdcPort(this,r,t)}catch(s){throw new MiMicException(s)}}};function e(v){try{var t=a.completePinFunctionName(v,"AD");var s=t.substring(2).split(".");var u={port:0,ch:parseInt(s[1]),pin_sel:a.getPinSelByFunctionName(v,t)};if(!isNaN(u.ch)){return u}throw new MiMicException(q.INVALID_CFG,"The pin has not AD fuction.")}catch(w){throw new MiMicException(w)}}a.AdcPort=function o(s,r,x){try{this._adc=s;this._pins=new Array();for(var u=0;u<r.length;u++){this._pins.push(e(r[u]))}var w=this._pins[0].port;for(var u=1;u<this._pins.length;u++){if(w!=this._pins[1].port){throw new MiMicException("Invalid pin combination.")}}this._port=new a.Port(s._mcu,r);this._port_no=w;this._adcr_mask=0;for(var u=0;u<this._pins.length;u++){this._adcr_mask|=(1<<this._pins[u].ch)}var t=k(x);t.sel=1;if(d(t.pin)){t.pin={}}if(d(t.pin.sel)){t.pin.sel=this._PINSEL_AUTO_DETECT}this.setOpt(t)}catch(v){throw new MiMicException(v)}};a.AdcPort.prototype={_PINSEL_AUTO_DETECT:268435455,_adc:null,_pins:null,_port_no:0,_port:null,_adcr_mask:0,setOpt:function h(y){try{var r=new Array();var x="";if(!d(y.pin)){var v=new Array();for(var t=0;t<this._pins.length;t++){var u=(y.pin.sel==this._PINSEL_AUTO_DETECT)?this._pins[t].pin_sel:y.pin.sel;v.push({sel:u,mode:y.pin.mode,od:y.pin.od})}}x+=this._port.BCF_setOpts(v,r);x+=this._adc.BCF_setSels(this._adcr_mask,y.sel,r);this._adc._mcu.callMiMicWithCheck(x+p.END,r);return}catch(w){throw new MiMicException(w)}},getValues:function i(){try{var s=new Array();var x="";for(var u=0;u<this._pins.length;u++){x+=this._adc.BCF_getAD0DR(this._pins[u].ch,s)}var t=this._adc._mcu.callMiMicWithCheck(x+p.END,s);var v=new Array();for(var u=0;u<this._pins.length;u++){v.push((t.stream[u]>>4)&4095)}return v}catch(w){throw new MiMicException(w)}}};a.AdcPin=function f(r,s,u){try{this._aport=new a.AdcPort(r,[s],u)}catch(t){throw new MiMicException(t)}};a.AdcPin.prototype={_aport:null,getValue:function g(){try{return this._aport.getValues()[0]}catch(r){throw new MiMicException(r)}},setOpt:function h(s){try{this._aport.setOpt(s)}catch(r){throw new MiMicException(r)}}}}());(function(){var a=LPCXpresso1769;var p=a._BCF;var q=a._EE;var e=MiMicLib.isUndef;var i=MiMicLib.cloneAssoc;a.Gpio=function j(r,t){try{this._mcu=r;r.registerPhl(this,"GPIO")}catch(s){throw new MiMicException(s)}};a.Gpio.prototype={_FIO_DIR:[537509888,537509920,537509952,537509984,537510016],_FIO_PIN:[537509908,537509940,537509972,537510004,537510036],_FIO_SET:[537509912,537509944,537509976,537510008,537510040],_FIO_CLR:[537509916,537509948,537509980,537510012,537510044],_FIO_MASK:[537509904,537509936,537509968,537510000,537510032],_mcu:null,BCF_getValues:function l(s,t,r){try{r.push(this._FIO_PIN[s],this._FIO_MASK[s],~t);return"EA00EA01EA02DF0201DB0300EE03"}catch(u){throw new MiMicException(u)}},BCF_setValues:function o(t,u,s,r){try{r.push(this._FIO_PIN[t],this._FIO_MASK[t],~u,s);return"EA00EA01EA02EA03DF0201DF0300"}catch(v){throw new MiMicException(v)}},BCF_setDirs:function b(s,t,u,r){try{return p.setBit(this._FIO_DIR[s],t,t*u,0,r)}catch(v){throw new MiMicException(v)}},getPin:function k(r,t){try{return new a.GpioPin(this,r,t)}catch(s){throw new MiMicException(s)}}};function d(v){try{var t=a.completePinFunctionName(v,"GPIO");var s=t.substring(4).split(".");var u={port:parseInt(s[0]),bit:parseInt(s[1]),pin_sel:a.getPinSelByFunctionName(v,t)};if(!isNaN(u.port)&&!isNaN(u.bit)){return u}throw new MiMicException(q.INVALID_CFG,"The pin has not GPIO fuction.")}catch(w){throw new MiMicException(w)}}a.GpioPort=function c(u,r,x){try{this._gpio=u;this._pins=new Array();for(var t=0;t<r.length;t++){this._pins.push(d(r[t]))}var w=this._pins[0].port;for(var t=1;t<this._pins.length;t++){if(w!=this._pins[1].port){throw new MiMicException("Invalid pin combination.")}}this._port=new a.Port(u._mcu,r);this._port_no=w;this._mask=0;for(var t=0;t<this._pins.length;t++){this._mask|=(1<<this._pins[t].bit)}var s=i(x);if(e(s.pin)){s.pin={}}if(e(s.pin.sel)){s.pin.sel=this._PINSEL_AUTO_DETECT}this.setOpt(s)}catch(v){throw new MiMicException(v)}};a.GpioPort.prototype={_PINSEL_AUTO_DETECT:268435455,_pins:null,_gpio:null,_port_no:0,_port:null,_mask:0,setOpt:function h(y){try{var r=new Array();var x="";if(!e(y.dir)){x+=this._gpio.BCF_setDirs(this._port_no,this._mask,y.dir,r)}if(!e(y.pin)){var v=new Array();for(var t=0;t<this._pins.length;t++){var u=(y.pin.sel==this._PINSEL_AUTO_DETECT)?this._pins[t].pin_sel:y.pin.sel;v.push({sel:u,mode:y.pin.mode,od:y.pin.od})}}x+=this._port.BCF_setOpts(v,r);this._gpio._mcu.callMiMicWithCheck(x+p.END,r);return}catch(w){throw new MiMicException(w)}},setValue:function f(w){try{var u=0;var s=this._pins.length;for(var x=0;x<s;x++){var r=((w>>x)&1);u|=(r<<this._pins[x].bit)}var t=new Array();var z=this._gpio.BCF_setValues(this._port_no,this._mask,u,t);this._gpio._mcu.callMiMicWithCheck(z+p.END,t)}catch(y){throw new MiMicException(y)}},getValue:function g(){try{var u=new Array();var y=this._gpio.BCF_getValues(this._port_no,this._mask,u);var s=this._gpio._mcu.callMiMicWithCheck(y+p.END,u).stream[0];var t=0;for(var w=this._pins.length-1;w>=0;w--){var r=((s>>this._pins[w].bit)&1);t=(t<<1)|r}return t}catch(x){throw new MiMicException(x)}},outPatt:function n(u){try{var A=new Array();var x="";for(var r=0;r<u.length;r++){var y=0;var s=this._pins.length;for(var t=0;t<s;t++){var z=((u[r]>>t)&1);y|=(z<<this._pins[t].bit)}x+=this._gpio.BCF_setValues(this._port_no,this._mask,y,A)}this._gpio._mcu.callMiMicWithCheck(x+p.END,A)}catch(w){throw new MiMicException(w)}}};a.GpioPin=function m(r,s,u){try{this._gport=new a.GpioPort(r,[s],u)}catch(t){throw new MiMicException(t)}};a.GpioPin.prototype={_gport:null,setOpt:function h(s){try{this._gport.setOpt(s)}catch(r){throw new MiMicException(r)}},setValue:function f(r){try{this._gport.setValue(r)}catch(s){throw new MiMicException(s)}},getValue:function g(){try{return this._gport.getValue()}catch(r){throw new MiMicException(r)}},outPatt:function n(r){try{this._gport.outPatt(r)}catch(s){throw new MiMicException(s)}},}}());(function(){var a=LPCXpresso1769;var n=a._BCF;var o=a._EE;var b=MiMicLib.isUndef;var g=MiMicLib.cloneAssoc;a.Pwm=function d(p,u){try{this._mcu=p;this._phl=new a.Peripheral(p,a.PHL.PWM1);var r=b(u)?{phl:{}}:{phl:b(u.phl)?{}:g(u.phl),freq:u.freq};if(b(r.phl.power)){r.phl.power=1}if(b(r.phl.clock)){r.phl.clock=0}if(b(r.freq)){r.freq=100}var t="";var q=new Array();t+=this.BCF_setOpt(r,q);t+=n.setMem(this._PC,0,q);t+=n.setMem(this._PCR,0,q);t+=n.setMem(this._CTCR,0,q);t+=n.setMem(this._TCR,0,q);t+=n.setMem(this._TC,0,q);t+=n.setMem(this._TCR,9,q);this._mcu.callMiMicWithCheck(t+n.END,q);this._mcu.registerPhl(this,"PWM")}catch(s){throw new MiMicException(s)}};a.Pwm.prototype={_cache:{mr0:0},_TCR:1073840132,_TC:1073840136,_PR:1073840140,_PC:1073840144,_MCR:1073840152,_PCR:1073840204,_LER:1073840208,_CTCR:1073840240,_MRn:[1073840152,1073840156,1073840160,1073840164,1073840192,1073840196,1073840200],_phl:null,_mcu:null,BCF_setOpt:function h(u,p){try{var t="";var r;var q;if(!b(u.phl)){t+=this._phl.BCF_setOpt(u.phl,p)}if(!b(u.freq)){q=Math.round(this._phl.getPCLK()/u.freq);if(q<=0){throw new MiMicException("The peripheral clock too small.")}t+=this.BCF_setMRn(0,q,p);t+=this.BCF_setLER(0,p);this._cache.mr0=q}return t}catch(s){throw new MiMicException(s)}},BCF_setLER:function e(q,p){return n.setBit(this._LER,1,1,q,p)},BCF_setMRn:function j(r,q,p){try{return n.setMem(this._MRn[r],q,p)}catch(s){throw new MiMicException(s)}},BCF_setMRnByDuty:function m(q,r,p){try{return this.BCF_setMRn(q,Math.round(r*this._cache.mr0),p)}catch(s){throw new MiMicException(s)}},BCF_setPCRbit:function l(u,r,s,q){try{var p,t;p=t=0;if(!b(r)){t|=r;p|=1}if(!b(s)){t|=(s<<8);p|=256}return n.setBit(this._PCR,p,t,u,q)}catch(w){throw new MiMicException(w)}},setOpt:function f(s){try{var p=new Array();var r=this.BCF_setOpt(s,p);this._mcu.callMiMicWithCheck(r+n.END,p)}catch(q){throw new MiMicException(q)}},getPin:function i(p,r){try{return new a.PwmPin(this,p,r)}catch(q){throw new MiMicException(q)}}};a.PwmPin=function k(p,r,t){try{this._pwm=p;this._pin=new a.Pin(p._mcu,r);this._pwminfo=function(x){var v=a.completePinFunctionName(x,"PWM");var u=v.substring(2).split(".");var w={port:0,ch:parseInt(u[1]),pin_sel:a.getPinSelByFunctionName(x,v)};if(!isNaN(w.ch)){return w}throw new MiMicException(o.INVALID_CFG,"The pin has not PWM fuction.")}(r);var q=b(t)?{pin:{}}:{pin:b(t.pin)?{}:g(t.pin),duty:t.duty,enable:t.enable};if(b(q.pin.sel)){q.pin.sel=this._pwminfo.pin_sel}if(b(q.duty)){q.duty=0}if(b(q.enable)){q.enable=1}this.setOpt(q)}catch(s){throw new MiMicException(s)}};a.PwmPin.prototype={_pwm:null,_pin:null,_pwminfo:null,BCF_setOpt:function h(s,p){try{var r="";if(!b(s.pin)){r+=this._pin.BCF_setOpt(s.pin,p)}if(!b(s.enable)){r+=this._pwm.BCF_setPCRbit(this._pwminfo.ch,0,s.enable,p)}if(!b(s.duty)){r+=this._pwm.BCF_setMRnByDuty(this._pwminfo.ch,s.duty,p);r+=this._pwm.BCF_setLER(this._pwminfo.ch,p)}return r}catch(q){throw new MiMicException(q)}},setOpt:function f(s){try{var p=new Array();var r=this.BCF_setOpt(s,p);this._pwm._mcu.callMiMicWithCheck(r+n.END,p)}catch(q){throw new MiMicException(q)}},setDuty:function c(p){try{this.setOpt({duty:p})}catch(q){throw new MiMicException(q)}}}}());(function(){var f=LPCXpresso1769;var e=f._BCF;var a=f._EE;var d=MiMicLib.isUndef;f.Ni=function c(g){try{this._mcu=g}catch(h){throw new MiMicException(h)}};f.Ni.prototype={call:function b(j,q,p){var n="";var r=new Array();if(!d(q)){for(var l=0;l<8;l++){var k="wm"+l;if(!d(q[k])){n+="FB"+MiMicLib.hexout(l,2)+MiMicLib.hexout(q[k],8)}}if(!d(q.stream)){for(var l=0;l<q.stream.length;l++){r.push(q.stream[l])}}}n+="ZF"+MiMicLib.hexout(j,8);var g=0;if(!d(p)){for(var l=0;l<8;l++){if(!d(p["wm"+l])){n+="EE"+MiMicLib.hexout(l,2);g++}}}var m=this._mcu.callMiMic(n+e.END,r);if(m.result!=0){return false}var o=0;if(!d(p)){var h=m.stream.length-g;for(var l=0;l<8;l++){var k="wm"+l;if(!d(p[k])){p[k]=m.stream[h];h++}}if(!d(p.stream)){p.stream=m.stream.slice(0,m.stream.length-g)}}return false}}}());
\ No newline at end of file
+var LPCXpresso1769;(function(){var g=MiMicLib.isUndef;var a={_EE:function(n){return{NG:[n|0,"Unknown exception in LPCXpresso1769"],INVALID_ARG:[n|1,"Invalid argument"],INVALID_PIN:[n|2,"Invalid pin"],INVALID_CFG:[n|3,"Invalid configulation"],VM_RUNTIME:[n|4,"MVM runtime error"],}}(MiMicError.NG[0]|MiMicError.MID_MiMic|MiMicError.CAID_LPCXPresso1769),_BCF:{setBit:function m(p,r,o,q,n){try{n.push(p);n.push(~(r<<q));n.push((r&o)<<q);return"EA00EA01EA02DB0700AA0701AE0702DF0700"}catch(s){throw new MiMicException(s)}},setMem:function b(p,o,n){try{n.push(p);n.push(o);return"EA00EA01DF0100"}catch(q){throw new MiMicException(q)}},getMem:function i(o,n){try{n.push(o);return"EA00DB0000EE00"}catch(p){throw new MiMicException(p)}},READMEM:"EA00DB0000EE00",END:"ZZ.E"},FUNC_NAME:["GPIO","AD","DA","PWM"],PHL_NAME:["GPIO","ADC","DAC","PWM"],PHL:{WDT:[0,0,null],TIMER0:[0,2,1],TIMER1:[0,4,2],UART0:[0,6,3],UART1:[0,8,4],PWM1:[0,12,6],I2C0:[0,14,7],SPI:[0,16,8],RTC:[null,null,9],SSPI1:[0,20,10],DAC:[0,22,null],ADC:[0,24,12],CAN1:[0,26,13],CAN2:[0,28,14],ACF:[0,30,null],QEI:[1,0,18],GPIOINT:[1,2,15],PCB:[1,4,null],I2C1:[1,6,19],SSP0:[1,10,21],TIMER2:[1,12,22],TIMER3:[1,14,23],UART2:[1,16,24],UART3:[1,18,25],I2C2:[1,20,26],I2S:[1,22,27],RIT:[1,26,16],SYSCON:[1,28,null],PWM_MC:[1,30,17],GPDMA:[null,null,29],ENET:[null,null,30],USB:[null,null,31]},P0:[[0,0,0,0,["GPIO0.0","RD1","TXD3","SDA1"]],[0,0,0,1,["GPIO0.1","TD1","RXD3","SCL1"]],[0,0,0,2,["GPIO0.2","TXD0","AD0.7",null]],[0,0,0,3,["GPIO0.3","RXD0","AD0.6",null]],[0,0,0,4,["GPIO0.4","I2SRX_CLK","RD2","CAP2.0"]],[0,0,0,5,["GPIO0.5","I2SRX_WS","TD2","CAP2.1"]],[0,0,0,6,["GPIO0.6","I2SRX_SDA","SSEL1","MAT2.0"]],[0,0,0,7,["GPIO0.7","I2STX_CLK","SCK1","MAT2.1"]],[0,0,0,8,["GPIO0.8","I2STX_WS","MISO1","MAT2.2"]],[0,0,0,9,["GPIO0.9","I2STX_SDA","MOSI1","MAT2.3"]],[0,0,0,10,["GPIO0.10","TXD2","SDA2","MAT3.0"]],[0,0,0,11,["GPIO0.11","RXD2","SCL2","MAT3.1"]],null,null,null,[0,0,0,15,["GPIO0.15","TXD1","SCK0","SCK"]],[1,1,0,16,["GPIO0.16","RXD1","SSEL0","SSEL"]],[1,1,0,17,["GPIO0.17","CTS1","MISO0","MISO"]],[1,1,0,18,["GPIO0.18","DCD1","MOSI0","MOSI"]],[1,1,0,19,["GPIO0.19","DSR1",null,"SDA1"]],[1,1,0,20,["GPIO0.20","DTR1",null,"SCL1"]],[1,1,0,21,["GPIO0.21","RI1",null,"RD1"]],[1,1,0,22,["GPIO0.22","RTS1",null,"TD1"]],[1,1,0,23,["GPIO0.23","AD0.0","I2SRX_CLK","CAP3.0"]],[1,1,0,24,["GPIO0.24","AD0.1","I2SRX_WS","CAP3.1"]],[1,1,0,25,["GPIO0.25","AD0.2","I2SRX_SDA","TXD3"]],[1,1,0,26,["GPIO0.26","AD0.3","AOUT","RXD3"]],[1,null,null,22,["GPIO0.27","SDA0","USB_SDA",null]],[1,null,null,24,["GPIO0.28","SCL0","USB_SCL",null]],[1,null,0,29,["GPIO0.29","USB_D+",null,null]],[1,null,0,30,["GPIO0.30","USB_D-",null,null]],],P1:[[2,2,1,0,["GPIO1.0","ENET_TXD0",null,null]],[2,2,1,1,["GPIO1.1","ENET_TXD1",null,null]],null,null,[2,2,1,4,["GPIO1.4","ENET_TX_EN",null,null]],null,null,null,[2,2,1,8,["GPIO1.8","ENET_CRS",null,null]],[2,2,1,9,["GPIO1.9","ENET_RXD0",null,null]],[2,2,1,10,["GPIO1.10","ENET_RXD1",null,null]],null,null,null,[2,2,1,14,["GPIO1.14","ENET_RX_ER",null,null]],[2,2,1,15,["GPIO1.15","ENET_REF_CLK",null,null]],[3,3,1,16,["GPIO1.16","ENET_MDC",null,null]],[3,3,1,17,["GPIO1.17","ENET_MDIO",null,null]],[3,3,1,18,["GPIO1.18","USB_UP_LED","PWM1.1","CAP1.0"]],[3,3,1,19,["GPIO1.19","MCOA0","USB_PPWR","CAP1.1"]],[3,3,1,20,["GPIO1.20","MCI0","PWM1.2","SCK0"]],[3,3,1,21,["GPIO1.21","MCABORT","PWM1.3","SSEL0"]],[3,3,1,22,["GPIO1.22","MCOB0","USB_PWRD","MAT1.0"]],[3,3,1,23,["GPIO1.23","MCI1","PWM1.4","MISO0"]],[3,3,1,24,["GPIO1.24","MCI2","PWM1.5","MOSI0"]],[3,3,1,25,["GPIO1.25","MCOA1",null,"MAT1.1"]],[3,3,1,26,["GPIO1.26","MCOB1","PWM1.6","CAP0.0"]],[3,3,1,27,["GPIO1.27","CLKOUT","USB_OVRCR","CAP0.1"]],[3,3,1,28,["GPIO1.28","MCOA2","PCAP1.0","MAT0.0"]],[3,3,1,29,["GPIO1.29","MCOB2","PCAP1.1","MAT0.1"]],[3,3,1,30,["GPIO1.30",null,"VBUS","AD0.4"]],[3,3,1,31,["GPIO1.31",null,"SCK1","AD0.5"]],],P2:[[4,4,2,0,["GPIO2.0","PWM1.1","TXD1",null]],[4,4,2,1,["GPIO2.1","PWM1.2","RXD1",null]],[4,4,2,2,["GPIO2.2","PWM1.3","CTS1",null]],[4,4,2,3,["GPIO2.3","PWM1.4","DCD1",null]],[4,4,2,4,["GPIO2.4","PWM1.5","DSR1",null]],[4,4,2,5,["GPIO2.5","PWM1.6","DTR1",null]],[4,4,2,6,["GPIO2.6","PCAP1.0","RI1",null]],[4,4,2,7,["GPIO2.7","RD2","RTS1",null]],[4,4,2,8,["GPIO2.8","TD2","TXD2","ENET_MDC"]],[4,4,2,9,["GPIO2.9","USB_CONNECT","RXD2","ENET_MDIO"]],[4,4,2,10,["GPIO2.10","EINT0","NMI",null]],[4,4,2,11,["GPIO2.11","EINT1",null,"I2STX_CLK"]],[4,4,2,12,["GPIO2.12","EINT2",null,"I2STX_WS"]],[4,4,2,13,["GPIO2.13","EINT3",null,"I2STX_SDA"]],],P3:[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[7,7,3,25,["GPIO3.25",null,"MAT0.0","PWM1.2"]],[7,7,3,26,["GPIO3.26","STCLK","MAT0.1","PWM1.3"]],],P4:[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[9,9,4,28,["GPIO4.28","RX_MCLK","MAT2.0","TXD3"]],[9,9,4,29,["GPIO4.29","TX_MCLK","MAT2.1","RXD3"]]],completePinFunctionName:function j(p,o){try{for(var n=0;n<p[4].length;n++){if(p[4][n].indexOf(o)==0){return p[4][n]}}throw new MiMicException("The function name '"+o+"' is not unknown.")}catch(q){throw new MiMicException(q)}},getPinRegInfo:function d(n){try{return{s:n[0],m:n[1],o:n[2],smb:(n[3]%16)*2,ob:n[3]}}catch(o){throw new MiMicException(o)}},getPinSelByFunctionName:function h(o,q){try{for(var n=0;n<o[4].length;n++){if(o[4][n]==q){return n}}throw new MiMicException("The function name '"+q+"' has not function.")}catch(p){throw new MiMicException(p)}},hasPinFunctionName:function l(n,o){return n[4].indexOf(o)>=0}};a.I2c=function c(){throw new MiMicException("Not imprement.")};a.Dma=function k(){throw new MiMicException("Not imprement.")};a.Uart=function f(){throw new MiMicException("Not imprement.")};a.Usb=function e(){throw new MiMicException("Not imprement.")};LPCXpresso1769=a}());(function(){var f=LPCXpresso1769;var p=f._BCF;var a=f._EE;var e=MiMicLib.isUndef;function b(t){try{var v="";for(var s=0;s<t.length;s++){v+=MiMicLib.hexout(t[s],8)}return v}catch(u){throw new MiMicException(u)}}function h(w){try{function x(A,z){for(var y=0;y<A.length;y++){if(A[y]==null){continue}if(f.hasPinFunctionName(A[y],z)){return A[y]}}return null}var v=[f.P0,f.P1,f.P2,f.P3,f.P4];for(var t=0;t<v.length;t++){var s=x(v[t],w);if(s!=null){return s}}throw new MiMicException("pin function '"+w+"' not found")}catch(u){throw new MiMicException(u)}}function n(v){try{var t={GPIO:"GPIO",AD:"ADC",DA:"DAC"};for(var s in t){if(v.indexOf(s)==0){return t[s]}}throw new MiMicException("Peripheral for "+i_pinfunction+" not found.")}catch(u){throw new MiMicException(u)}}f.Mcu=function o(v,t){try{this.events={onActivateChanged:null};this._phl_holder=[];this._mif=new MiMicRemoteMcuInterface(v);var s=e(t)?true:t;if(s){this.activate()}}catch(u){throw new MiMicException(u)}};f.Mcu.prototype={_mif:null,isActive:function m(){try{return this._mif.isConnected()}catch(s){throw new MiMicException(s)}},events:null,_phl_holder:null,getClockInfo:function g(){return{cclk:100*1000*1000}},activate:function d(){try{var s=this;if(this.isActive()){throw new MiMicException("Already activated!")}this._mif.connect(function(u){if(!u){if(s.events.onActivateChanged!=null){s.events.onActivateChanged(false)}}});if(this.events.onActivateChanged!=null){this.events.onActivateChanged(true)}}catch(t){throw new MiMicException(t)}},deactivate:function c(){try{if(!this.isActive()){throw new MiMicException("Already activated!")}this._mif.disconnect();if(this.events.onActivateChanged!=null){this.events.onActivateChanged(false)}}catch(s){throw new MiMicException(s)}},callMiMic:function l(){try{var t;switch(arguments.length){case 1:t=arguments[0];break;case 2:t=arguments[0]+b(arguments[1]);break;default:throw new MiMicException(s)}return this._mif.execBc(t)}catch(s){throw new MiMicException(s)}},callMiMicWithCheck:function k(){try{var s=this.callMiMic.apply(this,arguments);if(s.result!=0){throw new MiMicException(a.VM_RUNTIME,"Result="+s.toString())}return s}catch(t){throw new MiMicException(t)}},getPin:function q(){switch(arguments.length){case 1:var s=h(arguments[0]);var t=n(arguments[0]);return this.getPeripheral(t).getPin(s);case 2:var t=n(arguments[1]);return this.getPeripheral(t).getPin(arguments[0]);default:throw new MiMicException()}},getPort:function r(s,u){switch(arguments.length){case 2:var t=n(u);return this.getPeripheral(t).getPort(s);default:throw new MiMicException()}},getPeripheral:function i(s,t){if(e(this._phl_holder[s])){switch(s){case"GPIO":new f.Gpio(this,t);break;case"ADC":new f.Adc(this,t);break;case"PWM":new f.Pwm(this,t);break;default:throw new MiMicException("Unknown peripheral symbol "+s)}}else{if(!e(t)){throw new MiMicException()}}return this._phl_holder[s]},registerPhl:function j(t,s){try{if(!e(this._phl_holder[s])){throw new MiMicException("Peripheral symbol "+s+" is already exist on mcu.")}this._phl_holder[s]=t}catch(u){throw new MiMicException(u)}}}}());(function(){var f=LPCXpresso1769;var d=f._BCF;var a=f._EE;var b=MiMicLib.isUndef;f.Memory=function e(g,h){if(!b(h)){this._base=h}this._mcu=g};f.Memory.prototype={_base:0,_mcu:null,read32:function c(){try{function o(i){if(i%4!=0){throw new MiMicException(a.INVALID_ARG,"An alignment is not 32bit unit.")}}var n="";var h=new Array();var p=arguments[0];switch(arguments.length){case 1:if(!isNaN(p)){o(p);n=d.READMEM;h.push(this._base+p)}else{for(var k=0;k<p.length;k++){o(p[k]);n+=d.getMem(this._base+p[k],h)}}break;case 2:o(p);o(arguments[1]);var g=arguments[1]/4;for(var k=0;k<g;k++){n+=d.READMEM;h.push(this._base+p+k*4)}break;default:break}var j=this._mcu.callMiMicWithCheck(n+d.END,h).stream;return j.length==1?j[0]:j}catch(m){throw new MiMicException(m)}}}}());(function(){var g=LPCXpresso1769;var f=g._BCF;var c=g._EE;var e=MiMicLib.isUndef;g.Peripheral=function(h,i,k){try{if(e(i)){throw new MiMicException(c.INVALID_PHL)}this._mcu=h;this._phl=i;if(!e(k)){this.setOpt(k)}}catch(j){throw new MiMicException(j)}};g.Peripheral.prototype={_PCLKSEL:[1074774440,1074774444],_PCONP:1074774212,_phl:null,_mcu:null,_cache:{pclk:0},BCF_setOpt:function a(k,h){try{var j="";if(!e(k.power)){if(this._phl[2]==null){throw new MiMicException(c.INVALID_CFG,"The pin does not support PCONP.")}j+=f.setBit(this._PCONP,1,k.power,this._phl[2],h)}if(!e(k.clock)){if(this._phl[0]==null){throw new MiMicException(c.INVALID_CFG,"The pin does not support PCLKSEL.")}this._cache.pclk=k.clock;j+=f.setBit(this._PCLKSEL[this._phl[0]],3,k.clock,this._phl[1],h)}return j}catch(i){throw new MiMicException(i)}},setOpt:function b(k){try{var h=new Array();var j=this.BCF_setOpt(k,h);if(j.length==0){throw new MiMicException("i_opt is empty or invalid.")}this._mcu.callMiMicWithCheck(j+f.END,h)}catch(i){throw new MiMicException(i)}return},getPCLK:function d(){try{var h=[4,1,2,0];var i=h[this._cache.pclk];var j;if(i==0){if(this._phl===g.PHL.CAN1||this._phl===g.PHL.CAN2){j=this._mcu.getClockInfo().cclk/6}else{j=this._mcu.getClockInfo().cclk/8}}else{j=this._mcu.getClockInfo().cclk/i}return Math.round(j)}catch(k){throw new MiMicException(k)}}}}());(function(){var a=LPCXpresso1769;var i=a._BCF;var j=a._EE;var d=MiMicLib.isUndef;var h={_PINSEL:[1073922048,1073922052,1073922056,1073922060,1073922064,null,null,1073922240,null,1073922084,1073922088],_PINMODE:[1073922112,1073922116,1073922120,1073922124,1073922128,1073922132,1073922136,1073922140,null,1073922148],_PINMODE_OD:[1073922152,1073922156,1073922160,1073922164,1073922168],};a.Port=function f(l,m,k){try{this._mcu=l;this._pininfo=new Array();for(var n=0;n<m.length;n++){this._pininfo.push(a.getPinRegInfo(m[n]))}if(!d(k)){this.setOpts(k)}}catch(o){throw new MiMicException(o)}};a.Port.prototype={_mcu:null,BCF_setOpts:function c(l,k){try{var r={selr:[0,0,0,0,0,0,0,0,0,0],selr_mask:[0,0,0,0,0,0,0,0,0,0],modr:[0,0,0,0,0,0,0,0,0,0],modr_mask:[0,0,0,0,0,0,0,0,0,0],odr:[0,0,0,0,0],odr_mask:[0,0,0,0,0]};if(this._pininfo.length!=l.length){throw new MiMicException()}for(var n=0;n<l.length;n++){var q=this._pininfo[n];var m=l[n];if(!d(m.sel)){r.selr[q.s]|=(m.sel<<q.smb);r.selr_mask[q.s]|=(3<<q.smb)}if(!d(m.mode)){r.modr[q.m]|=(m.mode<<q.smb);r.modr_mask[q.m]|=(3<<q.smb)}if(!d(m.od)){r.odr[q.o]|=(m.od<<q.ob);r.odr_mask[q.o]|=(1<<q.ob)}}var p="";for(var n=0;n<10;n++){if(r.selr_mask[n]!=0){p+=i.setBit(h._PINSEL[n],r.selr_mask[n],r.selr[n],0,k)}if(r.modr_mask[n]!=0){p+=i.setBit(h._PINMODE[n],r.modr_mask[n],r.modr[n],0,k)}}for(var n=0;n<5;n++){if(r.odr_mask[n]!=0){p+=i.setBit(h._PINMODE_OD[n],r.odr_mask[n],r.odr[n],0,k)}}return p}catch(o){throw new MiMicException(o)}},setOpts:function g(k){try{var l=new Array();var n=this.BCF_setOpts(k,l);if(n.length==0){throw new MiMicException("i_opt is empty or invalid.")}this._mcu.callMiMicWithCheck(n+i.END,l)}catch(m){throw new MiMicException(m)}return}};a.Pin=function b(k,l,n){try{if(d(l)){throw new MiMicException(j.INVALID_PIN)}this._port=new a.Port(k,[l],d(n)?undefined:[n])}catch(m){throw new MiMicException(m)}};a.Pin.prototype={_port:null,setOpt:function e(l){try{this._port.setOpts([l])}catch(k){throw new MiMicException(k)}return}}}());(function(){var a=LPCXpresso1769;var p=a._BCF;var q=a._EE;var d=MiMicLib.isUndef;var k=MiMicLib.cloneAssoc;a.Adc=function b(r,w){try{this._mcu=r;this._phl=new a.Peripheral(r,a.PHL.ADC);var t=d(w)?{phl:{}}:{phl:d(w.phl)?{}:k(w.phl),};if(d(t.phl.power)){t.phl.power=1}var v="";var s=new Array();v+=this.BCF_setOpt(t,s);v+=p.setMem(this._AD0CR,2098176,s);v+=p.setMem(this._AD0CR,2163712,s);this._mcu.callMiMicWithCheck(v+p.END,s);this._mcu.registerPhl(this,"ADC")}catch(u){throw new MiMicException(u)}};a.Adc.prototype={_PHL_DEF:{power:1},_AD0CR:1073954816,_AD0DR:[1073954832,1073954836,1073954840,1073954844,1073954848,1073954852,1073954856,1073954860],_phl:null,_mcu:null,BCF_setOpt:function m(u,r){try{var t="";if(!d(u.phl)){t+=this._phl.BCF_setOpt(u.phl,r)}return t}catch(s){throw new MiMicException(s)}},BCF_setSels:function j(t,s,r){try{return p.setBit(this._AD0CR,t,s*t,0,r)}catch(u){throw new MiMicException(u)}},BCF_getAD0DR:function l(s,r){try{return p.getMem(this._AD0DR[s],r)}catch(t){throw new MiMicException(t)}},setOpt:function h(u){try{var r=new Array();var t=this.BCF_setOpt(u,r);this._mcu.callMiMicWithCheck(t+p.END,r)}catch(s){throw new MiMicException(s)}},getPin:function n(r,t){try{return new a.AdcPin(this,r,t)}catch(s){throw new MiMicException(s)}},getPort:function c(r,t){try{return new a.AdcPort(this,r,t)}catch(s){throw new MiMicException(s)}}};function e(v){try{var t=a.completePinFunctionName(v,"AD");var s=t.substring(2).split(".");var u={port:0,ch:parseInt(s[1]),pin_sel:a.getPinSelByFunctionName(v,t)};if(!isNaN(u.ch)){return u}throw new MiMicException(q.INVALID_CFG,"The pin has not AD fuction.")}catch(w){throw new MiMicException(w)}}a.AdcPort=function o(s,r,x){try{this._adc=s;this._pins=new Array();for(var u=0;u<r.length;u++){this._pins.push(e(r[u]))}var w=this._pins[0].port;for(var u=1;u<this._pins.length;u++){if(w!=this._pins[1].port){throw new MiMicException("Invalid pin combination.")}}this._port=new a.Port(s._mcu,r);this._port_no=w;this._adcr_mask=0;for(var u=0;u<this._pins.length;u++){this._adcr_mask|=(1<<this._pins[u].ch)}var t=k(x);t.sel=1;if(d(t.pin)){t.pin={}}if(d(t.pin.sel)){t.pin.sel=this._PINSEL_AUTO_DETECT}this.setOpt(t)}catch(v){throw new MiMicException(v)}};a.AdcPort.prototype={_PINSEL_AUTO_DETECT:268435455,_adc:null,_pins:null,_port_no:0,_port:null,_adcr_mask:0,setOpt:function h(y){try{var r=new Array();var x="";if(!d(y.pin)){var v=new Array();for(var t=0;t<this._pins.length;t++){var u=(y.pin.sel==this._PINSEL_AUTO_DETECT)?this._pins[t].pin_sel:y.pin.sel;v.push({sel:u,mode:y.pin.mode,od:y.pin.od})}}x+=this._port.BCF_setOpts(v,r);x+=this._adc.BCF_setSels(this._adcr_mask,y.sel,r);this._adc._mcu.callMiMicWithCheck(x+p.END,r);return}catch(w){throw new MiMicException(w)}},getValues:function i(){try{var s=new Array();var x="";for(var u=0;u<this._pins.length;u++){x+=this._adc.BCF_getAD0DR(this._pins[u].ch,s)}var t=this._adc._mcu.callMiMicWithCheck(x+p.END,s);var v=new Array();for(var u=0;u<this._pins.length;u++){v.push((t.stream[u]>>4)&4095)}return v}catch(w){throw new MiMicException(w)}}};a.AdcPin=function f(r,s,u){try{this._aport=new a.AdcPort(r,[s],u)}catch(t){throw new MiMicException(t)}};a.AdcPin.prototype={_aport:null,getValue:function g(){try{return this._aport.getValues()[0]}catch(r){throw new MiMicException(r)}},setOpt:function h(s){try{this._aport.setOpt(s)}catch(r){throw new MiMicException(r)}}}}());(function(){var g=LPCXpresso1769;var o=g._BCF;var a=g._EE;var f=MiMicLib.isUndef;var m=MiMicLib.cloneAssoc;g.Gpio=function q(s,u){try{this._mcu=s;s.registerPhl(this,"GPIO")}catch(t){throw new MiMicException(t)}};g.Gpio.prototype={_FIO_DIR:[537509888,537509920,537509952,537509984,537510016],_FIO_PIN:[537509908,537509940,537509972,537510004,537510036],_FIO_SET:[537509912,537509944,537509976,537510008,537510040],_FIO_CLR:[537509916,537509948,537509980,537510012,537510044],_FIO_MASK:[537509904,537509936,537509968,537510000,537510032],_mcu:null,BCF_getValues:function k(t,u,s){try{s.push(this._FIO_PIN[t],this._FIO_MASK[t],~u);return"EA00EA01EA02DF0201DB0300EE03"}catch(v){throw new MiMicException(v)}},BCF_setValues:function h(u,v,t,s){try{s.push(this._FIO_PIN[u],this._FIO_MASK[u],~v,t);return"EA00EA01EA02EA03DF0201DF0300"}catch(w){throw new MiMicException(w)}},BCF_setDirs:function e(t,u,v,s){try{return o.setBit(this._FIO_DIR[t],u,u*v,0,s)}catch(w){throw new MiMicException(w)}},getPin:function p(s,u){try{return new g.GpioPin(this,s,u)}catch(t){throw new MiMicException(t)}},getPort:function r(s,u){try{return new g.GpioPort(this,s,u)}catch(t){throw new MiMicException(t)}}};function j(v){try{var t=g.completePinFunctionName(v,"GPIO");var s=t.substring(4).split(".");var u={port:parseInt(s[0]),bit:parseInt(s[1]),pin_sel:g.getPinSelByFunctionName(v,t)};if(!isNaN(u.port)&&!isNaN(u.bit)){return u}throw new MiMicException(a.INVALID_CFG,"The pin has not GPIO fuction.")}catch(w){throw new MiMicException(w)}}g.GpioPort=function n(v,s,y){try{this._gpio=v;this._pins=new Array();for(var u=0;u<s.length;u++){this._pins.push(j(s[u]))}var x=this._pins[0].port;for(var u=1;u<this._pins.length;u++){if(x!=this._pins[1].port){throw new MiMicException("Invalid pin combination.")}}this._port=new g.Port(v._mcu,s);this._port_no=x;this._mask=0;for(var u=0;u<this._pins.length;u++){this._mask|=(1<<this._pins[u].bit)}var t=m(y);if(f(t.pin)){t.pin={}}if(f(t.pin.sel)){t.pin.sel=this._PINSEL_AUTO_DETECT}this.setOpt(t)}catch(w){throw new MiMicException(w)}};g.GpioPort.prototype={_PINSEL_AUTO_DETECT:268435455,_pins:null,_gpio:null,_port_no:0,_port:null,_mask:0,setOpt:function b(z){try{var t=new Array();var y="";if(!f(z.dir)){y+=this._gpio.BCF_setDirs(this._port_no,this._mask,z.dir,t)}if(!f(z.pin)){var w=new Array();for(var u=0;u<this._pins.length;u++){var v=(z.pin.sel==this._PINSEL_AUTO_DETECT)?this._pins[u].pin_sel:z.pin.sel;w.push({sel:v,mode:z.pin.mode,od:z.pin.od})}}y+=this._port.BCF_setOpts(w,t);this._gpio._mcu.callMiMicWithCheck(y+o.END,t);return}catch(x){throw new MiMicException(x)}},setValue:function c(x){try{var w=0;var t=this._pins.length;for(var y=0;y<t;y++){var s=((x>>y)&1);w|=(s<<this._pins[y].bit)}var u=new Array();var A=this._gpio.BCF_setValues(this._port_no,this._mask,w,u);this._gpio._mcu.callMiMicWithCheck(A+o.END,u)}catch(z){throw new MiMicException(z)}},getValue:function d(){try{var w=new Array();var z=this._gpio.BCF_getValues(this._port_no,this._mask,w);var t=this._gpio._mcu.callMiMicWithCheck(z+o.END,w).stream[0];var u=0;for(var x=this._pins.length-1;x>=0;x--){var s=((t>>this._pins[x].bit)&1);u=(u<<1)|s}return u}catch(y){throw new MiMicException(y)}},outPatt:function i(w){try{var B=new Array();var y="";for(var s=0;s<w.length;s++){var z=0;var t=this._pins.length;for(var u=0;u<t;u++){var A=((w[s]>>u)&1);z|=(A<<this._pins[u].bit)}y+=this._gpio.BCF_setValues(this._port_no,this._mask,z,B)}this._gpio._mcu.callMiMicWithCheck(y+o.END,B)}catch(x){throw new MiMicException(x)}}};g.GpioPin=function l(s,t,v){try{this._gport=new g.GpioPort(s,[t],v)}catch(u){throw new MiMicException(u)}};g.GpioPin.prototype={_gport:null,setOpt:function b(t){try{this._gport.setOpt(t)}catch(s){throw new MiMicException(s)}},setValue:function c(s){try{this._gport.setValue(s)}catch(t){throw new MiMicException(t)}},getValue:function d(){try{return this._gport.getValue()}catch(s){throw new MiMicException(s)}},outPatt:function i(s){try{this._gport.outPatt(s)}catch(t){throw new MiMicException(t)}},}}());(function(){var f=LPCXpresso1769;var o=f._BCF;var a=f._EE;var d=MiMicLib.isUndef;var m=MiMicLib.cloneAssoc;f.Pwm=function j(t,y){try{this._mcu=t;this._phl=new f.Peripheral(t,f.PHL.PWM1);var v=d(y)?{phl:{}}:{phl:d(y.phl)?{}:m(y.phl),freq:y.freq};if(d(v.phl.power)){v.phl.power=1}if(d(v.phl.clock)){v.phl.clock=0}if(d(v.freq)){v.freq=100}var x="";var u=new Array();x+=this.BCF_setOpt(v,u);x+=o.setMem(this._PC,0,u);x+=o.setMem(this._PCR,0,u);x+=o.setMem(this._CTCR,0,u);x+=o.setMem(this._TCR,0,u);x+=o.setMem(this._TC,0,u);x+=o.setMem(this._TCR,9,u);this._mcu.callMiMicWithCheck(x+o.END,u);this._mcu.registerPhl(this,"PWM")}catch(w){throw new MiMicException(w)}};f.Pwm.prototype={_cache:{mr0:0},_TCR:1073840132,_TC:1073840136,_PR:1073840140,_PC:1073840144,_MCR:1073840152,_PCR:1073840204,_LER:1073840208,_CTCR:1073840240,_MRn:[1073840152,1073840156,1073840160,1073840164,1073840192,1073840196,1073840200],_phl:null,_mcu:null,BCF_setOpt:function l(y,t){try{var x="";var v;var u;if(!d(y.phl)){x+=this._phl.BCF_setOpt(y.phl,t)}if(!d(y.freq)){u=Math.round(this._phl.getPCLK()/y.freq);if(u<=0){throw new MiMicException("The peripheral clock too small.")}x+=this.BCF_setMRn(0,u,t);x+=this.BCF_setLER(0,t);this._cache.mr0=u}return x}catch(w){throw new MiMicException(w)}},BCF_setLER:function b(u,t){try{return o.setBit(this._LER,1,1,u,t)}catch(v){throw new MiMicException(v)}},BCF_setLERs:function k(v,u,t){try{return o.setBit(this._LER,v,u*v,0,t)}catch(w){throw new MiMicException(w)}},BCF_setMRn:function i(v,u,t){try{return o.setMem(this._MRn[v],u,t)}catch(w){throw new MiMicException(w)}},BCF_setMRnByDuty:function e(u,v,t){try{return this.BCF_setMRn(u,Math.round(v*this._cache.mr0),t)}catch(w){throw new MiMicException(w)}},BCF_setPCRbits:function g(B,x,y,w){try{var u,z;u=z=0;if(!d(x)){var A=255&B;z|=x*A;u|=A}if(!d(y)){var A=65280&B;z|=(y*A);u|=A}return o.setBit(this._PCR,u,z,0,w)}catch(C){throw new MiMicException(C)}},setOpt:function c(w){try{var t=new Array();var v=this.BCF_setOpt(w,t);this._mcu.callMiMicWithCheck(v+o.END,t)}catch(u){throw new MiMicException(u)}},getPin:function p(t,v){try{return new f.PwmPin(this,t,v)}catch(u){throw new MiMicException(u)}},getPort:function r(t,v){try{return new f.PwmPort(this,t,v)}catch(u){throw new MiMicException(u)}}};function h(w){try{var u=f.completePinFunctionName(w,"PWM");var t=u.substring(2).split(".");var v={port:0,ch:parseInt(t[1]),pin_sel:f.getPinSelByFunctionName(w,u)};if(!isNaN(v.ch)){return v}throw new MiMicException(a.INVALID_CFG,"The pin has not PWM fuction.")}catch(x){throw new MiMicException(x)}}f.PwmPort=function q(u,t,z){try{this._pwm=u;this._pins=new Array();for(var w=0;w<t.length;w++){this._pins.push(h(t[w]))}var y=this._pins[0].port;for(var w=1;w<this._pins.length;w++){if(y!=this._pins[1].port){throw new MiMicException("Invalid pin combination.")}}this._port=new f.Port(u._mcu,t);this._port_no=y;this._ler_mask=0;this._pcr_mask=0;for(var w=0;w<this._pins.length;w++){this._ler_mask|=(1<<this._pins[w].ch);this._pcr_mask|=(257<<this._pins[w].ch)}var v=d(z)?{pin:{}}:{pin:d(z.pin)?{}:m(z.pin),duty:z.duty,enable:z.enable};if(d(v.pin.sel)){v.pin.sel=this._PINSEL_AUTO_DETECT}if(d(v.duty)){v.duty=0}if(d(v.enable)){v.enable=1}this.setOpt(v)}catch(x){throw new MiMicException(x)}};f.PwmPort.prototype={_PINSEL_AUTO_DETECT:268435455,_pwm:null,_pins:null,_port_no:0,_port:null,_pcr_mask:0,_ler_mask:0,setOpt:function c(z){try{var t=new Array();var y="";if(!d(z.pin)){var w=new Array();for(var u=0;u<this._pins.length;u++){var v=(z.pin.sel==this._PINSEL_AUTO_DETECT)?this._pins[u].pin_sel:z.pin.sel;w.push({sel:v,mode:z.pin.mode,od:z.pin.od})}}y+=this._port.BCF_setOpts(w,t);if(!d(z.enable)){y+=this._pwm.BCF_setPCRbits(this._pcr_mask,0,z.enable,t)}if(!d(z.duty)){for(var u=0;u<this._pins.length;u++){y+=this._pwm.BCF_setMRnByDuty(this._pins[u].ch,z.duty,t)}y+=this._pwm.BCF_setLERs(this._ler_mask,1,t)}this._pwm._mcu.callMiMicWithCheck(y+o.END,t);return}catch(x){throw new MiMicException(x)}},setDuty:function n(x){try{if(x.length!=this._pins.length){throw new MiMicException(v)}var w="";var t=new Array();for(var u=0;u<this._pins.length;u++){if(!d(x[u])){w+=this._pwm.BCF_setMRnByDuty(this._pins[u].ch,x[u],t)}}w+=this._pwm.BCF_setLERs(this._ler_mask,1,t);this._pwm._mcu.callMiMicWithCheck(w+o.END,t)}catch(v){throw new MiMicException(v)}}};f.PwmPin=function s(t,u,w){try{this._pport=new f.PwmPort(t,[u],w)}catch(v){throw new MiMicException(v)}};f.PwmPin.prototype={_pport:null,setOpt:function c(u){try{this._pport.setOpt(u)}catch(t){throw new MiMicException(t)}},setDuty:function n(t){try{this._pport.setDuty([t])}catch(u){throw new MiMicException(u)}}}}());(function(){var f=LPCXpresso1769;var e=f._BCF;var a=f._EE;var d=MiMicLib.isUndef;f.Ni=function c(g){try{this._mcu=g}catch(h){throw new MiMicException(h)}};f.Ni.prototype={call:function b(j,q,p){var n="";var r=new Array();if(!d(q)){for(var l=0;l<8;l++){var k="wm"+l;if(!d(q[k])){n+="FB"+MiMicLib.hexout(l,2)+MiMicLib.hexout(q[k],8)}}if(!d(q.stream)){for(var l=0;l<q.stream.length;l++){r.push(q.stream[l])}}}n+="ZF"+MiMicLib.hexout(j,8);var g=0;if(!d(p)){for(var l=0;l<8;l++){if(!d(p["wm"+l])){n+="EE"+MiMicLib.hexout(l,2);g++}}}var m=this._mcu.callMiMic(n+e.END,r);if(m.result!=0){return false}var o=0;if(!d(p)){var h=m.stream.length-g;for(var l=0;l<8;l++){var k="wm"+l;if(!d(p[k])){p[k]=m.stream[h];h++}}if(!d(p.stream)){p.stream=m.stream.slice(0,m.stream.length-g)}}return false}}}());
\ No newline at end of file
index 1385dc4..57674be 100644 (file)
@@ -809,7 +809,7 @@ LPCXpresso1769=DEV;
                 * @param {object as pin識別子} i_pin\r
                 * ピン識別子。指定できるのは、LPCXpresso1796.P?[?]である。\r
                 * @param {string as 機能名} i_function_name\r
-                * æ©\9fè\83½å\90\8dã\81¯文字列である。 指定できる文字列は、LPCXpresso1769.FUNC_NAMEで定義する。\r
+                * æ©\9fè\83½å\90\8dã\81®文字列である。 指定できる文字列は、LPCXpresso1769.FUNC_NAMEで定義する。\r
                 * @return {object as PinObject}\r
                 * @example\r
                 * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
@@ -862,16 +862,33 @@ LPCXpresso1769=DEV;
                        }\r
                },\r
                /**\r
-                * 未実装である。\r
                 * ポート(複数ピンで構成するIO)を制御するPortインスタンスを得るする。\r
                 * 制御ペリフェラル、Portを順に生成する方法と異なり、機能の実現に必要なインスタンスを自動的に生成する。\r
                 * Portが生成できない場合、例外が発生する。\r
                 * @name LPCXpresso1769.Mcu#getPort\r
-                * @function             \r
+                * @function \r
+                * @param {array[PIN識別子]} i_pins\r
+                * ポートを構成するピン識別子の配列。順序は生成するポートの説明を参照。\r
+                * @param {string} i_function_name\r
+                * 機能名の文字列である。 指定できる文字列は、LPCXpresso1769.FUNC_NAMEで定義する。\r
+                * @return {object as PortObject}\r
+                * 返却されるインスタンスのクラスは、機能により異なる。機能とインスタンスのクラスの対応は、以下の通りである。\r
+                * <ul>\r
+                * <li>GPIO - LPCXpresso1769.GpioPin</li>\r
+                * <li>AD - LPCXpresso1769.AdcPin</li>\r
+                * <li>PWM - LPCXpresso1769.PwmPin</li>\r
+                * </ul>                 \r
                 */\r
-               getPort:function getPort(i_port_name)\r
+               getPort:function getPort(i_pins,i_function_name)\r
                {\r
-                       throw new MiMicException("Not implemented.");\r
+                       switch(arguments.length){\r
+                       case 2://getPin:function getPin(i_pins,i_function_name)\r
+                               //function名からペリフェラル名を得る。(PINシンボル変換を流用)\r
+                               var phl_name=pinFuncName2PhlName(i_function_name);\r
+                               return this.getPeripheral(phl_name).getPort(i_pins);\r
+                       default:\r
+                               throw new MiMicException();\r
+                       }\r
                },\r
                /**\r
                 * ペリフェラル名から、ペリフェラルオブジェクトを得る。\r
@@ -1592,7 +1609,7 @@ DEV.Adc.prototype=
         * //create 2AdcPort that has 2 pins.\r
         * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
         * var adc=new LPCXpresso1769.Adc(mcu);\r
-        * var adpin=adc.getPort([LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]);\r
+        * var port=adc.getPort([LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]);\r
         */\r
        getPort:function getPort(i_pins,i_opt)\r
        {\r
@@ -1950,6 +1967,14 @@ DEV.Gpio.prototype={
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
+       },\r
+       getPort:function getPort(i_pins,i_opt)\r
+       {\r
+               try{\r
+                       return new DEV.GpioPort(this,i_pins,i_opt);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
        }\r
 }\r
 \r
@@ -2363,8 +2388,21 @@ DEV.Pwm.prototype=
        },\r
        BCF_setLER:function BCF_setLER(i_ch,i_db)\r
        {\r
-               //LERにビットをセット\r
-               return BCF.setBit(this._LER,0x01,0x01,i_ch,i_db);\r
+               try{\r
+                       //LERにビットをセット\r
+                       return BCF.setBit(this._LER,0x01,0x01,i_ch,i_db);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
+       },\r
+       BCF_setLERs:function BCF_setLERs(i_mask,i_value,i_db)\r
+       {\r
+               try{\r
+                       //LERにビットをセット\r
+                       return BCF.setBit(this._LER,i_mask,i_value*i_mask,0,i_db);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
        },\r
        \r
        /**\r
@@ -2391,32 +2429,34 @@ DEV.Pwm.prototype=
         * PCRに値を設定するBC\r
         i_ch=1の場合、エッジモードは無視します。\r
         @private\r
-        @param i_ch\r
-        1-6\r
+        @param i_mask\r
         @param i_edge\r
         エッジモード(1/0)\r
         @param i_en\r
        有効/無効の選択\r
         */\r
-       BCF_setPCRbit:function BCF_setPCR(i_ch,i_edge,i_en,i_db)\r
+       BCF_setPCRbits:function BCF_setPCRbits(i_mask,i_edge,i_en,i_db)\r
        {\r
                try{\r
                        var m,v;\r
                        m=v=0;\r
                        if(!isUndef(i_edge)){\r
-                               v|=i_edge;\r
-                               m|=0x00000001;\r
+                               var t=0xff&i_mask;\r
+                               v|=i_edge*t;\r
+                               m|=t;\r
                        }\r
                        if(!isUndef(i_en)){\r
-                               v|=(i_en<<8);\r
-                               m|=0x00000100;\r
+                               var t=0xff00&i_mask;\r
+                               v|=(i_en*t);\r
+                               m|=t;\r
                        }\r
                        //ビットの設定\r
-                       return BCF.setBit(this._PCR,m,v,i_ch,i_db);\r
+                       return BCF.setBit(this._PCR,m,v,0,i_db);\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
        },\r
+       \r
        /**\r
         * Pwmペリフェラルに値を設定する。\r
         * 設定する値は、全てのPWMチャンネル(PIN)に共通な項目である。\r
@@ -2472,102 +2512,256 @@ DEV.Pwm.prototype=
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
+       },\r
+       /**\r
+        * PWM機能を持つポート(Pin集合)を取得する。\r
+        * ピン識別子で指定されるピンのセットをPWMペリフェラルと結合して、PwmPortを生成する。\r
+        * 関数は、PwmPortのコンストラクタをコールする。\r
+        * 生成ルールについては、PwmPort関数を参照すること。\r
+        * @name LPCXpresso1769.Pwm#getPort\r
+        * @function\r
+        * @param {array[ピン識別子]} i_pin\r
+        * Pwm機能を割り当てるPINの識別子の配列である。値は、LPCXpresso1769.Pn[m]のメンバ変数である。\r
+        * @param {object as associative array} i_opt\r
+        * AdcPortのコンストラクタに渡すオプション値。省略時はundefinedである。詳細はLPCXpresso1769.PwmPort.setOptを参照。\r
+        * @return {object as LPCXpresso1769.PwmPort}\r
+        * LPCXpresso1769.PwmPortクラスのオブジェクトである。\r
+        * @example\r
+        * //create 2AdcPort that has 2 pins.\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
+        * var pwm=new LPCXpresso1769.Pwm(mcu);\r
+        * var port=pwm.getPort([LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]);\r
+        */\r
+       getPort:function getPort(i_pins,i_opt)\r
+       {\r
+               try{\r
+                       return new DEV.PwmPort(this,i_pins,i_opt);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
        }       \r
 }\r
 \r
 /**\r
- * PwmペリフェラルとPin識別子から、シングルエッジPwmピンを構成する。\r
- * Pwmペリフェラルオブジェクトにピン識別子で指定されたピンを関連付けて、PWM機能を持つピンを生成する。\r
- * 関数は、ピン識別子を元に、そのピンがPWM機能に接続できるかを調べる。ピンにPWM機能を割り当てられない場合、例外が発生する。どのピンにPWM機能が割り当てられるかは、MCUのスペックシートを参照すること。\r
- * ピンがPWM機能を持たない場合、例外が発生する。\r
+ * Pwm pinからPwmInfoを取得\r
+ * @private\r
+ */\r
+function pin2PwmPinInfo(i_pin)\r
+{\r
+       try{\r
+               //pinの完全な機能名を得る。(得られれば機能がある。)\r
+               var fn=DEV.completePinFunctionName(i_pin,"PWM");\r
+               //portとbitを得る(AD0だけしか管理しないよ)\r
+               var a=fn.substring(2).split(".");\r
+               var r={port:0,ch:parseInt(a[1]),pin_sel:DEV.getPinSelByFunctionName(i_pin,fn)};\r
+               if(!isNaN(r.ch)){\r
+                       return r;\r
+               }\r
+               throw new MiMicException(EE.INVALID_CFG,"The pin has not PWM fuction.");\r
+       }catch(e){\r
+               throw new MiMicException(e);    \r
+       }\r
+}\r
+/**\r
+ * Pwmペリフェラルと複数のPin識別子から、シングルエッジPwmポートを構成する。\r
+ * Pwmペリフェラルオブジェクトにピン識別子の配列で指定されたピンを関連付けて、PWM機能を持つポートを生成する。\r
+ * 関数は、ピン識別子を元に、それぞれのピンがPWM機能に接続できるかを調べる。\r
+ * ピンにPWM機能を割り当てられない場合、例外が発生する。どのピンにPWM機能が割り当てられるかは、MCUのスペックシートを参照すること。\r
+ * PWMポートは、複数の同一周期のPWMピンのデューティ比を、同期して操作するときに便利である。\r
  * @constructor\r
- * @name LPCXpresso1769.PwmPin\r
+ * @name LPCXpresso1769.PwmPort\r
  * @param {object as LPCXpresso1769.Pwm} i_pwm\r
- * インスタンスを結びつけるAdcオブジェクト。\r
- * @param {object as pin識別子} i_pin\r
- * ピン識別子。指定できるのは、LPCXpresso1796.P?[?]である。\r
+ * インスタンスを結びつけるPwmオブジェクト。\r
+ * @param {array[pin識別子]} i_pins\r
+ * ã\83\94ã\83³è­\98å\88¥å­\90ã\81®é\85\8då\88\97ã\80\82æ\8c\87å®\9aã\81§ã\81\8dã\82\8bã\81®ã\81¯ã\80\81LPCXpresso1796.P?[?]ã\81§ã\81\82ã\82\8bã\80\82\r
  * @param {object as associative array} i_opt\r
  * setOpt関数のi_optに渡すパラメタである。省略可能。省略時は{duty:100,enable:1,pin{sel:auto}}を設定する。\r
  * autoは、関数が自動的に決定するPINSELの値である。詳細はsetOpt関数を参照。 \r
+ * dutyをピン毎に設定する場合は、setDuty関数を使うこと。\r
  * @example\r
- * //create PWM1.0\r
+ * //create PWM1.0,PWM1.1\r
  * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
  * var pwm=new LPCXpresso1769.Pwm(mcu,{freq:100});\r
- * var pwmpin=new LPCXpresso1769.PwmPin(pwm,P2[0]); \r
+ * var port=new LPCXpresso1769.PwmPort(pwm,[LPCXpresso1769.P2[0],LPCXpresso1769.P2[1]]); \r
  */\r
-DEV.PwmPin=function PwmPin(i_pwm,i_pin,i_opt)\r
+DEV.PwmPort=function PwmPort(i_pwm,i_pins,i_opt)\r
 {\r
        try{\r
                this._pwm=i_pwm;\r
-               //PINがPWM持ってるか確認\r
-               this._pin=new DEV.Pin(i_pwm._mcu,i_pin);\r
-               //PinNameからピン情報を得る。\r
-               this._pwminfo=function(i_pin){\r
-                       //pinの完全な機能名を得る。(得られれば機能がある。)\r
-                       var func_name=DEV.completePinFunctionName(i_pin,"PWM");\r
-                       //portとbitを得る(AD0だけしか管理しないよ)\r
-                       var a=func_name.substring(2).split(".");\r
-                       var r={port:0,ch:parseInt(a[1]),pin_sel:DEV.getPinSelByFunctionName(i_pin,func_name)};\r
-                       if(!isNaN(r.ch)){\r
-                               return r;\r
+               //ピンセットを取得\r
+               this._pins=new Array();\r
+               //pinに変換する。\r
+               for(var i=0;i<i_pins.length;i++){\r
+                       this._pins.push(pin2PwmPinInfo(i_pins[i]));\r
+               }\r
+               //pinが全て同じポートに所属しているか確認\r
+               var p=this._pins[0].port;\r
+               for(var i=1;i<this._pins.length;i++){\r
+                       if(p!=this._pins[1].port){\r
+                               throw new MiMicException("Invalid pin combination.");\r
                        }\r
-                       throw new MiMicException(EE.INVALID_CFG,"The pin has not PWM fuction.");\r
-               }(i_pin);\r
-               //設定用のBCを作って実行\r
-               {\r
-                       var opt=isUndef(i_opt)?{pin:{}}:\r
-                       {\r
-                               pin:isUndef(i_opt.pin)?{}:cloneAssoc(i_opt.pin),\r
-                               duty:i_opt.duty,\r
-                               enable:i_opt.enable\r
-                       };\r
-                       //デフォルト値のロード\r
-                       if(isUndef(opt.pin.sel)){ opt.pin.sel=this._pwminfo.pin_sel;}\r
-                       if(isUndef(opt.duty)){opt.duty=0;}\r
-                       if(isUndef(opt.enable)){opt.enable=1;}\r
-                       this.setOpt(opt);\r
                }\r
+               //ポートの生成\r
+               this._port=new DEV.Port(i_pwm._mcu,i_pins);\r
+               this._port_no=p;\r
+               \r
+               this._ler_mask=0;\r
+               this._pcr_mask=0;\r
+               for(var i=0;i<this._pins.length;i++){\r
+                       this._ler_mask|=(0x1<<this._pins[i].ch);\r
+                       this._pcr_mask|=(0x101<<this._pins[i].ch);\r
+               }               \r
+               var opt=isUndef(i_opt)?{pin:{}}:\r
+               {\r
+                       pin:isUndef(i_opt.pin)?{}:cloneAssoc(i_opt.pin),\r
+                       duty:i_opt.duty,\r
+                       enable:i_opt.enable\r
+               };\r
+               //デフォルト値のロード\r
+               if(isUndef(opt.pin.sel)){opt.pin.sel=this._PINSEL_AUTO_DETECT;}\r
+               if(isUndef(opt.duty)){opt.duty=0;}\r
+               if(isUndef(opt.enable)){opt.enable=1;}\r
+               this.setOpt(opt);\r
        }catch(e){\r
                throw new MiMicException(e);\r
-       }\r
+       }       \r
 }\r
-\r
-DEV.PwmPin.prototype=\r
+DEV.PwmPort.prototype=\r
 {\r
+       _PINSEL_AUTO_DETECT:0x0fffffff,\r
        _pwm:null,\r
-       _pin:null,\r
-       _pwminfo:null,\r
+       _pins:null,\r
+       _port_no:0,\r
+       _port:null,\r
+       _pcr_mask:0,\r
+       _ler_mask:0,\r
        /**\r
-        * \r
-        @private\r
-        @param i_opt\r
-        シングルエッジPWMのオプション値を設定する。\r
-        {pin:{ピン初期化パラメタ},enable:有効値,duty:デューティ比}}
+        * PWMポートにオプション値を設定する。\r
+        * ポートを構成する全てのピンに同じ値が設定される。\r
+        * @name LPCXpresso1769.PwmPort#setOpt\r
+        * @function\r
+        * @param {object as associative array} i_opt\r
+        * PWMピンのコンフィグレーションパラメタである。必要な値を格納した連想配列で指定する。\r
+        * 全ての値を省略することは出来ない。連想配列のメンバは以下の通り。\r
+        * <pre>{pin:{associative array},enable:int,duty:double}</pre>\r
+        * <ul>\r
+        * <li>pin - LPCXpresso1769.Pin#setOpt関数のi_optに渡すパラメタである。</li>\r
+        * <li>enable - PWMの有効/無効を切り替える。1で有効。</li>\r
+        * <li>duty - デューティ比である。0.0<=n<=1.0のdouble値を指定する。</li>\r
+        * </ul>\r
+        * @example\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
+        * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
+        * var port=pwm.getPort([LPCXpresso1769.P2[0]]);\r
+        * port.setOpt({enable:0});\r
         */\r
-       BCF_setOpt:function BCF_setOpt(i_opt,i_db)\r
+       setOpt:function setOpt(i_opt)\r
        {\r
                try{\r
+                       var db=new Array();\r
+                       //BCの生成\r
                        var bc="";\r
-                       //pinselの値\r
+                       //i_optの展開\r
                        if(!isUndef(i_opt.pin)){\r
-                               //PINSEL設定\r
-                               bc+=this._pin.BCF_setOpt(i_opt.pin,i_db);\r
+                               var optset=new Array();\r
+                               for(var i=0;i<this._pins.length;i++){\r
+                                       //pinselが_PINSEL_AUTO_DETECTならばauto。そうでなければundefinedも含めて設定\r
+                                       var s=(i_opt.pin.sel==this._PINSEL_AUTO_DETECT)?this._pins[i].pin_sel:i_opt.pin.sel;\r
+                                       optset.push({sel:s,mode:i_opt.pin.mode,od:i_opt.pin.od});\r
+                               }\r
                        }\r
+                       //portの設定\r
+                       bc+=this._port.BCF_setOpts(optset,db);\r
                        //PCRに値設定\r
                        if(!isUndef(i_opt.enable)){\r
-                               bc+=this._pwm.BCF_setPCRbit(this._pwminfo.ch,0,i_opt.enable,i_db);\r
+                               bc+=this._pwm.BCF_setPCRbits(this._pcr_mask,0,i_opt.enable,db);\r
                        }\r
-                       //MRnに値設定してLERにセット\r
+                       //デューティ比を\r
                        if(!isUndef(i_opt.duty)){\r
-                               bc+=this._pwm.BCF_setMRnByDuty(this._pwminfo.ch,i_opt.duty,i_db);\r
-                               bc+=this._pwm.BCF_setLER(this._pwminfo.ch,i_db);\r
+                               //デューティ比を設定\r
+                               for(var i=0;i<this._pins.length;i++){\r
+                                       bc+=this._pwm.BCF_setMRnByDuty(this._pins[i].ch,i_opt.duty,db);\r
+                               }\r
+                               //LERにセット\r
+                               bc+=this._pwm.BCF_setLERs(this._ler_mask,1,db);\r
                        }\r
-                       return bc;\r
+                       this._pwm._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
+                       return;\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
        },\r
        /**\r
+        * PWMポートのデューティ比をまとめて変更する。\r
+        * @name LPCXpresso1769.PwmPort#setDuty\r
+        * @function\r
+        * @param {array[double]} i_duty_array\r
+        * デューティ比の配列である。0.0<=n<=1.0のdouble値を指定する。\r
+        * ポートを構成するピンの数だけ指定する。変更しないピンには、undefinedを指定すること。\r
+        * @example\r
+        * varmcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
+        * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
+        * var port=pwm.getPort([LPCXpresso1769.P2[0],LPCXpresso1769.P2[1]]);\r
+        * pwm.setDuty([0.5,0.0]);//PWM0=0.5,PWM1=0.0\r
+        * pwm.setDuty([undefined,0.0]);//PWM1=0.0\r
+        */     \r
+       setDuty:function setDuty(i_duty_array)\r
+       {\r
+               try{\r
+                       if(i_duty_array.length!=this._pins.length){\r
+                               throw new MiMicException(e);\r
+                       }\r
+                       var bc="";\r
+                       var db=new Array();\r
+                       //デューティ比をまとめてセット\r
+                       for(var i=0;i<this._pins.length;i++){\r
+                               if(!isUndef(i_duty_array[i])){\r
+                                       bc+=this._pwm.BCF_setMRnByDuty(this._pins[i].ch,i_duty_array[i],db);\r
+                               }\r
+                       }\r
+                       //LERにセット\r
+                       bc+=this._pwm.BCF_setLERs(this._ler_mask,1,db);\r
+                       this._pwm._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
+       }\r
+}\r
+/**\r
+ * PwmペリフェラルとPin識別子から、シングルエッジPwmピンを構成する。\r
+ * Pwmペリフェラルオブジェクトにピン識別子で指定されたピンを関連付けて、PWM機能を持つピンを生成する。\r
+ * 関数は、ピン識別子を元に、そのピンがPWM機能に接続できるかを調べる。ピンにPWM機能を割り当てられない場合、例外が発生する。どのピンにPWM機能が割り当てられるかは、MCUのスペックシートを参照すること。\r
+ * ピンがPWM機能を持たない場合、例外が発生する。\r
+ * @constructor\r
+ * @name LPCXpresso1769.PwmPin\r
+ * @param {object as LPCXpresso1769.Pwm} i_pwm\r
+ * インスタンスを結びつけるAdcオブジェクト。\r
+ * @param {object as pin識別子} i_pin\r
+ * ピン識別子。指定できるのは、LPCXpresso1796.P?[?]である。\r
+ * @param {object as associative array} i_opt\r
+ * setOpt関数のi_optに渡すパラメタである。省略可能。省略時は{duty:100,enable:1,pin{sel:auto}}を設定する。\r
+ * autoは、関数が自動的に決定するPINSELの値である。詳細はsetOpt関数を参照。 \r
+ * @example\r
+ * //create PWM1.0\r
+ * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
+ * var pwm=new LPCXpresso1769.Pwm(mcu,{freq:100});\r
+ * var pwmpin=new LPCXpresso1769.PwmPin(pwm,P2[0]); \r
+ */\r
+DEV.PwmPin=function PwmPin(i_pwm,i_pin,i_opt)\r
+{\r
+       try{\r
+               //1pinのポートとして実装\r
+               this._pport=new DEV.PwmPort(i_pwm,[i_pin],i_opt);\r
+       }catch(e){\r
+               throw new MiMicException(e);\r
+       }\r
+}\r
+\r
+DEV.PwmPin.prototype=\r
+{\r
+       _pport:null,\r
+\r
+       /**\r
         * PWMピンにオプション値を設定する。\r
         * @name LPCXpresso1769.PwmPin#setOpt\r
         * @function\r
@@ -2581,16 +2775,15 @@ DEV.PwmPin.prototype=
         * <li>duty - デューティ比である。0.0<=n<=1.0のdouble値を指定する。</li>\r
         * </ul>\r
         * @example\r
-        * var  mcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
         * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
-        * pwmpin=pwm.getPin(LPCXpresso1769.P2[0]);\r
-        */             \r
+        * var pin=pwm.getPin(LPCXpresso1769.P2[0]);\r
+        * pin.setOpt({duty:0});\r
+        */\r
        setOpt:function setOpt(i_opt)\r
        {\r
                try{\r
-                       var db=new Array();\r
-                       var bc=this.BCF_setOpt(i_opt,db);\r
-                       this._pwm._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
+                       this._pport.setOpt(i_opt);\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
@@ -2600,7 +2793,7 @@ DEV.PwmPin.prototype=
         * @name LPCXpresso1769.PwmPin#setDuty\r
         * @function\r
         * @param {double} i_duty\r
-        * デューティ比である。0.0<=n<=1.0のdouble値を指定する。</li>\r
+        * デューティ比である。0.0<=n<=1.0のdouble値を指定する。\r
         * @example\r
         * varmcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
         * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
@@ -2610,7 +2803,7 @@ DEV.PwmPin.prototype=
        setDuty:function setDuty(i_duty)\r
        {\r
                try{\r
-                       this.setOpt({duty:i_duty});\r
+                       this._pport.setDuty([i_duty]);\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
index 828787b..6c57dc4 100644 (file)
@@ -115,6 +115,33 @@ DEV.Gpio.prototype={
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
+       },\r
+       /**\r
+        * Gpio機能を持つポート(Pin集合)を取得する。\r
+        * ピン識別子で指定されるピンのセットをGpioペリフェラルと結合して、GpioPortを生成する。\r
+        * 関数は、GpioPortのコンストラクタをコールする。\r
+        * 生成ルールについては、GpioPort関数を参照すること。\r
+        * @name LPCXpresso1769.Gpio#getPort\r
+        * @function\r
+        * @param {array[ピン識別子]} i_pin\r
+        * Gpioポートを構成するPINの識別子の配列である。値は、LPCXpresso1769.Pn[m]のメンバ変数である。\r
+        * @param {object as associative array} i_opt\r
+        * GpioPortのコンストラクタに渡すオプション値。省略時はundefinedである。詳細はLPCXpresso1769.GpioPort.setOptを参照。\r
+        * @return {object as LPCXpresso1769.GpioPort}\r
+        * LPCXpresso1769.GpioPortクラスのオブジェクトである。\r
+        * @example\r
+        * //create 2AdcPort that has 2 pins.\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
+        * var gpio=new LPCXpresso1769.Gpio(mcu);\r
+        * var port=gpio.getPort([LPCXpresso1769.P0[0],LPCXpresso1769.P0[1]]);\r
+        */     \r
+       getPort:function getPort(i_pins,i_opt)\r
+       {\r
+               try{\r
+                       return new DEV.GpioPort(this,i_pins,i_opt);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
        }\r
 }\r
 \r
@@ -140,7 +167,27 @@ function pin2GpioPinInfo(i_pin)
        }\r
 }\r
 \r
-\r
+/**\r
+ * LPCXPresso1769.GpioPort (GpioPort)クラスのコンストラクタ。複数のGPIOピンを一括して操作する、パラレルポート等に使用する。\r
+ * Gpioペリフェラルオブジェクトに、ピン識別子の配列で指定されたピン集合を関連付けて、GPIO機能を持つポートを生成する。\r
+ * 関数は、ピン識別子を元に、そのピンがGPIO機能に接続できるかを調べる。全てのピンにGPIO機能を割り当てられない場合、例外が発生する。どのピンにGPIO機能が割り当てられるかは、MCUのスペックシートを参照すること。\r
+ * @constructor\r
+ * @name LPCXpresso1769.GpioPort\r
+ * @param {object as LPCXpresso1769.Gpio} i_gpio\r
+ * インスタンスを結びつけるGpioオブジェクト。\r
+ * @param {array[pin識別子]} i_pins\r
+ * ピン識別子の配列。指定できるのは、LPCXpresso1796.P?[?]である。順番は、このインスタンスの返す値の順序に影響する。\r
+ * 0番目のピンはビット0に対応する。同様に、1番目のピンはビット1に対応する。\r
+ * 組み合わせるピンは、同じ物理ポートに所属している必要がある。例えば、GPIO0.0とGPIO0.1は組み合わせられるが、GPIO0.0とGPIO1.1は組み合わせることが出来ない。\r
+ * @param {object as associative array} i_opt\r
+ * setOpt関数のi_optに渡すパラメタである。省略可能。省略時は{pin:{sel:auto}}を設定する。\r
+ * autoは、関数が自動的に決定するPINSELの値である。詳細はsetOpt関数を参照。 \r
+ * @example\r
+ * //create [AD0.0,AD0.1]\r
+ * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
+ * var gpio=new LPCXpresso1769.Gpio(mcu);\r
+ * var port=new LPCXpresso1769.GpioPort(adc,[LPCXpresso1769.P0[0],LPCXpresso1769.P0[1]]); \r
+ */\r
 DEV.GpioPort=function GpioPort(i_gpio,i_pins,i_opt)\r
 {\r
        try{\r
@@ -185,6 +232,15 @@ DEV.GpioPort.prototype=
        _port_no:0,\r
        _port:null,\r
        _mask:0,\r
+       /**\r
+        * Gpioポートにオプション値を設定する。\r
+        * 関数は、ポートを構成する全てのピンに、同一なオプション値を設定する。\r
+        * 設定可能な値は、LPCXpresso1769.GpioPin#setOptと同じである。\r
+        * @name LPCXpresso1769.GpioPort#setOpt\r
+        * @function\r
+        * @param {object as associative array} i_opt\r
+        * LPCXpresso1769.GpioPin#setOptを参照。\r
+        */     \r
        setOpt:function setOpt(i_opt)\r
        {\r
                try{\r
@@ -213,6 +269,21 @@ DEV.GpioPort.prototype=
                        throw new MiMicException(e);\r
                }\r
        },\r
+       /**\r
+        * ポートの出力状態を設定する。\r
+        * 値は、nビットの整数値で指定する。nは、ポートを構成するピン数である。\r
+        * この関数は、directionを1(output)に設定したポートで使用できる。inputに設定したピンには使用できない。\r
+        * @name LPCXpresso1769.GpioPort#setValue\r
+        * @function\r
+        * @param {int} i_val\r
+        * nビットの出力値。ビット数は、このポートを構成するピンの数に一致する。2ビットのポートを構成したときに0x03を指定すると、2本のピンがON状態になる。\r
+        * @example\r
+        * //set P0[0] pin to “on”. If LED was connected pin it will turn on.\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
+        * port=mcu.getPort([LPCXpresso1769.P0[0],LPCXpresso1769.P0[1]],"GPIO");\r
+        * port.setOpt({dir:1,pin:{mode:1,od:0}});\r
+        * port.setValue(0x3);   \r
+        */     \r
        setValue:function setValue(i_val)\r
        {\r
                try{\r
@@ -232,6 +303,21 @@ DEV.GpioPort.prototype=
                        throw new MiMicException(e);\r
                }\r
        },\r
+       /**\r
+        * ポートの入力状態を返す。\r
+        * 値は、nビットの整数値である。nは、ポートを構成するピン数である。\r
+        * この関数は、directionを0(input)に設定したポートで使用できる。outputに設定したピンには使用できない。\r
+        * @function\r
+        * @return {int}\r
+        * nビットの整数値。ビット数は、このポートを構成するピンの数に一致する。2ビットのポートを構成したときに1,1の入力があると、0x03が返る。\r
+        * @name LPCXpresso1769.GpioPort#getValue\r
+        * @example\r
+        * //show P0[0] value\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
+        * var port=mcu.getPort([LPCXpresso1769.P0[0],LPCXpresso1769.P0[1]],"GPIO");\r
+        * port.setOpt({dir:0,pin:{mode:0,od:0}});\r
+        * alert(port.getValue());       \r
+        */     \r
        getValue:function getValue()\r
        {\r
                try{\r
@@ -251,6 +337,23 @@ DEV.GpioPort.prototype=
                        throw new MiMicException(e);\r
                }\r
        },\r
+       /**\r
+        * 直列化された値パターンを出力する。\r
+        * ポートに連続した値パターンを出力するときに使用する。\r
+        * 出力速度はMCU依存であり、コントロールできない。\r
+        * この関数は、directionを1(output)に設定したポートで使用できる。inputに設定したピンには使用できない。\r
+        * @name LPCXpresso1769.GpioPort#outPatt\r
+        * @function\r
+        * @param {array[int]} i_val_array\r
+        * ビットパターンの配列。nビットの値(0 or 1)の配列を指定する。最大数は20である。ビット数は、このポートを構成するピンの数に一致する。\r
+        * [3,0,3,0]の場合、0,3,0,3の順に、パターンを出力する。\r
+        * @example\r
+        * //output  0x01,0x02 to P0[0]+P0[1]\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
+        * var port=mcu.getPin([LPCXpresso1769.P0[0],LPCXpresso1769.P0[1]],"GPIO");\r
+        * port.setOpt({dir:1,pin:{mode:1,od:0}});\r
+        * port.outPatt([0x01,0x02]);\r
+        */     \r
        outPatt:function outPatt(i_val_array)\r
        {\r
                try{\r
index 4cc0224..2b4d7ed 100644 (file)
@@ -175,7 +175,7 @@ DEV.Adc.prototype=
         * //create 2AdcPort that has 2 pins.\r
         * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
         * var adc=new LPCXpresso1769.Adc(mcu);\r
-        * var adpin=adc.getPort([LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]);\r
+        * var port=adc.getPort([LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]);\r
         */\r
        getPort:function getPort(i_pins,i_opt)\r
        {\r
@@ -225,7 +225,7 @@ function pin2AdcPinInfo(i_pin)
  * //create [AD0.0,AD0.1]\r
  * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
  * var adc=new LPCXpresso1769.Adc(mcu);\r
- * var adcpin=new LPCXpresso1769.AdcPin(adc,[LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]); \r
+ * var port=new LPCXpresso1769.AdcPort(adc,[LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]); \r
  */\r
 DEV.AdcPort=function AdcPort(i_adc,i_pins,i_opt)\r
 {\r
index c9e0294..fa2d671 100644 (file)
                 * @param {object as pin識別子} i_pin\r
                 * ピン識別子。指定できるのは、LPCXpresso1796.P?[?]である。\r
                 * @param {string as 機能名} i_function_name\r
-                * æ©\9fè\83½å\90\8dã\81¯文字列である。 指定できる文字列は、LPCXpresso1769.FUNC_NAMEで定義する。\r
+                * æ©\9fè\83½å\90\8dã\81®文字列である。 指定できる文字列は、LPCXpresso1769.FUNC_NAMEで定義する。\r
                 * @return {object as PinObject}\r
                 * @example\r
                 * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
                        }\r
                },\r
                /**\r
-                * 未実装である。\r
                 * ポート(複数ピンで構成するIO)を制御するPortインスタンスを得るする。\r
                 * 制御ペリフェラル、Portを順に生成する方法と異なり、機能の実現に必要なインスタンスを自動的に生成する。\r
                 * Portが生成できない場合、例外が発生する。\r
                 * @name LPCXpresso1769.Mcu#getPort\r
-                * @function             \r
+                * @function \r
+                * @param {array[PIN識別子]} i_pins\r
+                * ポートを構成するピン識別子の配列。順序は生成するポートの説明を参照。\r
+                * @param {string} i_function_name\r
+                * 機能名の文字列である。 指定できる文字列は、LPCXpresso1769.FUNC_NAMEで定義する。\r
+                * @return {object as PortObject}\r
+                * 返却されるインスタンスのクラスは、機能により異なる。機能とインスタンスのクラスの対応は、以下の通りである。\r
+                * <ul>\r
+                * <li>GPIO - LPCXpresso1769.GpioPin</li>\r
+                * <li>AD - LPCXpresso1769.AdcPin</li>\r
+                * <li>PWM - LPCXpresso1769.PwmPin</li>\r
+                * </ul>                 \r
                 */\r
-               getPort:function getPort(i_port_name)\r
+               getPort:function getPort(i_pins,i_function_name)\r
                {\r
-                       throw new MiMicException("Not implemented.");\r
+                       switch(arguments.length){\r
+                       case 2://getPin:function getPin(i_pins,i_function_name)\r
+                               //function名からペリフェラル名を得る。(PINシンボル変換を流用)\r
+                               var phl_name=pinFuncName2PhlName(i_function_name);\r
+                               return this.getPeripheral(phl_name).getPort(i_pins);\r
+                       default:\r
+                               throw new MiMicException();\r
+                       }\r
                },\r
                /**\r
                 * ペリフェラル名から、ペリフェラルオブジェクトを得る。\r
index da5a04b..24f6c43 100644 (file)
@@ -117,8 +117,21 @@ DEV.Pwm.prototype=
        },\r
        BCF_setLER:function BCF_setLER(i_ch,i_db)\r
        {\r
-               //LERにビットをセット\r
-               return BCF.setBit(this._LER,0x01,0x01,i_ch,i_db);\r
+               try{\r
+                       //LERにビットをセット\r
+                       return BCF.setBit(this._LER,0x01,0x01,i_ch,i_db);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
+       },\r
+       BCF_setLERs:function BCF_setLERs(i_mask,i_value,i_db)\r
+       {\r
+               try{\r
+                       //LERにビットをセット\r
+                       return BCF.setBit(this._LER,i_mask,i_value*i_mask,0,i_db);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
        },\r
        \r
        /**\r
@@ -145,32 +158,34 @@ DEV.Pwm.prototype=
         * PCRに値を設定するBC\r
         i_ch=1の場合、エッジモードは無視します。\r
         @private\r
-        @param i_ch\r
-        1-6\r
+        @param i_mask\r
         @param i_edge\r
         エッジモード(1/0)\r
         @param i_en\r
        有効/無効の選択\r
         */\r
-       BCF_setPCRbit:function BCF_setPCR(i_ch,i_edge,i_en,i_db)\r
+       BCF_setPCRbits:function BCF_setPCRbits(i_mask,i_edge,i_en,i_db)\r
        {\r
                try{\r
                        var m,v;\r
                        m=v=0;\r
                        if(!isUndef(i_edge)){\r
-                               v|=i_edge;\r
-                               m|=0x00000001;\r
+                               var t=0xff&i_mask;\r
+                               v|=i_edge*t;\r
+                               m|=t;\r
                        }\r
                        if(!isUndef(i_en)){\r
-                               v|=(i_en<<8);\r
-                               m|=0x00000100;\r
+                               var t=0xff00&i_mask;\r
+                               v|=(i_en*t);\r
+                               m|=t;\r
                        }\r
                        //ビットの設定\r
-                       return BCF.setBit(this._PCR,m,v,i_ch,i_db);\r
+                       return BCF.setBit(this._PCR,m,v,0,i_db);\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
        },\r
+       \r
        /**\r
         * Pwmペリフェラルに値を設定する。\r
         * 設定する値は、全てのPWMチャンネル(PIN)に共通な項目である。\r
@@ -226,102 +241,250 @@ DEV.Pwm.prototype=
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
+       },\r
+       /**\r
+        * PWM機能を持つポート(Pin集合)を取得する。\r
+        * ピン識別子で指定されるピンのセットをPWMペリフェラルと結合して、PwmPortを生成する。\r
+        * 関数は、PwmPortのコンストラクタをコールする。\r
+        * 生成ルールについては、PwmPort関数を参照すること。\r
+        * @name LPCXpresso1769.Pwm#getPort\r
+        * @function\r
+        * @param {array[ピン識別子]} i_pin\r
+        * Pwm機能を割り当てるPINの識別子の配列である。値は、LPCXpresso1769.Pn[m]のメンバ変数である。\r
+        * @param {object as associative array} i_opt\r
+        * AdcPortのコンストラクタに渡すオプション値。省略時はundefinedである。詳細はLPCXpresso1769.PwmPort.setOptを参照。\r
+        * @return {object as LPCXpresso1769.PwmPort}\r
+        * LPCXpresso1769.PwmPortクラスのオブジェクトである。\r
+        * @example\r
+        * //create 2AdcPort that has 2 pins.\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.0.39");\r
+        * var pwm=new LPCXpresso1769.Pwm(mcu);\r
+        * var port=pwm.getPort([LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]);\r
+        */\r
+       getPort:function getPort(i_pins,i_opt)\r
+       {\r
+               try{\r
+                       return new DEV.PwmPort(this,i_pins,i_opt);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
        }       \r
 }\r
 \r
 /**\r
- * PwmペリフェラルとPin識別子から、シングルエッジPwmピンを構成する。\r
- * Pwmペリフェラルオブジェクトにピン識別子で指定されたピンを関連付けて、PWM機能を持つピンを生成する。\r
- * 関数は、ピン識別子を元に、そのピンがPWM機能に接続できるかを調べる。ピンにPWM機能を割り当てられない場合、例外が発生する。どのピンにPWM機能が割り当てられるかは、MCUのスペックシートを参照すること。\r
- * ピンがPWM機能を持たない場合、例外が発生する。\r
+ * Pwm pinからPwmInfoを取得\r
+ * @private\r
+ */\r
+function pin2PwmPinInfo(i_pin)\r
+{\r
+       try{\r
+               //pinの完全な機能名を得る。(得られれば機能がある。)\r
+               var fn=DEV.completePinFunctionName(i_pin,"PWM");\r
+               //portとbitを得る(AD0だけしか管理しないよ)\r
+               var a=fn.substring(2).split(".");\r
+               var r={port:0,ch:parseInt(a[1]),pin_sel:DEV.getPinSelByFunctionName(i_pin,fn)};\r
+               if(!isNaN(r.ch)){\r
+                       return r;\r
+               }\r
+               throw new MiMicException(EE.INVALID_CFG,"The pin has not PWM fuction.");\r
+       }catch(e){\r
+               throw new MiMicException(e);    \r
+       }\r
+}\r
+/**\r
+ * Pwmペリフェラルと複数のPin識別子から、シングルエッジPwmポートを構成する。\r
+ * Pwmペリフェラルオブジェクトにピン識別子の配列で指定されたピンを関連付けて、PWM機能を持つポートを生成する。\r
+ * 関数は、ピン識別子を元に、それぞれのピンがPWM機能に接続できるかを調べる。\r
+ * ピンにPWM機能を割り当てられない場合、例外が発生する。どのピンにPWM機能が割り当てられるかは、MCUのスペックシートを参照すること。\r
+ * PWMポートは、複数の同一周期のPWMピンのデューティ比を、同期して操作するときに便利である。\r
  * @constructor\r
- * @name LPCXpresso1769.PwmPin\r
+ * @name LPCXpresso1769.PwmPort\r
  * @param {object as LPCXpresso1769.Pwm} i_pwm\r
- * インスタンスを結びつけるAdcオブジェクト。\r
- * @param {object as pin識別子} i_pin\r
- * ピン識別子。指定できるのは、LPCXpresso1796.P?[?]である。\r
+ * インスタンスを結びつけるPwmオブジェクト。\r
+ * @param {array[pin識別子]} i_pins\r
+ * ã\83\94ã\83³è­\98å\88¥å­\90ã\81®é\85\8då\88\97ã\80\82æ\8c\87å®\9aã\81§ã\81\8dã\82\8bã\81®ã\81¯ã\80\81LPCXpresso1796.P?[?]ã\81§ã\81\82ã\82\8bã\80\82\r
  * @param {object as associative array} i_opt\r
  * setOpt関数のi_optに渡すパラメタである。省略可能。省略時は{duty:100,enable:1,pin{sel:auto}}を設定する。\r
  * autoは、関数が自動的に決定するPINSELの値である。詳細はsetOpt関数を参照。 \r
+ * dutyをピン毎に設定する場合は、setDuty関数を使うこと。\r
  * @example\r
- * //create PWM1.0\r
+ * //create PWM1.0,PWM1.1\r
  * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
  * var pwm=new LPCXpresso1769.Pwm(mcu,{freq:100});\r
- * var pwmpin=new LPCXpresso1769.PwmPin(pwm,P2[0]); \r
+ * var port=new LPCXpresso1769.PwmPort(pwm,[LPCXpresso1769.P2[0],LPCXpresso1769.P2[1]]); \r
  */\r
-DEV.PwmPin=function PwmPin(i_pwm,i_pin,i_opt)\r
+DEV.PwmPort=function PwmPort(i_pwm,i_pins,i_opt)\r
 {\r
        try{\r
                this._pwm=i_pwm;\r
-               //PINがPWM持ってるか確認\r
-               this._pin=new DEV.Pin(i_pwm._mcu,i_pin);\r
-               //PinNameからピン情報を得る。\r
-               this._pwminfo=function(i_pin){\r
-                       //pinの完全な機能名を得る。(得られれば機能がある。)\r
-                       var func_name=DEV.completePinFunctionName(i_pin,"PWM");\r
-                       //portとbitを得る(AD0だけしか管理しないよ)\r
-                       var a=func_name.substring(2).split(".");\r
-                       var r={port:0,ch:parseInt(a[1]),pin_sel:DEV.getPinSelByFunctionName(i_pin,func_name)};\r
-                       if(!isNaN(r.ch)){\r
-                               return r;\r
+               //ピンセットを取得\r
+               this._pins=new Array();\r
+               //pinに変換する。\r
+               for(var i=0;i<i_pins.length;i++){\r
+                       this._pins.push(pin2PwmPinInfo(i_pins[i]));\r
+               }\r
+               //pinが全て同じポートに所属しているか確認\r
+               var p=this._pins[0].port;\r
+               for(var i=1;i<this._pins.length;i++){\r
+                       if(p!=this._pins[1].port){\r
+                               throw new MiMicException("Invalid pin combination.");\r
                        }\r
-                       throw new MiMicException(EE.INVALID_CFG,"The pin has not PWM fuction.");\r
-               }(i_pin);\r
-               //設定用のBCを作って実行\r
-               {\r
-                       var opt=isUndef(i_opt)?{pin:{}}:\r
-                       {\r
-                               pin:isUndef(i_opt.pin)?{}:cloneAssoc(i_opt.pin),\r
-                               duty:i_opt.duty,\r
-                               enable:i_opt.enable\r
-                       };\r
-                       //デフォルト値のロード\r
-                       if(isUndef(opt.pin.sel)){ opt.pin.sel=this._pwminfo.pin_sel;}\r
-                       if(isUndef(opt.duty)){opt.duty=0;}\r
-                       if(isUndef(opt.enable)){opt.enable=1;}\r
-                       this.setOpt(opt);\r
                }\r
+               //ポートの生成\r
+               this._port=new DEV.Port(i_pwm._mcu,i_pins);\r
+               this._port_no=p;\r
+               \r
+               this._ler_mask=0;\r
+               this._pcr_mask=0;\r
+               for(var i=0;i<this._pins.length;i++){\r
+                       this._ler_mask|=(0x1<<this._pins[i].ch);\r
+                       this._pcr_mask|=(0x101<<this._pins[i].ch);\r
+               }               \r
+               var opt=isUndef(i_opt)?{pin:{}}:\r
+               {\r
+                       pin:isUndef(i_opt.pin)?{}:cloneAssoc(i_opt.pin),\r
+                       duty:i_opt.duty,\r
+                       enable:i_opt.enable\r
+               };\r
+               //デフォルト値のロード\r
+               if(isUndef(opt.pin.sel)){opt.pin.sel=this._PINSEL_AUTO_DETECT;}\r
+               if(isUndef(opt.duty)){opt.duty=0;}\r
+               if(isUndef(opt.enable)){opt.enable=1;}\r
+               this.setOpt(opt);\r
        }catch(e){\r
                throw new MiMicException(e);\r
-       }\r
+       }       \r
 }\r
-\r
-DEV.PwmPin.prototype=\r
+DEV.PwmPort.prototype=\r
 {\r
+       _PINSEL_AUTO_DETECT:0x0fffffff,\r
        _pwm:null,\r
-       _pin:null,\r
-       _pwminfo:null,\r
+       _pins:null,\r
+       _port_no:0,\r
+       _port:null,\r
+       _pcr_mask:0,\r
+       _ler_mask:0,\r
        /**\r
-        * \r
-        @private\r
-        @param i_opt\r
-        シングルエッジPWMのオプション値を設定する。\r
-        {pin:{ピン初期化パラメタ},enable:有効値,duty:デューティ比}}
+        * PWMポートにオプション値を設定する。\r
+        * 関数は、ポートを構成する全てのピンに、同じ値を設定する。\r
+        * 設定可能な値は、LPCXpresso1769.PwmPin#setOptと同じである。     \r
+        * @name LPCXpresso1769.PwmPort#setOpt\r
+        * @function\r
+        * @param {object as associative array} i_opt\r
+        * LPCXpresso1769.PwmPin#setOptを参照。\r
+        * @example\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
+        * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
+        * var port=pwm.getPort([LPCXpresso1769.P2[0]]);\r
+        * port.setOpt({enable:0});\r
         */\r
-       BCF_setOpt:function BCF_setOpt(i_opt,i_db)\r
+       setOpt:function setOpt(i_opt)\r
        {\r
                try{\r
+                       var db=new Array();\r
+                       //BCの生成\r
                        var bc="";\r
-                       //pinselの値\r
+                       //i_optの展開\r
                        if(!isUndef(i_opt.pin)){\r
-                               //PINSEL設定\r
-                               bc+=this._pin.BCF_setOpt(i_opt.pin,i_db);\r
+                               var optset=new Array();\r
+                               for(var i=0;i<this._pins.length;i++){\r
+                                       //pinselが_PINSEL_AUTO_DETECTならばauto。そうでなければundefinedも含めて設定\r
+                                       var s=(i_opt.pin.sel==this._PINSEL_AUTO_DETECT)?this._pins[i].pin_sel:i_opt.pin.sel;\r
+                                       optset.push({sel:s,mode:i_opt.pin.mode,od:i_opt.pin.od});\r
+                               }\r
                        }\r
+                       //portの設定\r
+                       bc+=this._port.BCF_setOpts(optset,db);\r
                        //PCRに値設定\r
                        if(!isUndef(i_opt.enable)){\r
-                               bc+=this._pwm.BCF_setPCRbit(this._pwminfo.ch,0,i_opt.enable,i_db);\r
+                               bc+=this._pwm.BCF_setPCRbits(this._pcr_mask,0,i_opt.enable,db);\r
                        }\r
-                       //MRnに値設定してLERにセット\r
+                       //デューティ比を\r
                        if(!isUndef(i_opt.duty)){\r
-                               bc+=this._pwm.BCF_setMRnByDuty(this._pwminfo.ch,i_opt.duty,i_db);\r
-                               bc+=this._pwm.BCF_setLER(this._pwminfo.ch,i_db);\r
+                               //デューティ比を設定\r
+                               for(var i=0;i<this._pins.length;i++){\r
+                                       bc+=this._pwm.BCF_setMRnByDuty(this._pins[i].ch,i_opt.duty,db);\r
+                               }\r
+                               //LERにセット\r
+                               bc+=this._pwm.BCF_setLERs(this._ler_mask,1,db);\r
                        }\r
-                       return bc;\r
+                       this._pwm._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
+                       return;\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
        },\r
        /**\r
+        * PWMポートのデューティ比をまとめて変更する。\r
+        * @name LPCXpresso1769.PwmPort#setDutys\r
+        * @function\r
+        * @param {array[double]} i_duty_array\r
+        * デューティ比の配列である。0.0<=n<=1.0のdouble値を指定する。\r
+        * ポートを構成するピンの数だけ指定する。変更しないピンには、undefinedを指定すること。\r
+        * @example\r
+        * varmcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
+        * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
+        * var port=pwm.getPort([LPCXpresso1769.P2[0],LPCXpresso1769.P2[1]]);\r
+        * pwm.setDutys([0.5,0.0]);//PWM0=0.5,PWM1=0.0\r
+        * pwm.setDutys([undefined,0.0]);//PWM1=0.0\r
+        */     \r
+       setDutys:function setDutys(i_duty_array)\r
+       {\r
+               try{\r
+                       if(i_duty_array.length!=this._pins.length){\r
+                               throw new MiMicException(e);\r
+                       }\r
+                       var bc="";\r
+                       var db=new Array();\r
+                       //デューティ比をまとめてセット\r
+                       for(var i=0;i<this._pins.length;i++){\r
+                               if(!isUndef(i_duty_array[i])){\r
+                                       bc+=this._pwm.BCF_setMRnByDuty(this._pins[i].ch,i_duty_array[i],db);\r
+                               }\r
+                       }\r
+                       //LERにセット\r
+                       bc+=this._pwm.BCF_setLERs(this._ler_mask,1,db);\r
+                       this._pwm._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
+               }catch(e){\r
+                       throw new MiMicException(e);\r
+               }\r
+       }\r
+}\r
+/**\r
+ * PwmペリフェラルとPin識別子から、シングルエッジPwmピンを構成する。\r
+ * Pwmペリフェラルオブジェクトにピン識別子で指定されたピンを関連付けて、PWM機能を持つピンを生成する。\r
+ * 関数は、ピン識別子を元に、そのピンがPWM機能に接続できるかを調べる。ピンにPWM機能を割り当てられない場合、例外が発生する。どのピンにPWM機能が割り当てられるかは、MCUのスペックシートを参照すること。\r
+ * ピンがPWM機能を持たない場合、例外が発生する。\r
+ * @constructor\r
+ * @name LPCXpresso1769.PwmPin\r
+ * @param {object as LPCXpresso1769.Pwm} i_pwm\r
+ * インスタンスを結びつけるAdcオブジェクト。\r
+ * @param {object as pin識別子} i_pin\r
+ * ピン識別子。指定できるのは、LPCXpresso1796.P?[?]である。\r
+ * @param {object as associative array} i_opt\r
+ * setOpt関数のi_optに渡すパラメタである。省略可能。省略時は{duty:100,enable:1,pin{sel:auto}}を設定する。\r
+ * autoは、関数が自動的に決定するPINSELの値である。詳細はsetOpt関数を参照。 \r
+ * @example\r
+ * //create PWM1.0\r
+ * var mcu=new LPCXpresso1769.Mcu(“192.168.0.39”);\r
+ * var pwm=new LPCXpresso1769.Pwm(mcu,{freq:100});\r
+ * var pwmpin=new LPCXpresso1769.PwmPin(pwm,P2[0]); \r
+ */\r
+DEV.PwmPin=function PwmPin(i_pwm,i_pin,i_opt)\r
+{\r
+       try{\r
+               //1pinのポートとして実装\r
+               this._pport=new DEV.PwmPort(i_pwm,[i_pin],i_opt);\r
+       }catch(e){\r
+               throw new MiMicException(e);\r
+       }\r
+}\r
+\r
+DEV.PwmPin.prototype=\r
+{\r
+       _pport:null,\r
+\r
+       /**\r
         * PWMピンにオプション値を設定する。\r
         * @name LPCXpresso1769.PwmPin#setOpt\r
         * @function\r
@@ -335,16 +498,15 @@ DEV.PwmPin.prototype=
         * <li>duty - デューティ比である。0.0<=n<=1.0のdouble値を指定する。</li>\r
         * </ul>\r
         * @example\r
-        * var  mcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
+        * var mcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
         * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
-        * pwmpin=pwm.getPin(LPCXpresso1769.P2[0]);\r
-        */             \r
+        * var pin=pwm.getPin(LPCXpresso1769.P2[0]);\r
+        * pin.setOpt({duty:0});\r
+        */\r
        setOpt:function setOpt(i_opt)\r
        {\r
                try{\r
-                       var db=new Array();\r
-                       var bc=this.BCF_setOpt(i_opt,db);\r
-                       this._pwm._mcu.callMiMicWithCheck(bc+BCF.END,db);\r
+                       this._pport.setOpt(i_opt);\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
@@ -354,7 +516,7 @@ DEV.PwmPin.prototype=
         * @name LPCXpresso1769.PwmPin#setDuty\r
         * @function\r
         * @param {double} i_duty\r
-        * デューティ比である。0.0<=n<=1.0のdouble値を指定する。</li>\r
+        * デューティ比である。0.0<=n<=1.0のdouble値を指定する。\r
         * @example\r
         * varmcu=new LPCXpresso1769.Mcu("192.168.128.39",true);\r
         * var pwm=mcu.getPeripheral("PWM",{freq:100});\r
@@ -364,7 +526,7 @@ DEV.PwmPin.prototype=
        setDuty:function setDuty(i_duty)\r
        {\r
                try{\r
-                       this.setOpt({duty:i_duty});\r
+                       this._pport.setDuty([i_duty]);\r
                }catch(e){\r
                        throw new MiMicException(e);\r
                }\r
index f114bdd..766f240 100644 (file)
@@ -23,11 +23,9 @@ function scroll()
 }\r
 function init(){\r
        var mcu=new LPCXpresso1769.Mcu("192.168.128.39");\r
-//     var port=new LPCXpresso1769.AdcPort(\r
        var port=mcu.getPeripheral("ADC").getPort(\r
                [LPCXpresso1769.P0[23],LPCXpresso1769.P0[24]]\r
                );\r
-//     var pin=mcu.getPin(LPCXpresso1769.P0[23],"AD");\r
        var i=0;\r
        setInterval(function(){\r
                var v=port.getValues();\r
index 0ca923f..228f789 100644 (file)
@@ -71,6 +71,11 @@ try{
        //MiMicで作る2進カウンタデモ\r
        function test()\r
        {\r
+        var port=mcu.getPort([LPCXpresso1769.P0[0],LPCXpresso1769.P0[1]],"GPIO");\r
+        port.setOpt({dir:1,pin:{mode:1,od:0}});\r
+        port.setValue(0x2);                    \r
+/*             \r
+               \r
                var gpio=new LPCXpresso1769.Gpio(mcu);\r
                var gpioport1=new LPCXpresso1769.GpioPort(gpio,[\r
 //                     LPCXpresso1769.P0[0],LPCXpresso1769.P0[1],LPCXpresso1769.P0[18],LPCXpresso1769.P0[17]\r
@@ -79,7 +84,7 @@ try{
                var i=0;\r
                var p=[0x1,0x2,0x4,0x8];\r
                gpioport1.setValue(8);\r
-               gpioport1.outPatt([8]);\r
+               gpioport1.outPatt([8]);*/\r
 //             setInterval(function(){gpioport1.outPatt(p);},500);\r
 //             setInterval(function(){gpioport1.setValue(i++);},100);\r
 //             var gpiopin=new LPCXpresso1769.GpioPin(gpio,LPCXpresso1769.P0[0],{dir:1});\r