1
0

dev_linuxfb.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdio.h>
  2. #include "minilisp.h"
  3. #include "alloc.h"
  4. #include "stream.h"
  5. #include "compiler_new.h"
  6. #include <sys/mman.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #define WIDTH 1920
  10. #define HEIGHT 1080
  11. #define BPP 2
  12. #define DEPTH 16
  13. Cell* linux_fbfs_open() {
  14. return alloc_int(1);
  15. }
  16. Cell* linux_fbfs_read() {
  17. return alloc_int(0);
  18. }
  19. Cell* linux_fbfs_write(Cell* arg) {
  20. return NULL;
  21. }
  22. Cell* linux_fbfs_mmap(Cell* arg) {
  23. long sz = WIDTH*HEIGHT*BPP;
  24. int fd = open("/dev/fb0", O_RDWR);
  25. printf("[linux_fbfs_mmap] open fd: %d\n",fd);
  26. if (fd>-1) {
  27. Cell* buffer_cell = alloc_int(0);
  28. buffer_cell->ar.addr = mmap(NULL, sz, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
  29. buffer_cell->dr.size = sz;
  30. buffer_cell->tag = TAG_BYTES;
  31. printf("[linux_fbfs_mmap] buffer_cell->addr: %p\n",buffer_cell->ar.addr);
  32. return buffer_cell;
  33. } else {
  34. return alloc_nil();
  35. }
  36. }
  37. void mount_linux_fbfs() {
  38. fs_mount_builtin("/framebuffer", linux_fbfs_open, linux_fbfs_read, linux_fbfs_write, 0, linux_fbfs_mmap);
  39. }