parent
3575bb4c5a
commit
b98868c432
@ -0,0 +1,132 @@
|
|||||||
|
#ifndef _GPIO_H_
|
||||||
|
#define _GPIO_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ARM_MCU
|
||||||
|
#include "../stm32f042/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h"
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
pinA0 = GPIOA_BASE || 0,
|
||||||
|
pinA1 = GPIOA_BASE || 1,
|
||||||
|
pinA2 = GPIOA_BASE || 2,
|
||||||
|
pinA3 = GPIOA_BASE || 3,
|
||||||
|
pinA4 = GPIOA_BASE || 4,
|
||||||
|
pinA5 = GPIOA_BASE || 5,
|
||||||
|
pinA6 = GPIOA_BASE || 6,
|
||||||
|
pinA7 = GPIOA_BASE || 7,
|
||||||
|
pinA8 = GPIOA_BASE || 8,
|
||||||
|
pinA9 = GPIOA_BASE || 9,
|
||||||
|
pinA10 = GPIOA_BASE || 10,
|
||||||
|
pinA11 = GPIOA_BASE || 11,
|
||||||
|
pinA12 = GPIOA_BASE || 12,
|
||||||
|
pinA13 = GPIOA_BASE || 13,
|
||||||
|
pinA14 = GPIOA_BASE || 14,
|
||||||
|
pinA15 = GPIOA_BASE || 15,
|
||||||
|
|
||||||
|
pinB0 = GPIOB_BASE || 0,
|
||||||
|
pinB1 = GPIOB_BASE || 1,
|
||||||
|
pinB3 = GPIOB_BASE || 3,
|
||||||
|
pinB4 = GPIOB_BASE || 4,
|
||||||
|
pinB5 = GPIOB_BASE || 5,
|
||||||
|
pinB6 = GPIOB_BASE || 6,
|
||||||
|
pinB7 = GPIOB_BASE || 7,
|
||||||
|
pinB8 = GPIOB_BASE || 8,
|
||||||
|
|
||||||
|
pinF0 = GPIOF_BASE || 0,
|
||||||
|
pinF1 = GPIOF_BASE || 1
|
||||||
|
}pinNo_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RASPBERRY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
undefined,
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
analog,
|
||||||
|
alternate
|
||||||
|
}mode;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
floating,
|
||||||
|
pushPull,
|
||||||
|
openDrain
|
||||||
|
}state;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
none,
|
||||||
|
pullUp,
|
||||||
|
pullDown
|
||||||
|
}pullUpDown;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
slow,
|
||||||
|
normal,
|
||||||
|
fast,
|
||||||
|
veryFast
|
||||||
|
}speed;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
disabled,
|
||||||
|
enabled
|
||||||
|
}interrupt;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
mode md;
|
||||||
|
state st;
|
||||||
|
pullUpDown pud;
|
||||||
|
speed sp;
|
||||||
|
interrupt intr;
|
||||||
|
}configuration;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
notValidMode,
|
||||||
|
notValidOut,
|
||||||
|
OutOfRange,
|
||||||
|
NotDeclared,
|
||||||
|
NotReachable,
|
||||||
|
NoPullUpDown,
|
||||||
|
NotAnalog,
|
||||||
|
NotDigital,
|
||||||
|
TooFast,
|
||||||
|
Bocked,
|
||||||
|
AlreadyUsed,
|
||||||
|
NotGpio
|
||||||
|
}errors;
|
||||||
|
|
||||||
|
void setMode(pinNo_t pinNo, mode mode);
|
||||||
|
void setOutputState(pinNo_t pinNo, state state);
|
||||||
|
void setPullUpDonw(pinNo_t pinNo, pullUpDown resistance);
|
||||||
|
void setSpeed(pinNo_t pinNo, speed speed);
|
||||||
|
void config(pinNo_t pinNo, mode mode, state state, pullUpDown resistance, speed speed);
|
||||||
|
|
||||||
|
uint8_t get(pinNo_t pinNo);
|
||||||
|
void toggle(pinNo_t pinNo);
|
||||||
|
void set(pinNo_t pinNo, uint8_t state);
|
||||||
|
|
||||||
|
void init(pinNo_t pinNo);
|
||||||
|
void deInit(pinNo_t pinNo);
|
||||||
|
|
||||||
|
void hardwareInfo(pinNo_t pinNo);
|
||||||
|
void throwError();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _GPIO_H_
|
@ -1,92 +0,0 @@
|
|||||||
#ifndef _GPIO_H_
|
|
||||||
#define _GPIO_H_
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
class Pin
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum mode
|
|
||||||
{
|
|
||||||
undefined,
|
|
||||||
input,
|
|
||||||
output,
|
|
||||||
analog,
|
|
||||||
alternate
|
|
||||||
};
|
|
||||||
|
|
||||||
enum state
|
|
||||||
{
|
|
||||||
floating,
|
|
||||||
pushPull,
|
|
||||||
openDrain
|
|
||||||
};
|
|
||||||
|
|
||||||
enum pullUpDown
|
|
||||||
{
|
|
||||||
none,
|
|
||||||
pullUp,
|
|
||||||
pullDown
|
|
||||||
};
|
|
||||||
|
|
||||||
enum speed
|
|
||||||
{
|
|
||||||
slow,
|
|
||||||
normal,
|
|
||||||
fast,
|
|
||||||
veryFast
|
|
||||||
};
|
|
||||||
|
|
||||||
enum interrupt
|
|
||||||
{
|
|
||||||
disabled,
|
|
||||||
enabled
|
|
||||||
};
|
|
||||||
|
|
||||||
struct configuration
|
|
||||||
{
|
|
||||||
mode md;
|
|
||||||
state st;
|
|
||||||
pullUpDown pud;
|
|
||||||
speed sp;
|
|
||||||
interrupt intr;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum errors
|
|
||||||
{
|
|
||||||
notValidMode,
|
|
||||||
notValidOut,
|
|
||||||
OutOfRange,
|
|
||||||
NotDeclared,
|
|
||||||
NotReachable,
|
|
||||||
NoPullUpDown,
|
|
||||||
NotAnalog,
|
|
||||||
NotDigital,
|
|
||||||
TooFast,
|
|
||||||
Bocked,
|
|
||||||
AlreadyUsed,
|
|
||||||
NotGpio
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual void setMode(mode mode) = 0;
|
|
||||||
virtual void setOutputState(state state) = 0;
|
|
||||||
virtual void setPullUpDonw(pullUpDown resistance) = 0;
|
|
||||||
virtual void setSpeed(speed speed) = 0;
|
|
||||||
virtual void config(mode mode, state state, pullUpDown resistance, speed speed) = 0;
|
|
||||||
|
|
||||||
virtual bool read() = 0;
|
|
||||||
virtual void toggle() = 0;
|
|
||||||
virtual void write(bool state) = 0;
|
|
||||||
|
|
||||||
virtual void init() = 0;
|
|
||||||
virtual void deInit() = 0;
|
|
||||||
|
|
||||||
virtual void hardwareInfo() = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual void throwError(uint16_t line, errors errNo) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _GPIO_H_
|
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef __STM_PIN_HPP__
|
#ifndef __STM_PIN_HPP__
|
||||||
#define __STM_PIN_HPP__
|
#define __STM_PIN_HPP__
|
||||||
|
|
||||||
#include "../../interfaces/pin.hpp"
|
//#include "../../interfaces/pin.hpp"
|
||||||
#include "../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h"
|
//#include "../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
@ -0,0 +1,75 @@
|
|||||||
|
#include "pin.h"
|
||||||
|
|
||||||
|
|
||||||
|
void setMode(pinNo_t pinNo, mode mode)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void setOutputState(pinNo_t pinNo, state state)
|
||||||
|
{
|
||||||
|
RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
|
||||||
|
// Set PIN 3 of port B as Output
|
||||||
|
GPIOB->MODER |= GPIO_MODER_MODER3_0;
|
||||||
|
GPIOB->MODER &=~ GPIO_MODER_MODER3_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPullUpDonw(pinNo_t pinNo, pullUpDown resistance)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSpeed(pinNo_t pinNo, speed speed)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void config(pinNo_t pinNo, mode mode, state state, pullUpDown resistance, speed speed)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t get(pinNo_t pinNo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggle(pinNo_t pinNo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(pinNo_t pinNo, uint8_t state)
|
||||||
|
{
|
||||||
|
if(state == 1)
|
||||||
|
{
|
||||||
|
GPIOB->BSRR |= GPIO_BSRR_BS_3;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GPIOB->BSRR |= GPIO_BSRR_BR_3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init(pinNo_t pinNo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void deInit(pinNo_t pinNo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void hardwareInfo(pinNo_t pinNo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void throwError()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue