PORT
Ameba SDK » HAL

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

  obj | gpio port object define in application software.

  dir

  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_init | ( | port_t * | obj,
|  | PortName | port,
|  | int | mask,
|  | PinDirection | dir
| ) |  |

Initializes the GPIO device port, include data direction registers.

Parameters

  obj | gpio port object define in application software.

  port

  PortName 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

  mask | One bit one gpio pin, select one or multiple pins of the specified port.

  dir

  gpio 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

  obj | gpio port object define in application software.

  mode

  this 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

  port

  PortName 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_n | pin 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

  obj | gpio 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

  obj | gpio port object define in application software.
  value | One 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