GPIO, aka General Purpose Input Output, is a common hardware interface, which usually acts as a switch.
To know more about GPIO, please visit here.
- Visit here if you have no idea how to write application with Ruff.
- Visit Driver Getting Started and Driver Model, if you have no idea about driver development.
Please read your datasheet to confirm your interface is GPIO.
Please declare your interface is GPIO in driver.json. The declaration should be inputs with type as GPIO.
The following properties is accepted for GPIO:
direction, which defines interface direction
in, input mode, which reads data from interface, or responses a particular interrut. For instance, a button could do something for user input, or read current state to know if the button is pressed.
out, output mode, to control device. For instance, LED could be defined as output to turn on/off LED.
edge, which controls interrupt events, could be one of
This argument takes effect only if
directionis set to
rising, the electrical level rose from low to high
falling, the electrical level fell from high to low
both, both rising and falling
level, which defines initial electrical level of the interface, This argument takes effect only if
directionis set to
high, the initial electrical level is defined as
low, the initial electrical level is defined as
Interrupt will be triggered in GPIO
in mode. The driver could trigger different event based on different input value. An example is as follows:
// Driver Code
// Application Code
The driver could write
Level.low to interface in GPIO
out mode. An example is as follows:
var Level = require('gpio').Level;
Please visit GPIO API document to know more defails.
Push button module has an input GPIO with both edge. You can declare it in driver.json.
Push button module could emit
release event. You will listen
interrupt event and trigger
release based on button current state.
Buzzer has an output GPIO, trigged with high electrical level. You can declare it in driver.json: type as GPIO, direction as out, level as low.
We provides buzzer with three methods: turn on the buzzer, turn off the buzzer and judge if buzzer is on：
- turnOn, write Level.high to GPIO to turn on the buzzer
- turnOff, write Level.low to GPIO to turn off the buzzer
- isOn, read GPIO to know if buzzer is on