Skip to content

Commit

Permalink
add drivers in one folder -fixes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
gehadelkoumy committed Apr 11, 2023
1 parent bd7817a commit dfec29d
Show file tree
Hide file tree
Showing 24 changed files with 1,295 additions and 0 deletions.
11 changes: 11 additions & 0 deletions MCAL_Drivers/AFIO/include/AFIO_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**********************************************************/
/* Author : Gehad Elkoumy */
/* Date : 30 NOV 2022 */
/* Version : V01 */
/**********************************************************/

#ifndef AFIO_CONFIG_H
#define AFIO_CONFIG_H


#endif
19 changes: 19 additions & 0 deletions MCAL_Drivers/AFIO/include/AFIO_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**********************************************************/
/* Author : Gehad Elkoumy */
/* Date : 30 NOV 2022 */
/* Version : V01 */
/**********************************************************/

#ifndef AFIO_INTERFACE_H
#define AFIO_INTERFACE_H

void MAFIO_voidSetEXTIConfiguration(u8 Copy_u8Line ,u8 Copy_u8PortMap);

/*portmap used as an interrupt*/
#define AFIOA 0b0000
#define AFIOB 0b0001
#define AFIOC 0b0010

/*lines are in EXTI driver*/

#endif
23 changes: 23 additions & 0 deletions MCAL_Drivers/AFIO/include/AFIO_private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**********************************************************/
/* Author : Gehad Elkoumy */
/* Date : 30 NOV 2022 */
/* Version : V01 */
/**********************************************************/

#ifndef AFIO_PRIVATE_H
#define AFIO_PRIVATE_H


typedef struct{
volatile u32 EVCR;
volatile u32 MAPR;
volatile u32 EXTICR[4];
volatile u32 MAPR2;

}AFIO_t;


#define AFIO ((volatile AFIO_t *) 0x40010000 )


#endif
48 changes: 48 additions & 0 deletions MCAL_Drivers/AFIO/src/AFIO_program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**********************************************************/
/* Author : Gehad Elkoumy */
/* Date : 30 NOV 2022 */
/* Version : V01 */
/**********************************************************/
#include "STD_TYPES.h"
#include "BIT_MATH.h"

#include "AFIO_interface.h"
#include "AFIO_config.h"
#include "AFIO_private.h"


void MAFIO_voidSetEXTIConfiguration(u8 Copy_u8EXTILine ,u8 Copy_u8PortMap)
{
u8 Local_u8RegIndex = 0 ;
/* Assign to EXTICRX register */
if(Copy_u8EXTILine <= 3 )
{
Local_u8RegIndex = 0;
}
else if(Copy_u8EXTILine <= 7)
{
Local_u8RegIndex = 1;

/*bit0 to bit3 not 4 to 7*/
Copy_u8EXTILine -= 4;
}
else if(Copy_u8EXTILine <= 11)
{
Local_u8RegIndex = 2;
/*4bits from 0 to 3*/
Copy_u8EXTILine -= 8;

}
else if(Copy_u8EXTILine <= 15)
{
Local_u8RegIndex = 3;
/*4bits from 0 to 3*/
Copy_u8EXTILine -= 12;
}

/*reset first --> (avoiding overwrite)*/
AFIO->EXTICR[Local_u8RegIndex] &= ~((0b1111) << (Copy_u8EXTILine * 4));

/*set*/
AFIO->EXTICR[Local_u8RegIndex] |= ((Copy_u8PortMap) << (Copy_u8EXTILine * 4));
}
22 changes: 22 additions & 0 deletions MCAL_Drivers/EXTI/include/EXTI_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**********************************************************/
/* Author : Gehad Elkoumy */
/* Date : 6 DEC 2022 */
/* Version : V01 */
/**********************************************************/
#ifndef EXTI_CONFIG_H
#define EXTI_CONFIG_H


/*options : from LINE0 to LINE15*/
#define EXTI_LINE LINE0



/*options : RISING
FALLING
ON_CHANGE */
#define EXTI_MODE FALLING



#endif
44 changes: 44 additions & 0 deletions MCAL_Drivers/EXTI/include/EXTI_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**********************************************************/
/* Author : Gehad Elkoumy */
/* Date : 6 DEC 2022 */
/* Version : V01 */
/**********************************************************/
#ifndef EXTI_INTERFACE_H
#define EXTI_INTERFACE_H


void MEXTI_voidInit();
void MEXTI_voidEnableEXTI(u8 Copy_u8EXTILine);
void MEXTI_voidDisableEXTI(u8 Copy_u8EXTILine);
void MEXTI_voidSoftwareTrigger(u8 Copy_u8EXTILine);
void MEXTI_voidSetSignalLatch(u8 Copy_u8EXTILine , u8 Copy_u8EXTIMode);

/*pointer to function*/
void EXTI_voidSetCallBack(void (*ptr) (void) , u8 Copy_u8EXTILine);


#define LINE0 0
#define LINE1 1
#define LINE2 2
#define LINE3 3
#define LINE4 4
#define LINE5 5
#define LINE6 6
#define LINE7 7
#define LINE8 8
#define LINE9 9
#define LINE10 10
#define LINE11 11
#define LINE12 12
#define LINE13 13
#define LINE14 14
#define LINE15 15



#define RISING 0
#define FALLING 1
#define ON_CHANGE 2 /*any change (rising & falling)*/


#endif
25 changes: 25 additions & 0 deletions MCAL_Drivers/EXTI/include/EXTI_private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**********************************************************/
/* Author : Gehad Elkoumy */
/* Date : 6 DEC 2022 */
/* Version : V01 */
/**********************************************************/
#ifndef EXTI_PRIVATE_H
#define EXTI_PRIVATE_H

/*must be ordered*/
typedef struct{
volatile u32 IMR;
volatile u32 EMR;
volatile u32 RTSR;
volatile u32 FTSR;
volatile u32 SWIER;
volatile u32 PR;

}EXTI_t;

/*without dereference as it act as pointer*/
#define EXTI ((volatile EXTI_t *) 0x40010400 )

static void (*EXTI_GlobalPtr[16]) (void) ;

#endif
Loading

0 comments on commit dfec29d

Please sign in to comment.