Comments (25)
As wrote in PR #113, process.iotjs can be used for distinguishing between iotjs and others.
it may also have other properties, such as running product class, H/W board, and network or other environments that is needed to make application to decide better.
If this seems to be a bad idea, please add comments.
from iotjs.
I think we may need API reference for device control.
And for new module features will be introduced later on, how about consensus of API first and then implementation?
from iotjs.
https://github.com/Samsung/iotjs/wiki/IoT.js-API:-GPIO
from iotjs.
What type of mode could be exist for a pin of GPIO?
As far as I know there is only one; direction. Direction of a pin could be either input or output at one time thus rw pin is not possible right?
Is there any other type of mode besides direction?
from iotjs.
I've prepared a short page https://github.com/Samsung/iotjs/wiki/GPIO-control-ideas few days ago, and pin mode is described in summary. If you jump to link http://coactionos.com/embedded%20design%20tips/2013/10/21/Tips-Understanding-Microcontroller-Pin-Input-Output-Modes/ there is more. Hope this helps.
from iotjs.
@seanshpark The page you referred are only saying there are input and output mode(direction). Then can we assume that there are no other type of mode?
from iotjs.
@ILyoan , If you let mode to be input/output, one more thing is floating
that is something like disconnected
.
Is there any other type of mode besides direction?
Besides direction, to the pin,
- Pull up or down or open-drain(open collector)
- Rise up or down edge detection
- input in digital or analog
from iotjs.
Let's summarize what pin configuration are commonly definable so we can design our GPIO API more usable for anyone.
I see configurable options are:
Direction / mode
input
- floating
- pull-up
- pull-down
output
- open-drain
- push-pul
Frequency
Ports
from iotjs.
Mode control depends on H/W. Is it ok to define actual mode in iotjs? Previous your comment was not to.
from iotjs.
I'm not sure about it.
My first thought was that mode configuration API might be sufficient if it enable user to select direction("input" or "output"). but you mentioned there are other modes besides it. so I listed it up.
If detailed configuration(like pull-do/down, open-drain, etc.) was up to hardware (for example, if target architecture was fixed, modes will also be fixed), then we don't need to expose the APIs for control it for user. On the other hand, if some user application should choose detailed mode, we need to provide APIs for it.
My intention is that I want to know minimum set of APIs that is enough for controlling GPIO for majority of use case.
from iotjs.
What about GPIO API like below:
gpio.set(pin, direction[, callback])
pin: Number
- pin number.direction: String
- direction of the gpio pin'in'
|'out'
.callback: Function(err: Exception | null)
gpio.write(pin, value[, callback])
pin: Number
- pin number.value: Boolean
-true
to turn onfalse
to turn off.callback: Function(err)
gpio.read(pin[, callback])
pin: Number
- pin number.callback: Function(err: Exception | null, value: Boolean)
Concerns
- API for initializing GPIO may not be needed because we can initalize gpio when it is required.
- API for releasing GPIO may not be needed because we can release resources when program down.
- Setting mode like 'pull-up', 'pull-down', 'open-drain', and etc might not be need if we don't support interrupt based event, I'm not sure about this but my understanding is that this is trivial for most of the use cases, many gpio application could use default mode setting.
- pin number could be actual hardware pin number or it could be gpio number. I prefer later one, so that pin number could be always 1,2,3,... independent on hardware.
from iotjs.
Binding GPIO in iotjs
namespace is also thinkable.
By this applications can get gpio module by var gpio = require('iotjs').gpio
.
The advantage of binding is that we can provide 'iotjs' npm fo node.js, so that exactly the same program could be run on both node.js and iot.js without knowing the platform underneath it. Since apps can use 'iotjs' functionality including gpio control independent of hardwares, all that apps have to do will be requiring 'iotjs'.
from iotjs.
Setting mode like 'pull-up', 'pull-down', 'open-drain',
these may need for some devices for addition in/out control. so set()
with direction
may not be sufficient.
pin number could be actual hardware pin number or it could be gpio number.
please look around 2.2.5 I/O Interface
in http://www.element14.com/community/servlet/JiveServlet/previewBody/51124-102-2-267813/STM32F4DIS-BB%20User%20Manual.pdf and http://www.element14.com/community/docs/DOC-73950/l/raspberry-pi-2-model-b-gpio-40-pin-block-pinout file. my opinion is to use pin number and let the application or module develop define and use some named alias.
Binding GPIO in iotjs namespace is also thinkable.
yes, nice. currently in private but please look inside iotjs-app
repo.
from iotjs.
Then, what about this?
gpio.set(pin, direction[, mode][, callback])
pin: Number
- pin number.direction: String
- direction of the gpio pin 'in' | 'out'.mode: String
- optional.callback: Function(err: Exception | null)
It looks like name aliasing such as GPIO1, GPIO2, GPIO3,... is not proper approach as pin specification are very different from HW to HW. Let's just leave aliasing for application until we find general solution.
from iotjs.
gpio.set(pin, direction[, mode][, callback])
seems nice.
can you describe relation with this API and PR #125 ?
from iotjs.
API for initializing GPIO may not be needed because we can initalize gpio when it is required.
API for releasing GPIO may not be needed because we can release resources when program down.
There may be resource waste. disagree on this.
direction: String - direction of the gpio pin 'in' | 'out'.
why use string when number is used underneath? user module can use this.
API seems nice but for linux system using /sys/class/gpio, I cannot see how to unexport
from iotjs.
@seanshpark
The hardware dependent implementation could be changed according to API.
For example, if we decide to provide gpio.set(pin, direction)
the underneath function prototype should be something like SetMode(int pin_number, Direction direction)
current implementation assumes pin
include mode information including pin number. Also our API to write data to pin was gpio.write(pin, value:bool)
then corresponding C++ function prototype will be Write(int pin_number, bool value)
. So it's relevant to.
I think using string is more intuitive than using enum like number so easy to understand for user. For example filesystem use "r+"
instead of O_RDWR
.
We can add API for initialiing / releasing / unset pin.
gpio.initialize()
Initialize gpio service. User application should call this function before calling any other gpio functions.
gpio.release()
Release gpio service.
gpio.unset(pin[, callback])
pin: Number
- pin number to unset.callback: Function(err: Error | null)
.
from iotjs.
From discussion today morning, we have formed a consensus for GPIO API candidate.
I think this API layout will reflect the idea.
iotjs.gpio
- pin number is logical number starts from 1. Thus logical pin number k is not necessarily bound to physical pin number k in your board.
- port number is logical number starts from 1. Thus logical port number k is not necessarily bound to physical port number k in your board.
- 8 logical pin will be bound to a logical port. For example, pin number 1
8 will bound to port 1, pin number 916 bound to port 2, and so forth. - If you write a byte value to a port, the result is the same as writing each bit to corresponding pin. For example, let's say you write (10101011)2 to port 1. the operation will write up bit to pin 1, up bit to pin 2, down bit to pin 3, ... , up bit to pin 8.
gpio.initialize()
Initialize gpio control.
gpio.release()
Release gpio control.
gpio.setPin(pinNumber, direction[, mode][, callback])
pinNumber: Number
- pin number to configuredirection: 'in' | 'out'
- direction of the pin.mode: String
- pin mode.callback: Function(err: Error | null)
.
Configure single pin.
gpio.writePin(pinNumber, value[, callback])
pinNumber: Number
- pin number to wirtevalue: Boolean
.callback: Function(err: Error | null)
.
Write a boolean value to a pin.
gpio.readPin(pinNumber, callback)
pinNumber: Number
- pin number to read.callback: Function(err: Error | null, value: Boolean)
.
Read value from a pin.
gpio.setPort(portNumber, direction[, mode][, callback])
portNumber: Number
- port number to configure.direction: 'in' | 'out'
- direction of the port.mode: String
- pin mode.callback: Function(err: Error | null)
.
Configure single port. All pins bound to this port will have the configuration.
gpio.writePort(portNumber, value[, callback])
portNumber: Number
- port number to wirtevalue: Number(1 Byte)
.callback: Function(err: Error | null)
.
Write a byte value to a port.
gpio.readPort(portNumber, callback)
portNumber: Number
- port number to read.callback: Function(err: Error | null, value: Number(1 byte))
.
Read value from a port.
gpio.query(queryOption, callback)
queryOption: Object
.callback: Function(err: Error | null, result: Object)
.
from iotjs.
Great. I've coped above descriptions to GPIO-API-candidate page. I've some comments
direction: 'in' | 'out'
: what do you think using boolean. code will be simple.- is
resetPin()
api not needed anymore or just forgot?
from iotjs.
true
for what?in
orout
? I wonder if it could be a little confusing.- you men
unset()
? We could provide it. or we can do it withsetPin()
with direction'none'
.
from iotjs.
- something like
direction
change toout
oroutput
and if true, will be set to output mode. setPin()
with directionnone
can be a choice forunsetPin()
but I prefer not to use string as value. simple value compare not string compare.
from iotjs.
I think I got confused. for the JS API, direction
with 'out' | 'in' | 'none'
seems ok.
from iotjs.
@seanshpark, thanks for your confirmation.
from iotjs.
thank you too, I'll begin the implementation when new HW arrives, for testing.
from iotjs.
Closing as we reached consensus about the API:
https://github.com/Samsung/iotjs/wiki/IoT.js-API:-GPIO
Feel free to reopen if it needed.
from iotjs.
Related Issues (20)
- How can I use iotjs as an external library ? HOT 1
- Change process title
- make[1]: *** [net_clone.o] Error 1 HOT 1
- debian packaging [meta] HOT 11
- HTTPS handshake failure on IoT device HOT 2
- ICE: Assertion 'JERRY_CONTEXT (jmem_heap_allocated_size) == 0 HOT 2
- CVE-2020-29657 (reported by debian) HOT 1
- Memory leak when port sqlite to iotjs napi
- What's the dockerfile for iotjs/ubuntu HOT 2
- MQTT client can not works with mosquitto version 1.6.9 HOT 1
- test_fs_callbacks_called occationally failed.
- snapshort tool doesn't support unicode literal.
- An implementation of AS_JERRY_VALUE and AS_NAPI_VALUE to resolve NULL is integer problem.
- SegFault on require for JS module which uses RegEx with iotjs snapshots
- Invalid response when large file piped to http response HOT 1
- Buffer not accessible using the index position HOT 1
- Invalid http response with slow network
- IoT.js unexpectedly exits (caused by SIGPIPE) when the active socket is closed by the client HOT 1
- build failed HOT 1
- build failed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iotjs.