Added function pointer for interruptions (Arduino Like Interrupt)
This commit is contained in:
parent
39df95caf9
commit
4c965562b6
4 changed files with 22 additions and 15 deletions
|
@ -1,5 +1,12 @@
|
|||
#include "adcdriver.h"
|
||||
|
||||
void (* pFncADC) (void); /* déclaration d’un pointeur de fonction */
|
||||
|
||||
void MyADC_Init_Periph (void (* ptrFonction)(void))
|
||||
{
|
||||
pFncADC = ptrFonction; /* affectation du pointeur */
|
||||
}
|
||||
|
||||
void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr)
|
||||
{
|
||||
RCC->CFGR |= RCC_CFGR_ADCPRE_1; // ADC Prescaler : divided by 6 -> 72MHz to 12MHz
|
||||
|
@ -18,11 +25,7 @@ void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr)
|
|||
ADCStructPtr->ADC->CR2 |= ADC_CR2_EXTSEL; //Event externe choisie : SWSTART
|
||||
MyADC_ActiveIT(ADCStructPtr->ADC,0);
|
||||
ADCStructPtr->ADC->CR2 |= ADC_CR2_ADON; //Init l'ADC
|
||||
}
|
||||
|
||||
void MyADC_Start (ADC_TypeDef * ADC)
|
||||
{
|
||||
ADC->CR2 |= ADC_CR2_SWSTART; //Start Conversion of regular channels
|
||||
MyADC_Base_Start(ADCStructPtr->ADC); //Debut du premier ADC
|
||||
}
|
||||
|
||||
void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio)
|
||||
|
@ -31,3 +34,11 @@ void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio)
|
|||
NVIC->IP[ADC1_2_IRQn] |= (Prio << 0x4); //Prio de l'interruption (p.197 manuel reference RM0008 pour ADC1_IRQn)
|
||||
NVIC->ISER[0] |= (0x1<<ADC1_2_IRQn); //Active l'interruption au niveau NVIC (p.119 manuel programming pour ISER[0])
|
||||
}
|
||||
|
||||
void ADC1_2_IRQHandler(void)
|
||||
{
|
||||
if (pFncADC != 0)
|
||||
(*pFncADC) (); /* appel indirect de la fonction */
|
||||
MyADC_Base_Start(ADC1);
|
||||
ADC1->SR &= ~ADC_SR_EOC; //Prochaine lecture pouvant être effectuée.
|
||||
}
|
|
@ -23,8 +23,9 @@ typedef struct
|
|||
|
||||
void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr);
|
||||
void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio);
|
||||
void MyADC_Start (ADC_TypeDef * ADC);
|
||||
void MyADC_Init_Periph (void (* ptrFonction)(void));
|
||||
MyGPIO_Struct_TypeDef GPIOFromADC(MyADC_Struct_TypeDef ADC);
|
||||
|
||||
#define MyADC_Base_Start(ADC) (ADC->CR2 |= ADC_CR2_SWSTART)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#define ADON 0
|
||||
|
||||
void ADC1_2_IRQHandler(void)
|
||||
void LEDClignotte(void)
|
||||
{
|
||||
if(ADC1->DR >= 3102)
|
||||
{
|
||||
|
@ -16,8 +16,6 @@ void ADC1_2_IRQHandler(void)
|
|||
else{
|
||||
MyGPIO_Reset(GPIOA,5);
|
||||
}
|
||||
MyADC_Start(ADC1);
|
||||
ADC1->SR &= ~ADC_SR_EOC; //Prochaine lecture pouvant être effectuée.
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -29,12 +27,9 @@ int main (void)
|
|||
MyGPIO_Init(&led);
|
||||
|
||||
MyADC_Init(&adcStruct);
|
||||
MyADC_Init_Periph(LEDClignotte);
|
||||
MyGPIO_Init(&adc);
|
||||
|
||||
MyADC_Start(ADC1);
|
||||
|
||||
|
||||
|
||||
while(1){
|
||||
//MyADC_Start(ADC1);
|
||||
/*
|
||||
|
|
|
@ -529,7 +529,7 @@
|
|||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\timerdriver.c</PathWithFileName>
|
||||
|
|
Loading…
Reference in a new issue