<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>GFX library rotation issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71896/gfx-library-rotation-issue</link><description>Hi There, 
 
 I&amp;#39;m working with E-Ink display connected with nRF52 chip. I have a base library to display images and works very well. 
 
 Now I&amp;#39;m trying to use GFX library to support text drawing. Using the default rotation (0 degrees) seems to work fine</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 26 Feb 2021 06:52:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71896/gfx-library-rotation-issue" /><item><title>RE: GFX library rotation issue</title><link>https://devzone.nordicsemi.com/thread/296415?ContentTypeID=1</link><pubDate>Fri, 26 Feb 2021 06:52:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e628528e-281e-4c97-b144-f3f478c31e43</guid><dc:creator>jzumaeta</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for your advice. I will try with that modification or change the driver.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jhon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GFX library rotation issue</title><link>https://devzone.nordicsemi.com/thread/296038?ContentTypeID=1</link><pubDate>Wed, 24 Feb 2021 13:37:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94337fc0-27e9-490c-b2d2-950e911e9638</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ok,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have been looking at your driver for while now. Just to be clear, this is not nordic specific, and it is not something we have provided, so I believe you will need to take it from here, but here is what I see:&lt;/p&gt;
&lt;p&gt;In the drivers that are included in the SDK, we have functions implemented in lcd_rotation_set:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ili9341_rotation_set(nrf_lcd_rotation_t rotation)
{
    write_command(ILI9341_MADCTL);
    switch (rotation) {
        case NRF_LCD_ROTATE_0:
            write_data(ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR);
            break;
        case NRF_LCD_ROTATE_90:
            write_data(ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR);
            break;
        case NRF_LCD_ROTATE_180:
            write_data(ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR);
            break;
        case NRF_LCD_ROTATE_270:
            write_data(ILI9341_MADCTL_MX | ILI9341_MADCTL_MY | ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR);
            break;
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Which is a way to tell the screen that everything from now on should be following this rotation. That is implemented in the screen, not the gfx driver.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I see you have taken a different path to the rotation setting. You implement it in every pixel:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void paper_pixel_draw(uint16_t x, uint16_t y, uint32_t color) 
{
    ASSERT(x &amp;lt; PAPER_PIXEL_WIDTH);
    ASSERT(y &amp;lt; PAPER_PIXEL_HEIGHT);
    
    switch (lcd.p_lcd_cb-&amp;gt;rotation) {
      case 1:
        SWAP(x, y);
        x = PAPER_PIXEL_WIDTH - x - 1;
        break;
      case 2:
        x = PAPER_PIXEL_WIDTH - x - 1;
        y = PAPER_PIXEL_HEIGHT - y - 1;
        break;
      case 3:
        SWAP(x, y);
        y = PAPER_PIXEL_HEIGHT - y - 1;
        break;
    }

    int bitn = y * PAPER_PIXEL_WIDTH + x;
    int byten = bitn / 8;
    bitn = 8 - bitn % 8 - 1;

    if (color == 0) paper_buffer[byten] |= 1UL &amp;lt;&amp;lt; (bitn);
    else paper_buffer[byten] &amp;amp;= ~(1UL &amp;lt;&amp;lt; (bitn));
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;which is fine, but that means that we can&amp;#39;t tell you why it isn&amp;#39;t working. Also, remember that this check is running for every single pixel you are drawing. Just make sure that it isn&amp;#39;t taking too long, and drawing to much current for your use case.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now, since you do this at a pixel level, this may not be handled in every layer. You are saying that the text is not writing to the entire width. Have you looked at the nrf_gfx_print() implementation?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret_code_t nrf_gfx_print(nrf_lcd_t const * p_instance,
                         nrf_gfx_point_t const * p_point,
                         uint16_t font_color,
                         const char * string,
                         const nrf_gfx_font_desc_t * p_font,
                         bool wrap)
{
    ASSERT(p_instance != NULL);
    ASSERT(p_instance-&amp;gt;p_lcd_cb-&amp;gt;state != NRFX_DRV_STATE_UNINITIALIZED);
    ASSERT(p_point != NULL);
    ASSERT(string != NULL);
    ASSERT(p_font != NULL);

    uint16_t x = p_point-&amp;gt;x;
    uint16_t y = p_point-&amp;gt;y;

    if (y &amp;gt; (nrf_gfx_height_get(p_instance) - p_font-&amp;gt;height))
    {
        // Not enough space to write even single char.
        return NRF_ERROR_INVALID_PARAM;
    }

    for (size_t i = 0; string[i] != &amp;#39;\0&amp;#39; ; i++)
    {
        if (string[i] == &amp;#39;\n&amp;#39;)
        {
            x = p_point-&amp;gt;x;
            y += p_font-&amp;gt;height + p_font-&amp;gt;height / 10;
        }
        else
        {
            write_character(p_instance, p_font, (uint8_t)string[i], &amp;amp;x, y, font_color);
        }

        uint8_t char_idx = string[i] - p_font-&amp;gt;startChar;
        uint16_t char_width = string[i] == &amp;#39; &amp;#39; ? (p_font-&amp;gt;height / 2) :
                                                p_font-&amp;gt;charInfo[char_idx].widthBits;

        if (x &amp;gt; (nrf_gfx_width_get(p_instance) - char_width))
        {
            if (wrap)
            {
                x = p_point-&amp;gt;x;
                y += p_font-&amp;gt;height + p_font-&amp;gt;height / 10;
            }
            else
            {
                break;
            }

            if (y &amp;gt; (nrf_gfx_height_get(p_instance) - p_font-&amp;gt;height))
            {
                break;
            }
        }
    }

    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Particularly the line:&lt;/p&gt;
&lt;p&gt;if (x &amp;gt; (nrf_gfx_width_get(p_instance) - char_width))&lt;/p&gt;
&lt;p&gt;checks whether there is room for the next character on the line. nrf_gfx_width_get() isn&amp;#39;t aware of the rotation flipping that you do in your pixel_draw() function.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To be fair, the default gfx driver in the example doesn&amp;#39;t seem to be aware of it either. I suggest that you at least look into a proper driver for your epaper online. It may not have the exact same functions as the ones in our gfx example, but it&amp;nbsp;will probably be a lot easier to use.&lt;/p&gt;
&lt;p&gt;I did&amp;nbsp;this for an LED screen a while ago, to use with the nRF, since it used TWI instead of SPI.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you are almost there with what you need, and you only need to fix the width when the screen is oriented, you can try to modify these (from nrf_gfx.c)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint16_t nrf_gfx_height_get(nrf_lcd_t const * p_instance)
{
    ASSERT(p_instance != NULL);
    if (p_instance-&amp;gt;p_lcd_cb-&amp;gt;rotation == NRF_LCD_ROTATE_90 || p_instance-&amp;gt;p_lcd_cb-&amp;gt;rotation == NRF_LCD_ROTATE_270)
    {
        return p_instance-&amp;gt;p_lcd_cb-&amp;gt;width;
    }

    return p_instance-&amp;gt;p_lcd_cb-&amp;gt;height;
}

uint16_t nrf_gfx_width_get(nrf_lcd_t const * p_instance)
{
    ASSERT(p_instance != NULL);
    if (p_instance-&amp;gt;p_lcd_cb-&amp;gt;rotation == NRF_LCD_ROTATE_90 || p_instance-&amp;gt;p_lcd_cb-&amp;gt;rotation == NRF_LCD_ROTATE_270)
    {
        return p_instance-&amp;gt;p_lcd_cb-&amp;gt;height;
    }
    return p_instance-&amp;gt;p_lcd_cb-&amp;gt;width;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GFX library rotation issue</title><link>https://devzone.nordicsemi.com/thread/295900?ContentTypeID=1</link><pubDate>Tue, 23 Feb 2021 16:02:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fbaed8a-7d67-490c-b65c-1d70b521bf15</guid><dc:creator>jzumaeta</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your response. The initial rotation works because is by default set on variable &amp;quot;lcd_cb&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My test works as follows:&lt;/p&gt;
&lt;p&gt;void main() {&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;gui_interface_init();&lt;/p&gt;
&lt;p&gt;gui_interface_print_text(0, 0, &amp;quot;0123456789&amp;quot;);&lt;/p&gt;
&lt;p&gt;gui_interface_display();&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I&amp;#39;m using&amp;nbsp;nrf_gfx_print() function and&amp;nbsp;no error appears there.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, I wrote this driver, what more information do you need?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jhon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GFX library rotation issue</title><link>https://devzone.nordicsemi.com/thread/295882?ContentTypeID=1</link><pubDate>Tue, 23 Feb 2021 15:22:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96e5393c-f081-480b-a26b-d802aa4bdb23</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Actually, I am surprised that the text is rotated, because your paper_rotation_set() function isn&amp;#39;t even populated:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void paper_rotation_set(nrf_lcd_rotation_t rotation)
{
    UNUSED_PARAMETER(rotation);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Also, I don&amp;#39;t see where you print your text. perhaps you can share it?&lt;/p&gt;
&lt;p&gt;Are you using the text_print() funciton? Does the APP_ERROR_CHECK() inside that function trigger?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think you need to show a bit more what you have done. At least since you have written this driver yourself (?) and it doesn&amp;#39;t seem complete.&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>