forked from trocache/RefKEIL
Ajout de l'init et du read
This commit is contained in:
parent
f2e66b6b9d
commit
8dc81c0256
4 changed files with 59 additions and 15 deletions
|
@ -1,5 +1,43 @@
|
||||||
#include "Driver_GPIO.h"
|
#include "Driver_GPIO.h"
|
||||||
|
|
||||||
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) {
|
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) {
|
||||||
|
//Configurer les horloges
|
||||||
|
if(GPIOStructPtr->GPIO == GPIOA){
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;//RCC->APB2ENR = 0x02;
|
||||||
|
}
|
||||||
|
else if(GPIOStructPtr->GPIO == GPIOB){
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;//RCC->APB2ENR = 0x03;
|
||||||
|
}
|
||||||
|
else if (GPIOStructPtr->GPIO == GPIOC){
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; //RCC->APB2ENR = 0x04;
|
||||||
|
}
|
||||||
|
//Initialiser le registre urilisé
|
||||||
|
if (GPIOStructPtr->GPIO_Pin < 8) {
|
||||||
|
GPIOStructPtr->GPIO->CRL &= ~(0xF << (4 * GPIOStructPtr->GPIO_Pin));
|
||||||
|
GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf << (4 * GPIOStructPtr->GPIO_Pin));
|
||||||
|
} else {
|
||||||
|
GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * GPIOStructPtr->GPIO_Pin));
|
||||||
|
GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf << (4* GPIOStructPtr->GPIO_Pin));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||||
|
if((GPIO->IDR) &= (1 << GPIO_Pin)!=0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,14 +9,14 @@ typedef struct {
|
||||||
} MyGPIO_Struct_TypeDef;
|
} MyGPIO_Struct_TypeDef;
|
||||||
|
|
||||||
|
|
||||||
#define In_Floating 0x4 // 0x0100
|
#define In_Floating 0x4 // 0b0100
|
||||||
#define In_PullDown 0x... // a completer
|
#define In_PullDown 0x8
|
||||||
#define In_PullUp 0x... // a completer
|
#define In_PullUp 0x8
|
||||||
#define In_Analog 0x... // a completer
|
#define In_Analog 0x0
|
||||||
#define Out_Ppull 0x... // a completer
|
#define Out_Ppull 0x1
|
||||||
#define Out_OD 0x... // a completer
|
#define Out_OD 0x6
|
||||||
#define AltOut_Ppull 0x... // a completer
|
#define AltOut_Ppull 0x5
|
||||||
#define AltOut_OD 0x... // a completer
|
#define AltOut_OD 0xD
|
||||||
|
|
||||||
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr);
|
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr);
|
||||||
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin); // renvoie 0 ou autre chose d i f f e r e n t de 0
|
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin); // renvoie 0 ou autre chose d i f f e r e n t de 0
|
||||||
|
|
|
@ -1,26 +1,32 @@
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
#include "Driver_GPIO.h"
|
#include "Driver_GPIO.h"
|
||||||
|
|
||||||
|
|
||||||
|
// PA5 LED
|
||||||
|
// PC13 BP
|
||||||
|
|
||||||
|
MyGPIO_Struct_TypeDef LED;
|
||||||
|
|
||||||
int main ( void )
|
int main ( void )
|
||||||
{
|
{
|
||||||
// Clocks des ports A, B, C
|
// Clocks des ports A, B, C
|
||||||
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) ;
|
//RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) ;
|
||||||
|
|
||||||
GPIOA->CRL &= ~(0xF << 20); // Mise à 0
|
GPIOA->CRL &= ~(0xF << 20); // Mise à 0
|
||||||
GPIOA->CRL |= (0x1 << 20); // Output
|
GPIOA->CRL |= (0x1 << 20); // Output
|
||||||
GPIOA->BSRR |= (0x01 << 5);
|
GPIOA->BSRR |= (0x01 << 5);
|
||||||
|
|
||||||
// Configure PC13 as input with pull-up
|
// Configure PC13 as input with pull-up
|
||||||
GPIOC->CRH &=~ (1<<)
|
GPIOC->CRH &=~ (1<<13);
|
||||||
|
|
||||||
GPIOC->CRH &= ~(0x1 << 22)
|
GPIOC->CRH &= ~(0x1 << 22);
|
||||||
GPIOC->CRH |= GPIO_CRH_CNF13_1;
|
GPIOC->CRH |= GPIO_CRH_CNF13_1; // BP = PC13
|
||||||
GPIOC->ODR |= GPIO_ODR_ODR13;
|
GPIOC->ODR |= GPIO_ODR_ODR13;
|
||||||
|
|
||||||
//GPIOA->BSRR |= (1 << 21);
|
//GPIOA->BSRR |= (1 << 21);
|
||||||
|
|
||||||
|
|
||||||
for (;;)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,7 @@
|
||||||
<GroupNumber>2</GroupNumber>
|
<GroupNumber>2</GroupNumber>
|
||||||
<FileNumber>2</FileNumber>
|
<FileNumber>2</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<bDave2>0</bDave2>
|
<bDave2>0</bDave2>
|
||||||
<PathWithFileName>..\Drivers\Driver_GPIO.c</PathWithFileName>
|
<PathWithFileName>..\Drivers\Driver_GPIO.c</PathWithFileName>
|
||||||
|
|
Loading…
Reference in a new issue