@@ -28,7 +28,8 @@ SOFTWARE.
2828 * @param pin The pin to be set as GPIO
2929 * @return The GPIO port mask for this pin
3030 **/
31- uint32_t gpio_set (PinName pin ){
31+ uint32_t gpio_set (PinName pin )
32+ {
3233 MBED_ASSERT (pin != (PinName )NC );
3334 return (uint32_t )AM_HAL_GPIO_BIT (pin );
3435}
@@ -38,7 +39,8 @@ uint32_t gpio_set(PinName pin){
3839 * @return 0 if object was initialized with NC
3940 * @return non-zero if object was initialized with a valid PinName
4041 **/
41- int gpio_is_connected (const gpio_t * obj ){
42+ int gpio_is_connected (const gpio_t * obj )
43+ {
4244 MBED_ASSERT (obj != NULL );
4345 return (int )(((PinName )obj -> pad == (PinName )NC ) ? 0 : 1 );
4446}
@@ -48,82 +50,170 @@ int gpio_is_connected(const gpio_t *obj){
4850 * @param obj The GPIO object to initialize
4951 * @param pin The GPIO pin to initialize (may be NC)
5052 */
51- void gpio_init (gpio_t * obj , PinName pin ){
53+ void gpio_init (gpio_t * obj , PinName pin )
54+ {
5255 MBED_ASSERT (obj != NULL );
5356 obj -> pad = (ap3_uart_pad_t )pin ;
5457 return ;
5558}
56-
5759/** Set the input pin mode
5860 *
5961 * @param obj The GPIO object (must be connected)
6062 * @param mode The pin mode to be set
6163 */
62- void gpio_mode (gpio_t * obj , PinMode mode ){
64+ void gpio_mode (gpio_t * obj , PinMode mode )
65+ {
6366 MBED_ASSERT (gpio_is_connected (obj ));
6467 MBED_ASSERT (mode < (PinMode )PinModeElements );
68+ am_hal_gpio_pincfg_allow_t pinConfigBools ;
6569
66- obj -> cfg .uFuncSel = 3 ; // gpio
70+ obj -> cfg .uFuncSel = AP3_PINCFG_FUNCSEL_GPIO ; // gpio
6771
68- if ( mode & (PinMode )PowerSwNone ){ obj -> cfg .ePowerSw = AM_HAL_GPIO_PIN_POWERSW_NONE ; }
69- if ( mode & (PinMode )PowerSwVDD ){ obj -> cfg .ePowerSw = AM_HAL_GPIO_PIN_POWERSW_VDD ; }
70- if ( mode & (PinMode )PowerSwVSS ){ obj -> cfg .ePowerSw = AM_HAL_GPIO_PIN_POWERSW_VSS ; }
72+ if (mode & (PinMode )PowerSwNone )
73+ {
74+ obj -> cfg .ePowerSw = AM_HAL_GPIO_PIN_POWERSW_NONE ;
75+ pinConfigBools .powerSw = true;
76+ }
77+ if (mode & (PinMode )PowerSwVDD )
78+ {
79+ obj -> cfg .ePowerSw = AM_HAL_GPIO_PIN_POWERSW_VDD ;
80+ pinConfigBools .powerSw = true;
81+ }
82+ if (mode & (PinMode )PowerSwVSS )
83+ {
84+ obj -> cfg .ePowerSw = AM_HAL_GPIO_PIN_POWERSW_VSS ;
85+ pinConfigBools .powerSw = true;
86+ }
7187
72- if ( mode & (PinMode )PullNone ){ obj -> cfg .ePullup = AM_HAL_GPIO_PIN_PULLUP_NONE ; }
73- if ( mode & (PinMode )PullUp ){ obj -> cfg .ePullup = AM_HAL_GPIO_PIN_PULLUP_WEAK ; }
74- if ( mode & (PinMode )PullDown ){ obj -> cfg .ePullup = AM_HAL_GPIO_PIN_PULLDOWN ; }
88+ if (mode & (PinMode )PullNone )
89+ {
90+ obj -> cfg .ePullup = AM_HAL_GPIO_PIN_PULLUP_NONE ;
91+ pinConfigBools .pullup = true;
92+ }
93+ if (mode & (PinMode )PullUp )
94+ {
95+ obj -> cfg .ePullup = AM_HAL_GPIO_PIN_PULLUP_WEAK ;
96+ pinConfigBools .pullup = true;
97+ }
98+ if (mode & (PinMode )PullDown )
99+ {
100+ obj -> cfg .ePullup = AM_HAL_GPIO_PIN_PULLDOWN ;
101+ pinConfigBools .pullup = true;
102+ }
75103
76- if ( mode & (PinMode )DriveStrength2mA ){ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_2MA ; }
77- if ( mode & (PinMode )DriveStrength4mA ){ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_4MA ; }
78- if ( mode & (PinMode )DriveStrength8mA ){ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_8MA ; }
79- if ( mode & (PinMode )DriveStrength12mA ){ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA ; }
104+ if (mode & (PinMode )DriveStrength2mA )
105+ {
106+ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_2MA ;
107+ pinConfigBools .driveStrength = true;
108+ }
109+ if (mode & (PinMode )DriveStrength4mA )
110+ {
111+ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_4MA ;
112+ pinConfigBools .driveStrength = true;
113+ }
114+ if (mode & (PinMode )DriveStrength8mA )
115+ {
116+ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_8MA ;
117+ pinConfigBools .driveStrength = true;
118+ }
119+ if (mode & (PinMode )DriveStrength12mA )
120+ {
121+ obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA ;
122+ pinConfigBools .driveStrength = true;
123+ }
80124
81- if ( mode & (PinMode )OutDisable ){ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_DISABLE ; }
82- if ( mode & (PinMode )OutPushPull ){ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL ; }
83- if ( mode & (PinMode )OutOpenDrain ){ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN ; }
84- if ( mode & (PinMode )OutTristate ){ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_TRISTATE ; }
125+ if (mode & (PinMode )OutDisable )
126+ {
127+ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_DISABLE ;
128+ pinConfigBools .gpOutcfg = true;
129+ }
130+ if (mode & (PinMode )OutPushPull )
131+ {
132+ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL ;
133+ pinConfigBools .gpOutcfg = true;
134+ }
135+ if (mode & (PinMode )OutOpenDrain )
136+ {
137+ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN ;
138+ pinConfigBools .gpOutcfg = true;
139+ }
140+ if (mode & (PinMode )OutTristate )
141+ {
142+ obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_TRISTATE ;
143+ pinConfigBools .gpOutcfg = true;
144+ }
85145
86- if ( mode & (PinMode )InAuto ){ obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_AUTO ; }
87- if ( mode & (PinMode )InNone ){ obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_NONE ; }
88- if ( mode & (PinMode )InEnable ){ obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_ENABLE ; }
146+ if (mode & (PinMode )InAuto )
147+ {
148+ obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_AUTO ;
149+ pinConfigBools .gpInput = true;
150+ }
151+ if (mode & (PinMode )InNone )
152+ {
153+ obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_NONE ;
154+ pinConfigBools .gpInput = true;
155+ }
156+ if (mode & (PinMode )InEnable )
157+ {
158+ obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_ENABLE ;
159+ pinConfigBools .gpInput = true;
160+ }
89161
90- if ( mode & (PinMode )ReadPin ){ obj -> cfg .eGPRdZero = AM_HAL_GPIO_PIN_RDZERO_READPIN ; }
91- if ( mode & (PinMode )ReadZero ){ obj -> cfg .eGPRdZero = AM_HAL_GPIO_PIN_RDZERO_ZERO ; }
162+ if (mode & (PinMode )ReadPin )
163+ {
164+ obj -> cfg .eGPRdZero = AM_HAL_GPIO_PIN_RDZERO_READPIN ;
165+ pinConfigBools .gprdZero = true;
166+ }
167+ if (mode & (PinMode )ReadZero )
168+ {
169+ obj -> cfg .eGPRdZero = AM_HAL_GPIO_PIN_RDZERO_ZERO ;
170+ pinConfigBools .gprdZero = true;
171+ }
92172
93- am_hal_gpio_pinconfig ((uint32_t )(obj -> pad ), obj -> cfg ); // apply configuration
173+ ap3_hal_gpio_pinconfig_partial ((uint32_t )(obj -> pad ), obj -> cfg , pinConfigBools ); //padRegMsk.byte, GPConfigMsk.byte, padAltCfgMsk.byte ); // apply configuration
94174}
95175
96176/** Set the pin direction
97177 *
98178 * @param obj The GPIO object (must be connected)
99179 * @param direction The pin direction to be set
100180 */
101- void gpio_dir (gpio_t * obj , PinDirection direction ){
181+ void gpio_dir (gpio_t * obj , PinDirection direction )
182+ {
102183 MBED_ASSERT (gpio_is_connected (obj ));
103184 MBED_ASSERT (direction < (PinDirection )PIN_DIR_ELEMENTS );
185+ am_hal_gpio_pincfg_allow_t pinConfigBools ;
104186
105- if ( direction == (PinDirection )PIN_INPUT ){
187+ if (direction == (PinDirection )PIN_INPUT )
188+ {
106189 obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_ENABLE ;
190+ pinConfigBools .gpInput = true;
107191 obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_DISABLE ;
192+ pinConfigBools .gpOutcfg = true;
108193 }
109- else if ( direction == (PinDirection )PIN_OUTPUT ){
194+ else if (direction == (PinDirection )PIN_OUTPUT )
195+ {
110196 obj -> cfg .eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL ;
197+ pinConfigBools .gpOutcfg = false;
111198 obj -> cfg .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA ;
112- obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_ENABLE ;
113- obj -> cfg .eGPRdZero = AM_HAL_GPIO_PIN_RDZERO_READPIN ;
114- }else {
199+ obj -> cfg .eGPInput = AM_HAL_GPIO_PIN_INPUT_NONE ;
200+ pinConfigBools .gpInput = false;
201+ }
202+ else
203+ {
115204 MBED_ASSERT (false);
116205 }
117206
118- am_hal_gpio_pinconfig ((uint32_t )(obj -> pad ), obj -> cfg ); // apply configuration
207+ ap3_hal_gpio_pinconfig_partial ((uint32_t )(obj -> pad ), obj -> cfg , pinConfigBools ); //padRegMsk.byte, GPConfigMsk.byte, padAltCfgMsk.byte ); // apply configuration
119208}
120209
121210/** Set the output value
122211 *
123212 * @param obj The GPIO object (must be connected)
124213 * @param value The value to be set
125214 */
126- void gpio_write (gpio_t * obj , int value ){
215+ void gpio_write (gpio_t * obj , int value )
216+ {
127217 MBED_ASSERT (gpio_is_connected (obj ));
128218 (value ) ? am_hal_gpio_output_set (obj -> pad ) : am_hal_gpio_output_clear (obj -> pad );
129219}
@@ -133,7 +223,8 @@ void gpio_write(gpio_t *obj, int value){
133223 * @param obj The GPIO object (must be connected)
134224 * @return An integer value 1 or 0
135225 */
136- int gpio_read (gpio_t * obj ){
226+ int gpio_read (gpio_t * obj )
227+ {
137228 MBED_ASSERT (gpio_is_connected (obj ));
138229 uint32_t ui32BaseAddr = (obj -> pad ) / 8 ;
139230 uint32_t ui32BaseShift = (((obj -> pad ) % 8 ) * 4 ) + 1 ;
@@ -153,7 +244,8 @@ int gpio_read(gpio_t *obj){
153244 *
154245 * @return PinMap array
155246 */
156- const PinMap * gpio_pinmap (void ){
247+ const PinMap * gpio_pinmap (void )
248+ {
157249 MBED_ASSERT (false);
158250 return NULL ;
159- }
251+ }
0 commit comments