{"action":"created","issue":{"url":"https://api.github.com/repos/rust-embedded/rfcs/issues/19","repository_url":"https://api.github.com/repos/rust-embedded/rfcs","labels_url":"https://api.github.com/repos/rust-embedded/rfcs/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/rust-embedded/rfcs/issues/19/comments","events_url":"https://api.github.com/repos/rust-embedded/rfcs/issues/19/events","html_url":"https://github.com/rust-embedded/rfcs/issues/19","id":187534479,"number":19,"title":"Define minimal Traits for common embedded peripherals","user":{"login":"jamesmunns","id":2097964,"avatar_url":"https://avatars.githubusercontent.com/u/2097964?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesmunns","html_url":"https://github.com/jamesmunns","followers_url":"https://api.github.com/users/jamesmunns/followers","following_url":"https://api.github.com/users/jamesmunns/following{/other_user}","gists_url":"https://api.github.com/users/jamesmunns/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesmunns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesmunns/subscriptions","organizations_url":"https://api.github.com/users/jamesmunns/orgs","repos_url":"https://api.github.com/users/jamesmunns/repos","events_url":"https://api.github.com/users/jamesmunns/events{/privacy}","received_events_url":"https://api.github.com/users/jamesmunns/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-11-06T01:04:52Z","updated_at":"2016-11-07T22:17:26Z","closed_at":null,"body":"Peripherals are often used in a similar style (or a few styles), with an uncountable number of details of difference between implementations.\r\n\r\nIn order to have Arduino-level usability and portability, it would be useful to define a minimal set of traits that can be used to write libraries against. When more constraints are necessary, these traits can be composed together.\r\n\r\nFor example, a baseline trait may look like this:\r\n\r\n```Rust\r\ntrait Serial {\r\n  fn read(&self) -> Option<u8>;\r\n  fn write(&self, u8) -> Result<(), ()>;\r\n}\r\n```\r\n\r\nWhen necessary to constrain, the following pattern can be used.\r\n\r\n\r\n```Rust\r\nstruct FifoSerial {\r\n// some fields omitted\r\n}\r\n\r\nimpl Serial for FifoSerial {\r\n  fn read(&mut self) -> Option<u8> {\r\n    self.rd_fifo.pop()\r\n  }\r\n\r\n  fn write(&mut self, data: u8) -> Result<(), ()> {\r\n    self.wr_fifo.push(data)\r\n  }\r\n}\r\n\r\n// Marker trait used as a tag\r\nimpl Nonblocking for FifoSerial {};\r\n\r\nfn forward<I: Serial, O: Serial+Nonblocking>(in: I, out: O) -> Result<(), ()> {\r\n  // Take from a high priority port to a low priority, memory backed port\r\n  if Some(b) = in.read() {\r\n    try!(out.write(b));\r\n  }\r\n  Ok(())\r\n}\r\n```\r\n\r\nI would like to define the behavior of at least the following peripherals:\r\n\r\n* GPIO (maybe pins, maybe ports, maybe both)\r\n* SPI\r\n* I2C\r\n* Serial\r\n* PWM (analogWrite)\r\n\r\nAdditionally, [Arduino Language Reference](https://www.arduino.cc/en/Reference/HomePage) and [Arduino Libraries](https://www.arduino.cc/en/Reference/Libraries) may be good references for a minimal amount of functionality to be useful."},"comment":{"url":"https://api.github.com/repos/rust-embedded/rfcs/issues/comments/258981090","html_url":"https://github.com/rust-embedded/rfcs/issues/19#issuecomment-258981090","issue_url":"https://api.github.com/repos/rust-embedded/rfcs/issues/19","id":258981090,"user":{"login":"jamesmunns","id":2097964,"avatar_url":"https://avatars.githubusercontent.com/u/2097964?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesmunns","html_url":"https://github.com/jamesmunns","followers_url":"https://api.github.com/users/jamesmunns/followers","following_url":"https://api.github.com/users/jamesmunns/following{/other_user}","gists_url":"https://api.github.com/users/jamesmunns/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesmunns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesmunns/subscriptions","organizations_url":"https://api.github.com/users/jamesmunns/orgs","repos_url":"https://api.github.com/users/jamesmunns/repos","events_url":"https://api.github.com/users/jamesmunns/events{/privacy}","received_events_url":"https://api.github.com/users/jamesmunns/received_events","type":"User","site_admin":false},"created_at":"2016-11-07T22:17:26Z","updated_at":"2016-11-07T22:17:26Z","body":"> direct translation of the Arduino API\r\n\r\n> advise against rushing things\r\n\r\nI agree, I don't want to copy it wholesale. I'm still dipping my toes into `futures`, and think it could make sense from the embedded point of view, I guess I was just pushing to get something consistent first, that could grow.\r\n\r\n> non-trivial applications\r\n\r\nI will do my best to rebuild some existing things I have in C and C++ in the embedded space into at least a partially fleshed out set of examples. It might be good to outline what we want here, so that multiple people can outline an apples-to-apples comparison.\r\n\r\nI have started here: https://github.com/jamesmunns/rfcs/tree/add-serial-trait/mock-drivers, which consumes https://github.com/jamesmunns/rfcs/tree/add-serial-trait/trait-apis - though I admit it is pretty shallow. As I mentioned in the pull request discussion, I will break this out into a crate, or set of crates, and we can work from there."}}
{"actor":{"display_login":"jamesmunns"}}