Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, I think I understand what is going on here.</p> <p>First, <code>const uint8_t* data</code> is a pointer to the data stored in PROGMEM.</p> <p>In the <code>function void drawString(uint16_t x, uint16_t y, uint16_t color, const FONT_INFO *fontInfo, char *str)</code> we pass a pointer to <code>fontInfo</code>.</p> <p>To continue, the following is important to understand;</p> <pre><code>fontInfo.data (*ptr_to_fontInfo).data ptr_to_fontInfo-&gt;data </code></pre> <p>are all the same. So <code>ptr_to_fontInfo-&gt;data</code> returns the data (not address)</p> <p>Then using the <code>&amp;</code> operator, we pass the 'address of' this data to the next function</p> <pre><code>drawCharBitmap(currentX, y, color, &amp;fontInfo-&gt;data[charOffset], charWidth, fontInfo-&gt;height) </code></pre> <p>This address is stored in the declared pointer variable <code>unint8_t *glyph</code> here;</p> <pre><code>void drawCharBitmap(const uint16_t xPixel, const uint16_t yPixel, uint16_t color, const uint8_t *glyph, uint8_t cols, uint8_t rows) </code></pre> <p>Keeping this in mind;</p> <pre><code>int *ptr; int a; ptr = &amp;a; </code></pre> <p>Then glyph now points to the same address as <code>fontInfo-&gt;data[charOffset]</code>.</p> <p>The next thing to know is;</p> <blockquote> <p>a[b] in C is just a fancy way for writing *(a + b)</p> </blockquote> <p>So glyph being a pointer, when used like this <code>glyph[indexIntoGlyph]</code>, it is the same as <code>*(glyph + indexIntoGlyph)</code>, and the dereferencing operator <code>*</code> means we get the data at that address. </p> <p>From there, we can use the pgm rules as wex described;</p> <blockquote> <p>If the variable is in PROGMEM, you use pgm_read_byte() as a replacement for the dereference operator *. For "normal" variables in RAM you can always write *(&amp;a) instead of just a to return the value of the variable a; so to return a 8-bit wide variable from progmem you write pgm_read_byte(&amp;x).</p> </blockquote> <p>Hope this explanation is correct and helps people (newbies like me!) understand it a bit better.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload