Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ src/kernel/.gpp_data_bus.ko.cmd
src/kernel/.gpp_data_bus.mod.cmd
src/kernel/.gpp_data_bus.mod.o.cmd
src/kernel/.gpp_data_bus.o.cmd
src/kernel/.gpp_data_bus.mod
src/kernel/.modules.order.cmd
src/kernel/Module.symvers
src/kernel/gpp_data_bus.ko
Expand All @@ -13,4 +14,4 @@ src/kernel/gpp_data_bus.mod.o
src/kernel/gpp_data_bus.o
src/kernel/modules.order
src/utils/aux.h
src/utils/aux.c
src/utils/aux.c
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"ui.h": "c",
"DATA_A.C": "cpp",
"data.C": "cpp",
"stdlib.h": "c"
"stdlib.h": "c",
"mman.h": "c",
"device_manager.h": "c"
}
}
83 changes: 83 additions & 0 deletions src/Device_manager.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "Device_manager.h"

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>

void read_mouse(mouse_t* mouse) {
u8_t data[3] = {0};

if (read(mouse->fd, data, sizeof(data))) {
mouse->left = (data[0] & 0x1) ? 1 : 0;
mouse->right = (data[0] & 0x02) ? 1 : 0;
mouse->middle = (data[0] & 0x04) ? 1 : 0;

mouse->x += (data[1] / ((SENSIBILITY > 0) ? SENSIBILITY : 1));

if (mouse->x < 0) {
mouse->x = 0;
}
if (mouse->x > WIDTH) {
mouse->x = WIDTH;
}

mouse->y += ((data[2] * -1) / ((SENSIBILITY > 0) ? SENSIBILITY : 1));

if (mouse->y < 0) {
mouse->y = 0;
}
if (mouse->y > HEIGHT) {
mouse->y = HEIGHT;
}
}
}

mouse_t init_mouse(u64_t fd_mouse) {
fd_mouse = open("/dev/input/event0", O_RDONLY);

if (fd_mouse == -1) {
perror("Erro ao abrir o dispositivo de memória");
exit(EXIT_FAILURE);
}

return (mouse_t){
.fd = fd_mouse,
.x = 50,
.y = 50,
.left = 0,
.right = 0,
.middle = 0,
.read = read_mouse,
};
}

u64_t* read_KEY(u64_t fd_map, void* LW_virtual) {
fd_map = open("/dev/mem", (O_RDWR | O_SYNC));
if (fd_map == -1) {
perror("Erro ao abrir o dispositivo de memória");
exit(EXIT_FAILURE);
}

LW_virtual = mmap(NULL, LW_BRIDGE_SPAN, (PROT_READ | PROT_WRITE), MAP_SHARED, fd_map, LW_BRIDGE_BASE);
if (LW_virtual == MAP_FAILED) {
perror("Erro ao mapear memória");
exit(EXIT_FAILURE);
}

u64_t* KEY_ptr = (u64_t*)(LW_virtual + KEY_BASE);
return KEY_ptr;
}

void close_KEY(u64_t fd_map, void* LW_virtual) {
if (munmap(LW_virtual, LW_BRIDGE_SPAN) == -1) {
perror("Erro ao desmapear memória");
exit(EXIT_FAILURE);
}

if (close(fd_map) == -1) {
perror("Erro ao fechar dispositivo de memória");
exit(EXIT_FAILURE);
}
}
37 changes: 37 additions & 0 deletions src/Device_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef DEVICE_MANAGER_H_
#define DEVICE_MANAGER_H_

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>

#include "utils/types.h"
#include "utils/ui.h"

#define KEY_BASE 0x0
#define LW_BRIDGE_SPAN 0x00005000
#define LW_BRIDGE_BASE 0xff200000

#define HEIGHT 360
#define WIDTH 480
#define SENSIBILITY 2

typedef struct mouse_t {
u64_t fd;
u32_t x;
u32_t y;
u8_t left;
u8_t middle;
u8_t right;

void (*read)(struct mouse_t* mouse);
} mouse_t;

void read_mouse(mouse_t* mouse);
mouse_t init_mouse(u64_t fd_mouse);
u64_t* read_KEY(u64_t fd_map, void* LW_virtual);
void close_KEY(u64_t fd_map, void* LW_virtual);

#endif // DEVICE_MANAGER_H_
269 changes: 165 additions & 104 deletions src/GraphSync.c

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/GraphSync.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ void clean_polygon();

void clean_background();

sprite_fixed_t set_new_sprite(u16_t sprite_offset);
sprite_t set_new_sprite(u16_t sprite_offset);

void draw_picture();

u8_t increase_coordinate_sprite(sprite_t *sprite);

u8_t collision(sprite_t *sp1, sprite_t *sp2);
10 changes: 6 additions & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ build: build/dir build/main
build/dir:
@mkdir -p build

build/main: build/GraphSync.o build/main.o
@gcc build/GraphSync.o build/main.o -o build/main

build/main: build/GraphSync.o build/main.o build/Device_manager.o
@gcc build/GraphSync.o build/main.o build/Device_manager.o -o build/main

build/GraphSync.o: GraphSync.c GraphSync.h utils/ui.h utils/types.h
@gcc -c GraphSync.c -o build/GraphSync.o -Isrc -Iutils

build/main.o: main.c GraphSync.h utils/ui.h utils/types.h
build/Device_manager.o: Device_manager.c Device_manager.h utils/ui.h utils/types.h
@gcc -c Device_manager.c -o build/Device_manager.o -Isrc -Iutils

build/main.o: main.c GraphSync.h utils/ui.h utils/types.h
@gcc -c main.c -o build/main.o -Isrc -Iutils

run: build
Expand Down
Loading