├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /nbproject/ 3 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | SET(COMPILE_DEFINITIONS -Werror) 4 | 5 | include_directories(/opt/vc/include) 6 | include_directories(/opt/vc/include/interface/vcos/pthreads) 7 | include_directories(/opt/vc/include/interface/vmcs_host) 8 | include_directories(/opt/vc/include/interface/vmcs_host/linux) 9 | 10 | link_directories(/opt/vc/lib) 11 | 12 | add_executable(fbcp main.c) 13 | 14 | target_link_libraries(fbcp bcm_host) 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013 Tasanakorn Phaipool 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Raspberry Pi Framebuffer Copy 2 | ============================= 3 | This program used for copy primary framebuffer to secondary framebuffer (eg. FBTFT). It require lastest raspberry pi firmware (> 2013-07-11) to working properly. 4 | 5 | Tested on Raspberry Pi 3 6 | ======================== 7 | 2017-11-29-raspbian-stretch 8 | 9 | 10 | Requirement 11 | ----------- 12 | cmake 13 | 14 | $ sudo apt-get install cmake 15 | 16 | Build 17 | ----- 18 | 19 | $ mkdir build 20 | 21 | $ cd build 22 | 23 | $ cmake .. 24 | 25 | $ make 26 | 27 | 28 | How To Use 29 | ---------- 30 | $ ./fbcp 31 | 32 | Wanna to run from booting 33 | ------------------------- 34 | $ sudo cp fbcp /usr/bin 35 | $ sudo chmod +x /usr/bin/fbcp 36 | $ sudo nano /etc/rc.local -> add new line before "exit 0" with "/usr/bin/fbcp &" without quote 37 | $ sudo reboot 38 | 39 | 40 | License 41 | ------- 42 | 43 | 44 | Copyright (c) 2013 Tasanakorn Phaipool 45 | 46 | Permission is hereby granted, free of charge, to any person obtaining a copy 47 | of this software and associated documentation files (the "Software"), to deal 48 | in the Software without restriction, including without limitation the rights 49 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 50 | copies of the Software, and to permit persons to whom the Software is 51 | furnished to do so, subject to the following conditions: 52 | 53 | The above copyright notice and this permission notice shall be included in all 54 | copies or substantial portions of the Software. 55 | 56 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 57 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 58 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 59 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 60 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 61 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 62 | SOFTWARE. -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | int process() { 12 | DISPMANX_DISPLAY_HANDLE_T display; 13 | DISPMANX_MODEINFO_T display_info; 14 | DISPMANX_RESOURCE_HANDLE_T screen_resource; 15 | VC_IMAGE_TRANSFORM_T transform; 16 | uint32_t image_prt; 17 | VC_RECT_T rect1; 18 | int ret; 19 | int fbfd = 0; 20 | char *fbp = 0; 21 | 22 | struct fb_var_screeninfo vinfo; 23 | struct fb_fix_screeninfo finfo; 24 | 25 | 26 | bcm_host_init(); 27 | 28 | display = vc_dispmanx_display_open(0); 29 | if (!display) { 30 | syslog(LOG_ERR, "Unable to open primary display"); 31 | return -1; 32 | } 33 | ret = vc_dispmanx_display_get_info(display, &display_info); 34 | if (ret) { 35 | syslog(LOG_ERR, "Unable to get primary display information"); 36 | return -1; 37 | } 38 | syslog(LOG_INFO, "Primary display is %d x %d", display_info.width, display_info.height); 39 | 40 | 41 | fbfd = open("/dev/fb1", O_RDWR); 42 | if (fbfd == -1) { 43 | syslog(LOG_ERR, "Unable to open secondary display"); 44 | return -1; 45 | } 46 | if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { 47 | syslog(LOG_ERR, "Unable to get secondary display information"); 48 | return -1; 49 | } 50 | if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { 51 | syslog(LOG_ERR, "Unable to get secondary display information"); 52 | return -1; 53 | } 54 | 55 | syslog(LOG_INFO, "Second display is %d x %d %dbps\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); 56 | 57 | screen_resource = vc_dispmanx_resource_create(VC_IMAGE_RGB565, vinfo.xres, vinfo.yres, &image_prt); 58 | if (!screen_resource) { 59 | syslog(LOG_ERR, "Unable to create screen buffer"); 60 | close(fbfd); 61 | vc_dispmanx_display_close(display); 62 | return -1; 63 | } 64 | 65 | fbp = (char*) mmap(0, finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); 66 | if (fbp <= 0) { 67 | syslog(LOG_ERR, "Unable to create memory mapping"); 68 | close(fbfd); 69 | ret = vc_dispmanx_resource_delete(screen_resource); 70 | vc_dispmanx_display_close(display); 71 | return -1; 72 | } 73 | 74 | vc_dispmanx_rect_set(&rect1, 0, 0, vinfo.xres, vinfo.yres); 75 | 76 | while (1) { 77 | ret = vc_dispmanx_snapshot(display, screen_resource, 0); 78 | vc_dispmanx_resource_read_data(screen_resource, &rect1, fbp, vinfo.xres * vinfo.bits_per_pixel / 8); 79 | usleep(25 * 1000); 80 | } 81 | 82 | munmap(fbp, finfo.smem_len); 83 | close(fbfd); 84 | ret = vc_dispmanx_resource_delete(screen_resource); 85 | vc_dispmanx_display_close(display); 86 | } 87 | 88 | int main(int argc, char **argv) { 89 | setlogmask(LOG_UPTO(LOG_DEBUG)); 90 | openlog("fbcp", LOG_NDELAY | LOG_PID, LOG_USER); 91 | 92 | return process(); 93 | } 94 | --------------------------------------------------------------------------------