A31G12x F/W Packages  2.5.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
A31G12x_hal_pcu.c
Go to the documentation of this file.
1 /***************************************************************************//****************************************************************************/
34 
35 /* Includes ----------------------------------------------------------------- */
36 //******************************************************************************
37 // Include
38 //******************************************************************************
39 
40 #include "A31G12x_hal_pcu.h"
41 
42 /* Public Functions --------------------------------------------------------- */
43 //******************************************************************************
44 // Function
45 //******************************************************************************
46 
47 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
66 void HAL_GPIO_Init( Pn_Type* Px, uint32_t u32Mode, uint32_t u32Type, uint32_t u32Afsr1, uint32_t u32Afsr2, uint32_t u32PuPd )
67 {
68  Px->MOD = u32Mode; // 00/01/10/11: Input/Output/"Alternative Function"/Reserved Mode
69  Px->TYP = u32Type; // 0/1: Push-pull/Open-drain Output
70  Px->AFSR1 = u32Afsr1; // 0 to 4: Alternative Function 0 to 4
71  Px->AFSR2 = u32Afsr2; // 0 to 4: Alternative Function 0 to 4
72  Px->PUPD = u32PuPd; // 00/01/10/11: "Disable Pull-up/down"/"Enable Pull-up"/"Enable Pull-down"/Reserved Resistor
73 }
74 
75 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
89 void HAL_GPIO_ConfigFunction( Pn_Type* Px, uint8_t pin_no, uint32_t func )
90 {
91  uint8_t pin_offset;
92  uint32_t reg_val;
93 
94  if( pin_no < 8 ) // 0~7
95  {
96  //--------------------------------------
97  // pin_offset = pin_no * 4
98  //--------------------------------------
99  pin_offset = ( pin_no * 4 );
100 
101  //--------------------------------------
102  // MR
103  //--------------------------------------
104  reg_val = Px->AFSR1;
105  reg_val &= ~( AFSRx_Msk << pin_offset );
106  reg_val |= ( func << pin_offset );
107 
108  Px->AFSR1 = reg_val;
109  }
110  else
111  {
112  pin_no -= 8;
113  //--------------------------------------
114  // pin_offset = pin_no * 4
115  //--------------------------------------
116  pin_offset = ( pin_no * 4 );
117 
118  //--------------------------------------
119  // MR
120  //--------------------------------------
121  reg_val = Px->AFSR2;
122  reg_val &= ~( AFSRx_Msk << pin_offset );
123  reg_val |= ( func << pin_offset );
124 
125  Px->AFSR2 = reg_val;
126  }
127 }
128 
129 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
146 void HAL_GPIO_ConfigOutput( Pn_Type* Px, uint8_t pin_no, PCU_PORT_MODE dir_type )
147 {
148  uint8_t pin_offset;
149  uint32_t reg_val;
150  uint32_t dir_type_temp;
151 
152  dir_type_temp = dir_type;
153  if( dir_type_temp == OPEN_DRAIN_OUTPUT )
154  {
155  dir_type = PUSH_PULL_OUTPUT;
156  }
157  //--------------------------------------
158  // pin_offset = pin_no * 2
159  //--------------------------------------
160  pin_offset = ( pin_no << 1 );
161 
162  //--------------------------------------
163  // Pn_MOD
164  //--------------------------------------
165  reg_val = Px->MOD;
166  reg_val &= ~( MODEx_Msk << pin_offset );
167  reg_val |= ( dir_type << pin_offset );
168  Px->MOD = reg_val;
169 
170  //--------------------------------------
171  // Pn_TYP
172  //--------------------------------------
173  if( ( dir_type_temp == PUSH_PULL_OUTPUT ) || ( dir_type_temp == OPEN_DRAIN_OUTPUT ) )
174  {
175  reg_val = Px->TYP;
176  reg_val &= ~( 1 << pin_no );
177  if( dir_type_temp == OPEN_DRAIN_OUTPUT )
178  {
179  reg_val |= ( 1 << pin_no );
180  }
181  Px->TYP = reg_val;
182  }
183 }
184 
185 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
200 void HAL_GPIO_ConfigOutDataMask( Pn_Type* Px, uint8_t pin_no, FunctionalState maskctrl )
201 {
202  uint32_t reg_val;
203 
204  reg_val = Px->OUTDMSK;
205  reg_val &= ~( 1 << pin_no );
206  reg_val |= ( maskctrl << pin_no );
207  Px->OUTDMSK = reg_val;
208 }
209 
210 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
226 void HAL_GPIO_ConfigPullup( Pn_Type* Px, uint8_t pin_no, uint8_t pullupdown )
227 {
228  uint32_t reg_val;
229  uint8_t pin_offset;
230 
231  pin_offset = ( pin_no << 1 );
232 
233  reg_val = Px->PUPD;
234  reg_val &= ~( 3 << pin_offset );
235  reg_val |= ( pullupdown << pin_offset );
236  Px->PUPD = reg_val;
237 }
238 
239 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
261 void HAL_GPIO_SetDebouncePin( Pn_Type* Px, uint32_t u32Pins, uint32_t u32Debnc )
262 {
263 #if 0 // before bug fix
264  uint32_t reg_val;
265 
266  reg_val = ( 0x07ff & Px->DBCR );
267  reg_val |= ( 0x01 << u32Pins );
268  reg_val |= u32Debnc;
269  Px->DBCR = reg_val;
270 #else // after bug fix
271  Px->DBCR = Px->DBCR
272  & ~Pn_DBCR_DBCLK_Msk
273  | ( 1 << u32Pins )
274  | u32Debnc
275  ;
276 #endif
277 }
278 
279 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
291 void HAL_GPIO_SetPin( Pn_Type* Px, uint16_t bitValue )
292 {
293  Px->BSR = bitValue;
294 }
295 
296 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
308 void HAL_GPIO_ClearPin( Pn_Type* Px, uint16_t bitValue )
309 {
310  Px->BCR = bitValue;
311 }
312 
313 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
323 void HAL_GPIO_WritePin( Pn_Type* Px, uint16_t Value )
324 {
325  Px->OUTDR = Value;
326 }
327 
328 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
338 uint16_t HAL_GPIO_ReadPin( Pn_Type* Px )
339 {
340  return Px->INDR;
341 }
342 
Contains all macro definitions and function prototypes support for pcu firmware library on A31G12x.
void HAL_GPIO_ConfigOutput(Pn_Type *Px, uint8_t pin_no, PCU_PORT_MODE dir_type)
Configure pin mode.
PCU_PORT_MODE
void HAL_GPIO_ClearPin(Pn_Type *Px, uint16_t bitValue)
Clear 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_SetPin(Pn_Type *Px, uint16_t bitValue)
Set Value for bits that have output direction on GPIO port.
void HAL_GPIO_Init(Pn_Type *Px, uint32_t u32Mode, uint32_t u32Type, uint32_t u32Afsr1, uint32_t u32Afsr2, uint32_t u32PuPd)
Set PCU Pn_MOD/Pn_TYP/Pn_AFSR1/Pn_PUPD Registers.
void HAL_GPIO_SetDebouncePin(Pn_Type *Px, uint32_t u32Pins, uint32_t u32Debnc)
Set PCU Debounce.
uint16_t HAL_GPIO_ReadPin(Pn_Type *Px)
Read Current state on port pin that have input direction of GPIO.
FunctionalState
void HAL_GPIO_WritePin(Pn_Type *Px, uint16_t Value)
Write Value on port that have output direction of GPIO.
void HAL_GPIO_ConfigFunction(Pn_Type *Px, uint8_t pin_no, uint32_t func)
Configure pin function.
void HAL_GPIO_ConfigPullup(Pn_Type *Px, uint8_t pin_no, uint8_t pullupdown)
Configure Pin Pull-Up & Pull-Down.