LED and General Purpose I/O

Nano-RK has two ways of addressing general purpose input/output (gpio) pins; platform independent gpio functions and raw gpio functions. The prefered method is to use the standard platform independent gpio functions. These use registered pins with _NRK+ prefixed before them. These pins are registered in the nrk_pin_define.h file for a particular platform. Each pin is a variable that has the port as well as pin value encoded in it for a particular platform. The raw gpio functions are macros that directly access the port values. Using these functions may be faster, however they are macro functions specific to a particular architecture. These functions also bypass Nano-RK's ability to perform recording keeping on I/O operations and hence can be considered dangerous.

Pin mappings:

For a complete list of pin defines please see: FireFly3 , FireFly3_x2

int8_t nrk_gpio_set(uint8_t pin)

This function sets the output value of a gpio pin high. It returns NRK_OK upon success and NRK_ERROR upon failure.

val=nrk_gpio_set(NRK_GPIO34);

int8_t nrk_gpio_clr(uint8_t pin)

This function sets the output value of a gpio pin low. It returns NRK_OK upon success and NRK_ERROR upon failure.

val=nrk_gpio_clr(NRK_SPI_SS);

int8_t nrk_gpio_toggle(uint8_t pin)

This function reads the current value of the gpio pin and then changes it. It returns NRK_OK upon success and NRK_ERROR upon failure.

val=nrk_gpio_toggle(NRK_LED_0);

int8_t nrk_gpio_direction(uint8_t pin, uint8_t pin_direction)

This function sets a gpio pin as input or output . Use NRK_PIN_INPUT to set the pin as an input, or use
NRK_PIN_OUTPUT to set the pin as an output. This function returns NRK_OK upon success and NRK_ERROR upon failure.

val=nrk_gpio_direction(NRK_BUTTON, NRK_PIN_INPUT);

int8_t nrk_gpio_get(uint8_t pin)

This function reads the current binary value of the gpio pin and returns 1 or 0. This function returns NRK_ERROR upon failure.

val=nrk_gpio_get(NRK_BUTTON);

_int8_t nrk_gpio_pullups(uint8_t enable)*

This function enables and disables pullup resistors that are controlled by many MCU gpio registers. Setting enable to 1 connects the resistors while setting it to 0 disconnects them. This function returns NRK_OK upon success and NRK_ERROR upon failure. For MCUs that do not have pullup control this function will always return NRK_ERROR.

val=nrk_gpio_get(NRK_BUTTON);

void nrk_gpio_raw_set( _port, _pin )

void nrk_gpio_raw_clr( _port, _pin )

void nrk_gpio_raw_get( _port, _pin )

void nrk_gpio_raw_toggle( _port, _pin)


int8_t nrk_led_set( uint8_t num )

This function sets an LED based on number starting from 0. If the LED number does
not exist on your particular platform configuration 0 is returned. Upon success, the
LED should light and NRK_OK will be returned. NRK_ERROR is returned upon error.

int8_t nrk_led_clr( uint8_t num )

This function clears an LED based on number starting from 0. If the LED number does
not exist on your particular platform configuration 0 is returned. Upon success, the
LED should turn off and NRK_OK will be returned. NRK_ERROR is returned upon error.

int8_t nrk_led_toggle( uint8_t num )

This function toggles the LED. If the LED was previously on, it is turned off. If the LED was off, it is turned on. This function returns NRK_OK upon success, and NRK_ERROR upon error.

Prev: Device Drivers Next: Resource Reservations Top