<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/"/>

<title>Jeff Epler's blog</title>
<modified>2014-04-30T21:14:10Z</modified>
<tagline>Photos, electronics, cnc, and more</tagline>
<author><name>Jeff Epler</name><email>jepler@unpythonic.net</email></author>
<entry>
<title>Towards fast I/O in Arduino for AVRs</title>
<issued>2014-04-30T21:14:10Z</issued>
<modified>2014-04-30T21:14:10Z</modified>
<id>https://gamma.unpythonic.net/01398892450</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01398892450"/>
<content type="text/html" mode="escaped">

So I've been working on something.  I've only looked at assembler output so far,
but it looks right and promising.

&lt;p&gt;Basically, I'd like to let you name I/O pins via typedef, then efficiently
read and write the pins.  And I'd like to make Arduino's digitalWrite just as
efficient when the pin argument is a constant.

&lt;p&gt;All instruction counts are in Debian Wheezy's avr-gcc version 4.7.2 with 
&lt;tt&gt;-mmcu=atmega328p -Os&lt;/tt&gt; specified on the commandline.
&lt;pre&gt;
// You can declare ports (they use zero RAM)
typedef IOPIN&amp;lt;PORT_B, 0&amp;gt; iob0;
typedef IOPIN&amp;lt;PORT_B, 1&amp;gt; iob1;
typedef OCPIN&amp;lt;PORT_B, 1, true&amp;gt; ocb1; // emulate an open collector port

// .. and use them efficiently (instruction counts never include ret)
int en() { iob0::output(); }                // 1 instruction
int fn() { iob0::toggle(); }                // 1 instruction
int gn() { ocb1::set(); }                   // 2 instructions
int hn() { ocb1::clear(); }                 // 2 instructions
int jn(bool b) { iob0::write(b); }          // 5 instructions
int kn() { iob0::write(1); }                // 1 instruction

// you can use fastDigitalWrite just like digitalWrite (but faster and inline)
int c(int i) { fastDigitalWrite(1, i); }    // 5 instructions
int d() { fastDigitalWrite(1, 1); }         // 1 instruction

// these have a variable port so they still turn into calls to digitalWrite
int a(int i, int j) { fastDigitalWrite(i, j); }
int b(int i) { fastDigitalWrite(i, 1); }
&lt;/pre&gt;

&lt;p&gt;&lt;p&gt;&lt;b&gt;Files currently attached to this page:&lt;/b&gt;
&lt;table cellpadding=5 style=&quot;width:auto!important; clear:none!important&quot;&gt;&lt;col&gt;&lt;col style=&quot;text-align: right&quot;&gt;&lt;tr bgcolor=#eeeeee&gt;&lt;td&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01398892450/fast_io_prototype.cpp&quot;&gt;fast_io_prototype.cpp&lt;/a&gt;&lt;/td&gt;&lt;td&gt;6.2kB&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;p&gt;
</content>
</entry>
<entry>
<title>It's gratifying when the compiler is right</title>
<issued>2011-12-27T20:35:02Z</issued>
<modified>2011-12-27T20:35:02Z</modified>
<id>https://gamma.unpythonic.net/01325018102</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01325018102"/>
<content type="text/html" mode="escaped">I've been playing with &lt;a href=&quot;http://clang.llvm.org&quot;&gt;clang&lt;/a&gt;
because I'd like to use its &lt;a href=&quot;http://clang-analyzer.llvm.org/&quot;&gt;static analyzer&lt;/a&gt; on the code at $DAY_JOB.  Unfortunately, it frequently bombs
while building our code.  Fortunately, many of the bombs are due to our bugs,
not theirs.  Here's one example:</content>
</entry>
</feed>
