commit a84307a4b3de58cbb3dd57dede4588e7bd65b961 Author: Yohan Boujon Date: Wed Mar 22 15:20:38 2023 +0100 Init of project with the various libraries. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd33554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.obsidian diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/driver-algu/inc/gpio.h b/driver-algu/inc/gpio.h new file mode 100644 index 0000000..642010c --- /dev/null +++ b/driver-algu/inc/gpio.h @@ -0,0 +1,27 @@ +#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/inc/timer.h b/driver-algu/inc/timer.h new file mode 100644 index 0000000..281867e --- /dev/null +++ b/driver-algu/inc/timer.h @@ -0,0 +1,19 @@ +#ifndef MYTIMER_H +#define MYTIMER_H +#include "stm32f10x.h" + +typedef struct { + TIM_TypeDef * Timer; + unsigned short ARR; + unsigned short PSC; +} MyTimer_Struct_Typedef; + +void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer); +void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)); +void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel); +void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle); + +#define MyTimer_Base_Start(Tim) (Tim.Timer->CR1 |= TIM_CR1_CEN) +#define MyTimer_Base_Stop(Tim) (Tim.Timer->CR1 &= ~TIM_CR1_CEN) + +#endif diff --git a/driver-algu/src/gpio.c b/driver-algu/src/gpio.c new file mode 100644 index 0000000..c4c047f --- /dev/null +++ b/driver-algu/src/gpio.c @@ -0,0 +1,79 @@ +#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-algu/src/timer.c b/driver-algu/src/timer.c new file mode 100644 index 0000000..768cc8b --- /dev/null +++ b/driver-algu/src/timer.c @@ -0,0 +1,192 @@ +#include "timer.h" +#include "gpio.h" + +void plantage(void) { + while(1); +} +void (*IT_Tim1) (void) = plantage; +void (*IT_Tim2) (void) = plantage; +void (*IT_Tim3) (void) = plantage; +void (*IT_Tim4) (void) = plantage; + +void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer) { + if ((Timer->Timer) == TIM1) + RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; + if ((Timer->Timer) == TIM2) + RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; + if ((Timer->Timer) == TIM3) + RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; + if ((Timer->Timer) == TIM4) + RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; + + Timer->Timer->PSC = Timer->PSC; + Timer->Timer->ARR = Timer->ARR; +} + +void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)) { + Timer->DIER |= TIM_DIER_UIE; + if (Timer == TIM2) { + NVIC_EnableIRQ(TIM1_BRK_IRQn); + NVIC_SetPriority(TIM1_BRK_IRQn, Prio); + IT_Tim1 = IT_function; + } + if (Timer == TIM2) { + NVIC_EnableIRQ(TIM2_IRQn); + NVIC_SetPriority(TIM2_IRQn, Prio); + IT_Tim2 = IT_function; + } + if (Timer == TIM3) { + NVIC_EnableIRQ(TIM3_IRQn); + NVIC_SetPriority(TIM3_IRQn, Prio); + IT_Tim3 = IT_function; + } + if (Timer == TIM4) { + NVIC_EnableIRQ(TIM4_IRQn); + NVIC_SetPriority(TIM4_IRQn, Prio); + IT_Tim4 = IT_function; + } +} + +void TIM1_IRQHandler(void) { + TIM1->SR &= ~TIM_SR_UIF; + (*IT_Tim1)(); +} + +void TIM2_IRQHandler(void) { + TIM2->SR &= ~TIM_SR_UIF; + (*IT_Tim2)(); +} + +void TIM3_IRQHandler(void) { + TIM3->SR &= ~TIM_SR_UIF; + (*IT_Tim3)(); +} + +void TIM4_IRQHandler(void) { + TIM4->SR &= ~TIM_SR_UIF; + (*IT_Tim4)(); +} + +void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel) +{ + MyGPIO_Struct_TypeDef PWM_OUT; + PWM_OUT.GPIO_Conf = AltOut_Ppull; + switch (Channel) { + case 1: + case 2: + Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0; + Timer->CCMR1 |= (TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2); + break; + + case 3: + case 4: + Timer->CCMR2 &= ~TIM_CCMR1_OC1M_0; + Timer->CCMR2 |= (TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2); + break; + } + + Timer->CCER |= (TIM_CCER_CC1E << (4*(Channel-1))); + +if(Timer == TIM1) + { + TIM1->BDTR |= 0x8000; + PWM_OUT.GPIO = GPIOA; + switch (Channel) { + case 1: + PWM_OUT.GPIO_Pin = 8; + break; + case 2: + PWM_OUT.GPIO_Pin = 9; + break; + case 3: + PWM_OUT.GPIO_Pin = 10; + break; + case 4: + PWM_OUT.GPIO_Pin = 11; + break; + } + } + if(Timer == TIM2) + { + PWM_OUT.GPIO = GPIOA; + switch (Channel) { + case 1: + PWM_OUT.GPIO_Pin = 0; + break; + case 2: + PWM_OUT.GPIO_Pin = 1; + break; + case 3: + PWM_OUT.GPIO_Pin = 2; + break; + case 4: + PWM_OUT.GPIO_Pin = 3; + break; + } + } + + if(Timer == TIM3) + { + switch (Channel) { + case 1: + PWM_OUT.GPIO = GPIOA; + PWM_OUT.GPIO_Pin = 6; + break; + case 2: + PWM_OUT.GPIO = GPIOA; + PWM_OUT.GPIO_Pin = 7; + break; + case 3: + PWM_OUT.GPIO = GPIOB; + PWM_OUT.GPIO_Pin = 0; + break; + case 4: + PWM_OUT.GPIO = GPIOB; + PWM_OUT.GPIO_Pin = 1; + break; + } + } + + if(Timer == TIM4) + { + PWM_OUT.GPIO = GPIOB; + switch (Channel) { + case 1: + PWM_OUT.GPIO_Pin = 6; + break; + case 2: + PWM_OUT.GPIO_Pin = 7; + break; + case 3: + PWM_OUT.GPIO_Pin = 8; + break; + case 4: + PWM_OUT.GPIO_Pin = 9; + break; + } + } + MyGPIO_Init(&PWM_OUT); +} + +void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle) +{ + unsigned int RC; + RC = ((Timer->ARR)/100)*(DutyCycle); + switch (Channel) { + case 1: + Timer->CCR1 = RC; + break; + + case 2: + Timer->CCR2 = RC; + break; + + case 3: + Timer->CCR3 = RC; + break; + + case 4: + Timer->CCR4 = RC; + break; + } +} \ No newline at end of file diff --git a/driver-siyo/gpiodriver.c b/driver-siyo/gpiodriver.c new file mode 100644 index 0000000..3228fc7 --- /dev/null +++ b/driver-siyo/gpiodriver.c @@ -0,0 +1,70 @@ +#include "gpiodriver.h" + +void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) +{ + RCC->APB2ENR |= GPIO2Int(GPIOStructPtr->GPIO); + //We get the pointer of the CRH/CRL depending on the IO_Pin number + volatile uint32_t * CRAny = GPIOStructPtr->GPIO_Pin >= 0x08 ? &(GPIOStructPtr->GPIO->CRH):&(GPIOStructPtr->GPIO->CRL); + //setup high or low + *CRAny &= ~(0xF << (GPIOStructPtr->GPIO_Pin%8)*4); //reset + //for input pull or push + switch(GPIOStructPtr->GPIO_Conf) + { + case In_PullUp: + GPIOStructPtr->GPIO->ODR |= (0x01 << GPIOStructPtr->GPIO_Pin); //if pullup -> ODR = 1 + *CRAny |= (In_PullDown << (GPIOStructPtr->GPIO_Pin%8)*4); //set pin mode -> force to In_PullDown because PullDown is modified + break; + case In_PullDown: + GPIOStructPtr->GPIO->ODR &= ~(0x01 << GPIOStructPtr->GPIO_Pin); //if pullup -> ODR = 0 + default: + *CRAny |= (GPIOStructPtr->GPIO_Conf << (GPIOStructPtr->GPIO_Pin%8)*4); //set pin mode for any input/output + break; + } +} + +int MyGPIO_Read(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin) +{ + return (GPIO->IDR & (0x1 << GPIO_Pin)) > 0; +} + +void MyGPIO_Set(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin) +{ + GPIO->BSRR = (1 << GPIO_Pin); //BSX set register +} + +void MyGPIO_Reset(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin) +{ + GPIO->BRR = (1 << GPIO_Pin); //BRX = BSX+16 reset register +} + +void MyGPIO_Toggle(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin) +{ + if((GPIO->ODR = GPIO->ODR & (1 << GPIO_Pin)) > 0) + { + GPIO->BRR = (1 << GPIO_Pin); //reset + } else { + GPIO->BSRR = (1 << GPIO_Pin); //set + } +} + +int GPIO2Int(GPIO_TypeDef * GPIOX) +{ + if(GPIOX == GPIOA) + { + return (0x01 << 2); + } else if (GPIOX == GPIOB){ + return (0x01 << 3); + } else if (GPIOX == GPIOC){ + return (0x01 << 4); + } else if (GPIOX == GPIOD){ + return (0x01 << 5); + } else if (GPIOX == GPIOE){ + return (0x01 << 6); + } else if (GPIOX == GPIOF){ + return (0x01 << 7); + } else if (GPIOX == GPIOE){ + return (0x01 << 8); + } else { + return -1; + }; +} diff --git a/driver-siyo/gpiodriver.h b/driver-siyo/gpiodriver.h new file mode 100644 index 0000000..65a297c --- /dev/null +++ b/driver-siyo/gpiodriver.h @@ -0,0 +1,28 @@ +#ifndef GPIODRIVER_H +#define GPIODRIVER_H +#include "stm32f10x.h" + +typedef struct +{ + GPIO_TypeDef * GPIO; //GPIO A,B,C,D... + uint8_t GPIO_Pin; //numero de 0 à 15 + uint8_t GPIO_Conf; //voir ci dessous +} MyGPIO_Struct_TypeDef; + +#define In_Floating 0x04 +#define In_PullDown 0x08 +#define In_PullUp 0xF8 +#define In_Analog 0x00 +#define Out_PullUp 0x01 +#define Out_OD 0x05 +#define AltOut_Ppull 0x09 +#define AltOut_OD 0x0d + +int GPIO2Int(GPIO_TypeDef * GPIOX); +void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr); +int MyGPIO_Read(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin); +void MyGPIO_Set(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin); +void MyGPIO_Reset(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin); +void MyGPIO_Toggle(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin); + +#endif diff --git a/driver-siyo/timerdriver.c b/driver-siyo/timerdriver.c new file mode 100644 index 0000000..0dd11ca --- /dev/null +++ b/driver-siyo/timerdriver.c @@ -0,0 +1,162 @@ +#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< Utiliser SPI1 avec la carte Nucléo + + * **IO SPI 1** + SPI1_NSS PA4 + SPI1_SCK PA5 + SPI1_MISO PA6 + SPI1_MOSI PA7 + + **IO SPI 2** + SPI2_NSS PB12 + SPI2_SCK PB13 + SPI2_MISO PB14 + SPI2_MOSI PB15 + + + + + +************************************************************************************* +==================== Fondamentaux SPI ========================================== +************************************************************************************* +- Bus Synchrone, 4 fils (même si on peut l'utiliser en 3 fils) +- Transfert à l'octet +- Protocole entre un Master (contrôle SCK) et un Slave +- SCK permet de synchroniser les bits de chaque octet. Il se configure par : + * son niveau de repos : ici niveau '1' + * le front actif de synchronisation pour chaque bit : ici front montant (front up durant bit stable) +- /CS ou /NSS active le slave sur l'état bas +- MOSI : Master Out Slave In (donc data circulant du Master vers le Slave, donc écriture dans le Slave) +- MISO : Master In Slave Out (donc data circulant du Slave vers le Master, donc lecture du Slave) + +Bien que la lib propose une fonction d'écriture et de lecture : + * une écriture s'accompagne obligatoirement d'une lecture (bidon) + * une lecture s'accompagne obligatoirement d'une écriture (bidon) +La gestion /CS = /NSS se fait "à la main". On peut alors lire toute une série d'octets +en laissant /CS à l'état bas pendant toute la durée de circulation des octets. + + +************************************************************************************* +==================== La lib SPI ========================================== +************************************************************************************* + +fonctions essentielles : + +MySPI_Init +MySPI_Send +MySPI_Read +MySPI_Set_NSS +MySPI_Clear_NSS + + +==========================================================================================*/ + + + + +/*========================================================================================= + INITIALISATION SPI +========================================================================================= */ + +/** + * @brief Configure le SPI spécifié : FSCK = 281kHz, Repos SCK = '1', Front actif = up + Gestion /CS logicielle à part, configure les 4 IO + - SCK, MOSI : Out Alt push pull + - MISO : floating input + - /NSS (/CS) : Out push pull + * @param SPI_TypeDef * SPI : SPI1 ou SPI2 + */ +void MySPI_Init(SPI_TypeDef * SPI); + + + +/** + * @brief Envoie un octet (/CS non géré, à faire logiciellement) + Plus en détail, émission de l'octet souhaité sur MOSI + Lecture en même temps d'un octet poubelle sur MISO (non exploité) + * @param : char ByteToSend : l'octet à envoyer + */ +void MySPI_Send(char ByteToSend); + + +/** + * @brief Reçoit un octet (/CS non géré, à faire logiciellement) + Plus en détail, émission d'un octet bidon sur MOSI (0x00) + pour élaborer les 8 fronts sur SCK et donc piloter le slave en lecture + qui répond sur MISO + * @param : none + * @retval : l'octet lu. + */ +char MySPI_Read(void); + + + +/** + * @brief Positionne /CS = /NSS à '1'. A utiliser pour borner les octets à transmettre/recevoir + * @param : none + */ +void MySPI_Set_NSS(void); + + + +/** + * @brief Positionne /CS = /NSS à '0'. A utiliser pour borner les octets à transmettre/recevoir + * @param :none + */ +void MySPI_Clear_NSS(void); + +#endif