From 373e791693931ca557ef2c7547ca96bfe5be8c20 Mon Sep 17 00:00:00 2001 From: Mirabellensaft Date: Tue, 7 Mar 2023 16:46:03 +0100 Subject: [PATCH] clean text --- embedded-workshop-book/src/bsc-exercise.md | 27 ++++++++++--------- .../src/button-implementation.md | 26 ++++++++++++------ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/embedded-workshop-book/src/bsc-exercise.md b/embedded-workshop-book/src/bsc-exercise.md index a10226a..aed8f7e 100644 --- a/embedded-workshop-book/src/bsc-exercise.md +++ b/embedded-workshop-book/src/bsc-exercise.md @@ -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. diff --git a/embedded-workshop-book/src/button-implementation.md b/embedded-workshop-book/src/button-implementation.md index 045d5ba..96bbd47 100644 --- a/embedded-workshop-book/src/button-implementation.md +++ b/embedded-workshop-book/src/button-implementation.md @@ -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>` @@ -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. + -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 -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. -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. -6. Run the example! \ No newline at end of file +### Step 6: Run the example! + +Go to `/down-the-stack/apps` + +Run the following command: + +```shell +cargo run --bin button +``` \ No newline at end of file