add digital read

This commit is contained in:
Robert 2022-12-18 15:19:57 +01:00
parent 62825d5d28
commit 89b549ecc4
16 changed files with 306 additions and 33 deletions

View file

@ -11,4 +11,18 @@ mod tests {
fn bench_create_instance(b: &mut Bencher) {
b.iter(|| B15F::new());
}
#[bench]
fn bench_digital_write(b: &mut Bencher) {
let mut drv = B15F::new().unwrap();
b.iter(move || drv.digital_write::<0>(0xAB).unwrap());
}
#[bench]
fn bench_digital_read(b: &mut Bencher) {
let mut drv = B15F::new().unwrap();
b.iter(move || drv.digital_read::<0>().unwrap());
}
}

View file

@ -1,4 +1,4 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="This module contains all the structures and functions related to interacting with the B15 on a high level. If you are writing code for the B15, this is the module you want to use."><meta name="keywords" content="rust, rustlang, rust-lang, b15f"><title>b15f::b15f - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Module b15f</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Module <a href="../index.html">b15f</a>::<wbr><a class="mod" href="#">b15f</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/b15f/b15f.rs.html#1-316">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This module contains all the structures and functions related to
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="This module contains all the structures and functions related to interacting with the B15 on a high level. If you are writing code for the B15, this is the module you want to use."><meta name="keywords" content="rust, rustlang, rust-lang, b15f"><title>b15f::b15f - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Module b15f</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Module <a href="../index.html">b15f</a>::<wbr><a class="mod" href="#">b15f</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/b15f/b15f.rs.html#1-374">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This module contains all the structures and functions related to
interacting with the B15 on a high level. If you are writing code
for the B15, this is the module you want to use.</p>
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.B15F.html" title="b15f::b15f::B15F struct">B15F</a></div><div class="item-right docblock-short">Structure representing the driver for the board 15</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="b15f" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0 (69f9c33d7 2022-12-12)" ></div></body></html>

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Driver code for the board 15"><meta name="keywords" content="rust, rustlang, rust-lang, b15f"><title>b15f - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate b15f</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.1.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">b15f</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/b15f/lib.rs.html#1-20">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Driver code for the board 15</p>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Driver code for the board 15"><meta name="keywords" content="rust, rustlang, rust-lang, b15f"><title>b15f - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate b15f</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.1.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">b15f</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/b15f/lib.rs.html#1-21">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Driver code for the board 15</p>
<p>It aims to be syntactically similar to the <a href="https://github.com/devfix/b15f"><code>original</code></a> implementation.
The original repository is no longer maintained, and this library doesnt maintain it either,
it simply provides the same functionality in another language.</p>

View file

@ -1,5 +1,5 @@
var searchIndex = JSON.parse('{\
"b15f":{"doc":"Driver code for the board 15","t":[2,0,14,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11],"n":["B15F","b15f","build_request","B15F","borrow","borrow_mut","digital_write","discard","fmt","from","get_board_info","into","new","test_connection","test_int_conv","try_from","try_into","type_id","vzip"],"q":["b15f","","","b15f::b15f","","","","","","","","","","","","","","",""],"d":["","This module contains all the structures and functions …","Builds a new request buffer from the given data","Structure representing the driver for the board 15","","","Sets the value of the specified port","Clears data in the USART buffers on this device and on the …","","Returns the argument unchanged.","Yields information about the installed firmware on the B15","Calls <code>U::from(self)</code>.","Creates a new instance of the B15","Tests the connetion to the B15","Test the integer conversion of the USART connection","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"f":[0,0,0,0,[[]],[[]],[[1,2],[[3,[0]]]],[1,[[3,[0]]]],[[1,4],5],[[]],[1,[[3,[[7,[6]],0]]]],[[]],[[],[[3,[1,0]]]],[1,[[3,[0]]]],[1,[[3,[0]]]],[[],3],[[],3],[[],8],[[]]],"p":[[3,"B15F"],[15,"u8"],[4,"Result"],[3,"Formatter"],[6,"Result"],[3,"String"],[3,"Vec"],[3,"TypeId"]]}\
"b15f":{"doc":"Driver code for the board 15","t":[2,0,14,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11],"n":["B15F","b15f","build_request","B15F","borrow","borrow_mut","digital_read","digital_write","discard","fmt","from","get_board_info","into","new","test_connection","test_int_conv","try_from","try_into","type_id","vzip"],"q":["b15f","","","b15f::b15f","","","","","","","","","","","","","","","",""],"d":["","This module contains all the structures and functions …","Builds a new request buffer from the given data","Structure representing the driver for the board 15","","","Reads the value of the specified port","Sets the value of the specified port","Clears data in the USART buffers on this device and on the …","","Returns the argument unchanged.","Yields information about the installed firmware on the B15","Calls <code>U::from(self)</code>.","Creates a new instance of the B15","Tests the connetion to the B15","Test the integer conversion of the USART connection","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"f":[0,0,0,0,[[]],[[]],[1,[[3,[2,0]]]],[[1,2],[[3,[0]]]],[1,[[3,[0]]]],[[1,4],5],[[]],[1,[[3,[[7,[6]],0]]]],[[]],[[],[[3,[1,0]]]],[1,[[3,[0]]]],[1,[[3,[0]]]],[[],3],[[],3],[[],8],[[]]],"p":[[3,"B15F"],[15,"u8"],[4,"Result"],[3,"Formatter"],[6,"Result"],[3,"String"],[3,"Vec"],[3,"TypeId"]]}\
}');
if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)};
if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};

View file

@ -1,4 +1,4 @@
var sourcesIndex = JSON.parse('{\
"b15f":["",[],["b15f.rs","error.rs","lib.rs","request.rs"]]\
"b15f":["",[],["assert.rs","b15f.rs","error.rs","lib.rs","request.rs"]]\
}');
createSourceSidebar();

View file

@ -0,0 +1,19 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/assert.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>assert.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../source-script.js"></script><script defer src="../../source-files.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><div class="width-limiter"><nav class="sub"><a class="sub-logo-container" href="../../b15f/index.html"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><pre class="src-line-numbers"><span id="1">1</span>
<span id="2">2</span>
<span id="3">3</span>
<span id="4">4</span>
<span id="5">5</span>
<span id="6">6</span>
<span id="7">7</span>
<span id="8">8</span>
<span id="9">9</span>
</pre><pre class="rust"><code><span class="kw">struct </span>AssertInRange&lt;<span class="kw">const </span>VALUE: usize, <span class="kw">const </span>MIN: usize, <span class="kw">const </span>MAX: usize&gt;;
<span class="kw">impl</span>&lt;<span class="kw">const </span>VALUE: usize, <span class="kw">const </span>MIN: usize, <span class="kw">const </span>MAX: usize&gt; AssertInRange&lt;VALUE, MIN, MAX&gt; {
<span class="kw">const </span>OK: () = <span class="macro">assert!</span>(MIN &lt;= VALUE &amp;&amp; VALUE &lt;= MAX);
}
<span class="kw">pub fn </span>assert_in_range&lt;<span class="kw">const </span>VALUE: usize, <span class="kw">const </span>MIN: usize, <span class="kw">const </span>MAX: usize&gt; () {
<span class="kw">let </span>() = AssertInRange::&lt;VALUE, MIN, MAX&gt;::OK;
}</code></pre></div>
</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="b15f" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0 (69f9c33d7 2022-12-12)" ></div></body></html>

View file

@ -314,6 +314,64 @@
<span id="314">314</span>
<span id="315">315</span>
<span id="316">316</span>
<span id="317">317</span>
<span id="318">318</span>
<span id="319">319</span>
<span id="320">320</span>
<span id="321">321</span>
<span id="322">322</span>
<span id="323">323</span>
<span id="324">324</span>
<span id="325">325</span>
<span id="326">326</span>
<span id="327">327</span>
<span id="328">328</span>
<span id="329">329</span>
<span id="330">330</span>
<span id="331">331</span>
<span id="332">332</span>
<span id="333">333</span>
<span id="334">334</span>
<span id="335">335</span>
<span id="336">336</span>
<span id="337">337</span>
<span id="338">338</span>
<span id="339">339</span>
<span id="340">340</span>
<span id="341">341</span>
<span id="342">342</span>
<span id="343">343</span>
<span id="344">344</span>
<span id="345">345</span>
<span id="346">346</span>
<span id="347">347</span>
<span id="348">348</span>
<span id="349">349</span>
<span id="350">350</span>
<span id="351">351</span>
<span id="352">352</span>
<span id="353">353</span>
<span id="354">354</span>
<span id="355">355</span>
<span id="356">356</span>
<span id="357">357</span>
<span id="358">358</span>
<span id="359">359</span>
<span id="360">360</span>
<span id="361">361</span>
<span id="362">362</span>
<span id="363">363</span>
<span id="364">364</span>
<span id="365">365</span>
<span id="366">366</span>
<span id="367">367</span>
<span id="368">368</span>
<span id="369">369</span>
<span id="370">370</span>
<span id="371">371</span>
<span id="372">372</span>
<span id="373">373</span>
<span id="374">374</span>
</pre><pre class="rust"><code><span class="doccomment">//! This module contains all the structures and functions related to
//! interacting with the B15 on a high level. If you are writing code
//! for the B15, this is the module you want to use.
@ -321,9 +379,8 @@
</span><span class="kw">use </span>std::{process::Command, time::Duration, fmt::Debug, thread::sleep};
<span class="kw">use </span>rand::Rng;
<span class="kw">use </span>serialport::SerialPort;
<span class="kw">use </span><span class="kw">crate</span>::error::Error;
<span class="kw">use crate</span>::{request::Request, build_request};
<span class="kw">use crate</span>::{assert::assert_in_range, error::Error, request::Request, build_request};
<span class="macro">macro_rules! </span>log {
(<span class="macro-nonterminal">$text</span>: literal, $(<span class="macro-nonterminal">$arg</span>:tt)<span class="kw-2">*</span>) =&gt; (<span class="macro">println!</span>(<span class="macro">concat!</span>(<span class="string">&quot;[B15F] &quot;</span>, <span class="macro-nonterminal">$text</span>), $(<span class="macro-nonterminal">$arg</span>)<span class="kw-2">*</span>));
@ -435,30 +492,89 @@
<span class="doccomment">/// Sets the value of the specified port
///
/// # Errors
/// `port` can either be 0 or 1, other values will cause a compile-time
/// `PORT` can either be 0 or 1, other values will cause a compile-time
/// error. Otherwise an `error::Error` is generated if communication
/// with the B15 fails.
///
/// # Examples
/// ```
/// use b15f::B15F;
///
</span><span class="kw">pub fn </span>digital_write&lt;<span class="kw">const </span>port: u8&gt; (<span class="kw-2">&amp;mut </span><span class="self">self</span>, value: u8) -&gt; <span class="prelude-ty">Result</span>&lt;(), Error&gt; {
<span class="macro">assert!</span>(port == <span class="number">0 </span>|| port == <span class="number">1</span>);
/// fn main() -&gt; Result&lt;(), String&gt; {
/// let mut drv = B15F::new()?;
///
/// drv.digital_write::&lt;0&gt;(0xFF)?; // Turn on all bits of port 0
/// drv.digital_write::&lt;1&gt;(0x0F)?; // Turn on bits 0-4 of port 1
///
/// // drv.digital_write::&lt;2&gt;(0xFF); // Compiler error
///
/// Ok(())
/// }
/// ```
///
</span><span class="kw">pub fn </span>digital_write&lt;<span class="kw">const </span>PORT: usize&gt; (<span class="kw-2">&amp;mut </span><span class="self">self</span>, value: u8) -&gt; <span class="prelude-ty">Result</span>&lt;(), Error&gt; {
assert_in_range::&lt;PORT, <span class="number">0</span>, <span class="number">1</span>&gt;();
<span class="kw">let </span>reversed = value.reverse_bits();
<span class="kw">let </span>request = <span class="kw">if </span>port == <span class="number">0 </span>{ Request::DigitalWrite0 } <span class="kw">else </span>{ Request::DigitalWrite1 };
<span class="kw">let </span>request = <span class="kw">match </span>PORT {
<span class="number">0 </span>=&gt; Request::DigitalWrite0,
<span class="number">1 </span>=&gt; Request::DigitalWrite1,
<span class="kw">_ </span>=&gt; <span class="macro">panic!</span>(<span class="string">&quot;Report this issue to someone, this should not ever be visible.&quot;</span>)
};
<span class="self">self</span>.usart.write(<span class="macro">build_request!</span>[request, reversed])<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>aw: [u8; <span class="number">1</span>] = [<span class="number">0</span>; <span class="number">1</span>];
<span class="self">self</span>.usart.read(<span class="kw-2">&amp;mut </span>aw)<span class="question-mark">?</span>;
<span class="kw">if </span>aw[<span class="number">0</span>] != B15F::MSG_OK {
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="macro">format!</span>(<span class="string">&quot;Setting Port {} failed&quot;</span>, port).into());
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="macro">format!</span>(<span class="string">&quot;Setting Port {} failed&quot;</span>, PORT).into());
}
<span class="prelude-val">Ok</span>(())
}
<span class="doccomment">/// Reads the value of the specified port
///
/// # Errors
/// `PORT` can either be 0 or 1, other values will cause a compile-time
/// error. Otherwise an `error::Error` is generated if communication
/// with the B15 fails.
///
/// # Examples
/// ```
/// use b15f::B15F;
///
/// fn main() -&gt; Result&lt;(), String&gt; {
/// let mut drv = B15F::new()?;
///
/// let _ = drv.digital_read::&lt;0&gt;()?; // Read inputs of port 0
/// let _ = drv.digital_read::&lt;1&gt;()?; // Read inputs of port 1
///
/// // drv.digital_read::&lt;2&gt;(); // Compiler error
///
/// Ok(())
/// }
/// ```
///
</span><span class="kw">pub fn </span>digital_read&lt;<span class="kw">const </span>PORT: usize&gt; (<span class="kw-2">&amp;mut </span><span class="self">self</span>) -&gt; <span class="prelude-ty">Result</span>&lt;u8, Error&gt; {
assert_in_range::&lt;PORT, <span class="number">0</span>, <span class="number">1</span>&gt;();
<span class="kw">let </span>request = <span class="kw">match </span>PORT {
<span class="number">0 </span>=&gt; Request::DigitalRead0,
<span class="number">1 </span>=&gt; Request::DigitalRead1,
<span class="kw">_ </span>=&gt; <span class="macro">panic!</span>(<span class="string">&quot;Report this issue to someone, this should not ever be visible.&quot;</span>)
};
<span class="self">self</span>.usart.clear(serialport::ClearBuffer::Input)<span class="question-mark">?</span>;
<span class="self">self</span>.usart.write(<span class="macro">build_request!</span>[request])<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>aw: [u8; <span class="number">1</span>] = [<span class="number">0</span>; <span class="number">1</span>];
<span class="self">self</span>.usart.read(<span class="kw-2">&amp;mut </span>aw)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(u8::reverse_bits(aw[<span class="number">0</span>]))
}
<span class="doccomment">/// Yields information about the installed firmware on the B15
///
/// Returns an array of strings, where each string contains a piece

View file

@ -40,6 +40,12 @@
<span id="40">40</span>
<span id="41">41</span>
<span id="42">42</span>
<span id="43">43</span>
<span id="44">44</span>
<span id="45">45</span>
<span id="46">46</span>
<span id="47">47</span>
<span id="48">48</span>
</pre><pre class="rust"><code><span class="kw">use </span>std::fmt::Display;
<span class="attribute">#[derive(Debug)]
@ -77,6 +83,12 @@
}
}
<span class="kw">impl </span>From&lt;Error&gt; <span class="kw">for </span>String {
<span class="kw">fn </span>from(err: Error) -&gt; <span class="self">Self </span>{
err.message
}
}
<span class="kw">impl </span>Display <span class="kw">for </span>Error {
<span class="kw">fn </span>fmt(<span class="kw-2">&amp;</span><span class="self">self</span>, f: <span class="kw-2">&amp;mut </span>std::fmt::Formatter&lt;<span class="lifetime">&#39;_</span>&gt;) -&gt; std::fmt::Result {
<span class="macro">write!</span>(f, <span class="string">&quot;{}&quot;</span>, <span class="self">self</span>.message)

View file

@ -18,6 +18,7 @@
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
</pre><pre class="rust"><code><span class="attribute">#![deny(missing_docs,
missing_debug_implementations,
trivial_casts,
@ -36,6 +37,7 @@
</span><span class="kw">pub mod </span>b15f;
<span class="kw">mod </span>request;
<span class="kw">mod </span>error;
<span class="kw">mod </span>assert;
<span class="kw">pub use </span><span class="kw">crate</span>::b15f::B15F;</code></pre></div>
</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="b15f" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0 (69f9c33d7 2022-12-12)" ></div></body></html>

View file

@ -25,6 +25,8 @@
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
</pre><pre class="rust"><code><span class="doccomment">//! This module contains the request data used to communicate
//! with the B15 via USART.
//!
@ -51,5 +53,7 @@
DigitalWrite0 = <span class="number">5</span>,
DigitalWrite1 = <span class="number">6</span>,
}</code></pre></div>
DigitalRead0 = <span class="number">7</span>,
DigitalRead1 = <span class="number">8
</span>}</code></pre></div>
</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="b15f" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0 (69f9c33d7 2022-12-12)" ></div></body></html>

View file

@ -2,14 +2,14 @@ use std::{thread::sleep, time::Duration};
use b15f::b15f::B15F;
fn main() {
let mut drv = B15F::new().unwrap();
fn main() -> Result<(), String> {
let mut drv = B15F::new()?;
let mut position = 0;
let mut direction = 1;
loop {
drv.digital_write::<0>(1 << position);
drv.digital_write::<0>(1 << position)?;
position += direction;
if position >= 7 || position <= 0 {

8
examples/read.rs Normal file
View file

@ -0,0 +1,8 @@
use b15f::b15f::B15F;
fn main() -> Result<(), String> {
let mut drv = B15F::new()?;
println!("{}", drv.digital_read::<0>().unwrap());
Ok(())
}

View file

@ -118,18 +118,36 @@ impl B15F {
/// Sets the value of the specified port
///
/// # Errors
/// `port` can either be 0 or 1, other values will cause a compile-time
/// `PORT` can either be 0 or 1, other values will cause a compile-time
/// error. Otherwise an `error::Error` is generated if communication
/// with the B15 fails.
///
/// # Examples
/// ```
/// use b15f::B15F;
///
/// fn main() -> Result<(), String> {
/// let mut drv = B15F::new()?;
///
/// drv.digital_write::<0>(0xFF)?; // Turn on all bits of port 0
/// drv.digital_write::<1>(0x0F)?; // Turn on bits 0-4 of port 1
///
/// // drv.digital_write::<2>(0xFF); // Compiler error
///
/// Ok(())
/// }
/// ```
///
pub fn digital_write<const PORT: usize> (&mut self, value: u8) -> Result<(), Error> {
assert_in_range::<PORT, 0, 1>();
let reversed = value.reverse_bits();
let request = if PORT == 0 { Request::DigitalWrite0 } else { Request::DigitalWrite1 };
let request = match PORT {
0 => Request::DigitalWrite0,
1 => Request::DigitalWrite1,
_ => panic!("Report this issue to someone, this should not ever be visible.")
};
self.usart.write(build_request![request, reversed])?;
let mut aw: [u8; 1] = [0; 1];
@ -142,6 +160,47 @@ impl B15F {
Ok(())
}
/// Reads the value of the specified port
///
/// # Errors
/// `PORT` can either be 0 or 1, other values will cause a compile-time
/// error. Otherwise an `error::Error` is generated if communication
/// with the B15 fails.
///
/// # Examples
/// ```
/// use b15f::B15F;
///
/// fn main() -> Result<(), String> {
/// let mut drv = B15F::new()?;
///
/// let _ = drv.digital_read::<0>()?; // Read inputs of port 0
/// let _ = drv.digital_read::<1>()?; // Read inputs of port 1
///
/// // drv.digital_read::<2>(); // Compiler error
///
/// Ok(())
/// }
/// ```
///
pub fn digital_read<const PORT: usize> (&mut self) -> Result<u8, Error> {
assert_in_range::<PORT, 0, 1>();
let request = match PORT {
0 => Request::DigitalRead0,
1 => Request::DigitalRead1,
_ => panic!("Report this issue to someone, this should not ever be visible.")
};
self.usart.clear(serialport::ClearBuffer::Input)?;
self.usart.write(build_request![request])?;
let mut aw: [u8; 1] = [0; 1];
self.usart.read(&mut aw)?;
Ok(u8::reverse_bits(aw[0]))
}
/// Yields information about the installed firmware on the B15
///
/// Returns an array of strings, where each string contains a piece

View file

@ -35,6 +35,12 @@ impl From<String> for Error {
}
}
impl From<Error> for String {
fn from(err: Error) -> Self {
err.message
}
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)

View file

@ -24,4 +24,6 @@ pub enum Request {
DigitalWrite0 = 5,
DigitalWrite1 = 6,
DigitalRead0 = 7,
DigitalRead1 = 8
}