Setting Digital I/O


Before using digital I/O, setting each port is required. To set it, set command of pid_ioctl function is used.

pid_ioctl($pid, "set N1[-N2] mode TYPE");

N1 and N2 indicate a range of multiple ports. You can only use N1 in the case of setting a single port.

Setting to Input and Output

Available i/o types are as follows:

TYPE Description
in Digital Input
in_pu Digital Input: Pull-Up
in_pd Digital Input: Pull-Down
out - Digital Output
low Digital Output: default LOW
high Digital Output: default HIGH
toggle Digital Output: default TOGGLE
out_pp - Digital Output: Push-Pull
low Digital Output: Push-Pull + default LOW
high Digital Output: Push-Pull + default HIGH
toggle Digital Output: Push-Pull + default TOGGLE
out_od - Digital Output: Open-Drain
low Digital Output: Open-Drain + default LOW
high Digital Output: Open-Drain + default HIGH
toggle Digital Output: Open-Drain + default TOGGLE

Input Port Pull-Up

Pull-Up makes a default state of a input port to HIGH. To do this, set the TYPE of the input port to in_pu.

Input Port Pull-Down

Pull-Down makes a default state of input port to LOW. To do this, set the TYPE of the input port to in_pd.

Output Port Push-Pull

Push-Pull is a basic output mode which makes a state of output port to HIGH when it is ON and LOW when it is OFF. To do this, set the TYPE of output port to out_pp.

Output Port Open-Drain

This can be used when you want to connect external power source to an output port. The state of output port will be LOW when it is OFF and UNKNOWN when it is ON if you do not connect any external power source while setting the port to open drain. Thus, you need to pull up this pin with an external resistor.

To do this, set the TYPE of output port to out_od.

Setting to LED

Digital I/O ports can be set to one of the LED types. Available types of LED are as follows:

TYPE Description
led_sts System Status LED
led_net0_act
/ led_net1_act
Activation of NET(net0 - wired, net1 - wireless) link LED:
- successfully established network link: LOW
- at the moment sending or receiving network data: HIGH
led_net0_link
/ led_net1_link
Network Link LED: connected to network - LOW
led_net0_rx
/ led_net1_rx
Network Receive LED: at the moment receiving data - LOW
led_net0_tx
/ led_net1_tx
Network Send LED: at the moment sending data - LOW

※ Each LED type cannot be set to two or more output pins.

example of setting digital I/O

<?php
$pid = pid_open("/mmap/uio0");                // open UIO 0
pid_ioctl($pid, "set 0 mode in");             // set port 0 to input
pid_ioctl($pid, "set 1 mode in_pu");          // set port 1 to input: pull-up
pid_ioctl($pid, "set 2 mode in_pd");          // set port 2 to input: pull-down
pid_ioctl($pid, "set 3-6 mode out");          // set port 3 ~ 6 to output
// set port 7 ~ 9 to output with default high
pid_ioctl($pid, "set 7-9 mode out high");
// set port 10 to output with default low
pid_ioctl($pid, "set 10 mode out low");
// set port 11 to output: push-pull with default high
pid_ioctl($pid, "set 11 mode out_pp high");
// set port 12 to output: open-drain with default low
pid_ioctl($pid, "set 12 mode out_od low");
// set port 13 to network link LED
pid_ioctl($pid, "set 13 mode led_net0_link");
// set port 14 to network receive LED
pid_ioctl($pid, "set 14 mode led_net0_rx");
// set port 15 to network send LED
pid_ioctl($pid, "set 15 mode led_net0_tx");
?>

Setting Output Lock

You can lock or unlock to control output ports by using pid_ioctl command. When output lock is enabled, output ports cannot be controlled before they are unlocked.

<?php
pid_ioctl($pid, "set N1[-N2] lock");    // lock
pid_ioctl($pid, "set N1[-N2] unlock");  // unlock
?>

※ Caution: Digital I/O ports can be basically controlled. However, output lock is automatically enabled to ports which are shared with ST, UART, SPI and I2C if they are used.