1 /** mbed Microcontroller Library
2   ******************************************************************************
3   * @file    port_api.h
4   * @author
5   * @version V1.0.0
6   * @brief   This file provides following mbed GPIO PORT API
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2006-2013 ARM Limited
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   *     http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   ******************************************************************************
24   */
25 #ifndef MBED_PORTMAP_H
26 #define MBED_PORTMAP_H
27 
28 #include "device.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /** @addtogroup port PORT
35  *  @ingroup    hal
36  *  @brief      port functions
37  *  @{
38  */
39 
40 ///@name Ameba Common
41 ///@{
42 
43 typedef struct port_s port_t;
44 
45 /**
46   * @brief  Initializes the GPIO device port, include data direction registers.
47   * @param  obj: gpio port object define in application software.
48   * @param  port: PortName according to pinmux spec, this parameter can be one of the following values:
49   *		@arg PortA: port A, has 32 pins
50   *		@arg PortB: port B, has 7 pins
51   * @param  mask: One bit one gpio pin, select one or multiple pins of the specified port.
52   * @param  dir: gpio port direction, this parameter can be one of the following values:
53   *		@arg PIN_INPUT: port pins are input
54   *		@arg PIN_OUTPUT: port pins are output
55   * @retval none
56   */
57 void port_init(port_t *obj, PortName port, int mask, PinDirection dir);
58 
59 /**
60   * @brief  Get GPIO port pin name
61   * @param  port: PortName according to pinmux spec, this parameter can be one of the following values:
62   *		@arg PortA: port number is A, has 32 pins
63   *		@arg PortB: port number is B, has 7 pins
64   * @param  pin_n: pin number.
65   * @retval none
66   * @note  pin_n must be set to a value in the 0~31 range when PortA
67   * @note  pin_n must be set to a value in the 0~6 range when PortB
68   */
69 PinName port_pin(PortName port, int pin_n);
70 
71 /**
72   * @brief  Configure GPIO port pins pull up/pull down.
73   * @param  obj: gpio port object define in application software.
74   * @param  mode: this parameter can be one of the following values:
75   *		@arg PullNone: HighZ
76   *		@arg OpenDrain(is OpenDrain output): no pull + OUT + GPIO[gpio_bit] = 0
77   *		@arg PullDown: pull down
78   *		@arg PullUp: pull up
79   * @retval none
80   */
81 void port_mode(port_t *obj, PinMode mode);
82 
83 /**
84   * @brief  Set GPIO port pins data direction.
85   * @param  obj: gpio port object define in application software.
86   * @param  dir: this parameter can be one of the following values:
87   *		@arg PIN_INPUT: port pins are input
88   *		@arg PIN_OUTPUT: port pins are output
89   * @retval none
90   */
91 void port_dir(port_t *obj, PinDirection dir);
92 
93 /**
94   * @brief  Sets value to the selected port pins.
95   * @param  obj: gpio port object define in application software.
96   * @param  value: One bit one gpio pin, set value to one or multiple pins of the specified port.
97   * @retval none
98   * @note corresponding bit is 1, pin state set to high; corresponding bit is 0, pin state set to low
99   */
100 void port_write(port_t *obj, int value);
101 
102 /**
103   * @brief  Reads the specified gpio port pins.
104   * @param  obj: gpio port object define in application software.
105   * @retval : state of the specified gpio port pins
106   * @note corresponding bit is 1, pin state is high; corresponding bit is 0, pin state is low
107   */
108 int port_read(port_t *obj);
109 
110 ///@}
111 /*\@}*/
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif
117