Overview

This part of the platform interface deals with PIO (Programmable Input Output) operations, thus letting the user access the low level input/output facilities of the host MCU.

Data structures, constants and types

enum
{
  // Pin operations
  PLATFORM_IO_PIN_SET,                  // Set the pin to 1
  PLATFORM_IO_PIN_CLEAR,                // Clear the pin (set it to 0)
  PLATFORM_IO_PIN_GET,                  // Get the value of the pin
  PLATFORM_IO_PIN_DIR_INPUT,            // Make the pin an input
  PLATFORM_IO_PIN_DIR_OUTPUT,           // Make the pin an output
  PLATFORM_IO_PIN_PULLUP,               // Activate the pullup on the pin
  PLATFORM_IO_PIN_PULLDOWN,             // Activate the pulldown on the pin
  PLATFORM_IO_PIN_NOPULL,               // Disable all pullups/pulldowns on the pin
  // Port operations
  PLATFORM_IO_PORT_SET_VALUE,           // Set port value
  PLATFORM_IO_PORT_GET_VALUE,           // Get port value
  PLATFORM_IO_PORT_DIR_INPUT,           // Set port as input
  PLATFORM_IO_PORT_DIR_OUTPUT           // Set port as output
}; 

These are the operations that can be executed by the PIO subsystem on both ports and pins. They are given as arguments to the platform_pio_op function shown below.

typedef u32 pio_type;

This is the type used for the actual I/O operations. Currently defined as an unsigned 32-bit type, thus no port can have more than 32 pins. If this happens, it is possible to split it in two or more parts and adding the new parts as "virtual ports" (logical ports that don't have a direct hardware equivalent). The "virtual port" technique is used in the AVR32 backend.

Functions

int platform_pio_has_port( unsigned port );

Checks if the platform has the hardware port specified as argument. Implemented in src/common.c, it uses the NUM_PIO macro that must be defined in the platform's platform_conf.h file (see here for details). For example:

#define NUM_PIO   4      // The platform has 4 hardware PIO ports

Arguments: port - the port ID

Returns: 1 if the port exists, 0 otherwise

int platform_pio_has_pin( unsigned port, unsigned pin );

Checks if the platform has the hardware port and pin specified as arguments. Implemented in src/common.c, it uses the NUM_PIO macro to check the validity of the port and the PIO_PINS_PER_PORT or PIO_PIN_ARRAY macros to check the validity of the pin. The macros must be defined in the platform's platform_conf.h file (see here for details).

Arguments:

Returns: 1 if the pin exists, 0 otherwise

const char* platform_pio_get_prefix( unsigned port );

Get the port prefix. Used to establish if the port notation uses numbers (P0, P1, P2...) or letters (PA, PB, PC...). Implemented in src/common.c, it uses the PIO_PREFIX macro that must be defined in the platform's platform_conf.h file (see here for details). The value of this macro can be either '0' (for numeric notation) or 'A' (for letter notation). For example:

#define PIO_PREFIX    'A'   // Use PA, PB, PC ... for port notation

Arguments: port - the port ID

Returns: the port prefix (either '0' or 'A')

pio_type platform_pio_op( unsigned port, pio_type pinmask, int op );

This is the function that does the actual I/O work. It is implemented in the platform's own porting layer (platform.c, see here for more details).

Arguments:

Returns: