gpio is compiling corretcly and working as supposed, but let's have look to the implementation

master
Kerem Yollu 4 years ago
parent 6722bf017b
commit 37539d3f06

@ -26,3 +26,13 @@ Good C++ guide:
https://www.youtube.com/watch?v=PakbXnLht1I
#TODO ASAP :
Define a standart header for each code.
Define if we make 2 Standart error function leting us chose to kill or keep the code alive according to the error.
#Next Step :
Code SPI comminucation interface.
Change name organise and make a new Git rep or rename this one.
Prepare evrything for Doxygen.
Start With Cmake.
Sirts Implementation on STM MCU.

@ -45,10 +45,11 @@ int initPlatform()
{
lcd_init(&i2c);
Gpio gpio;
//gpio.setFunction(17,Gpio::gpio);
//gpio.setMode(17,Gpio::output);
// gpio.setFunction(17,Gpio::gpio);
//k gpio.setMode(17,Gpio::output);
//gpio.writePin(17,1);
//gpio.pinUninitiate(17);
gpio.pinUninitiate(17);
gpio.pinList();
return 0;
}

@ -2,6 +2,7 @@
#include "../../systems/systemCall.h"
#include <fstream>
#include <iostream>
#define PIN_COUNT 26
@ -13,6 +14,7 @@ class Gpio::gpioImpl
uint8_t currentPin = 0;
int ck = 0;
std::ifstream bufFile;
pinDefinition pins[PIN_COUNT + 1];
@ -78,7 +80,7 @@ class Gpio::gpioImpl
break;
case alternate:
default :
throwError(notValidMode);
throwError(__LINE__,notValidMode);
break;
}
@ -124,7 +126,7 @@ class Gpio::gpioImpl
}
else
{
throwError(notValidOut);
throwError(__LINE__,notValidOut);
}
}
@ -142,7 +144,7 @@ class Gpio::gpioImpl
void pinInitiate(uint8_t gpioNo)
{
if(gpioNo < PIN_COUNT)
if(gpioNo <= PIN_COUNT)
{
sprintf(buffer,"[ -d /sys/class/gpio/gpio%d ]",gpioNo); // retunrs null if directory exists
ck = system(buffer);
@ -159,13 +161,13 @@ class Gpio::gpioImpl
}
else
{
throwError(pinOutOfRange);
throwError(__LINE__,pinOutOfRange);
}
}
void pinUninitiate(uint8_t gpioNo)
{
if(gpioNo < PIN_COUNT)
if(gpioNo <= PIN_COUNT)
{
sprintf(buffer,"[ -d /sys/class/gpio/gpio%d ]",gpioNo); // retunrs null if directory exists
ck = system(buffer);
@ -176,18 +178,19 @@ class Gpio::gpioImpl
}
else
{
throwError(pinNotDeclared);
throwError(__LINE__,pinNotDeclared);
}
}
else
{
throwError(pinOutOfRange);
throwError(__LINE__,pinOutOfRange);
}
}
void checkCurrentPins()
{
uint8_t i = 0;
for( i = 0; i < PIN_COUNT; i++)
{
sprintf(buffer,"[ -d /sys/class/gpio/gpio%d ]",i); // retunrs null if directory exists
@ -195,11 +198,60 @@ class Gpio::gpioImpl
if( ck == 0)
{
std::cout << "Pin: "<< unsigned(i) << " Exists ";
sprintf(buffer,"/sys/class/gpio/gpio%d/direction",i); // retunrs null if directory exists
bufFile.open(buffer,std::ios::in);
// Reads what is wirtten to define the direction of the pin
if(bufFile.is_open())
{
bufFile.read(buffer,3);
if(buffer[0] == 'i')
{
if (buffer[1] == 'n')
{
pins[i].mode = input; // init of the direction and the rest as a stanard gpio pin.
pins[i].state = openDrain;
pins[i].pud = none;
pins[i].speed = normal;
pins[i].interrupt = disabled;
pins[i].function = gpio;
}
}
else if (buffer[0] == 'o')
{
if(buffer[1] == 'u')
{
if(buffer[2] == 't')
{
pins[i].mode = output;
pins[i].state = openDrain;
pins[i].pud = none;
pins[i].speed = normal;
pins[i].interrupt = disabled;
pins[i].function = gpio;
}
}
}
}
}
}
}
void pinList() // Lists allthe pins whom their mode in not set to undefined.
{
uint8_t i = 0;
for(i = 0; i < PIN_COUNT; i++)
{
if(pins[i].mode != undefined)
{
std::cout << "|Pin "<< unsigned(i) <<" already exists and will be initialized as default GPIO|" << std::endl;
pinPrintInfo(i);
}
}
}
void pinPrintInfo(uint8_t gpioNo)
void pinPrintInfo(uint8_t gpioNo) // a graphical arrangement to see the cunnrently acive pins
{
std::cout << "Pin No: " << unsigned(gpioNo);
switch(pins[gpioNo].mode)
@ -317,11 +369,52 @@ class Gpio::gpioImpl
std::cout << "|" << std::endl;
}
void throwError(Gpio::errors errNo)
void throwError(uint16_t line, Gpio::errors errNo)
{
std::cout << "Error >>GPIO.C<< No >>"<< errNo <<"<<"<< std::endl;
}
std::cout << "Error GPIO.C | Code Line: "<< unsigned(line) << " | Error No: "<< errNo << " | Description: ";
switch(errNo)
{
case notValidMode:
std::cout << "notValidMode";
break;
case notValidOut:
std::cout << "notValidOut";
break;
case pinOutOfRange:
std::cout << "pinOutOfRange";
break;
case pinNotDeclared:
std::cout << "pinNotDeclared";
break;
case pinNotReachable:
std::cout << "pinNotReachable";
break;
case pinNoPullUpDown:
std::cout << "pinNoPullUpDown";
break;
case pinNotAnalog:
std::cout << "pinNotAnalog";
break;
case pinNotDigital:
std::cout << "pinNotDigital";
break;
case pinTooFast:
std::cout << "pinTooFast";
break;
case pinBocked:
std::cout << "pinBocked";
break;
case pinAlreadyUsed:
std::cout << "pinAlreadyUsed";
break;
default:
std::cout << "Unhandled Error";
break;
}
std::cout << " |" << std::endl;
}
};
Gpio::Gpio():gpioPimpl(new gpioImpl()){}
@ -392,13 +485,17 @@ void Gpio::checkCurrentPins()
return gpioPimpl->checkCurrentPins();
}
void Gpio::pinList()
{
return gpioPimpl->pinList();
}
void Gpio::pinPrintInfo(uint8_t gpioNo)
{
return gpioPimpl->pinPrintInfo(gpioNo);
}
void Gpio::throwError(Gpio::errors error)
void Gpio::throwError(uint16_t line, Gpio::errors error)
{
return gpioPimpl->throwError(error);
return gpioPimpl->throwError(line, error);
}

@ -107,10 +107,11 @@ class Gpio
void pinUninitiate(uint8_t gpioNo);
void checkCurrentPins();
void pinList();
void pinPrintInfo(uint8_t gpioNo);
private:
void throwError(errors errNo);
void throwError(uint16_t line, errors errNo);
class gpioImpl;
std::unique_ptr<gpioImpl> gpioPimpl;
};

Binary file not shown.
Loading…
Cancel
Save