mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 16:25:37 +00:00
clean text
This commit is contained in:
parent
cd345aad95
commit
373e791693
2 changed files with 32 additions and 21 deletions
|
@ -15,17 +15,17 @@ Note: Introduction to the exercise is a guided tour through the template, and it
|
||||||
* implement a Trait
|
* implement a Trait
|
||||||
* to document and generate docs for your own library!
|
* to document and generate docs for your own library!
|
||||||
|
|
||||||
## Prerequesits
|
## Prerequisites
|
||||||
|
[todo!]
|
||||||
|
|
||||||
*
|
|
||||||
## Tasks
|
## Tasks
|
||||||
* Write a button implementation. This entails the following steps
|
* Write a button implementation. This entails the following steps
|
||||||
* `struct Buttons` with 4 fields, that represents each of the four buttons
|
✅ `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
|
✅ `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.
|
✅ a method `is_pushed` that checks if a single button is pushed.
|
||||||
* initialize the pins in `fn init()`
|
✅ initialize the pins in `fn init()`
|
||||||
* add the `struct Button` to the definition and instantiation of `struct Board`.
|
✅ add the `struct Button` to the definition and instantiation of `struct Board`.
|
||||||
* Run `apps/buttons.rs` to test.
|
✅ Run `apps/buttons.rs` to test.
|
||||||
* Write a UARTE implementation.
|
* Write a UARTE implementation.
|
||||||
|
|
||||||
## Knowledge
|
## 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 ...
|
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.
|
You have to add structs to represent the buttons and the UARTE peripheral to the board struct.
|
||||||
|
[todo!]
|
||||||
|
|
||||||
## Comments
|
## Comments
|
||||||
|
[todo!]
|
||||||
|
|
||||||
## impl blocks
|
## impl blocks
|
||||||
|
[todo!]
|
||||||
## visibility of structs, fields and functions: the pub keyword
|
## Visibility of structs, fields and functions: the pub keyword
|
||||||
|
[todo!]
|
||||||
|
|
||||||
## Hardware documentation for pin configuration
|
## 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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
# Write the Button Implementation
|
# Write the Button Implementation
|
||||||
## Step-by-Step Solution
|
## Step-by-Step Solution
|
||||||
|
|
||||||
1. Read the docs!
|
### Step 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.
|
|
||||||
|
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`.
|
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>>`
|
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!
|
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 -->
|
<!-- 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.
|
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 -->
|
<!-- 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.
|
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.
|
Building this code brings up warnings about unused variables.
|
||||||
<!-- Solution Code Snippet -->
|
<!-- 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 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.
|
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 -->
|
<!-- 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
|
||||||
|
```
|
Loading…
Reference in a new issue