New branch init
This commit is contained in:
parent
cd6ee1fa99
commit
f6f5a3eab5
2 changed files with 128 additions and 0 deletions
36
Drivers/Inc/ADC.h
Normal file
36
Drivers/Inc/ADC.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef MYTIMER_H
|
||||
#define MYTIMER_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TIM_TypeDef * Timer ; // TIM1 à TIM4
|
||||
unsigned short ARR;
|
||||
unsigned short PSC;
|
||||
}MyTimer_Struct_TypeDef;
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* @brief
|
||||
* @param -> Paramètre sous forme d’une structure (son adresse) contenant les
|
||||
informations de base
|
||||
* @Note -> Fonction à lancer systématiquement avant d’aller plus en détail dans les
|
||||
conf plus fines (PWM, codeur inc...)
|
||||
*************************************************************************************************
|
||||
*/
|
||||
void MyTimer_Base_Init (MyTimer_Struct_TypeDef * Timer);
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* @brief
|
||||
* @param -> - TIM_TypeDef * Timer : Timer concerne
|
||||
- char Prio : de 0 a 15
|
||||
* @Note -> La fonction MyTimer_Base_Init doit avoir ete lancee au prealable
|
||||
*************************************************************************************************
|
||||
*/
|
||||
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void));
|
||||
|
||||
|
||||
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= 0x01)
|
||||
#define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~0x01)
|
||||
|
||||
|
||||
#endif
|
92
Drivers/Src/ADC.c
Normal file
92
Drivers/Src/ADC.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include "TIMER.h"
|
||||
|
||||
/*periode_timer=peridoe_horloge*prescaler*resolution
|
||||
debordement stocké dans registre UIF
|
||||
fixer val prescaler+ autoreload(equivalent resolution)
|
||||
demarrage timer => CEN=1*/
|
||||
|
||||
void (*ptr_func)(void);
|
||||
|
||||
void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer)
|
||||
{
|
||||
if(Timer->Timer==TIM1)
|
||||
{
|
||||
RCC->APB2ENR |= 0x01<<11;
|
||||
}
|
||||
else if (Timer->Timer==TIM2)
|
||||
{
|
||||
RCC->APB1ENR |= 0x01;
|
||||
}
|
||||
else if (Timer->Timer==TIM3)
|
||||
{
|
||||
RCC->APB1ENR |= 0x01<<1;
|
||||
}
|
||||
else if (Timer->Timer==TIM4)
|
||||
{
|
||||
RCC->APB1ENR |= 0x01<<2;
|
||||
}
|
||||
Timer->Timer->ARR=Timer->ARR;
|
||||
Timer->Timer->PSC=Timer->PSC;
|
||||
}
|
||||
|
||||
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void))
|
||||
{
|
||||
int num_tim;
|
||||
ptr_func=IT_function;
|
||||
Timer->DIER |= 0x01;
|
||||
if(Timer==TIM1)
|
||||
{
|
||||
num_tim=TIM1_UP_IRQn;
|
||||
}
|
||||
else if(Timer==TIM2)
|
||||
{
|
||||
num_tim=TIM2_IRQn;
|
||||
}
|
||||
else if(Timer==TIM3)
|
||||
{
|
||||
num_tim=TIM3_IRQn;
|
||||
}
|
||||
else if(Timer==TIM4)
|
||||
{
|
||||
num_tim=TIM4_IRQn;
|
||||
}
|
||||
NVIC->ISER[0] |= 0x01<<num_tim;
|
||||
NVIC->IP[num_tim] |= Prio << 4;
|
||||
|
||||
}
|
||||
|
||||
void TIM2_IRQHandler (void)
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
}
|
||||
TIM2->SR &= ~(1<<0) ;
|
||||
}
|
||||
|
||||
void TIM3_IRQHandler (void)
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
}
|
||||
TIM3->SR &= ~(1<<0) ;
|
||||
}
|
||||
|
||||
void TIM4_IRQHandler (void)
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
}
|
||||
TIM4->SR &= ~(1<<0) ;
|
||||
}
|
||||
|
||||
void TIM1_UP_IRQHandler (void) // à vérifier
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
}
|
||||
TIM1->SR &= ~(1<<0) ;
|
||||
}
|
Loading…
Reference in a new issue