Code Monkey home page Code Monkey logo

k210-hal's Introduction

crates.io crates.io Build Status

k210-hal

Hardware abstract layer (HAL) for K210 chip, a dual RV64GC SoC with hardware accelerated AI peripherals.

This project is developed and maintained by the RISC-V team.

License

Copyright 2019 RISC-V team

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Code of Conduct

Contribution to this crate is organized under the terms of the Rust Code of Conduct, the maintainer of this crate, the RISC-V team, promises to intervene to uphold that code of conduct.

k210-hal's People

Contributors

burrbull avatar disasm avatar laanwj avatar longfangsong avatar luojia65 avatar tshepang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

k210-hal's Issues

GPIO abstraction

I am trying to wrap my head around the GPIO abstraction. The use of the type system is clever and intuitive (only a single owner for a given GPIO interface); however, I am struggling to understand how to use this architecture when the pull mode of the pin must change over time for signaling purposes.

I am trying to build a driver for a DHT-22 sensor, which uses a proprietary 1-wire signaling over GPIO. My first attempt looked something like this:

pub struct DhtReport {
    temperature: f32,
    humidity: f32
}

pub enum DhtError {
    Unavailable
}

type DhtResult = Result<DhtReport, DhtError>;

pub struct Dht22<GPIO, PIN> {
    gpio: GPIO,
    pin: PIN
}

impl<GPIO: GpioIndex, PIN: IoPin + Mode<GPIO::FUNC>> Dht22<GPIO, PIN>  {
    pub fn new(gpio: GPIO, pin: PIN) -> Self {
        Dht22 {
            gpio, pin
        }
    }
    pub fn report(&mut self) -> DhtResult {
        let buffer: [u8; 40] = [0; 40];
        let pin = Gpio::new(self.gpio, self.pin);
        let result = DhtReport {
            temperature: 0f32,
            humidity: 0f32
        };
        Err(DhtError::Unavailable)
    }
}

As you can see, that's not going to work because the ownership model prevents copying. Makes sense, but trying to use the Gpio abstraction doesn't work either, because while I can store an owned Gpio<GPIO, PIN>, due to type-mismatch and the ownership model, the pull direction cannot be changed through a mutable reference.

What am I supposed to do here? I suspect my inexperience of Rust is getting in the way here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.