vroland / epdiy

EPDiy is a driver board for affordable e-Paper (or E-ink) displays.
https://vroland.github.io/epdiy-hardware/
GNU Lesser General Public License v3.0
1.25k stars 178 forks source link

Cppcheck-Nitpicking #329

Closed holgerlembke closed 1 week ago

holgerlembke commented 1 week ago

Just some remarks from Cppcheck nitpicking some code fragments. No errors, no warning, just stil complains. All good!

epdiy.c/82

void epd_draw_pixel(int x, int y, uint8_t color, uint8_t* framebuffer) {
    // Check rotation and move pixel around if necessary
    Coord_xy coord = _rotate(x, y);
    x = coord.x;
    y = coord.y;

    if (x < 0 || x >= epd_width()) {
        return;
    }
    if (y < 0 || y >= epd_height()) {
        return;
    }

x/y can't be less 0, because coord.x/y is uint16_t.

lut.c/393

    uint32_t s1 = 0;
    for (uint8_t t2 = 0; t2 < 16; t2++) {
        uint8_t v2 = ((p_lut[(t2 << 2) + fi] >> fs) & 0x03) << 4;
        uint32_t s2 = t2 << 8;
        for (uint8_t t3 = 0; t3 < 16; t3++) {
            uint8_t v3 = ((p_lut[(t3 << 2) + fi] >> fs) & 0x03) << 2;
            uint32_t s3 = t3 << 4;
            for (uint8_t t4 = 0; t4 < 16; t4++) {
                uint8_t v4 = ((p_lut[(t4 << 2) + fi] >> fs) & 0x03) << 0;
                uint32_t s4 = t4;
                lut[s1 | s2 | s3 | s4] = v1 | v2 | v3 | v4;
            }
        }
    }

    // now just copy and the first 4096 bytes and add the upper two bits
    for (uint8_t t1 = 1; t1 < 16; t1++) {
        memcpy(&lut[t1 << 12], lut, 1 << 12);
    }

    for (int i = 0; i < 16; i++) {
        uint32_t v1 = ((p_lut[(i << 2) + fi] >> fs) & 0x03);
        uint32_t mask = (v1 << 30) | (v1 << 22) | (v1 << 14) | (v1 << 6);
        for (int j = 0; j < 16 * 16 * 16 / 4; j++) {
            ((uint32_t*)lut)[(i << 10) + j] |= mask;
        }
    }

Operator '|' with one operand equal to zero is redundant. /me assumes it means s1... and Local variable 'v1' shadows outer variable

There are some "Variable 'xxxxx' can be declared as pointer to const" and "The scope of the variable 'xxxx' can be reduced. "