You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
2.3 KiB
134 lines
2.3 KiB
#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
|
|
{
|
|
// NAME = BASE ADDR | PORT | PIN NO
|
|
pinA0 = GPIOA_BASE | 0x00 | 0,
|
|
pinA1 = GPIOA_BASE | 0x00 | 1,
|
|
pinA2 = GPIOA_BASE | 0x00 | 2,
|
|
pinA3 = GPIOA_BASE | 0x00 | 3,
|
|
pinA4 = GPIOA_BASE | 0x00 | 4,
|
|
pinA5 = GPIOA_BASE | 0x00 | 5,
|
|
pinA6 = GPIOA_BASE | 0x00 | 6,
|
|
pinA7 = GPIOA_BASE | 0x00 | 7,
|
|
pinA8 = GPIOA_BASE | 0x00 | 8,
|
|
pinA9 = GPIOA_BASE | 0x00 | 9,
|
|
pinA10 = GPIOA_BASE | 0x00 | 10,
|
|
pinA11 = GPIOA_BASE | 0x00 | 11,
|
|
pinA12 = GPIOA_BASE | 0x00 | 12,
|
|
pinA13 = GPIOA_BASE | 0x00 | 13,
|
|
pinA14 = GPIOA_BASE | 0x00 | 14,
|
|
pinA15 = GPIOA_BASE | 0x00 | 15,
|
|
|
|
pinB0 = GPIOB_BASE | 0x10 | 0,
|
|
pinB1 = GPIOB_BASE | 0x10 | 1,
|
|
pinB3 = GPIOB_BASE | 0x10 | 3,
|
|
pinB4 = GPIOB_BASE | 0x10 | 4,
|
|
pinB5 = GPIOB_BASE | 0x10 | 5,
|
|
pinB6 = GPIOB_BASE | 0x10 | 6,
|
|
pinB7 = GPIOB_BASE | 0x10 | 7,
|
|
pinB8 = GPIOB_BASE | 0x10 | 8,
|
|
|
|
pinF0 = GPIOF_BASE | 0x20 | 0,
|
|
pinF1 = GPIOF_BASE | 0x20 | 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 pinSetMode(pinNo_t pinNo, mode mode);
|
|
void pinSetOutputState(pinNo_t pinNo, state state);
|
|
void pinSetPullUpDonw(pinNo_t pinNo, pullUpDown resistance);
|
|
void pinSetSpeed(pinNo_t pinNo, speed speed);
|
|
void pinConfig(pinNo_t pinNo, mode mode, state state, pullUpDown resistance, speed speed);
|
|
|
|
uint8_t pinRead(pinNo_t pinNo);
|
|
void pinToggle(pinNo_t pinNo);
|
|
void pinWrite(pinNo_t pinNo, uint8_t state);
|
|
|
|
void pinInit(pinNo_t pinNo);
|
|
void pinDeInit(pinNo_t pinNo);
|
|
|
|
void pinHardwareInfo(pinNo_t pinNo);
|
|
void pinThrowError();
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // _GPIO_H_
|