Crates.io | cd74hc4067 |
lib.rs | cd74hc4067 |
version | 0.2.0 |
source | src |
created_at | 2021-01-14 17:56:54.471507 |
updated_at | 2021-02-02 13:17:45.996459 |
description | A platform agnostic driver to interface with CD74HC4067 |
homepage | https://github.com/barafael/cd74hc4067 |
repository | https://github.com/barafael/cd74hc4067 |
max_upload_size | |
id | 342017 |
size | 14,482 |
This library is an embedded-hal compliant driver for a GPIO-driven CD74HC4067 chip. It is completely hardware-agnostic, only requiring 5 output pins to operate. Given a compliant implementation of embedded-hal for a target, this driver should work there out-of-the-box.
The chip is quite simple. It connects 1 of 16 analog IO lines to 1 signal line, depending on the 4 select pins. The only thing to look out for is to disable the chip with the disable signal before changing the select pins to avoid activating an unwanted line for a short moment during switching.
Because of the simplicity of this chip, the driver is also nothing special. But that means it may serve as an example for an embedded-hal driver that uses type-state programming. In this driver, type-state programming is used to ensure that:
The tests for the library also show a basic example of how to use embedded-hal-mock to test drivers when the hardware isn't there yet :) or on CI. Note, the test coverage is practically 100% line coverage.
The only exception are the calls to PhantomData::<...>, as they are excluded from the compiled binary by design.