##// END OF EJS Templates
Removed error on fat32 library, seems now to be able navigate among sectors in...
Removed error on fat32 library, seems now to be able navigate among sectors in both directions. Improved SDLCD drawing performances by almost 1000x.

File last commit:

r64:b702edc52366 dev_alexis
r68:104125d87b89 dev_alexis
Show More
gpio.c
392 lines | 8.7 KiB | text/x-c | CLexer
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 /*------------------------------------------------------------------------------
-- This file is a part of the libuc, microcontroler library
-- Copyright (C) 2012, Alexis Jeandet
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------
-- Author : Alexis Jeandet
Jeandet Alexis
sync
r64 -- Mail : alexis.jeandet@member.fsf.org
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 -------------------------------------------------------------------------------*/
#include <gpio.h>
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_rcc.h>
#define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
#define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
gpio_t gpioopen(uint32_t gpio)
{
gpio &= -1^GPIOSPEEDMASK;
gpio |= gpiolowspeed;
gpio &= -1^GPIODIRMASK;
gpio |= gpioindir;
gpio &= -1^GPIOOUTTYPEMASK;
gpio |= gpiopushpulltype;
gpio &= -1^GPIOPULLTYPEMASK;
gpio |= gpionopulltype;
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 gpiosetconfig(&gpio);
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 RCC_AHB1PeriphClockCmd(((uint32_t)0x00000001<<GPIOPORTNUM(gpio)), ENABLE);
return gpio;
}
void gpioclose(gpio_t gpio)
{
}
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 void gpiosetconfig(gpio_t* gpio)
{
gpiosetdir(gpio, (*gpio & GPIODIRMASK));
gpiosetspeed(gpio, (*gpio & GPIOSPEEDMASK));
gpiosetouttype(gpio, (*gpio & GPIOOUTTYPEMASK));
gpiosetpulltype(gpio, (*gpio & GPIOPULLTYPEMASK));
}
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 extern void gpiosetspeed(gpio_t* gpio,gpiospeed_t speed)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIO_TypeDef* GPIOx = GPIOGETPORT((*gpio));
switch(speed)
{
case gpiolowspeed :
if((*gpio & 0xFF)==0xFF)
{
for(int i=0;i<16;i++)
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (i * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_2MHz) << (i * 2));
}
}
else
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << ((*gpio & 0xFF) * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_2MHz) << ((*gpio & 0xFF) * 2));
}
*gpio &= ~GPIOSPEEDMASK;
*gpio |= gpiolowspeed;
break;
case gpiomediumspeed :
if((*gpio & 0xFF)==0xFF)
{
for(int i=0;i<16;i++)
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (i * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_25MHz) << (i * 2));
}
}
else
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << ((*gpio & 0xFF) * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_25MHz) << ((*gpio & 0xFF) * 2));
}
*gpio &= ~GPIOSPEEDMASK;
*gpio |= gpiomediumspeed;
break;
case gpiofastspeed :
if((*gpio & 0xFF)==0xFF)
{
for(int i=0;i<16;i++)
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (i * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_50MHz) << (i * 2));
}
}
else
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << ((*gpio & 0xFF) * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_50MHz) << ((*gpio & 0xFF) * 2));
}
*gpio &= ~GPIOSPEEDMASK;
*gpio |= gpiofastspeed;
break;
case gpiohighspeed :
if((*gpio & 0xFF)==0xFF)
{
for(int i=0;i<16;i++)
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (i * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_100MHz) << (i * 2));
}
}
else
{
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << ((*gpio & 0xFF) * 2));
GPIOx->OSPEEDR |= ((uint32_t)(GPIO_Speed_100MHz) << ((*gpio & 0xFF) * 2));
}
*gpio &= ~GPIOSPEEDMASK;
*gpio |= gpiohighspeed;
break;
}
}
void gpiosetdir(gpio_t* gpio,gpiodir_t dir)
{
GPIO_TypeDef* GPIOx = GPIOGETPORT((*gpio));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 switch(dir)
{
case gpiooutdir:
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 if((*gpio & 0xFF)==0xFF)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
for(int i=0;i<16;i++)
{
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (i * 2));
GPIOx->MODER |= (GPIO_Mode_OUT << (i * 2));
}
}
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIOx->MODER &= ~(GPIO_MODER_MODER0 << ((*gpio & 0xFF) * 2));
GPIOx->MODER |= (GPIO_Mode_OUT << ((*gpio & 0xFF) * 2));
}
*gpio &= ~GPIODIRMASK;
*gpio |= gpiooutdir;
break;
case gpioaf:
if((*gpio & 0xFF)==0xFF)
{
for(int i=0;i<16;i++)
{
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (i * 2));
GPIOx->MODER |= (GPIO_Mode_AF << (i * 2));
}
}
else
{
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << ((*gpio & 0xFF) * 2));
GPIOx->MODER |= (GPIO_Mode_AF << ((*gpio & 0xFF) * 2));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 *gpio &= ~GPIODIRMASK;
*gpio |= gpioaf;
break;
case gpioan:
if((*gpio & 0xFF)==0xFF)
{
for(int i=0;i<16;i++)
{
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (i * 2));
GPIOx->MODER |= (GPIO_Mode_AN << (i * 2));
}
}
else
{
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << ((*gpio & 0xFF) * 2));
GPIOx->MODER |= (GPIO_Mode_AN << ((*gpio & 0xFF) * 2));
}
*gpio &= ~GPIODIRMASK;
*gpio |= gpioan;
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 break;
default :
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 if((*gpio & 0xFF)==0xFF)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
for(int i=0;i<16;i++)
{
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (i * 2));
GPIOx->MODER |= (GPIO_Mode_IN << (i * 2));
}
}
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIOx->MODER &= ~(GPIO_MODER_MODER0 << ((*gpio & 0xFF) * 2));
GPIOx->MODER |= (GPIO_Mode_IN << ((*gpio & 0xFF) * 2));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 *gpio &= ~GPIODIRMASK;
*gpio |= gpioindir;
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 break;
}
}
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 void gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIO_TypeDef* GPIOx = GPIOGETPORT((*gpio));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 if(outtype == gpioopendraintype)
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 if((*gpio & 0xFF)==0xFF)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
for(int i=0;i<16;i++)
{
GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)i));
GPIOx->OTYPER |= (uint16_t)(GPIO_OType_OD<<((uint16_t)i));
}
}
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)(*gpio & 0xFF)));
GPIOx->OTYPER |= (uint16_t)(GPIO_OType_OD<<((uint16_t)(*gpio & 0xFF)));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 *gpio &= ~GPIOOUTTYPEMASK;
*gpio |= gpioopendraintype;
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 if((*gpio & 0xFF)==0xFF)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
for(int i=0;i<16;i++)
{
GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)i));
GPIOx->OTYPER |= (uint16_t)(GPIO_OType_PP<<((uint16_t)i));
}
}
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)(*gpio & 0xFF)));
GPIOx->OTYPER |= (uint16_t)(GPIO_OType_PP<<((uint16_t)(*gpio & 0xFF)));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 *gpio &= ~GPIOOUTTYPEMASK;
*gpio |= gpiopushpulltype;
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
}
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 void gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIO_TypeDef* GPIOx = GPIOGETPORT(*gpio);
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 switch(pulltype)
{
case gpiopulluptype:
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 if((*gpio & 0xFF)==0xFF)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
for(int i=0;i<16;i++)
{
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)i * 2));
GPIOx->PUPDR |= (GPIO_PuPd_UP << (i * 2));
}
}
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)(*gpio & 0xFF) * 2));
GPIOx->PUPDR |= (GPIO_PuPd_UP << ((*gpio & 0xFF) * 2));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 *gpio &= ~GPIOPULLTYPEMASK;
*gpio |= gpiopulluptype;
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 break;
case gpiopulldowntype:
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 if((*gpio & 0xFF)==0xFF)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
for(int i=0;i<16;i++)
{
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)i * 2));
GPIOx->PUPDR |= (GPIO_PuPd_DOWN << (i * 2));
}
}
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)(*gpio & 0xFF) * 2));
GPIOx->PUPDR |= (GPIO_PuPd_DOWN << ((*gpio & 0xFF) * 2));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 *gpio &= ~GPIOPULLTYPEMASK;
*gpio |= gpiopulldowntype;
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 break;
default :
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 if((*gpio & 0xFF)==0xFF)
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 {
for(int i=0;i<16;i++)
{
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)i * 2));
GPIOx->PUPDR |= (GPIO_PuPd_NOPULL << (i * 2));
}
}
else
{
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)(*gpio & 0xFF) * 2));
GPIOx->PUPDR |= (GPIO_PuPd_NOPULL << ((*gpio & 0xFF) * 2));
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
Now uses qmake to compile an Qt-creator compatible!
r18 *gpio &= ~GPIOPULLTYPEMASK;
*gpio |= gpionopulltype;
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 break;
}
}
void gpioset(gpio_t gpio)
{
GPIO_TypeDef* GPIOx = GPIOGETPORT(gpio);
if((gpio & 0xFF)==0xFF)
{
GPIOx->BSRRL = -1;
}
else
{
GPIOx->BSRRL = 1<<(gpio & 0xFF);
}
}
void gpioclr(gpio_t gpio)
{
GPIO_TypeDef* GPIOx = GPIOGETPORT(gpio);
if((gpio & 0xFF)==0xFF)
{
GPIOx->BSRRH = -1;
}
else
{
GPIOx->BSRRH = 1<<(gpio & 0xFF);
}
}
void gpiosetval(gpio_t gpio,int val)
{
GPIO_TypeDef* GPIOx = GPIOGETPORT(gpio);
if((gpio & 0xFF)==0xFF)
{
GPIOx->ODR = val;
}
else
{
Added Oplayer BSP, Fixed bug on GPIO library(gpiosetval change all the port...
r60 if(val)
GPIOx->BSRRL = 1<<(gpio & 0xFF);
else
GPIOx->BSRRH = 1<<(gpio & 0xFF);
jeandet@pc-de-jeandet3.lab-lpp.local
Cleaned source tree....
r16 }
}
int gpiogetval(gpio_t gpio)
{
GPIO_TypeDef* GPIOx = GPIOGETPORT(gpio);
if((gpio & 0xFF)==0xFF)
{
return GPIOx->IDR;
}
else
{
return ((GPIOx->IDR>>(gpio & 0xFF)) & 1);
}
}