Skip to content

Peripherals Chapter #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 26, 2018
Merged

Peripherals Chapter #15

merged 11 commits into from
Sep 26, 2018

Conversation

jamesmunns
Copy link
Member

  • Still needs heavy expansion and editing
  • Move "singleton" to "peripherals"

@jamesmunns jamesmunns requested a review from a team as a code owner August 22, 2018 01:50
@jamesmunns
Copy link
Member Author

Related to #5, #6, and #2.

I have a four hour flight tomorrow, I hope to bring some more structure and detail to this, it still really looks like presenter notes.

CC @rust-embedded/resources, let me know if you do or do not like the content and structure.

For reference, my conference talk is here: https://ferrous-systems.github.io/rustconf-james-2018

@jamesmunns
Copy link
Member Author

I'd say there are two strategies here:

  • Merge the ugly content, and iteratively fix
  • Close this PR (or leave it unmerged as a reference), and open up separate PRs for each section as it has been prettified.

Open to suggestions, but I'm done for the evening.

}
```

> this goes in your chip crate
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: Make the wording (and presentation) consistent - use "Device Crate", include links to all example crates, consistent structuring.

@thejpster
Copy link
Contributor

I like this. I'd merge it on the grounds that something is better than nothing, and there's definitely value in here even if it does have gaps.

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few nits but otherwise that looks really good to me.

}
```

Although this works it is subjectively a little messy, so the first reaction might be to wrap these related things up in to a `struct` to better organize them. A second attempt could come up with something like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 prepositions after one another are maybe a bit excessive, I'd probably strike up and merge "in" and "to" into "into".


## The Borrow Checker

The last two of these rules sound suspiciously exactly like what the Borrow Checker does already!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"suspiciously exactly like" has a weird ring to it. Maybe "suspiciously similar to"?


## What are Peripherals?

Most Microcontrollers have more than just a CPU, RAM, or Flash Memory - they contain sections of silicon which are used for interacting with systems outside of the microcontroller. These components are collectively known as Peripherals, and are often used to manage communication with sensors, Bluetooth radios, screens, or touch pads.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe be a more general about what peripherals are: They're not just useful for interacting with other systems but to interface with the surroundings in the world, e.g. sensors, actors, humans and other systems.


These peripherals are useful because they allow a developer to offload processing to them, avoiding having to handle everything in software. Similar to how a desktop developer would offload graphics processing to a video card, embedded developers can offload some tasks to peripherals allowing the CPU to spend it's time doing something else important, or doing nothing in order to save power.

However, unlike graphics cards, which typically have a Software API like Vulkan, Metal, or OpenGL, peripherals are exposed to our CPU with a hardware interface, which is mapped to a chunk of the memory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MCU

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My use of CPU here was generally that "MCU = CPU + RAM + Flash + Peripherals" or such. Though, either way I should clarify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree, but there's a certain understanding of what goes into a CPU nowadays and that's a lot more than a plain ALU as it used to be 30 years ago so to avoid confusion I would not use the term CPU.


On a desktop system, access to memory is tightly controlled by the MMU, or Memory Management Unit. This component has two major responsibilities: enforcing access permission to sections of memory (preventing one thread from reading or modifying the memory of another thread); and re-mapping segments of the physical memory to virtual memory ranges used in software. Microcontrollers do not typically have an MMU, and instead only use real physical addresses in software.

Although 32 bit microcontrollers have a real and linear address space from `0x0000_0000`, and `0xFFFF_FFFF`, they generally only use a few hundred kilobytes of that range for actual memory. This leaves a significant about of address space remaining.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount instead of about

CS: OutputPin,
{
/// Creates a new driver from a SPI peripheral
/// and a NCS pin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spell out NCS (or CS) so people can guess what that does

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. This is a direct copy/paste from the embedded hal code. I'll make it more verbose to be readable out of context.

In

```rust
struct GpioPin; struct InputGpio; struct OutputGpio;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fan out and maybe put it in a comment or fictionally import them.

```

* Use type transitions to enforce setup steps
* Like the builder pattern in "normal" rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust -> Rust


```rust
pub struct PushPull; // good for general usage
pub struct OpenDrain; // better for high power LEDs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a MCU the main usage of OpenDrain GPIOs is communication with several devices on one bus. The internal MOSFETs in MCUs typically do not have a very high power rating, often not even higher than what a PP configuration can sink or source and also the maximum power is usually limited by the general sinking capabilities of the MCU which usually is in the order of a few hundred mA.

}
```

* Nested zero sized types are still zero sized, no matter how deep you nest it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it -> them

@jamesmunns jamesmunns changed the title WIP: Add content from my RustConf talk Peripherals Chapter Sep 24, 2018
@jamesmunns
Copy link
Member Author

Reping @rust-embedded/resources, I have stripped this down to just the peripherals chapter, and should be ready to merge if there are no further review comments.

@japaric japaric added T-resources S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 25, 2018
@jamesmunns
Copy link
Member Author

@therealprof addressed changes, dismissing old review

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jamesmunns
Copy link
Member Author

Thanks!

bors r+

bors bot added a commit that referenced this pull request Sep 26, 2018
15: Peripherals Chapter r=jamesmunns a=jamesmunns

* Still needs heavy expansion and editing
* Move "singleton" to "peripherals"

Co-authored-by: James Munns <[email protected]>
Co-authored-by: James Munns <[email protected]>
@jamesmunns jamesmunns removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 26, 2018
@bors
Copy link
Contributor

bors bot commented Sep 26, 2018

Build succeeded

@bors bors bot merged commit 3746885 into master Sep 26, 2018
@bors bors bot deleted the rustconf-dump branch September 26, 2018 13:17
njmartin10 pushed a commit to njmartin10/book that referenced this pull request Nov 10, 2018
15: Peripherals Chapter r=jamesmunns a=jamesmunns

* Still needs heavy expansion and editing
* Move "singleton" to "peripherals"

Co-authored-by: James Munns <[email protected]>
Co-authored-by: James Munns <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants