A31G11x F/W Packages  2.5.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
A31G11x_hal_pcu.c
Go to the documentation of this file.
1 /***************************************************************************//****************************************************************************/
34 
35 /* Includes ----------------------------------------------------------------- */
36 //******************************************************************************
37 // Include
38 //******************************************************************************
39 
40 #include "A31G11x_hal_pcu.h"
41 
42 /* Public Functions --------------------------------------------------------- */
43 //******************************************************************************
44 // Function
45 //******************************************************************************
46 
47 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
64 void HAL_GPIO_Init( Pn_Type* Px, uint32_t u32Mode, uint32_t u32Type, uint32_t u32Afsr1, uint32_t u32PuPd )
65 {
66  Px->MOD = u32Mode; // 00/01/10/11: Input/Output/"Alternative Function"/Reserved Mode
67  Px->TYP = u32Type; // 0/1: Push-pull/Open-drain Output
68  Px->AFSR1 = u32Afsr1; // 0 to 4: Alternative Function 0 to 4
69  Px->PUPD = u32PuPd; // 00/01/10/11: "Disable Pull-up/down"/"Enable Pull-up"/"Enable Pull-down"/Reserved Resistor
70 }
71 
72 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
86 void HAL_GPIO_ConfigFunction( Pn_Type* Px, uint8_t pin_no, uint32_t func )
87 {
88  uint8_t pin_offset;
89  uint32_t reg_val;
90 
91  if( pin_no < 8 ) // 0~7
92  {
93  //--------------------------------------
94  // pin_offset = pin_no * 4
95  //--------------------------------------
96  pin_offset = ( pin_no * 4 );
97 
98  //--------------------------------------
99  // MR
100  //--------------------------------------
101  reg_val = Px->AFSR1;
102  reg_val &= ~( AFSRx_Msk << pin_offset );
103  reg_val |= ( func << pin_offset );
104 
105  Px->AFSR1 = reg_val;
106  }
107 }
108 
109 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
126 void HAL_GPIO_ConfigOutput( Pn_Type* Px, uint8_t pin_no, PCU_PORT_MODE dir_type )
127 {
128  uint8_t pin_offset;
129  uint32_t reg_val;
130  uint32_t dir_type_temp;
131 
132  dir_type_temp = dir_type;
133  if( dir_type_temp == OPEN_DRAIN_OUTPUT )
134  {
135  dir_type = PUSH_PULL_OUTPUT;
136  }
137  //--------------------------------------
138  // pin_offset = pin_no * 2
139  //--------------------------------------
140  pin_offset = ( pin_no << 1 );
141 
142  //--------------------------------------
143  // Pn_MOD
144  //--------------------------------------
145  reg_val = Px->MOD;
146  reg_val &= ~( MODEx_Msk << pin_offset );
147  reg_val |= ( dir_type << pin_offset );
148  Px->MOD = reg_val;
149 
150  //--------------------------------------
151  // Pn_TYP
152  //--------------------------------------
153  if( ( dir_type_temp == PUSH_PULL_OUTPUT ) || ( dir_type_temp == OPEN_DRAIN_OUTPUT ) )
154  {
155  reg_val = Px->TYP;
156  reg_val &= ~( 1 << pin_no );
157  if( dir_type_temp == OPEN_DRAIN_OUTPUT )
158  {
159  reg_val |= ( 1 << pin_no );
160  }
161  Px->TYP = reg_val;
162  }
163 }
164 
165 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
180 void HAL_GPIO_ConfigOutDataMask( Pn_Type* Px, uint8_t pin_no, FunctionalState maskctrl )
181 {
182  uint32_t reg_val;
183 
184  reg_val = Px->OUTDMSK;
185  reg_val &= ~( 1 << pin_no );
186  reg_val |= ( maskctrl << pin_no );
187  Px->OUTDMSK = reg_val;
188 }
189 
190 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
206 void HAL_GPIO_ConfigPullup( Pn_Type* Px, uint8_t pin_no, uint8_t pullupdown )
207 {
208  uint32_t reg_val;
209  uint8_t pin_offset;
210 
211  pin_offset = ( pin_no << 1 );
212 
213  reg_val = Px->PUPD;
214  reg_val &= ~( 3 << pin_offset );
215  reg_val |= ( pullupdown << pin_offset );
216  Px->PUPD = reg_val;
217 }
218 
219 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
241 void HAL_GPIO_SetDebouncePin( Pn_Type* Px, uint32_t u32Pins, uint32_t u32Debnc )
242 {
243 #if 0 // before bug fix
244  uint32_t reg_val;
245 
246  reg_val = ( 0x00ff & Px->DBCR );
247  reg_val |= ( 0x01 << u32Pins );
248  reg_val |= u32Debnc;
249  Px->DBCR = reg_val;
250 #else // after bug fix
251  Px->DBCR = Px->DBCR
252  & ~Pn_DBCR_DBCLK_Msk
253  | ( 1 << u32Pins )
254  | u32Debnc
255  ;
256 #endif
257 }
258 
259 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
271 void HAL_GPIO_SetPin( Pn_Type* Px, uint16_t bitValue )
272 {
273  Px->BSR = bitValue;
274 }
275 
276 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
288 void HAL_GPIO_ClearPin( Pn_Type* Px, uint16_t bitValue )
289 {
290  Px->BCR = bitValue;
291 }
292 
293 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
303 void HAL_GPIO_WritePin( Pn_Type* Px, uint16_t Value )
304 {
305  Px->OUTDR = Value;
306 }
307 
308 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
318 uint16_t HAL_GPIO_ReadPin( Pn_Type* Px )
319 {
320  return Px->INDR;
321 }
322 
void HAL_GPIO_ClearPin(Pn_Type *Px, uint16_t bitValue)
Clear Value for bits that have output direction on GPIO port.
Contains all macro definitions and function prototypes support for pcu firmware library on A31G11x.
void HAL_GPIO_ConfigOutput(Pn_Type *Px, uint8_t pin_no, PCU_PORT_MODE dir_type)
Configure pin mode.
void HAL_GPIO_SetPin(Pn_Type *Px, uint16_t bitValue)
Set Value for bits that have output direction on GPIO port.
void HAL_GPIO_ConfigOutDataMask(Pn_Type *Px, uint8_t pin_no, FunctionalState maskctrl)
Configure out data Mask.
void HAL_GPIO_ConfigFunction(Pn_Type *Px, uint8_t pin_no, uint32_t func)
Configure pin function.
void HAL_GPIO_WritePin(Pn_Type *Px, uint16_t Value)
Write Value on port that have output direction of GPIO.
FunctionalState
void HAL_GPIO_SetDebouncePin(Pn_Type *Px, uint32_t u32Pins, uint32_t u32Debnc)
Set PCU Debounce.
void HAL_GPIO_Init(Pn_Type *Px, uint32_t u32Mode, uint32_t u32Type, uint32_t u32Afsr1, uint32_t u32PuPd)
Set PCU Pn_MOD/Pn_TYP/Pn_AFSR1/Pn_PUPD Registers.
PCU_PORT_MODE
uint16_t HAL_GPIO_ReadPin(Pn_Type *Px)
Read Current state on port pin that have input direction of GPIO.
void HAL_GPIO_ConfigPullup(Pn_Type *Px, uint8_t pin_no, uint8_t pullupdown)
Configure Pin Pull-Up & Pull-Down.