Skip to content

Commit

Permalink
Update docs chapter04_04 even more
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Mar 4, 2024
1 parent ff9613b commit aa987fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
37 changes: 17 additions & 20 deletions examples/chapter04_04/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ of approximately $\frac{1}{2}~\text{Hz}$.

The class hierarchy consists of an LED base class called
[`led_base`](https://github.com/ckormanyos/real-time-cpp/blob/master/examples/chapter04_04/src/mcal_led/mcal_led_base.h#L15).
It is located in namespace `mcal::led`.

Two additional LED classes,
[`led_port`](https://github.com/ckormanyos/real-time-cpp/blob/master/examples/chapter04_04/src/mcal_led/mcal_led_port.h#L17).
It is located in namespace `mcal::led`. Two additional LED classes,
[`led_port`](https://github.com/ckormanyos/real-time-cpp/blob/master/examples/chapter04_04/src/mcal_led/mcal_led_port.h#L17)
and
[`led_pwm`](https://github.com/ckormanyos/real-time-cpp/blob/master/examples/chapter04_04/src/mcal_led/mcal_led_pwm.h#L16),
are derived from the LED base class.
Expand All @@ -27,12 +25,6 @@ These include one microcontroller port and three other ports
located on an external
serial SPI port expander chip of type MICROCHIP(R) MCP23S17.

The PWM-based LED class controls its LED via dimming
its associated PWM duty cycle. Toggling is done by
adjusting the PWM duty cycle back-and-forth,
switching between $0\\%$ and $100\\%$.
There is one instantiation of this port class.

The port expander chip is controlled with SPI.
In this particular example, an all-software bus has been
developed using four microcontroller port pins toggled
Expand All @@ -42,14 +34,19 @@ is derived from a
base class. It provides a uniform interface
for rudimentary byte-read and byte-write functions.

The PWM-based LED class controls its LED via dimming
its associated PWM duty cycle. Toggling is done by
adjusting the PWM duty cycle, switching
back-and-forth between $0\\%$ and $100\\%$.
There is one instantiation of this type of PWM-based LED class.

## Application Description

The application places five LED base class pointers in an
`std::array` and subsequently toggles them in a range-based
`for`-loop in the application task.

The array of LED base class pointers is shown in pseudo-code
below. It is a singleton-object in the `app_led_base_class_array()`
below. It is a singleton-object found in the `app_led_base_class_array()`
subroutine.

```cpp
Expand Down Expand Up @@ -79,7 +76,7 @@ app_led_array_type& app_led_base_class_array()
The application task performs the toggle functionality
at a frequency of approximately $\frac{1}{2}~\text{Hz}$ using
dynamic polymorphism on the elements stored
in the base class pointer container.
in the base class pointer container, as shown below.

```cpp
void app::led::task_func()
Expand All @@ -105,13 +102,13 @@ void app::led::task_func()
The five discrete LEDs in this example are fitted and setup
as shown in the following table.

| LED | Port | Details |
| ---------- | --------------------------- | ---------------------------------------------------------- |
| LED0 | microcontroller `portb.5` | port toggle high / low, $750~\Omega$ |
| LED1 | microcontroller `portb.1` | Timer A, PWM duty cycle $0~{\ldots}~100{\\%}$ |
| LED2 | port expander pin `GPA0` | port toggle high / low, SPI software drive, $750~\Omega$ |
| LED3 | port expander pin `GPA1` | port toggle high / low, SPI software drive, $750~\Omega$ |
| LED4 | port expander pin `GPA2` | port toggle high / low, SPI software drive, $750~\Omega$ |
| LED | Port | Details |
| ---------- | --------------------------- | -------------------------------------------------------- |
| LED0 | microcontroller `portb.5` | port toggle high/low, $750~\Omega$ |
| LED1 | microcontroller `portb.1` | `timer a`, PWM duty cycle $0~{\ldots}~100{\\%}$ |
| LED2 | port expander pin `GPA0` | port toggle high/low, SPI software drive, $750~\Omega$ |
| LED3 | port expander pin `GPA1` | port toggle high/low, SPI software drive, $750~\Omega$ |
| LED4 | port expander pin `GPA2` | port toggle high/low, SPI software drive, $750~\Omega$ |

In this example, we use ports from both the microcontroller as well
as an external port expander chip. Hardware adressing is used
Expand Down
12 changes: 7 additions & 5 deletions examples/chapter04_04a/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
## LED Objects and Polymorphism via References

Example chapter04_04a implements the same basic functionality
as does example chapter04_04. Example chapter04_04a, however,
uses an `std::array` of LED base class references instead
of base class pointers in order to exercise object oriented polymorphism.
as does example
[chapter04_04](https://github.com/ckormanyos/real-time-cpp/tree/master/examples/chapter04_04).
Example chapter04_04a, however,
uses an `std::array` of LED base class _references_ instead
of base class _pointers_ in order to exercise object oriented polymorphism.

## Application Description

Expand All @@ -14,7 +16,7 @@ This is because C++ can not store references in STL containers such as
`std::array`.

The container of wrapped LED base class references is shown in pseudo-code
below. It is a singleton-object in the `app_led_base_class_array()`
below. It is a singleton-object found in the `app_led_base_class_array()`
subroutine.

```cpp
Expand Down Expand Up @@ -42,7 +44,7 @@ app_led_array_type& app_led_base_class_array()
```

The elements in the array of LED base class references
are toggled in the application task each second in the following
are toggled in the application task once per second in the following
fashion.

```cpp
Expand Down

0 comments on commit aa987fe

Please sign in to comment.