From 9564e30a93b488b6df7e1b218ca32519a3aad080 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Fri, 31 Mar 2023 09:44:52 +0200 Subject: [PATCH] Added basic library, removed specific ones --- driver-algu/inc/gpio.h | 27 ----- driver-algu/src/gpio.c | 79 ------------- driver-siyo/timerdriver.c | 162 --------------------------- driver-siyo/timerdriver.h | 39 ------- {driver-algu/src => driver}/UART.c | 0 {driver-algu/inc => driver}/UART.h | 0 {driver-siyo => driver}/adcdriver.c | 0 {driver-siyo => driver}/adcdriver.h | 0 {driver-siyo => driver}/gpiodriver.c | 0 {driver-siyo => driver}/gpiodriver.h | 0 {driver-algu/src => driver}/timer.c | 0 {driver-algu/inc => driver}/timer.h | 0 12 files changed, 307 deletions(-) delete mode 100644 driver-algu/inc/gpio.h delete mode 100644 driver-algu/src/gpio.c delete mode 100644 driver-siyo/timerdriver.c delete mode 100644 driver-siyo/timerdriver.h rename {driver-algu/src => driver}/UART.c (100%) rename {driver-algu/inc => driver}/UART.h (100%) rename {driver-siyo => driver}/adcdriver.c (100%) rename {driver-siyo => driver}/adcdriver.h (100%) rename {driver-siyo => driver}/gpiodriver.c (100%) rename {driver-siyo => driver}/gpiodriver.h (100%) rename {driver-algu/src => driver}/timer.c (100%) rename {driver-algu/inc => driver}/timer.h (100%) diff --git a/driver-algu/inc/gpio.h b/driver-algu/inc/gpio.h deleted file mode 100644 index 642010c..0000000 --- a/driver-algu/inc/gpio.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MYGPIO_H -#define MYGPIO_H -#include "stm32f10x.h" - -typedef struct { - GPIO_TypeDef * GPIO; - char GPIO_Pin; //numero de 0 a 15 - char GPIO_Conf; //voir ci dessous -} MyGPIO_Struct_TypeDef; - -#define In_Floating 0x4 -#define In_PullDown 0x7 //faire -#define In_PullUp 0x8 //faire -#define In_Analog 0x0 -#define Out_Ppull 0x2 -#define Out_OD 0x6 -#define AltOut_Ppull 0xA -#define AltOut_OD 0xE - -void MyGPIO_InitClock(void); -void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr); -int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin); -void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin); -void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin); -void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin); - -#endif diff --git a/driver-algu/src/gpio.c b/driver-algu/src/gpio.c deleted file mode 100644 index c4c047f..0000000 --- a/driver-algu/src/gpio.c +++ /dev/null @@ -1,79 +0,0 @@ -#include "gpio.h" - -void MyGPIO_InitClock(void) { - RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4); -} - -void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) { - if (GPIOStructPtr->GPIO_Pin >= 8) { - switch (GPIOStructPtr->GPIO_Conf) { - case In_PullDown: - GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin % 8))); - GPIOStructPtr->GPIO->CRH |= (0x8 << (4 * (GPIOStructPtr->GPIO_Pin % 8))); - GPIOStructPtr->GPIO->ODR &= (0x0 << GPIOStructPtr->GPIO_Pin); - break; - - case In_PullUp: - GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin % 8))); - GPIOStructPtr->GPIO->CRH |= (0x8 << (4 * (GPIOStructPtr->GPIO_Pin % 8))); - GPIOStructPtr->GPIO->ODR |= (0x1 << GPIOStructPtr->GPIO_Pin); - break; - - case In_Floating: - case In_Analog: - case Out_Ppull: - case Out_OD: - case AltOut_Ppull: - case AltOut_OD: - GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin % 8))); - GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf << (4 * (GPIOStructPtr->GPIO_Pin % 8))); - break; - } - } - else { - switch (GPIOStructPtr->GPIO_Conf) { - case In_PullDown: - GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin))); - GPIOStructPtr->GPIO->CRH |= (0x8 << (4 * (GPIOStructPtr->GPIO_Pin))); - GPIOStructPtr->GPIO->ODR &= (0x0 << GPIOStructPtr->GPIO_Pin); - break; - - case In_PullUp: - GPIOStructPtr->GPIO->CRL &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin))); - GPIOStructPtr->GPIO->CRL |= (0x8 << (4 * (GPIOStructPtr->GPIO_Pin))); - GPIOStructPtr->GPIO->ODR |= (0x1 << GPIOStructPtr->GPIO_Pin); - break; - - case In_Floating: - case In_Analog: - case Out_Ppull: - case Out_OD: - case AltOut_Ppull: - case AltOut_OD: - GPIOStructPtr->GPIO->CRL &= ~(0xF << (4 * (GPIOStructPtr->GPIO_Pin))); - GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf << (4 * (GPIOStructPtr->GPIO_Pin))); - break; - } - } -} - -int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin) { - return ((GPIO->IDR & (0x1 << GPIO_Pin)) >> GPIO_Pin); -} - -void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin) { - GPIO->ODR |= (0x1 << GPIO_Pin); -} - -void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin) { - GPIO->ODR &= (0x0 << GPIO_Pin); -} - -void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin) { - if (MyGPIO_Read(GPIO, GPIO_Pin) == 0x1) { - MyGPIO_Reset(GPIO, GPIO_Pin); - } - else { - MyGPIO_Set(GPIO, GPIO_Pin); - } -} diff --git a/driver-siyo/timerdriver.c b/driver-siyo/timerdriver.c deleted file mode 100644 index 0dd11ca..0000000 --- a/driver-siyo/timerdriver.c +++ /dev/null @@ -1,162 +0,0 @@ -#include "timerdriver.h" - -void (* pFnc) (void); /* déclaration d’un pointeur de fonction */ - -void Init_Periph (void (* ptrFonction)(void)) -{ - pFnc = ptrFonction; /* affectation du pointeur */ -} - -void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer) -{ - //TIM1 uses the APB2ENR register from RCC. The others uses the APB1ENR, so we check this value. - if(Timer->Timer == TIM1) - { - RCC->APB2ENR |= TimerX2Int(Timer->Timer); - } else { - RCC->APB1ENR |= TimerX2Int(Timer->Timer); - } - Timer->Timer->ARR = Timer->ARR; - Timer->Timer->PSC = Timer->PSC; -} - -void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio) -{ - uint8_t positionTimerIT = TimerIT2UInt(TimerX); - TimerX->DIER |= (0x1<IP[positionTimerIT] |= (Prio << 0x4); - NVIC->ISER[0] |= (0x1<channel) - { - case 2: - PWM->Timer->CCMR1 |= (PWMMode_1<Timer->CCR2 = PWM->CCR; //Compare Capture register count - break; - case 3: - PWM->Timer->CCMR2 |= (PWMMode_1<Timer->CCR3 = PWM->CCR; - break; - case 4: - PWM->Timer->CCMR2 |= (PWMMode_1<Timer->CCR4 = PWM->CCR; - break; - default: - PWM->Timer->CCMR1 |= (PWMMode_1<Timer->CCR1 = PWM->CCR; - break; - } - PWM->Timer->CCER |= (1<<4*(PWM->channel-1)); //enable capture/compare registers -} - -MyGPIO_Struct_TypeDef GPIOFromPWM(MyPWM_Struct_TypeDef PWM) -{ - //use of C99 compound literal for return statement, may not work on C90. - if(PWM.Timer == TIM2) - { - //PA0 -> TIM2,CH1... iteration - return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel-1,AltOut_Ppull}; - } - else if(PWM.Timer == TIM3) - { - if(PWM.channel > 2) { - return (MyGPIO_Struct_TypeDef){GPIOB,PWM.channel-3,AltOut_Ppull}; //PB0 -> TIM3,CH3;PB1 -> TIM3,CH4 - } - else { - return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel+5,AltOut_Ppull}; //PA6 -> TIM3,CH1;PA7 -> TIM3,CH2 - } - } - else if(PWM.Timer == TIM4) - { - return (MyGPIO_Struct_TypeDef){GPIOB,PWM.channel+5,AltOut_Ppull}; //PB6 -> TIM4,CH1... iteration - } - else { //TIM1 case - return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel+7,AltOut_Ppull};//PA8 -> TIM1,CH1... iteration - } -} - -int TimerX2Int(TIM_TypeDef * TimerX) -{ - if(TimerX == TIM1) - { - return (0x01 << 11); - } else if (TimerX == TIM2){ - return (0x01 << 0); - } else if (TimerX == TIM3){ - return (0x01 << 1); - } else if (TimerX == TIM4){ - return (0x01 << 2); - } /*else if (TimerX == TIM5){ - return (0x01 << 3); - } else if (TimerX == TIM6){ - return (0x01 << 4); - } else if (TimerX == TIM7){ - return (0x01 << 5); - } else if (TimerX == TIM8){ - return (0x01 << 13); - } else if (TimerX == TIM9){ //For now we dont do timer > 4 - return (0x01 << 19); - } else if (TimerX == TIM10){ - return (0x01 << 20); - } else if (TimerX == TIM11){ - return (0x01 << 21); - } else if (TimerX == TIM12){ - return (0x01 << 6); - } else if (TimerX == TIM13){ - return (0x01 << 7); - } else if (TimerX == TIM14){ - return (0x01 << 8); - }*/ else { - return -1; - }; -} - -uint8_t TimerIT2UInt(TIM_TypeDef * TimerX) -{ - if(TimerX == TIM1) - { - return TIM1_CC_IRQn; - } else if(TimerX == TIM2) - { - return TIM2_IRQn; - } else if(TimerX == TIM3) - { - return TIM3_IRQn; - } else if(TimerX == TIM4) - { - return 30; - } else { - return 0; - } -} - -void TIM1_CC_IRQHandler(void) -{ - if (pFnc != 0) - (*pFnc) (); /* appel indirect de la fonction */ - TIM1->SR &= ~(0x1<SR &= ~(0x1<SR &= ~(0x1<SR &= ~(0x1< TIM4 - unsigned short ARR; - unsigned short PSC; -} MyTimer_Struct_TypeDef; - -typedef struct { - TIM_TypeDef * Timer; //TIM1 -> TIM4 - uint8_t channel; - uint16_t CCR; -} MyPWM_Struct_TypeDef; - -void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer); -int TimerX2Int(TIM_TypeDef * TimerX); -uint8_t TimerIT2UInt(TIM_TypeDef * TimerX); -void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio); -void Init_Periph (void (* ptrFonction)(void)); -void MyTimer_PWM_Init(MyPWM_Struct_TypeDef * PWM); -MyGPIO_Struct_TypeDef GPIOFromPWM(MyPWM_Struct_TypeDef PWM); - -#define MyTimer_Base_Start(Timer) (Timer->CR1 |= (0x01<CR1 &= ~(0x01<BDTR |= (1<BDTR &= ~(1<