diff --git a/NicolasYarno/MyGPIO.c b/NicolasYarno/MyGPIO.c new file mode 100644 index 0000000..27c0a82 --- /dev/null +++ b/NicolasYarno/MyGPIO.c @@ -0,0 +1,39 @@ +#include "stm32f10x.h" + + +void GPIO_configure(GPIO_TypeDef *GPIO ,int pin, char mode){ + if (mode == 1) { // output push pull 2MHZ + GPIO->CRL = (GPIO->CRL & ~(0xF<CRL = (GPIO->CRL & ~(0xF<ODR |= (1<ODR |= (1<ODR &= ~(1<ODR & (1<ODR |= (1<ODR &= ~(1<IDR & (1<ARR = ValARR; + Timer->PSC = ValPSC; +}; +/* +TIM2_CH1 +PWM mode 2 by writing OC1M=’111’ in the TIMx_CCMR1 + +he PWM mode can be selected independently on each channel (one PWM per OCx +output) by writing ‘110’ (PWM mode 1) or ‘111’ (PWM mode 2) in the OCxM bits in the +TIMx_CCMRx register. You must enable the corresponding preload register by setting the +OCxPE bit in the TIMx_CCMRx register, and eventually the auto-reload preload register (in +upcounting or center-aligned modes) by setting the ARPE bit in the TIMx_CR1 register + +110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNTTIMx_CCR1 else active (OC1REF=’1’). + +void MyTimer_PWM( TIM_TypeDef * Timer, char Channel){ +Timer->CCMR1 + + + +}; +*/ + + +void (*pFnc) (void); + +void MyTimer_ActiveIT (TIM_TypeDef * Timer , char prio, void (*IT_function)(void)){ + Timer->DIER |= TIM_DIER_UIE; + IRQn_Type IRQn; + if (Timer == TIM2) IRQn = TIM2_IRQn; + else if (Timer == TIM3) IRQn = TIM3_IRQn; + else if (Timer == TIM4) IRQn = TIM4_IRQn; + NVIC_EnableIRQ(IRQn); + NVIC_SetPriority(IRQn, prio); + + pFnc = IT_function; +}; + + +void TIM2_IRQHandler(void){ + if (pFnc != 0){ + (*pFnc) (); /* appel indirect de la fonction */ + } + TIM2->SR &= ~TIM_SR_UIF; +}; + + +void TIM3_IRQHandler(void){ + TIM3->SR &= ~TIM_SR_UIF; + +}; + +void TIM4_IRQHandler(void){ + TIM4->SR &= ~TIM_SR_UIF; + +};