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

drivers/st77xx: introduce rotation defines #19919

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/adafruit-pybadge/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
#define BACKLIGHT_PIN GPIO_PIN(PA, 1) /**< Backlight pin */
#define BACKLIGHT_PORT PORT->Group[PA] /**< Backlight pin port */
#define BACKLIGHT_MASK (1 << 1) /**< Backlight pin mask */
#define BACKLIGHT_ON (BACKLIGHT_PORT.OUTSET.reg = BACKLIGHT_MASK) /**< Turn backlight on */

Check warning on line 62 in boards/adafruit-pybadge/include/board.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#define BACKLIGHT_OFF (BACKLIGHT_PORT.OUTCLR.reg = BACKLIGHT_MASK) /**< Turn backlight off */

Check warning on line 63 in boards/adafruit-pybadge/include/board.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
/** @} */

/**
Expand All @@ -73,10 +73,10 @@
#define ST77XX_PARAM_DCX GPIO_PIN(PB, 5) /**< DCX pin */
#define ST77XX_PARAM_RST GPIO_PIN(PA, 0) /**< Reset pin */
#define ST77XX_PARAM_NUM_LINES (160U) /**< Number of screen lines */
#define ST77XX_PARAM_RGB_CHANNELS (128U) /**< Number of screen rgb channel (height) */

Check warning on line 76 in boards/adafruit-pybadge/include/board.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#define ST77XX_PARAM_RGB (1) /**< RGB configuration */
#define ST77XX_PARAM_INVERTED (0) /**< Inversion configuration */
#define ST77XX_PARAM_ROTATION (ST77XX_ROTATION_HORZ_FLIP) /**< Rotation mode */
#define ST77XX_PARAM_ROTATION ST77XX_ROTATION_90 /**< Rotation mode */
#define LCD_SCREEN_WIDTH (ST77XX_PARAM_NUM_LINES) /**< LCD screen width */
#define LCD_SCREEN_HEIGHT (ST77XX_PARAM_RGB_CHANNELS) /**< LCD screen height */
/** @} */
Expand All @@ -85,7 +85,7 @@
* @name Neopixel LEDs (not supported yet)
* @{
*/
#define WS281X_PARAM_PIN (GPIO_PIN(PA, 15)) /**< GPIO pin connected to the data pin of the first LED */

Check warning on line 88 in boards/adafruit-pybadge/include/board.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#define WS281X_PARAM_NUMOF (5U) /**< Number of LEDs chained */
/** @} */

Expand Down
2 changes: 1 addition & 1 deletion boards/esp32s2-lilygo-ttgo-t8/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#define ST77XX_PARAM_INVERTED 1 /**< Inverted mode enable */
#define ST77XX_PARAM_NUM_LINES 240U /**< Number of lines */
#define ST77XX_PARAM_RGB_CHANNELS 135U /**< Number of columns */
#define ST77XX_PARAM_ROTATION ST77XX_ROTATION_HORZ /**< Rotation */
#define ST77XX_PARAM_ROTATION ST77XX_ROTATION_270 /**< Rotation */
#define ST77XX_PARAM_OFFSET_X 40 /**< X offset */
#define ST77XX_PARAM_OFFSET_Y 52 /**< Y offset */
#endif
Expand Down
2 changes: 1 addition & 1 deletion boards/esp32s3-usb-otg/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
#define ST77XX_PARAM_RST LCD_RST
#define ST77XX_PARAM_NUM_LINES 240
#define ST77XX_PARAM_RGB_CHANNELS 240
#define ST77XX_PARAM_ROTATION ST77XX_ROTATION_VERT
#define ST77XX_PARAM_ROTATION ST77XX_ROTATION_0
#define ST77XX_PARAM_INVERTED 1
#define ST77XX_PARAM_RGB 1

Expand Down
2 changes: 1 addition & 1 deletion boards/sipeed-longan-nano/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extern "C" {
#define ST77XX_PARAM_INVERTED 1 /**< Inverted mode enable */
#define ST77XX_PARAM_NUM_LINES 160U /**< Number of lines */
#define ST77XX_PARAM_RGB_CHANNELS 80U /**< Number of columns */
#define ST77XX_PARAM_ROTATION ST77XX_ROTATION_HORZ /**< Rotation mode */
#define ST77XX_PARAM_ROTATION ST77XX_ROTATION_270 /**< Rotation mode */
#define ST77XX_PARAM_OFFSET_Y 25 /**< Vertical offset */
#endif

Expand Down
36 changes: 36 additions & 0 deletions drivers/include/st77xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,34 @@ extern "C" {

/**
* @name ST77xx display rotation modes
*
* @note Using a rotation mode may require the definition of
* @ref ST77XX_PARAM_OFFSET_X or @ref ST77XX_PARAM_OFFSET_Y.
*
* Usually the dimension of an LCD is defined by W x H (width x height) in
* pixels, where width is the smaller dimension than height, e.g. 240 x 320
* (W x H). The height is then used as parameter @ref ST77XX_PARAM_NUM_LINES
* and the width as parameter @ref ST77XX_PARAM_RGB_CHANNELS. So vertical
* orientation means no rotation. Vertical orientation is given when the
* connector is shown at the bottom of the display.
*
* For example, the ST7789 controller supports 320 gate outputs and 240 source
* outputs (RGB channels). A display with a size of 240 x 320 (W x H) pixels
* can be used by setting `ST77XX_PARAM_NUM_LINES=320` and
* `ST77XX_PARAM_RGB_CHANNELS=240`.
*
* However, if the ST7789 is used with a display of 240 x 240 (W x H) pixels
* and a rotation is used, an offset must be defined for X or Y because the
* origin of the image will change. For example, in the case of
* @ref ST77XX_ROTATION_90 an offset for X would have to be defined by
* `ST77XX_PARAM_OFFSET_X=80` and in the case of @ref ST77XX_ROTATION_180
* an offset for Y would have to be defined by `ST77XX_PARAM_OFFSET_X=80`.
*
* Using the correct offset on rotation can be even more difficult if the
* display size in both dimensions is smaller than the size supported by
* the controller. In this case, the origin can deviate from 0, 0 even
* without rotation.
*
* @{
*/
#define ST77XX_ROTATION_VERT 0 /**< Vertical mode */
Expand All @@ -331,6 +359,14 @@ extern "C" {
LCD_MADCTL_MX /**< Horizontal mode */
#define ST77XX_ROTATION_HORZ_FLIP LCD_MADCTL_MV | \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define ST77XX_ROTATION_HORZ_FLIP LCD_MADCTL_MV | \
#define ST77XX_ROTATION_HORZ_FLIP ST77XX_ROTATION_90

tbh I don't quite understand why 'flip' is 90° rotation, but we should only have one source of truth here.

Copy link
Contributor Author

@gschorcht gschorcht Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the definitions ST77XX_ROTATION_{HORZ_FLIP,VERT_FLIP} are a bit misleading and it is not really clear what FLIP means without trying it. When configuring the display, a number of trials are required to find the correct orientation.

Per definition the display coordinates are defined as

    +------> X    (ST77XX_PARAM_RGB_CHANNELS)
    |
    |
    |
  Y v             (ST77XX_PARAM_NUM_LINES)

The X dimension is the smaller one compared with the Y dimension so that it corresponds to the vertical orientation. Usually (at least all displays I know) have the connector at the bottom, i.e. at Y_max.

To get the horizontal orientation of the display rotated by -90 °, X and Y have to be swapped (LCD_MADCTL_MV) and afterwards the new Y has to be mirrored (LCD_MADCTL_MY) which is the same as defined as ST77XX_ROTATION_HORZ_FLIP.

LCD_MADCTL_MY /**< Horizontal flipped */

#define ST77XX_ROTATION_0 0 /**< 0 deg counterclockwise */
#define ST77XX_ROTATION_90 LCD_MADCTL_MV | \
LCD_MADCTL_MY /**< 90 deg counterclockwise */
#define ST77XX_ROTATION_180 LCD_MADCTL_MX | \
LCD_MADCTL_MY /**< 180 deg counterclockwise */
#define ST77XX_ROTATION_270 LCD_MADCTL_MV | \
LCD_MADCTL_MX /**< 270 deg counterclockwise */
/** @} */

/**
Expand Down
Loading