Repository: jadonk/bonescript Branch: master Commit: e44d24450712 Files: 81 Total size: 465.2 KB Directory structure: gitextract_mlaszepj/ ├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── autorun.js ├── dts/ │ ├── bs_template.dts │ ├── bspm_template.dts │ └── bspwm_template.dts ├── etc/ │ ├── avahi/ │ │ └── services/ │ │ └── bone101.service │ ├── default/ │ │ ├── cloud9 │ │ └── node │ └── profile.d/ │ └── node.sh ├── lint-config.json ├── main.js ├── package.json ├── server.js ├── src/ │ ├── autorun.js │ ├── bone.js │ ├── bonescript.js │ ├── constants.js │ ├── eeprom.js │ ├── ffiimp.js │ ├── functions.js │ ├── hw_capemgr.js │ ├── hw_mainline.js │ ├── hw_oldkernel.js │ ├── hw_simulator.js │ ├── hw_universal.js │ ├── iic.js │ ├── index.d.ts │ ├── index.js │ ├── my.js │ ├── parse.js │ ├── rc.js │ ├── serial.js │ ├── server.js │ └── socket_handlers.js ├── systemd/ │ ├── bonescript-autorun.service │ ├── bonescript.service │ └── bonescript.socket └── test/ ├── TODO/ │ ├── bacon_test.js │ ├── basic_sanity.sh │ ├── constants.js │ ├── eeprom.js │ ├── fix-ssh.js │ ├── fix-ssh.sh │ ├── gitconfig │ ├── remote_bonetest.js │ ├── setdate.js │ ├── test-analogwrite.js │ ├── test-digitalread.js │ ├── test-digitalwrite.js │ ├── test-eeproms.json │ ├── test-getpinmode.js │ ├── test-globalsetuploop.js │ ├── test-i2c-accel.js │ ├── test-i2c.js │ ├── test-pocketbeagle.js │ ├── test-serial.js │ ├── test-templates.js │ ├── test-unloadslot.js │ ├── test.sh │ ├── update-bonescript.sh │ ├── watch-button.js │ ├── watch-button.sh │ └── wired_basic_test.js ├── test-analogread.js ├── test-analogwrite.js ├── test-autorun.js ├── test-bone.js ├── test-digitalread.js ├── test-digitalwrite.js ├── test-ffi.js ├── test-getpinmode.js ├── test-lint.js ├── test-math.js ├── test-pinMode.js ├── test-rpc.js ├── test-rpc_secure.js └── test-sanity.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .settings.xml .DS_Store bonescript.log *~ node_modules .coveralls.yml ================================================ FILE: .travis.yml ================================================ sudo: required language: node_js node_js: - "6" - "8" - "10" after_script: - npm run-script coveralls notifications: irc: - "chat.freenode.net#beagle-bonescript" webhooks: urls: - https://webhooks.gitter.im/e/800e4efb92aa7f8eda15 on_success: change # options: [always|never|change] default: always on_failure: always # options: [always|never|change] default: always on_start: false # default: false ================================================ FILE: LICENSE ================================================ Copyright (c) 2011 Jason Kridner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: Makefile ================================================ PREFIX:=/usr/local npm_options:=--unsafe-perm=true --progress=false --loglevel=error NODE_PATH:=$(DESTDIR)$(PREFIX)/lib/node_modules NODEJS:=nodejs NPM:=npm ver=$(shell nodejs -pe "require('./package.json').version") npm_version=$(shell $(NPM) --version) node_version=$(shell $(NODEJS) --version) bs_path=./build/lib/node_modules/bonescript all: mkdir -p $(bs_path) echo $(ver) > $(bs_path)/bonescript.version echo $(node_version) > $(bs_path)/bonescript.node_version echo $(npm_version) > $(bs_path)/bonescript.npm_version TERM=dumb $(NPM) install -g $(npm_options) --prefix ./build cp -dr --preserve=mode,timestamp etc/* ./build/etc/ clean: rm -rf build test: install: install -m 0755 -d $(DESTDIR)$(PREFIX) cp -dr --preserve=mode,timestamp ./build/* $(DESTDIR)$(PREFIX)/ systemctl stop bonescript-autorun.service || true systemctl stop bonescript.service || true systemctl stop bonescript.socket || true install -m 0755 -d $(DESTDIR)/lib/systemd/system install -m 0644 systemd/bonescript.socket $(DESTDIR)/lib/systemd/system/ install -m 0644 systemd/bonescript.service $(DESTDIR)/lib/systemd/system/ install -m 0644 systemd/bonescript-autorun.service $(DESTDIR)/lib/systemd/system/ systemctl enable bonescript.socket || true systemctl enable bonescript.service || true systemctl enable bonescript-autorun.service || true .PHONY: clean test install ================================================ FILE: README.md ================================================ BoneScript ========== [![Join the chat at https://gitter.im/jadonk/bonescript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jadonk/bonescript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/jadonk/bonescript.svg?branch=0.5.x)](https://travis-ci.org/jadonk/bonescript) [![Coverage Status](https://img.shields.io/coveralls/jadonk/bonescript.svg)](https://coveralls.io/r/jadonk/bonescript) BoneScript is a node.js library for physical computing on embedded Linux, starting with support for BeagleBone. Information on the language is available at http://nodejs.org. To check the version and to see if BoneScript is in your path, try running: ````sh node -pe "require('bonescript').getPlatform().bonescript" ```` Additional documentation is available at http://beagleboard.org/bonescript. The concept is to use Arduino-like functions written in JavaScript to simplify learning how to do physical computing tasks under embedded Linux and to further provide support for rapidly creating GUIs for your embedded applications through the use of HTML5/JavaScript web pages. Global Installation ------------------- BoneScript comes installed on your BeagleBone. To update to the latest revision, use 'npm' on a recent BeagleBoard.org Debian image from https://beagleboard.org/latest-images and perform: ````sh TERM=none sudo npm cache clear TERM=none sudo npm install -g --prefix /usr/local --unsafe-perm bonescript sudo shutdown -r now ```` Testing on other distributions is limited. There are some additional installation steps that can be performed, but are typically installed by other mechanisms on the BeagleBoard.org Debian images. These setup background services (bone101 webserver with bonescript RPC and bonescript autorun service) as well as configure environment variables for these services and other globally run scripts. ````sh sudo cp bonescript/etc/default/node /etc/default/node sudo cp bonescript/etc/profile.d/node.sh /etc/profile.d/node.sh sudo cp bonescript/systemd/\* /lib/systemd/system sudo systemctl enable bonescript.socket sudo systemctl enable bonescript-autorun.service ```` Launching applications persistently ----------------------------------- To have your applications launch on startup, simply drop them into the /var/lib/cloud9/autorun folder. Moving them out of that folder will kill the processes. You are expected to only drop in already bug-free apps into this folder as there isn't a good way to perform debug on them. Note on code state ================== There's still a lot of development going on, so be sure to check back on a frequent basis. Many of the fancier peripherals aren't yet supported except through performing file I/O. Directory layout ---------------- * index.js: Main BoneScript source code * autorun.js: Node.JS app to run apps dropped in the autorun folder * package.json: NPM.JS package descriptor * server.js: BoneScript web server to serve up remote procedure calls * dts: Devicetree templates * etc: Configuration files to be placed in target distro * src: Library source code * systemd: Configuration files for systemd to start services * test: To-be-automated test code Template ======== For a BoneScript application, you must currently manually 'require' the bonescript library. Functions are then referenced through the object provided back from require. I started out trying to provide Arduino-like setup/loop functions, but the idea really isn't a good match for JavaScript. Using JavaScript's native flow works best, but the familiar functions are enough to give you a boost in your physical computing productivity. Here's an example: ````javascript var b = require('bonescript'); b.pinMode('P8_12', b.INPUT); b.pinMode('P8_13', b.OUTPUT); setInterval(copyInputToOutput, 100); function copyInputToOutput() { b.digitalRead('P8_12', writeToOutput); function writeToOutput(x) { b.digitalWrite('P8_13', x.value); } } ```` The 'P8\_12' and 'P8\_13' are pin names on the board and the above example would copy the input value at P8\_12 to the output P8\_13 every 100 ms. API === When a callback is provided, the functions will behave asynchronously. Without a callback provided, the functions will synchronize and complete before returning. System ------ * getPlatform([callback]) -> platform * getEeproms([callback]) -> eeproms * echo(data, [callback]) -> data * readTextFile(filename, [callback]) -> data * writeTextFile(filename, data, [callback]) * setDate(date, [callback]) Digital and Analog I/O ---------------------- * analogRead(pin, [callback]) -> value * analogWrite(pin, value, [freq], [callback]) * attachInterrupt(pin, handler, mode, [callback]) * detachInterrupt(pin, [callback]) * digitalRead(pin, [calback]) -> value * digitalWrite(pin, value, [callback]) * pinMode(pin, direction, [mux], [pullup], [slew], [callback]) * getPinMode(pin, [callback]) -> pinMode * shiftOut(dataPin, clockPin, bitOrder, val, [callback]) Serial ------ Uses https://github.com/voodootikigod/node-serialport * serialOpen(port, options, [callback]) * serialWrite(port, data, [callback]) * serialParsers is serialport.parsers I2C --- Uses https://github.com/korevec/node-i2c * i2cOpen(port, address, options, [callback]) * i2cScan(port, [callback]) * i2cWriteByte(port, byte, [callback]) * i2cWriteBytes(port, command, bytes, [callback]) * i2cReadByte(port, [callback]) * i2cReadBytes(port, command, length, [callback]) * i2cStream(port, command, length, [callback]) Robot Control ------------- __new in 0.7.0__ Runs on BeagleBone Blue; or BeagleBone Black or BeagleBone Black Wireless with BeagleBoard.org Robotics Cape * rcInitialize([callback]) * rcState([state], [callback]) -> state * rcLED(led, [value], [callback]) -> value * rcOn(event, [callback]) * rcMotor(motor, value, [callback]) * rcServo(option, value, [callback]) * rcBMP([option], [callback]) -> value * rcIMU([option], [callback]) -> value * rcEncoder(encoder, [value], [callback]) -> value Bits/Bytes, Math, Trigonometry and Random Numbers ------------------------------------------------- * lowByte(value) * highByte(value) * bitRead(value, bitnum) * bitWrite(value, bitnum, bitdata) * bitSet(value, bitnum) * bitClear(value, bitnum) * bit(bitnum) * min(x, y) * max(x, y) * abs(x) * constrain(x, a, b) * map(value, fromLow, fromHigh, toLow, toHigh) * pow(x, y) * sqrt(x) * sin(radians) * cos(radians) * tan(radians) * randomSeed(x) * random([min], max) Note on performance =================== This code is totally unoptimized. The list of possible optimizations that run through my head is staggering. The good news is that I think it can all be done without impacting the API, primarily thanks to the introspection capabilities of JavaScript. Eventually, this is planned to enable real-time usage, directly from JavaScript. The plan is to attact the ability to use this programming environment in real-time on several fronts: * Enabling multiple loops and analyzing them to determine if they can be off- loaded to a PRU. This will be the primary mechanism for providing real-time servicing of the IOs. * Providing higher-order services that utilize the standard peripherals for their intended use: - Serial drivers for I2C, SPI, UARTs, etc. - analogWrite for PWMs using hardware PWMs, timers, kernel GPIO drivers, etc. * Adding real-time patches to the kernel The JavaScript language provides some features that I think are really cool for doing embedded programming and node.js does some things to help enable that. The primary one is that the I/O functions are all asynchronous. For embedded systems, this is especially useful for performing low-latency tasks that respond to events in the system. What makes JavaScript so much easier than other languages for doing this is that it keeps the full context around the handler, so you don't have to worry about it. What's New ========== 0.7.4 key updates ----------------- * Enabled BeagleBone AI GPIO functions (digitalRead/digitalWrite/getPinMode) 0.7.3 key updates ----------------- Big speed-up on loading by lazy-loading infrequently used modules 0.7.2 key updates ----------------- * https://github.com/beagleboard/bonescript/issues/52 * https://github.com/beagleboard/bonescript/issues/53 0.7.1 key updates ----------------- Very minor update on a function scope 0.7.0 key updates ----------------- Most of these fixes came from a [Google Summer of Code 2018 project](https://github.com/vaishnav98/bone101/wiki/BeagleBoard-GSoC'18:-Fixing-Bugs-in-BoneScript-and-Improving-BeagleBone-User-Interface) * Fixes in PWM output during analogWrite updates * Added function calls for Robot Control library support on BeagleBone Blue or Robotics Cape * Added support for node-style callbacks with error and data separated (optional) Plans ===== * SPI support * PRU support * Handling array of pins in pinMode and getPinMode * Saving off created dtbo and writing configuration to cape EEPROM ================================================ FILE: autorun.js ================================================ var b = require('bonescript'); var directory = (process.env.AUTORUN_DIR) ? process.env.AUTORUN_DIR : '/var/lib/cloud9/autorun'; b.autorun(directory); ================================================ FILE: dts/bs_template.dts ================================================ // Copyright 2013 // Charles Steinkuehler // Copyright 2014 // Jason Kridner // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA /dts-v1/; /plugin/; / { compatible = "ti,beaglebone", "ti,beaglebone-black"; /* identification */ part-number = "cape-bonescript"; version = "00A0"; /* state the resources this cape uses */ exclusive-use = /* "P8.1", GND */ /* "P8.2", GND */ /* "P8.3", emmc */ /* "P8.4", emmc */ /* "P8.5", emmc */ /* "P8.6", emmc */ "P8.7", "P8.8", "P8.9", "P8.10", "P8.11", "P8.12", "P8.13", "P8.14", "P8.15", "P8.16", "P8.17", "P8.18", "P8.19", /* "P8.20", emmc */ /* "P8.21", emmc */ /* "P8.22", emmc */ /* "P8.23", emmc */ /* "P8.24", emmc */ /* "P8.25", emmc */ "P8.26", /* "P8.27", hdmi */ /* "P8.28", hdmi */ /* "P8.29", hdmi */ /* "P8.30", hdmi */ /* "P8.31", hdmi */ /* "P8.32", hdmi */ /* "P8.33", hdmi */ /* "P8.34", hdmi */ /* "P8.35", hdmi */ /* "P8.36", hdmi */ /* "P8.37", hdmi */ /* "P8.38", hdmi */ /* "P8.39", hdmi */ /* "P8.40", hdmi */ /* "P8.41", hdmi */ /* "P8.42", hdmi */ /* "P8.43", hdmi */ /* "P8.44", hdmi */ /* "P8.45", hdmi */ /* "P8.46", hdmi */ /* "P9.1", GND */ /* "P9.2", GND */ /* "P9.3", 3.3V */ /* "P9.4", 3.3V */ /* "P9.5", VDD_5V */ /* "P9.6", VDD_5V */ /* "P9.7", SYS_5V */ /* "P9.8", SYS_5V */ /* "P9.9", PWR_BUT */ /* "P9.10", RESETn */ "P9.11", "P9.12", "P9.13", "P9.14", "P9.15", "P9.16", "P9.17", "P9.18", /* "P9.19", I2C */ /* "P9.20", I2C */ "P9.21", "P9.22", "P9.23", "P9.24", /* "P9.25", Audio */ "P9.26", "P9.27", /* "P9.28", Audio */ /* "P9.29", Audio */ "P9.30", /* "P9.31", Audio */ /* "P9.32", VADC */ /* "P9.33", AIN4 */ /* "P9.34", AGND */ /* "P9.35", AIN6 */ /* "P9.36", AIN5 */ /* "P9.37", AIN2 */ /* "P9.38", AIN3 */ /* "P9.39", AIN0 */ /* "P9.40", AIN1 */ "P9.41", "P9.41.1", "P9.42", "P9.42.1", /* "P9.43", GND */ /* "P9.44", GND */ /* "P9.45", GND */ /* "P9.46", GND */ "uart1", "uart2", "uart4", // "uart5", /* Conflicts with HDMI */ "ehrpwm0A", "ehrpwm0B", "ehrpwm1A", "ehrpwm1B", "ehrpwm2A", "ehrpwm2B", // "epwmss0", // "ehrpwm0", // "ecap0", // "epwmss1", // "ehrpwm1", // "epwmss2", // "ehrpwm2", // "ecap2", "i2c1", "spi1", "spi0", "dcan0", "dcan1", "pru0", "pru1", "pruss"; fragment@0 { target = <&am33xx_pinmux>; __overlay__ { /************************/ /* P8 Header */ /************************/ /* P8_01 GND */ /* P8_02 GND */ /* P8_03 (ZCZ ball R9 ) emmc */ /* P8_04 (ZCZ ball T9 ) emmc */ /* P8_05 (ZCZ ball R8 ) emmc */ /* P8_06 (ZCZ ball T8 ) emmc */ /* P8_07 (ZCZ ball R7 ) */ P8_07_default_pin: pinmux_P8_07_default_pin { pinctrl-single,pins = <0x090 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_07_gpio_pin: pinmux_P8_07_gpio_pin { pinctrl-single,pins = <0x090 0x2F>; }; /* Mode 7, RxActive */ P8_07_gpio_pu_pin: pinmux_P8_07_gpio_pu_pin { pinctrl-single,pins = <0x090 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_07_gpio_pd_pin: pinmux_P8_07_gpio_pd_pin { pinctrl-single,pins = <0x090 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_07_timer_pin: pinmux_P8_07_timer_pin { pinctrl-single,pins = <0x090 0x32>; }; /* Mode 2, Pull-Up, RxActive */ /* P8_08 (ZCZ ball T7 ) */ P8_08_default_pin: pinmux_P8_08_default_pin { pinctrl-single,pins = <0x094 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_08_gpio_pin: pinmux_P8_08_gpio_pin { pinctrl-single,pins = <0x094 0x2F>; }; /* Mode 7, RxActive */ P8_08_gpio_pu_pin: pinmux_P8_08_gpio_pu_pin { pinctrl-single,pins = <0x094 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_08_gpio_pd_pin: pinmux_P8_08_gpio_pd_pin { pinctrl-single,pins = <0x094 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_08_timer_pin: pinmux_P8_08_timer_pin { pinctrl-single,pins = <0x094 0x32>; }; /* Mode 2, Pull-Up, RxActive */ /* P8_09 (ZCZ ball T6 ) */ P8_09_default_pin: pinmux_P8_09_default_pin { pinctrl-single,pins = <0x09c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_09_gpio_pin: pinmux_P8_09_gpio_pin { pinctrl-single,pins = <0x09c 0x2F>; }; /* Mode 7, RxActive */ P8_09_gpio_pu_pin: pinmux_P8_09_gpio_pu_pin { pinctrl-single,pins = <0x09c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_09_gpio_pd_pin: pinmux_P8_09_gpio_pd_pin { pinctrl-single,pins = <0x09c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_09_timer_pin: pinmux_P8_09_timer_pin { pinctrl-single,pins = <0x09c 0x32>; }; /* Mode 2, Pull-Up, RxActive */ /* P8_10 (ZCZ ball U6 ) */ P8_10_default_pin: pinmux_P8_10_default_pin { pinctrl-single,pins = <0x098 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_10_gpio_pin: pinmux_P8_10_gpio_pin { pinctrl-single,pins = <0x098 0x2F>; }; /* Mode 7, RxActive */ P8_10_gpio_pu_pin: pinmux_P8_10_gpio_pu_pin { pinctrl-single,pins = <0x098 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_10_gpio_pd_pin: pinmux_P8_10_gpio_pd_pin { pinctrl-single,pins = <0x098 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_10_timer_pin: pinmux_P8_10_timer_pin { pinctrl-single,pins = <0x098 0x32>; }; /* Mode 2, Pull-Up, RxActive */ /* P8_11 (ZCZ ball R12) */ P8_11_default_pin: pinmux_P8_11_default_pin { pinctrl-single,pins = <0x034 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_11_gpio_pin: pinmux_P8_11_gpio_pin { pinctrl-single,pins = <0x034 0x2F>; }; /* Mode 7, RxActive */ P8_11_gpio_pu_pin: pinmux_P8_11_gpio_pu_pin { pinctrl-single,pins = <0x034 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_11_gpio_pd_pin: pinmux_P8_11_gpio_pd_pin { pinctrl-single,pins = <0x034 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_11_pruout_pin: pinmux_P8_11_pruout_pin { pinctrl-single,pins = <0x034 0x26>; }; /* Mode 6, Pull-Down, RxActive */ P8_11_qep_pin: pinmux_P8_11_qep_pin { pinctrl-single,pins = <0x034 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_12 (ZCZ ball T12) */ P8_12_default_pin: pinmux_P8_12_default_pin { pinctrl-single,pins = <0x030 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_12_gpio_pin: pinmux_P8_12_gpio_pin { pinctrl-single,pins = <0x030 0x2F>; }; /* Mode 7, RxActive */ P8_12_gpio_pu_pin: pinmux_P8_12_gpio_pu_pin { pinctrl-single,pins = <0x030 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_12_gpio_pd_pin: pinmux_P8_12_gpio_pd_pin { pinctrl-single,pins = <0x030 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_12_pruout_pin: pinmux_P8_12_pruout_pin { pinctrl-single,pins = <0x030 0x26>; }; /* Mode 6, Pull-Down, RxActive */ P8_12_qep_pin: pinmux_P8_12_qep_pin { pinctrl-single,pins = <0x030 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_13 (ZCZ ball T10) */ P8_13_default_pin: pinmux_P8_13_default_pin { pinctrl-single,pins = <0x024 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_13_gpio_pin: pinmux_P8_13_gpio_pin { pinctrl-single,pins = <0x024 0x2F>; }; /* Mode 7, RxActive */ P8_13_gpio_pu_pin: pinmux_P8_13_gpio_pu_pin { pinctrl-single,pins = <0x024 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_13_gpio_pd_pin: pinmux_P8_13_gpio_pd_pin { pinctrl-single,pins = <0x024 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_13_pwm_pin: pinmux_P8_13_pwm_pin { pinctrl-single,pins = <0x024 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_14 (ZCZ ball T11) */ P8_14_default_pin: pinmux_P8_14_default_pin { pinctrl-single,pins = <0x028 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_14_gpio_pin: pinmux_P8_14_gpio_pin { pinctrl-single,pins = <0x028 0x2F>; }; /* Mode 7, RxActive */ P8_14_gpio_pu_pin: pinmux_P8_14_gpio_pu_pin { pinctrl-single,pins = <0x028 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_14_gpio_pd_pin: pinmux_P8_14_gpio_pd_pin { pinctrl-single,pins = <0x028 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_14_pwm_pin: pinmux_P8_14_pwm_pin { pinctrl-single,pins = <0x028 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_15 (ZCZ ball U13) */ P8_15_default_pin: pinmux_P8_15_default_pin { pinctrl-single,pins = <0x03c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_15_gpio_pin: pinmux_P8_15_gpio_pin { pinctrl-single,pins = <0x03c 0x2F>; }; /* Mode 7, RxActive */ P8_15_gpio_pu_pin: pinmux_P8_15_gpio_pu_pin { pinctrl-single,pins = <0x03c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_15_gpio_pd_pin: pinmux_P8_15_gpio_pd_pin { pinctrl-single,pins = <0x03c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_15_pruin_pin: pinmux_P8_15_pruin_pin { pinctrl-single,pins = <0x03c 0x26>; }; /* Mode 6, Pull-Down, RxActive */ P8_15_qep_pin: pinmux_P8_15_qep_pin { pinctrl-single,pins = <0x03c 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_16 (ZCZ ball V13) */ P8_16_default_pin: pinmux_P8_16_default_pin { pinctrl-single,pins = <0x038 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_16_gpio_pin: pinmux_P8_16_gpio_pin { pinctrl-single,pins = <0x038 0x2F>; }; /* Mode 7, RxActive */ P8_16_gpio_pu_pin: pinmux_P8_16_gpio_pu_pin { pinctrl-single,pins = <0x038 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_16_gpio_pd_pin: pinmux_P8_16_gpio_pd_pin { pinctrl-single,pins = <0x038 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_16_pruin_pin: pinmux_P8_16_pruin_pin { pinctrl-single,pins = <0x038 0x26>; }; /* Mode 6, Pull-Down, RxActive */ P8_16_qep_pin: pinmux_P8_16_qep_pin { pinctrl-single,pins = <0x038 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_17 (ZCZ ball U12) */ P8_17_default_pin: pinmux_P8_17_default_pin { pinctrl-single,pins = <0x02c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_17_gpio_pin: pinmux_P8_17_gpio_pin { pinctrl-single,pins = <0x02c 0x2F>; }; /* Mode 7, RxActive */ P8_17_gpio_pu_pin: pinmux_P8_17_gpio_pu_pin { pinctrl-single,pins = <0x02c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_17_gpio_pd_pin: pinmux_P8_17_gpio_pd_pin { pinctrl-single,pins = <0x02c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_17_pwm_pin: pinmux_P8_17_pwm_pin { pinctrl-single,pins = <0x02c 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_18 (ZCZ ball V12) */ P8_18_default_pin: pinmux_P8_18_default_pin { pinctrl-single,pins = <0x08c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_18_gpio_pin: pinmux_P8_18_gpio_pin { pinctrl-single,pins = <0x08c 0x2F>; }; /* Mode 7, RxActive */ P8_18_gpio_pu_pin: pinmux_P8_18_gpio_pu_pin { pinctrl-single,pins = <0x08c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_18_gpio_pd_pin: pinmux_P8_18_gpio_pd_pin { pinctrl-single,pins = <0x08c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ /* P8_19 (ZCZ ball U10) */ P8_19_default_pin: pinmux_P8_19_default_pin { pinctrl-single,pins = <0x020 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_19_gpio_pin: pinmux_P8_19_gpio_pin { pinctrl-single,pins = <0x020 0x2F>; }; /* Mode 7, RxActive */ P8_19_gpio_pu_pin: pinmux_P8_19_gpio_pu_pin { pinctrl-single,pins = <0x020 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_19_gpio_pd_pin: pinmux_P8_19_gpio_pd_pin { pinctrl-single,pins = <0x020 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P8_19_pwm_pin: pinmux_P8_19_pwm_pin { pinctrl-single,pins = <0x020 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P8_20 (ZCZ ball V9 ) emmc */ /* P8_21 (ZCZ ball U9 ) emmc */ /* P8_22 (ZCZ ball V8 ) emmc */ /* P8_23 (ZCZ ball U8 ) emmc */ /* P8_24 (ZCZ ball V7 ) emmc */ /* P8_25 (ZCZ ball U7 ) emmc */ /* P8_26 (ZCZ ball V6 ) */ P8_26_default_pin: pinmux_P8_26_default_pin { pinctrl-single,pins = <0x07c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_26_gpio_pin: pinmux_P8_26_gpio_pin { pinctrl-single,pins = <0x07c 0x2F>; }; /* Mode 7, RxActive */ P8_26_gpio_pu_pin: pinmux_P8_26_gpio_pu_pin { pinctrl-single,pins = <0x07c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P8_26_gpio_pd_pin: pinmux_P8_26_gpio_pd_pin { pinctrl-single,pins = <0x07c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ /* P8_27 (ZCZ ball U5 ) hdmi */ /* P8_28 (ZCZ ball V5 ) hdmi */ /* P8_29 (ZCZ ball R5 ) hdmi */ /* P8_30 (ZCZ ball R6 ) hdmi */ /* P8_31 (ZCZ ball V4 ) hdmi */ /* P8_32 (ZCZ ball T5 ) hdmi */ /* P8_33 (ZCZ ball V3 ) hdmi */ /* P8_34 (ZCZ ball U4 ) hdmi */ /* P8_35 (ZCZ ball V2 ) hdmi */ /* P8_36 (ZCZ ball U3 ) hdmi */ /* P8_37 (ZCZ ball U1 ) hdmi */ /* P8_38 (ZCZ ball U2 ) hdmi */ /* P8_39 (ZCZ ball T3 ) hdmi */ /* P8_40 (ZCZ ball T4 ) hdmi */ /* P8_41 (ZCZ ball T1 ) hdmi */ /* P8_42 (ZCZ ball T2 ) hdmi */ /* P8_43 (ZCZ ball R3 ) hdmi */ /* P8_44 (ZCZ ball R4 ) hdmi */ /* P8_45 (ZCZ ball R1 ) hdmi */ /* P8_46 (ZCZ ball R2 ) hdmi */ /************************/ /* P9 Header */ /************************/ /* P9_01 GND */ /* P9_02 GND */ /* P9_03 3.3V */ /* P9_04 3.3V */ /* P9_05 VDD_5V */ /* P9_06 VDD_5V */ /* P9_07 SYS_5V */ /* P9_08 SYS_5V */ /* P9_09 PWR_BUT */ /* P9_10 (ZCZ ball A10) RESETn */ /* P9_11 (ZCZ ball T17) */ P9_11_default_pin: pinmux_P9_11_default_pin { pinctrl-single,pins = <0x070 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_11_gpio_pin: pinmux_P9_11_gpio_pin { pinctrl-single,pins = <0x070 0x2F>; }; /* Mode 7, RxActive */ P9_11_gpio_pu_pin: pinmux_P9_11_gpio_pu_pin { pinctrl-single,pins = <0x070 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_11_gpio_pd_pin: pinmux_P9_11_gpio_pd_pin { pinctrl-single,pins = <0x070 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_11_uart_pin: pinmux_P9_11_uart_pin { pinctrl-single,pins = <0x070 0x36>; }; /* Mode 6, Pull-Up, RxActive */ /* P9_12 (ZCZ ball U18) */ P9_12_default_pin: pinmux_P9_12_default_pin { pinctrl-single,pins = <0x078 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_12_gpio_pin: pinmux_P9_12_gpio_pin { pinctrl-single,pins = <0x078 0x2F>; }; /* Mode 7, RxActive */ P9_12_gpio_pu_pin: pinmux_P9_12_gpio_pu_pin { pinctrl-single,pins = <0x078 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_12_gpio_pd_pin: pinmux_P9_12_gpio_pd_pin { pinctrl-single,pins = <0x078 0x27>; }; /* Mode 7, Pull-Down, RxActive */ /* P9_13 (ZCZ ball U17) */ P9_13_default_pin: pinmux_P9_13_default_pin { pinctrl-single,pins = <0x074 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_13_gpio_pin: pinmux_P9_13_gpio_pin { pinctrl-single,pins = <0x074 0x2F>; }; /* Mode 7, RxActive */ P9_13_gpio_pu_pin: pinmux_P9_13_gpio_pu_pin { pinctrl-single,pins = <0x074 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_13_gpio_pd_pin: pinmux_P9_13_gpio_pd_pin { pinctrl-single,pins = <0x074 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_13_uart_pin: pinmux_P9_13_uart_pin { pinctrl-single,pins = <0x074 0x36>; }; /* Mode 6, Pull-Up, RxActive */ /* P9_14 (ZCZ ball U14) */ P9_14_default_pin: pinmux_P9_14_default_pin { pinctrl-single,pins = <0x048 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_14_gpio_pin: pinmux_P9_14_gpio_pin { pinctrl-single,pins = <0x048 0x2F>; }; /* Mode 7, RxActive */ P9_14_gpio_pu_pin: pinmux_P9_14_gpio_pu_pin { pinctrl-single,pins = <0x048 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_14_gpio_pd_pin: pinmux_P9_14_gpio_pd_pin { pinctrl-single,pins = <0x048 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_14_pwm_pin: pinmux_P9_14_pwm_pin { pinctrl-single,pins = <0x048 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_15 (ZCZ ball R13) */ P9_15_default_pin: pinmux_P9_15_default_pin { pinctrl-single,pins = <0x040 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_15_gpio_pin: pinmux_P9_15_gpio_pin { pinctrl-single,pins = <0x040 0x2F>; }; /* Mode 7, RxActive */ P9_15_gpio_pu_pin: pinmux_P9_15_gpio_pu_pin { pinctrl-single,pins = <0x040 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_15_gpio_pd_pin: pinmux_P9_15_gpio_pd_pin { pinctrl-single,pins = <0x040 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_15_pwm_pin: pinmux_P9_15_pwm_pin { pinctrl-single,pins = <0x040 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_16 (ZCZ ball T14) */ P9_16_default_pin: pinmux_P9_16_default_pin { pinctrl-single,pins = <0x04c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_16_gpio_pin: pinmux_P9_16_gpio_pin { pinctrl-single,pins = <0x04c 0x2F>; }; /* Mode 7, RxActive */ P9_16_gpio_pu_pin: pinmux_P9_16_gpio_pu_pin { pinctrl-single,pins = <0x04c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_16_gpio_pd_pin: pinmux_P9_16_gpio_pd_pin { pinctrl-single,pins = <0x04c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_16_pwm_pin: pinmux_P9_16_pwm_pin { pinctrl-single,pins = <0x04c 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_17 (ZCZ ball A16) */ P9_17_default_pin: pinmux_P9_17_default_pin { pinctrl-single,pins = <0x15c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_17_gpio_pin: pinmux_P9_17_gpio_pin { pinctrl-single,pins = <0x15c 0x2F>; }; /* Mode 7, RxActive */ P9_17_gpio_pu_pin: pinmux_P9_17_gpio_pu_pin { pinctrl-single,pins = <0x15c 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_17_gpio_pd_pin: pinmux_P9_17_gpio_pd_pin { pinctrl-single,pins = <0x15c 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_17_spi_pin: pinmux_P9_17_spi_pin { pinctrl-single,pins = <0x15c 0x30>; }; /* Mode 0, Pull-Up, RxActive */ P9_17_i2c_pin: pinmux_P9_17_i2c_pin { pinctrl-single,pins = <0x15c 0x32>; }; /* Mode 2, Pull-Up, RxActive */ P9_17_pwm_pin: pinmux_P9_17_pwm_pin { pinctrl-single,pins = <0x15c 0x33>; }; /* Mode 3, Pull-Up, RxActive */ /* P9_18 (ZCZ ball B16) */ P9_18_default_pin: pinmux_P9_18_default_pin { pinctrl-single,pins = <0x158 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_18_gpio_pin: pinmux_P9_18_gpio_pin { pinctrl-single,pins = <0x158 0x2F>; }; /* Mode 7, RxActive */ P9_18_gpio_pu_pin: pinmux_P9_18_gpio_pu_pin { pinctrl-single,pins = <0x158 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_18_gpio_pd_pin: pinmux_P9_18_gpio_pd_pin { pinctrl-single,pins = <0x158 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_18_spi_pin: pinmux_P9_18_spi_pin { pinctrl-single,pins = <0x158 0x30>; }; /* Mode 0, Pull-Up, RxActive */ P9_18_i2c_pin: pinmux_P9_18_i2c_pin { pinctrl-single,pins = <0x158 0x32>; }; /* Mode 2, Pull-Up, RxActive */ P9_18_pwm_pin: pinmux_P9_18_pwm_pin { pinctrl-single,pins = <0x158 0x33>; }; /* Mode 3, Pull-Up, RxActive */ // Leave the cape I2C EEPROM bus alone /* P9_19 (ZCZ ball D17) I2C */ /* P9_20 (ZCZ ball D18) I2C */ /* P9_21 (ZCZ ball B17) */ P9_21_default_pin: pinmux_P9_21_default_pin { pinctrl-single,pins = <0x154 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_21_gpio_pin: pinmux_P9_21_gpio_pin { pinctrl-single,pins = <0x154 0x2F>; }; /* Mode 7, RxActive */ P9_21_gpio_pu_pin: pinmux_P9_21_gpio_pu_pin { pinctrl-single,pins = <0x154 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_21_gpio_pd_pin: pinmux_P9_21_gpio_pd_pin { pinctrl-single,pins = <0x154 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_21_spi_pin: pinmux_P9_21_spi_pin { pinctrl-single,pins = <0x154 0x30>; }; /* Mode 0, Pull-Up, RxActive */ P9_21_uart_pin: pinmux_P9_21_uart_pin { pinctrl-single,pins = <0x154 0x31>; }; /* Mode 1, Pull-Up, RxActive */ P9_21_i2c_pin: pinmux_P9_21_i2c_pin { pinctrl-single,pins = <0x154 0x32>; }; /* Mode 2, Pull-Up, RxActive */ P9_21_pwm_pin: pinmux_P9_21_pwm_pin { pinctrl-single,pins = <0x154 0x33>; }; /* Mode 3, Pull-Up, RxActive */ /* P9_22 (ZCZ ball A17) */ P9_22_default_pin: pinmux_P9_22_default_pin { pinctrl-single,pins = <0x150 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_22_gpio_pin: pinmux_P9_22_gpio_pin { pinctrl-single,pins = <0x150 0x2F>; }; /* Mode 7, RxActive */ P9_22_gpio_pu_pin: pinmux_P9_22_gpio_pu_pin { pinctrl-single,pins = <0x150 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_22_gpio_pd_pin: pinmux_P9_22_gpio_pd_pin { pinctrl-single,pins = <0x150 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_22_spi_pin: pinmux_P9_22_spi_pin { pinctrl-single,pins = <0x150 0x30>; }; /* Mode 0, Pull-Up, RxActive */ P9_22_uart_pin: pinmux_P9_22_uart_pin { pinctrl-single,pins = <0x150 0x31>; }; /* Mode 1, Pull-Up, RxActive */ P9_22_i2c_pin: pinmux_P9_22_i2c_pin { pinctrl-single,pins = <0x150 0x32>; }; /* Mode 2, Pull-Up, RxActive */ P9_22_pwm_pin: pinmux_P9_22_pwm_pin { pinctrl-single,pins = <0x150 0x33>; }; /* Mode 3, Pull-Up, RxActive */ /* P9_23 (ZCZ ball V14) */ P9_23_default_pin: pinmux_P9_23_default_pin { pinctrl-single,pins = <0x044 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_23_gpio_pin: pinmux_P9_23_gpio_pin { pinctrl-single,pins = <0x044 0x2F>; }; /* Mode 7, RxActive */ P9_23_gpio_pu_pin: pinmux_P9_23_gpio_pu_pin { pinctrl-single,pins = <0x044 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_23_gpio_pd_pin: pinmux_P9_23_gpio_pd_pin { pinctrl-single,pins = <0x044 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_23_pwm_pin: pinmux_P9_23_pwm_pin { pinctrl-single,pins = <0x044 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_24 (ZCZ ball D15) */ P9_24_default_pin: pinmux_P9_24_default_pin { pinctrl-single,pins = <0x184 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_24_gpio_pin: pinmux_P9_24_gpio_pin { pinctrl-single,pins = <0x184 0x2F>; }; /* Mode 7, RxActive */ P9_24_gpio_pu_pin: pinmux_P9_24_gpio_pu_pin { pinctrl-single,pins = <0x184 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_24_gpio_pd_pin: pinmux_P9_24_gpio_pd_pin { pinctrl-single,pins = <0x184 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_24_uart_pin: pinmux_P9_24_uart_pin { pinctrl-single,pins = <0x184 0x30>; }; /* Mode 0, Pull-Up, RxActive */ P9_24_can_pin: pinmux_P9_24_can_pin { pinctrl-single,pins = <0x184 0x32>; }; /* Mode 2, Pull-Up, RxActive */ P9_24_i2c_pin: pinmux_P9_24_i2c_pin { pinctrl-single,pins = <0x184 0x33>; }; /* Mode 3, Pull-Up, RxActive */ P9_24_pruin_pin: pinmux_P9_24_pruin_pin { pinctrl-single,pins = <0x184 0x36>; }; /* Mode 6, Pull-Up, RxActive */ /* P9_25 (ZCZ ball A14) Audio */ /* P9_26 (ZCZ ball D16) */ P9_26_default_pin: pinmux_P9_26_default_pin { pinctrl-single,pins = <0x180 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_26_gpio_pin: pinmux_P9_26_gpio_pin { pinctrl-single,pins = <0x180 0x2F>; }; /* Mode 7, RxActive */ P9_26_gpio_pu_pin: pinmux_P9_26_gpio_pu_pin { pinctrl-single,pins = <0x180 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_26_gpio_pd_pin: pinmux_P9_26_gpio_pd_pin { pinctrl-single,pins = <0x180 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_26_uart_pin: pinmux_P9_26_uart_pin { pinctrl-single,pins = <0x180 0x30>; }; /* Mode 0, Pull-Up, RxActive */ P9_26_can_pin: pinmux_P9_26_can_pin { pinctrl-single,pins = <0x180 0x32>; }; /* Mode 2, Pull-Up, RxActive */ P9_26_i2c_pin: pinmux_P9_26_i2c_pin { pinctrl-single,pins = <0x180 0x33>; }; /* Mode 3, Pull-Up, RxActive */ P9_26_pruin_pin: pinmux_P9_26_pruin_pin { pinctrl-single,pins = <0x180 0x36>; }; /* Mode 6, Pull-Up, RxActive */ /* P9_27 (ZCZ ball C13) */ P9_27_default_pin: pinmux_P9_27_default_pin { pinctrl-single,pins = <0x1a4 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_27_gpio_pin: pinmux_P9_27_gpio_pin { pinctrl-single,pins = <0x1a4 0x2F>; }; /* Mode 7, RxActive */ P9_27_gpio_pu_pin: pinmux_P9_27_gpio_pu_pin { pinctrl-single,pins = <0x1a4 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_27_gpio_pd_pin: pinmux_P9_27_gpio_pd_pin { pinctrl-single,pins = <0x1a4 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_27_qep_pin: pinmux_P9_27_qep_pin { pinctrl-single,pins = <0x1a4 0x21>; }; /* Mode 1, Pull-Down, RxActive */ P9_27_pruout_pin: pinmux_P9_27_pruout_pin { pinctrl-single,pins = <0x1a4 0x25>; }; /* Mode 5, Pull-Down, RxActive */ P9_27_pruin_pin: pinmux_P9_27_pruin_pin { pinctrl-single,pins = <0x1a4 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_28 (ZCZ ball C12) Audio */ /* P9_29 (ZCZ ball B13) Audio */ /* P9_30 (ZCZ ball D12) */ P9_30_default_pin: pinmux_P9_30_default_pin { pinctrl-single,pins = <0x198 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_30_gpio_pin: pinmux_P9_30_gpio_pin { pinctrl-single,pins = <0x198 0x2F>; }; /* Mode 7, RxActive */ P9_30_gpio_pu_pin: pinmux_P9_30_gpio_pu_pin { pinctrl-single,pins = <0x198 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_30_gpio_pd_pin: pinmux_P9_30_gpio_pd_pin { pinctrl-single,pins = <0x198 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_30_pwm_pin: pinmux_P9_30_pwm_pin { pinctrl-single,pins = <0x198 0x21>; }; /* Mode 1, Pull-Down, RxActive */ P9_30_spi_pin: pinmux_P9_30_spi_pin { pinctrl-single,pins = <0x198 0x23>; }; /* Mode 3, Pull-Down, RxActive */ P9_30_pruout_pin: pinmux_P9_30_pruout_pin { pinctrl-single,pins = <0x198 0x25>; }; /* Mode 5, Pull-Down, RxActive */ P9_30_pruin_pin: pinmux_P9_30_pruin_pin { pinctrl-single,pins = <0x198 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_31 (ZCZ ball A13) Audio */ /* P9_32 VADC */ /* P9_33 (ZCZ ball C8 ) AIN4 */ /* P9_34 AGND */ /* P9_35 (ZCZ ball A8 ) AIN6 */ /* P9_36 (ZCZ ball B8 ) AIN5 */ /* P9_37 (ZCZ ball B7 ) AIN2 */ /* P9_38 (ZCZ ball A7 ) AIN3 */ /* P9_39 (ZCZ ball B6 ) AIN0 */ /* P9_40 (ZCZ ball C7 ) AIN1 */ /* P9_41 (ZCZ ball D14) */ P9_41_default_pin: pinmux_P9_41_default_pin { pinctrl-single,pins = <0x1b4 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_41_gpio_pin: pinmux_P9_41_gpio_pin { pinctrl-single,pins = <0x1b4 0x2F>; }; /* Mode 7, RxActive */ P9_41_gpio_pu_pin: pinmux_P9_41_gpio_pu_pin { pinctrl-single,pins = <0x1b4 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_41_gpio_pd_pin: pinmux_P9_41_gpio_pd_pin { pinctrl-single,pins = <0x1b4 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_41_timer_pin: pinmux_P9_41_timer_pin { pinctrl-single,pins = <0x1b4 0x24>; }; /* Mode 4, Pull-Down, RxActive */ P9_41_pruin_pin: pinmux_P9_41_pruin_pin { pinctrl-single,pins = <0x1b4 0x25>; }; /* Mode 5, Pull-Down, RxActive */ /* P9_41.1 */ /* P9_91 (ZCZ ball D13) */ P9_91_default_pin: pinmux_P9_91_default_pin { pinctrl-single,pins = <0x1a8 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_91_gpio_pin: pinmux_P9_91_gpio_pin { pinctrl-single,pins = <0x1a8 0x2F>; }; /* Mode 7, RxActive */ P9_91_gpio_pu_pin: pinmux_P9_91_gpio_pu_pin { pinctrl-single,pins = <0x1a8 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_91_gpio_pd_pin: pinmux_P9_91_gpio_pd_pin { pinctrl-single,pins = <0x1a8 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_91_qep_pin: pinmux_P9_91_qep_pin { pinctrl-single,pins = <0x1a8 0x21>; }; /* Mode 1, Pull-Down, RxActive */ P9_91_pruout_pin: pinmux_P9_91_pruout_pin { pinctrl-single,pins = <0x1a8 0x25>; }; /* Mode 5, Pull-Down, RxActive */ P9_91_pruin_pin: pinmux_P9_91_pruin_pin { pinctrl-single,pins = <0x1a8 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_42 (ZCZ ball C18) */ P9_42_default_pin: pinmux_P9_42_default_pin { pinctrl-single,pins = <0x164 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_42_gpio_pin: pinmux_P9_42_gpio_pin { pinctrl-single,pins = <0x164 0x2F>; }; /* Mode 7, RxActive */ P9_42_gpio_pu_pin: pinmux_P9_42_gpio_pu_pin { pinctrl-single,pins = <0x164 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_42_gpio_pd_pin: pinmux_P9_42_gpio_pd_pin { pinctrl-single,pins = <0x164 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_42_pwm_pin: pinmux_P9_42_pwm_pin { pinctrl-single,pins = <0x164 0x20>; }; /* Mode 0, Pull-Down, RxActive */ P9_42_uart_pin: pinmux_P9_42_uart_pin { pinctrl-single,pins = <0x164 0x21>; }; /* Mode 1, Pull-Down, RxActive */ P9_42_spics_pin: pinmux_P9_42_spics_pin { pinctrl-single,pins = <0x164 0x22>; }; /* Mode 2, Pull-Down, RxActive */ P9_42_spiclk_pin: pinmux_P9_42_spiclk_pin { pinctrl-single,pins = <0x164 0x24>; }; /* Mode 4, Pull-Down, RxActive */ /* P9_42.1 */ /* P9_92 (ZCZ ball B12) */ P9_92_default_pin: pinmux_P9_92_default_pin { pinctrl-single,pins = <0x1a0 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_92_gpio_pin: pinmux_P9_92_gpio_pin { pinctrl-single,pins = <0x1a0 0x2F>; }; /* Mode 7, RxActive */ P9_92_gpio_pu_pin: pinmux_P9_92_gpio_pu_pin { pinctrl-single,pins = <0x1a0 0x37>; }; /* Mode 7, Pull-Up, RxActive */ P9_92_gpio_pd_pin: pinmux_P9_92_gpio_pd_pin { pinctrl-single,pins = <0x1a0 0x27>; }; /* Mode 7, Pull-Down, RxActive */ P9_92_qep_pin: pinmux_P9_92_qep_pin { pinctrl-single,pins = <0x1a0 0x21>; }; /* Mode 1, Pull-Down, RxActive */ P9_92_pruout_pin: pinmux_P9_92_pruout_pin { pinctrl-single,pins = <0x1a0 0x25>; }; /* Mode 5, Pull-Down, RxActive */ P9_92_pruin_pin: pinmux_P9_92_pruin_pin { pinctrl-single,pins = <0x1a0 0x26>; }; /* Mode 6, Pull-Down, RxActive */ /* P9_43 GND */ /* P9_44 GND */ /* P9_45 GND */ /* P9_46 GND */ }; }; /************************/ /* Pin Multiplexing */ /************************/ fragment@1 { target = <&ocp>; __overlay__ { /************************/ /* P8 Header */ /************************/ P8_07_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "timer"; pinctrl-0 = <&P8_07_default_pin>; pinctrl-1 = <&P8_07_gpio_pin>; pinctrl-2 = <&P8_07_gpio_pu_pin>; pinctrl-3 = <&P8_07_gpio_pd_pin>; pinctrl-4 = <&P8_07_timer_pin>; }; P8_08_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "timer"; pinctrl-0 = <&P8_08_default_pin>; pinctrl-1 = <&P8_08_gpio_pin>; pinctrl-2 = <&P8_08_gpio_pu_pin>; pinctrl-3 = <&P8_08_gpio_pd_pin>; pinctrl-4 = <&P8_08_timer_pin>; }; P8_09_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "timer"; pinctrl-0 = <&P8_09_default_pin>; pinctrl-1 = <&P8_09_gpio_pin>; pinctrl-2 = <&P8_09_gpio_pu_pin>; pinctrl-3 = <&P8_09_gpio_pd_pin>; pinctrl-4 = <&P8_09_timer_pin>; }; P8_10_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "timer"; pinctrl-0 = <&P8_10_default_pin>; pinctrl-1 = <&P8_10_gpio_pin>; pinctrl-2 = <&P8_10_gpio_pu_pin>; pinctrl-3 = <&P8_10_gpio_pd_pin>; pinctrl-4 = <&P8_10_timer_pin>; }; P8_11_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pruout", "qep"; pinctrl-0 = <&P8_11_default_pin>; pinctrl-1 = <&P8_11_gpio_pin>; pinctrl-2 = <&P8_11_gpio_pu_pin>; pinctrl-3 = <&P8_11_gpio_pd_pin>; pinctrl-4 = <&P8_11_pruout_pin>; pinctrl-5 = <&P8_11_qep_pin>; }; P8_12_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pruout", "qep"; pinctrl-0 = <&P8_12_default_pin>; pinctrl-1 = <&P8_12_gpio_pin>; pinctrl-2 = <&P8_12_gpio_pu_pin>; pinctrl-3 = <&P8_12_gpio_pd_pin>; pinctrl-4 = <&P8_12_pruout_pin>; pinctrl-5 = <&P8_12_qep_pin>; }; P8_13_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P8_13_default_pin>; pinctrl-1 = <&P8_13_gpio_pin>; pinctrl-2 = <&P8_13_gpio_pu_pin>; pinctrl-3 = <&P8_13_gpio_pd_pin>; pinctrl-4 = <&P8_13_pwm_pin>; }; P8_14_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P8_14_default_pin>; pinctrl-1 = <&P8_14_gpio_pin>; pinctrl-2 = <&P8_14_gpio_pu_pin>; pinctrl-3 = <&P8_14_gpio_pd_pin>; pinctrl-4 = <&P8_14_pwm_pin>; }; P8_15_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pruin", "qep"; pinctrl-0 = <&P8_15_default_pin>; pinctrl-1 = <&P8_15_gpio_pin>; pinctrl-2 = <&P8_15_gpio_pu_pin>; pinctrl-3 = <&P8_15_gpio_pd_pin>; pinctrl-4 = <&P8_15_pruin_pin>; pinctrl-5 = <&P8_15_qep_pin>; }; P8_16_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pruin", "qep"; pinctrl-0 = <&P8_16_default_pin>; pinctrl-1 = <&P8_16_gpio_pin>; pinctrl-2 = <&P8_16_gpio_pu_pin>; pinctrl-3 = <&P8_16_gpio_pd_pin>; pinctrl-4 = <&P8_16_pruin_pin>; pinctrl-5 = <&P8_16_qep_pin>; }; P8_17_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P8_17_default_pin>; pinctrl-1 = <&P8_17_gpio_pin>; pinctrl-2 = <&P8_17_gpio_pu_pin>; pinctrl-3 = <&P8_17_gpio_pd_pin>; pinctrl-4 = <&P8_17_pwm_pin>; }; P8_18_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio"; pinctrl-0 = <&P8_18_default_pin>; pinctrl-1 = <&P8_18_gpio_pin>; pinctrl-2 = <&P8_18_gpio_pu_pin>; pinctrl-3 = <&P8_18_gpio_pd_pin>; }; P8_19_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P8_19_default_pin>; pinctrl-1 = <&P8_19_gpio_pin>; pinctrl-2 = <&P8_19_gpio_pu_pin>; pinctrl-3 = <&P8_19_gpio_pd_pin>; pinctrl-4 = <&P8_19_pwm_pin>; }; P8_26_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio"; pinctrl-0 = <&P8_26_default_pin>; pinctrl-1 = <&P8_26_gpio_pin>; pinctrl-2 = <&P8_26_gpio_pu_pin>; pinctrl-3 = <&P8_26_gpio_pd_pin>; }; /************************/ /* P9 Header */ /************************/ P9_11_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "uart"; pinctrl-0 = <&P9_11_default_pin>; pinctrl-1 = <&P9_11_gpio_pin>; pinctrl-2 = <&P9_11_gpio_pu_pin>; pinctrl-3 = <&P9_11_gpio_pd_pin>; pinctrl-4 = <&P9_11_uart_pin>; }; P9_12_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio"; pinctrl-0 = <&P9_12_default_pin>; pinctrl-1 = <&P9_12_gpio_pin>; pinctrl-2 = <&P9_12_gpio_pu_pin>; pinctrl-3 = <&P9_12_gpio_pd_pin>; }; P9_13_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "uart"; pinctrl-0 = <&P9_13_default_pin>; pinctrl-1 = <&P9_13_gpio_pin>; pinctrl-2 = <&P9_13_gpio_pu_pin>; pinctrl-3 = <&P9_13_gpio_pd_pin>; pinctrl-4 = <&P9_13_uart_pin>; }; P9_14_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P9_14_default_pin>; pinctrl-1 = <&P9_14_gpio_pin>; pinctrl-2 = <&P9_14_gpio_pu_pin>; pinctrl-3 = <&P9_14_gpio_pd_pin>; pinctrl-4 = <&P9_14_pwm_pin>; }; P9_15_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P9_15_default_pin>; pinctrl-1 = <&P9_15_gpio_pin>; pinctrl-2 = <&P9_15_gpio_pu_pin>; pinctrl-3 = <&P9_15_gpio_pd_pin>; pinctrl-4 = <&P9_15_pwm_pin>; }; P9_16_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P9_16_default_pin>; pinctrl-1 = <&P9_16_gpio_pin>; pinctrl-2 = <&P9_16_gpio_pu_pin>; pinctrl-3 = <&P9_16_gpio_pd_pin>; pinctrl-4 = <&P9_16_pwm_pin>; }; P9_17_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "spi", "i2c", "pwm"; pinctrl-0 = <&P9_17_default_pin>; pinctrl-1 = <&P9_17_gpio_pin>; pinctrl-2 = <&P9_17_gpio_pu_pin>; pinctrl-3 = <&P9_17_gpio_pd_pin>; pinctrl-4 = <&P9_17_spi_pin>; pinctrl-5 = <&P9_17_i2c_pin>; pinctrl-6 = <&P9_17_pwm_pin>; }; P9_18_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "spi", "i2c", "pwm"; pinctrl-0 = <&P9_18_default_pin>; pinctrl-1 = <&P9_18_gpio_pin>; pinctrl-2 = <&P9_18_gpio_pu_pin>; pinctrl-3 = <&P9_18_gpio_pd_pin>; pinctrl-4 = <&P9_18_spi_pin>; pinctrl-5 = <&P9_18_i2c_pin>; pinctrl-6 = <&P9_18_pwm_pin>; }; // I2C Pins // P9_19_pinmux // P9_20_pinmux P9_21_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "spi", "uart", "i2c", "pwm"; pinctrl-0 = <&P9_21_default_pin>; pinctrl-1 = <&P9_21_gpio_pin>; pinctrl-2 = <&P9_21_gpio_pu_pin>; pinctrl-3 = <&P9_21_gpio_pd_pin>; pinctrl-4 = <&P9_21_spi_pin>; pinctrl-5 = <&P9_21_uart_pin>; pinctrl-6 = <&P9_21_i2c_pin>; pinctrl-7 = <&P9_21_pwm_pin>; }; P9_22_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "spi", "uart", "i2c", "pwm"; pinctrl-0 = <&P9_22_default_pin>; pinctrl-1 = <&P9_22_gpio_pin>; pinctrl-2 = <&P9_22_gpio_pu_pin>; pinctrl-3 = <&P9_22_gpio_pd_pin>; pinctrl-4 = <&P9_22_spi_pin>; pinctrl-5 = <&P9_22_uart_pin>; pinctrl-6 = <&P9_22_i2c_pin>; pinctrl-7 = <&P9_22_pwm_pin>; }; P9_23_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm"; pinctrl-0 = <&P9_23_default_pin>; pinctrl-1 = <&P9_23_gpio_pin>; pinctrl-2 = <&P9_23_gpio_pu_pin>; pinctrl-3 = <&P9_23_gpio_pd_pin>; pinctrl-4 = <&P9_23_pwm_pin>; }; P9_24_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "uart", "can", "i2c", "pruin"; pinctrl-0 = <&P9_24_default_pin>; pinctrl-1 = <&P9_24_gpio_pin>; pinctrl-2 = <&P9_24_gpio_pu_pin>; pinctrl-3 = <&P9_24_gpio_pd_pin>; pinctrl-4 = <&P9_24_uart_pin>; pinctrl-5 = <&P9_24_can_pin>; pinctrl-6 = <&P9_24_i2c_pin>; pinctrl-7 = <&P9_24_pruin_pin>; }; // Audio pin // P9_25_pinmux P9_26_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "uart", "can", "i2c", "pruin"; pinctrl-0 = <&P9_26_default_pin>; pinctrl-1 = <&P9_26_gpio_pin>; pinctrl-2 = <&P9_26_gpio_pu_pin>; pinctrl-3 = <&P9_26_gpio_pd_pin>; pinctrl-4 = <&P9_26_uart_pin>; pinctrl-5 = <&P9_26_can_pin>; pinctrl-6 = <&P9_26_i2c_pin>; pinctrl-7 = <&P9_26_pruin_pin>; }; P9_27_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "qep", "pruout", "pruin"; pinctrl-0 = <&P9_27_default_pin>; pinctrl-1 = <&P9_27_gpio_pin>; pinctrl-2 = <&P9_27_gpio_pu_pin>; pinctrl-3 = <&P9_27_gpio_pd_pin>; pinctrl-4 = <&P9_27_qep_pin>; pinctrl-5 = <&P9_27_pruout_pin>; pinctrl-6 = <&P9_27_pruin_pin>; }; // Audio pins // P9_28_pinmux // P9_29_pinmux P9_30_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm", "spi", "pruout", "pruin"; pinctrl-0 = <&P9_30_default_pin>; pinctrl-1 = <&P9_30_gpio_pin>; pinctrl-2 = <&P9_30_gpio_pu_pin>; pinctrl-3 = <&P9_30_gpio_pd_pin>; pinctrl-4 = <&P9_30_pwm_pin>; pinctrl-5 = <&P9_30_spi_pin>; pinctrl-6 = <&P9_30_pruout_pin>; pinctrl-7 = <&P9_30_pruin_pin>; }; // Audio pin // P9_31_pinmux P9_41_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "timer", "pruin"; pinctrl-0 = <&P9_41_default_pin>; pinctrl-1 = <&P9_41_gpio_pin>; pinctrl-2 = <&P9_41_gpio_pu_pin>; pinctrl-3 = <&P9_41_gpio_pd_pin>; pinctrl-4 = <&P9_41_timer_pin>; pinctrl-5 = <&P9_41_pruin_pin>; }; P9_91_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "qep", "pruout", "pruin"; pinctrl-0 = <&P9_91_default_pin>; pinctrl-1 = <&P9_91_gpio_pin>; pinctrl-2 = <&P9_91_gpio_pu_pin>; pinctrl-3 = <&P9_91_gpio_pd_pin>; pinctrl-4 = <&P9_91_qep_pin>; pinctrl-5 = <&P9_91_pruout_pin>; pinctrl-6 = <&P9_91_pruin_pin>; }; P9_42_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "pwm", "uart", "spics", "spiclk"; pinctrl-0 = <&P9_42_default_pin>; pinctrl-1 = <&P9_42_gpio_pin>; pinctrl-2 = <&P9_42_gpio_pu_pin>; pinctrl-3 = <&P9_42_gpio_pd_pin>; pinctrl-4 = <&P9_42_pwm_pin>; pinctrl-5 = <&P9_42_uart_pin>; pinctrl-6 = <&P9_42_spics_pin>; pinctrl-7 = <&P9_42_spiclk_pin>; }; P9_92_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "qep", "pruout", "pruin"; pinctrl-0 = <&P9_92_default_pin>; pinctrl-1 = <&P9_92_gpio_pin>; pinctrl-2 = <&P9_92_gpio_pu_pin>; pinctrl-3 = <&P9_92_gpio_pd_pin>; pinctrl-4 = <&P9_92_qep_pin>; pinctrl-5 = <&P9_92_pruout_pin>; pinctrl-6 = <&P9_92_pruin_pin>; }; }; }; fragment@2 { target = <&ocp>; __overlay__ { // !!!WARNING!!! // gpio-of-helper &gpio pointers are off-by-one vs. the hardware: // hardware GPIO bank 0 = &gpio1 cape-universal { compatible = "gpio-of-helper"; status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; P8_07 { gpio-name = "P8_07"; gpio = <&gpio3 2 0>; input; dir-changeable; }; P8_08 { gpio-name = "P8_08"; gpio = <&gpio3 3 0>; input; dir-changeable; }; P8_09 { gpio-name = "P8_09"; gpio = <&gpio3 5 0>; input; dir-changeable; }; P8_10 { gpio-name = "P8_10"; gpio = <&gpio3 4 0>; input; dir-changeable; }; P8_11 { gpio-name = "P8_11"; gpio = <&gpio2 13 0>; input; dir-changeable; }; P8_12 { gpio-name = "P8_12"; gpio = <&gpio2 12 0>; input; dir-changeable; }; P8_13 { gpio-name = "P8_13"; gpio = <&gpio1 23 0>; input; dir-changeable; }; P8_14 { gpio-name = "P8_14"; gpio = <&gpio1 26 0>; input; dir-changeable; }; P8_15 { gpio-name = "P8_15"; gpio = <&gpio2 15 0>; input; dir-changeable; }; P8_16 { gpio-name = "P8_16"; gpio = <&gpio2 14 0>; input; dir-changeable; }; P8_17 { gpio-name = "P8_17"; gpio = <&gpio1 27 0>; input; dir-changeable; }; P8_18 { gpio-name = "P8_18"; gpio = <&gpio3 1 0>; input; dir-changeable; }; P8_19 { gpio-name = "P8_19"; gpio = <&gpio1 22 0>; input; dir-changeable; }; P8_26 { gpio-name = "P8_26"; gpio = <&gpio2 29 0>; input; dir-changeable; }; P9_11 { gpio-name = "P9_11"; gpio = <&gpio1 30 0>; input; dir-changeable; }; P9_12 { gpio-name = "P9_12"; gpio = <&gpio2 28 0>; input; dir-changeable; }; P9_13 { gpio-name = "P9_13"; gpio = <&gpio1 31 0>; input; dir-changeable; }; P9_14 { gpio-name = "P9_14"; gpio = <&gpio2 18 0>; input; dir-changeable; }; P9_15 { gpio-name = "P9_15"; gpio = <&gpio2 16 0>; input; dir-changeable; }; P9_16 { gpio-name = "P9_16"; gpio = <&gpio2 19 0>; input; dir-changeable; }; P9_17 { gpio-name = "P9_17"; gpio = <&gpio1 5 0>; input; dir-changeable; }; P9_18 { gpio-name = "P9_18"; gpio = <&gpio1 4 0>; input; dir-changeable; }; // I2C pins // P9_19 // P9_20 P9_21 { gpio-name = "P9_21"; gpio = <&gpio1 3 0>; input; dir-changeable; }; P9_22 { gpio-name = "P9_22"; gpio = <&gpio1 2 0>; input; dir-changeable; }; P9_23 { gpio-name = "P9_23"; gpio = <&gpio2 17 0>; input; dir-changeable; }; P9_24 { gpio-name = "P9_24"; gpio = <&gpio1 15 0>; input; dir-changeable; }; // Audio pin // P9_25 P9_26 { gpio-name = "P9_26"; gpio = <&gpio1 14 0>; input; dir-changeable; }; P9_27 { gpio-name = "P9_27"; gpio = <&gpio4 19 0>; input; dir-changeable; }; // Audio pins // P9_28 // P9_29 P9_30 { gpio-name = "P9_30"; gpio = <&gpio4 16 0>; input; dir-changeable; }; // Audio pin // P9_31 P9_41 { gpio-name = "P9_41"; gpio = <&gpio1 20 0>; input; dir-changeable; }; P9_91 { gpio-name = "P9_91"; gpio = <&gpio4 20 0>; input; dir-changeable; }; P9_42 { gpio-name = "P9_42"; gpio = <&gpio1 7 0>; input; dir-changeable; }; P9_92 { gpio-name = "P9_92"; gpio = <&gpio4 18 0>; input; dir-changeable; }; }; }; }; /************************/ /* UARTs */ /************************/ fragment@10 { target = <&uart2>; /* really uart1 */ __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; fragment@11 { target = <&uart3>; /* really uart2 */ __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; fragment@12 { target = <&uart5>; /* really uart4 */ __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; // /* UART 5 only available on LCD/HDMI pins */ // fragment@13 { // target = <&uart6>; /* really uart5 */ // __overlay__ { // status = "okay"; // pinctrl-names = "default"; // pinctrl-0 = <>; // }; // }; /************************/ /* Timers / PWM */ /************************/ fragment@20 { target = <&epwmss0>; __overlay__ { status = "okay"; }; }; fragment@21 { target = <&ehrpwm0>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; fragment@22 { target = <&ecap0>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; fragment@23 { target = <&epwmss1>; __overlay__ { status = "okay"; }; }; fragment@24 { target = <&ehrpwm1>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; fragment@25 { target = <&epwmss2>; __overlay__ { status = "okay"; }; }; fragment@26 { target = <&ehrpwm2>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; fragment@27 { target = <&ecap2>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; /************************/ /* I2C / SPI */ /************************/ fragment@30 { target = <&i2c1>; /* i2c1 is numbered correctly */ __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; /* this is the configuration part */ clock-frequency = <100000>; #address-cells = <1>; #size-cells = <0>; /* add any i2c devices on the bus here */ // commented out example of a touchscreen (taken from BB-BONE-LCD7-01-00A4) */ // maxtouch@4a { // compatible = "mXT224"; // reg = <0x4a>; // interrupt-parent = <&gpio4>; // interrupts = <19 0x0>; // atmel,irq-gpio = <&gpio4 19 0>; // }; }; }; fragment@31 { target = <&spi0>; /* spi0 is numbered correctly */ __overlay__ { #address-cells = <1>; #size-cells = <0>; status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; spi0channel@0 { #address-cells = <1>; #size-cells = <0>; compatible = "spidev"; reg = <0>; spi-max-frequency = <16000000>; spi-cpha; }; spi0channel@1 { #address-cells = <1>; #size-cells = <0>; compatible = "spidev"; reg = <1>; spi-max-frequency = <16000000>; }; }; }; fragment@32 { target = <&spi1>; /* spi1 is numbered correctly */ __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; #address-cells = <1>; #size-cells = <0>; spi1channel@0 { #address-cells = <1>; #size-cells = <0>; compatible = "spidev"; reg = <0>; spi-max-frequency = <16000000>; spi-cpha; }; spi1channel@1 { #address-cells = <1>; #size-cells = <0>; compatible = "spidev"; reg = <1>; spi-max-frequency = <16000000>; }; }; }; fragment@33 { target = <&dcan0>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; fragment@34 { target = <&dcan1>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <>; }; }; /************************/ /* PRUSS */ /************************/ fragment@40 { target = <&pruss>; __overlay__ { status = "okay"; }; }; }; ================================================ FILE: dts/bspm_template.dts ================================================ /* * This is a template-generated file from BoneScript */ /dts-v1/; /plugin/; /{ compatible = "ti,beaglebone", "ti,beaglebone-black"; part_number = "BS_PINMODE_!PIN_KEY!_!DATA!"; exclusive-use = "!PIN_DOT_KEY!", "!PIN_FUNCTION!"; fragment@0 { target = <&am33xx_pinmux>; __overlay__ { bs_pinmode_!PIN_KEY!_!DATA!: pinmux_bs_pinmode_!PIN_KEY!_!DATA! { pinctrl-single,pins = ; }; }; }; fragment@1 { target = <&ocp>; __overlay__ { bs_pinmode_!PIN_KEY!_!DATA!_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&bs_pinmode_!PIN_KEY!_!DATA!>; }; }; }; }; ================================================ FILE: dts/bspwm_template.dts ================================================ /* * Copyright (C) 2013 CircuitCo * Copyright (C) 2013 Texas Instruments * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This is a template-generated file from BoneScript */ /dts-v1/; /plugin/; / { compatible = "ti,beaglebone", "ti,beaglebone-black"; /* identification */ part-number = "BS_PWM_!PIN_KEY!_!DATA!"; /* state the resources this cape uses */ exclusive-use = /* the pin header uses */ "!PIN_DOT_KEY!", /* the hardware IP uses */ "!PIN_FUNCTION!"; fragment@0 { target = <&am33xx_pinmux>; __overlay__ { bs_pwm_!PIN_KEY!_!DATA!: pinmux_bs_pwm_!PIN_KEY!_!DATA! { pinctrl-single,pins = ; }; }; }; fragment@1 { target = <&ocp>; __overlay__ { bs_pwm_test_!PIN_KEY! { compatible = "pwm_test"; pwms = <&!PWM_MODULE! !PWM_INDEX! !DUTY_CYCLE! 1>; pwm-names = "PWM_!PIN_KEY!"; pinctrl-names = "default"; pinctrl-0 = <&bs_pwm_!PIN_KEY!_!DATA!>; enabled = <1>; duty = <0>; status = "okay"; }; }; }; }; ================================================ FILE: etc/avahi/services/bone101.service ================================================ BeagleBone 101 Getting Started for %h _http._tcp 80 ================================================ FILE: etc/default/cloud9 ================================================ NODE_PATH=/usr/lib/node_modules HOME=/root PORT=3000 ================================================ FILE: etc/default/node ================================================ NODE_PATH=/usr/lib/node_modules SERVER_DIR=/usr/share/bone101 ================================================ FILE: etc/profile.d/node.sh ================================================ #!/bin/sh export NODE_PATH=/usr/lib/node_modules ================================================ FILE: lint-config.json ================================================ { "indent_size": 4, "indent_char": " ", "indent_with_tabs": false, "eol": "\n", "end_with_newline": false, "indent_level": 0, "preserve_newlines": true, "max_preserve_newlines": 10, "space_in_paren": false, "space_in_empty_paren": false, "jslint_happy": true, "space_after_anon_function": false, "brace_style": "collapse", "unindent_chained_methods": false, "break_chained_methods": false, "keep_array_indentation": false, "unescape_strings": false, "wrap_line_length": 0, "e4x": false, "comma_first": false, "operator_position": "before-newline" } ================================================ FILE: main.js ================================================ module.exports = process.env.BONESCRIPT_COV ? require('./src-cov/index') : require('./src/index'); ================================================ FILE: package.json ================================================ { "author": { "name": "Jason Kridner", "email": "jkridner@beagleboard.org", "url": "http://jkridner.wordpress.com" }, "name": "bonescript", "description": "Physical computing library for embedded Linux", "keywords": [ "embedded", "linux", "beagleboard", "beaglebone", "physical", "gpio", "arduino" ], "version": "0.7.4-beta1", "homepage": "http://beagleboard.org/bonescript", "license": "MIT", "repository": { "type": "git", "url": "git://github.com/jadonk/bonescript" }, "main": "main", "types": "./src/index.d.ts", "engines": { "node": ">= 6.0.0" }, "dependencies": { "chokidar": "2.0.3", "express": "4.13.4", "socket.io": "1.4.5", "systemd": "0.3.1", "winston": "2.1.1", "@types/verror": "latest", "shelljs": "0.8.2" }, "optionalDependencies": { "serialport": "6.0.5", "@types/serialport": "latest", "i2c": "0.2.3", "epoll": "0.1.18", "pi-spi": "1.0.2", "roboticscape": "0.0.8", "ffi": "2.2.0" }, "devDependencies": { "coveralls": "~3.0.1", "js-beautify": "^1.7.5", "jscoverage": "~0.6.0", "nodeunit": "^0.11.2", "socket.io-client": "1.4.5" }, "scripts": { "start": "node server.js", "test": "NODE_PATH=.. nodeunit test", "beautify": "NODE_PATH=.. js-beautify --config lint-config.json -r -f *.js src/*.js test/*.js", "coveralls": "NODE_PATH=.. jscoverage src && NODE_PATH=.. BONESCRIPT_COV=1 nodeunit --reporter=lcov test | coveralls" } } ================================================ FILE: server.js ================================================ var b = require('bonescript'); var util = require('util'); var fs = require('fs'); var configFile = '/etc/default/bonescript'; var server; //read the configuration from configFile fs.readFile(configFile, { encoding: 'ascii' }, function read(err, data) { if (err) { server = b.serverStart(); //start server with default settings } else { data = JSON.parse(data); //start server with saved config server = b.serverStart(data.port, data.directory, { data: data.passphrase, hash: data.hash }); } onServerStart(); }); function onServerStart() { server.on('server$listening', serverListening); server.on('server$error', serverError); server.on('server$connection', serverConnection); } function serverListening() { if (debug) winston.debug('Server listening'); } function serverError(error) { if (debug) winston.debug('Server error: ' + JSON.stringify(error)); } function serverConnection(connection) { if (debug) winston.debug('Server connection: ' + connection); } ================================================ FILE: src/autorun.js ================================================ // Copyright (C) 2013 - Texas Instruments, Jason Kridner // // var fs = require('fs'); var child_process = require('child_process'); var events = require('events'); var my = require('./my'); var winston = my.require('winston'); var chokidar = my.require('chokidar'); var debug = process.env.DEBUG ? true : false; var apps = {}; var watchers = []; var emitter = new events.EventEmitter(); var autorun = function (dir) { var ar = dir || '/var/lib/cloud9/autorun'; winston.info('Starting bonescript autorun service'); fs.exists(ar, arExists); function arExists(exists) { if (!exists) fs.mkdir(ar, arWatch); else fs.readdir(ar, arFound); } function arFound(err, files) { if (err) { winston.err('Error reading directory: ' + err); arWatch(); return; } var i = 0; arTestNext(); function arTestNext() { if (i == files.length) { arWatch(); return; } if (debug) winston.debug("arTestNext: files[" + i + "] = " + ar + '/' + files[i]); appStart(ar + '/' + files[i]); i++; arTestNext(); } } function appStart(file) { if (apps[file]) { if (debug) winston.debug("already started: " + file); return; } appTest(); function appTest() { fs.exists(file, appExists); } function appExists(exists) { function onStdout(data) { winston.info('stdout (' + file + '): ' + data); } function onStderr(data) { winston.info('stderr (' + file + '):' + data); } if (exists) { if (typeof apps[file] != 'undefined') { winston.info('already running: ' + file); return; } if (file.match(/\.js$/)) { winston.info('start: ' + file); apps[file] = child_process.spawn(process.argv[0], [file]); apps[file].on('close', appClosed); apps[file].stdout.on('data', onStdout); apps[file].stderr.on('data', onStderr); } else if (file.match(/\.py$/)) { winston.info('start: ' + file); apps[file] = child_process.spawn('/usr/bin/python', [file]); apps[file].on('close', appClosed); apps[file].stdout.on('data', onStdout); apps[file].stderr.on('data', onStderr); } else if (file.match(/\.sh$/)) { winston.info('start: ' + file); apps[file] = child_process.spawn('/bin/bash', [file]); apps[file].on('close', appClosed); apps[file].stdout.on('data', onStdout); apps[file].stderr.on('data', onStderr); } else if (file.match(/\.ino$/)) { winston.info('start: ' + file); apps[file] = child_process.spawn('/usr/bin/make', [ "-f", "/var/lib/cloud9/extras/Userspace-Arduino/Makefile", "TARGET=" + file.replace(/\.ino$/, ''), "LOCAL_INO_SRCS=" + file, "LOCAL_C_SRCS=", "LOCAL_CPP_SRCS=", "LOCAL_PDE_SRCS=", "LOCAL_AS_SRCS=", "COMMON_DEPS=" ], { 'cwd': ar }); apps[file].on('close', appClosed); apps[file].stdout.on('data', onStdout); apps[file].stderr.on('data', onStderr); } emitter.emit('start', file); } } function appClosed(code, signal) { winston.info("closed: " + file); delete apps[file]; emitter.emit('closed', file); //setTimeout(appTest, 1000); } } function arWatch() { if (debug) winston.debug("arWatch: " + ar); var w = chokidar.watch(ar, { persistent: true }); w.on('add', arAdd); w.on('change', arChange); w.on('unlink', appStop); watchers.push(w); } function arAdd(filename) { winston.info('add: ' + filename); appStart(filename); } function arChange(filename) { winston.info('change: ' + filename); appStop(filename); appStart(filename); } function appStop(file) { if (debug) { for (var x in apps) { winston.debug('running: ' + x); } } if (typeof apps[file] != 'undefined') { emitter.emit('stop', file); winston.info('stop: ' + file + ' (pid: ' + apps[file].pid + ')'); apps[file].kill('SIGTERM'); } else { winston.info('already stopped: ' + file); } } return ({ getApps: function () { return (apps); }, getEmitter: function () { return (emitter); }, stop: function () { for (var app in apps) { appStop(app); } for (var w in watchers) { watchers[w].close(); } } }); }; module.exports = { autorun: autorun }; ================================================ FILE: src/bone.js ================================================ // Database of pins // pinIndex is an array whose elements describe each pin. The order is // USR LEDs, P8 header pins, then P9 header // pins is an object whose keys are the pinIndex keys, e.g. P9_14. // uarts and i2c are objects describing the serial ports and i2c buses. var pinIndex = [{ "name": "USR0", "gpio": 53, "led": "beaglebone:green:usr0", "mux": "gpmc_a5", "key": "USR0", "muxRegOffset": "0x054", "options": [ "gpmc_a5", "gmii2_txd0", "rgmii2_td0", "rmii2_txd0", "gpmc_a21", "pr1_mii1_rxd3", "eqep1b_in", "gpio1_21" ], "ball": { "ZCZ": "V15", "BSM": "P13" }, "ai": { "gpio": 81, "ball": { "abc": [ "AF6", "" ] }, "muxRegOffset": [ "0x1528", "" ], "options": [ "vin1a_d13", "vin1b_d2", "", "", "vout3_d10", "gpmc_a25", "", "", "", "kbd_row7", "pr1_edc_sync1_out", "", "pr1_pru0_gpi10", "pr1_pru0_gpo10", "gpio3_17", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "USR1", "gpio": 54, "led": "beaglebone:green:usr1", "mux": "gpmc_a6", "key": "USR1", "muxRegOffset": "0x058", "options": [ "gpmc_a6", "gmii2_txclk", "rgmii2_tclk", "mmc2_dat4", "gpmc_a22", "pr1_mii1_rxd2", "eqep1_index", "gpio1_22" ], "ball": { "ZCZ": "U15", "BSM": "T14" }, "ai": { "gpio": 133, "ball": { "abc": [ "J11", "" ] }, "muxRegOffset": [ "0x16C0", "" ], "options": [ "mcasp1_axr3", "mcasp6_axr3", "", "uart6_rtsn", "", "", "vout2_d3", "", "vin4a_d3", "", "", "", "", "", "gpio5_5", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "USR2", "gpio": 55, "led": "beaglebone:green:usr2", "mux": "gpmc_a7", "key": "USR2", "muxRegOffset": "0x05c", "options": [ "gpmc_a7", "gmii2_rxclk", "rgmii2_rclk", "mmc2_dat5", "gpmc_a23", "pr1_mii1_rxd1", "eqep1_strobe", "gpio1_23" ], "ball": { "ZCZ": "T15", "BSM": "R14" }, "ai": { "gpio": 79, "ball": { "abc": [ "AG5", "" ] }, "muxRegOffset": [ "0x1520", "" ], "options": [ "vin1a_d11", "vin1b_d4", "", "", "vout3_d12", "gpmc_a23", "", "", "", "kbd_row5", "pr1_edc_latch1_in", "", "pr1_pru0_gpi8", "pr1_pru0_gpo8", "gpio3_15", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "USR3", "gpio": 56, "led": "beaglebone:green:usr3", "mux": "gpmc_a8", "key": "USR3", "muxRegOffset": "0x060", "options": [ "gpmc_a8", "gmii2_rxd3", "rgmii2_rd3", "mmc2_dat6", "gpmc_a24", "pr1_mii1_rxd0", "mcasp0_aclkx", "gpio1_24" ], "ball": { "ZCZ": "V16", "BSM": "P14" }, "ai": { "gpio": 78, "ball": { "abc": [ "AG3", "" ] }, "muxRegOffset": [ "0x151C", "" ], "options": [ "vin1a_d10", "vin1b_d5", "", "", "vout3_d13", "", "", "", "", "kbd_row4", "pr1_edc_latch0_in", "", "pr1_pru0_gpi7", "pr1_pru0_gpo7", "gpio3_14", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "USR4", "led": "beaglebone:green:usr4", "key": "USR4", "ai": { "gpio": 71, "ball": { "abc": [ "AH6", "" ] }, "muxRegOffset": [ "0x1500", "" ], "options": [ "vin1a_d3", "", "", "vout3_d4", "vout3_d20", "uart8_rtsn", "", "", "", "", "eCAP1_in_PWM1_out", "", "pr1_pru0_gpi0", "pr1_pru0_gpo0", "gpio3_7", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "DGND", "key": [ "P8_1", "P8_2", "P9_1", "P9_2", "P9_43", "P9_44", "P9_45", "P9_46", "P1_15", "P1_16", "P1_22", "P2_15", "P2_21", "E1_1", "E2_1", "E3_1", "E4_1", "S1_1_1", "S1_2_1", "UT0_1", "UT1_1", "UT5_1", "DSM2_2", "I2C_1", "GPS_2", "GPS_6", "GP0_1", "GP1_1" ] }, { "name": "GPIO1_6", "gpio": 38, "mux": "gpmc_ad6", "eeprom": 26, "key": "P8_3", "universalName": [ "ocp:P8_03_pinmux" ], "muxRegOffset": "0x018", "options": [ "gpmc_ad6", "mmc1_dat6", "NA", "NA", "NA", "NA", "NA", "gpio1_6" ], "ball": { "ZCZ": "R9", "BSM": "P4" }, "ai": { "gpio": 24, "ball": { "abc": [ "AB8", "" ] }, "muxRegOffset": [ "0x179C", "" ], "options": [ "mmc3_dat6", "spi4_d0", "uart10_ctsn", "", "vin2b_de1", "", "", "", "", "vin5a_hsync0", "ehrpwm3_tripzone_input", "pr2_mii1_rxd1", "pr2_pru0_gpi10", "pr2_pru0_gpo10", "gpio1_24", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_7", "gpio": 39, "mux": "gpmc_ad7", "eeprom": 27, "key": "P8_4", "universalName": [ "ocp:P8_04_pinmux" ], "muxRegOffset": "0x01c", "options": [ "gpmc_ad7", "mmc1_dat7", "NA", "NA", "NA", "NA", "NA", "gpio1_7" ], "ball": { "ZCZ": "T9", "BSM": "R4" }, "ai": { "gpio": 25, "ball": { "abc": [ "AB5", "" ] }, "muxRegOffset": [ "0x17A0", "" ], "options": [ "mmc3_dat7", "spi4_cs0", "uart10_rtsn", "", "vin2b_clk1", "", "", "", "", "vin5a_vsync0", "eCAP3_in_PWM3_out", "pr2_mii1_rxd0", "pr2_pru0_gpi11", "pr2_pru0_gpo11", "gpio1_25", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_2", "gpio": 34, "mux": "gpmc_ad2", "eeprom": 22, "key": "P8_5", "universalName": [ "ocp:P8_05_pinmux" ], "muxRegOffset": "0x008", "options": [ "gpmc_ad2", "mmc1_dat2", "NA", "NA", "NA", "NA", "NA", "gpio1_2" ], "ball": { "ZCZ": "R8", "BSM": "R1" }, "ai": { "gpio": 193, "ball": { "abc": [ "AC9", "" ] }, "muxRegOffset": [ "0x178C", "" ], "options": [ "mmc3_dat2", "spi3_cs0", "uart5_ctsn", "", "vin2b_d3", "", "", "", "", "vin5a_d3", "eQEP3_index", "pr2_mii_mr1_clk", "pr2_pru0_gpi6", "pr2_pru0_gpo6", "gpio7_1", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_3", "gpio": 35, "mux": "gpmc_ad3", "eeprom": 23, "key": "P8_6", "universalName": [ "ocp:P8_06_pinmux" ], "muxRegOffset": "0x00c", "options": [ "gpmc_ad3", "mmc1_dat3", "NA", "NA", "NA", "NA", "NA", "gpio1_3" ], "ball": { "ZCZ": "T8", "BSM": "T3" }, "ai": { "gpio": 194, "ball": { "abc": [ "AC3", "" ] }, "muxRegOffset": [ "0x1790", "" ], "options": [ "mmc3_dat3", "spi3_cs1", "uart5_rtsn", "", "vin2b_d2", "", "", "", "", "vin5a_d2", "eQEP3_strobe", "pr2_mii1_rxdv", "pr2_pru0_gpi7", "pr2_pru0_gpo7", "gpio7_2", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "TIMER4", "gpio": 66, "mux": "gpmc_advn_ale", "eeprom": 41, "key": [ "P8_7", "RED", "GP1_5" ], "led": [ null, "red", "red" ], "universalName": [ "ocp:P8_07_pinmux" ], "muxRegOffset": "0x090", "options": [ "gpmc_advn_ale", "NA", "timer4", "NA", "NA", "NA", "NA", "gpio2_2" ], "ball": { "ZCZ": "R7", "BSM": "M1" }, "ai": { "gpio": 165, "ball": { "abc": [ "G14", "" ] }, "muxRegOffset": [ "0x16EC", "" ], "options": [ "mcasp1_axr14", "mcasp7_aclkx", "mcasp7_aclkr", "", "", "", "", "vin6a_d9", "", "", "timer11", "pr2_mii0_rxdv", "pr2_pru1_gpi16", "pr2_pru1_gpo16", "gpio6_5", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "TIMER7", "gpio": 67, "mux": "gpmc_oen_ren", "eeprom": 44, "key": [ "P8_8", "GREEN", "GP1_6" ], "led": [ null, "green", "green" ], "universalName": [ "ocp:P8_08_pinmux" ], "muxRegOffset": "0x094", "options": [ "gpmc_oen_ren", "NA", "timer7", "NA", "NA", "NA", "NA", "gpio2_3" ], "ball": { "ZCZ": "T7", "BSM": "N1" }, "ai": { "gpio": 166, "ball": { "abc": [ "F14", "" ] }, "muxRegOffset": [ "0x16F0", "" ], "options": [ "mcasp1_axr15", "mcasp7_fsx", "mcasp7_fsr", "", "", "", "", "vin6a_d8", "", "", "timer12", "pr2_mii0_rxd3", "pr2_pru0_gpi20", "pr2_pru0_gpo20", "gpio6_6", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "TIMER5", "gpio": 69, "mux": "gpmc_ben0_cle", "eeprom": 42, "key": [ "P8_9", "PAUSE" ], "universalName": [ "ocp:P8_09_pinmux" ], "muxRegOffset": "0x09c", "options": [ "gpmc_ben0_cle", "NA", "timer5", "NA", "NA", "NA", "NA", "gpio2_5" ], "ball": { "ZCZ": "T6", "BSM": "N3" }, "ai": { "gpio": 178, "ball": { "abc": [ "E17", "" ] }, "muxRegOffset": [ "0x1698", "" ], "options": [ "xref_clk1", "mcasp2_axr9", "mcasp1_axr5", "mcasp2_ahclkx", "mcasp6_ahclkx", "", "", "vin6a_clk0", "", "", "timer14", "pr2_mii1_crs", "pr2_pru1_gpi6", "pr2_pru1_gpo6", "gpio6_18", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "TIMER6", "gpio": 68, "mux": "gpmc_wen", "eeprom": 43, "key": [ "P8_10", "MODE" ], "muxRegOffset": "0x098", "options": [ "gpmc_wen", "NA", "timer6", "NA", "NA", "NA", "NA", "gpio2_4" ], "ball": { "ZCZ": "U6", "BSM": "N2" }, "ai": { "gpio": 164, "ball": { "abc": [ "A13", "" ] }, "muxRegOffset": [ "0x16E8", "" ], "options": [ "mcasp1_axr13", "mcasp7_axr1", "", "", "", "", "", "vin6a_d10", "", "", "timer10", "pr2_mii_mr0_clk", "pr2_pru1_gpi15", "pr2_pru1_gpo15", "gpio6_4", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_13", "gpio": 45, "mux": "gpmc_ad13", "eeprom": 29, "key": [ "P8_11", "E3_4", "P2_33" ], "muxRegOffset": "0x034", "options": [ "gpmc_ad13", "lcd_data18", "mmc1_dat5", "mmc2_dat1", "eqep2B_in", "pr1_mii0_txd", "pr1_pru0_pru_r30_15", "gpio1_13" ], "ball": { "ZCZ": "R12", "BSM": "R6" }, "ai": { "gpio": 75, "ball": { "abc": [ "AH4", "" ] }, "muxRegOffset": [ "0x1510", "" ], "options": [ "vin1a_d7", "", "", "vout3_d0", "vout3_d16", "", "", "", "", "", "eQEP2B_in", "", "pr1_pru0_gpi4", "pr1_pru0_gpo4", "gpio3_11", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_12", "gpio": 44, "mux": "gpmc_ad12", "eeprom": 28, "key": [ "P8_12", "E3_3", "P2_24" ], "muxRegOffset": "0x030", "options": [ "gpmc_ad12", "lcd_data19", "mmc1_dat4", "mmc2_dat0", "eqep2a_in", "pr1_mii0_txd2", "pr1_pru0_pru_r30_14", "gpio1_12" ], "ball": { "ZCZ": "T12", "BSM": "P6" }, "ai": { "gpio": 74, "ball": { "abc": [ "AG6", "" ] }, "muxRegOffset": [ "0x150C", "" ], "options": [ "vin1a_d6", "", "", "vout3_d1", "vout3_d17", "", "", "", "", "", "eQEP2A_in", "", "pr1_pru0_gpi3", "pr1_pru0_gpo3", "gpio3_10", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "EHRPWM2B", "gpio": 23, "mux": "gpmc_ad9", "eeprom": 15, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm2", "sysfs": 6, "index": 1, "muxmode": 4, "path": "ehrpwm.2:1", "name": "EHRPWM2B", "chip": "48304000", "addr": "48304200" }, "key": [ "P8_13", "P2_3" ], "universalName": [ "ocp:P8_13_pinmux", "ocp:P2_03_pinmux" ], "muxRegOffset": "0x024", "options": [ "gpmc_ad9", "lcd_data22", "mmc1_dat1", "mmc2_dat5", "ehrpwm2B", "pr1_mii0_col", "NA", "gpio0_23" ], "ball": { "ZCZ": "T10", "BSM": "P5" }, "ai": { "gpio": 107, "ball": { "abc": [ "D3", "" ] }, "muxRegOffset": [ "0x1590", "" ], "options": [ "vin2a_d10", "", "", "mdio_mclk", "vout2_d13", "", "", "", "", "kbd_col7", "ehrpwm2B", "pr1_mdio_mdclk", "pr1_pru1_gpi7", "pr1_pru1_gpo7", "gpio4_11", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO0_26", "gpio": 26, "mux": "gpmc_ad10", "eeprom": 16, "key": [ "P8_14", "BAT100", "P1_34" ], "led": [ null, "bat100", null ], "muxRegOffset": "0x028", "options": [ "gpmc_ad10", "lcd_data21", "mmc1_dat2", "mmc2_dat6", "ehrpwm2_tripzone_input", "pr1_mii0_txen", "NA", "gpio0_26" ], "ball": { "ZCZ": "T11", "BSM": "R5" }, "ai": { "gpio": 109, "ball": { "abc": [ "D5", "" ] }, "muxRegOffset": [ "0x1598", "" ], "options": [ "vin2a_d12", "", "", "rgmii1_txc", "vout2_d11", "", "", "", "mii1_rxclk", "kbd_col8", "eCAP2_in_PWM2_out", "pr1_mii1_txd1", "pr1_pru1_gpi9", "pr1_pru1_gpo9", "gpio4_13", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_15", "gpio": 47, "mux": "gpmc_ad15", "eeprom": 31, "key": [ "P8_15", "E4_4", "P2_18" ], "muxRegOffset": "0x03c", "options": [ "gpmc_ad15", "lcd_data16", "mmc1_dat7", "mmc2_dat3", "eqep2_strobe", "pr1_ecap0_ecap_capin_apwm_o", "pr1_pru0_pru_r31_15", "gpio1_15" ], "ball": { "ZCZ": "U13", "BSM": "P7" }, "ai": { "gpio": 99, "ball": { "abc": [ "D1", "A3" ] }, "muxRegOffset": [ "0x1570", "0x15B4" ], "options": [ "vin2a_d2", "", "", "", "vout2_d21", "emu12", "", "", "uart10_rxd", "kbd_row6", "eCAP1_in_PWM1_out", "pr1_ecap0_ecap_capin_apwm_o", "pr1_edio_data_in7", "pr1_edio_data_out7", "gpio4_3", "Driver off", "vin2a_d19", "", "vin2b_d4", "rgmii1_rxctl", "vout2_d4", "", "vin3a_d11", "", "mii1_txer", "", "ehrpwm3_tripzone_input", "pr1_mii1_rxd0", "pr1_pru1_gpi16", "pr1_pru1_gpo16", "gpio4_27", "Driver off" ] } }, { "name": "GPIO1_14", "gpio": 46, "mux": "gpmc_ad14", "eeprom": 30, "key": [ "P8_16", "E4_3", "P2_22" ], "muxRegOffset": "0x038", "options": [ "gpmc_ad14", "lcd_data17", "mmc1_dat6", "mmc2_dat2", "eqep2_index", "pr1_mii0_txd0", "pr1_pru0_pru_r31_14", "gpio1_14" ], "ball": { "ZCZ": "V13", "BSM": "T6" }, "ai": { "gpio": 125, "ball": { "abc": [ "B4", "" ] }, "muxRegOffset": [ "0x15BC", "" ], "options": [ "vin2a_d21", "", "vin2b_d2", "rgmii1_rxd2", "vout2_d2", "vin3a_fld0", "vin3a_d13", "", "mii1_col", "", "", "pr1_mii1_rxlink", "pr1_pru1_gpi18", "pr1_pru1_gpo18", "gpio4_29", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO0_27", "gpio": 27, "mux": "gpmc_ad11", "eeprom": 17, "key": [ "P8_17", "BAT25", "P2_19" ], "led": [ null, "bat25", null ], "muxRegOffset": "0x02c", "options": [ "gpmc_ad11", "lcd_data20", "mmc1_dat3", "mmc2_dat7", "ehrpwm0_synco", "pr1_mii0_txd3", "NA", "gpio0_27" ], "ball": { "ZCZ": "U12", "BSM": "T5" }, "ai": { "gpio": 242, "ball": { "abc": [ "A7", "" ] }, "muxRegOffset": [ "0x1624", "" ], "options": [ "vout1_d18", "", "emu4", "vin4a_d2", "vin3a_d2", "obs11", "obs27", "", "", "", "pr2_edio_data_in2", "pr2_edio_data_out2", "pr2_pru0_gpi15", "pr2_pru0_gpo15", "gpio8_18", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO2_1", "gpio": 65, "mux": "gpmc_clk", "eeprom": 40, "key": [ "P8_18", "P2_17" ], "muxRegOffset": "0x08c", "options": [ "gpmc_clk", "lcd_memory_clk_mux", "NA", "mmc2_clk", "NA", "NA", "mcasp0_fsr", "gpio2_1" ], "ball": { "ZCZ": "V12", "BSM": "T7" }, "ai": { "gpio": 105, "ball": { "abc": [ "F5", "" ] }, "muxRegOffset": [ "0x1588", "" ], "options": [ "vin2a_d8", "", "", "", "vout2_d15", "emu18", "", "", "mii1_rxd3", "kbd_col5", "eQEP2_strobe", "pr1_mii1_txd3", "pr1_pru1_gpi5", "pr1_pru1_gpo5", "gpio4_9", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "EHRPWM2A", "gpio": 22, "mux": "gpmc_ad8", "eeprom": 14, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm2", "sysfs": 5, "index": 0, "muxmode": 4, "path": "ehrpwm.2:0", "name": "EHRPWM2A", "chip": "48304000", "addr": "48304200" }, "key": "P8_19", "muxRegOffset": "0x020", "options": [ "gpmc_ad8", "lcd_data23", "mmc1_dat0", "mmc2_dat4", "ehrpwm2A", "pr1_mii_mt0_clk", "NA", "gpio0_22" ], "ball": { "ZCZ": "U10", "BSM": "T4" }, "ai": { "gpio": 106, "ball": { "abc": [ "E6", "" ] }, "muxRegOffset": [ "0x158C", "" ], "options": [ "vin2a_d9", "", "", "", "vout2_d14", "emu19", "", "", "mii1_rxd0", "kbd_col6", "ehrpwm2A", "pr1_mii1_txd2", "pr1_pru1_gpi6", "pr1_pru1_gpo6", "gpio4_10", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_31", "gpio": 63, "mux": "gpmc_csn2", "eeprom": 39, "key": "P8_20", "muxRegOffset": "0x084", "options": [ "gpmc_csn2", "gpmc_be1n", "mmc1_cmd", "pr1_edio_data_in7", "pr1_edio_data_out7", "pr1_pru1_pru_r30_13", "pr1_pru1_pru_r31_13", "gpio1_31" ], "ball": { "ZCZ": "V9", "BSM": "P1" }, "ai": { "gpio": 190, "ball": { "abc": [ "AC4", "" ] }, "muxRegOffset": [ "0x1780", "" ], "options": [ "mmc3_cmd", "spi3_sclk", "", "", "vin2b_d6", "", "", "", "", "vin5a_d6", "eCAP2_in_PWM2_out", "pr2_mii1_txd2", "pr2_pru0_gpi3", "pr2_pru0_gpo3", "gpio6_30", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_30", "gpio": 62, "mux": "gpmc_csn1", "eeprom": 38, "key": "P8_21", "muxRegOffset": "0x080", "options": [ "gpmc_csn1", "gpmc_clk", "mmc1_clk", "pr1_edio_data_in6", "pr1_edio_data_out6", "pr1_pru1_pru_r30_12", "pr1_pru1_pru_r31_12", "gpio1_30" ], "ball": { "ZCZ": "U9", "BSM": "P2" }, "ai": { "gpio": 189, "ball": { "abc": [ "AD4", "" ] }, "muxRegOffset": [ "0x177C", "" ], "options": [ "mmc3_clk", "", "", "", "vin2b_d7", "", "", "", "", "vin5a_d7", "ehrpwm2_tripzone_input", "pr2_mii1_txd3", "pr2_pru0_gpi2", "pr2_pru0_gpo2", "gpio6_29", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_5", "gpio": 37, "mux": "gpmc_ad5", "eeprom": 25, "key": "P8_22", "muxRegOffset": "0x014", "options": [ "gpmc_ad5", "mmc1_dat5", "NA", "NA", "NA", "NA", "NA", "gpio1_5" ], "ball": { "ZCZ": "V8", "BSM": "T1" }, "ai": { "gpio": 23, "ball": { "abc": [ "AD6", "" ] }, "muxRegOffset": [ "0x1798", "" ], "options": [ "mmc3_dat5", "spi4_d1", "uart10_txd", "", "vin2b_d0", "", "", "", "", "vin5a_d0", "ehrpwm3B", "pr2_mii1_rxd2", "pr2_pru0_gpi9", "pr2_pru0_gpo9", "gpio1_23", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_4", "gpio": 36, "mux": "gpmc_ad4", "eeprom": 24, "key": "P8_23", "muxRegOffset": "0x010", "options": [ "gpmc_ad4", "mmc1_dat4", "NA", "NA", "NA", "NA", "NA", "gpio1_4" ], "ball": { "ZCZ": "U8", "BSM": "T2" }, "ai": { "gpio": 22, "ball": { "abc": [ "AC8", "" ] }, "muxRegOffset": [ "0x1794", "" ], "options": [ "mmc3_dat4", "spi4_sclk", "uart10_rxd", "", "vin2b_d1", "", "", "", "", "vin5a_d1", "ehrpwm3A", "pr2_mii1_rxd3", "pr2_pru0_gpi8", "pr2_pru0_gpo8", "gpio1_22", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_1", "gpio": 33, "mux": "gpmc_ad1", "eeprom": 21, "key": "P8_24", "muxRegOffset": "0x004", "options": [ "gpmc_ad1", "mmc1_dat1", "NA", "NA", "NA", "NA", "NA", "gpio1_1" ], "ball": { "ZCZ": "V7", "BSM": "R2" }, "ai": { "gpio": 192, "ball": { "abc": [ "AC6", "" ] }, "muxRegOffset": [ "0x1788", "" ], "options": [ "mmc3_dat1", "spi3_d0", "uart5_txd", "", "vin2b_d4", "", "", "", "", "vin5a_d4", "eQEP3B_in", "pr2_mii1_txd0", "pr2_pru0_gpi5", "pr2_pru0_gpo5", "gpio7_0", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_0", "gpio": 32, "mux": "gpmc_ad0", "eeprom": 20, "key": "P8_25", "muxRegOffset": "0x000", "options": [ "gpmc_ad0", "mmc1_dat0", "NA", "NA", "NA", "NA", "NA", "gpio1_0" ], "ball": { "ZCZ": "U7", "BSM": "R3" }, "ai": { "gpio": 191, "ball": { "abc": [ "AC7", "" ] }, "muxRegOffset": [ "0x1784", "" ], "options": [ "mmc3_dat0", "spi3_d1", "uart5_rxd", "", "vin2b_d5", "", "", "", "", "vin5a_d5", "eQEP3A_in", "pr2_mii1_txd1", "pr2_pru0_gpi4", "pr2_pru0_gpo4", "gpio6_31", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_29", "gpio": 61, "mux": "gpmc_csn0", "eeprom": 37, "key": [ "P8_26", "BAT75" ], "led": [ null, "bat75" ], "muxRegOffset": "0x07c", "options": [ "gpmc_csn0", "NA", "NA", "NA", "NA", "NA", "NA", "gpio1_29" ], "ball": { "ZCZ": "V6", "BSM": "P3" }, "ai": { "gpio": 124, "ball": { "abc": [ "B3", "" ] }, "muxRegOffset": [ "0x15B8", "" ], "options": [ "vin2a_d20", "", "vin2b_d3", "rgmii1_rxd3", "vout2_d3", "vin3a_de0", "vin3a_d12", "", "mii1_rxer", "", "eCAP3_in_PWM3_out", "pr1_mii1_rxer", "pr1_pru1_gpi17", "pr1_pru1_gpo17", "gpio4_28", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO0_19", "gpio": 19, "mux": "xdma_event_intr0", "eeprom": 37, "key": [ "WIFI", "P2_31" ], "led": [ "wifi", null ], "muxRegOffset": "0x1b0", "options": [ "xdma_event_intr0", "NA", "timer4", "clkout1", "spi1_cs1", "pr1_pru1_pru_r31", "EMU2", "gpio0_19" ], "ball": { "ZCZ": "A15", "BSM": "A4" } }, { "name": "GPIO2_22", "gpio": 86, "mux": "lcd_vsync", "eeprom": 57, "key": [ "P8_27", "SERVO_1", "P2_35" ], "muxRegOffset": "0x0e0", "options": [ "lcd_vsync", "gpmc_a8", "NA", "pr1_edio_data_in2", "pr1_edio_data_out2", "pr1_pru1_pru_r30_8", "pr1_pru1_pru_r31_8", "gpio2_22" ], "ball": { "ZCZ": "U5", "BSM": "F3" }, "ai": { "gpio": 119, "ball": { "abc": [ "E11", "A8" ] }, "muxRegOffset": [ "0x15D8", "0x1628" ], "options": [ "vout1_vsync", "", "", "vin4a_vsync0", "vin3a_vsync0", "", "", "", "spi3_sclk", "", "", "", "pr2_pru1_gpi17", "pr2_pru1_gpo17", "gpio4_23", "Driver off", "vout1_d19", "", "emu15", "vin4a_d3", "vin3a_d3", "obs12", "obs28", "", "", "", "pr2_edio_data_in3", "pr2_edio_data_out3", "pr2_pru0_gpi16", "pr2_pru0_gpo16", "gpio8_19", "Driver off" ] } }, { "name": "GPIO2_24", "gpio": 88, "mux": "lcd_pclk", "eeprom": 59, "key": [ "P8_28", "SERVO_2", "P1_35", "PRU1_10" ], "muxRegOffset": "0x0e8", "options": [ "lcd_pclk", "gpmc_a10", "pr1_mii0_crs", "pr1_edio_data_in4", "pr1_edio_data_out4", "pr1_pru1_pru_r30_10", "pr1_pru1_pru_r31_10", "gpio2_24" ], "ball": { "ZCZ": "V5", "BSM": "F1" }, "ai": { "gpio": 115, "ball": { "abc": [ "D11", "C9" ] }, "muxRegOffset": [ "0x15C8", "0x162C" ], "options": [ "vout1_clk", "", "", "vin4a_fld0", "vin3a_fld0", "", "", "", "spi3_cs0", "", "", "", "", "", "gpio4_19", "Driver off", "vout1_d20", "", "emu16", "vin4a_d4", "vin3a_d4", "obs13", "obs29", "", "", "", "pr2_edio_data_in4", "pr2_edio_data_out4", "pr2_pru0_gpi17", "pr2_pru0_gpo17", "gpio8_20", "Driver off" ] } }, { "name": "GPIO2_23", "gpio": 87, "mux": "lcd_hsync", "eeprom": 58, "key": [ "P8_29", "SERVO_3", "P1_2" ], "muxRegOffset": "0x0e4", "options": [ "lcd_hsync", "gpmc_a9", "gpmc_a2", "pr1_edio_data_in3", "pr1_edio_data_out3", "pr1_pru1_pru_r30_9", "pr1_pru1_pru_r31_9", "gpio2_23" ], "ball": { "ZCZ": "R5", "BSM": "F2" }, "ai": { "gpio": 118, "ball": { "abc": [ "C11", "A9" ] }, "muxRegOffset": [ "0x15D4", "0x1630" ], "options": [ "vout1_hsync", "", "", "vin4a_hsync0", "vin3a_hsync0", "", "", "", "spi3_d0", "", "", "", "", "", "gpio4_22", "Driver off", "vout1_d21", "", "emu17", "vin4a_d5", "vin3a_d5", "obs14", "obs30", "", "", "", "pr2_edio_data_in5", "pr2_edio_data_out5", "pr2_pru0_gpi18", "pr2_pru0_gpo18", "gpio8_21", "Driver off" ] } }, { "name": "GPIO2_25", "gpio": 89, "mux": "lcd_ac_bias_en", "eeprom": 60, "key": [ "P8_30", "SERVO_4", "P1_4", "PRU1_11" ], "muxRegOffset": "0x0ec", "options": [ "lcd_ac_bias_en", "gpmc_a11", "pr1_mii1_crs", "pr1_edio_data_in5", "pr1_edio_data_out5", "pr1_pru1_pru_r30_11", "pr1_pru1_pru_r31_11", "gpio2_25" ], "ball": { "ZCZ": "R6", "BSM": "E1" }, "ai": { "gpio": 116, "ball": { "abc": [ "B10", "B9" ] }, "muxRegOffset": [ "0x15CC", "0x1634" ], "options": [ "vout1_de", "", "", "vin4a_de0", "vin3a_de0", "", "", "", "spi3_d1", "", "", "", "", "", "gpio4_20", "Driver off", "vout1_d22", "", "emu18", "vin4a_d6", "vin3a_d6", "obs15", "obs31", "", "", "", "pr2_edio_data_in6", "pr2_edio_data_out6", "pr2_pru0_gpi19", "pr2_pru0_gpo19", "gpio8_22", "Driver off" ] } }, { "name": "UART5_CTSN", "gpio": 10, "mux": "lcd_data14", "eeprom": 7, "key": "P8_31", "muxRegOffset": "0x0d8", "options": [ "lcd_data14", "gpmc_a18", "NA", "mcasp0_axr1", "NA", "NA", "NA", "gpio0_10" ], "ball": { "ZCZ": "V4", "BSM": "L1" }, "ai": { "gpio": 238, "ball": { "abc": [ "C8", "G16" ] }, "muxRegOffset": [ "0x1614", "0x173C" ], "options": [ "vout1_d14", "", "emu13", "vin4a_d14", "vin3a_d14", "obs9", "obs25", "", "", "", "pr2_uart0_txd", "", "pr2_pru0_gpi11", "pr2_pru0_gpo11", "gpio8_14", "Driver off", "mcasp4_axr0", "", "spi3_d0", "uart8_ctsn", "uart4_rxd", "", "vout2_d18", "", "vin4a_d18", "vin5a_d13", "", "", "", "", "", "Driver off" ] } }, { "name": "UART5_RTSN", "gpio": 11, "mux": "lcd_data15", "eeprom": 8, "key": [ "P8_32", "BAT50" ], "led": [ null, "bat50" ], "muxRegOffset": "0x0dc", "options": [ "lcd_data15", "gpmc_a19", "NA", "mcasp0_ahclkx", "mcasp0_axr3", "NA", "NA", "gpio0_11" ], "ball": { "ZCZ": "T5", "BSM": "M3" }, "ai": { "gpio": 239, "ball": { "abc": [ "C7", "D17" ] }, "muxRegOffset": [ "0x1618", "0x1740" ], "options": [ "vout1_d15", "", "emu14", "vin4a_d15", "vin3a_d15", "obs10", "obs26", "", "", "", "pr2_ecap0_ecap_capin_apwm_o", "", "pr2_pru0_gpi12", "pr2_pru0_gpo12", "gpio8_15", "Driver off", "mcasp4_axr1", "", "spi3_cs0", "uart8_rtsn", "uart4_txd", "", "vout2_d19", "", "vin4a_d19", "vin5a_d12", "", "", "pr2_pru1_gpi0", "pr2_pru1_gpo0", "", "Driver off" ] } }, { "name": "UART4_RTSN", "gpio": 9, "mux": "lcd_data13", "eeprom": 6, "key": [ "P8_33", "E2_4" ], "muxRegOffset": "0x0d4", "options": [ "lcd_data13", "gpmc_a17", "NA", "mcasp0_fsr", "mcasp0_axr3", "NA", "NA", "gpio0_9" ], "ball": { "ZCZ": "V3", "BSM": "L2" }, "ai": { "gpio": 237, "ball": { "abc": [ "C6", "AF9" ] }, "muxRegOffset": [ "0x1610", "0x14E8" ], "options": [ "vout1_d13", "", "emu12", "vin4a_d13", "vin3a_d13", "obs8", "obs24", "", "", "", "pr2_uart0_rxd", "", "pr2_pru0_gpi10", "pr2_pru0_gpo10", "gpio8_13", "Driver off", "vin1a_fld0", "vin1b_vsync1", "", "", "vout3_clk", "uart7_txd", "", "timer15", "spi3_d1", "kbd_row1", "eQEP1B_in", "", "", "", "gpio3_1", "Driver off" ] } }, { "name": "UART3_RTSN", "gpio": 81, "mux": "lcd_data11", "eeprom": 56, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm1", "sysfs": 4, "index": 1, "muxmode": 2, "path": "ehrpwm.1:1", "name": "EHRPWM1B", "chip": "48302000", "addr": "48302200" }, "key": "P8_34", "muxRegOffset": "0x0cc", "options": [ "lcd_data11", "gpmc_a15", "NA", "mcasp0_ahclkr", "mcasp0_axr2", "NA", "NA", "gpio2_17" ], "ball": { "ZCZ": "V3", "BSM": "K1" }, "ai": { "gpio": 235, "ball": { "abc": [ "D8", "G6" ] }, "muxRegOffset": [ "0x1608", "0x1564" ], "options": [ "vout1_d11", "", "emu10", "vin4a_d11", "vin3a_d11", "obs6", "obs22", "obs_dmarq2", "", "", "pr2_uart0_cts_n", "", "pr2_pru0_gpi8", "pr2_pru0_gpo8", "gpio8_11", "Driver off", "vin2a_vsync0", "", "", "vin2b_vsync1", "vout2_vsync", "emu9", "", "uart9_txd", "spi4_d1", "kbd_row3", "ehrpwm1A", "pr1_uart0_rts_n", "pr1_edio_data_in4", "pr1_edio_data_out4", "gpio4_0", "Driver off" ] } }, { "name": "UART4_CTSN", "gpio": 8, "mux": "lcd_data12", "eeprom": 5, "key": [ "P8_35", "E2_3" ], "muxRegOffset": "0x0d0", "options": [ "lcd_data12", "gpmc_a16", "NA", "mcasp0_aclkr", "mcasp0_axr2", "NA", "NA", "gpio0_8" ], "ball": { "ZCZ": "V2", "BSM": "L3" }, "ai": { "gpio": 236, "ball": { "abc": [ "A5", "AD9" ] }, "muxRegOffset": [ "0x160C", "0x14E4" ], "options": [ "vout1_d12", "", "emu11", "vin4a_d12", "vin3a_d12", "obs7", "obs23", "", "", "", "pr2_uart0_rts_n", "", "pr2_pru0_gpi9", "pr2_pru0_gpo9", "gpio8_12", "Driver off", "vin1a_de0", "vin1b_hsync1", "", "vout3_d17", "vout3_de", "uart7_rxd", "", "timer16", "spi3_sclk", "kbd_row0", "eQEP1A_in", "", "", "", "gpio3_0", "Driver off" ] } }, { "name": "UART3_CTSN", "gpio": 80, "mux": "lcd_data10", "eeprom": 55, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm1", "sysfs": 3, "index": 0, "muxmode": 2, "path": "ehrpwm.1:0", "name": "EHRPWM1A", "chip": "48302000", "addr": "48302200" }, "key": [ "P8_36", "SERVO_PWR_EN" ], "muxRegOffset": "0x0c8", "options": [ "lcd_data10", "gpmc_a14", "ehrpwm1A", "mcasp0_axr0", "mcasp0_axr0", "pr1_mii0_rxd1", "uart3_ctsn", "gpio2_16" ], "ball": { "ZCZ": "U3", "BSM": "K2" }, "ai": { "gpio": 234, "ball": { "abc": [ "D7", "F2" ] }, "muxRegOffset": [ "0x1604", "0x1568" ], "options": [ "vout1_d10", "", "emu3", "vin4a_d10", "vin3a_d10", "obs5", "obs21", "obs_irq2", "", "", "pr2_edio_sof", "", "pr2_pru0_gpi7", "pr2_pru0_gpo7", "gpio8_10", "Driver off", "vin2a_d0", "", "", "", "vout2_d23", "emu10", "", "uart9_ctsn", "spi4_d0", "kbd_row4", "ehrpwm1B", "pr1_uart0_rxd", "pr1_edio_data_in5", "pr1_edio_data_out5", "gpio4_1", "Driver off" ] } }, { "name": "UART5_TXD", "gpio": 78, "mux": "lcd_data8", "eeprom": 53, "key": [ "P8_37", "UT5_4" ], "muxRegOffset": "0x0c0", "options": [ "lcd_data8", "gpmc_a12", "NA", "mcasp0_aclkx", "NA", "NA", "uart2_ctsn", "gpio2_14" ], "ball": { "ZCZ": "U1", "BSM": "J1" }, "ai": { "gpio": 232, "ball": { "abc": [ "E8", "A21" ] }, "muxRegOffset": [ "0x15FC", "0x1738" ], "options": [ "vout1_d8", "", "uart6_rxd", "vin4a_d8", "vin3a_d8", "", "", "", "", "", "pr2_edc_sync1_out", "", "pr2_pru0_gpi5", "pr2_pru0_gpo5", "gpio8_8", "Driver off", "mcasp4_fsx", "mcasp4_fsr", "spi3_d1", "uart8_txd", "i2c4_scl", "", "vout2_d17", "", "vin4a_d17", "vin5a_d14", "", "", "", "", "", "Driver off" ] } }, { "name": "UART5_RXD", "gpio": 79, "mux": "lcd_data9", "eeprom": 54, "key": [ "P8_38", "UT5_3" ], "muxRegOffset": "0x0c4", "options": [ "lcd_data9", "gpmc_a13", "NA", "mcasp0_fsx", "NA", "NA", "uart2_rtsn", "gpio2_15" ], "ball": { "ZCZ": "U2", "BSM": "K3" }, "ai": { "gpio": 233, "ball": { "abc": [ "D9", "C18" ] }, "muxRegOffset": [ "0x1600", "0x1734" ], "options": [ "vout1_d9", "", "uart6_txd", "vin4a_d9", "vin3a_d9", "", "", "", "", "", "pr2_edio_latch_in", "", "pr2_pru0_gpi6", "pr2_pru0_gpo6", "gpio8_9", "Driver off", "mcasp4_aclkx", "mcasp4_aclkr", "spi3_sclk", "uart8_rxd", "i2c4_sda", "", "vout2_d16", "", "vin4a_d16", "vin5a_d15", "", "", "", "", "", "Driver off" ] } }, { "name": "GPIO2_12", "gpio": 76, "mux": "lcd_data6", "eeprom": 51, "key": [ "P8_39", "SERVO_5" ], "muxRegOffset": "0x0b8", "options": [ "lcd_data6", "gpmc_a6", "pr1_edio_data_in6", "eqep2_index", "pr1_edio_data_out6", "pr1_pru1_pru_r30_6", "pr1_pru1_pru_r31_6", "gpio2_12" ], "ball": { "ZCZ": "T3", "BSM": "J3" }, "ai": { "gpio": 230, "ball": { "abc": [ "F8", "" ] }, "muxRegOffset": [ "0x15F4", "" ], "options": [ "vout1_d6", "", "emu8", "vin4a_d22", "vin3a_d22", "obs4", "obs20", "", "", "", "pr2_edc_latch1_in", "", "pr2_pru0_gpi3", "pr2_pru0_gpo3", "gpio8_6", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO2_13", "gpio": 77, "mux": "lcd_data7", "eeprom": 52, "key": [ "P8_40", "SERVO_6" ], "muxRegOffset": "0x0bc", "options": [ "lcd_data7", "gpmc_a7", "pr1_edio_data_in7", "eqep2_strobe", "pr1_edio_data_out_7", "pr1_pru1_pru_r30_7", "pr1_pru1_pru_r31_7", "gpio2_13" ], "ball": { "ZCZ": "T4", "BSM": "J2" }, "ai": { "gpio": 231, "ball": { "abc": [ "E7", "" ] }, "muxRegOffset": [ "0x15F8", "" ], "options": [ "vout1_d7", "", "emu9", "vin4a_d23", "vin3a_d23", "", "", "", "", "", "pr2_edc_sync0_out", "", "pr2_pru0_gpi4", "pr2_pru0_gpo4", "gpio8_7", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO2_10", "gpio": 74, "mux": "lcd_data4", "eeprom": 49, "key": [ "P8_41", "SERVO_7" ], "muxRegOffset": "0x0b0", "options": [ "lcd_data4", "gpmc_a4", "pr1_mii0_txd1", "eQEP2A_in", "NA", "pr1_pru1_pru_r30_4", "pr1_pru1_pru_r31_4", "gpio2_10" ], "ball": { "ZCZ": "T1", "BSM": "H2" }, "ai": { "gpio": 228, "ball": { "abc": [ "E9", "" ] }, "muxRegOffset": [ "0x15EC", "" ], "options": [ "vout1_d4", "", "emu6", "vin4a_d20", "vin3a_d20", "obs2", "obs18", "", "", "", "pr1_ecap0_ecap_capin_apwm_o", "", "pr2_pru0_gpi1", "pr2_pru0_gpo1", "gpio8_4", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO2_11", "gpio": 75, "mux": "lcd_data5", "eeprom": 50, "key": [ "P8_42", "SERVO_8" ], "muxRegOffset": "0x0b4", "options": [ "lcd_data5", "gpmc_a5", "pr1_mii0_txd0", "eqep2b_in", "NA", "pr1_pru1_pru_r30_5", "pr1_pru1_pru_r31_5", "gpio2_11" ], "ball": { "ZCZ": "T2", "BSM": "H1" }, "ai": { "gpio": 229, "ball": { "abc": [ "F9", "" ] }, "muxRegOffset": [ "0x15F0", "" ], "options": [ "vout1_d5", "", "emu7", "vin4a_d21", "vin3a_d21", "obs3", "obs19", "", "", "", "pr2_edc_latch0_in", "", "pr2_pru0_gpi2", "pr2_pru0_gpo2", "gpio8_5", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO2_8", "gpio": 72, "mux": "lcd_data2", "eeprom": 47, "key": "P8_43", "muxRegOffset": "0x0a8", "options": [ "lcd_data2", "gpmc_a2", "pr1_mii0_txd3", "ehrpwm2_tripzone_input", "NA", "pr1_pru1_pru_r30_2", "pr1_pru1_pru_r31_2", "gpio2_8" ], "ball": { "ZCZ": "R3", "BSM": "G1" }, "ai": { "gpio": 226, "ball": { "abc": [ "F10", "" ] }, "muxRegOffset": [ "0x15E4", "" ], "options": [ "vout1_d2", "", "emu2", "vin4a_d18", "vin3a_d18", "obs0", "obs16", "obs_irq1", "", "", "pr1_uart0_rxd", "", "pr2_pru1_gpi20", "pr2_pru1_gpo20", "gpio8_2", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO2_9", "gpio": 73, "mux": "lcd_data3", "eeprom": 48, "key": "P8_44", "muxRegOffset": "0x0ac", "options": [ "lcd_data3", "gpmc_a3", "pr1_mii0_txd2", "ehrpwm0_synco", "NA", "pr1_pru1_pru_r30_3", "pr1_pru1_pru_r31_3", "gpio2_9" ], "ball": { "ZCZ": "R4", "BSM": "H3" }, "ai": { "gpio": 227, "ball": { "abc": [ "G11", "" ] }, "muxRegOffset": [ "0x15E8", "" ], "options": [ "vout1_d3", "", "emu5", "vin4a_d19", "vin3a_d19", "obs1", "obs17", "obs_dmarq1", "", "", "pr1_uart0_txd", "", "pr2_pru0_gpi0", "pr2_pru0_gpo0", "gpio8_3", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO2_6", "gpio": 70, "mux": "lcd_data0", "eeprom": 45, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm2", "sysfs": 5, "index": 0, "muxmode": 3, "path": "ehrpwm.2:0", "name": "EHRPWM2A", "chip": "48304000", "addr": "48304200" }, "key": "P8_45", "muxRegOffset": "0x0a0", "options": [ "lcd_data0", "gpmc_a0", "pr1_mii_mt0_clk", "ehrpwm2A", "NA", "pr1_pru1_pru_r30_0", "pr1_pru1_pru_r31_0", "gpio2_6" ], "ball": { "ZCZ": "R1", "BSM": "G3" }, "ai": { "gpio": 224, "ball": { "abc": [ "F11", "B7" ] }, "muxRegOffset": [ "0x15DC", "0x161C" ], "options": [ "vout1_d0", "", "uart5_rxd", "vin4a_d16", "vin3a_d16", "", "", "", "spi3_cs2", "", "pr1_uart0_cts_n", "", "pr2_pru1_gpi18", "pr2_pru1_gpo18", "gpio8_0", "Driver off", "vout1_d16", "", "uart7_rxd", "vin4a_d0", "vin3a_d0", "", "", "", "", "", "pr2_edio_data_in0", "pr2_edio_data_out0", "pr2_pru0_gpi13", "pr2_pru0_gpo13", "gpio8_16", "Driver off" ] } }, { "name": "GPIO2_7", "gpio": 71, "mux": "lcd_data1", "eeprom": 46, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm2", "sysfs": 6, "index": 1, "muxmode": 3, "path": "ehrpwm.2:1", "name": "EHRPWM2B", "chip": "48304000", "addr": "48304200" }, "key": "P8_46", "muxRegOffset": "0x0a4", "options": [ "lcd_data1", "gpmc_a1", "pr1_mii0_txen", "ehrpwm2B", "NA", "pr1_pru1_pru_r30_1", "pr1_pru1_pru_r31_1", "gpio2_7" ], "ball": { "ZCZ": "R2", "BSM": "G2" }, "ai": { "gpio": 225, "ball": { "abc": [ "G10", "A10" ] }, "muxRegOffset": [ "0x15E0", "0x1638" ], "options": [ "vout1_d1", "", "uart5_txd", "vin4a_d17", "vin3a_d17", "", "", "", "", "", "pr1_uart0_rts_n", "", "pr2_pru1_gpi19", "pr2_pru1_gpo19", "gpio8_1", "Driver off", "vout1_d23", "", "emu19", "vin4a_d7", "vin3a_d7", "", "", "", "spi3_cs3", "", "pr2_edio_data_in7", "pr2_edio_data_out7", "pr2_pru0_gpi20", "pr2_pru0_gpo20", "gpio8_23", "Driver off" ] } }, { "name": "VDD_3V3", "key": [ "P9_3", "P9_4", "P1_14", "P2_23", "E1_2", "E2_2", "E3_2", "E4_2", "GP0_2", "GP1_2", "S1_1_2", "S1_2_2", "UT0_2", "UT1_2", "UT5_2", "DSM2_1", "I2C_2" ] }, { "name": "VDD_5V", "key": [ "P9_5", "P9_6", "P1_1" ] }, { "name": "SYS_5V", "key": [ "P9_7", "P9_8", "P1_24", "P2_13", "GPS_5" ] }, { "name": "PWR_BUT", "key": [ "P9_9", "P2_12" ], "ball": { "BSM": "T11" }, "ai": { "gpio": null, "ball": { "abc": [ "PMIC - G8", "" ] }, "muxRegOffset": [ "", "" ], "options": [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "SYS_RESETn", "key": [ "P9_10", "P2_26" ], "ball": { "ZCZ": "A10", "BSM": "R11" }, "ai": { "gpio": null, "ball": { "abc": [ "F23", "" ] }, "muxRegOffset": [ "0x1864", "" ], "options": [ "rstoutn", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "UART4_RXD", "gpio": 30, "mux": "gpmc_wait0", "eeprom": 18, "key": [ "P9_11", "DSM2_3", "P2_5" ], "muxRegOffset": "0x070", "options": [ "gpmc_wait0", "mii2_crs", "gpmc_csn4", "rmii2_crs_dv", "mmc1_sdcd", "pr1_mii1_col", "uart4_rxd", "gpio0_30" ], "ball": { "ZCZ": "T17", "BSM": "P15" }, "ai": { "gpio": 241, "ball": { "abc": [ "B19", "B8" ] }, "muxRegOffset": [ "0x172C", "0x1620" ], "options": [ "mcasp3_axr0", "", "mcasp2_axr14", "uart7_ctsn", "uart5_rxd", "", "", "vin6a_d1", "", "", "", "pr2_mii1_rxer", "pr2_pru0_gpi14", "pr2_pru0_gpo14", "", "Driver off", "vout1_d17", "", "uart7_txd", "vin4a_d1", "vin3a_d1", "", "", "", "", "", "pr2_edio_data_in1", "pr2_edio_data_out1", "pr2_pru0_gpi14", "pr2_pru0_gpo14", "gpio8_17", "Driver off" ] } }, { "name": "GPIO1_28", "gpio": 60, "mux": "gpmc_ben1", "eeprom": 36, "key": [ "P9_12", "P2_8" ], "muxRegOffset": "0x078", "options": [ "gpmc_ben1", "mii2_col", "NA", "mmc2_dat3", "NA", "NA", "mcasp0_aclkr", "gpio1_28" ], "ball": { "ZCZ": "U18", "BSM": "N14" }, "ai": { "gpio": 128, "ball": { "abc": [ "B14", "" ] }, "muxRegOffset": [ "0x16AC", "" ], "options": [ "mcasp1_aclkr", "mcasp7_axr2", "", "", "", "", "vout2_d0", "", "vin4a_d0", "", "i2c4_sda", "", "", "", "gpio5_0", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "UART4_TXD", "gpio": 31, "mux": "gpmc_wpn", "eeprom": 19, "key": [ "P9_13", "P2_7" ], "muxRegOffset": "0x074", "options": [ "gpmc_wpn", "mii2_rxerr", "NA", "rmii2_rxerr", "mmc2_sdcd", "NA", "NA", "gpio0_31" ], "ball": { "ZCZ": "U17", "BSM": "R16" }, "ai": { "gpio": 172, "ball": { "abc": [ "C17", "AB10**" ] }, "muxRegOffset": [ "0x1730", "0x1680" ], "options": [ "mcasp3_axr1", "", "mcasp2_axr15", "uart7_rtsn", "uart5_txd", "", "", "vin6a_d0", "", "vin5a_fld0", "", "pr2_mii1_rxlink", "pr2_pru0_gpi15", "pr2_pru0_gpo15", "", "Driver off", "usb1_drvvbus", "", "", "", "", "", "", "timer16", "", "", "", "", "", "", "gpio6_12", "Driver off" ] } }, { "name": "EHRPWM1A", "gpio": 50, "mux": "gpmc_a2", "eeprom": 34, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm1", "sysfs": 3, "index": 0, "muxmode": 6, "path": "ehrpwm.1:0", "name": "EHRPWM1A", "chip": "48302000", "addr": "48302200" }, "key": [ "P9_14", "P2_1" ], "universalName": [ "ocp:P9_14_pinmux", "ocp:P2_01_pinmux", "ocp:PWM_pinmux" ], "muxRegOffset": "0x048", "options": [ "gpmc_a2", "gmii2_txd3", "rgmii2_td3", "mmc2_dat1", "gpmc_a18", "pr1_mii1_txd2", "ehrpwm1A", "gpio1_18" ], "ball": { "ZCZ": "U14", "BSM": "P12" }, "ai": { "gpio": 121, "ball": { "abc": [ "D6", "" ] }, "muxRegOffset": [ "0x15AC", "" ], "options": [ "vin2a_d17", "", "vin2b_d6", "rgmii1_txd0", "vout2_d6", "", "vin3a_d9", "", "mii1_txd2", "", "ehrpwm3A", "pr1_mii1_rxd2", "pr1_pru1_gpi14", "pr1_pru1_gpo14", "gpio4_25", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_16", "gpio": 48, "mux": "mii1_rxd3", "eeprom": 32, "key": "P9_15", "muxRegOffset": "0x040", "options": [ "gpmc_a0", "gmii2_txen", "rgmii2_tctl", "rmii2_txen", "gpmc_a16", "pr1_mii_mt1_clk", "ehrpwm1_tripzone_input", "gpio1_16" ], "ball": { "ZCZ": "R13", "BSM": "T12" }, "ai": { "gpio": 76, "ball": { "abc": [ "AG4", "" ] }, "muxRegOffset": [ "0x1514", "" ], "options": [ "vin1a_d8", "vin1b_d7", "", "", "vout3_d15", "", "", "", "", "kbd_row2", "eQEP2_index", "", "pr1_pru0_gpi5", "pr1_pru0_gpo5", "gpio3_12", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_16", "gpio": 64, "mux": "gpmc_csn3", "eeprom": null, "key": [ "P9_15B", "P2_20" ], "muxRegOffset": "0x088", "options": [ "gpmc_csn3", "gpmc_a3", "rmii2_crs_dv", "mmc2_cmd", "pr1_mii0_crs", "pr1_mdio_data", "gpio2_0" ], "ball": { "ZCZ": "T13", "BSM": "R7" } }, { "name": "EHRPWM1B", "gpio": 51, "mux": "gpmc_a3", "eeprom": 35, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm1", "sysfs": 4, "index": 1, "muxmode": 6, "path": "ehrpwm.1:1", "name": "EHRPWM1B", "chip": "48302000", "addr": "48302200" }, "key": "P9_16", "muxRegOffset": "0x04c", "options": [ "gpmc_a3", "gmii2_txd2", "rgmii2_td2", "mmc2_dat2", "gpmc_a19", "pr1_mii1_txd1", "ehrpwm1B", "gpio1_19" ], "ball": { "ZCZ": "T14", "BSM": "T13" }, "ai": { "gpio": 122, "ball": { "abc": [ "C5", "" ] }, "muxRegOffset": [ "0x15B0", "" ], "options": [ "vin2a_d18", "", "vin2b_d5", "rgmii1_rxc", "vout2_d5", "", "vin3a_d10", "", "mii1_txd3", "", "ehrpwm3B", "pr1_mii1_rxd1", "pr1_pru1_gpi15", "pr1_pru1_gpo15", "gpio4_26", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "I2C1_SCL", "gpio": 5, "mux": "spi0_cs0", "eeprom": 3, "key": [ "P9_17", "I2C_3", "P1_6" ], "muxRegOffset": "0x15c", "options": [ "spi0_cs0", "mmc2_sdwp", "i2c1_scl", "ehrpwm0_synci", "pr1_uart0_txd", "pr1_edio_data_in1", "pr1_edio_data_out1", "gpio0_5" ], "ball": { "ZCZ": "A16", "BSM": "A14" }, "ai": { "gpio": 209, "ball": { "abc": [ "B24", "F12" ] }, "muxRegOffset": [ "0x17CC", "0x16B8" ], "options": [ "spi2_cs0", "uart3_rtsn", "uart5_txd", "", "", "", "", "", "", "", "", "", "", "", "gpio7_17", "Driver off", "mcasp1_axr1", "", "", "uart6_txd", "", "", "", "vin6a_hsync0", "", "", "i2c5_scl", "pr2_mii_mt0_clk", "pr2_pru1_gpi9", "pr2_pru1_gpo9", "gpio5_3", "Driver off" ] } }, { "name": "I2C1_SDA", "gpio": 4, "mux": "spi0_d1", "eeprom": 2, "key": [ "P9_18", "I2C_4", "P1_12" ], "muxRegOffset": "0x158", "options": [ "spi0_d1", "mmc1_sdwp", "i2c1_sda", "ehrpwm0_tripzone_input", "pr1_uart0_rxd", "pr1_edio_data_in0", "pr1_edio_data_out0", "gpio0_4" ], "ball": { "ZCZ": "B16", "BSM": "B14" }, "ai": { "gpio": 208, "ball": { "abc": [ "G17", "G12" ] }, "muxRegOffset": [ "0x17C8", "0x16B4" ], "options": [ "spi2_d0", "uart3_ctsn", "uart5_rxd", "", "", "", "", "", "", "", "", "", "", "", "gpio7_16", "Driver off", "mcasp1_axr0", "", "", "uart6_rxd", "", "", "", "vin6a_vsync0", "", "", "i2c5_sda", "pr2_mii0_rxer", "pr2_pru1_gpi8", "pr2_pru1_gpo8", "gpio5_2", "Driver off" ] } }, { "name": "I2C2_SCL", "gpio": 13, "mux": "uart1_rtsn", "eeprom": 9, "key": [ "P9_19", "P1_28" ], "muxRegOffset": "0x17c", "options": [ "uart1_rtsn", "timer5", "d_can0_rx", "i2c2_scl", "spi1_cs1", "pr1_uart0_rts_n", "pr1_edc_latch1_in", "gpio0_13" ], "ball": { "ZCZ": "D17", "BSM": "A10" }, "ai": { "gpio": 102, "ball": { "abc": [ "R6", "F4" ] }, "muxRegOffset": [ "0x1440", "0x157C" ], "options": [ "gpmc_a0", "", "vin3a_d16", "vout3_d16", "vin4a_d0", "", "vin4b_d0", "i2c4_scl", "uart5_rxd", "", "", "", "", "", "gpio7_3", "Driver off", "vin2a_d5", "", "", "", "vout2_d18", "emu15", "", "", "uart10_rtsn", "kbd_col2", "eQEP2A_in", "pr1_edio_sof", "pr1_pru1_gpi2", "pr1_pru1_gpo2", "gpio4_6", "Driver off" ] } }, { "name": "I2C2_SDA", "gpio": 12, "mux": "uart1_ctsn", "eeprom": 10, "key": [ "P9_20", "P1_26" ], "muxRegOffset": "0x178", "options": [ "uart1_ctsn", "NA", "d_can0_tx", "i2c2_sda", "spi1_cs0", "pr1_uart0_cts_n", "pr1_edc_latch0_in", "gpio0_12" ], "ball": { "ZCZ": "D18", "BSM": "B10" }, "ai": { "gpio": 101, "ball": { "abc": [ "T9", "D2" ] }, "muxRegOffset": [ "0x1444", "0x1578" ], "options": [ "gpmc_a1", "", "vin3a_d17", "vout3_d17", "vin4a_d1", "", "vin4b_d1", "i2c4_sda", "uart5_txd", "", "", "", "", "", "gpio7_4", "Driver off", "vin2a_d4", "", "", "", "vout2_d19", "emu14", "", "", "uart10_ctsn", "kbd_col1", "ehrpwm1_synco", "pr1_edc_sync0_out", "pr1_pru1_gpi1", "pr1_pru1_gpo1", "gpio4_5", "Driver off" ] } }, { "name": "UART2_TXD", "gpio": 3, "mux": "spi0_d0", "eeprom": 1, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm0", "sysfs": 1, "index": 1, "muxmode": 3, "path": "ehrpwm.0:1", "name": "EHRPWM0B", "chip": "48300000", "addr": "48300200" }, "key": [ "P9_21", "GPS_4", "P1_10" ], "muxRegOffset": "0x154", "options": [ "spi0_d0", "uart2_txd", "i2c2_scl", "ehrpwm0B", "pr1_uart_rts_n", "pr1_edio_latch_in", "EMU3", "gpio0_3" ], "ball": { "ZCZ": "B17", "BSM": "B13" }, "ai": { "gpio": 67, "ball": { "abc": [ "AF8", "B22" ] }, "muxRegOffset": [ "0x14F0", "0x17C4" ], "options": [ "vin1a_vsync0", "vin1b_de1", "", "", "vout3_vsync", "uart7_rtsn", "", "timer13", "spi3_cs0", "", "eQEP1_strobe", "", "", "", "gpio3_3", "Driver off", "spi2_d1", "uart3_txd", "", "", "", "", "", "", "", "", "", "", "", "", "gpio7_15", "Driver off" ] } }, { "name": "UART2_RXD", "gpio": 2, "mux": "spi0_sclk", "eeprom": 0, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm0", "sysfs": 0, "index": 0, "muxmode": 3, "path": "ehrpwm.0:0", "name": "EHRPWM0A", "chip": "48300000", "addr": "48300200" }, "key": [ "P9_22", "GPS_3", "P1_8" ], "muxRegOffset": "0x150", "options": [ "spi0_sclk", "uart2_rxd", "i2c2_sda", "ehrpwm0A", "pr1_uart_cts_n", "pr1_edio_sof", "EMU2", "gpio0_2" ], "ball": { "ZCZ": "A17", "BSM": "A13" }, "ai": { "gpio": 179, "ball": { "abc": [ "B26", "A26" ] }, "muxRegOffset": [ "0x169C", "0x17C0" ], "options": [ "xref_clk2", "mcasp2_axr10", "mcasp1_axr6", "mcasp3_ahclkx", "mcasp7_ahclkx", "", "vout2_clk", "", "vin4a_clk0", "", "timer15", "", "", "", "gpio6_19", "Driver off", "spi2_sclk", "uart3_rxd", "", "", "", "", "", "", "", "", "", "", "", "", "gpio7_14", "Driver off" ] } }, { "name": "GPIO1_17", "gpio": 49, "mux": "gpmc_a1", "eeprom": 33, "key": [ "P9_23", "GP0_4" ], "muxRegOffset": "0x044", "options": [ "gpmc_a1", "gmii2_rxdv", "rgmii2_rctl", "mmc2_dat0", "gpmc_a17", "pr1_mii1_txd3", "ehrpwm0_synco", "gpio1_17" ], "ball": { "ZCZ": "V14", "BSM": "R12" }, "ai": { "gpio": 203, "ball": { "abc": [ "A22", "" ] }, "muxRegOffset": [ "0x17B4", "" ], "options": [ "spi1_cs1", "", "sata1_led", "spi2_cs1", "", "", "", "", "", "", "", "", "", "", "gpio7_11", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO1_25", "gpio": 57, "mux": "gpmc_wpn", "eeprom": null, "key": [ "GP0_3", "P2_6" ], "muxRegOffset": "0x064", "options": [ "gpmc_wpn", "gmii2_rxer", "gpmc_csn5", "rmii2_rxer", "mmc2_sdcd", "pr1_mii1_txen", "uart4_txd", "gpio1_25" ], "ball": { "ZCZ": "U16", "BSM": "T15" } }, { "name": "GPIO3_2", "gpio": 98, "mux": "gmii1_rxer", "eeprom": null, "key": "GP1_3", "muxRegOffset": "0x110", "options": [ "gmii1_rxer", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_2" ], "ball": { "ZCZ": "J15", "BSM": "E15" } }, { "name": "GPIO3_1", "gpio": 97, "mux": "gmii1_crs", "eeprom": null, "key": "GP1_4", "muxRegOffset": "0x10c", "options": [ "gmii1_crs", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_1" ], "ball": { "ZCZ": "H17", "BSM": "F14" } }, { "name": "UART1_TXD", "gpio": 15, "mux": "uart1_txd", "eeprom": 12, "key": [ "P9_24", "UT1_4", "P2_9" ], "muxRegOffset": "0x184", "options": [ "uart1_txd", "mmc2_sdwp", "d_can1_rx", "i2c1_scl", "NA", "pr1_uart0_txd_mux1", "NA", "gpio0_15" ], "ball": { "ZCZ": "D15", "BSM": "B11" }, "ai": { "gpio": 175, "ball": { "abc": [ "F20", "" ] }, "muxRegOffset": [ "0x168C", "" ], "options": [ "gpio6_15", "mcasp1_axr9", "dcan2_rx", "uart10_txd", "", "", "vout2_vsync", "", "vin4a_vsync0", "i2c3_scl", "timer2", "", "", "", "gpio6_15", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "GPIO3_21", "gpio": 117, "mux": "mcasp0_ahclkx", "eeprom": 66, "key": [ "P9_25", "P1_29", "PRU0_7" ], "muxRegOffset": "0x1ac", "options": [ "mcasp0_ahclkx", "NA", "mcasp0_axr3", "mcasp1_axr1", "NA", "NA", "NA", "gpio3_21" ], "ball": { "ZCZ": "A14", "BSM": "C4" }, "ai": { "gpio": 177, "ball": { "abc": [ "D18", "" ] }, "muxRegOffset": [ "0x1694", "" ], "options": [ "xref_clk0", "mcasp2_axr8", "mcasp1_axr4", "mcasp1_ahclkx", "mcasp5_ahclkx", "", "", "vin6a_d0", "hdq0", "clkout2", "timer13", "pr2_mii1_col", "pr2_pru1_gpi5", "pr2_pru1_gpo5", "gpio6_17", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "UART1_RXD", "gpio": 14, "mux": "uart1_rxd", "eeprom": 11, "key": [ "P9_26", "UT1_3", "P2_11" ], "muxRegOffset": "0x180", "options": [ "uart1_rxd", "mmc1_sdwp", "d_can1_tx", "i2c1_sda", "NA", "pr1_uart0_rxd_mux1", "pr1_pru1_pru_r31_16", "gpio0_14" ], "ball": { "ZCZ": "D16", "BSM": "A11" }, "ai": { "gpio": 88, "ball": { "abc": [ "E21", "AE2" ] }, "muxRegOffset": [ "0x1688", "0x1544" ], "options": [ "gpio6_14", "mcasp1_axr8", "dcan2_tx", "uart10_rxd", "", "", "vout2_hsync", "", "vin4a_hsync0", "i2c3_sda", "timer1", "", "", "", "gpio6_14", "Driver off", "vin1a_d20", "vin1b_d3", "", "", "vout3_d3", "", "vin3a_d4", "", "", "kbd_col5", "pr1_edio_data_in4", "pr1_edio_data_out4", "pr1_pru0_gpi17", "pr1_pru0_gpo17", "gpio3_24", "Driver off" ] } }, { "name": "GPIO3_19", "gpio": 115, "mux": "mcasp0_fsr", "eeprom": 64, "key": [ "P9_27", "P2_34", "PRU0_5", "E1_4" ], "muxRegOffset": "0x1a4", "options": [ "mcasp0_fsr", "NA", "mcasp0_axr3", "mcasp1_fsx", "EMU2", "pr1_pru0_pru_r30_5", "pr1_pru0_pru_r31_5", "gpio3_19" ], "ball": { "ZCZ": "C13", "BSM": "B3" }, "ai": { "gpio": 111, "ball": { "abc": [ "C3", "J14" ] }, "muxRegOffset": [ "0x15A0", "0x16B0" ], "options": [ "vin2a_d14", "", "", "rgmii1_txd3", "vout2_d9", "", "", "", "mii1_txclk", "", "eQEP3B_in", "pr1_mii_mr1_clk", "pr1_pru1_gpi11", "pr1_pru1_gpo11", "gpio4_15", "Driver off", "mcasp1_fsr", "mcasp7_axr3", "", "", "", "", "vout2_d1", "", "vin4a_d1", "", "i2c4_scl", "", "", "", "gpio5_1", "Driver off" ] } }, { "name": "SPI1_CS0", "gpio": 113, "mux": "mcasp0_ahclkr", "eeprom": 63, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ecap2", "sysfs": 7, "index": 0, "muxmode": 4, "path": "ecap.2", "name": "ECAPPWM2", "universalMode": "pwm2", "chip": "48304000", "addr": "48304100" }, "key": [ "P9_28", "GP0_6", "P2_30", "PRU0_3" ], "muxRegOffset": "0x19c", "options": [ "mcasp0_ahclkr", "NA", "mcasp0_axr2", "spi1_cs0", "eCAP2_in_PWM2_out", "pr1_pru0_pru_r30_3", "pr1_pru0_pru_r31_3", "gpio3_17" ], "ball": { "ZCZ": "C12", "BSM": "B1" }, "ai": { "gpio": 113, "ball": { "abc": [ "A12", "" ] }, "muxRegOffset": [ "0x16E0", "" ], "options": [ "mcasp1_axr11", "mcasp6_fsx", "mcasp6_fsr", "spi3_cs0", "", "", "", "vin6a_d12", "", "", "timer8", "pr2_mii0_txd1", "pr2_pru1_gpi13", "pr2_pru1_gpo13", "gpio4_17", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "SPI1_D0", "gpio": 111, "mux": "mcasp0_fsx", "eeprom": 61, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm0", "sysfs": 1, "index": 1, "muxmode": 1, "path": "ehrpwm.0:1", "name": "EHRPWM0B", "chip": "48300000", "addr": "48300200" }, "key": [ "P9_29", "S1_1_4", "S1_2_4", "P1_33", "PRU0_1" ], "muxRegOffset": "0x194", "options": [ "mcasp0_fsx", "ehrpwm0B", "NA", "spi1_d0", "mmc1_sdcd", "pr1_pru0_pru_r30_1", "pr1_pru0_pru_r31_1", "gpio3_15" ], "ball": { "ZCZ": "B13", "BSM": "A2" }, "ai": { "gpio": 139, "ball": { "abc": [ "A11", "D14" ] }, "muxRegOffset": [ "0x16D8", "0x16A8" ], "options": [ "mcasp1_axr9", "mcasp6_axr1", "", "spi3_d1", "", "", "", "vin6a_d14", "", "", "timer6", "pr2_mii0_txd3", "pr2_pru1_gpi11", "pr2_pru1_gpo11", "gpio5_11", "Driver off", "mcasp1_fsx", "", "", "", "", "", "", "vin6a_de0", "", "", "i2c3_scl", "pr2_mdio_data", "", "", "gpio7_30", "Driver off" ] } }, { "name": "SPI1_D1", "gpio": 112, "mux": "mcasp0_axr0", "eeprom": 62, "key": [ "P9_30", "S1_1_3", "S1_2_3", "P2_32", "PRU0_2" ], "muxRegOffset": "0x198", "options": [ "mcasp0_axr0", "NA", "NA", "spi1_d1", "mmc2_sdcd", "pr1_pru0_pru_r30_2", "pr1_pru0_pru_r31_2", "gpio3_16" ], "ball": { "ZCZ": "D12", "BSM": "B2" }, "ai": { "gpio": 140, "ball": { "abc": [ "B13", "" ] }, "muxRegOffset": [ "0x16DC", "" ], "options": [ "mcasp1_axr10", "mcasp6_aclkx", "mcasp6_aclkr", "spi3_d0", "", "", "", "vin6a_d13", "", "", "timer7", "pr2_mii0_txd2", "pr2_pru1_gpi12", "pr2_pru1_gpo12", "gpio5_12", "Driver off", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ] } }, { "name": "SPI1_SCLK", "gpio": 110, "mux": "mcasp0_aclkx", "eeprom": 65, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ehrpwm0", "sysfs": 0, "index": 0, "muxmode": 1, "path": "ehrpwm.0:0", "name": "EHRPWM0A", "chip": "48300000", "addr": "48300200" }, "key": [ "P9_31", "S1_1_5", "S1_2_5", "P1_36" ], "muxRegOffset": "0x190", "options": [ "mcasp0_aclkx", "ehrpwm0A", "NA", "spi1_sclk", "mmc0_sdcd", "pr1_pru0_pru_r30_0", "pr1_pru0_pru_r31_0", "gpio3_14" ], "ball": { "ZCZ": "A13", "BSM": "A1" }, "ai": { "gpio": 138, "ball": { "abc": [ "B12", "C14" ] }, "muxRegOffset": [ "0x16D4", "0x16A4" ], "options": [ "mcasp1_axr8", "mcasp6_axr0", "", "spi3_sclk", "", "", "", "vin6a_d15", "", "", "timer5", "pr2_mii0_txen", "pr2_pru1_gpi10", "pr2_pru1_gpo10", "gpio5_10", "Driver off", "mcasp1_aclkx", "", "", "", "", "", "", "vin6a_fld0", "", "", "i2c3_sda", "pr2_mdio_mdclk", "pr2_pru1_gpi7", "pr2_pru1_gpo7", "gpio7_31", "Driver off" ] } }, { "name": "VDD_ADC", "key": [ "P9_32", "ADC_2", "P1_17" ], "ball": { "ZCZ": "A9", "BSM": "B9" }, "ai": { // 0 = 1.8V, 1 = 3.3V "gpio": 91, "ball": { "abc": [ "AD3", "" ] }, "muxRegOffset": [ "0x1550", "" ], "options": [ "vin1a_d23", "vin1b_d0", "", "", "vout3_d0", "", "vin3a_d7", "", "", "kbd_col8", "pr1_edio_data_in7", "pr1_edio_data_out7", "pr1_pru0_gpi20", "pr1_pru0_gpo20", "gpio3_27", "Driver off" ] } }, { "name": "AIN4", "ain": 4, "eeprom": 71, "scale": 4096, "key": [ "P9_33", "P1_27" ], "ball": { "ZCZ": "C8", "BSM": "C7" }, "ai": { "ain": 7, "gpio": 503 } }, { "name": "GNDA_ADC", "key": [ "P9_34", "ADC_1", "P1_18" ], "ball": { "ZCZ": "B9", "BSM": "B7" } }, { "name": "AIN6", "ain": 6, "eeprom": 73, "scale": 4096, "key": [ "P9_35", "P1_2" ], "ball": { "ZCZ": "A8", "BSM": "C9" }, "ai": { "ain": 4, "gpio": 500 } }, { "name": "AIN5", "ain": 5, "eeprom": 72, "scale": 4096, "key": [ "P9_36", "P2_35" ], "ball": { "ZCZ": "B8", "BSM": "C8" }, "ai": { "ain": 6, "gpio": 502 } }, { "name": "AIN2", "ain": 2, "eeprom": 69, "scale": 4096, "key": [ "P9_37", "ADC_5", "P1_23" ], "ball": { "ZCZ": "B7", "BSM": "B6" }, "ai": { "ain": 3, "gpio": 498 } }, { "name": "AIN3", "ain": 3, "eeprom": 70, "scale": 4096, "key": [ "P9_38", "ADC_6", "P1_25" ], "ball": { "ZCZ": "A7", "BSM": "C6" }, "ai": { "ain": 2, "gpio": 497 } }, { "name": "AIN0", "ain": 0, "eeprom": 67, "scale": 4096, "key": [ "P9_39", "ADC_3", "P1_19" ], "ball": { "ZCZ": "B6", "BSM": "A8" }, "ai": { "ain": 0, "gpio": 496 } }, { "name": "AIN1", "ain": 1, "eeprom": 68, "scale": 4096, "key": [ "P9_40", "ADC_4", "P1_21" ], "ball": { "ZCZ": "C7", "BSM": "B8" }, "ai": { "ain": 1, "gpio": 497 } }, { "name": "AIN7", "ain": 7, "eeprom": null, "scale": 4096, "key": "P2_36", "ball": { "ZCZ": "C9", "BSM": "D7" } }, { "name": "CLKOUT2", "gpio": 116, "mux": "mcasp0_axr1", "eeprom": null, "key": [ "P9_41", "GP0_5", "P2_28", "PRU0_6" ], "muxRegOffset": "0x1a8", "options": [ "mcasp0_axr1", "eQEP0_index", "mcasp1_axr0", "EMU3", "NA", "NA", "NA", "gpio3_20" ], "ball": { "ZCZ": "D13", "BSM": "C3" }, "ai": { "gpio": 180, "ball": { "abc": [ "C23", "C1" ] }, "muxRegOffset": [ "0x16A0", "0x1580" ], "options": [ "xref_clk3", "mcasp2_axr11", "mcasp1_axr7", "mcasp4_ahclkx", "mcasp8_ahclkx", "", "vout2_de", "hdq0", "vin4a_de0", "clkout3", "timer16", "", "", "", "gpio6_20", "Driver off", "vin2a_d6", "", "", "", "vout2_d17", "emu16", "", "", "mii1_rxd1", "kbd_col3", "eQEP2B_in", "pr1_mii_mt1_clk", "pr1_pru1_gpi3", "pr1_pru1_gpo3", "gpio4_7", "Driver off" ] } }, { "name": "CLKOUT2", "gpio": 20, "mux": "xdma_event_intr1", "eeprom": 13, "key": [ "P9_41B", "P1_20" ], "muxRegOffset": "0x1b4", "options": [ "xdma_event_intr1", "NA", "NA", "clkout2", "NA", "NA", "NA", "gpio0_20" ], "ball": { "ZCZ": "D14", "BSM": "B4" } }, { "name": "GPIO0_7", "gpio": 7, "mux": "ecap0_in_pwm0_out", "eeprom": 4, // From am335x technical manual, p.183 // http://www.ti.com/lit/ug/spruh73n/spruh73n.pdf "pwm": { "module": "ecap0", "sysfs": 2, "index": 0, "muxmode": 0, "path": "ecap.0", "name": "ECAPPWM0", "chip": "48300000", "addr": "48300100" }, "key": [ "P9_42", "S1_2_6", "P2_29" ], "muxRegOffset": "0x164", "options": [ "eCAP0_in_PWM0_out", "uart3_txd", "spi1_cs1", "pr1_ecap0_ecap_capin_apwm_o", "spi1_sclk", "mmc0_sdwp", "xdma_event_intr2", "gpio0_7" ], "ball": { "ZCZ": "C18", "BSM": "C5" }, "ai": { "gpio": 114, "ball": { "abc": [ "E14", "C2" ] }, "muxRegOffset": [ "0x16E4", "0x159C" ], "options": [ "mcasp1_axr12", "mcasp7_axr0", "", "spi3_cs1", "", "", "", "vin6a_d11", "", "", "timer9", "pr2_mii0_txd0", "pr2_pru1_gpi14", "pr2_pru1_gpo14", "gpio4_18", "Driver off", "vin2a_d13", "", "", "rgmii1_txctl", "vout2_d10", "", "", "", "mii1_rxdv", "kbd_row8", "eQEP3A_in", "pr1_mii1_txd0", "pr1_pru1_gpi10", "pr1_pru1_gpo10", "gpio4_14", "Driver off" ] } }, { "name": "GPIO0_7", "gpio": 114, "mux": "ecap0_in_pwm0_out", "eeprom": null, "key": [ "P9_42B", "E1_3", "P1_31", "PRU0_4" ], "muxRegOffset": "0x1a0", "options": [ "mcasp0_aclkr", "eQEP0A_in", "mcasp0_axr2", "mcasp1_aclkx", "mmc0_sdwp", "pr1_pru0_pru_r30_4", "pr1_pru0_pru_r31_4", "gpio3_18" ], "ball": { "ZCZ": "B12", "BSM": "A3" } }, { "name": "USB1_DRVVBUS", "gpio": 109, "key": "P1_3", "muxRegOffset": "0x134", "mux": "USB1_DRVVBUS", "eeprom": null, "options": [ "USB1_DRVVBUS", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_13" ], "ball": { "ZCZ": "F15", "BSM": "M14" } }, { "name": "USB1_VBUS", "key": "P1_5", "ball": { "ZCZ": "T18", "BSM": "M15" }, "muxRegOffset": "0x130" }, { "name": "VIN_USB", "key": "P1_7", "ball": { "BSM": [ "P9", "R9", "T9" ] } }, { "name": "USB1_DN", "key": "P1_9", "ball": { "ZCZ": "R18", "BSM": "L16" }, "muxRegOffset": "0x120" }, { "name": "USB1_DP", "key": "P1_11", "ball": { "ZCZ": "R17", "BSM": "L15" }, "muxRegOffset": "0x124" }, { "name": "USB1_ID", "key": "P1_13", "ball": { "ZCZ": "P17", "BSM": "L14" }, "muxRegOffset": "0x12c" }, { "name": "VIN_BAT", "key": "P2_14", "ball": { "BSM": [ "P8", "R8", "T8" ] } }, { "name": "BAT_TEMP", "key": "P2_16", "ball": { "BSM": "N6" } }, { "name": "UART0_RXD", "gpio": 42, "mux": "uart0_rxd", "eeprom": null, "key": [ "UT0_3", "P1_32" ], "muxRegOffset": "0x170", "options": [ "uart0_rxd", "spi1_cs0", "dcan0_tx", "i2c2_sda", "eCAP2_in_PWM2_out", "pr1_pru1_pru_r30_14", "pr1_pru1_pru_r31_14", "gpio1_10" ], "ball": { "ZCZ": "E15", "BSM": "A12" } }, { "name": "UART0_TXD", "gpio": 43, "mux": "uart0_txd", "eeprom": null, "key": [ "UT0_4", "P1_30" ], "muxRegOffset": "0x174", "options": [ "uart0_rxd", "spi1_cs1", "dcan0_4x", "i2c2_scl", "eCAP1_in_PWM1_out", "pr1_pru1_pru_r30_15", "pr1_pru1_pru_r31_15", "gpio1_11" ], "ball": { "ZCZ": "E16", "BSM": "B12" } }, { "name": "GPIO1_20", "gpio": 52, "mux": "gpmc_a4", "eeprom": null, "key": "P2_10", "muxRegOffset": "0x050", "options": [ "gpmc_a4", "gmii2_txd1", "rgmii2_td1", "rmii2_txd1", "gpmc_a20", "pr1_mii1_txd0", "eQEP1A_in", "gpio1_20" ], "ball": { "ZCZ": "R14", "BSM": "R13" } }, { "name": "GPIO1_27", "gpio": 59, "mux": "gpmc_a11", "eeprom": null, "key": "P2_2", "muxRegOffset": "0x06c", "options": [ "gpmc_a11", "gmii2_rxd0", "rgmii2_rd0", "rmii2_rxd0", "gpmc_a27", "pr1_mii1_rxer", "mcasp0_axr1", "gpio1_27" ], "ball": { "ZCZ": "V17", "BSM": "T16" } }, { "name": "GPIO1_26", "gpio": 58, "mux": "gpmc_a10", "eeprom": null, "key": "P2_4", "muxRegOffset": "0x068", "options": [ "gpmc_a10", "gmii2_rxd1", "rgmii2_rd1", "rmii2_rxd1", "gpmc_a26", "pr1_mii1_rxdv", "mcasp0_axr0", "gpio1_26" ], "ball": { "ZCZ": "T16", "BSM": "R15" } }, { "name": "GPIO1_9", "gpio": 41, "mux": "uart0_rtsn", "eeprom": null, "key": "P2_25", "muxRegOffset": "0x16c", "options": [ "uart0_rtsn", "uart4_txd", "dcan1_rx", "i2c1_scl", "spi1_d1", "spi1_cs0", "pr1_edc_sync1_out", "gpio1_9" ], "ball": { "ZCZ": "E17", "BSM": "C13" } }, { "name": "GPIO1_8", "gpio": 40, "mux": "uart0_ctsn", "eeprom": null, "key": "P2_27", "muxRegOffset": "0x168", "options": [ "uart0_ctsn", "uart4_txd", "dcan1_tx", "i2c1_sda", "spi1_d0", "timer7", "pr1_edc_sync0_out", "gpio1_8" ], "ball": { "ZCZ": "E18", "BSM": "C12" } }, { "name": "MMC0_SDCD", "gpio": 6, "mux": "spi0_cs1", "eeprom": null, "muxRegOffset": "0x160", "options": [ "spi0_cs1", "uart3_rxd", "eCAP1_in_PWM1_out", "mmc0_pow", "xdma_event_intr2", "mmc0_sdcd", "EMU4", "gpio0_6" ], "ball": { "ZCZ": "C15", "BSM": "C14" } }, { "name": "MDIO_DATA", "gpio": 0, "mux": "mdio_data", "eeprom": null, "muxRegOffset": "0x148", "options": [ "mdio_data", "timer6", "uart5_rxd", "uart3_ctsn", "mmc0_sdcd", "mmc1_cmd", "mmc2_cmd", "gpio0_0" ], "ball": { "ZCZ": "M17", "BSM": "E13" } }, { "name": "MDIO_CLK", "gpio": 1, "mux": "mdio_clk", "eeprom": null, "muxRegOffset": "0x14c", "options": [ "mdio_clk", "timer5", "uart5_txd", "uart3_rtsn", "mmc0_wp", "mmc1_clk", "mmc2_clk", "gpio0_1" ], "ball": { "ZCZ": "M18", "BSM": "D13" } }, { "name": "MII_TX3", "gpio": 16, "mux": "gmii1_txd3", "eeprom": null, "muxRegOffset": "0x11c", "options": [ "gmii1_txd3", "NA", "NA", "NA", "NA", "NA", "NA", "gpio0_16" ], "ball": { "ZCZ": "J18", "BSM": "G15" } }, { "name": "MII_TX2", "gpio": 17, "mux": "gmii1_txd2", "eeprom": null, "muxRegOffset": "0x120", "options": [ "gmii1_txd2", "NA", "NA", "NA", "NA", "NA", "NA", "gpio0_17" ], "ball": { "ZCZ": "K15", "BSM": "G16" } }, { "name": "USB0_DRVVBUS", "gpio": 18, "mux": "USB0_DRVVBUS", "eeprom": null, "muxRegOffset": "0x11c", "options": [ "USB0_DRVVBUS", "NA", "NA", "NA", "NA", "NA", "NA", "gpio0_18" ], "ball": { "ZCZ": "F16", "BSM": "J15" } }, { "name": "MII_TX1", "gpio": 21, "mux": "gmii1_txd1", "eeprom": null, "muxRegOffset": "0x124", "options": [ "gmii1_txd1", "NA", "NA", "NA", "NA", "NA", "NA", "gpio0_21" ], "ball": { "ZCZ": "K16", "BSM": "H14" } }, { "name": "MII_TX1", "gpio": 21, "mux": "gmii1_txd1", "eeprom": null, "muxRegOffset": "0x124", "options": [ "gmii1_txd1", "NA", "NA", "NA", "NA", "NA", "NA", "gpio0_21" ], "ball": { "ZCZ": "K16", "BSM": "H14" } }, { "name": "MII_TX0", "gpio": 28, "mux": "gmii1_txd0", "eeprom": null, "muxRegOffset": "0x128", "options": [ "gmii1_txd0", "NA", "NA", "NA", "NA", "NA", "NA", "gpio0_28" ], "ball": { "ZCZ": "K17", "BSM": "H15" } }, { "name": "MII_TX0", "gpio": 28, "mux": "gmii1_txd0", "eeprom": null, "muxRegOffset": "0x128", "options": [ "gmii1_txd0", "NA", "NA", "NA", "NA", "NA", "NA", "gpio0_28" ], "ball": { "ZCZ": "K17", "BSM": "H15" } }, { "name": "GPIO0_29", "gpio": 29, "mux": "rmii1_refclk", "eeprom": null, "key": "S1_1_6", "muxRegOffset": "0x144", "options": [ "rmii1_refclk", "NA", "spi1_cs0", "NA", "NA", "NA", "NA", "gpio0_28" ], "ball": { "ZCZ": "H18", "BSM": "J14" } }, { "name": "MII_RX3", "gpio": 82, "mux": "gmii1_rxd3", "eeprom": null, "muxRegOffset": "0x134", "options": [ "gmii1_rxd3", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_18" ], "ball": { "ZCZ": "L17", "BSM": "D14" } }, { "name": "MII_RX2", "gpio": 83, "mux": "gmii1_rxd2", "eeprom": null, "muxRegOffset": "0x138", "options": [ "gmii1_rxd2", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_19" ], "ball": { "ZCZ": "L16", "BSM": "D15" } }, { "name": "MII_RX1", "gpio": 84, "mux": "gmii1_rxd1", "eeprom": null, "muxRegOffset": "0x13c", "options": [ "gmii1_rxd1", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_20" ], "ball": { "ZCZ": "L15", "BSM": "D16" } }, { "name": "MII_RX0", "gpio": 85, "mux": "gmii1_rxd0", "eeprom": null, "muxRegOffset": "0x140", "options": [ "gmii1_rxd0", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_21" ], "ball": { "ZCZ": "M16", "BSM": "E14" } }, { "name": "MMC0_DAT3", "gpio": 90, "mux": "mmc0_dat3", "eeprom": null, "muxRegOffset": "0x0f0", "options": [ "mmc0_dat3", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_26" ], "ball": { "ZCZ": "F17", "BSM": "C15" } }, { "name": "MMC0_DAT2", "gpio": 91, "mux": "mmc0_dat2", "eeprom": null, "muxRegOffset": "0x0f4", "options": [ "mmc0_dat2", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_27" ], "ball": { "ZCZ": "F18", "BSM": "C16" } }, { "name": "MMC0_DAT1", "gpio": 92, "mux": "mmc0_dat1", "eeprom": null, "muxRegOffset": "0x0f8", "options": [ "mmc0_dat1", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_28" ], "ball": { "ZCZ": "G15", "BSM": "A15" } }, { "name": "MMC0_DAT0", "gpio": 93, "mux": "mmc0_dat0", "eeprom": null, "muxRegOffset": "0x0fc", "options": [ "mmc0_dat0", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_29" ], "ball": { "ZCZ": "G16", "BSM": "A16" } }, { "name": "MMC0_CLK", "gpio": 94, "mux": "mmc0_clk", "eeprom": null, "muxRegOffset": "0x100", "options": [ "mmc0_clk", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_30" ], "ball": { "ZCZ": "G17", "BSM": "B15" } }, { "name": "MMC0_CMD", "gpio": 95, "mux": "mmc0_cmd", "eeprom": null, "muxRegOffset": "0x104", "options": [ "mmc0_cmd", "NA", "NA", "NA", "NA", "NA", "NA", "gpio2_31" ], "ball": { "ZCZ": "G18", "BSM": "B16" } }, { "name": "MII_COL", "gpio": 96, "mux": "gmii1_col", "eeprom": null, "muxRegOffset": "0x108", "options": [ "gmii1_col", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_0" ], "ball": { "ZCZ": "H16", "BSM": "F15" } }, { "name": "MII_TXEN", "gpio": 99, "mux": "gmii1_txen", "eeprom": null, "muxRegOffset": "0x114", "options": [ "gmii1_txen", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_3" ], "ball": { "ZCZ": "J16", "BSM": "G14" } }, { "name": "MII_RXDV", "gpio": 100, "mux": "gmii1_rxdv", "eeprom": null, "muxRegOffset": "0x118", "options": [ "gmii1_rxdv", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_4" ], "ball": { "ZCZ": "J17", "BSM": "F16" } }, { "name": "I2C0_SDA", "gpio": 101, "mux": "I2C0_SDA", "eeprom": null, "muxRegOffset": "0x188", "options": [ "I2C0_SDA", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_5" ], "ball": { "ZCZ": "C17", "BSM": "C11" } }, { "name": "I2C0_SCL", "gpio": 102, "mux": "I2C0_SCL", "eeprom": null, "muxRegOffset": "0x18c", "options": [ "I2C0_SCL", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_6" ], "ball": { "ZCZ": "C16", "BSM": "C10" } }, { "name": "EMU0", "gpio": 103, "mux": "EMU0", "eeprom": null, "muxRegOffset": "0x1e4", "options": [ "EMU0", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_7" ], "ball": { "ZCZ": "C14", "BSM": "E2" } }, { "name": "EMU1", "gpio": 104, "mux": "EMU1", "eeprom": null, "muxRegOffset": "0x1e8", "options": [ "EMU1", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_8" ], "ball": { "ZCZ": "B14", "BSM": "E3" } }, { "name": "MII_TXCLK", "gpio": 105, "mux": "gmii1_txclk", "eeprom": null, "muxRegOffset": "0x12c", "options": [ "gmii1_txclk", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_9" ], "ball": { "ZCZ": "K18", "BSM": "H16" } }, { "name": "MII_RXCLK", "gpio": 106, "mux": "gmii1_rxclk", "eeprom": null, "muxRegOffset": "0x130", "options": [ "gmii1_rxclk", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_10" ], "ball": { "ZCZ": "L18", "BSM": "E16" } }, { "name": "MII_RXCLK", "gpio": 106, "mux": "gmii1_rxclk", "eeprom": null, "muxRegOffset": "0x130", "options": [ "gmii1_rxclk", "NA", "NA", "NA", "NA", "NA", "NA", "gpio3_10" ], "ball": { "ZCZ": "L18", "BSM": "E16" } } ]; var pins = {}; for (var i in pinIndex) { if (Array.isArray(pinIndex[i].key)) { for (var j = 0; j < pinIndex[i].key.length; j++) { var myKey = pinIndex[i].key[j]; //console.log("key[" + j + "].[" + myKey + "]: " + i); pins[myKey] = i; } } else if (typeof pinIndex[i] != 'undefined') { pins[pinIndex[i].key] = i; } if (typeof pinIndex[i].gpio == 'number') { pins["GPIO_" + pinIndex[i].gpio] = i; } if (typeof pinIndex[i].eeprom == 'number') { pins["EEPROM_" + pinIndex[i].eeprom] = i; } if (typeof pinIndex[i].ain == 'number') { pins["A" + pinIndex[i].ain] = i; } if (typeof pinIndex[i].muxRegOffset == 'string') { var offset = pinIndex[i].muxRegOffset.toUpperCase(); pins["MUX_" + offset] = i; } } var uarts = { "/dev/ttyO0": {}, "/dev/ttyO1": { "devicetree": "BB-UART1", "rx": "P9_26", "tx": "P9_24" }, "/dev/ttyO2": { "devicetree": "BB-UART2", "rx": "P9_22", "tx": "P9_21" }, "/dev/ttyO3": {}, "/dev/ttyO4": { "devicetree": "BB-UART4", "rx": "P9_11", "tx": "P9_13" }, "/dev/ttyO5": { "devicetree": "BB-UART5", "rx": "P8_38", "tx": "P8_37" } }; var i2c = { "/dev/i2c-0": {}, "/dev/i2c-1": { "devicetree": "BB-I2C1", "path": "/dev/i2c-2", "sda": "P9_18", "scl": "P9_17" }, "/dev/i2c-1a": { "devicetree": "BB-I2C1A", "path": "/dev/i2c-2", "sda": "P9_26", "scl": "P9_24" }, "/dev/i2c-2": { "path": "/dev/i2c-1", "sda": "P9_20", "scl": "P9_19" } }; var getPinObject = function (key) { if (typeof key == "string") { // Ignore case key = key.toUpperCase(); // Replace alternate separators and leading zeros key = key.replace(/[\.\-_ ]0*/g, "_"); } if (typeof key == "number") { key = "GPIO_" + key; } //console.log(key); //console.log(pins[key]); if (typeof pinIndex[pins[key]] == "object") { var pinObject = Object.assign({}, pinIndex[pins[key]]); // Only keep the matching index led if (pinObject.led) { //console.log("pinObject[" + key + "]: " + JSON.stringify(pinObject)); if (Array.isArray(pinObject.led)) { //console.log("pinObject.key: " + pinObject.key); var i = pinObject.key.indexOf(key); if (i >= 0) { var led = pinObject.led[i]; pinObject.led = led; //console.log("pinObject.led[" + i + "]: " + led); } else { pinObject.led = null; } } } // Remove other keys pinObject.key = key; } else { return (null); } return (pinObject); }; var getPinKeys = function (filter) { var keys = []; for (var key in pins) { if (typeof filter != 'undefined') { if (key.search(filter) >= 0) { keys.push(key); } } else { keys.push(key); } } return (keys); }; // from https://stackoverflow.com/questions/15478954/sort-array-elements-string-with-numbers-natural-sort var naturalCompare = function (a, b) { var ax = [], bx = []; a.replace(/(\d+)|(\D+)/g, function (_, $1, $2) { ax.push([$1 || Infinity, $2 || ""]) }); b.replace(/(\d+)|(\D+)/g, function (_, $1, $2) { bx.push([$1 || Infinity, $2 || ""]) }); while (ax.length && bx.length) { var an = ax.shift(); var bn = bx.shift(); var nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1]); if (nn) return nn; } return ax.length - bx.length; } module.exports = { getPinObject: getPinObject, getPinKeys: getPinKeys, naturalCompare: naturalCompare, uarts: uarts, i2c: i2c } ================================================ FILE: src/bonescript.js ================================================ var _bonescript = {}; _bonescript.modules = {}; _bonescript._callbacks = {}; _bonescript._seqnum = 0; _bonescript.on = {}; _bonescript.on.connect = function () {}; _bonescript.on.connecting = function () {}; _bonescript.on.disconnect = function () {}; _bonescript.on.connect_failed = function () {}; _bonescript.on.error = function (err) { throw (new Error(err)) }; _bonescript.on.reconnect = function () {}; _bonescript.on.reconnect_failed = function () {}; _bonescript.on.reconnecting = function () {}; _bonescript.on.initialized = function () {}; (function () { if (typeof document == 'undefined') { var io = require('socket.io-client'); var crypto = require('crypto'); module.exports.startClient = function (host, callback) { var passphrase_hash; if (host.password) passphrase_hash = crypto.createHash('sha256').update(host.password).digest("hex"); //generate sha256 hash for supplied password _bonescript.on.initialized = callback; var socket = _onSocketIOLoaded(host.address, host.port, io, passphrase_hash); } return; } require = myrequire; var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = '___INSERT_HOST___/socket.io/socket.io.js'; script.charset = 'UTF-8'; var scriptObj = head.appendChild(script); scriptObj.onload = _onSocketIOLoaded; }()); function _onSocketIOLoaded(host, port, socketio, passphrase_hash) { //console.log("socket.io loaded"); if (typeof host == 'undefined') host = '___INSERT_HOST___'; if (typeof port == 'undefined') port = 80; if (typeof socketio == 'undefined' && typeof io != 'undefined') socketio = io; var socket; if (typeof host == 'string') socket = socketio('http://' + host + ':' + port, { extraHeaders: { 'Authorization': typeof passphrase_hash != 'undefined' ? passphrase_hash : null //send passphrase_has as Authorization extraheader } }); else socket = socketio('___INSERT_HOST___', { port: port }); socket.on('require', getRequireData); socket.on('bonescript', _seqcall); socket.on('connect', _bonescript.on.connect); socket.on('connecting', _bonescript.on.connecting); socket.on('disconnect', _bonescript.on.disconnect); socket.on('connect_failed', _bonescript.on.connect_failed); socket.on('error', _bonescript.on.error); socket.on('reconnect', _bonescript.on.reconnect); socket.on('reconnect_failed', _bonescript.on.reconnect_failed); socket.on('reconnecting', _bonescript.on.reconnecting); socket.on('initialized', _bonescript.on.initialized); function getRequireData(m) { if (!m.module || !m.data) throw ('Invalid "require" message sent for "' + m.module + '"'); //console.log('Initialized module: ' + m.module); _bonescript.modules[m.module] = {}; for (var x in m.data) { if (!m.data[x].type || !m.data[x].name || (typeof m.data[x].value == 'undefined')) throw ('Invalid data in "require" message sent for "' + m.module + '.' + m.data[x] + '"'); if (m.data[x].type == 'function') { // define the function if (!m.data[x].value) throw ('Missing args in "require" message sent for "' + m.module + '.' + m.data[x] + '"'); var myargs = m.data[x].value; // eval of objString builds the call data out of arguments passed in var objString = ''; for (var y in myargs) { if (isNaN(y)) continue; // Need to find the source of this bug if (myargs[y] == 'callback') continue; objString += ' if(typeof ' + myargs[y] + ' == "function") {\n'; objString += ' ' + myargs[y] + ' = ' + myargs[y] + '.toString();\n'; objString += ' }\n'; objString += ' calldata.' + myargs[y] + ' = ' + myargs[y] + ';\n'; } var argsString = myargs.join(', '); var handyfunc = '_bonescript.modules["' + m.module + '"].' + m.data[x].name + ' = ' + 'function (' + argsString + ') {\n' + ' var calldata = {};\n' + objString + ' if(callback) {\n' + ' _bonescript._callbacks[_bonescript._seqnum] = callback;\n' + ' calldata.seq = _bonescript._seqnum;\n' + ' calldata.length = callback.length;\n' + ' _bonescript._seqnum++;\n' + ' }\n' + ' socket.emit("' + m.module + '$' + m.data[x].name + '", calldata);\n' + '};\n'; eval(handyfunc); } else { _bonescript.modules[m.module][m.data[x].name] = m.data[x].value; } } _bonescript.modules[m.module].socket = socket; _bonescript.on.initialized(); } return (socket); } function _seqcall(data) { if ((typeof data.seq != 'number') || (typeof _bonescript._callbacks[data.seq] != 'function')) throw "Invalid callback message received: " + JSON.stringify(data); if (_bonescript._callbacks[data.seq].length == 1) _bonescript._callbacks[data.seq](data); else _bonescript._callbacks[data.seq](data.err, data.resp); if (data.oneshot) delete _bonescript._callbacks[data.seq]; } // Require must be synchronous to be able to return data structures and // functions and therefore cannot call socket.io. All exported modules must // be exported ahead of time. function myrequire(module) { if (typeof _bonescript == 'undefined') throw 'No BoneScript modules are not currently available'; if (typeof _bonescript.modules[module] == 'undefined') throw 'Module "' + module + '" is not currently available'; return (_bonescript.modules[module]); } if (typeof module != 'undefined') { module.exports.require = myrequire; } ================================================ FILE: src/constants.js ================================================ // Copyright (C) 2013 - Texas Instruments, Jason Kridner module.exports = { OUTPUT: "out", INPUT: "in", INPUT_PULLUP: "in_pullup", HIGH: 1, LOW: 0, LSBFIRST: 1, // used in: shiftOut(dataPin, clockPin, bitOrder, val) MSBFIRST: 0, CHANGE: "both", RISING: "rising", FALLING: "falling", ANALOG_OUTPUT: "analog_out" } ================================================ FILE: src/eeprom.js ================================================ // Functions derived from https://github.com/joyent/node/blob/master/lib/buffer.js are: // // Copyright Joyent, Inc. and other Node contributors. All rights reserved. // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. var fs = require('fs'); var buffer = require('buffer'); var util = require('util'); var winston = require('winston'); var bone = require('./bone'); var debug = process.env.DEBUG ? true : false; // Function derived from https://github.com/joyent/node/blob/master/lib/buffer.js if (!buffer.Buffer.prototype.readUint16BE) { buffer.Buffer.prototype.readUint16BE = function (offset) { var val = 0; val = this[offset] << 8; val |= this[offset + 1]; return (val); }; } // Function derived from https://github.com/joyent/node/blob/master/lib/buffer.js if (!buffer.Buffer.prototype.hexSlice) { var toHex = function (n) { if (n < 16) return '0' + n.toString(16); return n.toString(16); }; buffer.Buffer.prototype.hexSlice = function (start, end) { var len = this.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ''; for (var i = start; i < end; i++) { out += toHex(this[i]); } return (out); }; } // Function derived from https://github.com/joyent/node/blob/master/lib/buffer.js if (!buffer.Buffer.prototype.writeUint16BE) { buffer.Buffer.prototype.writeUint16BE = function (value, offset) { this[offset] = (value & 0xff00) >>> 8; this[offset + 1] = value & 0x00ff; }; } // Function derived from https://github.com/joyent/node/blob/master/lib/buffer.js // fill(value, start=0, end=buffer.length) if (!buffer.Buffer.prototype.fill) { buffer.Buffer.prototype.fill = function (value, start, end) { value || (value = 0); start || (start = 0); end || (end = this.length); for (var i = start; i < end; i++) { this[i] = value; } }; } // Function derived from https://github.com/joyent/node/blob/master/lib/buffer.js if (!buffer.Buffer.prototype.hexWrite) { buffer.Buffer.prototype.hexWrite = function (string, offset, length) { offset = +offset || 0; var remaining = this.length - offset; if (!length) { length = remaining; } else { length = +length; if (length > remaining) { length = remaining; } } // must be an even number of digits var strLen = string.length; if (strLen % 2) { throw new Error('Invalid hex string'); } if (length > strLen / 2) { length = strLen / 2; } for (var i = 0; i < length; i++) { var byte = parseInt(string.substr(i * 2, 2), 16); if (isNaN(byte)) throw new Error('Invalid hex string'); this[offset + i] = byte; } return i; }; } var eepromData = new buffer.Buffer(244); var readEeproms = function (files) { var data = {}; for (var file in files) { var raw = fetchEepromData(file); var parsed = null; if (raw) { if (files[file].type == 'bone') { parsed = parseMainEeprom(raw); if (parsed) parsed.type = 'bone'; } else { parsed = parseCapeEeprom(raw); if (parsed) parsed.type = 'cape'; } if (parsed) { data[file] = parsed; } } } return (data); }; var fetchEepromData = function (address) { try { if (debug) winston.debug('Reading EEPROM at ' + address); var eepromFile = fs.openSync( address, 'r' ); fs.readSync(eepromFile, eepromData, 0, 244, 0); return (eepromData); } catch (ex) { if (debug) winston.debug('Unable to open EEPROM at ' + address + ': ' + ex); return (null); } }; var parseMainEeprom = function (x) { var data = {}; data.header = x.hexSlice(0, 4); if (data.header != 'aa5533ee') { winston.error('Unknown EEPROM format: ' + data.header); return (null); } data.boardName = x.toString('ascii', 4, 12).trim().replace(/^\x00+|\x00+$/g, ''); data.version = x.toString('ascii', 12, 16).trim().replace(/^\x00+|\x00+$/g, ''); data.serialNumber = x.toString('ascii', 16, 28).trim().replace(/^\x00+|\x00+$/g, ''); data.configOption = x.hexSlice(28, 60); return (data); }; var parseCapeEeprom = function (x) { var data = {}; data.header = x.hexSlice(0, 4); if (data.header != 'aa5533ee') { winston.error('Unknown EEPROM format: ' + data.header); return (null); } data.formatRev = x.toString('ascii', 4, 6); if (data.formatRev != 'A0') { winston.error('Unknown EEPROM format revision: ' + data.formatRev); return (null); } data.boardName = x.toString('ascii', 6, 38).trim().replace(/^\x00+|\x00+$/g, ''); data.version = x.toString('ascii', 38, 42).trim().replace(/^\x00+|\x00+$/g, ''); data.manufacturer = x.toString('ascii', 42, 58).trim().replace(/^\x00+|\x00+$/g, ''); data.partNumber = x.toString('ascii', 58, 74).trim().replace(/^\x00+|\x00+$/g, ''); data.numPins = x.readUint16BE(74); data.serialNumber = x.toString('ascii', 76, 88).trim().replace(/^\x00+|\x00+$/g, ''); data.currentVDD_3V3EXP = x.readUint16BE(236); data.currentVDD_5V = x.readUint16BE(238); data.currentSYS_5V = x.readUint16BE(240); data.DCSupplied = x.readUint16BE(242); data.mux = {}; var pins = bone.getPinKeys("EEPROM"); for (var i = 0; i < pins.length; i++) { var pin = bone.getPinObject(pins[i]); if (typeof pin.eeprom != 'undefined') { var pinOffset = pin.eeprom * 2 + 88; var pinData = x.readUint16BE(pinOffset); var pinObject = {}; var used = (pinData & 0x8000) >> 15; if (used || debug) { pinObject.used = used ? 'used' : 'available'; if (debug) pinObject.data = x.hexSlice(pinOffset, pinOffset + 2); var direction = (pinData & 0x6000) >> 13; switch (direction) { case 1: pinObject.direction = 'in'; break; case 2: pinObject.direction = 'out'; break; case 3: pinObject.direction = 'bidir'; break; default: winston.error('Unknown direction value: ' + direction); } pinObject.slew = (pinData & 0x40) ? 'slow' : 'fast'; pinObject.rx = (pinData & 0x20) ? 'enabled' : 'disabled'; var pullup = (pinData & 0x18) >> 3; switch (pullup) { case 1: pinObject.pullup = 'disabled'; break; case 2: pinObject.pullup = 'pullup'; break; case 0: pinObject.pullup = 'pulldown'; break; default: winston.error('Unknown pullup value: ' + pullup); } pinObject.mode = (pinData & 0x0007); try { // read mux from debugfs var muxReadout = fs.readFileSync('/sys/kernel/debug/omap_mux/' + bone[pin].mux, 'ascii'); pinObject.function = muxReadout.split("\n")[2].split("|")[pinObject.mode].replace('signals:', '').trim(); } catch (ex) { if (debug) winston.debug('Unable to read pin mux function name: ' + bone[pin].mux); } data.mux[pin] = pinObject; } } } return (data); }; var fillCapeEepromData = function (data) { eepromData.fill(); eepromData.hexWrite('aa5533ee', 0, 4); eepromData.write('A0', 4, 2, 'ascii'); if (data.boardName.length > 32) { data.boardName.length = 32; } eepromData.write(data.boardName, 6, 32, 'ascii'); if (data.version.length > 4) { data.version.length = 4; } eepromData.write(data.version, 38, 4, 'ascii'); if (data.manufacturer.length > 16) { data.manufacturer.length = 16; } eepromData.write(data.manufacturer, 42, 16, 'ascii'); if (data.partNumber.length > 16) { data.partNumber.length = 16; } eepromData.write(data.partNumber, 58, 16, 'ascii'); eepromData.writeUint16BE(data.numPins, 74, 'ascii'); if (data.serialNumber.length > 12) { data.serialNumber.length = 12; } eepromData.write(data.serialNumber, 76, 12, 'ascii'); eepromData.writeUint16BE(data.currentVDD_3V3EXP, 236); eepromData.writeUint16BE(data.currentVDD_5V, 238); eepromData.writeUint16BE(data.currentSYS_5V, 240); eepromData.writeUint16BE(data.DCSupplied, 242); for (var pin in data.mux) { if (typeof bone[pin].eeprom != 'undefined') { var pinOffset = bone[pin].eeprom * 2 + 88; var pinObject = data.mux[pin]; var pinData = 0; if (pinObject.used == 'used') pinData |= 0x8000; switch (pinObject.direction) { case 'in': pinData |= 0x2000; break; case 'out': pinData |= 0x4000; break; case 'bidir': pinData |= 0x6000; break; default: winston.error('Unknown direction value: ' + pinObject.direction); pinData |= 0x2000; } if (pinObject.slew == 'slow') pinData |= 0x40; if (pinObject.rx == 'enabled') pinData |= 0x20; var pullup = (pinData & 0x18) >> 3; switch (pinObject.pullup) { case 'disabled': pinData |= 0x08; break; case 'pullup': pinData |= 0x10; break; case 'pulldown': break; default: winston.error('Unknown pullup value: ' + pullup); } pinData |= (pinObject.mode & 0x0007); eepromData.writeUint16BE(pinData, pinOffset); } } return (eepromData); }; var defaultEepromFiles = { '/sys/bus/i2c/drivers/at24/1-0050/eeprom': { type: 'bone' }, '/sys/bus/i2c/drivers/at24/1-0051/eeprom': { type: 'bone' }, '/sys/bus/i2c/drivers/at24/3-0054/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/3-0055/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/3-0056/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/3-0057/eeprom': { type: 'cape' }, 'test-bone.eeprom': { type: 'bone' }, 'test-cape.eeprom': { type: 'cape' }, }; module.exports = { readEeproms: readEeproms, fillCapeEepromData: fillCapeEepromData } ================================================ FILE: src/ffiimp.js ================================================ var bone = require('./bone'); var fs = require('fs'); var my = require('./my'); var shell = my.require('shelljs'); var winston = my.require('winston'); var ffi = my.require('ffi'); var debug = process.env.DEBUG ? true : false; //function to convert bonescript pin identifier to MRAA's format var mraaGPIO = function (pin) { var pinObject = bone.getPinObject(pin); var pinNo; if (typeof pinObject != 'object') { throw ("Invalid pin: " + pin); } if (pinObject.key.indexOf('P8') != -1) { pinNo = Number(pinObject.key.replace('P8_', '')); } else if (pinObject.key.indexOf('P9') != -1) { pinNo = Number(pinObject.key.replace('P9_', '')); pinNo += 46; } return '0x' + pinNo.toString(16); }; // function to write a .c file at path , similar to writeTextFile var writeCModule = function (filename, data, callback) { if (filename.indexOf(".c") == -1) filename += ".c"; if (typeof callback == 'function') { var cb = function (err) { callback({ 'err': err }); }; fs.writeFile(filename, data, 'utf-8', cb); } else { try { return fs.writeFileSync(filename, data, 'utf-8'); } catch (ex) { winston.error("writeCModule error: " + ex); return (false); } } }; //load C module from shared object at path var loadCModule = function (path, args, mraa) { //compile at the path if shared object does not exist if (path.indexOf('.c') != -1) path = path.replace('.c', ''); mraa = mraa || false; // link mraa var inPath = path + '.c'; var shellCmd = 'gcc -shared -fpic ' + inPath + ' -o ' + path + '.so'; if (mraa) shellCmd += ' -lmraa'; if (debug) winston.debug('loadCModule: shellCmd = ' + shellCmd); // Consider not running if .so newer than .c shell.exec(shellCmd); if (ffi.exists) return ffi.Library(path, args); else { winston.info("loadCModule: Could not load module FFI"); return "ffi not loaded"; } }; module.exports = { mraaGPIO: mraaGPIO, loadCModule: loadCModule, writeCModule: writeCModule } ================================================ FILE: src/functions.js ================================================ // // Copyright (C) 2012 - Cabin Programs, Ken Keller // // Permission is hereby granted, free of charge, to any person obtaining a copy of // this software and associated documentation files (the "Software"), to deal in // the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies // of the Software, and to permit persons to whom the Software is furnished to do // so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // // Bits and Bytes // lowByte(value) // highByte(value) // bitRead(value, bitnum) // bitWrite(value, bitnum, bitdata) // bitSet(value, bitnum) // bitClear(value, bitnum) // bit(bitnum) // // Trigonometry // sin(radians) // cos(radians) // tan(radians) // // Math // min(x,y) // max(x,y) // abs(x) // constrain(x, a, b) // map(value, fromLow, fromHigh, toLow, toHigh) // pow(x, y) // sqrt(x) // // Random Numbers // randomSeed(x) // random(min, max) // random(max) // // Returns the lower 8 bits of value var lowByte = function (value) { return (value & 0x0ff); }; // Returns the value shifted right by 8 bits var highByte = function (value) { return (lowByte(value >> 8)); }; // Returns the value of the bit number specified (return:0 or 1) var bitRead = function (value, bitnum) { return ((value >> bitnum) & 0x01); }; // Returns value with bit changed to specified data var bitWrite = function (value, bitnum, bitdata) { value = value & ~(0x01 << bitnum); bitdata = (bitdata & 0x01) << bitnum; return (value | bitdata); }; // Returns value with specified bit set var bitSet = function (value, bitnum) { return (value | (0x01 << bitnum)); }; // Returns value with specified bit clear var bitClear = function (value, bitnum) { return (value & (~(0x01 << bitnum))); }; //Returns a value with one specified bit number set var bit = function (bitnum) { return (0x01 << bitnum); }; // Returns the sine of an angle (in radians). var sin = function (radians) { return (Math.sin(radians)); }; // Returns the cos of an angle (in radians). var cos = function (radians) { return (Math.cos(radians)); }; // Returns the tan of an angle (in radians). var tan = function (radians) { return (Math.tan(radians)); }; // Returns the the minimum of x or y var min = function (x, y) { return (Math.min(x, y)); }; // Returns the the maximum of x or y var max = function (x, y) { return (Math.max(x, y)); }; // Returns the the absolute value of x var abs = function (x) { return (Math.abs(x)); }; // Returns a value constrained within the range of a to b // Returns: x if x is between a and b // a if x is less than a // b if x is greater than b var constrain = function (x, a, b) { if (x > b) x = b; else if (x < a) x = a; return (x); }; // Returns a value re-mapped from one range to another var map = function (value, fromLow, fromHigh, toLow, toHigh) { return (toLow + (((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow))); }; // Returns x raised to y power var pow = function (x, y) { return (Math.pow(x, y)); }; // Returns the aquare root of x var sqrt = function (x) { return (Math.sqrt(x)); }; // Returns nothing var randomSeedValue; var randomSeed = function (x) { // empty - javascript has no random seed function randomSeedValue = x; }; // Returns a pseudo-random number // Valid calls: random(max) // random(min, max) var random = function (min, max) { if (isNaN(max)) { max = min; min = 0; } return ((Math.random() * (max - min)) + min); }; module.exports = { lowByte: lowByte, highByte: highByte, bitRead: bitRead, bitWrite: bitWrite, bitSet: bitSet, bitClear: bitClear, bit: bit, sin: sin, cos: cos, tan: tan, min: min, max: max, abs: abs, constrain: constrain, map: map, pow: pow, sqrt: sqrt, randomSeed: randomSeed, random: random } ================================================ FILE: src/hw_capemgr.js ================================================ var fs = require('fs'); var winston = require('winston'); var my = require('./my'); var parse = require('./parse'); var debug = process.env.DEBUG ? true : false; var gpioFile = {}; var pwmPrefix = {}; var ainPrefix = ""; var logfile = '/var/lib/cloud9/bonescript.log'; var readPWMFreqAndValue = function (pin, pwm) { var mode = {}; try { var period = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/period'); var duty = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/duty'); mode.freq = 1.0e9 / period; mode.value = duty / period; } catch (ex) {} return (mode); }; var readGPIODirection = function (n, gpio) { var mode = {}; var directionFile = "/sys/class/gpio/gpio" + n + "/direction"; if (my.file_existsSync(directionFile)) { mode.active = true; var direction = fs.readFileSync(directionFile, 'utf-8'); direction = direction.replace(/^\s+|\s+$/g, ''); mode.direction = direction; } return (mode); }; var readPinMux = function (pin, mode, callback) { var pinctrlFile = '/sys/kernel/debug/pinctrl/44e10800.pinmux/pins'; var muxRegOffset = parseInt(pin.muxRegOffset, 16); var readPinctrl = function (err, data) { if (err) { mode.err = 'readPinctrl error: ' + err; if (debug) winston.debug(mode.err); callback(mode); } mode = parse.modeFromPinctrl(data, muxRegOffset, 0x44e10800, mode); callback(mode); }; var tryPinctrl = function (exists) { if (exists) { fs.readFile(pinctrlFile, 'utf8', readPinctrl); } else { if (debug) winston.debug('getPinMode(' + pin.key + '): no valid mux data'); callback(mode); } }; if (callback) { my.file_exists(pinctrlFile, tryPinctrl); } else { try { var data2 = fs.readFileSync(pinctrlFile, 'utf8'); mode = parse.modeFromPinctrl(data2, muxRegOffset, 0x44e10800, mode); } catch (ex) { if (debug) winston.debug('getPinMode(' + pin.key + '): ' + ex); } } return (mode); }; var setPinMode = function (pin, pinData, template, resp, callback) { if (debug) winston.debug('hw.setPinMode(' + [pin.key, pinData, template, JSON.stringify(resp)] + ');'); if (debug) winston.debug('typeof callack = ' + typeof callback); if (template == 'bspm') { gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (callback) { doCreateDT(resp); return (resp); } if (pin.led) { gpioFile[pin.key] = '/sys/class/leds/beaglebone::' + pin.led + '/brightness'; } } else if (template == 'bspwm') { if (callback) { my.load_dt('am33xx_pwm', null, resp, doCreateDT); return (resp); } if (!my.load_dt('am33xx_pwm')) { resp.err = 'Error loading am33xx_pwm devicetree overlay'; return (resp); } } else { resp.err = 'Unknown pin mode template'; if (callback) { callback(resp); return (resp); } } // only synchronous stuff at this point if (!my.create_dt(pin, pinData, template)) { resp.err = 'Error loading devicetree overlay for ' + pin.key + ' using template ' + template; return (resp); } if (template == 'bspwm') { try { var ocp = my.is_ocp(); var p = 'bs_pwm_test_' + pin.key; var pwm_test = my.find_sysfsFile(p, ocp, p + '.'); pwmPrefix[pin.pwm.name] = pwm_test; fs.writeFileSync(pwm_test + '/polarity', 0); } catch (ex) { resp.err = 'Error enabling PWM controls: ' + ex; winston.error(resp.err); } } // now to define the asynchronous calls function doCreateDT(resp) { if (resp.err) { callback(resp); return; } my.create_dt(pin, pinData, template, true, false, resp, onCreateDT); } function onCreateDT(resp) { if (resp.err) { callback(resp); return; } if (template == 'bspwm') { my.file_find('/sys/devices', 'ocp.', 1, onFindOCP); } else { callback(resp); } function onFindOCP(ocp) { if (ocp.err) { resp.err = "Error searching for ocp: " + ocp.err; if (debug) winston.debug(resp.err); callback(resp); return; } my.file_find(ocp.path, 'bs_pwm_test_' + pin.key + '.', 1, onFindPWM); } function onFindPWM(pwm_test) { if (pwm_test.err) { resp.err = "Error searching for pwm_test: " + pwm_test.err; if (debug) winston.debug(resp.err); callback(resp); return; } my.file_find(pwm_test.path, 'period', 1, onFindPeriod); function onFindPeriod(period) { if (period.err) { resp.err = "Error searching for period: " + period.err; if (debug) winston.debug(resp.err); callback(resp); return; } pwmPrefix[pin.pwm.name] = pwm_test.path; fs.writeFile(pwm_test.path + '/polarity', 0, 'ascii', onPolarityWrite); } } function onPolarityWrite(err) { if (err) { resp.err = "Error writing PWM polarity: " + err; if (debug) winston.debug(resp.err); } callback(resp); } } return (resp); }; var setLEDPinToGPIO = function (pin, resp) { var path = "/sys/class/leds/beaglebone:green:" + pin.led + "/trigger"; if (my.file_existsSync(path)) { fs.writeFileSync(path, "gpio"); } else { resp.err = "Unable to find LED " + pin.led; winston.error(resp.err); resp.value = false; } return (resp); }; var exportGPIOControls = function (pin, direction, resp, callback) { if (debug) winston.debug('hw.exportGPIOControls(' + [pin.key, direction, resp] + ');'); var n = pin.gpio; if (callback) { my.file_exists(gpioFile[pin.key], onFileExists); return; } var exists = my.file_existsSync(gpioFile[pin.key]); if (exists) { if (debug) winston.debug("gpio: " + n + " already exported."); fs.writeFileSync("/sys/class/gpio/gpio" + n + "/direction", direction, null); } else { try { if (debug) winston.debug("exporting gpio: " + n); fs.writeFileSync("/sys/class/gpio/export", "" + n, null); if (debug) winston.debug("setting gpio " + n + " direction to " + direction); fs.writeFileSync("/sys/class/gpio/gpio" + n + "/direction", direction, null); } catch (ex2) { resp.value = false; resp.err = 'Unable to export gpio-' + n + ': ' + ex2; if (debug) winston.debug(resp.err); var gpioUsers = fs.readFileSync('/sys/kernel/debug/gpio', 'utf-8'); gpioUsers = gpioUsers.split('\n'); } } function onFileExists(exists) { if (exists) { if (debug) winston.debug("gpio: " + n + " already exported."); fs.writeFile("/sys/class/gpio/gpio" + n + "/direction", direction, null, onGPIODirectionSet); } else { if (debug) winston.debug("exporting gpio: " + n); fs.writeFile("/sys/class/gpio/export", "" + n, null, onGPIOExport); } } function onGPIOExport(err) { if (err) onError(err); if (debug) winston.debug("setting gpio " + n + " direction to " + direction); fs.writeFile("/sys/class/gpio/gpio" + n + "/direction", direction, null, onGPIODirectionSet); } function onGPIODirectionSet(err) { if (err) onError(err); else callback(resp); } function onError(err) { resp.err = 'Unable to export gpio-' + n + ': ' + err; resp.value = false; if (debug) winston.debug(resp.err); findOwner(); } function findOwner() { fs.readFile('/sys/kernel/debug/gpio', 'utf-8', onGPIOUsers); } function onGPIOUsers(err, data) { if (!err) { var gpioUsers = data.split('\n'); for (var x in gpioUsers) { var y = gpioUsers[x].match(/gpio-(\d+)\s+\((\S+)\s*\)/); if (y && y[1] == n) { resp.err += '\nconsumed by ' + y[2]; if (debug) winston.debug(resp.err); } } } callback(resp); } return (resp); }; var writeGPIOValue = function (pin, value, callback) { if (typeof gpioFile[pin.key] == 'undefined') { gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (pin.led) { gpioFile[pin.key] = "/sys/class/leds/beaglebone:"; gpioFile[pin.key] += "green:" + pin.led + "/brightness"; } if (!my.file_existsSync(gpioFile[pin.key])) { winston.error("Unable to find gpio: " + gpioFile[pin.key]); } } if (debug) winston.debug("gpioFile = " + gpioFile[pin.key]); if (callback) { fs.writeFile(gpioFile[pin.key], '' + value, null, callback); } else { try { fs.writeFileSync(gpioFile[pin.key], '' + value, null); } catch (ex) { winston.error("Unable to write to " + gpioFile[pin.key]); } } }; var readGPIOValue = function (pin, resp, callback) { var gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (callback) { var readFile = function (err, data) { if (err) { resp.err = 'digitalRead error: ' + err; winston.error(resp.err); } resp.value = parseInt(data, 2); callback(resp); }; fs.readFile(gpioFile, readFile); return (true); } resp.value = parseInt(fs.readFileSync(gpioFile), 2); return (resp); }; var enableAIN = function (callback) { var helper = ""; if (my.load_dt('cape-bone-iio')) { var ocp = my.is_ocp(); if (ocp) { helper = my.find_sysfsFile('helper', ocp, 'helper.'); if (helper) { ainPrefix = helper + '/AIN'; } } } if (callback) { callback({ 'path': helper }) } return (helper.length > 1); }; var readAIN = function (pin, resp, callback) { var ainFile = ainPrefix + pin.ain.toString(); if (callback) { var readFile = function (err, data) { if (err) { resp.err = 'analogRead error: ' + err; winston.error(resp.err); } resp.value = parseInt(data, 10) / 1800; callback(resp); }; fs.readFile(ainFile, readFile); return (resp); } resp.value = parseInt(fs.readFileSync(ainFile), 10); if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') returned ' + resp.value; winston.error(resp.err); } resp.value = resp.value / 1800; if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') scaled to ' + resp.value; winston.error(resp.err); } return (resp); }; var writeGPIOEdge = function (pin, mode) { fs.writeFileSync('/sys/class/gpio/gpio' + pin.gpio + '/edge', mode); var resp = {}; resp.gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; resp.valuefd = fs.openSync(resp.gpioFile, 'r'); resp.value = new Buffer(1); return (resp); }; var writePWMFreqAndValue = function (pin, pwm, freq, value, resp, callback) { if (debug) winston.debug('hw.writePWMFreqAndValue(' + [pin.key, pwm, freq, value, resp] + ');'); var path = pwmPrefix[pin.pwm.name]; try { var period = Math.round(1.0e9 / freq); // period in ns var duty = Math.round(period * value); fs.writeFileSync(path + '/duty', 0); if (pwm.freq != freq) { if (debug) winston.debug('Updating PWM period: ' + period); fs.writeFileSync(path + '/period', period); } if (debug) winston.debug('Updating PWM duty: ' + duty); fs.writeFileSync(path + '/duty', duty); } catch (ex) { resp.err = 'error updating PWM freq and value: ' + path + ', ' + ex; winston.error(resp.err); } return (resp); }; var readEeproms = function (eeproms) { var boardName = fs.readFileSync(my.is_capemgr() + '/baseboard/board-name', 'ascii'); var version = fs.readFileSync(my.is_capemgr() + '/baseboard/revision', 'ascii'); var serialNumber = fs.readFileSync(my.is_capemgr() + '/baseboard/serial-number', 'ascii'); eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'] = {}; eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'].boardName = boardName; eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'].version = version; eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'].serialNumber = serialNumber; return (eeproms); }; var readPlatform = function (platform) { platform.name = fs.readFileSync(my.is_capemgr() + '/baseboard/board-name', 'ascii').trim(); if (platform.name == 'A335BONE') platform.name = 'BeagleBone'; if (platform.name == 'A335BNLT') platform.name = 'BeagleBone Black'; if (platform.name == 'A335PBGL') platform.name = 'PocketBeagle'; platform.version = fs.readFileSync(my.is_capemgr() + '/baseboard/revision', 'ascii').trim(); if (platform.version[0] == 0x1A) { platform.version = '1A'; platform.name = 'BeagleBone Green'; } else if (platform.version.match(/^GR/)) { platform.version = platform.version.substr(2); platform.name = 'BeagleBone Green'; } else if (platform.version.match(/^BL/)) { platform.version = platform.version.substr(2); platform.name = 'BeagleBone Blue'; } else if (!platform.version.match(/^[\040-\176]*$/)) delete platform.version; platform.serialNumber = fs.readFileSync(my.is_capemgr() + '/baseboard/serial-number', 'ascii').trim(); if (!platform.serialNumber.match(/^[\040-\176]*$/)) delete platform.serialNumber; return (platform); }; module.exports = { logfile: logfile, readPWMFreqAndValue: readPWMFreqAndValue, readGPIODirection: readGPIODirection, readPinMux: readPinMux, setPinMode: setPinMode, setLEDPinToGPIO: setLEDPinToGPIO, exportGPIOControls: exportGPIOControls, writeGPIOValue: writeGPIOValue, readGPIOValue: readGPIOValue, enableAIN: enableAIN, readAIN: readAIN, writeGPIOEdge: writeGPIOEdge, writePWMFreqAndValue: writePWMFreqAndValue, readEeproms: readEeproms, readPlatform: readPlatform, } ================================================ FILE: src/hw_mainline.js ================================================ var fs = require('fs'); var async = require('async'); var my = require('./my'); var parse = require('./parse'); var eeprom = require('./eeprom'); var util = require('util'); var winston = require('winston'); var shell = require('shelljs'); var debug = process.env.DEBUG ? true : false; if (debug) { winston.remove(winston.transports.Console); winston.add(winston.transports.Console, { colorize: true }); } var cbWarn = false; var gpioFile = {}; var pwmPrefix = {}; var ainPrefix = "/sys/bus/iio/devices/iio:device0"; var SLOTS = "/sys/devices/platform/bone_capemgr/slots"; var AINdts = "BB-ADC"; var isAI = false; var AI_vdd_adc_mV = 1800; var logfile = '/var/lib/cloud9/bonescript.log'; // TODO: This runs when 'require' is executed // and more thought should go into what happens // when it is run via RPC if (fs.existsSync("/proc/device-tree/model")) { var model = fs.readFileSync('/proc/device-tree/model', 'ascii').trim().replace(/\0/g, ''); if (model == "BeagleBoard.org BeagleBone AI") { isAI = true; } } var readPWMFreqAndValue = function (pin, pwm) { var mode = {}; try { var period = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/period_ns'); var duty = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/duty_ns'); mode.freq = 1.0e9 / period; mode.value = duty / period; } catch (ex) {} return (mode); }; var readGPIODirection = function (n, gpio) { var mode = {}; var directionFile = "/sys/class/gpio/gpio" + n + "/direction"; if (my.file_existsSync(directionFile)) { mode.active = true; var direction = fs.readFileSync(directionFile, 'utf-8'); direction = direction.replace(/^\s+|\s+$/g, ''); mode.direction = direction; } return (mode); }; var readPinMux = function (pin, mode, callback) { var pinctrlFile = isAI ? '/sys/kernel/debug/pinctrl/4a003400.pinmux/pins' : '/sys/kernel/debug/pinctrl/44e10800.pinmux/pins'; // This does not handle the case where 2 balls are tied // to the same header pin. Just grabbing first one for now. var muxRegOffset = null; try { muxRegOffset = isAI ? parseInt(pin.muxRegOffset[0], 16) : parseInt(pin.muxRegOffset, 16); } catch (ex) {} //handle the case when debugfs not mounted if (!my.file_existsSync(pinctrlFile)) { //exit code is 1 if /sys/kernel/debug not mounted const umount = shell.exec('mountpoint -q /sys/kernel/debug/').code; if (umount) shell.exec('mount -t debugfs none /sys/kernel/debug/', { silent: true }); } var readPinctrl = function (err, data) { if (err) { mode.err = 'readPinctrl error: ' + err; if (debug) winston.debug(mode.err); if (callback.length == 1) { winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(mode); } else callback(mode.err, data); } mode = parse.modeFromPinctrl(data, muxRegOffset, isAI ? 0x4a002000 : 0x44e10800, mode, isAI); if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(mode); } else callback(null, mode); }; var tryPinctrl = function (exists) { if (exists) { fs.readFile(pinctrlFile, 'utf8', readPinctrl); } else { if (debug) winston.debug('getPinMode(' + pin.key + '): no valid mux data'); if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(mode); } else callback('readPinMux error: no valid mux data', mode); } }; if (callback) { my.file_exists(pinctrlFile, tryPinctrl); } else { try { var data2 = fs.readFileSync(pinctrlFile, 'utf8'); mode = parse.modeFromPinctrl(data2, muxRegOffset, isAI ? 0x4a002000 : 0x44e10800, mode, isAI); } catch (ex) { if (debug) winston.debug('getPinMode(' + pin.key + '): ' + ex); } } return (mode); }; var setPinMode = function (pin, pinData, template, resp, callback) { if (debug) winston.debug('hw.setPinMode(' + [pin.key, pinData, template, JSON.stringify(resp)] + ');'); var p = "ocp:" + pin.key + "_pinmux"; gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (isAI) { if (callback) callback(resp); return (resp); } if (!pin.universalName) { pin.universalName = [p]; if (pin.ball && pin.ball.ZCZ) pin.universalName.push("ocp:" + pin.ball.ZCZ + "_pinmux"); } var pinmux = my.find_sysfsFile(p, my.is_ocp(), pin.universalName); if (pinmux) { var state = undefined; if ((pinData & 7) == 7) { state = 'gpio'; switch (pinData & 0x18) { case 0x00: state = 'gpio_pd'; break; case 0x10: state = 'gpio_pu'; break; default: break; } } else if (template == 'bspwm' || template == 'pwm') { state = "pwm"; if (pin.pwm.universalMode) state = pin.pwm.universalMode; } else { resp.err = 'Unknown pin mode template'; winston.error(resp.err); } if (!resp.err) { fs.writeFileSync(pinmux + "/state", state); } } else { resp.err = 'No pinmux for ' + pin.key; if (debug) winston.debug(resp.err); } if (template == 'bspwm') { // Buld a path like: /sys/devices/platform/ocp/48304000.epwmss/48304200.ehrpwm/pwm/pwmchip5/pwm5-:0 // pin.pwm.chip looks up the first address and pin.pwm.addr looks up the second // file_find figures which pwmchip to use // pin.pwm.index tells with half of the PWM to use (0 or 1) var chipPath = my.file_find('/sys/devices/platform/ocp', pin.pwm.chip, 1); if (debug) winston.debug("chipPath = " + chipPath); var addrPath = my.file_find(chipPath, pin.pwm.addr, 1); if (debug) winston.debug("addrPath = " + addrPath); var pwmchipPath = my.file_find(addrPath + '/pwm', 'pwmchip', 1); if (debug) winston.debug("pwmchipPath = " + pwmchipPath); var pwmPath = my.file_find(pwmchipPath, "pwm.*" + pin.pwm.index + "$", 1); if (debug) winston.debug("pwmPath = " + pwmPath); if (pwmchipPath && !pwmPath) { fs.appendFileSync(pwmchipPath + '/export', pin.pwm.index); pwmPath = my.file_find(pwmchipPath, "pwm.*" + pin.pwm.index + "$", 1); if (debug) winston.debug("pwmPath = " + pwmPath); } if (pwmPath) { pwmPrefix[pin.pwm.name] = pwmPath; } //fs.appendFileSync(pwmPrefix[pin.pwm.name]+'/enable', 1); } if (callback) callback(resp); return (resp); }; var setLEDPinToGPIO = function (pin, resp) { if (debug) winston.debug('setLEDPinTGPIO: ' + pin.key); var path; if (Array.isArray(pin.led)) { resp.err = "Unable to handle LED definition as array " + pin.led; winston.error(resp.err); resp.value = false; return (resp); } path = "/sys/class/leds/" + pin.led + "/trigger"; if (my.file_existsSync(path)) { fs.writeFileSync(path, "gpio"); } else { resp.err = "Unable to find LED " + pin.led; winston.error(resp.err); resp.value = false; } return (resp); }; var exportGPIOControls = function (pin, direction, resp, callback) { if (debug) winston.debug('hw.exportGPIOControls(' + [pin.key, direction, resp] + ');'); var n = pin.gpio; var exists = my.file_existsSync(gpioFile[pin.key]); if (!exists) { if (debug) winston.debug("exporting gpio: " + n); fs.writeFileSync("/sys/class/gpio/export", "" + n, null); } var directionFile = "/sys/class/gpio/gpio" + n + "/direction"; if (debug) winston.debug('Writing GPIO direction(' + direction + ') to ' + directionFile + ');'); fs.writeFileSync(directionFile, direction); return (resp); }; var writeGPIOValue = function (pin, value, callback) { if (typeof gpioFile[pin.key] == 'undefined') { gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (pin.led) { gpioFile[pin.key] = "/sys/class/leds/" + pin.led + "/brightness"; } if (!my.file_existsSync(gpioFile[pin.key])) { winston.error("Unable to find gpio: " + gpioFile[pin.key]); } } if (debug) winston.debug("gpioFile = " + gpioFile[pin.key]); if (callback) { fs.writeFile(gpioFile[pin.key], '' + value, null, callback); } else { try { fs.writeFileSync(gpioFile[pin.key], '' + value, null); } catch (ex) { winston.error("Unable to write to " + gpioFile[pin.key]); } } }; var readGPIOValue = function (pin, resp, callback) { var gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (callback) { var readFile = function (err, data) { if (err) { resp.err = 'digitalRead error: ' + err; winston.error(resp.err); } resp.value = parseInt(data, 2); if (callback.length == 1) { winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); } else callback(resp.err, resp.value); }; fs.readFile(gpioFile, readFile); return (true); } resp.value = parseInt(fs.readFileSync(gpioFile), 2); return (resp); }; var enableAIN = function (callback) { if (!my.file_existsSync(ainPrefix)) { if (debug) winston.debug('enableAIN: loading ' + AINdts); fs.writeFileSync(SLOTS, AINdts); // Loads AINdts } if (!my.file_existsSync(ainPrefix)) { if (debug) winston.debug('enableAIN: load of ' + AINdts + ' failed'); } if (callback) { callback({ 'path': ainPrefix }); } return (ainPrefix); }; var readAIN = function (pin, resp, callback) { var maxValue = (isAI && (AI_vdd_adc_mV == 1800)) ? 2234 : 4095; var ainFile = ainPrefix + '/in_voltage' + pin.ain.toString() + '_raw'; if (debug) winston.debug("readAIN: ainFile=" + ainFile); if (callback) { var readFile = function (err, data) { if (err) { resp.err = 'analogRead error: ' + err; winston.error(resp.err); } resp.value = parseInt(data, 10) / maxValue; if (callback.length == 1) { winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); } else callback(resp.err, resp.value); }; fs.readFile(ainFile, readFile); return (resp); } resp.value = parseInt(fs.readFileSync(ainFile), 10); if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') returned ' + resp.value; winston.error(resp.err); } resp.value = resp.value / maxValue; if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') scaled to ' + resp.value; winston.error(resp.err); } return (resp); }; var writeGPIOEdge = function (pin, mode) { fs.writeFileSync('/sys/class/gpio/gpio' + pin.gpio + '/edge', mode); var resp = {}; resp.gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; resp.valuefd = fs.openSync(resp.gpioFile, 'r'); resp.value = new Buffer(1); return (resp); }; var writePWMFreqAndValue = function (pin, pwm, freq, value, resp, callback) { if (debug) winston.debug('hw.writePWMFreqAndValue(' + [pin.key, util.inspect(pwm), freq, value, resp] + ');'); var path = pwmPrefix[pin.pwm.name]; try { var period = Math.round(1.0e9 / freq); // period in ns var duty = Math.round(period * value); var currentPeriod = fs.readFileSync(path + '/period'); //read Current Period for smooth PWM var currentDuty = fs.readFileSync(path + '/duty_cycle'); //read Current Duty for smooth PWM var pwmEnabled = Number(fs.readFileSync(path + '/enable')); //check whether PWM is enabled var disablePWM = !(duty * freq); //when duty||frequency ==0 , disablePWM to avoid spikes if (debug) winston.debug('hw.writePWMFreqAndValue: pwm.freq=' + pwm.freq + ', freq=' + freq + ', period=' + period); //smooth PWM Implementation if (!disablePWM && pwmEnabled) { if (period > currentDuty) { if (debug) winston.debug('Updating PWM period: ' + period); fs.writeFileSync(path + '/period', period); if (debug) winston.debug('Updating PWM duty: ' + duty); fs.writeFileSync(path + '/duty_cycle', duty); } else if (duty < currentPeriod) { if (debug) winston.debug('Updating PWM duty: ' + duty); fs.writeFileSync(path + '/duty_cycle', duty); if (debug) winston.debug('Updating PWM period: ' + period); fs.writeFileSync(path + '/period', period); } } else { var tryAgain = true; var tries = 0; async.until(function () { //try accessing 'path/enable' until no EACCES error is thrown (max 10 times) return !tryAgain; //to account for udev delay }, stopPWM, updatePeriodAndDuty); //async.until(test,iteratee,callback) function stopPWM(callback) { try { if (debug) winston.debug('Stopping PWM'); fs.writeFileSync(path + '/enable', "0\n"); tryAgain = false; //do not try again callback(null); //if no error } catch (ex2) { if (debug) winston.debug('Error stopping PWM: ' + ex2); if (ex2.code == 'EACCES') { tries++; if (tries < 10) tryAgain = true; //if EACCES error thrown try again for a maximum of 10 times else tryAgain = false; callback(null); //async.until requires an err first format callback & } else { //if there is an error iteration stops, so neglect the error if EACCES thrown tryAgain = false; callback(ex2); } } } function updatePeriodAndDuty() { // It appears that the first time you set the pwm you have to // set the period before you set the duty_cycle if (!disablePWM) { //if duty||frequency == 0 do not re-enable PWM (to avoid spikes) try { if (debug) winston.debug('Updating PWM period: ' + period); fs.writeFileSync(path + '/period', period + "\n"); } catch (ex2) { winston.info('Unable to update PWM period, period is set to ' + currentPeriod + "\tIs other half of PWM enabled?"); } try { if (debug) winston.debug('Starting PWM'); fs.writeFileSync(path + '/enable', "1\n"); } catch (ex2) { if (debug) winston.debug('Error starting PWM: ' + ex2); } } if (debug) winston.debug('Updating PWM duty: ' + duty); //if(duty == 0) winston.error('Updating PWM duty: ' + duty); if (!disablePWM) fs.writeFileSync(path + '/duty_cycle', duty + "\n"); } } } catch (ex) { resp.err = 'error updating PWM freq and value: ' + path + ', ' + ex; winston.error(resp.err); } return (resp); }; var readEeproms = function (eeproms) { var EepromFiles = { '/sys/bus/i2c/devices/0-0050/0-00500/nvmem': { type: 'bone' }, '/sys/bus/i2c/devices/2-0054/2-00540/nvmem': { type: 'cape' }, '/sys/bus/i2c/devices/2-0055/2-00550/nvmem': { type: 'cape' }, '/sys/bus/i2c/devices/2-0056/2-00560/nvmem': { type: 'cape' }, '/sys/bus/i2c/devices/2-0057/2-00570/nvmem': { type: 'cape' } }; eeproms = eeprom.readEeproms(EepromFiles); return (eeproms); }; var readPlatform = function (platform) { var eeproms = eeprom.readEeproms({ '/sys/bus/i2c/devices/0-0050/0-00500/nvmem': { type: 'bone' } }); var x = eeproms['/sys/bus/i2c/devices/0-0050/0-00500/nvmem']; platform.name = fs.readFileSync('/proc/device-tree/model', 'ascii').trim().replace(/\0/g, ''); if (platform.name.indexOf('Green') > 0) { platform.name = platform.name.replace('TI AM335x', 'SeeedStudio') } if (platform.name.indexOf('Arduino') > 0) { platform.name = platform.name.replace('TI AM335x', '') } platform.name = platform.name.replace('TI AM335x BeagleBone', 'BeagleBoard.org BeagleBone'); platform.name = platform.name.replace('TI AM5728 BeagleBoard-X15', 'BeagleBoard.org BeagleBoard-X15'); if (x && x.version) { platform.version = x.version; if (!platform.version.match(/^[\040-\176]*$/)) delete platform.version; } if (x && x.serialNumber) { platform.serialNumber = x.serialNumber; if (!platform.serialNumber.match(/^[\040-\176]*$/)) delete platform.serialNumber; } try { platform.dogtag = fs.readFileSync('/etc/dogtag', 'ascii'); } catch (ex) {} return (platform); }; var getPin = function (pin) { pin = my.getpin(pin); if (isAI && typeof pin.ai == "object") { Object.assign(pin, pin.ai); delete pin.ai; } if (debug) winston.debug('hw.getPin(): pin=' + JSON.stringify(pin) + ' iAI=' + isAI); return (pin); }; module.exports = { logfile: logfile, readPWMFreqAndValue: readPWMFreqAndValue, readGPIODirection: readGPIODirection, readPinMux: readPinMux, setPinMode: setPinMode, setLEDPinToGPIO: setLEDPinToGPIO, exportGPIOControls: exportGPIOControls, writeGPIOValue: writeGPIOValue, readGPIOValue: readGPIOValue, enableAIN: enableAIN, readAIN: readAIN, writeGPIOEdge: writeGPIOEdge, writePWMFreqAndValue: writePWMFreqAndValue, readEeproms: readEeproms, readPlatform: readPlatform, getPin: getPin } ================================================ FILE: src/hw_oldkernel.js ================================================ // Used for 3.2 kernel using /sys/kernel/debug/omap_mux/ var fs = require('fs'); var my = require('./my'); var parse = require('./parse'); var eeprom = require('./eeprom'); var hw_capemgr = require('./hw_capemgr'); var winston = require('winston'); var debug = true; var gpioFile = {}; var pwmPrefix = {}; var logfile = '/var/lib/cloud9/bonescript.log'; var readPWMFreqAndValue = function (pin, pwm) { var mode = {}; try { var duty_percent = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/duty_percent'); mode.freq = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/period_freq'); mode.value = duty_percent / 100.0; } catch (ex) { mode.err = 'cannot set PWM frequency and value: ' + ex; } return (mode); }; var readGPIODirection = hw_capemgr.readGPIODirection; var readPinMux = function (pin, mode, callback) { var muxFile = '/sys/kernel/debug/omap_mux/' + pin.mux; var readOmapMux = function (err, data) { if (err) { mode.err = 'readOmapMux error: ' + err; if (debug) winston.debug(mode.err); callback(mode); } mode = parse.modeFromOmapMux(data, mode); callback(mode); }; var tryOmapMux = function (exists) { if (exists) { fs.readFile(muxFile, 'utf8', readOmapMux); } }; if (callback) { my.file_exists(muxFile, tryOmapMux); } else { try { var data = fs.readFileSync(muxFile, 'utf8'); mode = parse.modeFromOmapMux(data, mode); } catch (ex) { if (debug) winston.debug('getPinMode(' + pin.key + '): ' + ex); } } return (mode); }; var setPinMode = function (pin, pinData, template, resp) { var muxFile = '/sys/kernel/debug/omap_mux/' + pin.mux; var n = pin.gpio; try { var fd = fs.openSync(muxFile, 'w'); fs.writeSync(fd, pinData.toString(16), null); } catch (ex) { resp.err = 'Error writing to ' + muxFile + ': ' + ex; return (resp); } if (template == 'bspm') { gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (pin.led) { gpioFile[pin.key] = '/sys/class/leds/beaglebone::' + pin.led + '/brightness'; } } else if (template == 'bspwm') { resp.path = '/sys/class/pwm/' + pin.pwm.path; var path = resp.path; pwmPrefix[pin.pwm.name] = path; // Clear up any unmanaged usage fs.writeFileSync(path + '/request', '0'); // Allocate and configure the PWM fs.writeFileSync(path + '/request', '1'); fs.writeFileSync(path + '/period_freq', '0'); fs.writeFileSync(path + '/polarity', '0'); fs.writeFileSync(path + '/run', '1'); } return (resp); }; var setLEDPinToGPIO = function (pin, resp) { var path = "/sys/class/leds/beaglebone::" + pin.led + "/trigger"; if (my.file_existsSync(path)) { fs.writeFileSync(path, "gpio"); } else { resp.err = "Unable to find LED: " + pin.led; winston.error(resp.err); resp.value = false; } return (resp); }; var exportGPIOControls = hw_capemgr.exportGPIOControls; var writeGPIOValue = function (pin, value, callback) { if (typeof gpioFile[pin.key] == 'undefined') { gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (pin.led) { gpioFile[pin.key] = "/sys/class/leds/beaglebone:"; gpioFile[pin.key] += ":" + pin.led + "/brightness"; } if (!my.file_existsSync(gpioFile[pin.key])) { winston.error("Unable to find gpio: " + gpioFile[pin.key]); } } if (debug) winston.debug("gpioFile = " + gpioFile[pin.key]); if (callback) { fs.writeFile(gpioFile[pin.key], '' + value, null, callback); } else { try { fs.writeFileSync(gpioFile[pin.key], '' + value, null); } catch (ex) { winston.error("Unable to write to " + gpioFile[pin.key]); } } }; var readGPIOValue = hw_capemgr.readGPIOValue; var enableAIN = function () { return (true); }; var readAIN = function (pin, resp, callback) { var ainFile = '/sys/bus/platform/devices/tsc/ain' + (pin.ain + 1).toString(); if (callback) { var readFile = function (err, data) { if (err) { resp.err = 'analogRead error: ' + err; winston.error(resp.err); } resp.value = parseInt(data, 10) / 4096; callback(resp); }; fs.readFile(ainFile, readFile); return (resp); } resp.value = parseInt(fs.readFileSync(ainFile), 10); if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') returned ' + resp.value; winston.error(resp.err); } resp.value = resp.value / 4096; if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') scaled to ' + resp.value; } return (resp); }; var writeGPIOEdge = hw_capemgr.writeGPIOEdge; var writePWMFreqAndValue = function (pin, pwm, freq, value, resp) { var path = pwmPrefix[pin.pwm.name]; if (pwm.freq != freq) { fs.writeFileSync(path + '/run', '0'); fs.writeFileSync(path + '/duty_percent', '0'); fs.writeFileSync(path + '/period_freq', Math.round(freq)); fs.writeFileSync(path + '/run', '1'); } fs.writeFileSync(path + '/duty_percent', Math.round(value * 100)); return (resp); }; var readEeproms = function (eeproms) { var EepromFiles = { '/sys/bus/i2c/drivers/at24/1-0050/eeprom': { type: 'bone' }, '/sys/bus/i2c/drivers/at24/3-0054/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/3-0055/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/3-0056/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/3-0057/eeprom': { type: 'cape' } }; eeproms = eeprom.readEeproms(EepromFiles); return (eeproms); }; var readPlatform = function (platform) { return (platform); }; module.exports = { logfile: logfile, readPWMFreqAndValue: readPWMFreqAndValue, readGPIODirection: readGPIODirection, readPinMux: readPinMux, setPinMode: setPinMode, setLEDPinToGPIO: setLEDPinToGPIO, exportGPIOControls: exportGPIOControls, writeGPIOValue: writeGPIOValue, readGPIOValue: readGPIOValue, enableAIN: enableAIN, readAIN: readAIN, writeGPIOEdge: writeGPIOEdge, writePWMFreqAndValue: writePWMFreqAndValue, readEeproms: readEeproms, readPlatform: readPlatform } ================================================ FILE: src/hw_simulator.js ================================================ var fs = require('fs'); var winston = require('winston'); var my = require('./my'); var gpioFile = {}; var logfile = 'bonescript.log'; var readPWMFreqAndValue = function (pin, pwm) { winston.info('readPWMFreqAndValue(' + [pin.key, pwm.key] + ')'); var mode = {}; mode.freq = pwm.freq; mode.value = pwm.value; return (mode); }; var readGPIODirection = function (n, gpio) { winston.info('readGPIODirection(' + [n] + ')'); var mode = {}; if (typeof gpio[n] != 'undefined') { if (gpio[n].active) { mode.active = true; } else { mode.active = false; } mode.direction = gpio[n].direction; } return (mode); }; var readPinMux = function (pin, mode, callback) { winston.info('readPinMux(' + [pin.key] + ')'); if (callback) { if (callback.length == 1) callback(mode); else callback(null, mode); } return (mode); }; var setPinMode = function (pin, pinData, template, resp) { winston.info('setPinMode(' + [pin.key, pinData, template] + ')'); gpioFile[pin.key] = true; return (resp); }; var setLEDPinToGPIO = function (pin, resp) { winston.info('setLEDPinToGPIO(' + [pin.key] + ')'); return (resp); }; var exportGPIOControls = function (pin, direction, resp) { winston.info('expertGPIOControls(' + [pin.key, direction] + ')'); return (resp); }; var writeGPIOValue = function (pin, value, callback) { winston.info('writeGPIOValue(' + [pin.key, value] + ')'); if (callback) { callback(); } }; var readGPIOValue = function (pin, resp, callback) { winston.info('readGPIOValue(' + [pin.key] + ')'); if (callback) { resp.value = 0; if (callback.length == 1) callback(resp); else callback(null, resp.value); return (true); } resp.value = 0; return (resp); }; var enableAIN = function () { winston.info('enableAIN()'); return (true); }; var readAIN = function (pin, resp, callback) { winston.info('readAIN(' + [pin.key] + ')'); resp.value = 0; if (callback) { if (callback.length == 1) callback(resp); else callback(null, resp.value); } return (resp); }; var writeGPIOEdge = function (pin, mode) { winston.info('writeGPIOEdge(' + [pin.key, mode] + ')'); var resp = {}; return (resp); }; var writePWMFreqAndValue = function (pin, pwm, freq, value, resp) { winston.info('writePWMFreqAndValue(' + [pin.key, pwm.name, freq, value] + ')'); return (resp); }; var readEeproms = function (eeproms) { winston.info('readEeproms()'); var boardName = 'A335BNLT'; var version = ''; var serialNumber = ''; eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'] = {}; eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'].boardName = boardName; eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'].version = version; eeproms['/sys/bus/i2c/drivers/at24/1-0050/eeprom'].serialNumber = serialNumber; return (eeproms); }; var readPlatform = function (platform) { winston.info('readPlatform()'); platform.name = 'BeagleBone Simulator'; return (platform); }; var getPin = function (pin) { return (my.getpin(pin)); }; module.exports = { logfile: logfile, readPWMFreqAndValue: readPWMFreqAndValue, readGPIODirection: readGPIODirection, readPinMux: readPinMux, setPinMode: setPinMode, setLEDPinToGPIO: setLEDPinToGPIO, exportGPIOControls: exportGPIOControls, writeGPIOValue: writeGPIOValue, readGPIOValue: readGPIOValue, enableAIN: enableAIN, readAIN: readAIN, writeGPIOEdge: writeGPIOEdge, writePWMFreqAndValue: writePWMFreqAndValue, readEeproms: readEeproms, readPlatform: readPlatform, getPin: getPin } ================================================ FILE: src/hw_universal.js ================================================ var fs = require('fs'); var winston = require('winston'); var my = require('./my'); var parse = require('./parse'); var eeprom = require('./eeprom'); var debug = process.env.DEBUG ? true : false; var gpioFile = {}; var pwmPrefix = {}; var ainPrefix = ""; var logfile = '/var/lib/cloud9/bonescript.log'; var readPWMFreqAndValue = function (pin, pwm) { var mode = {}; try { var period = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/period_ns'); var duty = fs.readFileSync(pwmPrefix[pin.pwm.name] + '/duty_ns'); mode.freq = 1.0e9 / period; mode.value = duty / period; } catch (ex) {} return (mode); }; var readGPIODirection = function (n, gpio) { var mode = {}; var directionFile = "/sys/class/gpio/gpio" + n + "/direction"; if (my.file_existsSync(directionFile)) { mode.active = true; var direction = fs.readFileSync(directionFile, 'utf-8'); direction = direction.replace(/^\s+|\s+$/g, ''); mode.direction = direction; } return (mode); }; var readPinMux = function (pin, mode, callback) { var pinctrlFile = '/sys/kernel/debug/pinctrl/44e10800.pinmux/pins'; var muxRegOffset = parseInt(pin.muxRegOffset, 16); var readPinctrl = function (err, data) { if (err) { mode.err = 'readPinctrl error: ' + err; if (debug) winston.debug(mode.err); callback(mode); } mode = parse.modeFromPinctrl(data, muxRegOffset, 0x44e10800, mode); callback(mode); }; var tryPinctrl = function (exists) { if (exists) { fs.readFile(pinctrlFile, 'utf8', readPinctrl); } else { if (debug) winston.debug('getPinMode(' + pin.key + '): no valid mux data'); callback(mode); } }; if (callback) { my.file_exists(pinctrlFile, tryPinctrl); } else { try { var data2 = fs.readFileSync(pinctrlFile, 'utf8'); mode = parse.modeFromPinctrl(data2, muxRegOffset, 0x44e10800, mode); } catch (ex) { if (debug) winston.debug('getPinMode(' + pin.key + '): ' + ex); } } return (mode); }; var setPinMode = function (pin, pinData, template, resp, callback) { if (debug) winston.debug('hw.setPinMode(' + [pin.key, pinData, template, JSON.stringify(resp)] + ');'); var p = pin.key + "_pinmux"; if (pin.universalName) p = pin.universalName + "_pinmux"; var pinmux = my.find_sysfsFile(p, my.is_ocp(), p + '.'); if (!pinmux) { throw p + " was not found under " + my.is_ocp(); } if ((pinData & 7) == 7) { gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; fs.writeFileSync(pinmux + "/state", 'gpio'); } else if (template == 'bspwm') { fs.writeFileSync(pinmux + "/state", 'pwm'); pwmPrefix[pin.pwm.name] = '/sys/class/pwm/pwm' + pin.pwm.sysfs; if (!my.file_existsSync(pwmPrefix[pin.pwm.name])) { fs.appendFileSync('/sys/class/pwm/export', pin.pwm.sysfs); } fs.appendFileSync(pwmPrefix[pin.pwm.name] + '/run', 1); } else { resp.err = 'Unknown pin mode template'; } if (callback) callback(resp); return (resp); }; var setLEDPinToGPIO = function (pin, resp) { var path = "/sys/class/leds/beaglebone:green:" + pin.led + "/trigger"; if (my.file_existsSync(path)) { fs.writeFileSync(path, "gpio"); } else { resp.err = "Unable to find LED " + pin.led; winston.error(resp.err); resp.value = false; } return (resp); }; var exportGPIOControls = function (pin, direction, resp, callback) { if (debug) winston.debug('hw.exportGPIOControls(' + [pin.key, direction, resp] + ');'); var n = pin.gpio; var exists = my.file_existsSync(gpioFile[pin.key]); if (!exists) { if (debug) winston.debug("exporting gpio: " + n); fs.writeFileSync("/sys/class/gpio/export", "" + n, null); } var directionFile = "/sys/class/gpio/gpio" + n + "/direction"; if (debug) winston.debug('Writing GPIO direction(' + direction + ') to ' + directionFile + ');'); fs.writeFileSync(directionFile, direction); return (resp); }; var writeGPIOValue = function (pin, value, callback) { if (typeof gpioFile[pin.key] == 'undefined') { gpioFile[pin.key] = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (pin.led) { gpioFile[pin.key] = "/sys/class/leds/beaglebone:"; gpioFile[pin.key] += "green:" + pin.led + "/brightness"; } if (!my.file_existsSync(gpioFile[pin.key])) { winston.error("Unable to find gpio: " + gpioFile[pin.key]); } } if (debug) winston.debug("gpioFile = " + gpioFile[pin.key]); if (callback) { fs.writeFile(gpioFile[pin.key], '' + value, null, callback); } else { try { fs.writeFileSync(gpioFile[pin.key], '' + value, null); } catch (ex) { winston.error("Unable to write to " + gpioFile[pin.key]); } } }; var readGPIOValue = function (pin, resp, callback) { var gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if (callback) { var readFile = function (err, data) { if (err) { resp.err = 'digitalRead error: ' + err; winston.error(resp.err); } resp.value = parseInt(data, 2); callback(resp); }; fs.readFile(gpioFile, readFile); return (true); } resp.value = parseInt(fs.readFileSync(gpioFile), 2); return (resp); }; var enableAIN = function (callback) { var helper = ""; if (my.load_dt('cape-bone-iio')) { var ocp = my.is_ocp(); if (ocp) { helper = my.find_sysfsFile('helper', ocp, 'helper.'); if (helper) { ainPrefix = helper + '/AIN'; } } } else { if (debug) winston.debug('enableAIN: load of cape-bone-iio failed'); } if (callback) { callback({ 'path': helper }) } return (helper.length > 1); }; var readAIN = function (pin, resp, callback) { var ainFile = ainPrefix + pin.ain.toString(); if (callback) { var readFile = function (err, data) { if (err) { resp.err = 'analogRead error: ' + err; winston.error(resp.err); } resp.value = parseInt(data, 10) / 1800; callback(resp); }; fs.readFile(ainFile, readFile); return (resp); } resp.value = parseInt(fs.readFileSync(ainFile), 10); if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') returned ' + resp.value; winston.error(resp.err); } resp.value = resp.value / 1800; if (isNaN(resp.value)) { resp.err = 'analogRead(' + pin.key + ') scaled to ' + resp.value; winston.error(resp.err); } return (resp); }; var writeGPIOEdge = function (pin, mode) { fs.writeFileSync('/sys/class/gpio/gpio' + pin.gpio + '/edge', mode); var resp = {}; resp.gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; resp.valuefd = fs.openSync(resp.gpioFile, 'r'); resp.value = new Buffer(1); return (resp); }; var writePWMFreqAndValue = function (pin, pwm, freq, value, resp, callback) { if (debug) winston.debug('hw.writePWMFreqAndValue(' + [pin.key, pwm, freq, value, resp] + ');'); var path = pwmPrefix[pin.pwm.name]; try { var period = Math.round(1.0e9 / freq); // period in ns if (pwm.freq != freq) { if (debug) winston.debug('Stopping PWM'); fs.writeFileSync(path + '/run', "0\n"); if (debug) winston.debug('Setting duty to 0'); fs.writeFileSync(path + '/duty_ns', "0\n"); try { if (debug) winston.debug('Updating PWM period: ' + period); fs.writeFileSync(path + '/period_ns', period + "\n"); } catch (ex2) { period = fs.readFileSync(path + '/period_ns'); winston.info('Unable to update PWM period, period is set to ' + period); } if (debug) winston.debug('Starting PWM'); fs.writeFileSync(path + '/run', "1\n"); } var duty = Math.round(period * value); if (debug) winston.debug('Updating PWM duty: ' + duty); //if(duty == 0) winston.error('Updating PWM duty: ' + duty); fs.writeFileSync(path + '/duty_ns', duty + "\n"); } catch (ex) { resp.err = 'error updating PWM freq and value: ' + path + ', ' + ex; winston.error(resp.err); } return (resp); }; var readEeproms = function (eeproms) { var EepromFiles = { '/sys/bus/i2c/drivers/at24/0-0050/eeprom': { type: 'bone' }, '/sys/bus/i2c/drivers/at24/2-0054/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/2-0055/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/2-0056/eeprom': { type: 'cape' }, '/sys/bus/i2c/drivers/at24/2-0057/eeprom': { type: 'cape' } }; eeproms = eeprom.readEeproms(EepromFiles); return (eeproms); }; var readPlatform = function (platform) { var eeproms = eeprom.readEeproms({ '/sys/bus/i2c/drivers/at24/0-0050/eeprom': { type: 'bone' } }); var x = eeproms['/sys/bus/i2c/drivers/at24/0-0050/eeprom']; if (x.boardName == 'A335BONE') platform.name = 'BeagleBone'; if (x.boardName == 'A335BNLT') platform.name = 'BeagleBone Black'; platform.version = x.version; if (!platform.version.match(/^[\040-\176]*$/)) delete platform.version; platform.serialNumber = x.serialNumber; if (!platform.serialNumber.match(/^[\040-\176]*$/)) delete platform.serialNumber; try { platform.dogtag = fs.readFileSync('/etc/dogtag', 'ascii'); } catch (ex) {} return (platform); }; module.exports = { logfile: logfile, readPWMFreqAndValue: readPWMFreqAndValue, readGPIODirection: readGPIODirection, readPinMux: readPinMux, setPinMode: setPinMode, setLEDPinToGPIO: setLEDPinToGPIO, exportGPIOControls: exportGPIOControls, writeGPIOValue: writeGPIOValue, readGPIOValue: readGPIOValue, enableAIN: enableAIN, readAIN: readAIN, writeGPIOEdge: writeGPIOEdge, writePWMFreqAndValue: writePWMFreqAndValue, readEeproms: readEeproms, readPlatform: readPlatform } ================================================ FILE: src/iic.js ================================================ // Copyright (C) 2013 - Texas Instruments, Jason Kridner var bone = require('./bone'); var my = require('./my'); var m = {}; m.name = 'i2c'; m.module = my.require('i2c'); m.ports = bone.i2c; m.events = { 'data': ['data'] }; m.openPorts = {}; m.doOpen = function (args) { var path = args.port[0]; if (m.ports[args.port[0]].path) path = m.ports[args.port[0]].path; if (typeof args.options !== typeof {}) args.options = {}; args.options.device = path; var openPort = new m.module(args.port[1], args.options); return (openPort); }; module.exports = { i2cOpen: my.wrapOpen(m, ['options']), i2cScan: my.wrapCall(m, 'scan', [], ['err', 'data']), i2cWriteByte: my.wrapCall(m, 'writeByte', ['byte'], ['err']), i2cWriteBytes: my.wrapCall(m, 'writeBytes', ['command', 'bytes'], ['err']), i2cReadByte: my.wrapCall(m, 'readByte', [], ['err', 'res']), i2cReadBytes: my.wrapCall(m, 'readBytes', ['command', 'length'], ['err', 'res']), i2cStream: my.wrapCall(m, 'stream', ['command', 'length', 'delay'], []) } ================================================ FILE: src/index.d.ts ================================================ // Type definitions for bonescript 0.6 // Project: https://github.com/jadonk/bonescript // Definitions by: Troy W. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import * as SerialPort from 'serialport'; import * as VError from 'verror'; // OBJECTS export const bone: BoneObj; // FUNCTIONS - TODO obliterate all "any" types where possible! --- TWW // https://github.com/jadonk/bonescript#system export function getPlatform(callback?: (error: ErrorType, platform: PlatformObj) => void): any; export function echo(data: string, callback?: (error: ErrorType, data: string) => void): any; export function readTextFile(filename: string, callback?: (error: ErrorType, data: string) => void): string; export function writeTextFile(filename: string, data: any, callback?: (error: ErrorType) => void): any; export function writeCModule(filename: string, data: any, callback?: (error: ErrorType) => void): any; export function setDate(date: string, callback?: (error: ErrorType) => void): any; export function analogRead(pin: string, callback?: (err: ErrorType, value: number) => void): any; export function analogWrite(pin: string, value: number, freq?: number, callback?: ErrorCb): any; export function attachInterrupt( pin: string, handler: InterruptFn, mode: InterruptType, callback?: AttachIntCb ): any; export function detachInterrupt(pin: string, callback?: DetachIntCb): any; export function digitalRead(pin: string, callback?: (err: ErrorType, value: number) => void): any; export function digitalWrite(pin: string, value: PinStateType, callback?: DigitalWriteCb): any; export function pinMode( pin: string, direction: 'in' | 'out' | 'analog_out' | 'in_pullup', mux?: string, pullup?: 'disabled' | 'pullup' | 'pulldown', slew?: 'fast' | 'slow', callback?: PinModeCb ): any; export function getPinMode(pin: string, callback?: (err: ErrorType, mode: PinModeObj) => void): any; export function shiftOut(dataPin: string, clockPin: string, bitOrder: BitOrderType, val: number, callback?: ErrorCb): any; // https://github.com/jadonk/bonescript#serial export function serialOpen(port: any, options: any, callback?: ErrorCb): any; export function serialWrite(port: any, data: any, callback?: ErrorCb): any; export const serialParsers: typeof SerialPort.parsers; export function i2cOpen(port: any, address: any, options: any, callback?: ErrorCb): any; export function i2cScan(port: any, callback?: ErrorCb): any; export function i2cWriteByte(port: any, byte: any, callback?: ErrorCb): any; export function i2cWriteBytes(port: any, command: any, bytes: any, callback?: ErrorCb): any; export function i2cReadByte(port: any, callback?: ErrorCb): any; export function i2cReadBytes(port: any, command: any, length: any, callback?: ErrorCb): any; export function i2cStream(port: any, command: any, length: any, callback?: ErrorCb): any; // ffi export function loadCModule(filename: string, data: any, isMRAA?: boolean): any; export function lowByte(value: number): number; export function highByte(value: number): number; export function bitRead(value: number, bitnum: number): number; export function bitWrite(value: number, bitnum: number, bitdata: any): number; export function bitSet(value: number, bitnum: number): number; export function bitClear(value: number, bitnum: number): number; export function bit(bitnum: number): number; export function min(x: number, y: number): number; export function max(x: number, y: number): number; export function abs(x: number): number; export function constrain(x: number, a: number, b: number): number; export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number; export function pow(x: number, y: number): number; export function sqrt(x: number): number; export function sin(radians: number): number; export function cos(radians: number): number; export function tan(radians: number): number; export function randomSeed(x: number): void; export function random(min: number, max?: number): number; export function delay(...args: any[]): any; export function autorun(...args: any[]): any; export function serverStart(...args: any[]): any; export function socketJSReqHandler(...args: any[]): any; export function addSocketListeners(...args: any[]): any; export function setGlobals(...args: any[]): any; // CONSTANTS export const OUTPUT: 'out'; export const INPUT: 'in'; export const INPUT_PULLUP: 'in_pullup'; export const ANALOG_OUTPUT: 'analog_out'; export const HIGH: 1; export const LOW: 0; export const LSBFIRST: 1; export const MSBFIRST: 0; export const CHANGE: 'both'; export const RISING: 'rising'; export const FALLING: 'falling'; // INTERFACES - adjusted based on observation / testing interface PlatformObj { name: string; platform: BoneObj; bonescript: string; serialNumber?: string; dogtag?: string; os: { hostname: string, type: string, arch: string, release: string, uptime: number, loadavg: number[], totalmem: number, freemem: number, networkInterfaces?: any }; } export interface PinModeObj { gpio?: { active: boolean, direction: 'in' | 'out', allocated: boolean, }; modes: string[]; mux?: number; name: string; pin: string; pinState: string; pullup?: 'disabled' | 'pullup' | 'pulldown'; pwm?: { freq: number, value: number, }; rx?: 'enabled' | 'disabled'; slew?: 'fast' | 'slow'; } interface BoneObj { i2c: i2cObj; uarts: UartsObj; getPinKeys(): string[]; getPinObjects(): any; naturalCompare(): any; } interface PinsObj { [i: string]: PinInfo; } interface UartsObj { [i: string]: UartInfo; } interface i2cObj { [i: string]: i2cInfo; } export interface PinInfo { // Analog In ain?: number; // GPIO / LEDs / Analog In eeprom?: number; // GPIO / LEDs gpio?: number; key: string; // LEDs led?: string; mux?: string; muxRegOffset?: string; // All name: string; options?: string[]; // PWM pwm?: PwmInfo; scale?: number; universalName?: string; } interface PwmInfo { addr: string; chip: string; index: number; module: string; muxmode: number; name: string; path: string; sysfs: number; } interface UartInfo { devicetree?: string; rx?: string; tx?: string; } interface i2cInfo { devicetree?: string; path?: string; scl?: string; sda?: string; } // TYPES - adjusted based on observation / testing type PinStateType = typeof HIGH | typeof LOW; type PinModeType = typeof ANALOG_OUTPUT | typeof INPUT | typeof INPUT_PULLUP | typeof OUTPUT; type InterruptType = typeof RISING | typeof FALLING | typeof CHANGE; type BitOrderType = typeof LSBFIRST | typeof MSBFIRST; type ErrorCb = (err: ErrorType) => void; type InterruptFn = (resp: { pin: PinInfo, value: number }) => void; type AttachIntCb = (resp: { pin: PinInfo, attached: boolean }) => void; type DetachIntCb = (resp: { pin: PinInfo, detached: boolean }) => void; type PinModeCb = (resp: { value: number, err: VError }) => void; type DigitalWriteCb = (resp: { data: any, err: VError }) => void; type ErrorType = VError; ================================================ FILE: src/index.js ================================================ // Copyright (C) 2011 - Texas Instruments, Jason Kridner // // var fs = require('fs'); var child_process = require('child_process'); var os = require('os'); var bone = require('./bone'); // Database of pins var functions = require('./functions'); // functions.js defines several math/bit functions that are handy var package_json = require('../package.json'); var g = require('./constants'); var my = require('./my'); var serial = require('./serial'); var iic = require('./iic'); var winston = my.require('winston'); var fibers = my.require('fibers'); var epoll = my.require('epoll'); var autorun = require('./autorun'); var server = require('./server'); var socketHandlers = require('./socket_handlers'); var ffi = require('./ffiimp'); var rc = require('./rc'); var debug = process.env.DEBUG ? true : false; var cbWarn = false; // Detect if we are on a Beagle var hw; if (os.type() == 'Linux' && os.arch() == 'arm') { var osVer = ("" + os.release()).split('.'); if (debug) console.log(osVer.join(":")); if (my.is_new_capemgr() || osVer[0] > 4 || (osVer[0] == 4 && osVer[1] >= 4)) { // Used for 4.4+ kernels using capemgr and universal helpers hw = require('./hw_mainline'); if (debug) console.log('Using Mainline interface'); } else if (my.is_cape_universal()) { // Used for 3.8 kernels using a single universal overlay with pinmux helpers // located in debugfs at /sys/kernel/debug/pinctrl/44e10800.pinmux/pins hw = require('./hw_universal'); if (debug) console.log('Using Universal Cape interface'); } else if (my.is_capemgr()) { // Used for 3.8 kernels using an older out-of-tree version of CapeMgr hw = require('./hw_capemgr'); if (debug) console.log('Using CapeMgr interface'); } else { // Used for 3.2 kernels using /sys/kernel/debug/omap_mux/ hw = require('./hw_oldkernel'); if (debug) console.log('Using 3.2 kernel interface'); } } else { // Incomplete implementation of a set of hardware stubs to run on non BeagleBone targets hw = require('./hw_simulator'); if (debug) winston.debug('Using simulator mode'); } if (debug) { winston.add(winston.transports.File, { filename: hw.logfile, level: 'debug' }); winston.level = 'debug'; } else { winston.setLevels(winston.config.syslog.levels); } if (debug) winston.debug('index.js loaded'); var f = {}; // Keep track of allocated resources var gpio = {}; var gpioInt = {}; var pwm = {}; var ain = false; // returned object has: // mux: index of mux mode // options: array of mode names // slew: 'fast' or 'slow' // rx: 'enabled' or 'disabled' // pullup: 'diabled', 'pullup' or 'pulldown' // pin: key string for pin // name: pin name // pwm: object if pwm enabled, undefind otherwise // freq: frequency of PWM // value: duty cycle of PWM as number between 0 and 1 // gpio: object if GPIO enabled, undefined otherwise // active: GPIO is enabled by the kernel // allocated: boolean for if it is allocated by this application // direction: 'in' or 'out' (allocated might be false) f.getPinMode = function (pin, callback) { pin = hw.getPin(pin); if (debug) winston.debug('getPinMode(' + pin.key + ');'); var mode = { 'pin': pin.key, 'name': pin.name }; if (pin.options) mode.options = pin.options; // Get PWM settings if applicable if ( (typeof pin.pwm != 'undefined') // pin has PWM capabilities && (typeof pwm[pin.pwm.name] != 'undefined') // PWM used for this pin is enabled && (pin.key == pwm[pin.pwm.name].key) // PWM is allocated for this pin ) { mode.pwm = hw.readPWMFreqAndValue(pin, pwm[pin.pwm.name]); } // Get GPIO settings if applicable if ((typeof pin.gpio != 'undefined')) { var n = pin.gpio; mode.gpio = hw.readGPIODirection(n, gpio); if (typeof gpio[n] == 'undefined') { mode.gpio.allocated = false; } else { mode.gpio.allocated = true; } } // Get pinmux settings mode = hw.readPinMux(pin, mode, callback); return (mode); }; f.getPinMode.args = ['pin', 'callback']; f.pinMode = function (pin, direction, mux, pullup, slew, callback) { pin = hw.getPin(pin); if (debug) winston.debug('pinMode(' + [pin.key, direction, mux, pullup, slew] + ');'); if (direction == g.INPUT_PULLUP) pullup = 'pullup'; pullup = pullup || ((direction == g.INPUT) ? 'pulldown' : 'disabled'); slew = slew || 'fast'; mux = (typeof mux != 'undefined') ? mux : 7; // default to GPIO mode var resp = { value: true }; var template = 'bspm'; var n = pin.gpio; if ( direction == g.ANALOG_OUTPUT || mux == g.ANALOG_OUTPUT || (typeof pin.pwm != 'undefined' && mux == pin.pwm.muxmode) ) { if ( (typeof pin.pwm == 'undefined') || // pin does not have PWM capability (typeof pin.pwm.muxmode == 'undefined') // required muxmode is not provided ) { var err = 'pinMode only supports ANALOG_OUTPUT for PWM pins: ' + pin.key; winston.info(err); if (callback) { //support both nodestyle and oldstyle callbacks based on arguments length if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback({ value: false, err: err }); } else callback(err, false); } return (false); } direction = g.OUTPUT; mux = pin.pwm.muxmode; template = 'bspwm'; pwm[pin.pwm.name] = { 'key': pin.key, 'freq': 0 }; } if (!pin.mux) { winston.info('pinMode: Missing mux name for pin object: ' + JSON.stringify(pin)); } // Handle case where pin is allocated as a gpio-led if (debug) winston.debug('pinMode: pin.led = ' + pin.led); if (pin.led) { if ((direction != g.OUTPUT) || (mux != 7)) { resp.err = 'pinMode only supports GPIO output for LEDs: ' + pin.key; winston.info(resp.err); resp.value = false; if (callback) callback(resp); return (false); } resp = hw.setLEDPinToGPIO(pin, resp); if (typeof resp.err == 'undefined') { gpio[n] = true; } if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(resp); } else callback(resp.err, resp.value); } return (resp.value); } // Figure out the desired value var pinData = my.pin_data(slew, direction, pullup, mux); // May be required: mount -t debugfs none /sys/kernel/debug resp = hw.setPinMode(pin, pinData, template, resp); if (typeof resp.err != 'undefined') { if (debug) winston.debug('Unable to configure mux for pin ' + pin + ': ' + resp.err); // It might work if the pin is already muxed to desired mode var currentMode = f.getPinMode(pin); if (currentMode.mux != mux) { resp.value = false; winston.info(resp.err); delete gpio[n]; if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(resp); } else callback(resp.err, resp.value); } return (resp.value); } } // Enable GPIO and set direction if (mux == 7) { // Export the GPIO controls resp = hw.exportGPIOControls(pin, direction, resp); if (typeof resp.err != 'undefined') { if (typeof gpio[n] == 'undefined') { delete gpio[n]; } } else { gpio[n] = true; } } else { delete gpio[n]; } if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(resp); } else callback(resp.err, resp.value); } return (resp.value); }; f.pinMode.args = ['pin', 'direction', 'mux', 'pullup', 'slew', 'callback']; f.digitalWrite = function (pin, value, callback) { var myCallback = false; if (callback) myCallback = function (resp) { if (!resp || (typeof resp != 'object')) resp = { 'data': resp }; callback(resp); } pin = hw.getPin(pin); if (debug) winston.debug('digitalWrite(' + [pin.key, value] + ');'); value = parseInt(Number(value), 2) ? 1 : 0; //handle case digitalWrite() on Analog_Out if (typeof pin.pwm != 'undefined' && typeof f.getPinMode(pin).mux != 'undefined') { var gpioEnabled = (7 == f.getPinMode(pin).mux); //check whether pin set as gpio if (!gpioEnabled) { winston.debug([pin.key, value] + ' set as ANALOG_OUTPUT modifying duty cycle according to value'); f.analogWrite(pin, value, 2000, myCallback); //write duty cycle as per value return (true); } } hw.writeGPIOValue(pin, value, myCallback); return (true); }; f.digitalWrite.args = ['pin', 'value', 'callback']; f.digitalRead = function (pin, callback) { pin = hw.getPin(pin); if (debug) winston.debug('digitalRead(' + [pin.key] + ');'); var resp = {}; if (typeof pin.ain != 'undefined') { if (callback) { f.analogRead(pin, analogCallback); } else { resp.value = f.analogRead(pin); if (resp.value >= 0.5) { resp.value = g.HIGH; } else { resp.value = g.LOW; } } } else { resp = hw.readGPIOValue(pin, resp, callback); } function analogCallback(x) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(analogValue(x)); } else callback(x.err, analogValue(x).value); } function analogValue(x) { if (typeof x.value == 'undefined') return; if (x.value >= 0.5) { x.value = g.HIGH; } else { x.value = g.LOW; } return x; } return (resp.value); }; f.digitalRead.args = ['pin', 'callback']; f.analogRead = function (pin, callback) { pin = hw.getPin(pin); if (debug) winston.debug('analogRead(' + [pin.key] + ');'); var resp = {}; if (!ain) { ain = hw.enableAIN(); } if (typeof pin.ain == 'undefined') { resp.value = f.digitalRead(pin, callback); } else { resp = hw.readAIN(pin, resp, callback); } return (resp.value); }; f.analogRead.args = ['pin', 'callback']; f.shiftOut = function (dataPin, clockPin, bitOrder, val, callback) { dataPin = hw.getPin(dataPin); clockPin = hw.getPin(clockPin); if (debug) winston.debug('shiftOut(' + [dataPin.key, clockPin.key, bitOrder, val] + ');'); var i = 0; var bit; var clock = 0; function next(err) { if (debug) winston.debug('i = ' + i); if (debug) winston.debug('clock = ' + clock); if (err || i == 8) { callback({ 'err': err }); return; } if (bitOrder == g.LSBFIRST) { bit = val & (1 << i); } else { bit = val & (1 << (7 - i)); } if (clock === 0) { clock = 1; if (bit) { f.digitalWrite(dataPin, g.HIGH, next); } else { f.digitalWrite(dataPin, g.LOW, next); } } else if (clock == 1) { clock = 2; f.digitalWrite(clockPin, g.HIGH, next); } else if (clock == 2) { i++; clock = 0; f.digitalWrite(clockPin, g.LOW, next); } } if (callback) { next(); } else { for (i = 0; i < 8; i++) { if (bitOrder == g.LSBFIRST) { bit = val & (1 << i); } else { bit = val & (1 << (7 - i)); } if (bit) { f.digitalWrite(dataPin, g.HIGH); } else { f.digitalWrite(dataPin, g.LOW); } f.digitalWrite(clockPin, g.HIGH); f.digitalWrite(clockPin, g.LOW); } } }; f.shiftOut.args = ['dataPin', 'clockPin', 'bitOrder', 'val', 'callback']; f.attachInterrupt = function (pin, handler, mode, callback) { pin = hw.getPin(pin); if (debug) winston.debug('attachInterrupt(' + [pin.key, handler, mode] + ');'); var n = pin.gpio; var resp = { 'pin': pin, 'attached': false }; // Check if we don't have the required Epoll module if (!epoll.exists) { resp.err = 'attachInterrupt: requires Epoll module'; if (debug) winston.debug(resp.err); if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(resp); } else { var err = resp.err; delete resp.err; callback(err, resp); } } return (resp.attached); } // Check if pin isn't already configured as GPIO if (typeof gpio[n] == 'undefined') { resp.err = 'attachInterrupt: pin ' + pin.key + ' not already configured as GPIO'; if (debug) winston.debug(resp.err); resp.attached = false; resp.configured = false; if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(resp); } else { var err = resp.err; delete resp.err; callback(err, resp); } } return (resp); } // Check if someone already has a handler configured if (typeof gpioInt[n] != 'undefined') { resp.err = 'attachInterrupt: pin ' + pin.key + ' already has an interrupt handler assigned'; if (debug) winston.debug(resp.err); resp.attached = false; resp.configured = true; if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(resp); } else { var err = resp.err; delete resp.err; callback(err, resp); } } return (resp.attached); } handler = (typeof handler === "string") ? my.myeval('(' + handler + ')') : handler; var intHandler = function (err, fd, events) { var m = {}; if (err) { m.err = err; } fs.readSync(gpioInt[n].valuefd, gpioInt[n].value, 0, 1, 0); m.pin = pin; m.value = parseInt(gpioInt[n].value.toString(), 2); if (typeof handler == 'function') m.output = handler(m); else m.output = { handler: handler }; if (m.output && (typeof callback == 'function')) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(m); } else { var err = m.err; delete m.err; callback(err, m); } } }; try { gpioInt[n] = hw.writeGPIOEdge(pin, mode); gpioInt[n].epoll = new epoll.Epoll(intHandler); fs.readSync(gpioInt[n].valuefd, gpioInt[n].value, 0, 1, 0); gpioInt[n].epoll.add(gpioInt[n].valuefd, epoll.Epoll.EPOLLPRI); resp.attached = true; } catch (ex) { resp.err = 'attachInterrupt: GPIO input file not opened: ' + ex; if (debug) winston.debug(resp.err); } if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); cbWarn = true; callback(resp); } else { var err = resp.err; delete resp.err; callback(err, resp); } } return (resp.attached); }; f.attachInterrupt.args = ['pin', 'handler', 'mode', 'callback']; f.detachInterrupt = function (pin, callback) { pin = hw.getPin(pin); if (debug) winston.debug('detachInterrupt(' + [pin.key] + ');'); var n = pin.gpio; if (typeof gpio[n] == 'undefined' || typeof gpioInt[n] == 'undefined') { if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'pin': pin, 'detached': false }); } else callback(true, { 'pin': pin, 'detached': false }); } return (false); } gpioInt[n].epoll.remove(gpioInt[n].valuefd); delete gpioInt[n]; if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'pin': pin, 'detached': true }); } else callback(null, { 'pin': pin, 'detached': true }); } return (true); }; f.detachInterrupt.args = ['pin', 'callback']; // See http://processors.wiki.ti.com/index.php/AM335x_PWM_Driver's_Guide // That guide isn't useful for the new pwm_test interface f.analogWrite = function (pin, value, freq, callback) { pin = hw.getPin(pin); if (debug) winston.debug('analogWrite(' + [pin.key, value, freq] + ');'); freq = freq || 2000.0; var resp = {}; // Make sure the pin has a PWM associated if (typeof pin.pwm == 'undefined') { //handle analogWrite() on digital OUTPUT if (typeof pin.gpio != 'undefined') { if (value >= 0.5) { if (callback) f.digitalWrite(pin, g.HIGH, callback); else f.digitalWrite(pin, g.HIGH); return (true); } else { if (callback) f.digitalWrite(pin, g.LOW, callback); else f.digitalWrite(pin, g.LOW); return (true); } } resp.err = 'analogWrite: ' + pin.key + ' does not support analogWrite()'; winston.error(resp.err); if (callback) callback(resp); return (false); } // Make sure there is no one else who has the PWM if ( (typeof pwm[pin.pwm.name] != 'undefined') // PWM needed by this pin is already allocated && (pin.key != pwm[pin.pwm.name].key) // allocation is not by this pin ) { resp.err = 'analogWrite: ' + pin.key + ' requires pwm ' + pin.pwm.name + ' but it is already in use by ' + pwm[pin.pwm.name].key; winston.error(resp.err); if (callback) callback(resp); return (false); } // Enable PWM controls if not already done if (typeof pwm[pin.pwm.name] == 'undefined') { var pinMode = f.getPinMode(pin.key); var slew = pinMode.slew || 'fast'; var pullup = pinMode.pullup || 'disabled'; f.pinMode(pin, g.ANALOG_OUTPUT, pin.pwm.muxmode, pullup, slew); } // Perform update resp = hw.writePWMFreqAndValue(pin, pwm[pin.pwm.name], freq, value, resp); // Save off the freq, value and PWM assignment pwm[pin.pwm.name].freq = freq; pwm[pin.pwm.name].value = value; // All done if (callback) callback(resp); return (true); }; f.analogWrite.args = ['pin', 'value', 'freq', 'callback']; f.getEeproms = function (callback) { var eeproms = {}; eeproms = hw.readEeproms(eeproms); if (eeproms == {}) { if (debug) winston.debug('No valid EEPROM contents found'); } if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(eeproms); } else callback(eeproms == {} ? 'No valid EEPROM contents found' : null, eeproms); } return (eeproms); }; f.getEeproms.args = ['callback']; f.readTextFile = function (filename, callback) { if (typeof callback == 'function') { var cb = function (err, data) { callback({ 'err': err, 'data': data }); }; if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); fs.readFile(filename, 'ascii', cb); } else fs.readFile(filename, 'ascii', callback); } else { return fs.readFileSync(filename, 'ascii'); } }; f.readTextFile.args = ['filename', 'callback']; f.writeTextFile = function (filename, data, callback) { if (typeof callback == 'function') { var cb = function (err) { callback({ 'err': err }); }; fs.writeFile(filename, data, 'ascii', cb); } else { try { return fs.writeFileSync(filename, data, 'ascii'); } catch (ex) { winston.error("writeTextFile error: " + ex); return (false); } } }; f.writeTextFile.args = ['filename', 'data', 'callback']; f.getPlatform = function (callback) { var platform = { 'platform': bone, 'name': "BeagleBone", 'bonescript': package_json.version, 'os': {} }; platform.os.hostname = os.hostname(); platform.os.type = os.type(); platform.os.arch = os.arch(); platform.os.release = os.release(); platform.os.uptime = os.uptime(); platform.os.loadavg = os.loadavg(); platform.os.totalmem = os.totalmem(); platform.os.freemem = os.freemem(); platform.os.networkInterfaces = os.networkInterfaces(); platform = hw.readPlatform(platform); if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(platform); } else callback(null, platform); } return (platform); }; f.getPlatform.args = ['callback']; f.echo = function (data, callback) { winston.info(data); if (callback) { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'data': data }); } else callback(null, data); } return (data); }; f.echo.args = ['data', 'callback']; f.setDate = function (date, callback) { child_process.execFile('date', ['-s', date], dateResponse) function dateResponse(error, stdout, stderr) { if (typeof callback != 'function') return; else { if (callback.length == 1) { if (!cbWarn) winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'error': error, 'stdout': stdout, 'stderr': stderr }); } else callback({ 'error': error, 'stderr': stderr }, stdout); } } }; f.setDate.args = ['date', 'callback']; f.delay = function (ms) { var fiber = fibers.current; if (typeof fiber == 'undefined') { winston.error('sleep may only be called within the setup or run functions'); return; } setTimeout(function () { fiber.run(); }, ms); fibers.yield(); }; // Exported variables f.bone = bone; // this likely needs to be platform and be detected for (var x in functions) { f[x] = functions[x]; } for (var x in serial) { f[x] = serial[x]; } for (var x in iic) { f[x] = iic[x]; } for (var x in g) { f[x] = g[x]; } for (var x in autorun) { f[x] = autorun[x]; } for (var x in server) { f[x] = server[x]; } for (var x in socketHandlers) { f[x] = socketHandlers[x]; } for (var x in ffi) { f[x] = ffi[x]; } for (var x in rc) { f[x] = rc[x]; } var alreadyRan = false; function run() { if (debug) winston.debug('Calling run()'); if (alreadyRan) return (false); alreadyRan = true; // 'setup' and 'loop' are globals that may or may not be defined if (typeof global.setup == 'function' || typeof global.loop == 'function') { fibers(function () { if (typeof global.setup == 'function') { winston.debug('Running setup()'); global.setup(); } if (typeof global.loop == 'function') { if (debug) winston.debug('Starting loop()'); while (1) { global.loop(); } } }).run(); } } process.nextTick(run); // Global variable assignments // This section is broken out because it will eventually be deprecated f.setGlobals = function () { for (var x in f) { global[x] = f[x]; } global.run = run; }; module.exports = f; ================================================ FILE: src/my.js ================================================ // Copyright (C) 2013 - Texas Instruments, Jason Kridner // // This is meant to hold some private functions // var fs = require('fs'); var winston = require('winston'); var child_process = require('child_process'); var bone = require('./bone'); var g = require('./constants'); var debug = process.env.DEBUG ? true : false; var sysfsFiles = {}; // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy var myRequire = function (packageName, onfail) { var module; var exists; var proxyHandler = {}; function proxyGet(target, name) { if (name === "exists") { return exists; } if (!module && exists) { module = require(packageName); } return module[name]; } proxyHandler.get = proxyGet; function proxyFunction() { if (!module && exists) { module = require(packageName); } return module.apply(this, arguments); } var y = new Proxy(proxyFunction, proxyHandler); try { exists = require.resolve(packageName); } catch (ex) { exists = false; if (debug) winston.debug("Optional package '" + packageName + "' not loaded"); if (onfail) onfail(); } return (y); }; var fibers = myRequire('fibers'); var is_new_capemgr = function (callback) { var exists = file_existsSync('/sys/devices/platform/bone_capemgr/slots'); if (callback) callback(exists); return (exists); }; var is_capemgr = function (callback) { return (find_sysfsFile('capemgr', '/sys/devices', 'bone_capemgr.', callback)); }; var is_ocp = function (callback) { var found = find_sysfsFile('ocp', '/sys/devices', 'ocp.', callback); if (debug) winston.debug("is_ocp, found = " + found); if (typeof found == 'undefined') { found = find_sysfsFile('ocp', '/sys/devices/platform', 'ocp', callback); if (debug) winston.debug("is_ocp, found2 = " + found); } return (found); }; var is_cape_universal = function (callback) { var ocp = is_ocp(); if (debug) winston.debug('is_ocp() = ' + ocp); var cape_universal = find_sysfsFile('cape-universal', ocp, 'cape-universal.', callback); if (debug) winston.debug('is_cape_universal() = ' + cape_universal); return (cape_universal); }; var find_sysfsFile = function (name, path, prefix, callback) { if (debug) winston.debug('find_sysfsFile(' + name + ',' + path + ',' + prefix + ')'); if (typeof sysfsFiles[name] == 'undefined') { if (callback) { sysfsFiles[name] = file_find(path, prefix, 1, onFindCapeMgr); } else { sysfsFiles[name] = file_find(path, prefix, 1); } } else { if (callback) callback({ path: sysfsFiles[name] }); } function onFindCapeMgr(resp) { if (typeof resp.path == 'undefined') sysfsFiles[name] = false; else sysfsFiles[name] = resp.path; callback(resp); } return (sysfsFiles[name]); }; file_exists = fs.exists; file_existsSync = fs.existsSync; if (typeof file_exists == 'undefined') { var path = require('path'); file_exists = path.exists; file_existsSync = path.existsSync; } var file_find = function (path, prefix, attempts, callback) { var resp = {}; resp.attempts = 0; if (typeof attempts == 'undefined') attempts = 1; if (callback) { fs.readdir(path, onReadDir); } else { while (resp.attempts < attempts) { try { var files = fs.readdirSync(path); onReadDir(null, files); } catch (ex) { if (debug) winston.debug('Error reading ' + path); return (resp.path); } if (resp.path) return (resp.path); } return (resp.path); } function onReadDir(err, files) { resp.attempts++; if (err) { resp.err = 'Error listing directory ' + path + ': ' + err; if (callback) callback(resp); return; } for (var j in files) { if (Array.isArray(prefix)) { for (var k = 0; k < prefix.length; k++) { if (files[j].search(prefix[k]) == 0) { resp.path = path + '/' + files[j]; if (callback) callback(resp); return; } } } else { if (files[j].search(prefix) === 0) { resp.path = path + '/' + files[j]; if (callback) callback(resp); return; } } } if (callback) { if (resp.attempts >= attempts) { resp.err = 'Did not find ' + prefix + ' in ' + path; callback(resp); } else { fs.readdir(path, onReadDir); } } } return (resp.path); }; // Note, this just makes sure there was an attempt to load the // devicetree fragment, not if it was successful var load_dt = function (name, pin, resp, callback) { if (debug) winston.debug('load_dt(' + [name, pin ? pin.key : null, JSON.stringify(resp)] + ')'); resp = resp || {}; var slotsFile; var lastSlots; var writeAttempts = 0; var readAttempts = 0; if (pin) { var slotRegex = new RegExp('\\d+(?=\\s*:.*,bs.*' + pin.key + ')', 'gm'); } var capemgr = is_capemgr(); onFindCapeMgr({ path: capemgr }); function onFindCapeMgr(x) { if (debug) winston.debug('onFindCapeMgr: path = ' + x.path); if (typeof x.path == 'undefined') { resp.err = "CapeMgr not found: " + x.err; winston.error(resp.err); if (callback) callback(resp); return (false); } slotsFile = x.path + '/slots'; var slots; try { slots = fs.readFileSync(slotsFile, 'ascii'); } catch (ex) { resp.err = ex; } onReadSlots(resp.err, slots); } function onReadSlots(err, slots) { readAttempts++; if (err) { resp.err = 'Unable to read from CapeMgr slots: ' + err; winston.error(resp.err); if (callback) callback(resp); return (false); } lastSlots = slots; var index = slots.indexOf(name); if (debug) winston.debug('onReadSlots: index = ' + index + ', readAttempts = ' + readAttempts); if (index >= 0) { // Fragment is already loaded if (callback) callback(resp); } else if (readAttempts <= 1) { // Attempt to load fragment try { if (debug) winston.debug('Writing ' + name + ' to ' + slotsFile); fs.writeFileSync(slotsFile, name, 'ascii'); } catch (ex) { resp.err = ex; } onWriteSlots(resp.err); } else { resp.err = 'Error waiting for CapeMgr slot to load'; callback(resp); } } function onWriteSlots(err) { writeAttempts++; if (err) { resp.err = 'Write to CapeMgr slots failed: ' + err; if (pin && writeAttempts <= 1) unloadSlot(); else { if (callback) callback(resp); return (false); } } var slots; try { slots = fs.readFileSync(slotsFile, 'ascii'); } catch (ex) { resp.err = ex; } onReadSlots(resp.err, slots); } function unloadSlot() { var slot = lastSlots.match(slotRegex); if (slot && slot[0]) { if (debug) winston.debug('Attempting to unload conflicting slot ' + slot[0] + ' for ' + name); try { fs.writeFileSync(slotsFile, '-' + slot[0], 'ascii'); } catch (ex) { resp.err = ex; } onUnloadSlot(resp.err); } else { if (callback) callback(resp); return (false); } } function onUnloadSlot(err) { if (err) { resp.err = "Unable to unload conflicting slot: " + err; callback(resp); return; } try { fs.writeFileSync(slotsFile, name, 'ascii'); } catch (ex) { resp.err = ex; } onWriteSlots(resp.err); } if (debug) winston.debug('load_dt resp: ' + JSON.stringify(resp)); if (debug) winston.debug('load_dt return: ' + (typeof resp.err == 'undefined')); return (typeof resp.err == 'undefined'); }; var create_dt = function (pin, data, template, load, force_create, resp, callback) { if (debug) winston.debug('create_dt(' + [pin.key, data, template, load, force_create, JSON.stringify(resp)] + ')'); resp = resp || {}; template = template || 'bspm'; load = (typeof load === 'undefined') ? true : load; var fragment = template + '_' + pin.key + '_' + data.toString(16); var dtsFilename = '/lib/firmware/' + fragment + '-00A0.dts'; var dtboFilename = '/lib/firmware/' + fragment + '-00A0.dtbo'; if (force_create) { createDTS(); } else { var exists = file_existsSync(dtboFilename); onDTBOExistsTest(exists); } function onDTBOExistsTest(exists) { if (exists) { onDTBOExists(); } else { createDTS(); } } function createDTS() { var templateFilename = require.resolve('bonescript').replace('main.js', 'dts/' + template + '_template.dts'); if (debug) winston.debug('Creating template: ' + templateFilename); var dts = fs.readFileSync(templateFilename, 'utf8'); dts = dts.replace(/!PIN_KEY!/g, pin.key); dts = dts.replace(/!PIN_DOT_KEY!/g, pin.key.replace(/_/, '.')); dts = dts.replace(/!PIN_FUNCTION!/g, pin.options[data & 7]); dts = dts.replace(/!PIN_OFFSET!/g, pin.muxRegOffset); dts = dts.replace(/!DATA!/g, '0x' + data.toString(16)); if (pin.pwm) { dts = dts.replace(/!PWM_MODULE!/g, pin.pwm.module); dts = dts.replace(/!PWM_INDEX!/g, pin.pwm.index); dts = dts.replace(/!DUTY_CYCLE!/g, 500000); } try { fs.writeFileSync(dtsFilename, dts, 'ascii'); } catch (ex) { resp.err = ex; } onDTSWrite(resp.err); } function onDTSWrite(err) { if (err) { resp.err = 'Error writing ' + dtsFilename + ': ' + err; if (debug) winston.debug(resp.err); if (callback) callback(resp); return (resp); } var command = 'dtc -O dtb -o ' + dtboFilename + ' -b 0 -@ ' + dtsFilename; try { child_process.execSync(command); } catch (ex) { resp.err = ex; } dtcHandler(resp.err); } function dtcHandler(error, stdout, stderr) { if (debug) winston.debug('dtcHandler: ' + JSON.stringify({ error: error, stdout: stdout, stderr: stderr })); if (!error) onDTBOExists(); } function onDTBOExists() { if (debug) winston.debug('onDTBOExists()'); if (load) load_dt(fragment, pin, resp); } if (callback) callback(resp); return (typeof resp.err == 'undefined'); }; var myeval = function (x) { winston.debug('myeval("' + x + '");'); var y; try { y = eval(x); } catch (ex) { y = undefined; winston.error('myeval error: ' + ex); throw ('myeval error: ' + ex); } winston.debug('result = ' + y); return (y); }; var getpin = function (pin) { if (typeof pin == 'object') return (pin); else { var pinObject = bone.getPinObject(pin); if (typeof pinObject != 'object') { throw ("Invalid pin: " + pin); } return (pinObject); } }; var wrapCall = function (m, func, funcArgs, cbArgs) { if (!m.module.exists) { if (debug) winston.debug(m.name + ' support module not loaded.'); return (function () {}); } funcArgs.unshift('port'); funcArgs.push('callback'); var newFunction = function () { var args = []; var port = arguments[0]; var callback = false; for (var i = 1; i < arguments.length; i++) { winston.debug('Adding argument ' + funcArgs[i] + ' to wrapper'); if (funcArgs[i] == 'callback') { callback = arguments[i]; var wrappedCallback = function () { var cbData = {}; for (var j = 0; j < cbArgs.length; j++) { cbData[cbArgs[j]] = arguments[j]; } cbData.event = 'callback'; winston.debug('cbData = ' + JSON.stringify(cbData)); callback(cbData); }; args.push(wrappedCallback); } else { args.push(arguments[i]); } } if (!m.openPorts[port]) { if (callback) callback({ 'err': m.name + ' ' + port + ' not opened' }); return (false); } winston.debug('Calling ' + m.name + '[' + port + '].' + func + '(' + args + ')'); var x = m.openPorts[port][func].apply( m.openPorts[port], args); if (callback) callback({ 'event': 'return', 'return': x }); return (x); }; newFunction.args = funcArgs; return (newFunction); }; var wrapOpen = function (m, openArgs) { if (!m.module.exists) { if (debug) winston.debug(m.name + ' support module not loaded.'); return (function () {}); } openArgs.unshift('port'); openArgs.push('callback'); var newFunction = function () { var args = {}; for (var i = 0; i < openArgs.length; i++) { args[openArgs[i]] = arguments[i]; } var port = args.port; var callback = args.callback; winston.debug(m.name + ' opened with ' + JSON.stringify(arguments)); if (m.ports[port] && m.ports[port].devicetree) { var fragment = m.ports[port].devicetree; if (!is_capemgr()) { if (callback) callback({ err: 'Kernel does not include CapeMgr module' }); return (false); } if (!load_dt(fragment)) { if (callback) callback({ 'err': 'Devicetree overlay fragment ' + fragment + ' not loaded' }); return (false); } } m.openPorts[port] = m.doOpen(args); if (!m.openPorts[port]) { if (callback) callback({ 'err': 'Unable to ' + m.name }); return (false); } for (var e in m.events) { var addHandler = function (m, port, e) { var handler = function () { var myargs = arguments; myargs.event = e; for (var i = 0; i < arguments.length; i++) { myargs[m.events[e][i]] = arguments[i]; } callback(myargs); }; m.openPorts[port].on(e, handler); }; addHandler(m, port, e); } if (callback) callback({ 'event': 'return', 'value': true }); return (true); }; newFunction.args = openArgs; return (newFunction); }; var pin_data = function (slew, direction, pullup, mux) { var pinData = 0; if (slew == 'slow') pinData |= 0x40; if (direction != g.OUTPUT) pinData |= 0x20; switch (pullup) { case 'disabled': pinData |= 0x08; break; case 'pullup': pinData |= 0x10; break; default: break; } pinData |= (mux & 0x07); return (pinData); }; // Inspired by // https://github.com/luciotato/waitfor/blob/master/waitfor.js // https://github.com/0ctave/node-sync/blob/master/lib/sync.js var wait_for = function (fn, myargs, result_name, no_error) { var fiber = fibers.current; var yielded = false; var args = []; var result; for (var i in fn.args) { if (fn.args[i] == 'callback') { args.push(myCallback); } else { args.push(myargs[i]); } } if (typeof fiber == 'undefined') { if (no_error) { // No callback required (fire and forget) fn.apply(this, args); } else { var stack = new Error().stack; var err = 'As of BoneScript 0.2.5, synchronous calls must be made\n' + 'within a fiber such as within loop() or setup():\n' + stack; winston.error(err); throw (err); } } else { fn.apply(this, args); if (!myCallback.called) { yielded = true; fibers.yield(); } } function myCallback(x) { if (debug) winston.debug('Callback: ' + fn.name + ' ' + x.err); if (myCallback.called) return; if (typeof result_name == 'undefined') { result = x; } else if (typeof x[result_name] != 'undefined') { result = x[result_name]; } if (typeof x.err != 'undefined' && x.err) { //var fn_name = fn.toString().substr('function '.length); //fn_name = fn_name.substr(0, fn_name.indexOf('(')); if (debug) winston.debug(fn.name + ' ' + x.err); } myCallback.called = true; if (typeof fiber == 'undefined' && no_error) return; if (yielded) fiber.run(); } return (result); }; module.exports = { require: myRequire, is_new_capemgr: is_new_capemgr, is_capemgr: is_capemgr, is_ocp: is_ocp, is_cape_universal: is_cape_universal, find_sysfsFile: find_sysfsFile, file_exists: file_exists, file_existsSync: file_existsSync, file_find: file_find, load_dt: load_dt, create_dt: create_dt, myeval: myeval, getpin: getpin, wrapCall: wrapCall, wrapOpen: wrapOpen, pin_data: pin_data, wait_for: wait_for } ================================================ FILE: src/parse.js ================================================ var winston = require('winston'); var debug = process.env.PARSE_DEBUG ? true : false; // This parses pinmux data from the register value var modeFromStatus = function (pinData, mode, isAI) { mode = mode || {}; mode.mux = isAI ? (pinData & 0x0f) : (pinData & 0x07); mode.slew = (isAI ? (pinData & (1 << 19)) : (pinData & (1 << 6))) ? 'slow' : 'fast'; mode.rx = (isAI ? (pinData & (1 << 18)) : (pinData & (1 << 5))) ? 'enabled' : 'disabled'; var pullup = isAI ? ((pinData & (3 << 16)) >> 16) : ((pinData & (3 << 3)) >> 3); switch (pullup) { case 1: mode.pullup = 'disabled'; break; case 2: mode.pullup = 'pullup'; break; case 0: mode.pullup = 'pulldown'; break; default: winston.error('Unknown pullup value: ' + pullup); } return (mode); }; var modeFromOmapMux = function (readout, mode) { if (debug) winston.debug('' + readout); mode = mode || {}; // The format read from debugfs looks like this: // name: mcasp0_axr0.spi1_d1 (0x44e10998/0x998 = 0x0023), b NA, t NA // mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE3 // signals: mcasp0_axr0 | ehrpwm0_tripzone | NA | spi1_d1 | mmc2_sdcd_mux1 | NA | NA | gpio3_16 var breakdown = ''; try { breakdown = readout.split('\n'); } catch (ex) { winston.info('Unable to parse mux readout "' + readout + '": ' + ex); return (mode); } try { // Parse the muxmode number, '3' in the above example mode.mux = breakdown[1].split('|')[1].substr(-1); // Parse the mux register value, '0x0023' in the above example var pinData = parseInt(breakdown[0].split('=')[1].substr(1, 6), 16); if (debug) winston.debug('pinData = ' + pinData); mode = modeFromStatus(pinData, mode); } catch (ex2) { winston.info('Unable to parse mux mode "' + breakdown + '": ' + ex2); } try { mode.options = breakdown[2].split('|'); for (var option in mode.options) { var x = '' + mode.options[option]; try { mode.options[option] = x.replace(/ /g, '').replace('signals:', ''); } catch (ex) { winston.info('Unable to parse option "' + x + '": ' + ex); mode.options[option] = 'NA'; } } } catch (ex3) { winston.info('Unable to parse options "' + breakdown + '": ' + ex3); mode.options = null; } return (mode); }; var modeFromPinctrl = function (pins, muxRegOffset, muxBase, mode, isAI) { if (debug) winston.debug('' + pins); muxBase = muxBase || 0x44e10800; mode = mode || {}; // The format read from debugfs looks like this: // registered pins: 142 // ... // pin 108 (44e109b0) 00000027 pinctrl-single // ... // // new format is: // registered pins: 142 // ... // pin 0 (PIN0) 44e10800 00000027 pinctrl-single // ... // var pinLines = pins.split('\n'); var numRegistered = pinLines[0].replace(/registered pins: (\d+)/, "$1"); var pattern = /pin (\d+) (\(PIN\d+\))? \(?([0-9a-f\.]+)\(? ([0-9a-f]+) pinctrl-single/; var muxAddress = muxBase + muxRegOffset; for (var i = 0; i < numRegistered; i++) { if (debug) winston.debug('pinLine = ' + pinLines[i + 1]); var parsedFields = pattern.exec(pinLines[i + 1]); if (debug) winston.debug('parsedFields = ' + parsedFields); //var index = parseInt(parsedFields[1], 10); var address = parseInt(parsedFields[3], 16); var status = parseInt(parsedFields[4], 16); if (address == muxAddress) { mode = modeFromStatus(status, mode, isAI); return (mode); } } //winston.error('Did not find status at ' + muxAddress); return (mode); }; module.exports = { modeFromStatus: modeFromStatus, modeFromOmapMux: modeFromOmapMux, modeFromPinctrl: modeFromPinctrl } ================================================ FILE: src/rc.js ================================================ // Copyright (C) 2017 - Texas Instruments, Jason Kridner var my = require('./my'); var rc = my.require('roboticscape'); if (rc.exists) { var rcInitialize = function (callback) { var i = rc.initialize(); var x = {}; if (i) { x.error = i; } if (callback) callback(x); return (i); }; rcInitialize.args = ['callback']; var rcState = function (state, callback) { var x = {}; if (state) { rc.state(state); } else { state = rc.state(); } x.state = state; if (callback) callback(x); return (state); }; rcState.args = ['state', 'callback']; var rcLED = function (led, value, callback) { if (typeof value !== 'undefined') { rc.led(led, value); } if (callback) callback(); }; rcLED.args = ['led', 'value', 'callback']; var rcOn = function (event, callback) { function myCallback() { callback({ 'event': event }); } rc.on(event, myCallback); }; rcOn.args = ['event', 'callback']; var rcMotor = function (motor, value, callback) { if (typeof value !== 'undefined') { rc.motor(motor, value); } else { rc.motor(motor); } if (callback) callback(); }; rcMotor.args = ['motor', 'value', 'callback']; var rcServo = function (option, value, callback) { if (typeof value !== 'undefined') { rc.servo(option, value); } else { rc.servo(option); } if (callback) callback(); }; rcServo.args = ['option', 'value', 'callback']; var rcBMP = function (option, callback) { var value if (typeof option !== 'undefined') { value = rc.bmp(option); } if (callback) callback(null, value); else return value; }; rcBMP.args = ['option', 'callback']; var rcIMU = function (option, callback) { var value if (typeof option !== 'undefined') { value = rc.imu(option); } if (callback) callback(null, value); else return value; }; rcIMU.args = ['option', 'callback']; var rcEncoder = function (encoder, value, callback) { var x = {}; x.encoder = encoder; var i; if (typeof value !== 'undefined') { i = rc.encoder(encoder, value); } else { i = rc.encoder(encoder); x.value = i; } if (callback) callback(x); }; rcEncoder.args = ['encoder', 'value', 'callback']; module.exports = { rcInitialize: rcInitialize, rcState: rcState, rcLED: rcLED, rcOn: rcOn, rcMotor: rcMotor, rcServo: rcServo, rcBMP: rcBMP, rcIMU: rcIMU, rcEncoder: rcEncoder }; } ================================================ FILE: src/serial.js ================================================ // Copyright (C) 2013 - Texas Instruments, Jason Kridner var bone = require('./bone'); var my = require('./my'); var m = {}; m.name = 'serialport'; m.module = my.require('serialport'); m.ports = bone.uarts; m.events = { 'open': [], 'data': ['data'] }; m.openPorts = {}; m.doOpen = function (args) { var path = args.port; if (m.ports[args.port].path) path = m.ports[args.port].path; var openPort = new m.module.SerialPort(path, args.options); return (openPort); }; module.exports = { serialOpen: my.wrapOpen(m, ['options']), serialWrite: my.wrapCall(m, 'write', ['data'], ['err', 'results']), serialParsers: m.module.exists ? m.module.parsers : {} } ================================================ FILE: src/server.js ================================================ // Copyright (C) 2011 - Texas Instruments, Jason Kridner // // var fs = require('fs'); var http = require('http'); var events = require('events'); var crypto = require('crypto'); var my = require('./my'); var winston = my.require('winston'); var express = my.require('express'); var socketHandlers = my.require('./socket_handlers'); var serverEmitter = new events.EventEmitter(); var debug = process.env.DEBUG ? true : false; var systemd = my.require('systemd'); if (!systemd.exists) { if (debug) winston.debug("Startup as socket-activated service under systemd not enabled"); } var serverStart = function (port, directory, passphrase, callback) { if (port === undefined) { port = (process.env.LISTEN_PID > 0) ? 'systemd' : ((process.env.PORT) ? process.env.PORT : 80); } if (directory === undefined) { directory = (process.env.SERVER_DIR) ? process.env.SERVER_DIR : '/usr/share/bone101'; } var passphrase_hash; if (passphrase) { if (passphrase.hash) //whether passphrase supplied as hash/text passphrase_hash = passphrase.data; else passphrase_hash = crypto.createHash('sha256').update(passphrase.data).digest("hex"); //generate hash } var server = mylisten(port, directory, passphrase_hash); serverEmitter.on('newListner', addServerListener); function addServerListener(event, listener) { console.log('got here'); //TODO: not getting here if (debug) winston.debug('Got request to add listener to ' + event); var serverEvent = event.replace(/^server\$/, ''); if (serverEvent) { if (debug) winston.debug('Adding listener to server$' + serverEvent); server.on(serverEvent, listener); } } if (callback) { callback({ server: server, serverEmitter: serverEmitter }); } return (serverEmitter); }; function mylisten(port, directory, passphrase_hash) { winston.info("Opening port " + port + " to serve up " + directory); var app = express(); app.get('/bonescript.js', socketHandlers.socketJSReqHandler); app.use('/bone101', express.static(directory)); app.use('/bone101/static', express.static(directory + "/static")); app.use(express.static(directory)); var server = http.createServer(app); socketHandlers.addSocketListeners(server, serverEmitter, passphrase_hash); server.listen(port); return (server); } module.exports = { serverStart: serverStart } ================================================ FILE: src/socket_handlers.js ================================================ // Copyright (C) 2011 - Texas Instruments, Jason Kridner // // var b = require('../main'); var fs = require('fs'); var url = require('url'); var child_process = require('child_process'); var my = require('./my'); var winston = my.require('winston'); var socketio = my.require('socket.io'); var debug = process.env.DEBUG ? true : false; var socketJSReqHandler = function (req, res) { function sendFile(err, file) { if (err) { res.writeHead(500, { "Content-Type": "text/plain" }); res.end(err + '\n'); return; } res.setHeader('Content-Type', 'text/javascript'); file = file.replace(/___INSERT_HOST___/g, host); res.end(file); } var parsedUrl = url.parse(req.url); var uri = parsedUrl.pathname; var host = 'http://' + req.headers.host; if (uri == '/bonescript.js') { var filename = __dirname + '/bonescript.js'; if (debug) winston.debug('filename = ' + filename) fs.readFile(filename, 'utf8', sendFile); } } var addSocketListeners = function (server, serverEmitter, passphrase_hash) { var io = socketio(server); if (passphrase_hash) { //attach middleware to handle authentication io.use(function (socket, next) { socket.auth = false; //consider the all sockets initially as unauthorized if (socket.handshake.headers.authorization) { if (socket.handshake.headers.authorization == passphrase_hash) { socket.auth = true; //authorize the socket next(); } else next(new Error("Authentication Failed : incorrect passphrase !!")); } else { next(new Error("Authentication data not send !!")); } }); } if (debug) winston.debug('Listening for new socket.io clients'); io.on('connection', function (socket) { if (socket.auth || !passphrase_hash) onconnect(socket); else socket.disconnect('unauthorized'); }); function onconnect(socket) { winston.debug('Client connected'); serverEmitter.emit('socket$connect', socket); // on disconnect socket.on('disconnect', function () { if (debug) winston.debug('Client disconnected'); serverEmitter.emit('socket$disconnect'); }); socket.on('message', serverMessage); spawn(socket); var modmsg = {}; modmsg.module = 'bonescript'; modmsg.data = {}; var callMyFunc = function (name, m) { var myCallback = function (resp) { if (debug) winston.debug(name + ' replied to ' + JSON.stringify(m) + ' with ' + JSON.stringify(resp)); if (typeof m.seq == 'undefined') return; if (!resp || (typeof resp != 'object')) resp = { 'data': resp }; resp.seq = m.seq; // TODO: consider setting 'oneshot' if (debug) winston.debug('Sending message "bonescript": ' + JSON.stringify(resp)); socket.emit('bonescript', resp); }; var myCallback_nodestyle = function (err, resp) { if (debug) winston.debug(name + ' replied to ' + JSON.stringify(m) + ' with ' + JSON.stringify(resp)); if (typeof m.seq == 'undefined') return; // TODO: consider setting 'oneshot' if (debug) winston.debug('Sending message "bonescript": ' + JSON.stringify(resp)); socket.emit('bonescript', { err: err, resp: resp, seq: m.seq }); }; try { var callargs = []; for (var arg in b[name].args) { var argname = b[name].args[arg]; if (argname == 'callback') { if (typeof m.seq == 'number') { if (m.length == 1) callargs.push(myCallback); else callargs.push(myCallback_nodestyle); } else callargs.push(null); } else if (typeof m[argname] != 'undefined') { callargs.push(m[argname]); } else { callargs.push(undefined); } } if (debug) winston.debug('Calling ' + name + '(' + callargs.join(',') + ')'); b[name].apply(this, callargs); } catch (ex) { if (debug) winston.debug('Error handing ' + name + ' message: ' + ex); if (debug) winston.debug('m = ' + JSON.stringify(m)); } }; var addSocketX = function (message, name) { var onFuncMessage = function (m) { callMyFunc(name, m); }; socket.on(message, onFuncMessage); }; var b = require('../main'); for (var i in b) { if (typeof b[i] == 'function') { if (typeof b[i].args != 'undefined') { modmsg.data[i] = {}; modmsg.data[i].name = i; modmsg.data[i].type = 'function'; modmsg.data[i].value = b[i].args; addSocketX('bonescript$' + i, i); } } else { modmsg.data[i] = {}; modmsg.data[i].name = i; modmsg.data[i].type = typeof b[i]; modmsg.data[i].value = b[i]; } } socket.emit('require', modmsg); } function serverMessage(message) { serverEmitter.emit('message', message); } return (io); } // most heavily borrowed from https://github.com/itchyny/browsershell function spawn(socket) { var stream = ''; var timer; var len = 0; var c; socket.on('shell', receive); return (receive); function receive(msg) { if (!c) { try { if (debug) winston.debug('Spawning bash'); c = child_process.spawn('/bin/bash', ['-i'], { customFds: [-1, -1, -1] }); c.stdout.on('data', send); c.stderr.on('data', send); c.on('exit', function () { socket.emit('shell', send('\nexited\n')); c = undefined; }); socket.on('disconnect', function () { if (debug) winston.debug('Killing bash'); c.kill('SIGHUP'); }); } catch (ex) { c = undefined; send('Error invoking bash'); winston.error('Error invoking bash'); } } if (c) { if (msg) { c.stdin.write(msg + '\n', 'utf-8'); } } else { winston.error('Unable to invoke child process'); } } function send(data) { // add data to the stream stream += data.toString(); ++len; // clear any existing timeout if it exists if (timer) clearTimeout(timer); // set new timeout timer = setTimeout(function () { socket.emit('shell', stream); stream = ''; len = 0; }, 100); // send data if over threshold if (len > 1000) { clearTimeout(timer); socket.emit('shell', stream); stream = ''; len = 0; } } } module.exports = { socketJSReqHandler: socketJSReqHandler, addSocketListeners: addSocketListeners } ================================================ FILE: systemd/bonescript-autorun.service ================================================ [Unit] Description=Bonescript autorun ConditionPathExists=|/var/lib/cloud9 [Service] WorkingDirectory=/usr/lib/node_modules/bonescript EnvironmentFile=/etc/default/node ExecStart=/usr/bin/node autorun.js SyslogIdentifier=bonescript-autorun [Install] WantedBy=multi-user.target ================================================ FILE: systemd/bonescript.service ================================================ [Unit] Description=Bonescript server ConditionPathExists=|/usr/share/bone101 [Service] WorkingDirectory=/usr/share/bone101 EnvironmentFile=/etc/default/node ExecStart=npm start -g bonescript SyslogIdentifier=bonescript [Install] WantedBy=multi-user.target ================================================ FILE: systemd/bonescript.socket ================================================ [Socket] ListenStream=80 [Install] WantedBy=sockets.target ================================================ FILE: test/TODO/bacon_test.js ================================================ /* * Setup */ var b = require("bonescript"); // Read BoneScript library // Map used pins var LED_RED = "P9_42"; var LED_BLUE = "P9_16"; var LED_GREEN = "P9_14"; var BUTTON = "P8_19"; var S_DATA = "P9_18"; var S_CLOCK = "P9_22"; var S_LATCH = "P9_17"; var S_CLEAR = "P9_15"; var POT = 'P9_36'; // Define global variables var state = false; var segments = [ 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90 ]; var port = '/dev/i2c-2'; var address = 0x1c; // Configure pins b.pinMode(LED_RED, b.OUTPUT); b.pinMode(LED_BLUE, b.OUTPUT); b.pinMode(BUTTON, b.INPUT); b.pinMode(S_DATA, b.OUTPUT); b.pinMode(S_CLOCK, b.OUTPUT); b.pinMode(S_LATCH, b.OUTPUT); b.pinMode(S_CLEAR, b.OUTPUT); // Initial pin states b.digitalWrite(S_DATA, b.LOW); b.digitalWrite(S_CLOCK, b.LOW); b.digitalWrite(S_LATCH, b.LOW); b.digitalWrite(S_CLEAR, b.HIGH); // Configure accelerometer b.i2cOpen(port, address, {}, onI2C); // Open I2C port b.i2cWriteBytes(port, 0x2a, [0x00]); // Set accelerometer in STANDBY mode b.i2cWriteBytes(port, 0x0e, [0x00]); // Set accelerometer scale to 2G b.i2cWriteBytes(port, 0x2a, [0x01]); // Set accelerometer in ACTIVE mode /* * Add handlers */ blink(); // Call blink() to start it iterating setInterval(readButton, 100); // Call readButton() every 100ms setInterval(update7Seg, 100); // Call update7Seg() every 100ms setInterval(readAccel, 200); // Call readAccel() every 200ms /* * Define functions */ function blink() { state = !state; if(state) setTimeout(blink, 10); // Leave LED on for 10ms if(!state) setTimeout(blink, 990); // Leave LED off for 990ms b.digitalWrite(LED_RED, state ? b.HIGH : b.LOW); } function readButton() { // Read BUTTON status var status = b.digitalRead(BUTTON, onDigitalRead); } function onDigitalRead(x) { if(x.err) return; var status = x.value; // Set LED_BLUE to HIGH if BUTTON is LOW b.digitalWrite(LED_BLUE, status ? b.LOW : b.HIGH); } function update7Seg() { // Read the voltage from potentiometer b.analogRead(POT, onAnalogRead); } function onAnalogRead(x) { if(x.err) return; var value = x.value; // Convert floating point value 0-1 to digit 0-9 var digit = parseInt(value*10, 10) % 10; // Shift out the character LED pattern b.shiftOut(S_DATA, S_CLOCK, b.MSBFIRST, segments[digit]); b.digitalWrite(S_LATCH, b.HIGH); b.digitalWrite(S_LATCH, b.LOW); } function onI2C() { } function readAccel() { b.i2cReadBytes(port, 1, 6, onReadBytes); } function onReadBytes(x) { if(x.event == 'callback') { var X = convertToG(x.res[0]); // First byte is X var brightness = Math.abs(X); if(brightness > 1) brightness = 1; b.analogWrite(LED_GREEN, brightness); } } function convertToG(x) { if(x >= 128) x = -((x^0xFF)+1); // Get two's complement x = x / 64; // Scale to G x = x.toFixed(2); // Limit decimal places return(x); } ================================================ FILE: test/TODO/basic_sanity.sh ================================================ #!/bin/sh cd $(dirname $0) node -pe "'Name: ' + require('../index').getPlatform().name" node -pe "'Version: ' + require('../index').getPlatform().bonescript" node -pe "require('../index').digitalRead('P8_19')" ================================================ FILE: test/TODO/constants.js ================================================ // Copyright (C) 2013 - Texas Instruments, Jason Kridner exports.OUTPUT = "out"; exports.INPUT = "in"; exports.INPUT_PULLUP = "in_pullup"; exports.HIGH = 1; exports.LOW = 0; exports.LSBFIRST = 1; // used in: shiftOut(dataPin, clockPin, bitOrder, val) exports.MSBFIRST = 0; exports.CHANGE = "both"; exports.RISING = "rising"; exports.FALLING = "falling"; ================================================ FILE: test/TODO/eeprom.js ================================================ // test process: // $ node eeprom.js // $ node eeprom.js -w test-eeproms.json // $ echo "a18bf9b65d676cd0a6e07b13fa06a362 test-cape.eeprom" | md5sum -c // $ node eeprom.js -rmy-eeproms.json cape:test-cape.eeprom // $ node eeprom.js -r cape:test-cape.eeprom verify-eeproms.json // $ diff my-eeproms.json verify-eeproms.json // $ node eeprom.js -wmy-eeproms.json test-cape.eeprom verify-cape.eeprom // $ echo "a18bf9b65d676cd0a6e07b13fa06a362 verify-cape.eeprom" | md5sum -c var printUsage = function() { var usageString = 'Print usage:\n' + '\n' + ' node bonescript/eeprom.js -h\n' + '\n' + '\n' + 'Read eeproms and write the output to a JSON-compatible file:\n' + '\n' + ' node bonescript/eeprom.js [-r [type:source.eeprom ...] destination.json] \n' + '\n' + ' type : the word "bone" or "cape"\n' + ' source.eeprom : source eeprom file\n' + '\n' + '\n' + 'Read JSON eeproms file and write the output to eeprom(s):\n' + '\n' + ' node bonescript/eeprom.js -w source.json [[source-eeprom] destination.eeprom]\n' + '\n' + ' source.json : source JSON file containing one or more eeprom structures\n' + ' destination.eeprom : where to write the output,\n' + ' must either match eeprom structure name or\n' + ' provide a source-eeprom parameter\n' + ' source-eeprom : which eeprom structure to use as source\n'; winston.error(usageString); }; // Only run this section when run as a stand-alone application if(!module.parent) { var eeproms = {}; var destinationJSON = ''; process.argv.shift(); process.argv.shift(); if((process.argv.length > 0) && (process.argv[0].match(/^-w/i))) { // Write EEPROMs var sourceJSON = process.argv.shift().substr(2); var sourceEeprom = ''; var destinationEeprom = ''; if(sourceJSON === '') { sourceJSON = process.argv.shift(); } if(process.argv.length > 2) { printUsage(); throw('Too many arguments'); } else if(process.argv.length > 0) { sourceEeprom = destinationEeprom = process.argv.pop(); if(process.argv.length > 0) { sourceEeprom = process.argv.pop(); } } try { winston.info('Reading '+sourceJSON); var jsonFile = fs.readFileSync(sourceJSON, 'ascii'); winston.info('Parsing '+sourceJSON); if(debug) winston.info(jsonFile); eeproms = JSON.parse(jsonFile); } catch(ex) { throw('Unable to parse '+sourceJSON+': '+ex); } // If source file isn't nested, make it if(eeproms.type) { if(destinationEeprom === '') { printUsage(); throw('Destination must be specified if not part of the JSON file'); } eeproms[destinationEeprom] = eeproms; } for(var x in eeproms) { if((sourceEeprom === '') || (x == sourceEeprom)) { winston.info('Writing eeprom '+x); if(eeproms[x].type != 'cape') { throw('Only type "cape" is currently handled'); } fillCapeEepromData(eeproms[x]); if(debug) winston.debug(util.inspect(eepromData, true, null)); if(destinationEeprom === '') { fs.writeFileSync(x, eepromData); } else { winston.info('Writing to file '+destinationEeprom); fs.writeFileSync(destinationEeprom, eepromData); } } else { winston.info('Skipping eeprom '+x); } } } else if(process.argv.length === 0 || ((process.argv.length > 0) && (process.argv[0].match(/^-r/i)))) { // Read EEPROMs var eepromsToRead = defaultEepromFiles; if(process.argv.length > 0) { destinationJSON = process.argv.shift().substr(2); if(destinationJSON === '') { destinationJSON = process.argv.pop(); } } if(process.argv.length > 0) { eepromsToRead = {}; while(process.argv.length > 0) { var eepromFile = process.argv.shift().split(':'); if(eepromFile.length != 2) { printUsage(); throw('Source eeproms must be of the format :'); } eepromsToRead[eepromFile[1]] = { type: eepromFile[2] }; } } eeproms = readEeproms(eepromsToRead); if(eeproms == {}) { winston.info('No valid EEPROM contents found'); } else { var eepromsString = JSON.stringify(eeproms, null, 2); if(destinationJSON === '') { console.log(eepromsString); } else { winston.info('Writing JSON file to '+destinationJSON); fs.writeFileSync(destinationJSON, eepromsString); } } } else { printUsage(); return(0); } } ================================================ FILE: test/TODO/fix-ssh.js ================================================ var b = require('bonescript'); b.getPlatform(onGetPlatform); function onGetPlatform(x) { if(!x.name || !x.serialNumber || !x.version) err('getPlatform returned ' + JSON.stringify(x)); console.log('Name = ' + x.name); console.log('S/N = ' + x.serialNumber); console.log('Version = ' + x.version); console.log('BoneScript version = ' + x.bonescript); b.setDate(Date().toString(), onSetDate); } function onSetDate(x) { b.socket.on('shell', onShell); b.socket.emit('shell', '\n'); b.socket.emit('shell', 'rm /etc/dropbear/dropbear_rsa_host_key\n'); //b.socket.emit('shell', 'systemctl --system daemon-reload\n'); b.socket.emit('shell', 'systemctl stop dropbear.socket\n'); b.socket.emit('shell', '/etc/init.d/dropbear stop\n'); b.socket.emit('shell', '/etc/init.d/dropbear start\n'); //b.socket.emit('shell', 'systemctl status dropbear.socket\n'); b.socket.emit('shell', 'journalctl -f\n'); setTimeout(complete, 10000); //complete(); } function onShell(x) { console.log('shell: ' + x); //if(x.indexOf('Listening on dropbear.socket') >= 0) //complete(); } function complete() { console.log('***PASS***'); process.exit(0); } function err(x) { console.log('***FAIL*** ' + x); throw(x); } function printJSON(x) { console.log('x = ' + JSON.stringify(x)); } ================================================ FILE: test/TODO/fix-ssh.sh ================================================ #!/bin/sh set -x set -e node remote_bonetest.js fix-ssh.js ================================================ FILE: test/TODO/gitconfig ================================================ [receive] denyCurrentBranch = warn ================================================ FILE: test/TODO/remote_bonetest.js ================================================ var io = require('../node_modules/socket.io/node_modules/socket.io-client'); var fs = require('fs'); var clientName = process.env.TARGET_NAME || 'http://192.168.7.2:80'; if(process.argv.length != 3) { console.log('Usage: node ' + process.argv[1] + ' '); process.exit(-1); } var _bonescript = {}; _bonescript.modules = {}; _bonescript._callbacks = {}; _bonescript._seqnum = 0; _bonescript.on = {}; _bonescript.on.connect = function(){ console.log('socket.io: connect'); }; _bonescript.on.connecting = function(){ console.log('socket.io: connecting'); }; _bonescript.on.disconnect = function(){ console.log('socket.io: disconnect'); }; _bonescript.on.connect_failed = function(){ console.log('socket.io: connect_failed'); }; _bonescript.on.error = function(){ console.log('socket.io: error'); }; _bonescript.on.reconnect = function(){ console.log('socket.io: reconnect'); }; _bonescript.on.reconnect_failed = function(){ console.log('socket.io: reconnect_failed'); }; _bonescript.on.reconnecting = function(){ console.log('socket.io: reconnecting'); }; _bonescript.on.initialized = function(){ console.log('socket.io: initialized'); }; function _onSocketIOLoaded() { console.log("socket.io loaded"); var socket = io.connect(clientName); socket.on('require', getRequireData); socket.on('bonescript', _seqcall); socket.on('connect', _bonescript.on.connect); socket.on('connecting', _bonescript.on.connecting); socket.on('disconnect', _bonescript.on.disconnect); socket.on('connect_failed', _bonescript.on.connect_failed); socket.on('error', _bonescript.on.error); socket.on('reconnect', _bonescript.on.reconnect); socket.on('reconnect_failed', _bonescript.on.reconnect_failed); socket.on('reconnecting', _bonescript.on.reconnecting); socket.on('initialized', _bonescript.on.initialized); function getRequireData(m) { if(!m.module || !m.data) throw('Invalid "require" message sent for "' + m.module + '"'); console.log('Initialized module: ' + m.module); _bonescript.modules[m.module] = {}; for(var x in m.data) { if(!m.data[x].type || !m.data[x].name || (typeof m.data[x].value == 'undefined')) throw('Invalid data in "require" message sent for "' + m.module + '.' + m.data[x] + '"'); if(m.data[x].type == 'function') { // define the function if(!m.data[x].value) throw('Missing args in "require" message sent for "' + m.module + '.' + m.data[x] + '"'); var myargs = m.data[x].value; // eval of objString builds the call data out of arguments passed in var objString = ''; for(var y in myargs) { if(isNaN(y)) continue; // Need to find the source of this bug if(myargs[y] == 'callback') continue; objString += ' if(typeof ' + myargs[y] + ' == "function") {\n'; objString += ' ' + myargs[y] + ' = ' + myargs[y] + '.toString();\n'; objString += ' }\n'; objString += ' calldata.' + myargs[y] + ' = ' + myargs[y] + ';\n'; } var argsString = myargs.join(', '); var handyfunc = '_bonescript.modules["' + m.module + '"].' + m.data[x].name + ' = ' + 'function (' + argsString + ') {\n' + ' var calldata = {};\n' + objString + ' if(callback) {\n' + ' _bonescript._callbacks[_bonescript._seqnum] = callback;\n' + ' calldata.seq = _bonescript._seqnum;\n' + ' _bonescript._seqnum++;\n' + ' }\n' + ' socket.emit("' + m.module + '$' + m.data[x].name + '", calldata);\n' + '};\n'; eval(handyfunc); } else { _bonescript.modules[m.module][m.data[x].name] = m.data[x].value; } } _bonescript.modules[m.module].socket = socket; _bonescript.on.initialized(); } } function _seqcall(data) { if((typeof data.seq != 'number') || (typeof _bonescript._callbacks[data.seq] != 'function')) throw "Invalid callback message received: " + JSON.stringify(data); _bonescript._callbacks[data.seq](data); if(data.oneshot) delete _bonescript._callbacks[data.seq]; } // Require must be synchronous to be able to return data structures and // functions and therefore cannot call socket.io. All exported modules must // be exported ahead of time. var require = function(module) { if(typeof _bonescript.modules[module] == 'undefined') throw 'Module "' + module + '" is not currently available'; return(_bonescript.modules[module]); }; var test = function() { try { console.log('Loading ' + process.argv[2]); var script = fs.readFileSync(process.argv[2], 'ascii'); //console.log('Executing: ' + script); eval(script); } catch(ex) { console.log('***FAIL*** ' + ex); process.exit(-2); } }; _bonescript.on.initialized = test; _onSocketIOLoaded(); ================================================ FILE: test/TODO/setdate.js ================================================ var b = require('bonescript'); b.getPlatform(onGetPlatform); function onGetPlatform(x) { if(!x.name || !x.serialNumber || !x.version) err('getPlatform returned ' + JSON.stringify(x)); console.log('Name = ' + x.name); console.log('S/N = ' + x.serialNumber); console.log('Version = ' + x.version); console.log('BoneScript version = ' + x.bonescript); b.setDate(Date().toString(), onSetDate); } function onSetDate(x) { complete(); } function complete() { console.log('***PASS***'); process.exit(0); } function err(x) { console.log('***FAIL*** ' + x); throw(x); } function printJSON(x) { console.log('x = ' + JSON.stringify(x)); } ================================================ FILE: test/TODO/test-analogwrite.js ================================================ var b = require('bonescript'); b.analogWrite('P9_16', 0.01); ================================================ FILE: test/TODO/test-digitalread.js ================================================ var b = require('bonescript'); b.pinMode('P8_19', b.INPUT, undefined, undefined, undefined, doRead); function doRead() { b.digitalRead('P8_19', function(x) { console.log(JSON.stringify(x)); }); } ================================================ FILE: test/TODO/test-digitalwrite.js ================================================ var b = require('bonescript'); b.pinMode('P9_16', b.ANALOG_OUTPUT); global.setup = function() { b.analogWrite('P9_14', 0.2); b.pinMode('P9_14', b.OUTPUT); b.digitalWrite('P9_14', false); b.digitalWrite('P9_14', true); console.log(JSON.stringify(b.getPinMode('P9_16'))); b.pinMode('P9_16', b.OUTPUT); console.log(JSON.stringify(b.getPinMode('P9_16'))); b.digitalWrite('P9_16', false); console.log(JSON.stringify(b.getPinMode('P9_16'))); b.digitalWrite('P9_16', true); console.log(JSON.stringify(b.getPinMode('P9_16'))); }; ================================================ FILE: test/TODO/test-eeproms.json ================================================ { "test-lcd7-cape.eeprom": { "type": "cape", "header": "aa5533ee", "formatRev": "A0", "boardName": "BeagleBone LCD Cape", "version": "01", "manufacturer": "BeagleBoardToys", "partNumber": "BB-BONE-LCD7-01", "numPins": 30, "serialNumber": "52114P130000", "currentVDD_3V3EXP": 2, "currentVDD_5V": 2, "currentSYS_5V": 2, "DCSupplied": 2000, "mux": { "P8_20": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_31" }, "P8_27": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_vsync" }, "P8_28": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_pclk" }, "P8_29": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_hsync" }, "P8_30": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_ac_bias_en" }, "P8_31": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data14" }, "P8_32": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data15" }, "P8_33": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data13" }, "P8_34": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data11" }, "P8_35": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data12" }, "P8_36": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data10" }, "P8_37": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data8" }, "P8_38": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data9" }, "P8_39": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data6" }, "P8_40": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data7" }, "P8_41": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data4" }, "P8_42": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data5" }, "P8_43": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data2" }, "P8_44": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data3" }, "P8_45": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data0" }, "P8_46": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data1" }, "P9_14": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 6, "function": "ehrpwm1a" }, "P9_15": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_16" }, "P9_16": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_19" }, "P9_23": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_17" }, "P9_37": { "used": "used", "function": "ain2" }, "P9_38": { "used": "used", "function": "ain3" }, "P9_39": { "used": "used", "function": "ain0" }, "P9_40": { "used": "used", "function": "ain1" }, "P9_42": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio0_7" } } } , "test-lcd35-cape.eeprom": { "type": "cape", "header": "aa5533ee", "formatRev": "A0", "boardName": "BeagleBone LCD Cape", "version": "01", "manufacturer": "BeagleBoardToys", "partNumber": "BB-BONE-LCD3-01", "numPins": 30, "serialNumber": "08124P130000", "currentVDD_3V3EXP": 2, "currentVDD_5V": 2, "currentSYS_5V": 2, "DCSupplied": 0, "mux": { "P8_20": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_31" }, "P8_27": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_vsync" }, "P8_28": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_pclk" }, "P8_29": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_hsync" }, "P8_30": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_ac_bias_en" }, "P8_31": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data14" }, "P8_32": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data15" }, "P8_33": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data13" }, "P8_34": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data11" }, "P8_35": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data12" }, "P8_36": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data10" }, "P8_37": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data8" }, "P8_38": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data9" }, "P8_39": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data6" }, "P8_40": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data7" }, "P8_41": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data4" }, "P8_42": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data5" }, "P8_43": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data2" }, "P8_44": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data3" }, "P8_45": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data0" }, "P8_46": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data1" }, "P9_14": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 6, "function": "ehrpwm1a" }, "P9_15": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_16" }, "P9_16": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_19" }, "P9_23": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio1_17" }, "P9_37": { "used": "used", "function": "ain2" }, "P9_38": { "used": "used", "function": "ain3" }, "P9_39": { "used": "used", "function": "ain0" }, "P9_40": { "used": "used", "function": "ain1" }, "P9_42": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio0_7" } } } , "test-dvi-cape.eeprom": { "type": "cape", "header": "aa5533ee", "formatRev": "A0", "boardName": "BeagleBone DVI-D CAPE", "version": "01", "manufacturer": "Beagleboardtoys", "partNumber": "BB-BONE-DVID-01", "numPins": 25, "serialNumber": "WWYYDVIDnnnn", "currentVDD_3V3EXP": 2, "currentVDD_5V": 2, "currentSYS_5V": 2, "DCSupplied": 0, "mux": { "P8_27": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_vsync" }, "P8_28": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_pclk" }, "P8_29": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_hsync" }, "P8_30": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_ac_bias_en" }, "P8_31": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data14" }, "P8_32": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data15" }, "P8_33": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data13" }, "P8_34": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data11" }, "P8_35": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data12" }, "P8_36": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data10" }, "P8_37": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data8" }, "P8_38": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data9" }, "P8_39": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data6" }, "P8_40": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data7" }, "P8_41": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data4" }, "P8_42": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data5" }, "P8_43": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data2" }, "P8_44": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data3" }, "P8_45": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data0" }, "P8_46": { "used": "used", "direction": "out", "pullup": "disabled", "mode": 0, "function": "lcd_data1" } } }, "TowerTech-TT3201-CAN-Cape.eeprom": { "type": "cape", "header": "aa5533ee", "formatRev": "A0", "boardName": "TT3201 CAN Cape", "version": "01", "manufacturer": "TowerTech", "partNumber": "TT3201-001", "numPins": 30, "serialNumber": "12050100002", "currentVDD_3V3EXP": 1, "currentVDD_5V": 0, "currentSYS_5V": 0, "DCSupplied": 0, "mux": { "P9_26": { "used": "used", "direction": "out", "pullup": "pulldown", "mode": 2, "function": "d_can1_tx" }, "P9_24": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 2, "function": "d_can1_rx" }, "P9_27": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio3_19" }, "P9_25": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 7, "function": "gpio3_21" }, "P9_42": { "used": "used", "direction": "out", "rx": "enabled", "pullup": "pullup", "mode": 2, "function": "spi1_cs1" }, "P9_28": { "used": "used", "direction": "out", "rx": "enabled", "pullup": "pullup", "mode": 3, "function": "spi1_cs0" }, "P9_31": { "used": "used", "direction": "out", "rx": "enabled", "pullup": "pullup", "mode": 3, "function": "spi1_sclk" }, "P9_29": { "used": "used", "direction": "out", "rx": "enabled", "pullup": "pullup", "mode": 3, "function": "spi1_d0" }, "P9_30": { "used": "used", "direction": "in", "rx": "enabled", "pullup": "pullup", "mode": 3, "function": "spi1_d1" } } } } ================================================ FILE: test/TODO/test-getpinmode.js ================================================ var b = require('bonescript'); var fs = require('fs'); var my = require('../src/my.js'); global.setup = function() { var capemgr = my.is_capemgr(); var slots = fs.readFileSync(capemgr + '/slots', 'ascii'); console.log(slots); var slot = slots.match(/^\s*\d+\s*:.*,bs.*P9_14/gm); console.log(slot); slot = slots.match(/\d+(?=\s*:.*,bs.*P9_14)/gm); console.log(slot); if(slot && slot[0]) { fs.writeFileSync(capemgr + '/slots', '-'+slot[0], 'ascii'); } slots = fs.readFileSync(capemgr + '/slots', 'ascii'); console.log(slots); deleteFile('/lib/firmware/bspwm_P9_14_e-00A0.dtbo'); deleteFile('/lib/firmware/bspwm_P9_14_6-00A0.dtbo'); function deleteFile(filename) { if(my.file_existsSync(filename)) { fs.unlinkSync(filename); } } b.analogWrite('P9_14', 0.9); console.log(JSON.stringify(b.getPinMode('USR3'))); console.log(JSON.stringify(b.getPinMode('P9_12'))); console.log(JSON.stringify(b.getPinMode('P9_13'))); console.log(JSON.stringify(b.getPinMode('P9_14'))); console.log(JSON.stringify(b.getPinMode('P9_35'))); console.log(JSON.stringify(b.getPinMode('P9_15'))); b.writeTextFile('/sys/class/gpio/unexport', ''+b.bone.pins.P9_15.gpio); console.log(JSON.stringify(b.getPinMode('P9_15'))); b.pinMode('P9_15', b.OUTPUT); console.log(JSON.stringify(b.getPinMode('P9_15'))); console.log('got here: ' + b.analogWrite('P9_14', 0.1)); }; ================================================ FILE: test/TODO/test-globalsetuploop.js ================================================ var b = require('bonescript'); var x = 0; global.setup = function() { b.pinMode('P9_14', b.ANALOG_OUTPUT); }; global.loop = function() { //console.log(x); b.analogWrite('P9_14', x); x += 0.001; if(x >= 1.0) x = 0; }; ================================================ FILE: test/TODO/test-i2c-accel.js ================================================ var b = require('bonescript'); var port = '/dev/i2c-2' var address = 0x1c; var data = [0xAA, 0x55, 0x33, 0xEE, 65, 51, 51, 53, 66, 78, 76, 84]; var GSCALE = 2; b.i2cOpen(port, address, {}, onI2C); b.i2cScan(port, onScan); b.i2cWriteBytes(port, 0x2a, [1], onWriteBytes); function onI2C(x) { if(x.event == 'data') { console.log('data = ' + JSON.stringify(x.data)); } } function onScan(x) { console.log('scan = ' + JSON.stringify(arguments)); } function onWriteBytes(x) { console.log('writeBytes = ' + JSON.stringify(arguments)); //if(x.event == 'callback') b.i2cWriteByte(port, 0, onWriteByte); if(x.event == 'callback') b.i2cReadBytes(port, 1, 6, onReadBytes); } function onWriteByte(x) { console.log('writeByte = ' + JSON.stringify(arguments)); if(x.event == 'callback') b.i2cReadBytes(port, null, 13, onReadBytes); } function onReadBytes(x) { console.log('readBytes = ' + JSON.stringify(arguments)); //if(x.event == 'callback') process.exit(0); } ================================================ FILE: test/TODO/test-i2c.js ================================================ var b = require('bonescript'); var port = '/dev/i2c-0'; var address = 0x50; //var data = [0xAA, 0x55, 0x33, 0xEE, 65, 51, 51, 53, 66, 78, 76, 84]; // Where is the first byte going?!? b.i2cOpen(port, address, {}, onI2C); b.i2cScan(port, onScan); b.i2cWriteByte(port, 0, onWriteByte); b.i2cReadBytes(port, null, 12, onReadBytes); function onI2C(x) { if(x.event == 'data') { console.log('data = ' + JSON.stringify(x.data)); } } function onScan(err, data) { console.log('scan = ' + JSON.stringify(arguments)); } function onWriteByte(err) { console.log('writeByte = ' + JSON.stringify(err)); } function onReadBytes(err, res) { console.log('readBytes = ' + JSON.stringify(arguments)); if(err.event == 'callback') process.exit(0); } ================================================ FILE: test/TODO/test-pocketbeagle.js ================================================ var b = require('bonescript'); var gpios = [ 'p1.2', 'p1.04', 'P1.6', 'P1_20', 'P1_29', 'P1_30', 'P1_31', 'P1_33', 'P1_35', 'P1.36', 'P1.37', 'P1_38', 'p2.1', 59, 23, 'p2_06', 60, 52, 65, 47, 27, 46, 'P2_26', 'P2_28', 'p2_30', 'p2.32', 'p2_33', 'p2_34', 'P2_35', 'P2_36', ]; for(i in gpios) { b.setMode(gpios[i], b.OUTPUT); } ================================================ FILE: test/TODO/test-serial.js ================================================ var b = require('bonescript'); var rxport = '/dev/ttyO1'; var txport = '/dev/ttyO4'; var options = { baudrate: 115200, parser: b.serialParsers.readline('\n') }; var teststring = "This is the string I'm sending out as a test"; b.serialOpen(rxport, options, onRxSerial); function onRxSerial(x) { console.log('rx.event = ' + x.event); if(x.err) throw('***FAIL*** ' + JSON.stringify(x)); if(x.event == 'open') { b.serialOpen(txport, options, onTxSerial); } if(x.event == 'data') { console.log('rx (' + x.data.length + ') = ' + x.data.toString('ascii')); } } function onTxSerial(x) { console.log('tx.event = ' + x.event); if(x.err) throw('***FAIL*** ' + JSON.stringify(x)); if(x.event == 'open') { writeRepeatedly(); } if(x.event == 'data') { console.log('tx (' + x.data.length + ') = ' + x.data.toString('ascii')); } } function printJSON(x) { console.log(JSON.stringify(x)); } function writeRepeatedly() { b.serialWrite(txport, teststring, onSerialWrite); } function onSerialWrite(x) { if(x.err) console.log('onSerialWrite err = ' + x.err); if(x.event == 'callback') setTimeout(writeRepeatedly, 1000); } ================================================ FILE: test/TODO/test-templates.js ================================================ var my = require('../node_modules/bonescript/my'); var bone = require('../node_modules/bonescript/bone'); var pin = { "name": "PIN_NAME", "gpio": 0, "mux": "mux_name", "eeprom": 1, "pwm": { "module": "pwm_module", "index": 0, "muxmode": 4, "path": "pwmpath.0:0", "name": "PWMNAME" }, "key": "P_NONE", "muxRegOffset": "0x0", "options": [ "option0", "option1", "option2", "option3", "option4", "option5", "option6", "option7" ] }; var pinData = 0xFF; my.create_dt(pin, pinData, 'bspm', false, true); my.create_dt(pin, pinData, 'bspwm', false, true); ================================================ FILE: test/TODO/test-unloadslot.js ================================================ var fs = require('fs'); var my = require('../src/my.js'); var capemgr = my.is_capemgr(); var slots = fs.readFileSync(capemgr + '/slots', 'ascii'); console.log(slots); var slot = slots.match(/^\s*\d+\s*:.*,bs.*P8_13/gm); console.log(slot); slot = slots.match(/\d+(?=\s*:.*,bs.*P8_13)/gm); console.log(slot); ================================================ FILE: test/TODO/test.sh ================================================ #!/bin/sh node remote_bonetest.js wired_basic_test.js ================================================ FILE: test/TODO/update-bonescript.sh ================================================ #!/bin/sh set -x set -e # Get directory cd $(dirname $0) cd .. BS_DIR=$(pwd) ssh-copy-id root@192.168.7.2 cd $BS_DIR/test node remote_bonetest.js setdate.js ssh root@192.168.7.2 < /sys/class/gpio/export echo in > /sys/class/gpio/gpio22/direction echo both > /sys/class/gpio/gpio22/edge node watch-button ================================================ FILE: test/TODO/wired_basic_test.js ================================================ var b = require('bonescript'); var serial = { in: { port: '/dev/ttyO1', options: { baudrate: 115200 } }, out: { port: '/dev/ttyO4', options: { baudrate: 115200 }, } }; var pinDW = 'P9_12'; var pinDR = 'P9_14'; var pinGM = 'P9_20'; var pinAW = 'P9_21'; var pinAR = 'P9_35'; //var pinST = 'P9_13'; //var pinSR = 'P9_26'; var supported = { '0.2.2': true, '0.2.3': true, '0.2.4': true }; var version; var timeout = setTimeout(onTimeout, 10000); console.log('Testing getPlatform'); b.getPlatform(onGetPlatform); function onGetPlatform(x) { if(!x.name || !x.serialNumber || !x.version) err('getPlatform returned ' + JSON.stringify(x)); console.log('Name = ' + x.name); console.log('S/N = ' + x.serialNumber); console.log('Version = ' + x.version); console.log('BoneScript version = ' + x.bonescript); if(typeof supported[x.bonescript] === undefined || !supported[x.bonescript]) err('BoneScript needs to be 0.2.2 or newer'); version = x.bonescript; console.log('Testing setDate'); b.setDate(Date().toString(), onSetDate); } function onSetDate(x) { // Different distros have different success results running 'date' if(false && x.stdout !== null) { err('setDate returned ' + JSON.stringify(x)); } console.log('Testing echo'); b.echo('test', onEcho); } function onEcho(x) { if(x.data != 'test') err('doEcho returned ' + JSON.stringify(x)); console.log('Testing getPinMode'); b.getPinMode(pinGM, onGetPinMode); } function onGetPinMode(x) { if(x.mux != 3) err('getPinMode returned ' + JSON.stringify(x)); console.log('Testing pinMode(input,GPIO)'); b.pinMode(pinDR, b.INPUT, 7, 'disabled', 'fast', onPinModeInput); } function onPinModeInput(x) { if(x.value !== true) err('pinMode(input) returned ' + JSON.stringify(x)); console.log('Testing pinMode(output,GPIO)'); b.pinMode(pinDW, b.OUTPUT, 7, 'disabled', 'fast', onPinModeOutput); } function onPinModeOutput(x) { if(x.value !== true) err('pinMode(output) returned ' + JSON.stringify(x)); console.log('Testing digitalWrite(low)'); b.digitalWrite(pinDW, b.LOW, onDigitalWriteLow); } function onDigitalWriteLow(x) { if(x.data !== null) err('digitalWrite(low) returned ' + JSON.stringify(x)); console.log('Testing digitalRead(low)'); b.digitalRead(pinDR, onDigitalReadLow); } function onDigitalReadLow(x) { if(x.value != b.LOW) err('digitalRead(low) returned ' + JSON.stringify(x)); console.log('Testing digitalWrite(high)'); b.digitalWrite(pinDW, b.HIGH, onDigitalWriteHigh); } function onDigitalWriteHigh(x) { if(x.data !== null) err('digitalWrite(high) returned ' + JSON.stringify(x)); console.log('Testing digitalRead(high)'); b.digitalRead(pinDR, onDigitalReadHigh); } function onDigitalReadHigh(x) { if(x.value != b.HIGH) err('digitalRead(high) returned ' + JSON.stringify(x)); console.log('Testing analogWrite'); b.analogWrite(pinAW, 0.27, 2000.0, onAnalogWrite); } function onAnalogWrite(x) { if(x.value !== true) err('analogWrite returned ' + JSON.stringify(x)); console.log('Testing analogRead'); setTimeout(doAnalogRead, 1000); } function doAnalogRead() { b.analogRead(pinAR, onAnalogRead); } function onAnalogRead(x) { if(x.value > 0.55 || x.value < 0.45) err('analogRead returned ' + JSON.stringify(x)); console.log('Testing writeTextFile'); b.writeTextFile('/tmp/basic_test', 'So far so good', onWriteTextFile); } function onWriteTextFile(x) { if(x.err !== null) err('writeTextFile returned ' + JSON.stringify(x)); console.log('Testing readTextFile'); b.readTextFile('/tmp/basic_test', onReadTextFile); } function onReadTextFile(x) { if(x.err !== null) err('readTextFile returned ' + JSON.stringify(x)); if(x.data != 'So far so good') err('readTextFile returned ' + JSON.stringify(x)); if(version != '0.2.2') doSerial(); else complete(); } function doSerial() { console.log('Testing serialOpen(in)'); b.serialOpen(serial.in.port, serial.in.options, onSerialInOpen); } function onSerialInOpen(x) { if(x.err) err('serialOpen(in) returned' + JSON.stringify(x)); if(x.event == 'open') { console.log('Testing serialOpen(out)'); b.serialOpen(serial.out.port, serial.out.options, onSerialOutOpen); } if(x.event == 'data') { onSerialInData(x); } } function onSerialOutOpen(x) { if(x.err) err('serialOpen(out) returned' + JSON.stringify(x)); if(x.event == 'open') { doSerialWrite(); } if(x.event == 'data') { err('Unexpected data on serial output port: ' + JSON.stringify(x)); } } function doSerialWrite() { console.log('Testing serialWrite'); serial.size = 2000; serial.data = new Buffer(serial.size); for(var i = 0; i < serial.size; i++) { serial.data.writeUInt8(i%255, i); } serial.offset = 0; b.serialWrite(serial.out.port, serial.data, onSerialWrite); } function onSerialWrite(x) { if(x.err) err('serialWrite returned' + JSON.stringify(x)); } function onSerialInData(x) { if(x.data.length < 1) err('invalid serial data ' + JSON.stringify(x)); console.log('Recieved ' + x.data.length + ' bytes'); for(var i = 0; i < x.data.length; i++) { if(x.data.readUInt8(i) != serial.data[serial.offset]) err('invalid serial data ' + JSON.stringify(x)); serial.offset++; } if(serial.offset >= serial.size) complete(); } function complete() { clearTimeout(timeout); console.log('***PASS***'); process.exit(0); } function err(x) { clearTimeout(timeout); console.log('***FAIL*** ' + x); throw(x); } function onTimeout() { err('Timeout'); } function printJSON(x) { console.log('x = ' + JSON.stringify(x)); } ================================================ FILE: test/test-analogread.js ================================================ var b = require('bonescript'); var pinKeys = []; for (var i = 1; i <= 36; i++) { pinKeys.push("P1_" + i); pinKeys.push("P2_" + i); } for (var i = 1; i <= 46; i++) { pinKeys.push("P8_" + i); pinKeys.push("P9_" + i); } exports.testanalogread1 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { var y = b.analogRead(pinKeys[x]); test.ok(typeof y == 'number'); } test.done(); } exports.testanalogread2 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.analogRead(pinKeys[x], function (x) { test.ok(typeof x.value == 'number' && !x.err); }); if (x == pinKeys.length - 1) test.done(); } } exports.testanalogread3 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.analogRead(pinKeys[x], function (err, value) { test.ok(typeof value == 'number' && !err); }); if (x == pinKeys.length - 1) test.done(); } } ================================================ FILE: test/test-analogwrite.js ================================================ var b = require('bonescript'); var pinKeys = []; for (var i = 1; i <= 36; i++) { pinKeys.push("P1_" + i); pinKeys.push("P2_" + i); } for (var i = 1; i <= 46; i++) { pinKeys.push("P8_" + i); pinKeys.push("P9_" + i); } exports.testanalogwrite1 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { test.doesNotThrow(function () { b.analogWrite(pinKeys[x], Math.random()); }); } test.done(); } exports.testanalogwrite2 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.analogWrite(pinKeys[x], Math.random(), 2000, function (x) { test.ok(true); }); if (x == pinKeys.length - 1) test.done(); } } ================================================ FILE: test/test-autorun.js ================================================ var autorun = require('bonescript').autorun; var fs = require('fs'); var testDir = '/tmp/autorun-test'; var file0 = testDir + '/autorun-test0.js'; var file1 = testDir + '/autorun-test1.js'; exports.testAutorun = function (test) { test.expect(3); setTimeout(onTimeout1, 100); setTimeout(onTimeout2, 1000); if (!fs.existsSync(testDir)) { fs.mkdirSync(testDir); } try { fs.unlinkSync(file0); } catch (ex) { console.log('Unable to delete ' + file0); } try { fs.unlinkSync(file1); } catch (ex) { console.log('Unable to delete ' + file1); } fs.writeFileSync(file0, 'console.log("got here in ' + file0 + '");'); console.log('Wrote ' + file0); var ar = autorun(testDir); var apps = ar.getApps(); var emitter = ar.getEmitter(); emitter.on('start', function (file) { console.log('Started ' + file); if (file == file1) { setTimeout(function () { fs.unlink(file1, onUnlink); }, 500); test.ok(true); } }); emitter.on('closed', function (file) { if (file == file1) { ar.stop(); test.ok(true); } }); function onTimeout1() { fs.writeFileSync(file1, 'console.log("got here in ' + file1 + '"); setTimeout(function(){console.log("timeout")}, 3000);'); console.log('Wrote ' + file1); test.ok(true); } function onTimeout2() { console.log('Done'); test.done(); } function onUnlink() { console.log('Deleted ' + file1); } }; ================================================ FILE: test/test-bone.js ================================================ //process.env.DEBUG = true; var bone = require('bonescript').bone; var expectedResults = []; expectedResults.push({ "name": "LEDs", "search": /^USR/, "keys": ["USR0", "USR1", "USR2", "USR3"] }); var pbKeys = []; for (var i = 1; i <= 36; i++) { pbKeys.push("P1_" + i); pbKeys.push("P2_" + i); } expectedResults.push({ "name": "PocketBeagleHeaders", "search": /^P[12]/, "keys": pbKeys }); var boneKeys = []; for (var i = 1; i <= 46; i++) { boneKeys.push("P8_" + i); boneKeys.push("P9_" + i); } boneKeys.push("P9_15B"); boneKeys.push("P9_41B"); boneKeys.push("P9_42B"); expectedResults.push({ "name": "BeagleBoneHeaders", "search": /^P[89]/, "keys": boneKeys }); var ainKeys = []; for (var i = 0; i <= 7; i++) { ainKeys.push("A" + i); } expectedResults.push({ "name": "AnalogInPins", "search": /^A[0-7]/, "keys": ainKeys }); var gpioKeys = []; for (var i = 0; i <= 117; i++) { gpioKeys.push("GPIO_" + i); } expectedResults.push({ "name": "GPIOPins", "search": /^GPIO_/, "keys": gpioKeys }); // removes must be done high-to-low to keep indexes valid gpioKeys.splice(108, 1); // remove GPIO3_12 gpioKeys.splice(107, 1); // remove GPIO3_11 gpioKeys.splice(25, 1); // remove GPIO0_25 gpioKeys.splice(24, 1); // remove GPIO0_24 var eepromKeys = []; for (var i = 0; i < 74; i++) { eepromKeys.push("EEPROM_" + i); } expectedResults.push({ "name": "EEPROM", "search": /^EEPROM_/, "keys": eepromKeys }); var blueKeys = []; for (var i = 1; i <= 6; i++) { blueKeys.push("GP0_" + i); blueKeys.push("GP1_" + i); blueKeys.push("S1_1_" + i); blueKeys.push("S1_2_" + i); blueKeys.push("ADC_" + i); } for (var i = 2; i <= 6; i++) { blueKeys.push("GPS_" + i); } for (var i = 1; i <= 4; i++) { for (var j = 1; j <= 4; j++) { blueKeys.push("E" + j + "_" + i); } blueKeys.push("I2C_" + i); blueKeys.push("UT0_" + i); blueKeys.push("UT1_" + i); blueKeys.push("UT5_" + i); } for (var i = 1; i <= 3; i++) { blueKeys.push("DSM2_" + i); } blueKeys.push("RED"); blueKeys.push("GREEN"); blueKeys.push("WIFI"); blueKeys.push("BAT25"); blueKeys.push("BAT50"); blueKeys.push("BAT75"); blueKeys.push("BAT100"); blueKeys.push("PAUSE"); blueKeys.push("MODE"); expectedResults.push({ "name": "BeagleBoneBlue", "search": /^((E[1234]|GP[01]|GPS|S1_[12]|I2C|UT[015]|ADC|DSM2)_|RED|GREEN|WIFI|BAT|PAUSE|MODE)/, "keys": blueKeys }); var results = {}; for (var i = 0; i < expectedResults.length; i++) { var er = expectedResults[i]; exports['testBoneGetPinKeys' + er.name] = makeTest(i); } function makeTest(i) { var search = expectedResults[i].search; var expected = expectedResults[i].keys.sort(bone.naturalCompare); return (function (test) { test.expect(2); test.doesNotThrow(function () { results = bone.getPinKeys(search).sort(bone.naturalCompare); }); test.ok(compareResults(results, expected)); test.done(); }); } function compareResults(results, expected) { console.log("results = " + JSON.stringify(results)); console.log("expectedResults = " + JSON.stringify(expected)); for (i in expected) { if (results[i] != expected[i]) return (false); } return (true); } ================================================ FILE: test/test-digitalread.js ================================================ var b = require('bonescript'); var pinKeys = []; for (var i = 1; i <= 36; i++) { pinKeys.push("P1_" + i); pinKeys.push("P2_" + i); } for (var i = 1; i <= 46; i++) { pinKeys.push("P8_" + i); pinKeys.push("P9_" + i); } exports.testdigitalRead1 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { var y = b.digitalRead(pinKeys[x]); test.ok(typeof y == 'number'); } test.done(); } exports.testdigitalRead2 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.digitalRead(pinKeys[x], function (x) { test.ok(typeof x.value == 'number' && !x.err); }); if (x == pinKeys.length - 1) test.done(); } } exports.testdigitalRead3 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.digitalRead(pinKeys[x], function (err, value) { test.ok(typeof value == 'number' && !err); }); if (x == pinKeys.length - 1) test.done(); } } ================================================ FILE: test/test-digitalwrite.js ================================================ var b = require('bonescript'); var pinKeys = []; for (var i = 1; i <= 36; i++) { pinKeys.push("P1_" + i); pinKeys.push("P2_" + i); } for (var i = 1; i <= 46; i++) { pinKeys.push("P8_" + i); pinKeys.push("P9_" + i); } pinKeys = pinKeys.concat(['USR0', 'USR1', 'USR2', 'USR3']); exports.testdigitalwrite1 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { test.doesNotThrow(function () { b.digitalWrite(pinKeys[x], b.HIGH); }); } test.done(); } exports.testdigitalwrite2 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.digitalWrite(pinKeys[x], b.LOW, function () { test.ok(true); }); if (x == pinKeys.length - 1) test.done(); } } ================================================ FILE: test/test-ffi.js ================================================ var b = require('bonescript'); var fs = require('fs'); var testDir = '/tmp/ffi-test'; var Cfile = testDir + '/ffi-test'; var Cfile1 = testDir + '/ffi-test1'; var txtFile = testDir + '/txt-test.txt' var txtFile1 = testDir + '/txt-test1.txt' var args = { 'dummy': ['int', ['void']] }; var text = "HELLO"; var cCode = ` #include int dummy() { printf("Hello, World!"); return 0; } ` module.exports.testFFI = function (test) { test.expect(8); if (!fs.existsSync(testDir)) { fs.mkdirSync(testDir); } //test writetxtFile b.writeTextFile(txtFile, text); if (fs.existsSync(txtFile)) { console.log("Write Text File Successful"); test.ok(true); } //test readtxtFile if (b.readTextFile(txtFile) == text) { console.log("Read Text File Successful"); test.ok(true); } //test mraaGPIO() var mraaGPIO = b.mraaGPIO('P9_12'); if (mraaGPIO === '0x3a') { console.log("MRAA Library Load Successful"); test.ok(true); } //test writeCModule b.writeCModule(Cfile, cCode); if (fs.existsSync(Cfile + '.c')) { console.log("Write C Module Successful"); test.ok(true); } //test loadCModule var Cmodule = b.loadCModule(Cfile, args); if (Cmodule == "ffi not loaded") { console.log("Load C Module Unsuccesful(ffi not loaded)"); test.ok(true); } else { var moduleRetVal = Cmodule.dummy(0); //returns 0 console.log("Load C Module Succesful, returned: " + moduleRetVal); test.ok(moduleRetVal == 0); } //test writetxtFile with callback b.writeTextFile(txtFile1, text, function (x) { if (!x.err) test.ok(true); onWriteTextFile(); }); //test readtxtFile with callback function onWriteTextFile() { b.readTextFile(txtFile1, function (err, data) { if (!err && data == text) test.ok(true); onReadTextFile() }) } //test writeCModule with callback function onReadTextFile() { b.writeCModule(Cfile1, cCode, function (x) { if (!x.err) test.ok(true); test.done(); }); } } ================================================ FILE: test/test-getpinmode.js ================================================ //process.env.DEBUG = true; var b = require('bonescript'); var expectedResults = [{ "pin": "USR0", "name": "USR0" }, { "pin": "USR1", "name": "USR1" }, { "pin": "USR2", "name": "USR2" }, { "pin": "USR3", "name": "USR3" }, { "pin": "P8_1", "name": "DGND" }, { "pin": "P8_2", "name": "DGND" }, { "pin": "P8_3", "name": "GPIO1_6" }, { "pin": "P8_4", "name": "GPIO1_7" }, { "pin": "P8_5", "name": "GPIO1_2" }, { "pin": "P8_6", "name": "GPIO1_3" }, { "pin": "P8_7", "name": "TIMER4" }, { "pin": "P8_8", "name": "TIMER7" }, { "pin": "P8_9", "name": "TIMER5" }, { "pin": "P8_10", "name": "TIMER6" }, { "pin": "P8_11", "name": "GPIO1_13" }, { "pin": "P8_12", "name": "GPIO1_12" }, { "pin": "P8_13", "name": "EHRPWM2B" }, { "pin": "P8_14", "name": "GPIO0_26" }, { "pin": "P8_15", "name": "GPIO1_15" }, { "pin": "P8_16", "name": "GPIO1_14" }, { "pin": "P8_17", "name": "GPIO0_27" }, { "pin": "P8_18", "name": "GPIO2_1" }, { "pin": "P8_19", "name": "EHRPWM2A" }, { "pin": "P8_20", "name": "GPIO1_31" }, { "pin": "P8_21", "name": "GPIO1_30" }, { "pin": "P8_22", "name": "GPIO1_5" }, { "pin": "P8_23", "name": "GPIO1_4" }, { "pin": "P8_24", "name": "GPIO1_1" }, { "pin": "P8_25", "name": "GPIO1_0" }, { "pin": "P8_26", "name": "GPIO1_29" }, { "pin": "P8_27", "name": "GPIO2_22" }, { "pin": "P8_28", "name": "GPIO2_24" }, { "pin": "P8_29", "name": "GPIO2_23" }, { "pin": "P8_30", "name": "GPIO2_25" }, { "pin": "P8_31", "name": "UART5_CTSN" }, { "pin": "P8_32", "name": "UART5_RTSN" }, { "pin": "P8_33", "name": "UART4_RTSN" }, { "pin": "P8_34", "name": "UART3_RTSN" }, { "pin": "P8_35", "name": "UART4_CTSN" }, { "pin": "P8_36", "name": "UART3_CTSN" }, { "pin": "P8_37", "name": "UART5_TXD" }, { "pin": "P8_38", "name": "UART5_RXD" }, { "pin": "P8_39", "name": "GPIO2_12" }, { "pin": "P8_40", "name": "GPIO2_13" }, { "pin": "P8_41", "name": "GPIO2_10" }, { "pin": "P8_42", "name": "GPIO2_11" }, { "pin": "P8_43", "name": "GPIO2_8" }, { "pin": "P8_44", "name": "GPIO2_9" }, { "pin": "P8_45", "name": "GPIO2_6" }, { "pin": "P8_46", "name": "GPIO2_7" }, { "pin": "P9_1", "name": "DGND" }, { "pin": "P9_2", "name": "DGND" }, { "pin": "P9_3", "name": "VDD_3V3" }, { "pin": "P9_4", "name": "VDD_3V3" }, { "pin": "P9_5", "name": "VDD_5V" }, { "pin": "P9_6", "name": "VDD_5V" }, { "pin": "P9_7", "name": "SYS_5V" }, { "pin": "P9_8", "name": "SYS_5V" }, { "pin": "P9_9", "name": "PWR_BUT" }, { "pin": "P9_10", "name": "SYS_RESETn" }, { "pin": "P9_11", "name": "UART4_RXD" }, { "pin": "P9_12", "name": "GPIO1_28" }, { "pin": "P9_13", "name": "UART4_TXD" }, { "pin": "P9_14", "name": "EHRPWM1A" }, { "pin": "P9_15", "name": "GPIO1_16" }, { "pin": "P9_15B", "name": "GPIO1_16" }, { "pin": "P9_16", "name": "EHRPWM1B" }, { "pin": "P9_17", "name": "I2C1_SCL" }, { "pin": "P9_18", "name": "I2C1_SDA" }, { "pin": "P9_19", "name": "I2C2_SCL" }, { "pin": "P9_20", "name": "I2C2_SDA" }, { "pin": "P9_21", "name": "UART2_TXD" }, { "pin": "P9_22", "name": "UART2_RXD" }, { "pin": "P9_23", "name": "GPIO1_17" }, { "pin": "P9_24", "name": "UART1_TXD" }, { "pin": "P9_25", "name": "GPIO3_21" }, { "pin": "P9_26", "name": "UART1_RXD" }, { "pin": "P9_27", "name": "GPIO3_19" }, { "pin": "P9_28", "name": "SPI1_CS0" }, { "pin": "P9_29", "name": "SPI1_D0" }, { "pin": "P9_30", "name": "SPI1_D1" }, { "pin": "P9_31", "name": "SPI1_SCLK" }, { "pin": "P9_32", "name": "VDD_ADC" }, { "pin": "P9_33", "name": "AIN4" }, { "pin": "P9_34", "name": "GNDA_ADC" }, { "pin": "P9_35", "name": "AIN6" }, { "pin": "P9_36", "name": "AIN5" }, { "pin": "P9_37", "name": "AIN2" }, { "pin": "P9_38", "name": "AIN3" }, { "pin": "P9_39", "name": "AIN0" }, { "pin": "P9_40", "name": "AIN1" }, { "pin": "P9_41", "name": "CLKOUT2" }, { "pin": "P9_41B", "name": "CLKOUT2" }, { "pin": "P9_42", "name": "GPIO0_7" }, { "pin": "P9_42B", "name": "GPIO0_7" }, { "pin": "P9_43", "name": "DGND" }, { "pin": "P9_44", "name": "DGND" }, { "pin": "P9_45", "name": "DGND" }, { "pin": "P9_46", "name": "DGND" }, ]; var results = {}; for (var i = 0; i < expectedResults.length; i++) { var er = expectedResults[i]; exports['testGetPinMode' + er.pin] = makeTest(i); } function makeTest(i) { var pin = expectedResults[i].pin; var expected = expectedResults[i]; return (function (test) { test.expect(2); test.doesNotThrow(function () { results = b.getPinMode(pin); // Only compare name to work on travis-ci results = { "pin": results.pin, "name": results.name }; }); test.ok(compareResults(results, expected)); test.done(); }); } function compareResults(results, expected) { console.log("results = " + JSON.stringify(results)); console.log("expectedResults = " + JSON.stringify(expected)); for (i in expected) { if (results[i] != expected[i]) return (false); } return (true); } ================================================ FILE: test/test-lint.js ================================================ module.exports = {}; var beautify = require('../node_modules/js-beautify'); var fs = require('fs'); var path = require('path'); var config = JSON.parse(fs.readFileSync('./lint-config.json')); var index = 0; testDir("./"); testDir("./src/"); testDir("./test/"); function testDir(dir) { var files = fs.readdirSync(dir); files.forEach(function (file, index) { testFile(dir + file); }); } function testFile(fileToTest) { var stat = fs.statSync(fileToTest); if (stat.isFile() && fileToTest.match(/js$/)) { //console.log("Adding lint test for " + fileToTest); index++; module.exports["testLint" + index] = function (test) { var inFile = "a"; var outFile = "b"; test.expect(2); test.doesNotThrow(function () { console.log("Running lint on " + fileToTest); inFile = fs.readFileSync(fileToTest, 'utf8'); outFile = beautify.js(inFile, config); //fs.writeFileSync(fileToTest + ".lint", outFile); }); test.equal(inFile, outFile); test.done(); }; } } ================================================ FILE: test/test-math.js ================================================ var math = require('../src/functions'); var b = require('bonescript'); var mathFns = Object.getOwnPropertyNames(math); for (var x in mathFns) mathFns[x] = b[mathFns[x]]; function getRandomInt() { return Math.floor(Math.random() * 100); } exports.testMathFunctions = function (test) { test.expect(mathFns.length - 1); //randomseed does not return anything for (var x in mathFns) { var result = mathFns[x].call(null, getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt()); if (typeof result == 'number') //assuming every math function returns a number test.ok(true); } test.done(); } ================================================ FILE: test/test-pinMode.js ================================================ var b = require('bonescript'); var pinKeys = []; for (var i = 1; i <= 36; i++) { pinKeys.push("P1_" + i); pinKeys.push("P2_" + i); } for (var i = 1; i <= 46; i++) { pinKeys.push("P8_" + i); pinKeys.push("P9_" + i); } for (var i = 0; i <= 7; i++) { pinKeys.push("A" + i); } pinKeys = pinKeys.concat(['USR0', 'USR1', 'USR2', 'USR3']); exports.testpinMode1 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { test.doesNotThrow(function () { b.pinMode(pinKeys[x], b.OUTPUT); b.pinMode(pinKeys[x], b.INPUT); b.pinMode(pinKeys[x], b.INPUT_PULLUP); b.pinMode(pinKeys[x], b.ANALOG_OUTPUT); }); } test.done(); } exports.testpinMode2 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.pinMode(pinKeys[x], b.OUTPUT, 7, 'pullup', 'fast', function (x) { test.ok(x.value && !x.err); }); if (x == pinKeys.length - 1) test.done(); } } exports.testpinMode3 = function (test) { test.expect(pinKeys.length); for (var x in pinKeys) { b.pinMode(pinKeys[x], b.OUTPUT, 7, 'pullup', 'fast', function (err, value) { test.ok(value && !err); }); if (x == pinKeys.length - 1) test.done(); } } ================================================ FILE: test/test-rpc.js ================================================ var server = require('bonescript'); var bonescript = require('../src/bonescript'); var myserver = null; exports.setUp = function (callback) { server.serverStart(8000, process.cwd(), null, mycb); function mycb(serverObj) { myserver = serverObj.server; callback(); } }; exports.testRPC_callbacks = function (test) { test.expect(15); bonescript.startClient({ address: '127.0.0.1', port: 8000 }, getPlatformTest_oldstyle); function getPlatformTest_oldstyle() { var b = bonescript.require('bonescript'); b.getPlatform(function (platform) { console.log("***getPlatformTest_oldstyle***"); console.log(platform); console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); getPlatformTest_nodestyle(platform); }); } function getPlatformTest_nodestyle(platform_) { console.log('here'); var b = bonescript.require('bonescript'); b.getPlatform(function (err, platform) { console.log("***getPlatformTest_nodestyle***"); console.log(platform); console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); test.equals(platform.name, platform_.name); test.equals(platform.bonescript, platform_.bonescript); pinModeTest_oldstyle(); }); } function pinModeTest_oldstyle() { var b = bonescript.require('bonescript'); b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); function printStatus(x) { console.log("***pinModeTest_oldstyle***"); console.log('value = ' + x.value); console.log('err = ' + x.err); pinModeTest_nodestyle(x); } } function pinModeTest_nodestyle(x) { var b = bonescript.require('bonescript'); b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); function printStatus(err, value) { console.log("***pinModeTest_nodestyle***"); console.log('value = ' + value); console.log('err = ' + err); test.equals(x.err, err); test.equals(x.value, value); getPinModeTest_oldstyle(); } } function getPinModeTest_oldstyle() { var b = bonescript.require('bonescript'); b.getPinMode("P8_13", printPinMux); function printPinMux(x) { console.log("***getPinModeTest_oldstyle***"); console.log('mux = ' + x.mux); console.log('pullup = ' + x.pullup); console.log('slew = ' + x.slew); console.log('options = ' + x.options.join(',')); console.log('err = ' + x.err); getPinModeTest_nodestyle(x) } } function getPinModeTest_nodestyle(x) { var b = bonescript.require('bonescript'); b.getPinMode("P8_13", printPinMux); function printPinMux(err, resp) { console.log("***getPinModeTest_nodestyle***"); console.log('mux = ' + resp.mux); console.log('pullup = ' + resp.pullup); console.log('slew = ' + resp.slew); console.log('options = ' + resp.options.join(',')); console.log('err = ' + resp.err); test.equals(x.mux, resp.mux); test.equals(x.pullup, resp.pullup); test.equals(x.slew, resp.slew); test.equals(x.options.join(','), resp.options.join(',')); digitalWriteTest(); } } function digitalWriteTest() { var b = bonescript.require('bonescript'); b.digitalWrite('USR0', b.HIGH, printErr); function printErr(x) { console.log("***digitalWriteTest***"); console.log('err = ' + x.err); test.ok(true); digitalReadTest_oldstyle(); } } function digitalReadTest_oldstyle() { var b = bonescript.require('bonescript'); b.digitalRead('P8_19', printStatus); function printStatus(x) { console.log("***digitalReadTest_oldstyle***"); console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); digitalReadTest_nodestyle(x) } } function digitalReadTest_nodestyle(x) { var b = bonescript.require('bonescript'); b.digitalRead('P8_19', printStatus); function printStatus(err, value) { console.log("***digitalReadTest_nodestyle***"); console.log('x.value = ' + value); console.log('x.err = ' + err); test.equals(x.value, value); analogWriteTest() } } function analogWriteTest() { var b = bonescript.require('bonescript'); b.analogWrite('P9_14', 0.7, 2000, printJSON); function printJSON(x) { console.log("***analogWriteTest***"); console.log(JSON.stringify(x)); test.ok(true); analogReadTest_oldstyle(); } } function analogReadTest_oldstyle() { var b = bonescript.require('bonescript'); b.analogRead('P9_36', printStatus); function printStatus(x) { console.log("***analogReadTest_oldstyle***"); console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); analogReadTest_nodestyle(x); } } function analogReadTest_nodestyle(x) { var b = bonescript.require('bonescript'); b.analogRead('P9_36', printStatus); function printStatus(err, value) { console.log("***analogReadTest_nodestyle***"); console.log('x.value = ' + value); console.log('x.err = ' + err); test.equals(x.value, value); attachInterruptTest_oldstyle() } } function attachInterruptTest_oldstyle() { var b = bonescript.require('bonescript'); b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); function interruptCallback(x) { console.log("***attachInterruptTest_oldstyle***"); console.log(JSON.stringify(x)); attachInterruptTest_nodestyle(x) } } function attachInterruptTest_nodestyle(x) { var b = bonescript.require('bonescript'); b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); function interruptCallback(err, resp) { console.log("***attachInterruptTest_nodestyle***"); console.log(JSON.stringify(resp)); test.equals(x.pin.name, resp.pin.name); readTextFileTest_oldstyle(); } } function readTextFileTest_oldstyle() { var b = bonescript.require('bonescript'); b.readTextFile('/etc/fstab', printStatus); function printStatus(x) { console.log("***readTextFileTest_oldstyle***"); console.log('x.data = ' + x.data); console.log('x.err = ' + x.err); readTextFileTest_nodestyle(x); } } function readTextFileTest_nodestyle(x) { var b = bonescript.require('bonescript'); b.readTextFile('/etc/fstab', printStatus); function printStatus(err, data) { console.log("***readTextFileTest_nodestyle***"); console.log('x.data = ' + data); console.log('x.err = ' + err); test.equals(x.data, data); test.equals(x.err, err); myserver.close(); test.done(); } } } ================================================ FILE: test/test-rpc_secure.js ================================================ var server = require('bonescript'); var bonescript = require('../src/bonescript'); var myserver = null; exports.setUp = function (callback) { server.serverStart(8000, process.cwd(), { // create a secure server by supplying credentials data: 'testpass', hash: false }, mycb); function mycb(serverobj) { myserver = serverobj.server; callback(); } }; exports.testRPC_secure1 = function (test) { test.expect(1); bonescript.startClient({ // this should throw an authentication error address: '127.0.0.1', port: 8000, password: 'tdestpass' }, function () {}); process.on('uncaughtException', function (err) { console.log(err.toString()); test.equals(err.toString(), 'Error: Authentication Failed : incorrect passphrase !!'); myserver.close(); test.done(); }); } exports.testRPC_secure2 = function (test) { test.expect(1); bonescript.startClient({ address: '127.0.0.1', port: 8000, password: 'testpass' // will not throw any error }, function () { var b = bonescript.require('bonescript'); b.getPlatform(function (platform) { console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); test.ok(platform != 'undefined'); myserver.close(); test.done(); }); }); } ================================================ FILE: test/test-sanity.js ================================================ //process.env.DEBUG = true; exports.testSanity1 = function (test) { test.expect(1); test.doesNotThrow(function () { var b = require('bonescript'); console.log('Name: ' + b.getPlatform().name); console.log('Version: ' + b.getPlatform().bonescript); }); test.done(); }