Ajouter des commentaires et enlever des redondances
This commit is contained in:
parent
1283e0f110
commit
cd739176a3
10 changed files with 49 additions and 60 deletions
|
|
@ -1,4 +1,8 @@
|
|||
// Gestion des signaux
|
||||
extern int ChercherEtat(GPIO_TypeDef * GPIO, int pin);
|
||||
extern void ResetBroche(uint32_t GPIO, int Broche);
|
||||
extern void SetBroche(uint32_t GPIO, int Broche);
|
||||
extern void TogglePin(GPIO_TypeDef*GPIO, int Broche);
|
||||
// Config des broches
|
||||
extern void ConfigureBroche(uint32_t GPIO, int Broche, int IO, char Mode);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,11 @@
|
|||
#include "stm32f10x.h"
|
||||
|
||||
//TIMERS
|
||||
extern void MyTimer_Base_Init ( TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC );
|
||||
extern void EnableTimer(void);
|
||||
extern void ConfigureBroches();
|
||||
extern void ConfigureTimers();
|
||||
//TIMERS start
|
||||
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= TIM_CR1_CEN)
|
||||
#define MyTimer_Base_Stop(Timer) (Timer -> CR1 =(0x0))
|
||||
// IT
|
||||
extern volatile int g_tick_count; // Declara que a variável existe em outro arquivo
|
||||
extern void TIM2_IRQHandler(void);
|
||||
extern void TIM3_IRQHandler(void);
|
||||
extern void TIM4_IRQHandler(void);
|
||||
extern void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void));
|
||||
//PWM
|
||||
extern void MyTimer_PWM(TIM_TypeDef *Timer, char Channel);
|
||||
extern void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent);
|
||||
void Test(void);
|
||||
void ConfigureIT();
|
||||
// PWM
|
||||
void ConfigurePWM();
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
#include "stm32f10x.h"
|
||||
// Config
|
||||
extern void ConfigHorloge(void);
|
||||
extern void ConfigBroche(void);
|
||||
// Gestion des IO Spesifiques
|
||||
extern int BoutonAppuye(void);
|
||||
extern void AllumerLED(void);
|
||||
extern void EteindreLED(void);
|
||||
extern void TogglePin(GPIO_TypeDef*GPIO, int Broche);
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#include "stm32f10x.h"
|
||||
// Config
|
||||
extern void MyTimer_PWM(TIM_TypeDef *Timer, char Channel);
|
||||
extern void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent);
|
||||
|
|
@ -1,6 +1,12 @@
|
|||
#include "stm32f10x.h"
|
||||
// Config de timer
|
||||
extern void MyTimer_Base_Init(TIM_TypeDef *Timer , unsigned short ValARR , unsigned short ValPSC );
|
||||
extern void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void));
|
||||
extern void EnableTimer();
|
||||
// Fonctions d'interruption
|
||||
extern void TIM2_IRQHandler(void);
|
||||
extern void TIM3_IRQHandler(void);
|
||||
extern void TIM4_IRQHandler(void);
|
||||
extern void TIM1_CC_IRQnHandler(void);
|
||||
extern void TIM1_UP_IRQnHandler(void);
|
||||
// Enable timers
|
||||
extern void EnableTimer();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "stm32f10x.h"
|
||||
#include <stdlib.h>
|
||||
#include "../Include/GPIO.h"
|
||||
|
||||
int ChercherEtat(GPIO_TypeDef * GPIO, int pin){ // Trouvons la valeur d'un broche sur un certain GPIO
|
||||
return((GPIO -> IDR & (0x01 << pin)));
|
||||
|
|
@ -13,6 +14,10 @@ void SetBroche(uint32_t GPIO, int Broche){ // Mettre à zero d'un certain broche
|
|||
GPIO -> BSRR |= BSBroche << 16;
|
||||
}
|
||||
|
||||
void TogglePin(GPIO_TypeDef*GPIO, int Broche){ // Inverser la valueur de broche sur GPIO
|
||||
GPIO -> ODR = GPIO -> ODR ^ (0x1 << Broche);
|
||||
}
|
||||
|
||||
void ConfigureGPIO(uint32_t GPIO, int Broche, int IO, char Mode){ // Mettre un broche d'un GPIO sur un mode
|
||||
// Possble de améliorer avec des int à la place de string
|
||||
//Start clock pour les GPIO concernés
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "Nucleo.h"
|
||||
#include "Timer.h"
|
||||
#include "PWM.h"
|
||||
#include "GPIO.h"
|
||||
#include "../Include/Timer.h"
|
||||
#include "../Include/PWM.h"
|
||||
#include "../Include/GPIO.h"
|
||||
// Variables
|
||||
#define ARR_TIM1 0xFFAD
|
||||
#define PSC_TIM1 0xFF
|
||||
|
|
@ -18,30 +17,6 @@ void Test(void){
|
|||
TogglePin(GPIOA, 8);
|
||||
}
|
||||
|
||||
|
||||
void ConfigureBroches(){
|
||||
ConfigureGPIO(GPIOA, 6, 4, Push-Pull); // Cela équivaut à :
|
||||
// GPIOA->CRL &= ~(0xF << 6*4); // clean pin 6
|
||||
// GPIOA->CRL |= (0xB << 6*4); // Alternate Function output, Push-Pull max 50 Hz
|
||||
// Exemples d'_tilisation
|
||||
//Mettre Broche 5 sur input Pull-up/down
|
||||
ConfigureGPIO(GPIOC, 3, 0, Pull-Up);
|
||||
//GPIOC ->CRL &= ~(0xF << (4 *3));
|
||||
//GPIOC ->CRL |= (0x1 << (4 *3));
|
||||
|
||||
//Mettre Broche 5 sur input Pull-up/down
|
||||
ConfigureGPIO(GPIOA, 5, 0, Pull-Up);
|
||||
//GPIOA ->CRL &= ~(0xF << (4 *5));
|
||||
//GPIOA ->CRL |= (0x3 << (4 *5));
|
||||
|
||||
//Mettre Broche D7 sur input Open drain
|
||||
ConfigureGPIO(GPIOA, 0, 0, Open-Drain);
|
||||
//GPIOA ->CRH &= ~(0xF << (4 *0));
|
||||
//GPIOA ->CRH |= (0x7 << (4 *0));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ConfigureTimers(){
|
||||
MyTimer_Base_Init(TIM2, ARR_TIM2, PSC_TIM2);
|
||||
MyTimer_Base_Init(TIM1, ARR_TIM1, PSC_TIM1);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "../Include/Nucleo.h"
|
||||
#include "GPIO.h"
|
||||
|
||||
void ConfigHorloge(void) { // Peut-être redondant ??
|
||||
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_TIM1EN;
|
||||
|
|
@ -6,26 +8,30 @@ RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) | RCC_APB2ENR_IOPCEN | R
|
|||
|
||||
void ConfigBroche(void){ //
|
||||
//Mettre Broche 5 GPIOA à output push-pull
|
||||
GPIOA ->CRL &= ~(0x1 << (5*4 + 2)); //0x44144444;
|
||||
GPIOA ->CRL |= (0x1 << 5*4); //0x44144444;
|
||||
|
||||
//Mettre Broche 5 sur input Pull-up/down
|
||||
GPIOA ->CRH &= ~(0x1 << (4 + 2));
|
||||
GPIOA ->CRH |= (0x1 << (4 + 3));
|
||||
ConfigureGPIO(GPIOA, 5, 4, Push-Pull);
|
||||
// Equivaut à :
|
||||
//GPIOA ->CRL &= ~(0x1 << (5*4 + 2)); //0x44144444;
|
||||
//GPIOA ->CRL |= (0x1 << 5*4); //0x44144444;
|
||||
|
||||
//Mettre broche 8 sur GPIOA à output open drain
|
||||
GPIOA ->CRH |= (0x1 );
|
||||
ConfigureGPIO(GPIOA, 8, 4, Open-Drain);
|
||||
// Equivaut à :
|
||||
//GPIOA ->CRH |= (0x1 );
|
||||
};
|
||||
|
||||
int BoutonAppuye(void){ // Peut être modifié avec ChercherEtat
|
||||
return((GPIOA -> IDR & (0x01 << 9)));
|
||||
ChercherEtat(GPIOA, 9);
|
||||
// Equivaut à
|
||||
//return((GPIOA -> IDR & (0x01 << 9)));
|
||||
}
|
||||
void AllumerLED(void){
|
||||
GPIOA -> ODR &= ~(0x1 << 8); // Peut être modifié avec SetBroche
|
||||
SetBroche(GPIOA, 8);
|
||||
// Equivaut à :
|
||||
//GPIOA -> ODR &= ~(0x1 << 8); // Peut être modifié avec SetBroche
|
||||
}
|
||||
void EteindreLED(void){
|
||||
GPIOA -> ODR |= (0x1 << 8); // Peut être modifié avec ResetBroche
|
||||
}
|
||||
void TogglePin(GPIO_TypeDef*GPIO, int Broche){ // Redondant
|
||||
GPIO -> ODR = GPIO -> ODR ^ (0x1 << Broche);
|
||||
ResetBroche(GPIOA, 8);
|
||||
// Equivaut à :
|
||||
//GPIOA -> ODR |= (0x1 << 8); // Peut être modifié avec ResetBroche
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "PWM.h"
|
||||
#include "../Include/PWM.h"
|
||||
|
||||
|
||||
void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { // Activer PWM sur un output
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "Nucleo.h"
|
||||
#include "../Include/Timer.h"
|
||||
|
||||
//REMEMBER TO ENALBLE TIMERS
|
||||
//EXAMPLES
|
||||
|
|
|
|||
Loading…
Reference in a new issue