Before any operations related to GPIOs, the following function must be called to initialize the system:

julia> init_gpio()

This function opens the device /dev/gpiomem. Thus, make sure that the user has permissions to read and write this file.

GPIO mode

The mode of a GPIO can be set by the function gpio_set_mode, which has the following signatures:

gpio_set_mode(gpio::Int, mode::Symbol)
gpio_set_mode(gpio::AbstractVector{Int}, mode::Symbol)

In the former, the GPIO gpio will be set to mode, and, in the later, all the GPIOs in the vector gpio will be set to mode.

mode must be one of the following symbols:

The current GPIO mode can be retrieved by the function gpio_get_mode, which has the following signature:


This function returns symbol with the current mode of gpio using the same convention as shown before.

julia> gpio_set_mode(9, :out)

julia> gpio_get_mode(9)

julia> gpio_set_mode(9, :alt0)

julia> gpio_get_mode(9)

julia> gpio_set_mode(9:11, :alt0)

julia> gpio_get_mode.(9:11)
3-element Array{Symbol,1}:

GPIO functions

The following functions can be used to set a GPIO, i.e., change it to the logic level 1.


The former set the GPIO gpio, whereas the later set all GPIOs in the vector gpio.

julia> gpio_set(5)

julia> gpio_set(1:10)

No check is performed to verify which is the current mode of the GPIO. The user must take care to set those GPIOs mode to :out.

The input from a GPIO can be read by the function gpio_read, which has the following signature:


It returns true if the GPIO gpio is in high logic level, or false otherwise.

julia> gpio_read(5)

julia> gpio_read(5)

It is also possible to use the function gpio_value to set all the GPIOs to a specific value:


where the bits that are 0 will be cleared, and the bits that are 1 will be set. Another possibility is to pass to gpio_value a BitVector, which will perform the same operation considering the values on the vector.

julia> gpio_value(0)        # ................................ Clears all GPIOs.

julia> gpio_set(0xFFFFFFFF) # .................................. Sets all GPIOs.

julia> gpio_set(0xAAAAAAAA) # .... Sets the even GPIOs and clears the odd GPIOs.

The bits higher than 27, which are the number of GPIOs, are just ignored.


See the example LED.