SDK4.0
This document shows Ameba SDK 4.0 APIs
PORT

port functions More...

Ameba Common

typedef struct port_s port_t
 
void port_init (port_t *obj, PortName port, int mask, PinDirection dir)
 Initializes the GPIO device port, include data direction registers. More...
 
PinName port_pin (PortName port, int pin_n)
 Get GPIO port pin name. More...
 
void port_mode (port_t *obj, PinMode mode)
 Configure GPIO port pins pull up/pull down. More...
 
void port_dir (port_t *obj, PinDirection dir)
 Set GPIO port pins data direction. More...
 
void port_write (port_t *obj, int value)
 Sets value to the selected port pins. More...
 
int port_read (port_t *obj)
 Reads the specified gpio port pins. More...
 

Detailed Description

port functions

Function Documentation

void port_dir ( port_t *  obj,
PinDirection  dir 
)

Set GPIO port pins data direction.

Parameters
objgpio port object define in application software.
dirthis parameter can be one of the following values:
  • PIN_INPUT: port pins are input
  • PIN_OUTPUT: port pins are output
Return values
none
void port_init ( port_t *  obj,
PortName  port,
int  mask,
PinDirection  dir 
)

Initializes the GPIO device port, include data direction registers.

Parameters
objgpio port object define in application software.
portPortName according to pinmux spec, this parameter can be one of the following values:
  • PortA: port A, has 32 pins
  • PortB: port B, has 7 pins
maskOne bit one gpio pin, select one or multiple pins of the specified port.
dirgpio port direction, this parameter can be one of the following values:
  • PIN_INPUT: port pins are input
  • PIN_OUTPUT: port pins are output
Return values
none
void port_mode ( port_t *  obj,
PinMode  mode 
)

Configure GPIO port pins pull up/pull down.

Parameters
objgpio port object define in application software.
modethis parameter can be one of the following values:
  • PullNone: HighZ
  • OpenDrain(is OpenDrain output): no pull + OUT + GPIO[gpio_bit] = 0
  • PullDown: pull down
  • PullUp: pull up
Return values
none
PinName port_pin ( PortName  port,
int  pin_n 
)

Get GPIO port pin name.

Parameters
portPortName according to pinmux spec, this parameter can be one of the following values:
  • PortA: port number is A, has 32 pins
  • PortB: port number is B, has 7 pins
pin_npin number.
Return values
none
Note
pin_n must be set to a value in the 0~31 range when PortA
pin_n must be set to a value in the 0~6 range when PortB
int port_read ( port_t *  obj)

Reads the specified gpio port pins.

Parameters
objgpio port object define in application software.
Return values
state of the specified gpio port pins
Note
corresponding bit is 1, pin state is high; corresponding bit is 0, pin state is low
void port_write ( port_t *  obj,
int  value 
)

Sets value to the selected port pins.

Parameters
objgpio port object define in application software.
valueOne bit one gpio pin, set value to one or multiple pins of the specified port.
Return values
none
Note
corresponding bit is 1, pin state set to high; corresponding bit is 0, pin state set to low