Created
January 23, 2023 09:28
-
-
Save M0nteCarl0/3009bb1617a8c4f36e72d3c42db6d603 to your computer and use it in GitHub Desktop.
STM32MP1 GpioControler HAL driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* GpioControler.cpp | |
* | |
* Created on: Sep 30, 2019 | |
* Author: M0nteCarl0 | |
*/ | |
#include "GpioControler.h" | |
GpioControler::GpioControler():MaxCountBank(0),MaxCountLinesPerBank(0),Iter(nullptr),Chip(nullptr){ | |
} | |
GpioControler::~GpioControler(){ | |
MaxCountBank = 0; | |
MaxCountLinesPerBank = 0; | |
Iter = nullptr; | |
Chip = nullptr; | |
} | |
int GpioControler::Reset(int ChipID,int Offset){ | |
return Write(ChipID,Offset,0); | |
} | |
int GpioControler::Init(void){ | |
int State = 0; | |
return State; | |
} | |
int GpioControler::Set(int ChipID,int Offset){ | |
return Write(ChipID,Offset,1); | |
} | |
int GpioControler::Write(int ChipID,int Offset,int Value){ | |
char device[255]; | |
int State = 0; | |
sprintf(device,"gpiochip%i",ChipID); | |
State = gpiod_ctxless_set_value(device,Offset,Value, | |
true, "gpiowrite", | |
nullptr, | |
nullptr); | |
return State; | |
} | |
int GpioControler::Read(int ChipID,int Offset) | |
{ | |
char device[255]; | |
int State = 0; | |
sprintf(device,"gpiochip%i",ChipID); | |
State = gpiod_ctxless_get_value(device, Offset, | |
true, "gpioread"); | |
return State; | |
} | |
int GpioControler::SetMode(int ChipID,int Offset,int Mode){ | |
int State = 0; | |
return State; | |
} | |
const int GpioControler::Get(int ChipID,int Offset){ | |
int State = 0; | |
return State; | |
} | |
const int GpioControler::GetMode(int ChipID,int Offset){ | |
int GpioMode = 0; | |
return GpioMode; | |
} | |
const int GpioControler::GetChipCount(void){ | |
int GpioChipCount = 0; | |
return GpioChipCount; | |
} | |
const int GpioControler::GetNumLines(int ChipID){ | |
int GpioLinesCount = 0; | |
return GpioLinesCount; | |
} | |
int GpioControler::Blink(int ChipID,int Offset,int Count,int Time){ | |
int State = 0; | |
this->Reset(ChipID,Offset); | |
for(int i = 0; i < Count; i++){ | |
this->Set(ChipID,Offset); | |
sleep(Time); | |
this->Reset(ChipID,Offset); | |
sleep(Time); | |
} | |
this->Set(ChipID,Offset); | |
return State; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* GpioControler.h | |
* | |
* Created on: Sep 30, 2019 | |
* Author: M0nteCarl0 | |
*/ | |
#ifndef GPIOCONTROLER_H_ | |
#define GPIOCONTROLER_H_ | |
#include <unistd.h> | |
#include <gpiod.h> | |
#include <cstdio> | |
typedef enum GpioControlerPort | |
{ | |
GpioControlerPort_PORTA, | |
GpioControlerPort_PORTB, | |
GpioControlerPort_PORTC, | |
GpioControlerPort_PORTD, | |
GpioControlerPort_PORTE, | |
GpioControlerPort_PORTF, | |
GpioControlerPort_PORTG, | |
GpioControlerPort_PORTH, | |
GpioControlerPort_PORTI, | |
GpioControlerPort_PORTJ, | |
}GpioControlerPort; | |
typedef enum GpioControler_Pin | |
{ | |
GpioControler_Pin_0, | |
GpioControler_Pin_1, | |
GpioControler_Pin_2, | |
GpioControler_Pin_3, | |
GpioControler_Pin_4, | |
GpioControler_Pin_5, | |
GpioControler_Pin_6, | |
GpioControler_Pin_7, | |
GpioControler_Pin_8, | |
GpioControler_Pin_9, | |
GpioControler_Pin_10, | |
GpioControler_Pin_11, | |
GpioControler_Pin_12, | |
GpioControler_Pin_13, | |
GpioControler_Pin_14, | |
GpioControler_Pin_15, | |
}GpioControler_Pin; | |
class GpioControler { | |
public: | |
GpioControler(); | |
virtual ~GpioControler(); | |
int Init(void); | |
int Set(int ChipID,int Offset); | |
int Reset(int ChipID,int Offset); | |
int Write(int ChipID,int Offset,int Value); | |
int Read(int ChipID,int Offset); | |
int SetMode(int ChipID,int Offset,int Mode); | |
int Blink(int ChipID,int Offset,int Count,int Time); | |
const int Get(int ChipID,int Offset); | |
const int GetMode(int ChipID,int Offset); | |
const int GetChipCount(void); | |
const int GetNumLines(int ChipID); | |
private: | |
int MaxCountBank; | |
int MaxCountLinesPerBank; | |
struct gpiod_chip_iter *Iter; | |
struct gpiod_chip *Chip; | |
}; | |
#endif /* GPIOCONTROLER_H_ */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment