dlinyj: (Default)
[personal profile] dlinyj
Что-то в связи с болезнью никак не могу добраться до ЖЖ, собраться с мыслями и написать данный простенький пост. Грёбаная осень!

Забегая вперёд скажу, что мне удалось по UART передать картинку, всё благодаря товарищу [livejournal.com profile] paracloud, который мне точно указал что делать в этом посте http://dlinyj.livejournal.com/609986.html .

Говоря простым языком, нужно настроить консоль. Я набросал небольшую програмку

#include <stdio.h>

...
int main (int argc, char* argv[])
{
    struct termios oldtty, newtty;
    fcntl(0, F_SETFL, 0);     //read com-port is the bloking
    tcgetattr(0, &oldtty);
    newtty = oldtty;
    newtty.c_iflag =  IGNBRK;
    newtty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    newtty.c_oflag = 0;
    newtty.c_cflag &= ~PARENB;
    newtty.c_cflag |= CS8;
    newtty.c_cc[VMIN] = 1;
    newtty.c_cc[VTIME] = 1;
    tcsetattr(0, TCSANOW, &newtty);
    return 0;
}



По сути программа перенастраивает терминал и отключает эхо. После чего "вслепую" вводим на книжке
cat /dev/tty > result.raw

а на компе вводим
sudo cat img.raw > /dev/ttyUSB0

И спустя, примерно, минуту получаем исходный файл на книжке. Консоль удаётся вернуть только после перезагрузки книжки. Это файл вполне себе видится и выводится на экран без потерь и артефактов.

Это был топорный тестовый вариант, в стиле "а можно ли?"

Далее, я решил написать программу, которая не создаёт промежуточный файл, а принимает данные в буфер, а затем этот буфер копирует во фреймбуффер.
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>        /* File control definitions */
#include <termios.h>    /* POSIX terminal control definitions */
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <string.h>        /* String function definitions */
#include <unistd.h>

#define resultfile                         "result.img"
#define FBIO_EINK_GET_TEMPERATURE        0x46A1    //Returns temperature in degree Celsius
#define FBIO_EINK_DISP_PIC                0x46A2    //Displays picture

int main (int argc, char* argv[])
{
    struct termios oldtty, newtty;
    char buffer[100];
    printf ("Test recive data\n");
    sleep(1);
    fcntl(0, F_SETFL, 0);     //read com-port is the bloking
    //config UART
    tcgetattr(0, &oldtty);
    newtty = oldtty;
    newtty.c_iflag =  IGNBRK;
    newtty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    newtty.c_oflag = 0;
    newtty.c_cflag &= ~PARENB;
    newtty.c_cflag |= CS8;
    newtty.c_cc[VMIN] = 1;
    newtty.c_cc[VTIME] = 1;
    tcsetattr(0, TCSANOW, &newtty);

    char *tmp;
    unsigned int count=0, i=0, l;

    ssize_t n;
    
    tmp=malloc(480000);
    while(count<480000)
    {    
        n=read(0,buffer,50);
        count+=n;
        l=0;
        for(;i<n;i++) 
        {
            tmp[i]=buffer[l];
            l++;
        }

    }

    //write old config
    tcsetattr(0, TCSANOW, &oldtty);
    

    int *fb;
    int pio_fd = open ( "/dev/fb0", O_RDWR);
    int f_image = open ( argv[1], O_RDWR);                                 //open file into arg
    int t= ioctl (pio_fd, FBIO_EINK_GET_TEMPERATURE, NULL);    //configure framebuffer

    fb= mmap(0, 800*600, PROT_WRITE, MAP_SHARED, pio_fd, 0);    //map device into memory
    memset(fb,0,800*600);                                        //clear image
    ioctl (pio_fd, FBIO_EINK_DISP_PIC, 0);
    
    memcpy(fb,tmp,800*600);
    ioctl (pio_fd, FBIO_EINK_DISP_PIC, 0);
    
    close(pio_fd);

    return 0;
}



Здесь настраивается блокирующее чтение:

fcntl(0, F_SETFL, 0); //read com-port is the bloking

Которое не делает бесконечный цикл, а блокирует оператор read до появления данных.

Не знаю, что я делаю не так. Пограмма честно отрабатывает, но выводит тупо чёрный экран, по завершению приёма. Увы...
Надо разбираться дальше.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

January 2026

S M T W T F S
    123
456 78910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 22nd, 2026 12:22 pm
Powered by Dreamwidth Studios