Skip to content

Commit

Permalink
examples/leds_shell: code refactoring-one led and gpio commands
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-cabaj committed Jul 16, 2024
1 parent 4273f97 commit 8d9af20
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 335 deletions.
32 changes: 1 addition & 31 deletions examples/leds_shell/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
####
#### Sample Makefile for building applications with the RIOT OS
####
#### The example file system layout is:
#### ./application Makefile
#### ../../RIOT
####

# Set the name of your application:
APPLICATION = leds_shell

Expand All @@ -15,17 +7,10 @@ BOARD ?= native
# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../../

# Uncomment this to enable scheduler statistics for ps:
#CFLAGS += -DSCHEDSTATISTICS

# If you want to use native with valgrind, you should recompile native
# with the target all-valgrind instead of all:
# make -B clean all-valgrind

# Uncomment this to enable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
#DEVELHELP = 1
DEVELHELP = 1

# Change this to 0 to show compiler invocation lines by default:
QUIET ?= 1
Expand All @@ -34,19 +19,4 @@ QUIET ?= 1
USEMODULE += shell
USEMODULE += periph_gpio

# If your application is very simple and doesn't use modules that use
# messaging, it can be disabled to save some memory:

#DISABLE_MODULE += core_msg

#INCLUDES += -Iapplication_include

# Specify custom dependencies for your application here ...
# APPDEPS = app_data.h config.h

include $(RIOTBASE)/Makefile.include

# ... and define them here (after including Makefile.include,
# otherwise you modify the standard target):
#proj_data.h: script.py data.tar.gz
# ./script.py
69 changes: 22 additions & 47 deletions examples/leds_shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

The application `leds_shell` is a basic example, which allows easy, interactive
control of internal board LEDs, and basic GPIO for externally connected simple
devices (for e.g. additional LEDs, relay, motors - via dedicated drivers, etc.).
devices (for e.g. additional LEDs, relay, motors - via dedicated drivers, etc.)
via the shell.

In particular, this example shows:
- on/off and toggle internal board LEDs.
Expand All @@ -15,44 +16,24 @@ In particular, this example shows:

The following commands are available:

- `led0`, `led1` ... `led7`: allows switching on/off or toggle internal board
LEDs. Number of commands depends on internal LEDs number.
- `init`: call before interact with GPIO port to initialize chosen port in
output mode, which allows setting it to HIGH or LOW state.
- `set`: sets GPIO port state to HIGH.
- `clear`: sets GPIO port stet to LOW.
- `led`: allows switching on/off or toggle internal board LEDs.
- `gpio`: allows initialization of GPIO port and set state to HIGH/LOW.
- `help`: default RIOT command, which shows available commands.

## Example on `native`
## Usage on `BOARD=native`

- Build and run `LEDs` example application on the `native` target,
- Build and run `leds_shell` example application on the `native` target,
as Linux application:

```
$ make term
$ make all term
[...]
RIOT native interrupts/signals initialized.
RIOT native board initialized.
RIOT native hardware initialization complete.
main(): This is RIOT! (Version: 2021.07-devel-10893-gb2e97-example-leds_shell)
leds_shell, version 1.0.0
>
```

Or run it directly without terminal. Go to `RIOT/examples/leds_shell` and run
commands:

```
$ make
[...]
$ ./bin/native/leds_shell.elf
RIOT native interrupts/signals initialized.
RIOT native board initialized.
RIOT native hardware initialization complete.
main(): This is RIOT! (Version: 2021.07-devel-10893-gb2e97-example-leds_shell)
leds_shell, version 1.0.0
This board has 2 LEDs
>
```

Expand All @@ -62,45 +43,39 @@ leds_shell, version 1.0.0
help
Command Description
---------------------------------------
init GPIO pin initialization
set Set GPIO pin to HIGH
clear Set GPIO pin to LOW
led0 Switch on/off on-board LED0
led1 Switch on/off on-board LED1
gpio GPIO pin initialization and set port state HIGH/LOW
led Switch on/off or toggle on-board LEDs
```

- Enable internal LED0 and LED1 (the `native` target has two virtual LEDs):

```
> led0 on
led0 on
> led 0 on
led 0 on
LED_RED_ON
> led1 on
led1 on
> led 1 on
led 1 on
LED_GREEN_ON
```
## Example on sample board - stm32f469i-disco
## Usage on actual hardware - `BOARD=stm32f469i-disco`

- Build and flash `leds_shell` example application on sample board, for example
`stm32f469i-disco` target, which has 4 internal LEDs:

```
$ make BOARD=stm32f469i-disco flash term
$ make all BOARD=stm32f469i-disco flash term
[...]
main(): This is RIOT! (Version: 2021.07-devel-10894-g2ad22b9-example-leds_shell)
leds_shell, version 1.0.0
This board has 4 LEDs
> help
help
Command Description
---------------------------------------
init GPIO pin initialization
set Set GPIO pin to HIGH
clear Set GPIO pin to LOW
led0 Switch on/off on-board LED0
led1 Switch on/off on-board LED1
led2 Switch on/off on-board LED2
led3 Switch on/off on-board LED3
gpio GPIO pin initialization and set port state HIGH/LOW
led Switch on/off or toggle on-board LEDs
```

- Switch on/off internal LEDs using commands `led0`, `led1`, `led2` or `led3`.
- Switch on/off internal LEDs using `led` command and appropriate LED id.
- Initialize GPIO port using `gpio init`.
- Change state of GPIO port using `gpio set` and `gpio clear`.
Loading

0 comments on commit 8d9af20

Please sign in to comment.