Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
Gpio.h
1#pragma once
2#include <cstdint>
3#include "Mmap.h"
4
5class Gpio{
6public:
7 Gpio();
8
9 ~Gpio();
10
11 typedef enum {
12 INPUT,
13 OUTPUT,
14 } Direction;
15
25 int open(unsigned int pin, Direction direction, bool unexport = true);
26
30 void close();
31
36 bool read(){
37 return (gpio[GPIO_DATAIN] & pinMask);
38 }
39
43 void set(){
44 gpio[GPIO_SETDATAOUT] = pinMask;
45 }
46
49 void clear(){
50 gpio[GPIO_CLEARDATAOUT] = pinMask;
51 }
52
57 void write(bool value){
58 if(value){
59 set();
60 } else {
61 clear();
62 }
63 }
64
70 bool enabled(){
71 return nullptr != gpio;
72 }
73
77 static uint32_t getBankAddress(unsigned int bank);
78private:
79 static constexpr uint32_t GPIO_DATAIN = (0x138 / 4);
80 static constexpr uint32_t GPIO_CLEARDATAOUT = (0x190 / 4);
81 static constexpr uint32_t GPIO_SETDATAOUT = (0x194 / 4);
82 bool shouldUnexport;
83 Mmap mmap;
84 int pin;
85 uint32_t pinMask;
86 volatile uint32_t* gpio;
87};
int open(unsigned int pin, Direction direction, bool unexport=true)
void clear()
Definition Gpio.h:49
void set()
Definition Gpio.h:43
void write(bool value)
Definition Gpio.h:57
static uint32_t getBankAddress(unsigned int bank)
bool read()
Definition Gpio.h:36
bool enabled()
Definition Gpio.h:70
void close()
Definition Mmap.h:4