You can control the OSIF's GPIO output by setting a single 8 bit byte representing all 6 gpios.
The OSIF API has many GPIO functions, but a simplistic setup, turning on LED connected to GPIO 0 (TX) and 1 (RX) would be to send the following:
OSIF_init(); // initialise OSIF
OSIF_io_set_ddr(0, 0xFF, 0xFF); // enable all pins as output (including disabling I2C)
OSIF_io_set_ddr(0, 0xCF, 0xCF); // enable all pins as output (EXCLUDING disabling I2C)
OSIF_io_set_out(0, 3, 1) // set the gpios 1 + 2 high by setting the whole byte
OSIF_io_set_out1(0, 3, 1) // using gpio number, set gpio 3 high
...
IO Pins
OSIF has 6 general purpose IO pins (GPIO) that can be used for various functions.
Here are the GPIO pins as designated on the board labels, and their GPIO number:
GPIO 0 TX line
GPIO 1 RX line
GPIO 2 MISO
GPIO 3 MOSI
GPIO 4 SDA
GPIO 5 SCL
Note that GPIO 4 and 5 overlap with the I2C functionality and if set as outputs will disable the I2C feature.
API use
Direction
You can set the gpio pin as either an input or an output using the function
OSIF_io_set_ddr(int adapter_number,int direction, int enabled);
OSIF_io_set_ddr(0, 0xCF, 0xCF); // enable all pins except I2C
The int direction holds the bit values of all of the pin direction states. Setting a bit to 1 will set it as an output, while 0 is input.
This function will also disable the I2C module if you attempt to set the I2C GPIOs 4 + 5 as input/output.
the int enabled is of limited use, but can be used to set a gpio "disabled" (0) this means any future writes will not affect the current state. Can be used as a locking bit mask for the ports.
Output high or low
A GPIO is set to the high or low state (if set as output) by writing an 8 bit value representing the bits of the GPIOS.
OSIF_io_set_out(int adapter_num, int gpios_value, int high_low)
OSIF_io_set_out(0, 3, 1) // set the gpios 1 + 2 high by setting the whole byte
OSIF_io_set_out1(adapter_num, int gpio_num, int high_low)
OSIF_io_set_out1(0, 3, 1) // using gpio number, set gpio 3 high
gpios_value: set all 6 gpio states vis one byte
gpio_num: using out1 you may specify a GPIO to set by it's number
high_low: 1 for pin high, 0 for low
Input
gpios = OSIF_io_get_in(adapter);
returns the current gpio states masked in an 8 bit int 1. high 0 low
![View your cart items []](/sites/all/modules/ecommerce/cart/images/cart_full.png)