Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation not supported #17

Open
FxIII opened this issue Oct 21, 2020 · 1 comment
Open

Rotation not supported #17

FxIII opened this issue Oct 21, 2020 · 1 comment

Comments

@FxIII
Copy link

FxIII commented Oct 21, 2020

I'm using this library with the DSTIKE ESP32 Watch DevKit TFT here.
It works like a charm (put python into a watch was my secret dream).
Alas the screen is rotated 90° cw, I added a function to set rotation :

STATIC mp_obj_t st7789_ST7789_set_rotation(mp_obj_t self_in, mp_obj_t value) {
    st7789_ST7789_obj_t *self = MP_OBJ_TO_PTR(self_in);
    mp_int_t m = mp_obj_get_int(value);
    uint8_t madctl[] = {ST7789_MADCTL_RGB};
    switch (m) {
    case 0:
      madctl[0] =  ST7789_MADCTL_MX | ST7789_MADCTL_MY | ST7789_MADCTL_RGB ;
      write_cmd(self, ST7789_MADCTL, madctl, 1);
      break;
    case 1:
      madctl[0] =  ST7789_MADCTL_MY | ST7789_MADCTL_MV | ST7789_MADCTL_RGB ;
      write_cmd(self, ST7789_MADCTL, madctl, 1);
      break;
    case 2:
      madctl[0] =  ST7789_MADCTL_RGB ;
      write_cmd(self, ST7789_MADCTL, madctl, 1);
      break;
    case 3:
      madctl[0] =  ST7789_MADCTL_MX | ST7789_MADCTL_MV | ST7789_MADCTL_RGB ;
      write_cmd(self, ST7789_MADCTL, madctl, 1);
      break;
    default:
      break;
    }
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(st7789_ST7789_set_rotation_obj, st7789_ST7789_set_rotation);

But when setting in mode 1 there is like an offset of 80 pixels (the fill function leaves a vertical band on the right)

No clues of what next (I'm remapping everything in sw right now). Any Idea?

@jej
Copy link

jej commented Dec 30, 2020

Look at this fork https://github.com/russhughes/st7789_mpy

rotation argument and method ST7789.rotation(r)

STATIC void set_rotation(st7789_ST7789_obj_t *self) {
    uint8_t madctl_value = ST7789_MADCTL_RGB;

    if (self->rotation == 0) {              // Portrait
        self->width = self->display_width;
        self->height = self->display_height;
        if (self->display_height == 320 || self->display_width == 240) {
            self->xstart = 0;
            self->ystart = 0;
        }
        else if (self->display_width == 135) {
                self->xstart = 52;
                self->ystart = 40;
        }
    }
    else if (self->rotation == 1) {         // Landscape
        madctl_value |= ST7789_MADCTL_MX | ST7789_MADCTL_MV;
        self->width = self->display_height;
        self->height = self->display_width;
        if (self->display_height == 320 || self->display_width == 240) {
            self->xstart = 0;
            self->ystart = 0;
        } else if (self->display_width == 135) {
            self->xstart = 40;
            self->ystart = 53;
        }
    }
    else if (self->rotation == 2) {        // Inverted Portrait
        madctl_value |= ST7789_MADCTL_MX | ST7789_MADCTL_MY;
        self->width = self->display_width;
        self->height = self->display_height;
        if (self->display_height == 320) {
            self->xstart = 0;
            self->ystart = 0;
        } else if (self->display_width == 135) {
            self->xstart = 53;
            self->ystart = 40;
        }
        else if (self->display_width == 240) {
            self->xstart = 0;
            self->ystart = 80;
        }

    }
    else if (self->rotation == 3) {         // Inverted Landscape
        madctl_value |= ST7789_MADCTL_MV | ST7789_MADCTL_MY;
        self->width = self->display_height;
        self->height = self->display_width;
        if (self->display_height == 320) {
            self->xstart = 0;
            self->ystart = 0;
        } else if (self->display_width == 135) {
            self->xstart = 40;
            self->ystart = 52;
        }
        else if (self->display_width == 240) {
            self->xstart = 80;
            self->ystart = 0;
        }
    }
    const uint8_t madctl[] = { madctl_value };
    write_cmd(self, ST7789_MADCTL, madctl, 1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants