<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CY8CKIT-028-EPD &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/category/devkits/cy8ckit-028-epd/feed/" rel="self" type="application/rss+xml" />
	<link>https://iotexpert.com</link>
	<description>Engineering for the Internet of Things</description>
	<lastBuildDate>Sun, 19 May 2019 15:12:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://iotexpert.com/wp-content/uploads/2017/01/cropped-Avatar-32x32.jpg</url>
	<title>CY8CKIT-028-EPD &#8211; IoT Expert</title>
	<link>https://iotexpert.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>IoT Expert Logo -&gt; EPD &#8211; Bitmap Madness (Part 2)</title>
		<link>https://iotexpert.com/iot-expert-logo-epd-bitmap-madness-part-2/</link>
					<comments>https://iotexpert.com/iot-expert-logo-epd-bitmap-madness-part-2/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 20 May 2019 12:00:31 +0000</pubDate>
				<category><![CDATA[CY8CKIT-028-EPD]]></category>
		<category><![CDATA[Graphics]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6895</guid>

					<description><![CDATA[Summary In the last article I showed you how to display a bitmap in the Segger format.  In this article I will show you how to convert a BMP to a &#8220;C&#8221; file and then display it using the Segger GUI_BMP_Draw() API. To this I will follow these steps: Use GIMP to Export a Black [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>In the <a href="https://iotexpert.com/2019/05/13/iot-expert-logo-conversion-bitmap-madness-part-1/" target="_blank" rel="noopener noreferrer">last article</a> I showed you how to display a bitmap in the Segger format.  In this article I will show you how to convert a <a href="https://en.wikipedia.org/wiki/BMP_file_format" target="_blank" rel="noopener noreferrer">BMP</a> to a &#8220;C&#8221; file and then display it using the Segger GUI_BMP_Draw() API.</p>
<p>To this I will follow these steps:</p>
<ul>
<li>Use GIMP to Export a Black and White Logo</li>
<li>Convert the BMP to a &#8220;C&#8221; array using Bin2C</li>
<li>Add the C to the project and fix up the project</li>
</ul>
<h1>Use GIMP to Export a Black and White Logo as BMP</h1>
<p>As in the last article, Ill use GIMP to manipulate the IoT Expert.  First, Ill load the logo from the PNG file.</p>
<p><a href="https://iotexpert.com/?attachment_id=6908" rel="attachment wp-att-6908"><img fetchpriority="high" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.04-PM-1024x672.png" alt="" width="1024" height="672" class="alignnone size-large wp-image-6908" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.04-PM-1024x672.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.04-PM-600x394.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.04-PM-300x197.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.04-PM-768x504.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Then I will convert the PNG to a black and white only image.  This will be a 1-bit per pixel indexed image.  Indexed means that instead of ARGB (aka 32 bits for each pixel), that the color of each pixel will be referenced via an index into a color table.  For instance the color table might look like this:</p>
<div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Index</th>
<th >Value</th>
<th >Color</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td >0xFF000000</td>
<td >Black</td>
</tr>

<tr><td >1</td>
<td >0xFFFFFFFF</td>
<td >White</td>
</tr>
</tbody></table></div>
<p>The BMP file will then have a color table (like the one above) and each pixel value will be an index into the table.  It turns out that these color tables must have  2^n rows where n is the number of bits in the index.  Also with the BMP format any bitmaps with 24 bits per pixel will not have a color table.</p>
<p>Gimp can convert an image to indexed.  To do this, click  Image&#8211;&gt;Mode&#8211;&gt;Indexed&#8230;</p>
<p><a href="https://iotexpert.com/?attachment_id=6907" rel="attachment wp-att-6907"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.23-PM.png" alt="" width="656" height="912" class="alignnone size-large wp-image-6907" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.23-PM.png 656w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.23-PM-600x834.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.23-PM-216x300.png 216w" sizes="(max-width: 656px) 100vw, 656px" /></a></p>
<p>On this screen you will be given the option to specify the color indexes.  Notice that there is a &#8220;black and white only&#8221; option.</p>
<p><a href="https://iotexpert.com/?attachment_id=6906" rel="attachment wp-att-6906"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.40-PM.png" alt="" width="746" height="798" class="alignnone size-large wp-image-6906" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.40-PM.png 746w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.40-PM-600x642.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.40-PM-280x300.png 280w" sizes="(max-width: 746px) 100vw, 746px" /></a></p>
<p>Once you have made the conversion you can see that image is now indexed.</p>
<p><a href="https://iotexpert.com/?attachment_id=6905" rel="attachment wp-att-6905"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.55-PM-1024x38.png" alt="" width="1024" height="38" class="alignnone size-large wp-image-6905" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.55-PM-1024x38.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.55-PM-600x22.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.55-PM-300x11.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.55-PM-768x28.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.31.55-PM.png 1624w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>On that screen you could have converted the image to indexed with up to 256 colors (but I choose 2 by using the Use black and white (1-bit) palette.</p>
<p><a href="https://iotexpert.com/?attachment_id=6935" rel="attachment wp-att-6935"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.25.34-AM.png" alt="" width="736" height="790" class="alignnone size-full wp-image-6935" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.25.34-AM.png 736w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.25.34-AM-600x644.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.25.34-AM-279x300.png 279w" sizes="auto, (max-width: 736px) 100vw, 736px" /></a></p>
<p>The next step is to export to a BMP using &#8220;File&#8211;&gt;Export As&#8230;&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6912" rel="attachment wp-att-6912"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.04-PM.png" alt="" width="696" height="854" class="alignnone size-large wp-image-6912" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.04-PM.png 696w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.04-PM-600x736.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.04-PM-244x300.png 244w" sizes="auto, (max-width: 696px) 100vw, 696px" /></a></p>
<p>I set the file name to &#8220;IOTexpert_Logo_Vertical_BW.bmp&#8221;.  Gimp does its magic by using the file extension.  In this case &#8220;bmp&#8221; creates a Microsoft BMP file.</p>
<p><a href="https://iotexpert.com/?attachment_id=6911" rel="attachment wp-att-6911"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.22-PM-1024x709.png" alt="" width="1024" height="709" class="alignnone size-large wp-image-6911" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.22-PM-1024x709.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.22-PM-600x415.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.22-PM-300x208.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.22-PM-768x532.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.22-PM.png 1430w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>When I hit export I get this dialog box (which I had no idea what it meant when I started). For now click &#8220;OK&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6910" rel="attachment wp-att-6910"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.37-PM.png" alt="" width="556" height="352" class="alignnone size-large wp-image-6910" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.37-PM.png 556w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.37-PM-300x190.png 300w" sizes="auto, (max-width: 556px) 100vw, 556px" /></a></p>
<p>Once the file is exported this is what I get.  OK&#8230; is not very helpful.  What happened?</p>
<p><a href="https://iotexpert.com/?attachment_id=6909" rel="attachment wp-att-6909"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.54-PM-1024x723.png" alt="" width="1024" height="723" class="alignnone size-large wp-image-6909" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.54-PM-1024x723.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.54-PM-600x424.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.54-PM-300x212.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.34.54-PM-768x543.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The answer is that an Indexed BMP does not support Alpha.  So, GIMP ditched the Alpha, which turned everything that wasnt black to the background color, which is black. So, what is the deal with the Alpha channel?  Alpha is how transparent everything is.  You can get rid of it using Layer&#8211;&gt;Transparency&#8211;&gt;Remove Alpha Channel</p>
<p><a href="https://iotexpert.com/?attachment_id=6913" rel="attachment wp-att-6913"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.37.12-PM.png" alt="" width="798" height="760" class="alignnone size-full wp-image-6913" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.37.12-PM.png 798w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.37.12-PM-600x571.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.37.12-PM-300x286.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.37.12-PM-768x731.png 768w" sizes="auto, (max-width: 798px) 100vw, 798px" /></a></p>
<p>Which once again turns my image black.  But why?  On the left hand side of the screen you will see the foreground/background colors.  And you will notice that the background is black.</p>
<p><a href="https://iotexpert.com/?attachment_id=6915" rel="attachment wp-att-6915"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.53.58-PM-1024x679.png" alt="" width="1024" height="679" class="alignnone size-large wp-image-6915" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.53.58-PM-1024x679.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.53.58-PM-600x398.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.53.58-PM-300x199.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.53.58-PM-768x509.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.53.58-PM.png 1928w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>To fix the problem undo the remove alpha.  Then click the little back and forth arrow to turn the background white.  Then re-remove the alpha.  Now that problem is fixed.</p>
<p><a href="https://iotexpert.com/?attachment_id=6914" rel="attachment wp-att-6914"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.55.14-PM-1024x681.png" alt="" width="1024" height="681" class="alignnone size-large wp-image-6914" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.55.14-PM-1024x681.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.55.14-PM-600x399.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.55.14-PM-300x199.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.55.14-PM-768x510.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.55.14-PM.png 1926w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now, I can shrink it to the right size using Image&#8211;&gt;Scale Image&#8230;</p>
<p><a href="https://iotexpert.com/?attachment_id=6918" rel="attachment wp-att-6918"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.57.57-PM.png" alt="" width="438" height="906" class="alignnone size-large wp-image-6918" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.57.57-PM.png 438w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.57.57-PM-145x300.png 145w" sizes="auto, (max-width: 438px) 100vw, 438px" /></a></p>
<p>Then pick the 276 width (aka the same width as the EPD screen)</p>
<p><a href="https://iotexpert.com/?attachment_id=6917" rel="attachment wp-att-6917"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.58.11-PM.png" alt="" width="756" height="600" class="alignnone size-large wp-image-6917" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.58.11-PM.png 756w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.58.11-PM-600x476.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.58.11-PM-300x238.png 300w" sizes="auto, (max-width: 756px) 100vw, 756px" /></a></p>
<p>Now do &#8220;File&#8211;&gt;Export As..&#8221; with a &#8220;.bmp&#8221; file name extension.  This time it doesn&#8217;t ask me about the transparency.</p>
<p><a href="https://iotexpert.com/?attachment_id=6916" rel="attachment wp-att-6916"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.59.15-PM-1024x703.png" alt="" width="1024" height="703" class="alignnone size-large wp-image-6916" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.59.15-PM-1024x703.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.59.15-PM-600x412.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.59.15-PM-300x206.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.59.15-PM-768x527.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-12.59.15-PM.png 1430w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And, now I have a nice BMP file.  Here is the view from the preview in Mac.</p>
<p><a href="https://iotexpert.com/?attachment_id=6919" rel="attachment wp-att-6919"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.02.39-PM-1024x510.png" alt="" width="1024" height="510" class="alignnone size-large wp-image-6919" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.02.39-PM-1024x510.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.02.39-PM-600x299.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.02.39-PM-300x149.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.02.39-PM-768x383.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.02.39-PM.png 1100w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>So, how do I get a BMP file into my program?  Well, I need turn it into an array of bytes.  And to do that&#8230;</p>
<h1>Segger Bin2C</h1>
<p>One of the utility programs that Segger provides is called &#8220;<a href="https://www.segger.com/free-utilities/bin2c/" target="_blank" rel="noopener noreferrer">Bin2C</a>&#8221; which can read in a file and turn it into an array of bytes in &#8220;c&#8221; format.  You can download it <a href="https://www.segger.com/downloads/free-utilities/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p><a href="https://iotexpert.com/?attachment_id=6923" rel="attachment wp-att-6923"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-4.47.56-PM-1024x696.png" alt="" width="1024" height="696" class="alignnone size-large wp-image-6923" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-4.47.56-PM-1024x696.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-4.47.56-PM-600x408.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-4.47.56-PM-300x204.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-4.47.56-PM-768x522.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>When I run it, first I select the file, then press &#8220;Convert&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6921" rel="attachment wp-att-6921"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.04.32-PM.png" alt="" width="698" height="266" class="alignnone size-large wp-image-6921" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.04.32-PM.png 698w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.04.32-PM-600x229.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.04.32-PM-300x114.png 300w" sizes="auto, (max-width: 698px) 100vw, 698px" /></a></p>
<p>And it generates a nice array of bytes.</p>
<p><a href="https://iotexpert.com/?attachment_id=6920" rel="attachment wp-att-6920"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.05.15-PM-1024x696.png" alt="" width="1024" height="696" class="alignnone size-large wp-image-6920" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.05.15-PM-1024x696.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.05.15-PM-600x408.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.05.15-PM-300x204.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-1.05.15-PM-768x522.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Update the Project</h1>
<p>To use the array, first copy the file into your project.  You notice that the array is defined as &#8220;static&#8221; which means that it is not accessible from other files.  Remove that.  Now edit the eInkTask.c and</p>
<ol>
<li>Add an extern reference to the array of bytes</li>
<li>Make a call to &#8220;GMP_BMP_Draw()&#8221; to display the logo</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">extern unsigned char _acIOTexpert_Logo_Vertical_BW[6862UL + 1];
void ShowIoTScreen(void)
{
	GUI_Clear();
	GUI_BMP_Draw(_acIOTexpert_Logo_Vertical_BW, 0,0);
	/* Send the display buffer data to display*/
	UpdateDisplay(CY_EINK_FULL_4STAGE, true);
	while(1)
		vTaskDelay(100);
}</pre>
<p>When I program the kit I get this&#8230; all black.</p>
<p>&nbsp;</p>
<p>But why?  I didn&#8217;t know the answer.  So I assumed that it must be something to do with me and my understanding of bitmaps.  In the next article I&#8217;ll tell you all about that journey.  But after a day or two of learning about bitmap file formats I was convinced that it wasn&#8217;t me.  So I started looking around on the web and I found this thread on Segger&#8217;s forum.</p>
<p><a href="https://iotexpert.com/?attachment_id=6937" rel="attachment wp-att-6937"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.36.45-AM-1024x255.png" alt="" width="1024" height="255" class="alignnone size-large wp-image-6937" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.36.45-AM-1024x255.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.36.45-AM-600x149.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.36.45-AM-300x75.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-17-at-11.36.45-AM-768x191.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And, when I got to work the next Monday I called an amazing engineer that works for Cypress in Ukraine. He provided me a v5.48 which sure enough fixed the problem.  When I program that, looks like things are working with bitmaps:</p>
<p><a href="https://iotexpert.com/?attachment_id=6929" rel="attachment wp-att-6929"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0493-1024x836.jpg" alt="" width="1024" height="836" class="alignnone size-large wp-image-6929" srcset="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0493-1024x836.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0493-600x490.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0493-300x245.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0493-768x627.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Unfortunately that means that we (Cypress) have a released version of Segger emWin that is broken.  This will be fixed with an updated version soon, but for now if you are stuck send me an email and I&#8217;ll help you.</p>
<p>The next article is a deep dive into the BMP format.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/iot-expert-logo-epd-bitmap-madness-part-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>IoT Expert Logo &#8211;&gt; EPD &#8211; Bitmap Madness (Part 1)</title>
		<link>https://iotexpert.com/iot-expert-logo-conversion-bitmap-madness-part-1/</link>
					<comments>https://iotexpert.com/iot-expert-logo-conversion-bitmap-madness-part-1/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 13 May 2019 12:00:50 +0000</pubDate>
				<category><![CDATA[CY8CKIT-028-EPD]]></category>
		<category><![CDATA[Graphics]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6855</guid>

					<description><![CDATA[Summary In the last article I showed you a bunch of things about programming the Pervasive EPD eInk Display that is attached to the CY8CKIT-028-EPD.  You might have noticed in the first video I have a screen that shows the IoT Expert Logo.  Simple right?  Yes you would think, but it actually turned out to [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>In the last <a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/">article</a> I showed you a bunch of things about programming the Pervasive EPD eInk Display that is attached to the CY8CKIT-028-EPD.  You might have noticed in the first video I have a screen that shows the IoT Expert Logo.  Simple right?  Yes you would think, but it actually turned out to be quite a pain in the ass!  This article is my journey through bit maps.  It is hardly canonical, but hopefully it will help you.</p>
<p><a href="https://iotexpert.com/?attachment_id=6856" rel="attachment wp-att-6856"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0480-1024x636.jpg" alt="" width="1024" height="636" class="alignnone size-large wp-image-6856" srcset="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0480-1024x636.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0480-600x373.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0480-300x186.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0480-768x477.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In this article I will specifically walk you through:</p>
<ul>
<li>The IoT Expert Logo</li>
<li>Segger emWin Bitmap Drawing APIs</li>
<li>Segger Bitmap Converter</li>
<li>Updating a Project to draw a Segger Bitmaps</li>
<li>Converting a Color Bitmap to Black and White</li>
<li>Using GIMP to Fix B/W Conversion</li>
</ul>
<p>In the next two articles I will address drawing bitmaps that are in the Windows BMP format and PNG format.</p>
<h1>The IoT Expert Logo</h1>
<p>If you guys remember, in early 2017, I ran a design contest to create a logo for the IoT Expert website.  You can read about it <a href="https://iotexpert.com/2017/01/16/iotexpert-logo-design-contest-part1/" target="_blank" rel="noopener noreferrer">here</a> and <a href="https://iotexpert.com/2017/02/20/new-logo-design-contest-iot-expert-part-2/" target="_blank" rel="noopener noreferrer">here</a>.  When it was over, I had a bunch of different images including this one which is a 1091&#215;739 PNG file with what I thought was five colors but is actually nine (which I discovered during this journey)</p>
<p><a href="https://iotexpert.com/?attachment_id=6857" rel="attachment wp-att-6857"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/IOTexpert_Logo_Vertical-1024x694.png" alt="" width="1024" height="694" class="alignnone size-large wp-image-6857" srcset="https://iotexpert.com/wp-content/uploads/2019/05/IOTexpert_Logo_Vertical-1024x694.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/IOTexpert_Logo_Vertical-600x406.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/IOTexpert_Logo_Vertical-300x203.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/IOTexpert_Logo_Vertical-768x520.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/IOTexpert_Logo_Vertical.png 1091w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>OK, thats cool.  But how do I get that onto the eInk screen which is 276&#215;176 and black and white?</p>
<h1>emWin Bitmap Drawing APIs</h1>
<p>I started by looking at the Segger emWin documentation which you can either get directly from the Segger website <a href="https://www.segger.com/downloads/emwin/UM03001" target="_blank" rel="noopener noreferrer">here</a>.  Or you can find it inside of Modus Toolbox.  Select &#8220;Help&#8211;&gt;ModusToolbox API Reference&#8211;&gt;PSoC PDL Reference&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6894" rel="attachment wp-att-6894"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.29.18-AM-1024x673.png" alt="" width="1024" height="673" class="alignnone size-large wp-image-6894" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.29.18-AM-1024x673.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.29.18-AM-600x394.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.29.18-AM-300x197.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.29.18-AM-768x505.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.29.18-AM.png 1190w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Then pick &#8220;Middleware and Software API Reference &#8211;&gt; Segger emWin &#8211;&gt; emWin User Guide&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6893" rel="attachment wp-att-6893"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.38.05-AM-1024x768.png" alt="" width="1024" height="768" class="alignnone size-large wp-image-6893" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.38.05-AM-1024x768.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.38.05-AM-600x450.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.38.05-AM-300x225.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.38.05-AM-768x576.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-10.38.05-AM.png 1422w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>From the documentation you see that emWin can display bitmaps in the emWin format using the APIs GUI_DrawBitmap.  This section actually goes on for more than another page worth of APIs.  The API that I will focus on in this article is GUI_DrawBitmap()</p>
<p><a href="https://iotexpert.com/?attachment_id=6862" rel="attachment wp-att-6862"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.42.16-AM-1024x205.png" alt="" width="1024" height="205" class="alignnone size-large wp-image-6862" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.42.16-AM-1024x205.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.42.16-AM-600x120.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.42.16-AM-300x60.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.42.16-AM-768x153.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also display bitmaps that are in GIF, PNG, BMP or JPEG format.</p>
<p><a href="https://iotexpert.com/?attachment_id=6863" rel="attachment wp-att-6863"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.39.54-AM-1024x592.png" alt="" width="1024" height="592" class="alignnone size-large wp-image-6863" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.39.54-AM-1024x592.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.39.54-AM-600x347.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.39.54-AM-300x173.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-11.39.54-AM-768x444.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Bitmap Converter for emWin</h1>
<p>I suppose the first question is, &#8220;How do I get a bitmap from my computer in PNG format into the Segger Bitmap format?&#8221;  Well, it turns out that Segger has a program called <a href="https://www.segger.com/products/user-interface/emwin/tools/tools-overview/" target="_blank" rel="noopener noreferrer">Bitmap Converter for emWin</a>.</p>
<p><a href="https://iotexpert.com/?attachment_id=6859" rel="attachment wp-att-6859"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-10.26.49-AM-1024x384.png" alt="" width="1024" height="384" class="alignnone size-large wp-image-6859" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-10.26.49-AM-1024x384.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-10.26.49-AM-600x225.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-10.26.49-AM-300x112.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-11-at-10.26.49-AM-768x288.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>This is a pay program, but you can download it to try it out.  It is sort of an old-school windows program.  So I installed it on parallels on my mac.  When you run it the first time it reminds me that this is not for production.  Got it!</p>
<p><a href="https://iotexpert.com/?attachment_id=6868" rel="attachment wp-att-6868"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.14.23-AM.png" alt="" width="992" height="452" class="alignnone size-large wp-image-6868" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.14.23-AM.png 992w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.14.23-AM-600x273.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.14.23-AM-300x137.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.14.23-AM-768x350.png 768w" sizes="auto, (max-width: 992px) 100vw, 992px" /></a></p>
<p>I start by opening the PNG file of my logo.  Notice that it says the file is 1091 by 739 and in &#8220;ARGB&#8221; colors.  &#8220;ARGB&#8221; means Alpha, Red, Green and Blue. (more on this later).</p>
<p><a href="https://iotexpert.com/?attachment_id=6867" rel="attachment wp-att-6867"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.06-AM-1024x880.png" alt="" width="1024" height="880" class="alignnone size-large wp-image-6867" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.06-AM-1024x880.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.06-AM-600x515.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.06-AM-300x258.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.06-AM-768x660.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.06-AM.png 1404w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>On the Image menu I start by picking &#8220;Scale..&#8221; to reduce the size.</p>
<p><a href="https://iotexpert.com/?attachment_id=6866" rel="attachment wp-att-6866"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.26-AM.png" alt="" width="542" height="580" class="alignnone size-large wp-image-6866" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.26-AM.png 542w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.26-AM-280x300.png 280w" sizes="auto, (max-width: 542px) 100vw, 542px" /></a></p>
<p>I pick out 276 wide and it keeps the aspect ratio the same, which results in a height of 186 (actually 10 pixels to high)</p>
<p><a href="https://iotexpert.com/?attachment_id=6865" rel="attachment wp-att-6865"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.37-AM.png" alt="" width="454" height="376" class="alignnone size-full wp-image-6865" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.37-AM.png 454w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.15.37-AM-300x248.png 300w" sizes="auto, (max-width: 454px) 100vw, 454px" /></a></p>
<p>After clicking OK I get this.</p>
<p><a href="https://iotexpert.com/?attachment_id=6869" rel="attachment wp-att-6869"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.17.45-AM.png" alt="" width="760" height="620" class="alignnone size-full wp-image-6869" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.17.45-AM.png 760w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.17.45-AM-600x489.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.17.45-AM-300x245.png 300w" sizes="auto, (max-width: 760px) 100vw, 760px" /></a></p>
<p>Now, I want to take that bitmap and turn it into a &#8220;C&#8221; file that has the right data structures.  To do that pick &#8220;Save As..&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6873" rel="attachment wp-att-6873"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.19.47-AM.png" alt="" width="1014" height="224" class="alignnone size-large wp-image-6873" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.19.47-AM.png 1014w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.19.47-AM-600x133.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.19.47-AM-300x66.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.19.47-AM-768x170.png 768w" sizes="auto, (max-width: 1014px) 100vw, 1014px" /></a></p>
<p>Then pick &#8220;C&#8221; bitmap file (*.c)</p>
<p><a href="https://iotexpert.com/?attachment_id=6872" rel="attachment wp-att-6872"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.20.11-AM-1024x765.png" alt="" width="1024" height="765" class="alignnone size-large wp-image-6872" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.20.11-AM-1024x765.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.20.11-AM-600x448.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.20.11-AM-300x224.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.20.11-AM-768x574.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.20.11-AM.png 1106w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now, it asks me this question, which I didn&#8217;t really know the answer to. (more on this later) but I let the default be &#8220;True color with alpha&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6871" rel="attachment wp-att-6871"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.25.06-AM.png" alt="" width="606" height="456" class="alignnone size-large wp-image-6871" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.25.06-AM.png 606w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.25.06-AM-600x451.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.25.06-AM-300x226.png 300w" sizes="auto, (max-width: 606px) 100vw, 606px" /></a></p>
<p>This created a &#8220;C&#8221; file called IOTexpert_Logo_Vertical.c&#8221; which seems to be OK.</p>
<h1>Updating a Project to draw a Segger Bitmap</h1>
<p>Rather than make a new project.  I start with the project from the previous article.  I use the finder to copy/paste the c file into my project.  You can see it below.</p>
<p><a href="https://iotexpert.com/?attachment_id=6870" rel="attachment wp-att-6870"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.34.43-AM.png" alt="" width="920" height="682" class="alignnone size-full wp-image-6870" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.34.43-AM.png 920w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.34.43-AM-600x445.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.34.43-AM-300x222.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-8.34.43-AM-768x569.png 768w" sizes="auto, (max-width: 920px) 100vw, 920px" /></a></p>
<p>Then I double click on the file.  Here is the top.  Notice it reminds me that this is demo only.  And it gives me a little bit of information about the bitmap.  Specifically the width and height.  As well as the number of colors which is 32 bits per pixel.  It turns out that this is 4-bytes per pixel.  The first byte is Alpha and then one byte each for Red, Green and Blue.  Notice that it also declares an extern structure &#8220;extern GUI_CONST_STORAGE GUI_BITMAP bmIOTexpert_Logo_Vertical&#8221;.  This is exactly the right type to call the GUI_Drawbitmap function.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">/*********************************************************************
*                SEGGER Microcontroller GmbH &amp; Co. KG                *
*        Solutions for real time microcontroller applications        *
*                           www.segger.com                           *
**********************************************************************
*                                                                    *
* C-file generated by                                                *
*                                                                    *
*        Bitmap Converter for emWin (Demo version) V5.48.            *
*        Compiled Jun 12 2018, 15:10:41                              *
*                                                                    *
*        (c) 1998 - 2018 Segger Microcontroller GmbH                 *
*                                                                    *
*        May not be used in a product                                *
*                                                                    *
**********************************************************************
*                                                                    *
* Source file: IOTexpert_Logo_Vertical                               *
* Dimensions:  276 * 186                                             *
* NumColors:   32bpp: 16777216 + 256                                 *
*                                                                    *
**********************************************************************
*/

#include &lt;stdlib.h&gt;

#include "GUI.h"

#ifndef GUI_CONST_STORAGE
  #define GUI_CONST_STORAGE const
#endif

extern GUI_CONST_STORAGE GUI_BITMAP bmIOTexpert_Logo_Vertical;

static GUI_CONST_STORAGE U32 _acIOTexpert_Logo_Vertical[] = {
  0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 
</pre>
<p>In my project I create a new function called &#8220;ShowIoT&#8221; screen.  This will just clear the screen, update the display, then draw the bitmap, then update the screen, then wait forever.  In order for my file to know about the bitmap I copy the &#8220;extern GUI_CONST_STORAGE GUI_BITMAP bmIOTexpert_Logo_Vertical&#8221; into my file.  Typically this declaration would be in a &#8220;.h&#8221; file that was paired with the &#8220;.c&#8221; file.  Oh well.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">extern GUI_CONST_STORAGE GUI_BITMAP bmCypressLogoFullColor_PNG_1bpp;

void ShowIoTScreen(void)
{
    /* Set foreground and background color and font size */
    GUI_Clear();
    GUI_SetBkColor(GUI_WHITE);
    GUI_SetColor(GUI_BLACK);
    UpdateDisplay(CY_EINK_FULL_4STAGE, true);

    GUI_DrawBitmap(&amp;bmCypressLogoFullColor_PNG_1bpp, 0, 0);

    /* Send the display buffer data to display*/
    UpdateDisplay(CY_EINK_FULL_4STAGE, true);
    while(1)
    	vTaskDelay(100);
}
</pre>
<p>When I build the project I find out.. HOLY CRAP my project is now 270648 bytes.  Wow.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">=========================================
== Application CM0+ Memory ==
=========================================
code:6560	sram:1724


=========================================
== Application CM4 Memory ==
=========================================
code:270648	sram:278508

</pre>
<p>Why is this?  Simple, by looking at the linker map you can see that the array of data for the bitmap is 0x32220 which is also known as <span>205344 bytes.  Im going to have to figure out something better than that.</span></p>
<pre class="EnlighterJSRAW" data-enlighter-language="c"> .rodata._acIOTexpert_Logo_Vertical
                0x0000000000000000    0x32220 ./Source/IOTexpert_Logo_Vertical.o</pre>
<p>When I program the screen I get this&#8230; which obviously is jacked up.</p>
<p><a href="https://iotexpert.com/?attachment_id=6879" rel="attachment wp-att-6879"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0482-2-1024x872.jpg" alt="" width="1024" height="872" class="alignnone size-large wp-image-6879" srcset="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0482-2-1024x872.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0482-2-600x511.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0482-2-300x256.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0482-2-768x654.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>But what to do?</p>
<h1>Converting a Color Bitmap to Black and White</h1>
<p>Well instead of a color image (32 bits-per-pixel) let&#8217;s use the Bitmap Converter for emWin (Demo version V5.8 to convert the image to BW.  On the Image &#8211;&gt;Covert to &#8211;&gt; BW (1BPP)</p>
<p><a href="https://iotexpert.com/?attachment_id=6877" rel="attachment wp-att-6877"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.17-AM-1024x879.png" alt="" width="1024" height="879" class="alignnone size-large wp-image-6877" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.17-AM-1024x879.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.17-AM-600x515.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.17-AM-300x257.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.17-AM-768x659.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.17-AM.png 1156w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>After running that I get this. (what happened to my logo?).</p>
<p><a href="https://iotexpert.com/?attachment_id=6876" rel="attachment wp-att-6876"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.30-AM-1024x889.png" alt="" width="1024" height="889" class="alignnone size-large wp-image-6876" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.30-AM-1024x889.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.30-AM-600x521.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.30-AM-300x261.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.30-AM-768x667.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.11.30-AM.png 1400w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><br />
After exporting the new image to a &#8220;.c&#8221; file I go have a look.  OK it isnt very often that I learn something new about &#8220;C&#8221;.  But look at this.  Apparently you can represent binary data as &#8220;X&#8221; and &#8220;_&#8221; when initializing arrays.  Who knew?</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">static GUI_CONST_STORAGE unsigned char _acIOTexpert_Logo_Vertical[] = {
  XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, 
        XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXXXXXX, XXXX____,
</pre>
<p>When I build the project I find that it is much much smaller.  Thats good.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">=========================================
== Application CM0+ Memory ==
=========================================
code:6560	sram:1724


=========================================
== Application CM4 Memory ==
=========================================
code:69744	sram:278492

</pre>
<p>And I find that the image occupies 0x196e bytes (also known as 6510 in decimal).  Much better.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">.rodata._acIOTexpert_Logo_Vertical
                0x000000001000f880     0x196e ./Source/IOTexpert_Logo_Vertical.o</pre>
<p>But, when I program the board, my image is jacked up.  I suppose that I shouldn&#8217;t be surprised as thats what the program showed me as well.</p>
<p><a href="https://iotexpert.com/?attachment_id=6880" rel="attachment wp-att-6880"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0483-1024x859.jpg" alt="" width="1024" height="859" class="alignnone size-large wp-image-6880" srcset="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0483-1024x859.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0483-600x504.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0483-300x252.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0483-768x645.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Using GIMP to Fix B/W Conversion</h1>
<p>My lab assistant, Nicholas, looked at the image and said.  The problem is that when you converted it to black and white, the light colors in the logo turned to white instead of black.  OK.  How do I fix it?  Simple, install <a href="https://www.gimp.org" target="_blank" rel="noopener noreferrer">GIMP</a> and edit the PNG.  GIMP is GNU Image Processor and is a program that acts like Adobe Photoshop.</p>
<p>Start by opening up the logo and it tell me nearly the same thing as the BitMap converter program.</p>
<p><a href="https://iotexpert.com/?attachment_id=6885" rel="attachment wp-att-6885"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.36.13-AM-1024x645.png" alt="" width="1024" height="645" class="alignnone size-large wp-image-6885" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.36.13-AM-1024x645.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.36.13-AM-600x378.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.36.13-AM-300x189.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.36.13-AM-768x484.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>On the left side of the screen there is a &#8220;bucket&#8221; icon which will pour color into regions of the image.  So, to make things work I pour black everywhere there is color.  That little black white thing specifies the foreground and background colors.</p>
<p><a href="https://iotexpert.com/?attachment_id=6883" rel="attachment wp-att-6883"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.13-AM-1024x642.png" alt="" width="1024" height="642" class="alignnone size-large wp-image-6883" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.13-AM-1024x642.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.13-AM-600x376.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.13-AM-300x188.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.13-AM-768x482.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now I take the file and export it back to an PNG.</p>
<p><a href="https://iotexpert.com/?attachment_id=6882" rel="attachment wp-att-6882"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.27-AM.png" alt="" width="612" height="854" class="alignnone size-large wp-image-6882" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.27-AM.png 612w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.27-AM-600x837.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.39.27-AM-215x300.png 215w" sizes="auto, (max-width: 612px) 100vw, 612px" /></a></p>
<p>When you pick &#8220;PNG&#8221; you need to give it some options.  Which I took also as default.</p>
<p><a href="https://iotexpert.com/?attachment_id=6881" rel="attachment wp-att-6881"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.40.39-AM.png" alt="" width="580" height="920" class="alignnone size-full wp-image-6881" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.40.39-AM.png 580w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.40.39-AM-189x300.png 189w" sizes="auto, (max-width: 580px) 100vw, 580px" /></a></p>
<p>Now when I open it up in the Bitmap Converter it looks all black and white.  BUT notice that it is still &#8220;ARGB&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=6886" rel="attachment wp-att-6886"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.44.16-AM.png" alt="" width="878" height="798" class="alignnone size-full wp-image-6886" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.44.16-AM.png 878w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.44.16-AM-600x545.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.44.16-AM-300x273.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.44.16-AM-768x698.png 768w" sizes="auto, (max-width: 878px) 100vw, 878px" /></a></p>
<p>So, I convert it to black and white.</p>
<p><a href="https://iotexpert.com/?attachment_id=6887" rel="attachment wp-att-6887"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.45.24-AM.png" alt="" width="906" height="822" class="alignnone size-full wp-image-6887" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.45.24-AM.png 906w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.45.24-AM-600x544.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.45.24-AM-300x272.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-12-at-9.45.24-AM-768x697.png 768w" sizes="auto, (max-width: 906px) 100vw, 906px" /></a></p>
<p>Then I follow the same process to program the development kit. (export C file, copy into project, fix up the extern and build/program).  Excellent.  Now my image is good.</p>
<p><a href="https://iotexpert.com/?attachment_id=6890" rel="attachment wp-att-6890"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0484-1024x806.jpg" alt="" width="1024" height="806" class="alignnone size-large wp-image-6890" srcset="https://iotexpert.com/wp-content/uploads/2019/05/IMG_0484-1024x806.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0484-600x472.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0484-300x236.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/05/IMG_0484-768x604.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In the next article I will talk more about the Bitmap format, and colors, and Alpha.  I will then show you how to use some of the other APIs.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/iot-expert-logo-conversion-bitmap-madness-part-1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CY8CKIT-028-EPD:  How Does The Driver Work?</title>
		<link>https://iotexpert.com/cy8ckit-028-epd-how-does-the-driver-work/</link>
					<comments>https://iotexpert.com/cy8ckit-028-epd-how-does-the-driver-work/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Fri, 10 May 2019 15:02:39 +0000</pubDate>
				<category><![CDATA[CY8CKIT-028-EPD]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6826</guid>

					<description><![CDATA[Summary Before I finish this series there are two more issues which I would like to address.  First, I want to walk you through the schematic and show you how things are connected.  And second, I want to talk about the &#8220;Update Scheme&#8221;.  Unfortunately, there are a couple of other things that I would like [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>Before I finish this series there are two more issues which I would like to address.  First, I want to walk you through the schematic and show you how things are connected.  And second, I want to talk about the &#8220;Update Scheme&#8221;.  Unfortunately, there are a couple of other things that I would like to dig into, but for now this article will be the last.  But, I will leave a few links at the end of the article which will give you a hint about other things that I might be interested in.</p>
<h1>Electrical Interface</h1>
<p>If you follow back through the previous articles you will notice that there are several different pins.  Here is the pin assignment from PSoC Creator.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-09-03-pm/" rel="attachment wp-att-6687"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM.png" alt="" width="670" height="297" class="alignnone size-full wp-image-6687" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM.png 670w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM-600x266.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM-300x133.png 300w" sizes="auto, (max-width: 670px) 100vw, 670px" /></a></p>
<p>But what do they do?  If you look at the list you will see that four of them are to control the SPI interface to the G2 display driver. (miso, mosi, sclk, CY_EINK_Ssel).  The rest of them Ill go one by one through.</p>
<p>First is the pin called &#8220;CY_EINK_DispEn&#8221;.  This pin really should have been called &#8220;DISP_PWR_EN&#8221; so that it matched the actual shield schematic.  This is a digital output pin which is connected to a <a href="https://www.vishay.com/docs/63705/sip32401a.pdf" target="_blank" rel="noopener noreferrer">Vishay sip32401a 1.1 V to 5.5 V, Slew Rate Controlled Load Switch</a>.  Simply a power switch for the display.  Notice in the schematic that there is a 100K pulldown resistor connected to the enable which means that by default the power is off to the display.  Also notice that R3 is a &#8220;No Load&#8221; pullup resistor.  You could remove R4 and load R3 to make the power on by default&#8230; which I don&#8217;t think that you would actually ever do as if you are using an EPD you probably care about power.</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-9-47-19-am/" rel="attachment wp-att-6839"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.47.19-AM.png" alt="" width="535" height="292" class="alignnone size-full wp-image-6839" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.47.19-AM.png 535w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.47.19-AM-300x164.png 300w" sizes="auto, (max-width: 535px) 100vw, 535px" /></a></p>
<p>The next pin is called &#8220;CY_EINK_DispIoEn&#8221;.  This is a digital output pin which is connected to &#8220;DISP_IO_EN_L&#8221; on the shield.  This is simply the I/O enable of a Fairchild <a href="https://www.onsemi.com/pub/Collateral/FXMA108-D.pdf" target="_blank" rel="noopener noreferrer">FXMA108BQX</a> level shifter.  This allows the PSoC to run at lower voltages (e.g. 1.8v) than the 3.3v required by the EPD G2 driver chip.  This would also enable a chip to run at a higher voltage (e.g. 5V) if you were using a 5V capable PSoC (e.g. all of the PSoC 4s).  The schematic uses the same pullup/down scheme that was used on the power switch above.</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-9-43-59-am/" rel="attachment wp-att-6838"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.43.59-AM.png" alt="" width="533" height="373" class="alignnone size-full wp-image-6838" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.43.59-AM.png 533w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.43.59-AM-300x210.png 300w" sizes="auto, (max-width: 533px) 100vw, 533px" /></a></p>
<p>The next pin is called &#8220;CY_EINK_Discharge&#8221; and is a digital output from the PSoC.  Notice that when the PSoC drives this pin high that it will enable two power transistors and will short &#8220;VGH&#8221; and &#8220;VDH&#8221; to ground.</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-9-49-53-am/" rel="attachment wp-att-6841"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.49.53-AM.png" alt="" width="347" height="295" class="alignnone size-large wp-image-6841" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.49.53-AM.png 347w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.49.53-AM-300x255.png 300w" sizes="auto, (max-width: 347px) 100vw, 347px" /></a></p>
<p>If you read the &#8220;E-paper Display COG Driver Interface Timing for 1.44”,1.9”,2”,2.6” and 2.7” EPD with G2 COG and Aurora Mb Film&#8221; document you will see this note:</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-11-17-23-am/" rel="attachment wp-att-6845"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.23-AM.png" alt="" width="602" height="78" class="alignnone size-large wp-image-6845" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.23-AM.png 602w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.23-AM-600x78.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.23-AM-300x39.png 300w" sizes="auto, (max-width: 602px) 100vw, 602px" /></a></p>
<p>And a bit later on in the documented you will see this logic diagram.</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-11-17-49-am/" rel="attachment wp-att-6844"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.49-AM-1024x563.png" alt="" width="1024" height="563" class="alignnone size-large wp-image-6844" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.49-AM-1024x563.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.49-AM-600x330.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.49-AM-300x165.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.49-AM-768x422.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.17.49-AM.png 1145w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>According to the data sheet, Vgh is driven to &gt;12v and Vdh&gt;8v by a charge pump while talking to the screen.  What I don&#8217;t understand is why the note says to drive &#8220;Vdd and Vcc&#8221; to ground when their schematic says Vdh and Vgh.  I am assuming that the note is an error and the schematic is correct, but Ill send them a note and ask. [edit: I got a quick response from an excellent FAE at Pervasive&#8230; with this answer]</p>
<p>&#8220;No, the expression of Note 1 about Vcc/Vdd, it means the power off command set. You can also refer to Power off sequence in section 6 on page 34 of 4P018-00 as follows&#8221;</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/thumbnail_image002/" rel="attachment wp-att-6849"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/thumbnail_image002-1024x584.png" alt="" width="1024" height="584" class="alignnone size-large wp-image-6849" srcset="https://iotexpert.com/wp-content/uploads/2019/05/thumbnail_image002-1024x584.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/thumbnail_image002-600x342.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/thumbnail_image002-300x171.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/thumbnail_image002-768x438.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/thumbnail_image002.png 1105w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The last digital I/O pin is called &#8220;CY_EINK_Border&#8221;.  This pin is connected to the note &#8220;EPD_BRDR_CTRL&#8221; on this little circuit on the shield.</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-9-50-00-am/" rel="attachment wp-att-6840"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.50.00-AM.png" alt="" width="348" height="375" class="alignnone size-full wp-image-6840" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.50.00-AM.png 348w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-9.50.00-AM-278x300.png 278w" sizes="auto, (max-width: 348px) 100vw, 348px" /></a></p>
<p>If you look in the documentation you will see this note:</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-11-33-45-am/" rel="attachment wp-att-6846"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.33.45-AM.png" alt="" width="1002" height="135" class="alignnone size-full wp-image-6846" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.33.45-AM.png 1002w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.33.45-AM-600x81.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.33.45-AM-300x40.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.33.45-AM-768x103.png 768w" sizes="auto, (max-width: 1002px) 100vw, 1002px" /></a></p>
<p>And when you look at the timing diagram you see this which shows that after you have update the frame, that you need to do a low, high, low of the border to make it white again.</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-09-at-11-37-23-am/" rel="attachment wp-att-6847"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.37.23-AM.png" alt="" width="956" height="749" class="alignnone size-full wp-image-6847" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.37.23-AM.png 956w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.37.23-AM-600x470.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.37.23-AM-300x235.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-09-at-11.37.23-AM-768x602.png 768w" sizes="auto, (max-width: 956px) 100vw, 956px" /></a></p>
<p>This transition is handled for you by the function &#8220;Pv_EINK_HardwarePowerOff&#8221; function&#8230; which I chopped out a little bit of to show the border control.</p>
<pre class="lang:c decode:true ">pv_eink_status_t Pv_EINK_HardwarePowerOff(void)
{
.....
    
    /* After E-INK updates, the border color may degrade to a gray level that is not
    as white as the active area. Toggle the Border pin to avoid this phenomenon. */
    CY_EINK_Delay(PV_EINK_DUMMY_LINE_DELAY);
    CY_EINK_BorderLow;
    CY_EINK_Delay(PV_EINK_BOARDER_DELAY);
    CY_EINK_BorderHigh;

...
turn of the G2    
....

    /* Detach SPI and disable the load switch connected to E-INK display's Vcc */
    Cy_EINK_DetachSPI();
    CY_EINK_TurnOffVcc;
    
    /* Return the pins to their default (OFF) values*/
    CY_EINK_BorderLow;
    CY_EINK_Delay(PV_EINK_CS_OFF_DELAY);
    CY_EINK_CsLow;
    CY_EINK_RstLow;
    CY_EINK_DischargeHigh;
    CY_EINK_Delay(PV_EINK_DETACH_DELAY);
    CY_EINK_DischargeLow;
    
    /* If all operations were completed successfully, send the corresponding flag */
    return(PV_EINK_RES_OK);
}</pre>
<h1>Update Scheme</h1>
<p>If you look at the original picture that I posted,  you can see that &#8220;Hassane&#8230;&#8221; text.  But if you look closely you can see a &#8220;ghost image&#8221; of the Cypress logo in the background.  Why is this?</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/img_0408/" rel="attachment wp-att-6668"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-6668" srcset="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-scaled-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-768x576.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>It turns out that Pervasive has three schemes for updating the screen they are called</p>
<ol>
<li>Four stage</li>
<li>Two stage</li>
<li>Partial</li>
</ol>
<p>The four stage update actually writes four complete images on the screen as below (here is the picture from the Pervasive document)</p>
<p><a href="https://iotexpert.com/2019/05/10/cy8ckit-028-epd-how-does-the-driver-work/screen-shot-2019-05-07-at-6-41-59-am/" rel="attachment wp-att-6834"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-07-at-6.41.59-AM-1024x384.png" alt="" width="1024" height="384" class="alignnone size-large wp-image-6834" srcset="https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-07-at-6.41.59-AM-1024x384.png 1024w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-07-at-6.41.59-AM-600x225.png 600w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-07-at-6.41.59-AM-300x113.png 300w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-07-at-6.41.59-AM-768x288.png 768w, https://iotexpert.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-07-at-6.41.59-AM.png 1552w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The purpose of this four stage update is to reduce the ghost images which remain from the previous updates.  Remember that the cool part about these screens is that there are crystals that flip from white to black and back&#8230; and once they are flipped you do not need to maintain power to keep them flipped.  The bad news is that they really want to stay flipped which causes Ghosting.</p>
<p>So why can you see the old image of the Cypress logo?  Simple,  when the four-stage update happened, I had just programmed the kit which means that my program had no idea what was on the screen from before.  This made stage 1 not work correctly because it had to assume all white.</p>
<p>The next question is what is the problem with the four-stage update?  Well it takes a while (like about 2 seconds) on the 2.7&#8243; screen.  And because it writes 4 times it also consumes more power.  Pervasive also says that you can do a two-stage update with just stage 1 and stage 4 from above.  In my case this cuts the time in about half.</p>
<p>Finally you can also do a &#8220;partial&#8221; update.  I tried this and it didn&#8217;t work very well for my demo application which massively changes the screen from screen to screen.  But, it does seem to work pretty well for a series of updates to the same reigon (like this counter).  Here is a video I made showing Partial, Two and Four stage updates.   In addition our API lets you turn the power on/off for the G2 Driver &#8211; called &#8220;power cycle&#8221;.  I used that as a variable as well.</p>
<div class="jupiterx-oembed"><iframe loading="lazy" title="CY8CKIT-028-EPD emWin EPD Update Speed" width="500" height="281" src="https://www.youtube.com/embed/IFwcekb7GkQ?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<h1>Terms of Art</h1>
<p>EPD &#8211; Electrophoretic Display</p>
<p>eTC &#8211; external timing control</p>
<p>iTC &#8211; internal timing control</p>
<p>G2 COG &#8211; Display Controller Chip&#8230; Chip on Glass</p>
<p>FPL &#8211; Front Plane Laminate (of which Aurora ma and mb are two types)</p>
<p>Aurora ma &#8211; Wide Temperature film</p>
<p>Aurora mb &#8211; Low power</p>
<p>E2271CS021 &#8211; Aurora mb 2.71&#8243; EPD Panel &#8211; on CY8CKIT-028-EPD</p>
<p>E2271BS021 &#8211; Aurora ma 2.71&#8243; EPD Panel</p>
<h1>References</h1>
<p>mbed add http://os.mbed.com/users/dreschpe/code/EaEpaper/</p>
<p>http://www.pervasivedisplays.com/kits/ext2_kit</p>
<p>https://www.nayuki.io/page/pervasive-displays-epaper-panel-hardware-driver</p>
<p>https://github.com/nayuki/Pervasive-Displays-epaper-driver</p>
<p>https://github.com/repaper/gratis</p>
<p>https://github.com/aerialist/repaper_companion</p>
<p>https://www.paulschow.com/2017/02/pervasive-displays-epd-extension-kit.html</p>
<p>https://embeddedcomputing.weebly.com/pervasive-displays-e-paper-epd-extension-kit-gen-2.html</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/cy8ckit-028-epd-how-does-the-driver-work/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CY8CKIT-028 Eink Mo-better</title>
		<link>https://iotexpert.com/cy8ckit-028-eink-mo-better/</link>
					<comments>https://iotexpert.com/cy8ckit-028-eink-mo-better/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Sun, 21 Apr 2019 23:33:13 +0000</pubDate>
				<category><![CDATA[CY8CKIT-028-EPD]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6751</guid>

					<description><![CDATA[Summary In the last article, I walked you through the process of making the CY8CKIT-028 EINK shield work on the PSoC 6 and Modus Toolbox 1.1.  The article got to be a bit out of control in terms of length so I decided to split it into four pieces.  In this article, the second part, [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>In the last <a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/">article</a>, I walked you through the process of making the CY8CKIT-028 EINK shield work on the PSoC 6 and Modus Toolbox 1.1.  The article got to be a bit out of control in terms of length so I decided to split it into four pieces.  In this article, the second part, I will make updates to the project to increase the overall speed of updating the display.  This will require a dive into the PSoC 6 clocking system.</p>
<p>This article will contain the following steps/commentary:</p>
<ol>
<li>Make a new project based on the previous example</li>
<li>Examine the PSOC 6 clocking system</li>
<li>Look at what is required to speed up the SPI &amp; make the changes</li>
<li>Update, program and test the faster clock</li>
</ol>
<h1>Make a new project</h1>
<p>I really wish I knew how to copy a Modus Toolbox project, and I suppose that is something I should probably figure out.  But, for this article, Ill create a new project, setup the middleware and copy in the files from the previous project.  Here we go:</p>
<p>First, create a new project for the CY8CKIT-062-BLE</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-10-44-22-am/" rel="attachment wp-att-6754"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-10.44.22-AM-1024x692.png" alt="" width="1024" height="692" class="alignnone size-large wp-image-6754" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-10.44.22-AM-1024x692.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-10.44.22-AM-600x405.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-10.44.22-AM-300x203.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-10.44.22-AM-768x519.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-10.44.22-AM.png 1172w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><br />
Then copy the &#8220;design.modus&#8221; from the previous project and paste it into the new project.  You can do with ctrl-c and ctrl-v.  Remember, the design.modus file is just an xml file that contains all of the configuration information for your project.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-30-31-am/" rel="attachment wp-att-6752"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.31-AM.png" alt="" width="710" height="970" class="alignnone size-full wp-image-6752" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.31-AM.png 710w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.31-AM-600x820.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.31-AM-220x300.png 220w" sizes="auto, (max-width: 710px) 100vw, 710px" /></a></p>
<p>Next, select middleware for your project including FreeRTOS, Retarget I/O and the two Segger libraries.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-30-10-am/" rel="attachment wp-att-6753"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.10-AM-1024x907.png" alt="" width="1024" height="907" class="alignnone size-large wp-image-6753" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.10-AM-1024x907.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.10-AM-600x532.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.10-AM-300x266.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.10-AM-768x680.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.30.10-AM.png 1966w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Recall from the previous article that you need to remove the incorrectly included path for &#8230;Bitplains/config.  To do this right click on the project, select settings, pick paths and symbols then click on the wrong directory path and hit Delete.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-33-24-am/" rel="attachment wp-att-6755"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.33.24-AM-1024x807.png" alt="" width="1024" height="807" class="alignnone size-large wp-image-6755" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.33.24-AM-1024x807.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.33.24-AM-600x473.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.33.24-AM-300x236.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.33.24-AM-768x605.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now you need to add the paths for &#8220;eInk Library&#8221; and the &#8220;emWin_Config&#8221;.   To do this click the &#8220;Add&#8230;&#8221; button.  In the screen below you can see that I clicked &#8220;Is a workspace path&#8221; which will make it a relative path (i.e. not hardcoded).  Now click &#8220;Workspace&#8230;&#8221;</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-44-37-am/" rel="attachment wp-att-6765"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM.png" alt="" width="784" height="428" class="alignnone size-large wp-image-6765" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM.png 784w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM-600x328.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM-300x164.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM-768x419.png 768w" sizes="auto, (max-width: 784px) 100vw, 784px" /></a></p>
<p>Then select the &#8220;emWin_Config&#8221; folder</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-46-14-am/" rel="attachment wp-att-6762"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.14-AM.png" alt="" width="790" height="784" class="alignnone size-large wp-image-6762" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.14-AM.png 790w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.14-AM-100x100.png 100w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.14-AM-600x595.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.14-AM-150x150.png 150w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.14-AM-300x298.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.14-AM-768x762.png 768w" sizes="auto, (max-width: 790px) 100vw, 790px" /></a></p>
<p>Then do the same process again for the eInk Library.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-44-37-am/" rel="attachment wp-att-6765"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM.png" alt="" width="784" height="428" class="alignnone size-large wp-image-6765" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM.png 784w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM-600x328.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM-300x164.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.44.37-AM-768x419.png 768w" sizes="auto, (max-width: 784px) 100vw, 784px" /></a></p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-45-42-am/" rel="attachment wp-att-6763"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.45.42-AM.png" alt="" width="794" height="780" class="alignnone size-large wp-image-6763" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.45.42-AM.png 794w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.45.42-AM-600x589.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.45.42-AM-300x295.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.45.42-AM-768x754.png 768w" sizes="auto, (max-width: 794px) 100vw, 794px" /></a></p>
<p>Now your Include path should look something like this:</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-46-26-am/" rel="attachment wp-att-6761"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.26-AM-1024x605.png" alt="" width="1024" height="605" class="alignnone size-large wp-image-6761" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.26-AM-1024x605.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.26-AM-600x354.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.26-AM-300x177.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.46.26-AM-768x454.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The next thing to do is copy your c and h files from the previous project.  I just use ctrl-c and ctrl-v</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-42-07-am/" rel="attachment wp-att-6759"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.42.07-AM.png" alt="" width="714" height="874" class="alignnone size-full wp-image-6759" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.42.07-AM.png 714w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.42.07-AM-600x734.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.42.07-AM-245x300.png 245w" sizes="auto, (max-width: 714px) 100vw, 714px" /></a></p>
<p>&nbsp;</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-41-35-am/" rel="attachment wp-att-6760"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.41.35-AM.png" alt="" width="714" height="880" class="alignnone size-large wp-image-6760" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.41.35-AM.png 714w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.41.35-AM-600x739.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.41.35-AM-243x300.png 243w" sizes="auto, (max-width: 714px) 100vw, 714px" /></a></p>
<p>Finally build it and make sure everything is working.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-20-at-11-52-09-am/" rel="attachment wp-att-6766"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.52.09-AM-1024x387.png" alt="" width="1024" height="387" class="alignnone size-large wp-image-6766" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.52.09-AM-1024x387.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.52.09-AM-600x227.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.52.09-AM-300x114.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-20-at-11.52.09-AM-768x291.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>How does the clocking in the PSoC 6 work?</h1>
<p>Before we can fix the SPI speed problem we should have a closer look at the PSoC 6 clocking system.  Let&#8217;s start this by double clicking the design.modus in order to open up the device configurator.  When you click on the &#8220;Platform&#8221; you should see a window that looks like this.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-6-12-42-pm/" rel="attachment wp-att-6787"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.12.42-PM-1024x495.png" alt="" width="1024" height="495" class="alignnone size-large wp-image-6787" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.12.42-PM-1024x495.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.12.42-PM-600x290.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.12.42-PM-300x145.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.12.42-PM-768x371.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.12.42-PM.png 1249w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>On the far left side of the picture you can see the &#8220;Input&#8221; section.  These are reference sources that will drive all of the clock signals in the chip.  This includes</p>
<ul>
<li>IMO &#8211; Internal Main Oscillator which is an 8Mhz 1% precision RC Oscillator (requires no external components)</li>
<li>ECO &#8211; External Crystal Oscillator which will drive a precision crystal for a more accurate clock.  This is sometimes called the &#8220;Megahertz clock&#8221;</li>
<li>External Clock &#8211; a pin that will take a clock signal from outside the chip</li>
<li>ILO &#8211; Internal Low Speed Oscillator &#8211; a 32Khz +- 30% (yes 30%) very low power very slow oscillator for generating wakeup signals etc.</li>
<li>WCO &#8211; Watch Crystal Oscillator &#8211; a very precise circuit for driving a 32Khz watch crystal for very accurate clocks</li>
</ul>
<p>You can configure each of the &#8220;Input&#8221; clock sources on the &#8220;Input&#8221; section of the &#8220;System Clock&#8221;.  In the picture below you can see that I have enabled all of the clock sources and I&#8217;m updating the parameters on the ECO.  In the picture above all of the input sources that are enabled become green.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-11-49-31-am/" rel="attachment wp-att-6780"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-11.49.31-AM.png" alt="" width="491" height="640" class="alignnone size-full wp-image-6780" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-11.49.31-AM.png 491w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-11.49.31-AM-230x300.png 230w" sizes="auto, (max-width: 491px) 100vw, 491px" /></a></p>
<p>The next section of the clock tree is the &#8220;Paths&#8221;.  On the input side of the paths are the &#8220;Sources&#8221; which are attached to six multiplexors labeled &#8220;PATH_MUXn&#8221;.  You can use the &#8220;Paths&#8221; to select which Input source is driving the &#8220;Path&#8221; (i.e. IMO, ECO etc.).  The outputs of the Paths are used to drive the HF_CLOCKs.  The only trick in the paths is that &#8220;Path0&#8221; and &#8220;Path1&#8221; are special.  In Path0 you can either use the Input to drive an FLL or you can just &#8220;pass through&#8221; the input signal to the output of the path.  And in &#8220;Path1&#8221; you can either use the Input PATH_MUX1 to drive a PLL or as above, you can just &#8220;pass through&#8221; the input signal to the output of the path.  Unfortunately this picture does not label &#8220;CLK_PATH0&#8221; or &#8220;CLK_PATH1&#8221;, but if they were on the picture, they would be just to the right of the three multiplexors just to the right of the FLL and PLL.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-6-13-03-pm/" rel="attachment wp-att-6786"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.13.03-PM.png" alt="" width="294" height="441" class="alignnone size-full wp-image-6786" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.13.03-PM.png 294w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.13.03-PM-200x300.png 200w" sizes="auto, (max-width: 294px) 100vw, 294px" /></a></p>
<p>The next interesting section of the the paths is the FLL.  The frequency locked loop can generate a higher frequency signal from a lower frequency input.  In PSoC 6, the range of the FLL is 24 MHz to 100 MHz and is programmable by enabling the FLL with the checkbox, then setting the parameters.  Notice that I set it for a 24 MHz clock.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-5-42-23-pm/" rel="attachment wp-att-6783"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-5.42.23-PM.png" alt="" width="492" height="694" class="alignnone size-full wp-image-6783" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-5.42.23-PM.png 492w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-5.42.23-PM-213x300.png 213w" sizes="auto, (max-width: 492px) 100vw, 492px" /></a></p>
<p>There is also a PLL in the chip.  This can be configured to run between 12.5 MHz and 150 MHz with the IMO.  If you select a different input source e.g. ECO you will have a different range of frequencies.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-6-29-22-pm/" rel="attachment wp-att-6789"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.29.22-PM.png" alt="" width="548" height="656" class="alignnone size-full wp-image-6789" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.29.22-PM.png 548w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.29.22-PM-251x300.png 251w" sizes="auto, (max-width: 548px) 100vw, 548px" /></a></p>
<p>Notice that if you disable either the FLL or the PLL that the frequency of CLOCK_Path0 or CLOCK_Path1 will be set by the PATH_MUX0 or 1.  In other words you can pick any of the input sources to drive into CLOCK_PATH0/1</p>
<p>Just to the right of the &#8220;PATHs&#8221; there are five High Frequency Clocks labeled CLK_HF0 &#8211;&gt; CLK_HF4.  Each CLK HF has a multiplexor (which isnt shown) that selects its input from one of the 5 &#8220;paths&#8221;.  It also has a divider that allows you to divide by 1,2,4,8.  Here is a picture of the selector box for CLK_HF0</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-6-33-28-pm/" rel="attachment wp-att-6790"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.33.28-PM.png" alt="" width="542" height="712" class="alignnone size-full wp-image-6790" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.33.28-PM.png 542w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.33.28-PM-228x300.png 228w" sizes="auto, (max-width: 542px) 100vw, 542px" /></a></p>
<p>The last section of the clocks, that are relevant to this discussion, are &#8220;CLK_FAST&#8221; which sets the speed of the CPU (unfortunately the CPU clock isn&#8217;t shown on the picture&#8230; but it is attached to CLK_FAST) and &#8220;CLK_PERI&#8221; which is the source clock for many of the peripherals in the chip including the SCB/SPI and the SCB/UART.  Each of those clocks also have a configuration box where you can select one more 8-bit divider.  Notice that the source of CLK_FAST and CLK_PERI is always CLK_HF0.  Here is a picture of the selection for CLK_PERI</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-6-37-35-pm/" rel="attachment wp-att-6791"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.37.35-PM.png" alt="" width="577" height="608" class="alignnone size-full wp-image-6791" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.37.35-PM.png 577w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-6.37.35-PM-285x300.png 285w" sizes="auto, (max-width: 577px) 100vw, 577px" /></a></p>
<p>Now that we know what&#8217;s going on with the clock tree, let&#8217;s fix the SPI speed.</p>
<h1>Fix the SPI speed</h1>
<p>You might recall that when I looked at the datasheet for the Pervasive EPD EInk display driver, that I found that the SPI can be run at 20MHz.  Thats good.  And you might also recall that the way that the code example project was configured had the speed set to 8.333MHz, that isn&#8217;t so good.  These eInk screens take long enough to update as-is so speeding things up will make a better user experience.</p>
<p>We know that we want 20Mhz clock on the output of the SPI.  And from the previous article we know that the input to the SPI must be a mutliple of the &#8220;oversample&#8221;.  That means that we need the input clock to the SCB block to be 20,40,60,80,100,120, or 140 MHz.  All right given all of that I think that I&#8217;m going to run my system with a base frequency of 100 MHz.  So, fix the SPI to 20 MHz and 5 times oversampling.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-7-03-15-pm/" rel="attachment wp-att-6796"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.03.15-PM.png" alt="" width="666" height="608" class="alignnone size-full wp-image-6796" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.03.15-PM.png 666w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.03.15-PM-600x548.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.03.15-PM-300x274.png 300w" sizes="auto, (max-width: 666px) 100vw, 666px" /></a></p>
<p>Somehow or the other in all of my clicking, I got PATH_MUX1 turned off.  Ill turn it back on and select the IMO as the source.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-7-01-17-pm/" rel="attachment wp-att-6794"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.01.17-PM.png" alt="" width="469" height="408" class="alignnone size-full wp-image-6794" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.01.17-PM.png 469w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.01.17-PM-300x261.png 300w" sizes="auto, (max-width: 469px) 100vw, 469px" /></a></p>
<p>Next Ill turn on the PLL and set it to 100 Mhz</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-7-02-06-pm/" rel="attachment wp-att-6795"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.06-PM.png" alt="" width="477" height="614" class="alignnone size-full wp-image-6795" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.06-PM.png 477w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.06-PM-233x300.png 233w" sizes="auto, (max-width: 477px) 100vw, 477px" /></a></p>
<p>When I do this I get two errors, one for the UART and one for the SPI</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-7-02-42-pm/" rel="attachment wp-att-6797"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.42-PM.png" alt="" width="962" height="167" class="alignnone size-full wp-image-6797" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.42-PM.png 962w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.42-PM-600x104.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.42-PM-300x52.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.02.42-PM-768x133.png 768w" sizes="auto, (max-width: 962px) 100vw, 962px" /></a></p>
<p>Let&#8217;s fix the SPI one first.  To do that click on the little wrench and pick out the &#8220;8 bit diver 1 to 1&#8221;, which makes sense as we picked the oversampling to make that work.</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-7-05-07-pm/" rel="attachment wp-att-6798"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.05.07-PM.png" alt="" width="449" height="192" class="alignnone size-full wp-image-6798" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.05.07-PM.png 449w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.05.07-PM-300x128.png 300w" sizes="auto, (max-width: 449px) 100vw, 449px" /></a></p>
<p>And then do the same thing to fix the UART</p>
<p><a href="https://iotexpert.com/2019/04/21/cy8ckit-028-eink-mo-better/screen-shot-2019-04-21-at-7-06-24-pm/" rel="attachment wp-att-6799"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.06.24-PM.png" alt="" width="868" height="144" class="alignnone size-full wp-image-6799" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.06.24-PM.png 868w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.06.24-PM-600x100.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.06.24-PM-300x50.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-21-at-7.06.24-PM-768x127.png 768w" sizes="auto, (max-width: 868px) 100vw, 868px" /></a></p>
<h1>Build, Program and Test</h1>
<p>After all of that, build, program and test.  On my development kit it is noticeably faster now.  I suppose that I should figure out how to time it and see exactly what improvement I got, but Ill save that to the next Article.</p>
<p>In the next article Ill address the hardware timer.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/cy8ckit-028-eink-mo-better/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CY8CKIT-028-EPD and Modus Toolbox 1.1</title>
		<link>https://iotexpert.com/cy8ckit-028-epd-and-modus-toolbox-1-1/</link>
					<comments>https://iotexpert.com/cy8ckit-028-epd-and-modus-toolbox-1-1/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 15 Apr 2019 21:50:36 +0000</pubDate>
				<category><![CDATA[CY8CKIT-028-EPD]]></category>
		<category><![CDATA[CY8CKIT-062-BLE]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6666</guid>

					<description><![CDATA[Summary One of my very influential readers is working on a project where he wants to use the CY8CKIT-028-EPD.  But, he wants to use Modus Toolbox 1.1 instead of PSoC Creator and he observed, correctly, that Cypress doesn&#8217;t have a MTB code example project for the CY8CKIT-028-EPD.  I knew that we had a working code [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>One of my very influential readers is working on a project where he wants to use the <a href="https://www.cypress.com/documentation/development-kitsboards/e-ink-display-shield-board-cy8ckit-028-epd" target="_blank" rel="noopener noreferrer">CY8CKIT-028-EPD</a>.  But, he wants to use Modus Toolbox 1.1 instead of PSoC Creator and he observed, correctly, that Cypress doesn&#8217;t have a MTB code example project for the CY8CKIT-028-EPD.  I knew that we had a working code example in PSoC Creator (<a href="https://www.cypress.com/documentation/code-examples/ce23727-psoc-6-e-ink-display-interface-emwin-graphics-library" target="_blank" rel="noopener noreferrer">CE223727</a>), so I decided to do a port to MTB1.1.  This turned out to be a bit of an adventure which required me to dig out a logic analyzer to solve self inflicted problems.  Here is a picture I took while sorting it out.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/img_0408/" rel="attachment wp-att-6668"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-1024x768.jpg" alt="" width="1024" height="768" class="alignnone wp-image-6668 size-large" srcset="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-scaled-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0408-e1555270252695-768x576.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>There are a few things in the PSoC Creator example code which I didn&#8217;t really like, so, for the final solution, I would like it to be</p>
<ul>
<li>In Modus Toolbox 1.1</li>
<li>Using FreeRTOS</li>
<li>Using the Segger emWin graphics library</li>
<li>Getting the best response time</li>
<li>Using DMA to drive the display</li>
</ul>
<p>For this article I will go through these steps:</p>
<ol>
<li>Build CE223727 EmWin_Eink_Display in PSoC Creator</li>
<li>Explain the PSoC Creator Project</li>
<li>Create a new MTB Project &amp; add the FreeRTOS, Segger emWin and stdio middleware</li>
<li>Configure the device for the correct pins, clocks and peripherals</li>
<li>Setup FreeRTOS and Standard I/O</li>
<li>Copy the driver files into the MTB project from the PSoC Creator workspace</li>
<li>Port the drivers and eInkTask to work in MTB</li>
<li>Program and Test</li>
<li>(Part 2) Update the driver to remove the hardware timer</li>
<li>(Part 2) Update the example to remove polled switch and use a semaphore</li>
<li>(Part 2) Update the driver to use DMA</li>
<li>(Part 2) Explain how the EINK EPD Display Works</li>
</ol>
<p>If you lack patience and you just want a working project, you can download it from the <a href="https://github.com/iotexpert/eink-emwin-mtb1-1" target="_blank" rel="noopener noreferrer">IoT Expert GitHub</a> site. git@github.com:iotexpert/eink-emwin-mtb1-1.git</p>
<h1>First build CE223727 EmWin_Eink_Display in PSoC Creator</h1>
<p>Start by finding the code example project for the Eink Display.  In PSoC Creator on the File-&gt;Code Example menu you will be able to pick out the code example.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-4-53-44-pm/" rel="attachment wp-att-6679"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.53.44-PM.png" alt="" width="242" height="163" class="alignnone size-large wp-image-6679" /></a></p>
<p>There are a bunch of code examples, so the easiest way to find them is the filter based on &#8220;emwin&#8221;.  I did this because I knew we had used the Segger emWin Graphics library.  Notice in the picture below there are two emWin examples.  One with a &#8220;world&#8221; beside it and one without.  The world symbol means that it is on the internet and you will need to download it.  You can do that by clicking the world button.  Probably, you will find that your CE223727 EmWin_EInk_Display will have a world beside it and you will need to download it before you can make the project.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-4-53-26-pm/" rel="attachment wp-att-6680"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.53.26-PM.png" alt="" width="626" height="478" class="alignnone size-large wp-image-6680" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.53.26-PM.png 626w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.53.26-PM-600x458.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.53.26-PM-300x229.png 300w" sizes="auto, (max-width: 626px) 100vw, 626px" /></a></p>
<p>Once you click create project it will ask you about the project.  Just click &#8220;next&#8221;</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-4-54-18-pm/" rel="attachment wp-att-6678"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.18-PM.png" alt="" width="626" height="471" class="alignnone size-large wp-image-6678" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.18-PM.png 626w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.18-PM-600x451.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.18-PM-300x226.png 300w" sizes="auto, (max-width: 626px) 100vw, 626px" /></a></p>
<p>Then give your project (and workspace) a name.  I called the workspace &#8220;EPDExample&#8221; and the project &#8220;CE22&#8230;.&#8221;</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-4-54-40-pm/" rel="attachment wp-att-6677"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.40-PM.png" alt="" width="626" height="466" class="alignnone size-large wp-image-6677" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.40-PM.png 626w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.40-PM-600x447.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.54.40-PM-300x223.png 300w" sizes="auto, (max-width: 626px) 100vw, 626px" /></a></p>
<p>After all of that is done you will have a schematic (and all of the other stuff required for the project).</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-4-55-50-pm/" rel="attachment wp-att-6675"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.50-PM-1024x791.png" alt="" width="1024" height="791" class="alignnone size-large wp-image-6675" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.50-PM-1024x791.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.50-PM-600x464.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.50-PM-300x232.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.50-PM-768x593.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.50-PM.png 1126w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>When you click the program button it will ask you which MCU target to program (pick either, it doesnt matter)</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-4-55-28-pm/" rel="attachment wp-att-6676"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.28-PM.png" alt="" width="557" height="394" class="alignnone size-large wp-image-6676" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.28-PM.png 557w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.55.28-PM-300x212.png 300w" sizes="auto, (max-width: 557px) 100vw, 557px" /></a></p>
<p>After a while, your console window should look like this.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-4-59-13-pm/" rel="attachment wp-att-6681"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.59.13-PM-1024x174.png" alt="" width="1024" height="174" class="alignnone size-large wp-image-6681" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.59.13-PM-1024x174.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.59.13-PM-600x102.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.59.13-PM-300x51.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.59.13-PM-768x130.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-4.59.13-PM.png 1198w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And you development kit should do its thing.</p>
<h1><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/img_0429/" rel="attachment wp-att-6682"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0429-1024x632.jpg" alt="" width="1024" height="632" class="alignnone size-large wp-image-6682" srcset="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0429-1024x632.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0429-600x371.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0429-300x185.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0429-768x474.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></h1>
<h1>Explain the PSoC Creator Project</h1>
<p>Now, lets have a look at the project.  Starting on the upper left hand part of the schematic you find that the interface to the EPD is via a SPI.  The SPI slave select is controlled with the Pervasive driver firmware rather than letting the SPI block directly control it.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-12-52-pm/" rel="attachment wp-att-6688"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.12.52-PM.png" alt="" width="436" height="232" class="alignnone size-full wp-image-6688" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.12.52-PM.png 436w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.12.52-PM-300x160.png 300w" sizes="auto, (max-width: 436px) 100vw, 436px" /></a></p>
<p>The SPI is configured to be 16 megabits per second with CPHA=0 and CPOL=0.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-09-40-pm/" rel="attachment wp-att-6686"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.40-PM.png" alt="" width="795" height="892" class="alignnone size-large wp-image-6686" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.40-PM.png 795w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.40-PM-600x673.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.40-PM-267x300.png 267w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.40-PM-768x862.png 768w" sizes="auto, (max-width: 795px) 100vw, 795px" /></a></p>
<p>I didn&#8217;t notice this at first, but in the picture above you can see that the actual speed of the SPI is 8.33 mbs.  That isn&#8217;t 16mbs for sure.  But why the gap?  The first thing to know is that in order for the SPI block to work correctly the input clock must be set at the desired datarate times the oversample.  What is oversample?  That is a scheme to get rid of glitchy-ness in the input signal.  In this case it will take 6 input samples to determine if the input is a 1 or a 0.  (median filter I think).  With this configuration the input clock to the SCB needs to be 16mbs * 6 = 96mhz.</p>
<p>But what is the input clock frequency?  If you click on the dwr-&gt;clocks you will see this screen which shows that the input clock is 50Mhz (the last line highlighted in blue).  Further more you can see that the source clock for the SCB is &#8220;Clk_Peri&#8221;.  When you divide 50mhz source clock rate by 6 oversample you will find that the actual bitrate is 8.33kbs.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-15-57-pm/" rel="attachment wp-att-6691"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.15.57-PM.png" alt="" width="786" height="777" class="alignnone size-large wp-image-6691" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.15.57-PM.png 786w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.15.57-PM-100x100.png 100w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.15.57-PM-600x593.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.15.57-PM-300x297.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.15.57-PM-768x759.png 768w" sizes="auto, (max-width: 786px) 100vw, 786px" /></a></p>
<p>But where does the 50mhz come from?  Well, the clock system is driven by the &#8220;IMO&#8221;.  IMO stands for internal main oscillator and it is a trimmed RC oscillator built into the chip. (thanks Tim).  This oscillator runs into an FLL which up converts it to 100MHz.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-17-08-pm/" rel="attachment wp-att-6689"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.17.08-PM.png" alt="" width="768" height="554" class="alignnone size-full wp-image-6689" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.17.08-PM.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.17.08-PM-600x433.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.17.08-PM-300x216.png 300w" sizes="auto, (max-width: 768px) 100vw, 768px" /></a></p>
<p>That signal is then run into the &#8220;Clk_Peri&#8221; divider which divides it by two to yield a clock of 50MHz.  Which is not all that close to 96MHz&#8230; and means that our SPI runs at the wrong speed.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-16-57-pm/" rel="attachment wp-att-6690"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.16.57-PM.png" alt="" width="779" height="445" class="alignnone size-large wp-image-6690" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.16.57-PM.png 779w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.16.57-PM-600x343.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.16.57-PM-300x171.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.16.57-PM-768x439.png 768w" sizes="auto, (max-width: 779px) 100vw, 779px" /></a></p>
<p>But what does the EPD driver chip actually want?  You can find the documentation for this EPD on the Pervasive <a href="http://www.pervasivedisplays.com/products/271" target="_blank" rel="noopener noreferrer">website</a>.  That web page also has a link to the Product Specification <a href="http://www.pervasivedisplays.com/LiteratureRetrieve.aspx?ID=238025">2.7&#8243; TFT EPD Panel (E2271CS021) Rev.01</a> as well as the driver chip <a href="http://www.pervasivedisplays.com/_literature_220873/COG_Driver_Interface_Timing_for_small_size_G2_V231">COG Driver Interface Timing for small size G2 V231</a></p>
<p>When you look in the timing document you will find that the actual chip can take up to a 20Mhz input clock.  This means that our code example actually updates the screen at 42% (8.33/20) of what it could.  That gives us a chance to make things faster&#8230; which I will do after the port to MTB.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-25-08-pm/" rel="attachment wp-att-6692"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.25.08-PM.png" alt="" width="743" height="207" class="alignnone size-full wp-image-6692" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.25.08-PM.png 743w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.25.08-PM-600x167.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.25.08-PM-300x84.png 300w" sizes="auto, (max-width: 743px) 100vw, 743px" /></a></p>
<p>The next sectin of the schematic has a TCPWM that is configured as a timer.  This has an input clock of 2kHz.</p>
<p>&nbsp;</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-10-00-pm/" rel="attachment wp-att-6685"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.10.00-PM.png" alt="" width="445" height="255" class="alignnone size-large wp-image-6685" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.10.00-PM.png 445w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.10.00-PM-300x172.png 300w" sizes="auto, (max-width: 445px) 100vw, 445px" /></a></p>
<p>And is setup to divide by 2 which will yield a counter that updates every 1ms.  The author of this code example used the TCPWM to time operations inside of the driver (which I will also replace with something better)</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-10-09-pm/" rel="attachment wp-att-6684"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.10.09-PM.png" alt="" width="626" height="476" class="alignnone size-full wp-image-6684" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.10.09-PM.png 626w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.10.09-PM-600x456.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.10.09-PM-300x228.png 300w" sizes="auto, (max-width: 626px) 100vw, 626px" /></a></p>
<p>Lastly there are some GPIOs that control various control pins on the display.  I don&#8217;t really know what all of the pins do, but will sort it out in the next article.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-47-16-pm/" rel="attachment wp-att-6694"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.47.16-PM.png" alt="" width="499" height="639" class="alignnone size-full wp-image-6694" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.47.16-PM.png 499w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.47.16-PM-234x300.png 234w" sizes="auto, (max-width: 499px) 100vw, 499px" /></a></p>
<p>And all of the pins are assigned like this:</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-09-03-pm/" rel="attachment wp-att-6687"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM.png" alt="" width="670" height="297" class="alignnone size-large wp-image-6687" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM.png 670w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM-600x266.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.09.03-PM-300x133.png 300w" sizes="auto, (max-width: 670px) 100vw, 670px" /></a></p>
<h1>Create a new MTB project &amp; Add the Middleware</h1>
<p>It is time to start the project in MTB.  Start up Modus Toolbox 1.1 and select File-&gt;New-&gt;ModusToobox IDE Application    <a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-8-57-36-am/" rel="attachment wp-att-6701"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.57.36-AM-1024x173.png" alt="" width="1024" height="173" class="alignnone size-large wp-image-6701" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.57.36-AM-1024x173.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.57.36-AM-600x101.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.57.36-AM-300x51.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.57.36-AM-768x129.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.57.36-AM.png 1614w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Then select the CY8CKIT-062-BLE Development Kit.  This kit comes with the CY8CKIT-028-EPD EINK Shield that you can see in the pictures above.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-8-58-04-am/" rel="attachment wp-att-6700"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.04-AM-1024x489.png" alt="" width="1024" height="489" class="alignnone size-large wp-image-6700" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.04-AM-1024x489.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.04-AM-600x287.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.04-AM-300x143.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.04-AM-768x367.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.04-AM.png 2030w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>I decide to call my project &#8220;EHKEink&#8221; and I derive my project from the &#8220;EmptyPSoC6App&#8221; template.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-8-58-32-am/" rel="attachment wp-att-6699"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.32-AM-1024x490.png" alt="" width="1024" height="490" class="alignnone size-large wp-image-6699" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.32-AM-1024x490.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.32-AM-600x287.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.32-AM-300x144.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.32-AM-768x367.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.32-AM.png 2032w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Once that is done, Let it rip.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-8-58-51-am/" rel="attachment wp-att-6698"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.51-AM-1024x718.png" alt="" width="1024" height="718" class="alignnone size-large wp-image-6698" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.51-AM-1024x718.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.51-AM-600x421.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.51-AM-300x210.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.51-AM-768x538.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-8.58.51-AM.png 1224w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And you should end up with a screen that looks like this. On the left in the workspace explorer you see the main app project.  In the middle you see the readme file which explains how this project is configured.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-01-13-am-2/" rel="attachment wp-att-6703"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.01.13-AM-1-1024x626.png" alt="" width="1024" height="626" class="alignnone size-large wp-image-6703" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.01.13-AM-1-1024x626.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.01.13-AM-1-600x367.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.01.13-AM-1-300x183.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.01.13-AM-1-768x469.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The next step is to add the &#8220;Middleware&#8221; that we need to make this project work.  You can do this by clicking the select Middleware button from the ModusToolbox quick panel.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-13-02-am/" rel="attachment wp-att-6704"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.13.02-AM.png" alt="" width="708" height="852" class="alignnone size-full wp-image-6704" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.13.02-AM.png 708w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.13.02-AM-600x722.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.13.02-AM-249x300.png 249w" sizes="auto, (max-width: 708px) 100vw, 708px" /></a></p>
<p>For this project we need</p>
<ul>
<li>FreeRTOS</li>
<li>Retarget I/O</li>
<li>Segger emWin Core, OS, no Touch, Soft FP</li>
<li>Segger emWin display driver BitPlains</li>
</ul>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-18-52-am/" rel="attachment wp-att-6708"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.18.52-AM-1024x911.png" alt="" width="1024" height="911" class="alignnone size-large wp-image-6708" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.18.52-AM-1024x911.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.18.52-AM-600x534.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.18.52-AM-300x267.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.18.52-AM-768x683.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.18.52-AM.png 1972w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The middleware selector will bring in all of the drivers you selected into your project.  You can see that it also adds the FreeRTOS configuration file &#8220;FreeRTOSConfig.h&#8221; as well as &#8220;stdio_user.c&#8221; etc.  These files endup in the source folder and are for you to edit.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-19-50-am/" rel="attachment wp-att-6707"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.19.50-AM.png" alt="" width="718" height="788" class="alignnone size-full wp-image-6707" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.19.50-AM.png 718w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.19.50-AM-600x658.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.19.50-AM-273x300.png 273w" sizes="auto, (max-width: 718px) 100vw, 718px" /></a></p>
<p>While I was working on this, I found a bug in the emWin middleware, specifically the the configuration files for BitPlains get included twice.  To fix this you need to change the project properties and remove the path to &#8220;..components/psoc6mw/emWin/code/drivers/BitPlains/config&#8221;.  To do this, select the project in the workspace explorer then right click and select properties.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-22-04-am/" rel="attachment wp-att-6710"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.04-AM-543x1024.png" alt="" width="543" height="1024" class="alignnone size-large wp-image-6710" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.04-AM-543x1024.png 543w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.04-AM-600x1131.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.04-AM-159x300.png 159w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.04-AM-768x1447.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.04-AM.png 916w" sizes="auto, (max-width: 543px) 100vw, 543px" /></a></p>
<p>Then select &#8220;C/C++ General &#8211;&gt; Paths and Symbols&#8221;.  Select the &#8220;&#8230;BitPlains/config&#8221; path and click &#8220;Delete&#8221;</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-22-43-am/" rel="attachment wp-att-6709"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.43-AM-1024x541.png" alt="" width="1024" height="541" class="alignnone size-large wp-image-6709" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.43-AM-1024x541.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.43-AM-600x317.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.43-AM-300x158.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.22.43-AM-768x405.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Configure the device in MTB</h1>
<p>Modus Toolbox does not have a &#8220;schematic&#8221; or a &#8220;dwr&#8221; like PSoC Creator.  In order to achieve the same functionality we built the &#8220;Configurator&#8221;.  This tool will let you setup all of the peripherals in your project.  To run it select &#8220;Configure Device&#8221; in the MTB Quick Panel.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-29-54-am/" rel="attachment wp-att-6712"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.29.54-AM.png" alt="" width="714" height="938" class="alignnone size-full wp-image-6712" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.29.54-AM.png 714w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.29.54-AM-600x788.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.29.54-AM-228x300.png 228w" sizes="auto, (max-width: 714px) 100vw, 714px" /></a></p>
<p>Remember from the PSoC Creator Schematic we need to have:</p>
<ul>
<li>A bunch of pins</li>
<li>A SPI</li>
<li>A Timer</li>
<li>Plus I want a UART to connect to standard I/O.</li>
</ul>
<p>First, click on the &#8220;Pins&#8221; tab.  This lets you set all of the configuration information for each of the pins on the chip.  I will go one by one enabling the pins and setting them as digital inputs or output.  I am going to give all of the pins that exact same names that they had in the PSoC Creator Project because I know the author of that project used PDL.  When you give a pin a name in the configurator it will generate #defines or c structures based on the name.  This will make the source code the original PSoC Creator author wrote almost exactly compatible with MTB.</p>
<p>Here is an example of the first output pin which is P0[2] and is named CY_EINK_DispIoEn.  For the output pins you need to do four things.</p>
<ol>
<li>Enable the checkbox next to the pin name. (in this case P0[2])</li>
<li>Give the pin a name (CY_EINK_DispIoEn)</li>
<li>Set the drive mode (Strong Drive, Input buffer off)</li>
<li>Set the initial state of the pin (High (1))</li>
</ol>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-48-55-am/" rel="attachment wp-att-6716"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.48.55-AM-1024x889.png" alt="" width="1024" height="889" class="alignnone size-large wp-image-6716" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.48.55-AM-1024x889.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.48.55-AM-600x521.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.48.55-AM-300x260.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.48.55-AM-768x667.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.48.55-AM.png 1726w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now, you need to go one by one turning on all of the output pins (Im not showing you screen shots of all of them)</p>
<p>There are two input pins for this project SW2 P0[4] and CY_EINK_DispBusy P5[3].  For these pins I will:</p>
<ol>
<li>Enable the pin checkbox</li>
<li>Give the pin a name (in this case SW2)</li>
<li>Resistive Pull-Up, Input buffer on.  Note for P5[3] the pullup resistor is not needed</li>
</ol>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-52-01-am/" rel="attachment wp-att-6718"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.52.01-AM-1024x894.png" alt="" width="1024" height="894" class="alignnone size-large wp-image-6718" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.52.01-AM-1024x894.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.52.01-AM-600x524.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.52.01-AM-300x262.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.52.01-AM-768x670.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.52.01-AM.png 1698w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now that the digital pins are configured, you can setup the STDIO Uart.  This will be used to send debugging messages to the console Uart which is attached to your computer via a USB&lt;-&gt;UART bridge in KitProg 3.</p>
<p>Start by enabling SCB5 and giving it the name &#8220;UART&#8221;.  Make sure that the baud rate is set to 115200 and the rest to 8n1<a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-57-26-am/" rel="attachment wp-att-6720"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.57.26-AM-820x1024.png" alt="" width="820" height="1024" class="alignnone size-large wp-image-6720" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.57.26-AM-820x1024.png 820w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.57.26-AM-600x749.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.57.26-AM-240x300.png 240w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.57.26-AM-768x959.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.57.26-AM.png 1190w" sizes="auto, (max-width: 820px) 100vw, 820px" /></a></p>
<p>Scroll down the window and pick out the RX and TX Pins plus the clock (any of the 8-bit clock dividers will do.  In this case I chose Divider 0)</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-9-58-51-am/" rel="attachment wp-att-6721"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.58.51-AM-1024x657.png" alt="" width="1024" height="657" class="alignnone size-large wp-image-6721" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.58.51-AM-1024x657.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.58.51-AM-600x385.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.58.51-AM-300x192.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.58.51-AM-768x493.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-9.58.51-AM.png 1244w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now, you need to setup the SPI.  To do this turn on SCB 6, set it to SPI, give it the name &#8220;CY_EINK_SPIM&#8221;, set it to &#8220;Master&#8221;, fix the data rate to 1000<a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-10-01-18-am/" rel="attachment wp-att-6722"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.01.18-AM-1024x993.png" alt="" width="1024" height="993" class="alignnone size-large wp-image-6722" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.01.18-AM-1024x993.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.01.18-AM-600x582.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.01.18-AM-300x291.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.01.18-AM-768x745.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.01.18-AM.png 1524w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Then scroll down to the &#8220;Connections&#8221; section and assign the pins</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-3-48-22-pm/" rel="attachment wp-att-6744"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.48.22-PM-1024x588.png" alt="" width="1024" height="588" class="alignnone size-large wp-image-6744" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.48.22-PM-1024x588.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.48.22-PM-600x345.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.48.22-PM-300x172.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.48.22-PM-768x441.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.48.22-PM.png 1146w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The last bit of hardware we need is a timer with a 1000kHz input clock, in other words a millisecond timer.  To do this start by enabling TCPWM[1] 16-bit counter.  Call it &#8220;CY_EINK_Timer&#8221; which was the same name as the PSoC Creator project.  Then setup</p>
<ul>
<li>As a &#8220;Timer Counter&#8221;.</li>
<li>One shot</li>
<li>Up count</li>
<li>Period is 65535 (aka the max)</li>
<li>And pick &#8220;Clock signal&#8221; as 16 bit Divider</li>
</ul>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-12-26-51-pm/" rel="attachment wp-att-6736"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.26.51-PM-1024x858.png" alt="" width="1024" height="858" class="alignnone size-large wp-image-6736" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.26.51-PM-1024x858.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.26.51-PM-600x503.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.26.51-PM-300x251.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.26.51-PM-768x644.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.26.51-PM.png 1592w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Given that we want it to count milliseconds and the input has a 128 bit pre-divider&#8230; we need for the input clock to be setup to 128khz.  Click on &#8220;Peripheral clocks&#8221; then select &#8220;16 Bit Divider 0&#8221;.  Notice that the input frequency is 72Mhz and we need 128Khz&#8230; to get this a divider of 562 is required.  72mhz/128khz = 562</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-12-35-10-pm/" rel="attachment wp-att-6737"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.35.10-PM-1024x901.png" alt="" width="1024" height="901" class="alignnone size-large wp-image-6737" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.35.10-PM-1024x901.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.35.10-PM-600x528.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.35.10-PM-300x264.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.35.10-PM-768x676.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-12.35.10-PM.png 1412w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Setup FreeRTOS and Standard I/O</h1>
<p>The next step is to setup the &#8220;plumbing&#8221;.  In this projet we are using FreeRTOS and Standard I/O. To configure FreeRTOS just edit the &#8220;FreeRTOSConfig.h&#8221; and remove the &#8220;warning&#8221;</p>
<pre class="start-line:45 EnlighterJSRAW" data-enlighter-language="c"">#warning This is a template. Modify it according to your project and remove this line. 
</pre>
<p>Enable mutexes on line 57</p>
<pre class="start-line:57 EnlighterJSRAW" data-enlighter-language="c"">#define configUSE_MUTEXES                       1
</pre>
<p>Make the heap bigger on line 70</p>
<pre class="start-line:70 EnlighterJSRAW" data-enlighter-language="c"">#define configTOTAL_HEAP_SIZE                   1024*48
</pre>
<p>Change the memory scheme to 4 on line 194</p>
<pre class="start-line:194 EnlighterJSRAW" data-enlighter-language="c"">#define configHEAP_ALLOCATION_SCHEME                (HEAP_ALLOCATION_TYPE4)
</pre>
<p>To enable the UART to be used for Standard I/O, edit &#8220;stdio_user.h&#8221; and add the includes for &#8220;cycfg.h&#8221;.  Then update the output and input Uart to be &#8220;UART_HW&#8221; (which is the name you gave it in the configurator)</p>
<pre class="start-line:172 EnlighterJSRAW" data-enlighter-language="c"">#include "cycfg.h"
/* Must remain uncommented to use this utility */
#define IO_STDOUT_ENABLE
#define IO_STDIN_ENABLE
#define IO_STDOUT_UART      UART_HW
#define IO_STDIN_UART       UART_HW
</pre>
<p>Now make a few edits to main.c to</p>
<ul>
<li>Add includes for the configuration, rtos and standard i/o</li>
<li>Create a context for the UART</li>
<li>Create a blinking LED Task</li>
<li>In main start the UART and start the blinking LED task.</li>
</ul>
<pre class="start-line:27 EnlighterJSRAW" data-enlighter-language="c"">#include "cy_device_headers.h"
#include "cycfg.h"
#include "FreeRTOS.h"
#include "task.h"
#include &lt;stdio.h&gt;

cy_stc_scb_uart_context_t UART_context;

void blinkTask(void *arg)
{
	(void)arg;

    for(;;)
    {
    		vTaskDelay(500);
    		Cy_GPIO_Inv(LED_RED_PORT,LED_RED_PIN);
    		printf("blink\n");
    }
}
int main(void)
{
    init_cycfg_all();
    __enable_irq();

    Cy_SCB_UART_Init(UART_HW,&amp;UART_config,&amp;UART_context);
	Cy_SCB_UART_Enable(UART_HW);

  	xTaskCreate( blinkTask,"blinkTask", configMINIMAL_STACK_SIZE,  0,  1, 0  );
  	vTaskStartScheduler();
  	while(1);// Will never get here
}
</pre>
<p>As I edited the code I notice that it can&#8217;t find &#8220;LED_RED&#8221; which made me realize that I forgot to add the LED_RED attached to P0[3] in the configuration.  So, I go back and update P0[3] to be LED_RED as strong drive digital output.</p>
<p>Finally just to make sure that it is all working lets program the kit.  When I press &#8220;EHKEink Program&#8221; form the quickpanel&#8230;<a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-10-45-20-am/" rel="attachment wp-att-6725"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.45.20-AM.png" alt="" width="710" height="880" class="alignnone size-full wp-image-6725" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.45.20-AM.png 710w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.45.20-AM-600x744.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.45.20-AM-242x300.png 242w" sizes="auto, (max-width: 710px) 100vw, 710px" /></a></p>
<p>I get this message in the console.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-10-46-38-am/" rel="attachment wp-att-6726"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.46.38-AM-1024x493.png" alt="" width="1024" height="493" class="alignnone size-large wp-image-6726" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.46.38-AM-1024x493.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.46.38-AM-600x289.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.46.38-AM-300x145.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.46.38-AM-768x370.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.46.38-AM.png 1100w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>But how can that be?  I have my kit plugged in?  In order to program your kit using Modus you need &#8220;KitProg3&#8221;.  PSoC Creator can program you kit with KitProg3 only if it is in the CMSIS-DAP HID mode.  To switch you development kit to KitProg3, you can use the program &#8220;fw-loader&#8221; which comes with MTB.  You can see what firmware you have by running &#8220;fw-loader &#8211;device-list&#8221;.  To change to KitProg 2 run &#8220;fw-loader &#8211;update-kp2&#8221; and to update to KitProg3 run &#8220;fw-loader &#8211;update-kp3&#8221;</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-14-at-5-35-26-pm/" rel="attachment wp-att-6693"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.35.26-PM.png" alt="" width="980" height="523" class="alignnone size-full wp-image-6693" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.35.26-PM.png 980w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.35.26-PM-600x320.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.35.26-PM-300x160.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-5.35.26-PM-768x410.png 768w" sizes="auto, (max-width: 980px) 100vw, 980px" /></a></p>
<p>Now when i program I get both the LED blinking and the console printing blink.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-10-37-24-am/" rel="attachment wp-att-6728"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.37.24-AM-1024x700.png" alt="" width="1024" height="700" class="alignnone size-large wp-image-6728" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.37.24-AM-1024x700.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.37.24-AM-600x410.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.37.24-AM-300x205.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.37.24-AM-768x525.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.37.24-AM.png 1190w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Copy the files into the MTB project</h1>
<p>Next, I want to bring over the drivers from the PSoC Creator project.  They reside in folder called &#8220;eInk Library&#8221; inside of the PSoC Creator project.  You can copy them by navigating to the PSoC Creator workspace, then typing ctrl-c in the File Explorer, then clicking the &#8220;Source&#8221; directory in your Eclipse WorkSpace explorer and typing ctrl-v<a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-10-56-36-am/" rel="attachment wp-att-6730"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.56.36-AM-1024x596.png" alt="" width="1024" height="596" class="alignnone size-large wp-image-6730" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.56.36-AM-1024x596.png 1024w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.56.36-AM-600x349.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.56.36-AM-300x174.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-10.56.36-AM-768x447.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You will also need the four files &#8220;GUIConf.c&#8221;, &#8220;GUIConf.h&#8221;, &#8220;LCDConf.h&#8221; and &#8220;LCDConf.c&#8221;.  Copy and paste them into the emWin_config directory.</p>
<p>For this project I am going to use the code that existed in &#8220;main.c&#8221; from the original PSoC Creator project.  But I want it to be a task (and a few other changes).  To facilitate things, I will copy it as well. Then rename it to eInkTask.c.  And finally, the file &#8220;Cypress Logo Full Color_png1bpp.c&#8221; needs to be copied as well.</p>
<p>After all of those copies you should have your project looking something like this:</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-3-58-04-pm/" rel="attachment wp-att-6745"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.58.04-PM.png" alt="" width="710" height="820" class="alignnone size-full wp-image-6745" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.58.04-PM.png 710w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.58.04-PM-600x693.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-3.58.04-PM-260x300.png 260w" sizes="auto, (max-width: 710px) 100vw, 710px" /></a></p>
<h1>Port the Drivers and eInkTask</h1>
<p>Now we need to fix all of the driver code.  Big picture you will need to take the following actions.</p>
<ul>
<li>Update the Project settings to include the new folders (emWin_config and emWin Library)</li>
<li>Replace the PSoC Creator #include &lt;project.h&gt; with MTB #include &#8220;cycfg.h&#8221;</li>
<li>Update the files to have #include &#8220;FreeRTOS.h&#8221; and &#8220;task.h&#8221; where appropriate</li>
<li>Replace all of the CyDelay&#8217;s with vTaskDelays</li>
<li>Fix the old PSoC Creator component calls for the timer with PDL calls</li>
</ul>
<p>First go to the project settings (remember, click on the project then select properties).  Then pick &#8220;C/C++ Build Settings&#8221; then &#8220;GNU ARM Cross C Compiler&#8221; and &#8220;includes&#8221;  Press the little green &#8220;+&#8221; to add the new directories</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-11-29-00-am/" rel="attachment wp-att-6732"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.29.00-AM-1003x1024.png" alt="" width="1003" height="1024" class="alignnone size-large wp-image-6732" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.29.00-AM-1003x1024.png 1003w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.29.00-AM-600x612.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.29.00-AM-294x300.png 294w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.29.00-AM-768x784.png 768w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.29.00-AM.png 1546w" sizes="auto, (max-width: 1003px) 100vw, 1003px" /></a></p>
<p>You can select both directories at once.</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/screen-shot-2019-04-15-at-11-28-31-am/" rel="attachment wp-att-6733"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.28.31-AM.png" alt="" width="794" height="782" class="alignnone size-large wp-image-6733" srcset="https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.28.31-AM.png 794w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.28.31-AM-600x591.png 600w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.28.31-AM-300x295.png 300w, https://iotexpert.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-15-at-11.28.31-AM-768x756.png 768w" sizes="auto, (max-width: 794px) 100vw, 794px" /></a></p>
<p>Next edit  <strong>eInkTask.c</strong></p>
<p>Update #include &#8220;project.h&#8221; to be #include &#8220;cycfg.h&#8221; on line 59.  Add &#8220;FreeRTOS.h&#8221; and &#8220;task.h&#8221; to the includes.</p>
<pre class="start-line:59 EnlighterJSRAW" data-enlighter-language="c"">#include "cycfg.h"
#include "GUI.h"
#include "pervasive_eink_hardware_driver.h"
#include "cy_eink_library.h"
#include "LCDConf.h"
#include "FreeRTOS.h"
#include "task.h"
#include &lt;stdio.h&gt;</pre>
<p>Find and replace &#8220;CyDelay&#8221; with &#8220;vTaskDelay&#8221;</p>
<p>Update the PSoC Creator component call  _Read with the pdl calls Cy_GPIO_Read on line 661</p>
<pre class="start-line:661 EnlighterJSRAW" data-enlighter-language="c"">void WaitforSwitchPressAndRelease(void)
{
    /* Wait for SW2 to be pressed */
    while(Cy_GPIO_Read(SW2_PORT,SW2_PIN) != 0);
    
    /* Wait for SW2 to be released */
    while(Cy_GPIO_Read(SW2_PORT,SW2_PIN) == 0);
}</pre>
<p>Update the &#8220;int main(void)&#8221; to be &#8220;void eInkTask(void *arg)&#8221; on line 687</p>
<pre class="start-line:687 EnlighterJSRAW" data-enlighter-language="c" ">void eInkTask(void *arg)
{
	(void)arg;</pre>
<p>Remove &#8221; __enable_irq(); /* Enable global interrupts. */&#8221; from the old main on line 695.</p>
<p>In the file <strong>cy_eink_psoc_interface.h</strong></p>
<p>Update the #include &lt;project.h&gt; to be #include &#8220;cycfg.h&#8221; on line 59.</p>
<p>In the file <strong>cy_eink_psoc_interface.c</strong></p>
<p>Create a context for the SPIM by adding on line 58:</p>
<pre class="start-line:58 EnlighterJSRAW" data-enlighter-language="c" ">cy_stc_scb_spi_context_t CY_EINK_SPIM_context;
</pre>
<p>The three timer functions in this file use the old PSoC Creator component timer interface APIs rather than the PDL interface.  So you will need to change Cy_EINK_TimerInit, Cy_EINK_GetTimeTick and Cy_EINK_TimerStop to use PDL.</p>
<p>Here is Cy_EINK_TimerInit</p>
<pre class="start-line:76 EnlighterJSRAW" data-enlighter-language="c" ">void Cy_EINK_TimerInit(void)
{   
    /* Clear the counter value and the counter variable */
    //CY_EINK_Timer_SetCounter(0);

    Cy_TCPWM_Counter_Init (CY_EINK_Timer_HW, CY_EINK_Timer_NUM, &amp;CY_EINK_Timer_config);
    Cy_TCPWM_Counter_SetCounter	(	CY_EINK_Timer_HW, CY_EINK_Timer_NUM,0);
    
    Cy_TCPWM_Enable_Multiple(	CY_EINK_Timer_HW,CY_EINK_Timer_MASK);
    /* Initialize the Timer */
    //CY_EINK_Timer_Start();
    Cy_TCPWM_TriggerStart	(	CY_EINK_Timer_HW,CY_EINK_Timer_MASK);
}
</pre>
<p>And Cy_EINK_GetTimeTick</p>
<pre class="start-line:106 EnlighterJSRAW" data-enlighter-language="c"">uint32_t Cy_EINK_GetTimeTick(void)
{
    /* Variable used to store the time tick */
    uint32_t timingCount;
    
    /* Read the current time tick from the E-INK Timer */
    //timingCount = CY_EINK_Timer_GetCounter();
    timingCount = Cy_TCPWM_Counter_GetCounter	(CY_EINK_Timer_HW, CY_EINK_Timer_NUM);


    /* Return the current value of time tick */
    return(timingCount);
}</pre>
<p>And Cy_EINK_TimerStop</p>
<pre class="start-line:136 EnlighterJSRAW" data-enlighter-language="c"">void Cy_EINK_TimerStop(void)
{
    /* Stop the E-INK Timer */
    //CY_EINK_Timer_Disable();
	Cy_TCPWM_Counter_Disable(CY_EINK_Timer_HW, CY_EINK_Timer_NUM);

}</pre>
<p>In  the file LCDConf.h change the include to stdint.h and make the type uint8_t instead of uint8</p>
<pre class="start-line:48 EnlighterJSRAW" data-enlighter-language="c"">#include  &lt;stdint.h&gt;
    
void LCD_CopyDisplayBuffer(uint8_t * destination, int count);</pre>
<p>In the file <strong>LCDConf.c</strong> remove the #include &#8220;<span>syslib</span>/cy_syslib.h&#8221; (I have no idea why it is/was there) and then add &#8220;<span>#include</span><span> </span>&lt;stdint.h&gt;&#8221;  On line 219 change &#8220;uint8&#8221; to be &#8220;uint8_t&#8221;</p>
<pre class="start-line:219 EnlighterJSRAW" data-enlighter-language="c" ">void LCD_CopyDisplayBuffer(uint8_t * destination, int count)
</pre>
<p>In the file <strong>cy_eink_fonts.h</strong> change the &#8220;#include &lt;project.h&gt;&#8221; to be</p>
<pre class="start-line:56 EnlighterJSRAW" data-enlighter-language="c" ">#include &lt;stdint.h&gt;
#include &lt;stdbool.h&gt;</pre>
<p>In <strong>main.c</strong> add an external reference to the eInkTask on line 36 (yes this is really ugly Alan)</p>
<pre class="start-line:36 EnlighterJSRAW" data-enlighter-language="c" ">extern void eInkTask(void *);
</pre>
<p>And start the eInkTask on line 58.  Notice that I put in 10K for the stacksize&#8230; but I dont actually know how much it takes.</p>
<pre class="start-line:58 EnlighterJSRAW" data-enlighter-language="c"">  	xTaskCreate( eInkTask,"eInkTask", 1024*10,  0,  1, 0  );
</pre>
<h1>Program &amp; Test the MTB Project</h1>
<p>When you program the development kit you should have</p>
<ol>
<li>A blinking RED LED</li>
<li>The ability to scroll through a bunch of screens using the SW2 button.</li>
</ol>
<p>Here is a picture</p>
<p><a href="https://iotexpert.com/2019/04/15/cy8ckit-028-epd-and-modus-toolbox-1-1/img_0433/" rel="attachment wp-att-6747"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0433-1024x608.jpg" alt="" width="1024" height="608" class="alignnone size-large wp-image-6747" srcset="https://iotexpert.com/wp-content/uploads/2019/04/IMG_0433-1024x608.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0433-600x356.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0433-300x178.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/04/IMG_0433-768x456.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In the next article I will:</p>
<ol>
<li>Speed up the SPI</li>
<li>Get rid of the hardware timer</li>
<li>Explain more about the EINK.</li>
</ol>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/cy8ckit-028-epd-and-modus-toolbox-1-1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Bosch BMI160 w/PSoC 6 CY8CKIT-028-EPD</title>
		<link>https://iotexpert.com/bosch-bmi160-psoc-6-cy8ckit-028-epd/</link>
					<comments>https://iotexpert.com/bosch-bmi160-psoc-6-cy8ckit-028-epd/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Tue, 06 Feb 2018 13:00:04 +0000</pubDate>
				<category><![CDATA[CY8CKIT-028-EPD]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=4946</guid>

					<description><![CDATA[Summary I have been working on a bunch of PSoC 6 projects in preparation for some new videos and for use at Embedded World.  For one of those project I need a motion sensitive remote control&#8230; and conveniently enough we put a Bosch BMI160 motion sensor onto the new CY8CKIT-028-EPD shield that comes with the [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>I have been working on a bunch of PSoC 6 projects in preparation for some new videos and for use at Embedded World.  For one of those project I need a motion sensitive remote control&#8230; and conveniently enough we put a <a href="https://www.bosch-sensortec.com/bst/products/all_products/bmi160" target="_blank" rel="noopener">Bosch BMI160</a> motion sensor onto the new CY8CKIT-028-EPD shield that comes with the CY8CKIT-062-BLE development kit.</p>
<p>In this article I will show you how to make a complete test system using PSoC 6 to talk to the BMI160.  The steps are:</p>
<ol>
<li>Clone the Bosch BMI160 Driver Library</li>
<li>Create a new PSoC 6 project &amp; add the driver library</li>
<li>Create the HAL for the Bosch Driver</li>
<li>Create the main firmware and test</li>
</ol>
<h1>Clone the Bosch BMI160 Driver Library</h1>
<p>When I started this, I knew that the board had a motion sensor but I didnt know what kind.  I assumed that it was an I2C based sensor, so I attached the bridge control panel and probed the I2C bus.  But this is what it said:</p>
<p><a href="https://iotexpert.com/?attachment_id=4951" rel="attachment wp-att-4951"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.35-AM-1024x818.png" alt="Bridge Control Panel" width="1024" height="818" class="alignnone wp-image-4951 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.35-AM-1024x818.png 1024w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.35-AM-600x479.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.35-AM-300x240.png 300w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.35-AM-768x614.png 768w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.35-AM.png 1692w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>So&#8230; what the hell?  Then I looked at the board to try to figure out what was going on&#8230; and low and behold&#8230; the board that I had was a prototype that was done before we added the motion sensor.  Here it is:</p>
<p><a href="https://iotexpert.com/?attachment_id=4979" rel="attachment wp-att-4979"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/IMG_5716-e1517838436841-1024x768.jpg" alt="" width="1024" height="768" class="alignnone wp-image-4979 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/02/IMG_5716-e1517838436841-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/02/IMG_5716-e1517838436841-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/02/IMG_5716-e1517838436841-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/02/IMG_5716-e1517838436841-768x576.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And here is a board with the sensor on it.</p>
<p><a href="https://iotexpert.com/?attachment_id=4950" rel="attachment wp-att-4950"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/IMG_5692-e1517672737625-1024x768.jpg" alt="CY8CKIT-028-EPD with Bosch BMI160" width="1024" height="768" class="alignnone wp-image-4950 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/02/IMG_5692-e1517672737625-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/02/IMG_5692-e1517672737625-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/02/IMG_5692-e1517672737625-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/02/IMG_5692-e1517672737625-768x576.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>When I plug in that board and test it with the Bridge Control Panel I get:</p>
<p><a href="https://iotexpert.com/?attachment_id=4952" rel="attachment wp-att-4952"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.06-AM-1024x818.png" alt="" width="1024" height="818" class="alignnone wp-image-4952 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.06-AM-1024x818.png 1024w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.06-AM-600x479.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.06-AM-300x240.png 300w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.06-AM-768x613.png 768w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.47.06-AM.png 1696w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The next thing that I did was look at the schematics.  OK, you can see that the Inertial Measurement Unit (IMU) is a BMI160 that is connected to the I2C bus.  The other cool thing is that the devkit team hooked up the two interrupt lines.  These lines are typically used for the IMU to signal the PSoC 6 that something has happened (like maybe the user started moving).</p>
<p><a href="https://iotexpert.com/?attachment_id=4947" rel="attachment wp-att-4947"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.31.56-AM-897x1024.png" alt="" width="897" height="1024" class="alignnone wp-image-4947 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.31.56-AM-897x1024.png 897w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.31.56-AM-600x685.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.31.56-AM-263x300.png 263w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.31.56-AM-768x877.png 768w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.31.56-AM.png 902w" sizes="auto, (max-width: 897px) 100vw, 897px" /></a></p>
<p>After looking at the schematics, the next step was to look at the BMI160 <a href="https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMI160-DS000-07.pdf" target="_blank" rel="noopener">datasheet</a> and try to figure out how to interface with the device. Typically these devices have a boatload of registers with a mind boggling number of bit fields.  This is always the un-fun part of the process.  But this time when I went to the BMI160 device page on Bosch&#8217;s website, there was a button that says &#8220;Documents and Drivers&#8221; and when you click it, there is a link to GitHub with a <a href="https://github.com/BoschSensortec/BMI160_driver" target="_blank" rel="noopener">BMI160 driver</a>.  Score!</p>
<p><a href="https://iotexpert.com/?attachment_id=4948" rel="attachment wp-att-4948"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.40.22-AM-1024x792.png" alt="" width="1024" height="792" class="alignnone wp-image-4948 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.40.22-AM-1024x792.png 1024w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.40.22-AM-600x464.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.40.22-AM-300x232.png 300w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.40.22-AM-768x594.png 768w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-10.40.22-AM.png 1712w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>To make this work you just &#8220;git clone <span>git@github.com:BoschSensortec/BMI160_driver.git&#8221;</span></p>
<h1>Create New PSoC 6 project &amp; with Bosch BMI160 driver library</h1>
<p>So, lets get on with testing it.  First create a new PSoC 63 Project</p>
<p><a href="https://iotexpert.com/?attachment_id=4959" rel="attachment wp-att-4959"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.18.53-PM.png" alt="" width="623" height="466" class="alignnone wp-image-4959 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.18.53-PM.png 623w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.18.53-PM-600x449.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.18.53-PM-300x224.png 300w" sizes="auto, (max-width: 623px) 100vw, 623px" /></a></p>
<p>Use a blank schematic</p>
<p><a href="https://iotexpert.com/?attachment_id=4958" rel="attachment wp-att-4958"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.07-PM.png" alt="" width="624" height="465" class="alignnone wp-image-4958 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.07-PM.png 624w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.07-PM-600x447.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.07-PM-300x224.png 300w" sizes="auto, (max-width: 624px) 100vw, 624px" /></a></p>
<p>Give it a name</p>
<p><a href="https://iotexpert.com/?attachment_id=4957" rel="attachment wp-att-4957"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.54-PM.png" alt="" width="622" height="468" class="alignnone wp-image-4957 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.54-PM.png 622w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.54-PM-600x451.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.19.54-PM-300x226.png 300w" sizes="auto, (max-width: 622px) 100vw, 622px" /></a></p>
<p>Add the Retarget I/O and FreeRTOS (from the build settings menu)</p>
<p><a href="https://iotexpert.com/?attachment_id=4956" rel="attachment wp-att-4956"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.20.17-PM.png" alt="" width="698" height="667" class="alignnone wp-image-4956 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.20.17-PM.png 698w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.20.17-PM-600x573.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.20.17-PM-300x287.png 300w" sizes="auto, (max-width: 698px) 100vw, 698px" /></a></p>
<p>Add a UART and an I2C Master</p>
<p><a href="https://iotexpert.com/?attachment_id=4955" rel="attachment wp-att-4955"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.20.46-PM.png" alt="" width="516" height="454" class="alignnone wp-image-4955 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.20.46-PM.png 516w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.20.46-PM-300x264.png 300w" sizes="auto, (max-width: 516px) 100vw, 516px" /></a></p>
<p>To get the I2C to be a master you need to double click it and change it into a master</p>
<p><a href="https://iotexpert.com/?attachment_id=4960" rel="attachment wp-att-4960"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.25.19-PM.png" alt="" width="628" height="478" class="alignnone wp-image-4960 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.25.19-PM.png 628w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.25.19-PM-600x457.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.25.19-PM-300x228.png 300w" sizes="auto, (max-width: 628px) 100vw, 628px" /></a></p>
<p>Then assign the pins</p>
<p><a href="https://iotexpert.com/?attachment_id=4954" rel="attachment wp-att-4954"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.21.08-PM.png" alt="" width="1108" height="844" class="alignnone wp-image-4954 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.21.08-PM.png 1108w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.21.08-PM-600x457.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.21.08-PM-300x229.png 300w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.21.08-PM-768x585.png 768w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.21.08-PM-1024x780.png 1024w" sizes="auto, (max-width: 1108px) 100vw, 1108px" /></a></p>
<p>Run &#8220;Build -&gt; Generate Application&#8221; to get all of the PDL firmware you need.</p>
<p>Edit stdio_user.h to use the UART (scan down the stdio_user.h to find the right place)</p>
<pre class="lang:c decode:true">#include "project.h"
/* Must remain uncommented to use this utility */
#define IO_STDOUT_ENABLE
#define IO_STDIN_ENABLE
#define IO_STDOUT_UART      UART_1_HW
#define IO_STDIN_UART       UART_1_HW</pre>
<p>Add the &#8220;BMI_driver&#8221; directory to the include path of the CM4 project.  (To get to this menu right click the project and pick &#8220;build settings&#8221;)</p>
<p><a href="https://iotexpert.com/?attachment_id=4961" rel="attachment wp-att-4961"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.31.53-PM.png" alt="" width="1052" height="732" class="alignnone wp-image-4961 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.31.53-PM.png 1052w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.31.53-PM-600x417.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.31.53-PM-300x209.png 300w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.31.53-PM-768x534.png 768w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.31.53-PM-1024x713.png 1024w" sizes="auto, (max-width: 1052px) 100vw, 1052px" /></a></p>
<p>Add the Bosch Driver files to the project</p>
<p><a href="https://iotexpert.com/?attachment_id=4963" rel="attachment wp-att-4963"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.09-PM.png" alt="" width="442" height="291" class="alignnone wp-image-4963 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.09-PM.png 442w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.09-PM-300x198.png 300w" sizes="auto, (max-width: 442px) 100vw, 442px" /></a></p>
<p>&nbsp;</p>
<p><a href="https://iotexpert.com/?attachment_id=4962" rel="attachment wp-att-4962"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.28-PM.png" alt="" width="957" height="866" class="alignnone wp-image-4962 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.28-PM.png 957w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.28-PM-600x543.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.28-PM-300x271.png 300w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.44.28-PM-768x695.png 768w" sizes="auto, (max-width: 957px) 100vw, 957px" /></a></p>
<h1>Create the HAL for the Bosch driver</h1>
<p>It is simple to use the Bosch driver.  All you need to do is update the HAL.</p>
<ol>
<li>Provide a function to write I2C registers</li>
<li>Provide a function to read I2C registers</li>
<li>Provide a function to delay for a specified number of milliseconds</li>
<li>Create a structure to hold initialization information and function pointers</li>
</ol>
<p>This device implements what Cypress calls the &#8220;EZI2C&#8221; protocol which is also known as an I2C EEPROM protocol.  The device is organized as an array of registers.  Each register has an address from 0-&gt;0xFF (a single byte of addresses).  To write to a register you need to</p>
<ol>
<li>Send an I2C Start</li>
<li>Send the 7-bit I2C address</li>
<li>Send a write bit (aka a 0)</li>
<li>Send the register address you want to write to (dont confuse I2C address with the internal BMI160 address)</li>
<li>Send the 8-bit value that you want to write</li>
<li>Send a stop</li>
</ol>
<p>A cool thing with EZI2C is that it keeps track of the address, and automatically increments the register address each time you write.  This means you can write a sequence of address without having to do a complete transaction for each address.</p>
<p>Given that introduction the write function is simple:</p>
<pre class="lang:c decode:true " title="I2C Write Function">static int8_t BMI160BurstWrite(uint8_t dev_addr, uint8_t reg_addr,uint8_t *data, uint16_t len)
{
    
    Cy_SCB_I2C_MasterSendStart(I2C_1_HW,dev_addr,CY_SCB_I2C_WRITE_XFER,0,&amp;I2C_1_context);
    Cy_SCB_I2C_MasterWriteByte(I2C_1_HW,reg_addr,0,&amp;I2C_1_context);
    for(int i = 0;i&lt;len; i++)
    { 
        Cy_SCB_I2C_MasterWriteByte(I2C_1_HW,data[i],0,&amp;I2C_1_context);
    }
    
    Cy_SCB_I2C_MasterSendStop(I2C_1_HW,0,&amp;I2C_1_context);
    
    return 0;
}</pre>
<p>In order to read you do a similar transaction to write.  Specifically the steps are:</p>
<ol>
<li>Send an I2C Start</li>
<li>Send the 7-bit I2c address</li>
<li>Send a WRITE bit aka 0</li>
<li>Send the address of the register you want to read</li>
<li>Send an I2C re-start</li>
<li>Read a byte</li>
<li>Send a NAK</li>
<li>Send a stop</li>
</ol>
<p>The read transaction is similar to the write in that you can continue to read sequential bytes by sending an ACK.  The last byte you read should be NAK-ed to tell the remote device that you are done reading. Given that the code is also straight forward.</p>
<pre class="lang:c decode:true " title="I2C Read Function">// This function supports the BMP180 library and read I2C Registers
static int8_t BMI160BurstRead(uint8_t dev_addr, uint8_t reg_addr,uint8_t *data, uint16_t len)
{
    
    Cy_SCB_I2C_MasterSendStart(I2C_1_HW,dev_addr,CY_SCB_I2C_WRITE_XFER,0,&amp;I2C_1_context);
    Cy_SCB_I2C_MasterWriteByte(I2C_1_HW,reg_addr,0,&amp;I2C_1_context);
    Cy_SCB_I2C_MasterSendReStart(I2C_1_HW,dev_addr,CY_SCB_I2C_READ_XFER,0,&amp;I2C_1_context);
    for(int i = 0;i&lt;len-1; i++)
    {
        Cy_SCB_I2C_MasterReadByte(I2C_1_HW,CY_SCB_I2C_ACK,&amp;data[i],0,&amp;I2C_1_context);
    }
    Cy_SCB_I2C_MasterReadByte(I2C_1_HW,CY_SCB_I2C_NAK,&amp;data[len-1],0,&amp;I2C_1_context);
    
    Cy_SCB_I2C_MasterSendStop(I2C_1_HW,0,&amp;I2C_1_context);
    
    
    return 0;
}
</pre>
<p>There is one error with both my read and write functions.  And that error is?  No error checking.  I have seen some intermittent weirdness in which the I2C bus gets locked that ends up requiring a reset to fix.  This could be prevented by checking error codes on the I2C functions.</p>
<p>Now that we have a read and write function we can setup our device:  To do this:</p>
<ol>
<li>Setup a structure of type bmi160_dev</li>
<li>Initialize the function pointers</li>
<li>Initialize the settings for the device</li>
<li>Finally send the settings</li>
</ol>
<pre class="lang:c decode:true">static struct bmi160_dev bmi160Dev;

static void sensorsDeviceInit(void)
{

  int8_t rslt;
  vTaskDelay(500); // guess

  /* BMI160 */
  bmi160Dev.read = (bmi160_com_fptr_t)BMI160BurstRead;
  bmi160Dev.write = (bmi160_com_fptr_t)BMI160BurstWrite;
  bmi160Dev.delay_ms = (bmi160_delay_fptr_t)vTaskDelay;
  
  bmi160Dev.id = BMI160_I2C_ADDR;  // I2C device address

  rslt = bmi160_init(&amp;bmi160Dev); // initialize the device
  if (rslt == 0)
    {
      printf("BMI160 I2C connection [OK].\n");
      bmi160Dev.gyro_cfg.odr = BMI160_GYRO_ODR_800HZ;
      bmi160Dev.gyro_cfg.range = BMI160_GYRO_RANGE_125_DPS;
      bmi160Dev.gyro_cfg.bw = BMI160_GYRO_BW_OSR4_MODE;

      /* Select the power mode of Gyroscope sensor */
      bmi160Dev.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;

      bmi160Dev.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
      bmi160Dev.accel_cfg.range = BMI160_ACCEL_RANGE_4G;
      bmi160Dev.accel_cfg.bw = BMI160_ACCEL_BW_OSR4_AVG1;
      bmi160Dev.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;

      /* Set the sensor configuration */
      bmi160_set_sens_conf(&amp;bmi160Dev);
      bmi160Dev.delay_ms(50);
    }
  else
    {
      printf("BMI160 I2C connection [FAIL].\n");
    }
}</pre>
<h1>Create the main firmware and test</h1>
<p>Finally I test the firmware by running an infinite loop that prints out acceleration data.</p>
<pre class="lang:c decode:true">void motionTask(void *arg)
{
    (void)arg;
    I2C_1_Start();
    sensorsDeviceInit();
    struct bmi160_sensor_data acc;

    while(1)
    {
        
        bmi160_get_sensor_data(BMI160_ACCEL_ONLY, &amp;acc, NULL, &amp;bmi160Dev);      
        printf("x=%4d y=%4d z=%4d\r\n",acc.x,acc.y,acc.z,);       
        vTaskDelay(200);
    }
}
</pre>
<p>Now you should have this:</p>
<p><a href="https://iotexpert.com/?attachment_id=4964" rel="attachment wp-att-4964"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.47.49-PM.png" alt="" width="660" height="420" class="alignnone wp-image-4964 size-full" srcset="https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.47.49-PM.png 660w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.47.49-PM-600x382.png 600w, https://iotexpert.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-2.47.49-PM-300x191.png 300w" sizes="auto, (max-width: 660px) 100vw, 660px" /></a></p>
<p>And finally the whole program in one shot</p>
<pre class="lang:c decode:true ">#include "project.h"
#include "FreeRTOS.h"
#include "task.h"
#include &lt;stdio.h&gt;
#include "bmi160.h"

static struct bmi160_dev bmi160Dev;

static int8_t BMI160BurstWrite(uint8_t dev_addr, uint8_t reg_addr,uint8_t *data, uint16_t len)
{
    
    Cy_SCB_I2C_MasterSendStart(I2C_1_HW,dev_addr,CY_SCB_I2C_WRITE_XFER,0,&amp;I2C_1_context);
    Cy_SCB_I2C_MasterWriteByte(I2C_1_HW,reg_addr,0,&amp;I2C_1_context);
    for(int i = 0;i&lt;len; i++)
    { 
        Cy_SCB_I2C_MasterWriteByte(I2C_1_HW,data[i],0,&amp;I2C_1_context);
    }
    
    Cy_SCB_I2C_MasterSendStop(I2C_1_HW,0,&amp;I2C_1_context);
    
    return 0;
}

// This function supports the BMP180 library and read I2C Registers
static int8_t BMI160BurstRead(uint8_t dev_addr, uint8_t reg_addr,uint8_t *data, uint16_t len)
{
    
    Cy_SCB_I2C_MasterSendStart(I2C_1_HW,dev_addr,CY_SCB_I2C_WRITE_XFER,0,&amp;I2C_1_context);
    Cy_SCB_I2C_MasterWriteByte(I2C_1_HW,reg_addr,0,&amp;I2C_1_context);
    Cy_SCB_I2C_MasterSendReStart(I2C_1_HW,dev_addr,CY_SCB_I2C_READ_XFER,0,&amp;I2C_1_context);
    for(int i = 0;i&lt;len-1; i++)
    {
        Cy_SCB_I2C_MasterReadByte(I2C_1_HW,CY_SCB_I2C_ACK,&amp;data[i],0,&amp;I2C_1_context);
    }
    Cy_SCB_I2C_MasterReadByte(I2C_1_HW,CY_SCB_I2C_NAK,&amp;data[len-1],0,&amp;I2C_1_context);
    
    Cy_SCB_I2C_MasterSendStop(I2C_1_HW,0,&amp;I2C_1_context);
    
    
    return 0;
}


static void sensorsDeviceInit(void)
{

  int8_t rslt;
  vTaskDelay(500); // guess

  /* BMI160 */
  bmi160Dev.read = (bmi160_com_fptr_t)BMI160BurstRead;
  bmi160Dev.write = (bmi160_com_fptr_t)BMI160BurstWrite;
  bmi160Dev.delay_ms = (bmi160_delay_fptr_t)vTaskDelay;
  
  bmi160Dev.id = BMI160_I2C_ADDR;  // I2C device address

  rslt = bmi160_init(&amp;bmi160Dev); // initialize the device
  if (rslt == 0)
    {
      printf("BMI160 I2C connection [OK].\n");
      bmi160Dev.gyro_cfg.odr = BMI160_GYRO_ODR_800HZ;
      bmi160Dev.gyro_cfg.range = BMI160_GYRO_RANGE_125_DPS;
      bmi160Dev.gyro_cfg.bw = BMI160_GYRO_BW_OSR4_MODE;

      /* Select the power mode of Gyroscope sensor */
      bmi160Dev.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;

      bmi160Dev.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
      bmi160Dev.accel_cfg.range = BMI160_ACCEL_RANGE_4G;
      bmi160Dev.accel_cfg.bw = BMI160_ACCEL_BW_OSR4_AVG1;
      bmi160Dev.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;

      /* Set the sensor configuration */
      bmi160_set_sens_conf(&amp;bmi160Dev);
      bmi160Dev.delay_ms(50);
    }
  else
    {
      printf("BMI160 I2C connection [FAIL].\n");
    }
}
#define MAXACCEL 8000
void motionTask(void *arg)
{
    (void)arg;
    I2C_1_Start();
    sensorsDeviceInit();
    struct bmi160_sensor_data acc;

    while(1)
    {
        bmi160_get_sensor_data(BMI160_ACCEL_ONLY, &amp;acc, NULL, &amp;bmi160Dev);
        printf("x=%4d y=%4d z=%4d\r\n",acc.x,acc.y,acc.z);
        
        vTaskDelay(200);
    }
}



int main(void)
{
    __enable_irq(); /* Enable global interrupts. */

    UART_1_Start();

    xTaskCreate( motionTask, "Motion Task",400,0,1,0);
    vTaskStartScheduler();

    while(1);
}

/* [] END OF FILE */
</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/bosch-bmi160-psoc-6-cy8ckit-028-epd/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
