clean text

This commit is contained in:
Mirabellensaft 2023-03-07 16:46:03 +01:00
parent cd345aad95
commit 373e791693
2 changed files with 32 additions and 21 deletions

View file

@ -15,17 +15,17 @@ Note: Introduction to the exercise is a guided tour through the template, and it
* implement a Trait
* to document and generate docs for your own library!
## Prerequesits
## Prerequisites
[todo!]
*
## Tasks
* Write a button implementation. This entails the following steps
* `struct Buttons` with 4 fields, that represents each of the four buttons
* `struct Button` that is a wrapper for the pin that a single button is connected to
* a method `is_pushed` that checks if a single button is pushed.
* initialize the pins in `fn init()`
* add the `struct Button` to the definition and instantiation of `struct Board`.
* Run `apps/buttons.rs` to test.
`struct Buttons` with 4 fields, that represents each of the four buttons
`struct Button` that is a wrapper for the pin that a single button is connected to
a method `is_pushed` that checks if a single button is pushed.
initialize the pins in `fn init()`
add the `struct Button` to the definition and instantiation of `struct Board`.
Run `apps/buttons.rs` to test.
* Write a UARTE implementation.
## Knowledge
@ -34,18 +34,19 @@ Note: Introduction to the exercise is a guided tour through the template, and it
The boards peripherals are represented as nested structs. The `struct Board` contains fields that represent single peripherals or groups of peripherals as structs, which in turn either contain a field of the single peripheral or ...
You have to add structs to represent the buttons and the UARTE peripheral to the board struct.
[todo!]
## Comments
[todo!]
## impl blocks
## visibility of structs, fields and functions: the pub keyword
[todo!]
## Visibility of structs, fields and functions: the pub keyword
[todo!]
## Hardware documentation for pin configuration
Go to [Nordic Infocenter](https://infocenter.nordicsemi.com/topic/ug_nrf52840_dk/UG/dk/intro.html) to download the User Guide. You can find all the information that is relevant to this exercise in there.

View file

@ -1,11 +1,12 @@
# Write the Button Implementation
## Step-by-Step Solution
1. Read the docs!
Read docs, section 8.7 for info about pins and pin configuration related to the buttons. Note down the pins that the buttons are connected to.
### Step 1: Read the docs!
Go to [Nordic Infocenter](https://infocenter.nordicsemi.com/topic/ug_nrf52840_dk/UG/dk/intro.html) to download the User Guide. Read docs, section 8.7 for info about pins and pin configuration related to the buttons. Note down the pins that the buttons are connected to.
The pins need to be configured as input pins with an internal pull-up. The pins as well as the configurations are defined as types in the `nrf-hal` in the `gpio` peripheral. Add the following imports: `Input` and `PullUp`.
2. Add the structs that represent the buttons as a group and a generic single button.
### Step 2: Add the structs that represent the buttons as a group and a generic single button.
Add the struct that represents the single button. It has only one field, `inner`. The type of this button is the pin configuration: `Pin<Input<PullUp>>`
@ -13,10 +14,11 @@ Add the `struct` that represents the group of buttons has four fields, one for e
Add doc comments for every struct and field!
Building this code should return a warning: field `inner` is never read
Building this code should return a warning: field `inner` is never read.
<!-- Solution Code Snippet -->
1. Implement the button function.
### Step 3: Implement the button function.
Add an `impl` block for the `struct Button`. Add a method `is_pushed` that takes in the struct as `&self` and returns a bool, if the button is pushed.
@ -27,18 +29,26 @@ In the `nrf-hal` you can find a method to check if a single pin is low. To use i
<!-- Solution Code Snippet -->
4. Bring up the pins!
### Step 4: Bring up the pins!
Go to `pub fn init()`, the function that initializes the board's peripherals. Get your notes for the pin numbers that are reserver for the buttons. Configure each pin as degraded, pull-up input pin and bind it to a variable that makes it clear what button number it is connected to.
Building this code brings up warnings about unused variables.
<!-- Solution Code Snippet -->
5. Add everything to the board struct.
### Step 5: Add everything to the board struct.
In the definition of the board struct add a field for the `struct Buttons`
In the pub `fn init()` function. Add the button field to the instantiation of the Board struct, assigning the pins you defined earlier to the respective buttons.
<!-- Solution Code Snippet -->
6. Run the example!
### Step 6: Run the example!
Go to `/down-the-stack/apps`
Run the following command:
```shell
cargo run --bin button
```