-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework micro:bit tests to use Ada Drivers Library.
* test-microbit/buttons.adb: use ADL interrupt facilities. Allow use of either Port or Channel interrupts (Channel is better). * test-microbit/circle.adb: renamed from testbed.adb. Draw a circle round the edge LEDs (the spiral design made it hard to check the speed changes). * test-microbit/event_support.adb: new. * test-microbit/event_support.ads: new. * test-microbit/events.adb: new. * test-microbit/leds.adb: use ADL. * test-microbit/lights.adb: Now that the display only involves edge LEDs, no need for the scale factor. * test-microbit/tests.gpr: renamed from testbed.gpr. * test-microbit/Makefile: build circle (x testbed) and events. * test-microbit/README.md: new.
- Loading branch information
1 parent
122f3d3
commit 37663e5
Showing
10 changed files
with
342 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# micro:bit tests and demos # | ||
|
||
There are three programs built by `make` (or `gprbuild`, but `make` goes on to build hex files that can be dropped onto the micro:bit): | ||
|
||
* `circle` displays a circle running round the LEDs: pressing button A alters the speed, button B alters the direction (clockwise/anticlockwise). The buttons are interrupt-driven. | ||
|
||
* `events` demonstrates `Timing_Events`. The top-left LED (row 1, column 1) flashes every 2 seconds, the LED in row 4, column 5 flashes every 5 seconds. _Why not the bottom right LED? because of the complicated mapping of GPIOs to LEDS_. | ||
|
||
* `seconds` checks out `Clock` functionality by flashing the centre LED once a second. You get to time a number of flashes with a stopwatch to make sure it really is once a second. | ||
|
||
The tests interact with the micro:bit hardware using the [Ada\_Drivers\_Library](https://github.com/AdaCore/Ada_Drivers_Library). Configure it using that library's `project_wizard.py`: | ||
``` | ||
Welcome to the Ada Drivers Library (ADL) project wizard. This script will | ||
ask you some questions to define the ADL configuration of your project. It will | ||
then generate the different files required to use ADL based on this | ||
configuration. | ||
Board | ||
- (0) Custom_Board | ||
- (1) STM32F407_Discovery | ||
- (2) STM32F429_Discovery | ||
- (3) STM32F469_Discovery | ||
- (4) STM32F746_Discovery | ||
- (5) STM32F769_Discovery | ||
- (6) STM32_H405 | ||
- (7) NUCLEO_F446ZE | ||
- (8) Crazyflie | ||
- (9) Feather_STM32F405 | ||
- (10) OpenMV2 | ||
- (11) MicroBit | ||
- (12) NRF52_DK | ||
- (13) HiFive1 | ||
- (14) HiFive1_rev_B | ||
- (15) Unleashed | ||
- (16) Native | ||
? 11 | ||
For key 'Architecture', take value 'ARM' from board definition | ||
For key 'Vendor', take value 'Nordic' from board definition | ||
For key 'Device_Family', take value 'nRF51' from board definition | ||
For key 'Device_Name', take value 'nRF51822xxAA' from board definition | ||
For key 'Number_Of_Interrupts', take value '32' from MCU definition | ||
For key 'Has_ZFP_Runtime', take value 'True' from board definition | ||
For key 'Has_Ravenscar_SFP_Runtime', take value 'False' from board definition | ||
For key 'Has_Ravenscar_Full_Runtime', take value 'False' from board definition | ||
Runtime_Profile | ||
- (0) zfp | ||
? | ||
For key 'Runtime_Name_Suffix', take value 'cortex-m0' from board definition | ||
Runtime_Name [default: 'zfp-cortex-m0'] | ||
? ../../../local/microbit | ||
Use_Startup_Gen [y/N] | ||
Boot_Memory [default: 'flash'] | ||
? | ||
Max_Path_Length [default: 1024] | ||
Max_Mount_Points [default: 2] | ||
Max_Mount_Name_Length [default: 128] | ||
The configuration is now finished. | ||
Let's generate some files: | ||
-> Writing gprbuild project file. | ||
-> Writing the Ada configuration file. | ||
Your Ada Drivers Library project is now ready to use. | ||
``` | ||
After selecting the `MicroBit`, the default (RET) is OK for most answers. The only odd one is that for `Runtime_Name`; the output files are created in the directory `Ada_Drivers_Library`, so the generated `ada_drivers_library.gpr` is one level down, and to select the locally-installed runtime you have to go up three levels and down 2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
-- Copyright (C) 2020 Free Software Foundation, Inc. | ||
|
||
-- This file is part of the Cortex GNAT RTS package. | ||
-- | ||
-- The Cortex GNAT RTS package is free software; you can redistribute | ||
-- it and/or modify it under the terms of the GNU General Public | ||
-- License as published by the Free Software Foundation; either | ||
-- version 3 of the License, or (at your option) any later version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, | ||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
-- General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU General Public License | ||
-- along with this program; see the file COPYING3. If not, see | ||
-- <http://www.gnu.org/licenses/>. | ||
|
||
package body Event_Support is | ||
|
||
protected body LED_Event_Handling is | ||
|
||
procedure Handle | ||
(Event : in out Ada.Real_Time.Timing_Events.Timing_Event) | ||
is | ||
Our_Event : LED_Event | ||
renames LED_Event | ||
(Ada.Real_Time.Timing_Events.Timing_Event'Class (Event)); | ||
New_State : constant Boolean := Our_Event.State; | ||
Flash : constant Milliseconds := 250; | ||
use type Ada.Real_Time.Time; | ||
begin | ||
Set_LEDs (Our_Event.Row, Our_Event.Col) := New_State; | ||
Our_Event.State := not New_State; | ||
LEDs.Clear_All_LEDs; | ||
for R in LEDs.Coord loop | ||
for C in LEDs.Coord loop | ||
if Set_LEDs (R, C) then | ||
LEDs.Set_One_LED (R, C); | ||
end if; | ||
end loop; | ||
end loop; | ||
-- turn off after Flash, turn on after the event's Period | ||
-- minus Flash | ||
Event.Set_Handler | ||
(Handler => Handler, | ||
At_Time => Ada.Real_Time.Clock | ||
+ Ada.Real_Time.Milliseconds (if New_State | ||
then Flash | ||
else Our_Event.Period - Flash)); | ||
end Handle; | ||
|
||
end LED_Event_Handling; | ||
|
||
end Event_Support; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
-- Copyright (C) 2020 Free Software Foundation, Inc. | ||
|
||
-- This file is part of the Cortex GNAT RTS package. | ||
-- | ||
-- The Cortex GNAT RTS package is free software; you can redistribute | ||
-- it and/or modify it under the terms of the GNU General Public | ||
-- License as published by the Free Software Foundation; either | ||
-- version 3 of the License, or (at your option) any later version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, | ||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
-- General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU General Public License | ||
-- along with this program; see the file COPYING3. If not, see | ||
-- <http://www.gnu.org/licenses/>. | ||
|
||
with LEDs; | ||
with Ada.Real_Time.Timing_Events; | ||
package Event_Support is | ||
|
||
subtype Milliseconds is Natural; | ||
|
||
type LED_Event is new Ada.Real_Time.Timing_Events.Timing_Event | ||
with record | ||
Row : LEDs.Coord; | ||
Col : LEDs.Coord; | ||
Period : Milliseconds; | ||
State : Boolean; | ||
end record; | ||
|
||
Slow : LED_Event := | ||
(Ada.Real_Time.Timing_Events.Timing_Event | ||
with 4, 5, 5000, True); | ||
Quick : LED_Event := | ||
(Ada.Real_Time.Timing_Events.Timing_Event | ||
with 1, 1, 2000, True); | ||
|
||
type LEDs_Status is array (LEDs.Coord, LEDs.Coord) of Boolean; | ||
-- (Row, Col) | ||
|
||
protected LED_Event_Handling is | ||
pragma Interrupt_Priority; | ||
procedure Handle | ||
(Event : in out Ada.Real_Time.Timing_Events.Timing_Event); | ||
private | ||
Set_LEDs : LEDs_Status := (others => (others => False)); | ||
end LED_Event_Handling; | ||
|
||
Handler : constant Ada.Real_Time.Timing_Events.Timing_Event_Handler | ||
:= LED_Event_Handling.Handle'Access; | ||
|
||
end Event_Support; |
Oops, something went wrong.