summaryrefslogtreecommitdiff
path: root/code_refs/sharpmem.c
blob: 4e0040aa3128ddc5aa1e07e04e439dd1b755cf8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "sharpmem.h"

void SHARPMEM_TOGGLEVCOM(SharpMemDisplay_t *display) {
    display->_sharpmem_vcom = display->_sharpmem_vcom ? 0x00 : SHARPMEM_BIT_VCOM;  
}

void SHARPMEM_draw_pixel(SharpMemDisplay_t *display, uint16_t x, uint16_t y, bool white) {
    if ((x < 0) || (x >= display->width) || (y < 0) || (y >= display->height))
        return;

    if (black) {
        display->buffer[(y * WIDTH + x) / 8] |= (0x1 << (x & 7)); //potentially expensive when run many times, use lookup from adafruit lib
    } else {
        display->buffer[(y * WIDTH + x) / 8] &= ~(0x1 << (x & 7));
    }
}

void SHARPMEM_draw_line(SharpMemDisplay_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool white, uint8_t thickness) {

}

void SHARPMEM_draw_circle(SharpMemDisplay_t *display, uint16_t x, uint16_t y, uint8_t r, bool filled) {

}

void SHARPMEM_draw_rect(SharpMemDisplay_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool filled) {

}

uint8_t SHARPMEM_get_pixel(SharpMemDisplay_t *display, uint16_t x, uint16_t y) {

}

void SHARPMEM_clear_display(SharpMemDisplay_t *display) {
    memset(display->_buffer, 0xff, (display->width * display->height) / 8);

    // Send the clear screen command rather than doing a HW refresh (quicker)
    
    uint8_t clear_data[2] = {(uint8_t)(display->_sharpmem_vcom | SHARPMEM_BIT_CLEAR),
                            0x00};
    
    HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_SET);
    HAL_SPI_Transmit(&display->spidev, clear_data, 2);
    HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_RESET);

    SHARPMEM_TOGGLEVCOM(display);
}

void SHARPMEM_refresh_display(SharpMemDisplay_t *display) {
    uint16_t i, currentline;

    spidev->beginTransaction();
    // Send the write command
    HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_SET);

    HAL_SPI_Transmit(&display->spidev, (_sharpmem_vcom | SHARPMEM_BIT_WRITECMD), 1);
    SHARPMEM_TOGGLEVCOM(display);;

    uint8_t bytes_per_line = display->width / 8;
    uint16_t totalbytes = (display->width * display->height) / 8;

    for (i = 0; i < totalbytes; i += bytes_per_line) {
        uint8_t line[bytes_per_line + 2];

        // Send address byte
        currentline = ((i + 1) / (WIDTH / 8)) + 1;
        line[0] = currentline;
        // copy over this line
        memcpy(line + 1, display->_buffer + i, bytes_per_line);
        // Send end of line
        line[bytes_per_line + 1] = 0x00;
        // send it!
        HAL_SPI_Transmit(&display->spidev, line, bytes_per_line + 2);
    }

    // Send another trailing 8 bits for the last line
    HAL_SPI_Transmit(&display->spidev, (0x00), 1);
    HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_RESET);
}

void SHARPMEM_clear_display_buffer(SharpMemDisplay_t *display) {

}

uint8_t *SHARPMEM_get_buffer(SharpMemDisplay_t *display) {

}