voilier-team-1/implementation/girouette.c

54 lines
1.4 KiB
C
Raw Normal View History

2023-04-11 13:35:12 +02:00
#include "girouette.h"
void MyGirouette_Init(TIM_TypeDef *TIMX)
{
//configuration gpiob6 et gpiob7 en entr<74>es In_Floating imposer par le timer4
MyGPIO_Struct_TypeDef MyGPIO={GPIOB,6,In_Floating};
MyGPIO_Init(&MyGPIO);
MyGPIO.GPIO_Pin=7;
MyGPIO_Init(&MyGPIO);
//config pa0 en entr<74>es
MyGPIO.GPIO_Pin=0;
MyGPIO.GPIO=GPIOA;
MyGPIO_Init(&MyGPIO);
//configuration TIM4 reset a 360
2023-04-11 14:56:00 +02:00
MyTimer_Struct_Typedef MyTimerGirouette ={TIMX,1439,0};
2023-04-11 13:35:12 +02:00
MyTimer_Base_Init(&MyTimerGirouette);
TIMX->SMCR &=~0x07;
TIMX->SMCR |=TIM_SMCR_SMS_1;
TIMX->CCMR1 &=~(0xF2F2);
TIMX->CCMR1 |= TIM_CCMR1_CC1S_0;
TIMX->CCMR1 |= TIM_CCMR1_CC2S_0; //CC2S dans CCMR1 et pas CCMR2
TIMX->CCER &=~TIM_CCER_CC1P;
TIMX->CCER &=~TIM_CCER_CC2P;
TIMX->CCMR1&=~(0x0F<<4); //IC1F
TIMX->CCMR1&=~(0x0F<<12);//IC2F
TIMX->CR1 |= 1;
}
int MyGirouette_Angle(TIM_TypeDef *TIMX)
{
2023-04-11 14:56:00 +02:00
return (TIMX->CNT)/4;
2023-04-11 13:35:12 +02:00
}
void MyGirouette_Init_IT_Z(uint8_t GPIO_Pin)
{
2023-04-11 14:56:00 +02:00
RCC->APB2ENR |=0x01;
2023-04-11 13:35:12 +02:00
EXTI->IMR |= (0x01<<GPIO_Pin); // Autorisation de l'interruption de la ligne
EXTI->RTSR|= (0x01<<GPIO_Pin); // Activation du d<>clenchement de l'interruption sur un front montant
AFIO->EXTICR[0] &= ~(0x0000000F);// L'interruption <20> EXTI0 <20> doit <20>tre provoqu<71>e par une modification PA0
NVIC->ISER[0] |= (1 << (6 & 0x1F)); // Autorisation de l'interruption <20> EXTI0 <20> NUMERO 6,
}
2023-04-11 14:56:00 +02:00
void EXTI0_IRQHandler(void) {
2023-04-11 13:35:12 +02:00
TIM4->CNT=0;
2023-04-11 14:56:00 +02:00
EXTI->PR|=0x01;
2023-04-11 13:35:12 +02:00
}