Sure.
Code: Select all
CPP = g++
CFLAGS = -O2 -std=c++14 -D_RPI
INC = -I/opt/vc/include
DEPS = fruitbox.hpp fruitbox_types.hpp pages.hpp status.hpp playqueue.hpp audio.hpp config.hpp config_base.hpp database.hpp display.hpp \
engine.hpp fruitbox_logo.hpp info_bkgnd.hpp chooser_arrow.hpp info_font.hpp status_events.hpp userguide.hpp bitmap.hpp joystick.hpp \
display_base.hpp input.hpp gpio.hpp
OBJ = fruitbox.o playqueue.o audio.o config.o database.o display.o engine.o pages.o status.o userguide.o bitmap.o joystick.o input.o gpio.o
LIBS = \
-lmpg123 \
-lallegro -lallegro_memfile -lallegro_font -lallegro_ttf -lallegro_primitives \
-lallegro_image -lallegro_audio -lallegro_acodec -lallegro_video \
-lm -ldl -L/opt/vc/lib/ -lpthread
%.o: %.cpp $(DEPS)
$(CPP) -c -o $@ $< $(CFLAGS) $(INC)
# ./fruitbox: $(OBJ)
../fruitbox: $(OBJ)
$(CPP) -Wall -o $@ $^ $(CFLAGS) $(LIBS) `pkg-config --libs`
.PHONY: clean
clean:
rm -f *.o
rm -f ../fruitbox
touch Makefile
touch *.?ppThe value 0x7E000000 + 0x200000 is just arbitrary. I have absolutely no clue of where the GPIO pins sit in a Pi4. So this is WRONG. But as I am not using any GPIO pins for anything I just put in some guess.
Code: Select all
void GpioClass::OpenDevice(void)
{
#ifdef _RPI
uint32_t mem_fd;
void *reg_map;
if (gpio_base != nullptr) return; // already opened
// /dev/mem is a psuedo-driver for accessing memory in the Linux filesystem
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0)
{
error("can't open /dev/mem");
}
reg_map = mmap
(
NULL, // Address at which to start local mapping (null means don't-care)
BLOCK_SIZE, // Size of mapped memory block
PROT_READ|PROT_WRITE, // Enable both reading and writing to the mapped memory
MAP_SHARED, // This program does not have exclusive access to this memory
mem_fd, // Map to /dev/mem
0x7E000000 + 0x200000 // Offset to GPIO peripheral
);
if (reg_map == MAP_FAILED)
{
close(mem_fd);
error("gpio mmap error.\nTry running fruitbox as sudo (i.e. sudo ./fruitbox --cfg ...)");
}
gpio_base = (volatile uint32_t *)reg_map;
// first save the state of the GPIO registers so they can be restored later...
for (uint32_t r=0; r<6; ++r)
{
gpio_regs.gpfsel[r] = GPFSEL[r];
}
// gpio_regs.gpren[0] = GPREN[0];
// gpio_regs.gpren[1] = GPREN[1];
// gpio_regs.gpfen[0] = GPFEN[0];
// gpio_regs.gpfen[1] = GPFEN[1];
gpio_regs.saved = true;
cout << NOTE << "Opened GPIO" << endl;
#endif
}