├── .gitignore ├── Cargo.toml ├── src ├── bindings.rs └── lib.rs ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | target 4 | **/*.rs.bk 5 | Cargo.lock 6 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "esp8266-hal" 3 | version = "0.0.1" 4 | authors = ["Eitan Mosenkis "] 5 | categories = ["embedded", "hardware-support"] 6 | keywords = ["esp-rs", "esp8266", "embedded-hal", "embedded-hal-impl"] 7 | repository = "https://github.com/emosenkis/esp8266-hal" 8 | license = "MIT" 9 | description = "Implementation of the `embedded-hal` traits for ESP8266" 10 | 11 | [dependencies] 12 | libc = { version = "0.2.22", default-features = false } 13 | embedded-hal = { version = "0.2.1", features = ["unproven"] } 14 | -------------------------------------------------------------------------------- /src/bindings.rs: -------------------------------------------------------------------------------- 1 | /* automatically generated by rust-bindgen */ 2 | 3 | #![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] 4 | extern crate libc; 5 | 6 | pub const HIGH: libc::c_uint = 1; 7 | pub const LOW: libc::c_uint = 0; 8 | pub const INPUT: libc::c_uint = 0; 9 | pub const OUTPUT: libc::c_uint = 1; 10 | pub type __uint8_t = libc::c_uchar; 11 | extern "C" { 12 | pub fn pinMode(pin: u8, mode: u8); 13 | } 14 | extern "C" { 15 | pub fn digitalWrite(pin: u8, val: u8); 16 | } 17 | extern "C" { 18 | pub fn digitalRead(pin: u8) -> libc::c_int; 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED - try [esp-rs/esp8266-hal](https://github.com/esp-rs/esp8266-hal) 2 | 3 | # [`embedded-hal`](https://github.com/japaric/embedded-hal) implementation for ESP8266 4 | 5 | This crate implements `embedded-hal` traits for the ESP8266 series of 6 | microcontrollers by using the [Arduino 7 | SDK](https://github.com/esp8266/Arduino). Since LLVM, and therefore rustc, do 8 | not support the Xtensa architecture, they must be transpiled to C using 9 | [mrustc](https://github.com/thepowersgang/mrustc), then compiled using GCC. The 10 | [esp-rs](https://github.com/emosenkis/esp-rs) build script implements this 11 | peculiar build process. 12 | 13 | ## Supported traits 14 | 15 | - `digital::InputPin` 16 | 17 | - `digital::OutputPin` 18 | 19 | - `digital::StatefulOutputPin` 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Eitan Mosenkis 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | extern crate embedded_hal; 4 | extern crate libc; 5 | 6 | mod bindings; 7 | use bindings::*; 8 | 9 | pub struct InputPin(u8); 10 | pub struct OutputPin(u8); 11 | 12 | impl InputPin { 13 | pub fn new(pin: u8) -> Self { 14 | InputPin::set_pin_mode(pin); 15 | InputPin::with_pin_mode_already_set(pin) 16 | } 17 | 18 | pub fn with_pin_mode_already_set(pin: u8) -> Self { 19 | InputPin(pin) 20 | } 21 | 22 | pub fn to_output(self) -> OutputPin { 23 | OutputPin::new(self.0) 24 | } 25 | 26 | fn set_pin_mode(pin: u8) { 27 | unsafe { 28 | pinMode(pin, INPUT as u8); 29 | } 30 | } 31 | } 32 | 33 | impl OutputPin { 34 | pub fn new(pin: u8) -> Self { 35 | OutputPin::set_pin_mode(pin); 36 | OutputPin::with_pin_mode_already_set(pin) 37 | } 38 | 39 | pub fn with_pin_mode_already_set(pin: u8) -> Self { 40 | OutputPin(pin) 41 | } 42 | 43 | pub fn to_input(self) -> InputPin { 44 | InputPin::new(self.0) 45 | } 46 | 47 | fn set_pin_mode(pin: u8) { 48 | unsafe { 49 | pinMode(pin, OUTPUT as u8); 50 | } 51 | } 52 | } 53 | 54 | impl embedded_hal::digital::InputPin for InputPin { 55 | fn is_low(&self) -> bool { 56 | let result; 57 | unsafe { 58 | result = digitalRead(self.0) as u8; 59 | } 60 | result == (LOW as u8) 61 | } 62 | fn is_high(&self) -> bool { 63 | let result; 64 | unsafe { 65 | result = digitalRead(self.0) as u8; 66 | } 67 | result == (HIGH as u8) 68 | } 69 | } 70 | 71 | impl embedded_hal::digital::OutputPin for OutputPin { 72 | fn set_low(&mut self) { 73 | unsafe { 74 | digitalWrite(self.0, LOW as u8); 75 | } 76 | } 77 | fn set_high(&mut self) { 78 | unsafe { 79 | digitalWrite(self.0, HIGH as u8); 80 | } 81 | } 82 | } 83 | 84 | impl embedded_hal::digital::StatefulOutputPin for OutputPin { 85 | fn is_set_low(&self) -> bool { 86 | let result; 87 | unsafe { 88 | result = digitalRead(self.0) as u8; 89 | } 90 | result == (LOW as u8) 91 | } 92 | fn is_set_high(&self) -> bool { 93 | let result; 94 | unsafe { 95 | result = digitalRead(self.0) as u8; 96 | } 97 | result == (HIGH as u8) 98 | } 99 | } 100 | 101 | impl embedded_hal::digital::toggleable::Default for OutputPin {} 102 | --------------------------------------------------------------------------------