Compare commits
18 Commits
e4e1148eb9
...
503ec28492
Author | SHA1 | Date |
---|---|---|
Maxim Reznik | 503ec28492 | |
Maxim Reznik | 22ae2aea53 | |
Maxim Reznik | 4615730b4e | |
Maxim Reznik | 580945562d | |
Maxim Reznik | 3d584b8f9b | |
Maxim Reznik | 724b7462a4 | |
Maxim Reznik | 7232cb4069 | |
Maxim Reznik | 945dde1dbc | |
Maxim Reznik | b60639de8b | |
Maxim Reznik | 639e9031fb | |
Maxim Reznik | fd4e628835 | |
Maxim Reznik | f79cd470a0 | |
Maxim Reznik | dfbc15d772 | |
Maxim Reznik | 5712224102 | |
Maxim Reznik | 0aaf152c5b | |
Maxim Reznik | 51e21e7160 | |
Maxim Reznik | 2e50b6885c | |
Maxim Reznik | 31e36cf1c2 |
|
@ -32,6 +32,7 @@ jobs:
|
|||
|
||||
- run: python3 $PWD/scripts/build_all_examples.py
|
||||
- run: python3 $PWD/testsuite/run.py
|
||||
- run: python3 $PWD/scripts/check_readme.py
|
||||
|
||||
win-build:
|
||||
name: Build and test on Windows
|
||||
|
|
45
README.md
45
README.md
|
@ -15,6 +15,51 @@ Ada_Drivers_Library provides support for various devices in the ARM Cortex-M
|
|||
and RISC-V architectures. Some devices are only partially supported. Go to the
|
||||
[boards directory](boards/) for a list of supported hardware.
|
||||
|
||||
## Board list
|
||||
|
||||
| Arch | Board |
|
||||
| ------ | --------------------- |
|
||||
| ARM | [STM32F407_Discovery] |
|
||||
| ARM | [STM32F429_Discovery] |
|
||||
| ARM | [STM32F469_Discovery] |
|
||||
| ARM | [STM32F4XX_M] |
|
||||
| ARM | [STM32_F4VE] |
|
||||
| ARM | [STM32F746_Discovery] |
|
||||
| ARM | [STM32F769_Discovery] |
|
||||
| ARM | [STM32_H405] |
|
||||
| ARM | [NUCLEO_F446ZE] |
|
||||
| ARM | [Crazyflie] |
|
||||
| ARM | [Feather_STM32F405] |
|
||||
| ARM | [OpenMV2] |
|
||||
| ARM | [MicroBit] |
|
||||
| ARM | [NRF52_DK] |
|
||||
| RISC-V | [HiFive1] |
|
||||
| RISC-V | [HiFive1_rev_B] |
|
||||
| RISC-V | [Unleashed] |
|
||||
| | [Native] |
|
||||
|
||||
<!-- Examples: -->
|
||||
[HiFive1]: examples/HiFive1/README.md
|
||||
[HiFive1_rev_B]: examples/HiFive1_rev_B/README.md
|
||||
[MicroBit]: examples/MicroBit/README.md
|
||||
[NRF52_DK]: examples/NRF52_DK/README.md
|
||||
[OpenMV2]: examples/OpenMV2/README.md
|
||||
[STM32F429_Discovery]: examples/STM32F429_Discovery/README.md
|
||||
[STM32F469_Discovery]: examples/STM32F469_Discovery/README.md
|
||||
[STM32F407_Discovery]: examples/STM32F4_DISCO/README.md
|
||||
[STM32_F4VE]: examples/stm32_f4ve/README.md
|
||||
[STM32F4XX_M]: examples/stm32f4xx_m/README.md
|
||||
[STM32F746_Discovery]: examples/STM32F746_Discovery/README.md
|
||||
[STM32F769_Discovery]: examples/STM32F769_Discovery/README.md
|
||||
|
||||
<!-- Undocumented: -->
|
||||
[STM32_H405]: examples/stm32_h405/
|
||||
[NUCLEO_F446ZE]: examples/nucleo_f446ze/
|
||||
[Feather_STM32F405]: examples/feather_stm32f405
|
||||
[Crazyflie]: boards/crazyflie/
|
||||
[Unleashed]: examples/Unleashed
|
||||
[Native]: boards/native
|
||||
|
||||
# 3. Getting started
|
||||
|
||||
To start using the Ada_Drivers_Library, please go to the [examples
|
||||
|
|
|
@ -727,6 +727,24 @@ package body STM32.Device is
|
|||
RCC_Periph.AHB2RSTR.DCMIRST := False;
|
||||
end Reset_DCMI;
|
||||
|
||||
-----------------------
|
||||
-- Enable_FSMC_Clock --
|
||||
-----------------------
|
||||
|
||||
procedure Enable_FSMC_Clock is
|
||||
begin
|
||||
STM32_SVD.RCC.RCC_Periph.AHB3ENR.FSMCEN := True;
|
||||
end Enable_FSMC_Clock;
|
||||
|
||||
------------------------
|
||||
-- Disable_FSMC_Clock --
|
||||
------------------------
|
||||
|
||||
procedure Disable_FSMC_Clock is
|
||||
begin
|
||||
STM32_SVD.RCC.RCC_Periph.AHB3ENR.FSMCEN := False;
|
||||
end Disable_FSMC_Clock;
|
||||
|
||||
------------------
|
||||
-- Enable_Clock --
|
||||
------------------
|
||||
|
|
|
@ -417,6 +417,12 @@ package STM32.Device is
|
|||
procedure Enable_Clock (This : in out SDMMC_Controller);
|
||||
procedure Reset (This : in out SDMMC_Controller);
|
||||
|
||||
procedure Set_Clock_Source
|
||||
(This : in out SDMMC_Controller;
|
||||
Src : SDIO_Clock_Source) is null;
|
||||
-- On this MCU SDIO clock source can't be changed, but this routine is
|
||||
-- used in SDCard_Controller initialization code.
|
||||
|
||||
---------
|
||||
-- CRC --
|
||||
---------
|
||||
|
@ -429,6 +435,13 @@ package STM32.Device is
|
|||
|
||||
procedure Reset (This : in out CRC_32);
|
||||
|
||||
----------
|
||||
-- FSMC --
|
||||
----------
|
||||
|
||||
procedure Enable_FSMC_Clock;
|
||||
procedure Disable_FSMC_Clock;
|
||||
|
||||
-----------------------------
|
||||
-- Reset and Clock Control --
|
||||
-----------------------------
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# Flexible static memory controller (FSMC)
|
||||
|
||||
This component of STM32F40x/41x processors allows for the management
|
||||
of static memory, flash memory, and PC Cards. Unlike the FMC in more
|
||||
advanced MCU models, dynamic memory is not supported. Each type of
|
||||
memory has its address bank. The controller offers flexible settings
|
||||
for various operating modes. For instance, extended modes can have
|
||||
different delays set for read and write operations. It is recommended
|
||||
to refer to the STM32 Reference Manual (RM0090) for a detailed description
|
||||
of possible modes and corresponding settings.
|
||||
|
||||
* [Datasheet](https://www.st.com/resource/en/reference_manual/dm00031020-stm32f405-415-stm32f407-417-stm32f427-437-and-stm32f429-439-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf) - STM32 Reference Manual (RM0090), FSMC chapter.
|
||||
|
||||
* [Configuration example](../../../../../boards/stm32_f4ve/src/display_ili9341.adb) - display_ili9341.adb:
|
||||
|
||||
## Example
|
||||
|
||||
Configuring Bank_1 for ILI9341 LCD controller:
|
||||
|
||||
* half word (16 bit access)
|
||||
* with write enabled
|
||||
* distinct read and write timings
|
||||
|
||||
```ada
|
||||
STM32.FSMC.Configure
|
||||
(Bank_1 =>
|
||||
(1 => -- TFT is connected to sub-bank 1
|
||||
(Is_Set => True,
|
||||
Value =>
|
||||
(Write_Enable => True,
|
||||
Bus_Width => STM32.FSMC.Half_Word,
|
||||
Memory_Type => STM32.FSMC.SRAM,
|
||||
Bus_Turn => 15, -- 90ns
|
||||
Data_Setup => 57, -- 342ns
|
||||
Address_Setup => 0,
|
||||
Extended =>
|
||||
(STM32.FSMC.Mode_A,
|
||||
Write_Bus_Turn => 3, -- 18ns
|
||||
Write_Data_Setup => 2, -- 12ns
|
||||
Write_Address_Setup => 0),
|
||||
others => <>)),
|
||||
others => <>));
|
||||
```
|
|
@ -0,0 +1,140 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with STM32_SVD.FSMC;
|
||||
|
||||
package body STM32.FSMC is
|
||||
|
||||
type BCR_BTR is record
|
||||
BCR : STM32_SVD.FSMC.BCR_Register;
|
||||
-- SRAM/NOR-Flash chip-select timing register
|
||||
BTR : STM32_SVD.FSMC.BTR_Register;
|
||||
-- SRAM/NOR-Flash chip-select control register
|
||||
end record
|
||||
with Volatile;
|
||||
|
||||
for BCR_BTR use record
|
||||
BCR at 16#0# range 0 .. 31;
|
||||
BTR at 16#4# range 0 .. 31;
|
||||
end record;
|
||||
|
||||
type BCR_BTR_Array is array (1 .. 4) of BCR_BTR;
|
||||
|
||||
---------------
|
||||
-- Configure --
|
||||
---------------
|
||||
|
||||
procedure Configure
|
||||
(Bank_1 : Bank_1_Configuration := (1 .. 4 => (Is_Set => False));
|
||||
Bank_2 : NAND_PC_Card_Configuration := (Is_Set => False);
|
||||
Bank_3 : NAND_PC_Card_Configuration := (Is_Set => False);
|
||||
Bank_4 : NAND_PC_Card_Configuration := (Is_Set => False))
|
||||
is
|
||||
pragma Unreferenced (Bank_2, Bank_3, Bank_4);
|
||||
BCR_BTR_List : BCR_BTR_Array
|
||||
with Import, Address => STM32_SVD.FSMC.FSMC_Periph.BCR1'Address;
|
||||
|
||||
BWTR_List : array (1 .. 4) of STM32_SVD.FSMC.BWTR_Register
|
||||
with Import, Address => STM32_SVD.FSMC.FSMC_Periph.BWTR1'Address;
|
||||
begin
|
||||
for X in Bank_1'Range loop
|
||||
declare
|
||||
pragma Warnings (Off, "is not referenced");
|
||||
-- GNAT GCC 12.2 gives a wrong warning here
|
||||
BCR : STM32_SVD.FSMC.BCR_Register renames BCR_BTR_List (X).BCR;
|
||||
BTR : STM32_SVD.FSMC.BTR_Register renames BCR_BTR_List (X).BTR;
|
||||
pragma Warnings (On, "is not referenced");
|
||||
BWTR : STM32_SVD.FSMC.BWTR_Register renames BWTR_List (X);
|
||||
begin
|
||||
if Bank_1 (X).Is_Set then
|
||||
declare
|
||||
Value : Asynchronous_Configuration renames Bank_1 (X).Value;
|
||||
begin
|
||||
BCR :=
|
||||
(MBKEN => True,
|
||||
MUXEN => False,
|
||||
MTYP => Memory_Type'Pos (Value.Memory_Type),
|
||||
MWID => Memory_Bus_Width'Pos (Value.Bus_Width),
|
||||
FACCEN => Value.Memory_Type = NOR_Flash,
|
||||
Reserved_7_7 => 1,
|
||||
BURSTEN => False,
|
||||
WAITPOL => Value.Wait_Signal = Positive,
|
||||
WRAPMOD => False,
|
||||
WAITCFG => False,
|
||||
WREN => Value.Write_Enable,
|
||||
WAITEN => False,
|
||||
EXTMOD => Value.Extended.Mode /= None,
|
||||
ASYNCWAIT => Value.Wait_Signal /= None,
|
||||
Reserved_16_18 => 0,
|
||||
CBURSTRW => False,
|
||||
Reserved_20_31 => 0);
|
||||
|
||||
BTR :=
|
||||
(ADDSET => HAL.UInt4 (Value.Address_Setup),
|
||||
ADDHLD =>
|
||||
(if Value.Extended.Mode = Mode_D
|
||||
then HAL.UInt4 (Value.Extended.Read_Address_Hold)
|
||||
else 0),
|
||||
DATAST => HAL.UInt8 (Value.Data_Setup),
|
||||
BUSTURN => HAL.UInt4 (Value.Bus_Turn),
|
||||
CLKDIV => 0,
|
||||
DATLAT => 0,
|
||||
ACCMOD =>
|
||||
(if Value.Extended.Mode = None then 0
|
||||
else Asynchronous_Extended_Mode'Pos
|
||||
(Value.Extended.Mode)),
|
||||
Reserved_30_31 => 3);
|
||||
|
||||
if Value.Extended.Mode /= None then
|
||||
BWTR :=
|
||||
(ADDSET =>
|
||||
HAL.UInt4 (Value.Extended.Write_Address_Setup),
|
||||
ADDHLD =>
|
||||
(if Value.Extended.Mode = Mode_D
|
||||
then HAL.UInt4 (Value.Extended.Write_Address_Hold)
|
||||
else 0),
|
||||
DATAST =>
|
||||
HAL.UInt8 (Value.Extended.Write_Data_Setup),
|
||||
Reserved_16_19 => 16#F#,
|
||||
CLKDIV => 0,
|
||||
DATLAT => 0,
|
||||
ACCMOD => 0,
|
||||
Reserved_30_31 => 0);
|
||||
end if;
|
||||
end;
|
||||
else
|
||||
BCR.MBKEN := False;
|
||||
end if;
|
||||
end;
|
||||
end loop;
|
||||
end Configure;
|
||||
|
||||
end STM32.FSMC;
|
|
@ -0,0 +1,137 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- Flexible Static Memory Controller in STM32F40x/41x family
|
||||
|
||||
with System;
|
||||
|
||||
package STM32.FSMC is
|
||||
|
||||
subtype Clock_Cycle_Count is Natural;
|
||||
-- Number of AHB clock cycles (HCLK)
|
||||
|
||||
-- Bank 1 supports NOR Flash, PSRAM and SRAM.
|
||||
type Memory_Type is (SRAM, PSRAM, NOR_Flash);
|
||||
type Memory_Bus_Width is (Byte, Half_Word); -- 8 or 16 bit
|
||||
type Signal_Kind is (None, Positive, Negative);
|
||||
|
||||
type Asynchronous_Extended_Mode is (Mode_A, Mode_B, Mode_C, Mode_D, None);
|
||||
-- See extended mode definitions in STM32F40x/41x datasheet.
|
||||
-- None corresponds to Mode 1 or Mode 2 depending on the type of memory.
|
||||
-- Extended modes have a dedicated settings for write operations, while
|
||||
-- Mode 1, 2 have shared settings for read/write.
|
||||
|
||||
type Asynchronous_Extended_Configuration
|
||||
(Mode : Asynchronous_Extended_Mode := None) is
|
||||
record
|
||||
case Mode is
|
||||
when None =>
|
||||
null;
|
||||
|
||||
when others =>
|
||||
Write_Bus_Turn : Clock_Cycle_Count range 0 .. 15;
|
||||
Write_Data_Setup : Clock_Cycle_Count range 1 .. 256;
|
||||
Write_Address_Setup : Clock_Cycle_Count range 0 .. 15;
|
||||
|
||||
case Mode is
|
||||
when Mode_D =>
|
||||
Read_Address_Hold : Clock_Cycle_Count range 0 .. 15;
|
||||
Write_Address_Hold : Clock_Cycle_Count range 0 .. 15;
|
||||
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end case;
|
||||
end record;
|
||||
|
||||
type Asynchronous_Configuration is record
|
||||
Wait_Signal : Signal_Kind := None;
|
||||
Write_Enable : Boolean := False;
|
||||
Bus_Width : Memory_Bus_Width := Byte;
|
||||
Memory_Type : FSMC.Memory_Type;
|
||||
Bus_Turn : Clock_Cycle_Count range 0 .. 15 := 15;
|
||||
Data_Setup : Clock_Cycle_Count range 1 .. 255 := 255;
|
||||
Address_Setup : Clock_Cycle_Count range 0 .. 15 := 15;
|
||||
|
||||
Extended : Asynchronous_Extended_Configuration := (Mode => None);
|
||||
-- Additional settings
|
||||
end record;
|
||||
-- Configuration of the subbank of Bank 1. Not every combination of memory
|
||||
-- type and extended mode is allowed. Corresponding predicate is:
|
||||
-- with Predicate =>
|
||||
-- (if Memory_Type = NOR_Flash then Extended.Mode /= Mode_A
|
||||
-- else Extended.Mode not in Mode_B | Mode_C);
|
||||
|
||||
type NOR_PSRAM_Configuration (Is_Set : Boolean := False) is record
|
||||
case Is_Set is
|
||||
when True =>
|
||||
Value : Asynchronous_Configuration;
|
||||
when False =>
|
||||
null;
|
||||
end case;
|
||||
end record;
|
||||
|
||||
subtype Subbank_Index is Integer range 1 .. 4;
|
||||
-- Bank 1 has 4 sub-banks
|
||||
|
||||
type Bank_1_Configuration is array (Subbank_Index) of NOR_PSRAM_Configuration;
|
||||
|
||||
type NAND_PC_Card_Configuration (Is_Set : Boolean := False) is record
|
||||
null; -- TBD
|
||||
end record;
|
||||
-- Bank 2, 3 supports NAND flash, Bank 4 - PC Card
|
||||
-- These are not yet implemented
|
||||
|
||||
procedure Configure
|
||||
(Bank_1 : Bank_1_Configuration := (1 .. 4 => (Is_Set => False));
|
||||
Bank_2 : NAND_PC_Card_Configuration := (Is_Set => False);
|
||||
Bank_3 : NAND_PC_Card_Configuration := (Is_Set => False);
|
||||
Bank_4 : NAND_PC_Card_Configuration := (Is_Set => False));
|
||||
-- Configure memory banks
|
||||
|
||||
function Bank_1_Start
|
||||
(Subbank : Subbank_Index := 1) return System.Address is
|
||||
(case Subbank is
|
||||
when 1 => System'To_Address (16#6000_0000#),
|
||||
when 2 => System'To_Address (16#6400_0000#),
|
||||
when 3 => System'To_Address (16#6800_0000#),
|
||||
when 4 => System'To_Address (16#6C00_0000#));
|
||||
|
||||
Bank_2_Start : constant System.Address :=
|
||||
System'To_Address (16#7000_0000#);
|
||||
|
||||
Bank_3_Start : constant System.Address :=
|
||||
System'To_Address (16#8000_0000#);
|
||||
|
||||
Bank_4_Start : constant System.Address :=
|
||||
System'To_Address (16#9000_0000#);
|
||||
|
||||
end STM32.FSMC;
|
|
@ -105,6 +105,7 @@ library project NUCLEO_F446ZE_Full is
|
|||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
|
|
|
@ -105,6 +105,7 @@ library project NUCLEO_F446ZE_SFP is
|
|||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
|
|
|
@ -47,6 +47,15 @@ package body SDCard is
|
|||
(Interrupt_ID => SD_Interrupt,
|
||||
Priority => System.Interrupt_Priority'Last);
|
||||
|
||||
-----------------------
|
||||
-- Has_SD_Detect_Pin --
|
||||
-----------------------
|
||||
|
||||
function Has_SD_Detect_Pin return Boolean is
|
||||
begin
|
||||
return (for all Pin of SD_Pins => Pin.Pin /= SD_Detect_Pin.Pin);
|
||||
end Has_SD_Detect_Pin;
|
||||
|
||||
----------------
|
||||
-- Initialize --
|
||||
----------------
|
||||
|
@ -78,12 +87,19 @@ package body SDCard is
|
|||
Resistors => Pull_Up));
|
||||
|
||||
-- GPIO configuration for the SD-Detect pin
|
||||
Configure_IO
|
||||
(SD_Detect_Pin,
|
||||
(Mode => Mode_In,
|
||||
-- Output_Type => Open_Drain,
|
||||
-- Speed => Speed_High,
|
||||
Resistors => Pull_Up));
|
||||
if Has_SD_Detect_Pin then
|
||||
Configure_IO
|
||||
(SD_Detect_Pin,
|
||||
(Mode => Mode_In,
|
||||
Resistors => Pull_Up));
|
||||
else
|
||||
Configure_IO
|
||||
(SD_Detect_Pin,
|
||||
(Mode => Mode_In,
|
||||
Resistors => Pull_Down));
|
||||
|
||||
This.Card_Detected := False;
|
||||
end if;
|
||||
|
||||
-- Enable the SDIO clock
|
||||
STM32.Device.Enable_Clock (This.Device.all);
|
||||
|
@ -140,8 +156,30 @@ package body SDCard is
|
|||
function Card_Present
|
||||
(This : in out SDCard_Controller) return Boolean
|
||||
is
|
||||
function Card_Detect return Boolean;
|
||||
-- Check SD_Detect_Pin depending on the presence of a dedicated pin
|
||||
|
||||
-----------------
|
||||
-- Card_Detect --
|
||||
-----------------
|
||||
|
||||
function Card_Detect return Boolean is
|
||||
begin
|
||||
if Has_SD_Detect_Pin then
|
||||
-- We have a dedicated pin.
|
||||
return not STM32.GPIO.Set (SD_Detect_Pin);
|
||||
elsif This.Card_Detected then
|
||||
-- We have no dedicated pin.
|
||||
-- In normal operation mode no detection is possible.
|
||||
return True;
|
||||
else
|
||||
-- We have no dedicated pin. Check DAT3 pin
|
||||
return STM32.GPIO.Set (SD_Detect_Pin);
|
||||
end if;
|
||||
end Card_Detect;
|
||||
|
||||
begin
|
||||
if STM32.GPIO.Set (SD_Detect_Pin) then
|
||||
if not Card_Detect then
|
||||
-- No card
|
||||
This.Device.Clear_Card_Information;
|
||||
This.Card_Detected := False;
|
||||
|
@ -152,7 +190,21 @@ package body SDCard is
|
|||
delay until Clock + Milliseconds (50);
|
||||
end if;
|
||||
|
||||
This.Card_Detected := not STM32.GPIO.Set (SD_Detect_Pin);
|
||||
if Has_SD_Detect_Pin then
|
||||
This.Card_Detected := Card_Detect;
|
||||
|
||||
elsif not This.Card_Detected and Card_Detect then
|
||||
-- Reconfigure the SD_Detect_Pin pin to SDIO function
|
||||
Configure_IO
|
||||
(SD_Detect_Pin,
|
||||
(Mode => Mode_AF,
|
||||
AF => SD_Pins_AF,
|
||||
AF_Output_Type => Push_Pull,
|
||||
AF_Speed => Speed_High,
|
||||
Resistors => Pull_Up));
|
||||
|
||||
This.Card_Detected := True;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
return This.Card_Detected;
|
||||
|
|
|
@ -53,6 +53,19 @@ package SDCard is
|
|||
function Card_Present
|
||||
(This : in out SDCard_Controller) return Boolean;
|
||||
-- Whether a SD-Card is present in the sdcard reader
|
||||
--
|
||||
-- If there is no separate pin on the device for card detection, then a pin
|
||||
-- shared with the data transmission line is used. In this case, card
|
||||
-- detection cannot work simultaneously with other subprograms, and caution
|
||||
-- is required when using it. In this configuration, the card detection
|
||||
-- mode operates immediately after the Initialize function is called until
|
||||
-- the Card_Present function returns True. From that moment on, the
|
||||
-- controller switches to normal operation mode, and the Card_Present
|
||||
-- function will keep returning True until the next Initialize function
|
||||
-- call.
|
||||
|
||||
function Has_SD_Detect_Pin return Boolean;
|
||||
-- Whether the dedicated SD card detection pin is present on the device
|
||||
|
||||
function Get_Card_Information
|
||||
(This : in out SDCard_Controller)
|
||||
|
|
|
@ -38,6 +38,8 @@ with STM32.SPI; use STM32.SPI;
|
|||
|
||||
with HAL.SPI;
|
||||
|
||||
with Ravenscar_Time;
|
||||
|
||||
package body Framebuffer_ILI9341 is
|
||||
|
||||
LCD_SPI : SPI_Port renames SPI_5;
|
||||
|
@ -114,8 +116,9 @@ package body Framebuffer_ILI9341 is
|
|||
|
||||
Configure_Alternate_Function (LCD_RGB_AF9, GPIO_AF_LTDC_9);
|
||||
|
||||
-- Set LCD_CSX: Chip Unselect
|
||||
-- Set LCD_CSX: Chip Unselect, LCD_RESET - inactive
|
||||
Set (LCD_CSX);
|
||||
Set (LCD_RESET);
|
||||
end LCD_Pins_Init;
|
||||
|
||||
|
||||
|
@ -131,7 +134,7 @@ package body Framebuffer_ILI9341 is
|
|||
begin
|
||||
LCD_Pins_Init;
|
||||
LCD_SPI_Init;
|
||||
Display.Device.Initialize (ILI9341.RGB_Mode);
|
||||
Display.Device.Initialize (Ravenscar_Time.Delays);
|
||||
Display.Initialize
|
||||
(Width => LCD_WIDTH,
|
||||
Height => LCD_HEIGHT,
|
||||
|
|
|
@ -31,10 +31,11 @@
|
|||
|
||||
with HAL; use HAL;
|
||||
with HAL.Framebuffer; use HAL.Framebuffer;
|
||||
with Ravenscar_Time;
|
||||
|
||||
with Framebuffer_LTDC;
|
||||
private with ILI9341;
|
||||
private with ILI9341.Device;
|
||||
private with ILI9341.SPI_Connector;
|
||||
|
||||
private with STM32.GPIO;
|
||||
private with STM32.Device;
|
||||
|
||||
|
@ -55,13 +56,17 @@ private
|
|||
LCD_WRX_DCX : STM32.GPIO.GPIO_Point renames STM32.Device.PD13;
|
||||
LCD_RESET : STM32.GPIO.GPIO_Point renames STM32.Device.PD12;
|
||||
|
||||
type Frame_Buffer
|
||||
is limited new Framebuffer_LTDC.Frame_Buffer with record
|
||||
Device : ILI9341.ILI9341_Device (STM32.Device.SPI_5'Access,
|
||||
Chip_Select => LCD_CSX'Access,
|
||||
WRX => LCD_WRX_DCX'Access,
|
||||
Reset => LCD_RESET'Access,
|
||||
Time => Ravenscar_Time.Delays);
|
||||
package RGB_SPI_Device is new ILI9341.Device
|
||||
(ILI9341_Connector => ILI9341.SPI_Connector.ILI9341_Connector,
|
||||
Send_Command => ILI9341.SPI_Connector.Send_Command,
|
||||
Connection => ILI9341.RGB,
|
||||
Connector =>
|
||||
(Port => STM32.Device.SPI_5'Access,
|
||||
Chip_Select => LCD_CSX'Access,
|
||||
WRX => LCD_WRX_DCX'Access));
|
||||
|
||||
type Frame_Buffer is limited new Framebuffer_LTDC.Frame_Buffer with record
|
||||
Device : RGB_SPI_Device.ILI9341_Device;
|
||||
end record;
|
||||
|
||||
end Framebuffer_ILI9341;
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with STM32.Board;
|
||||
with STM32.Device;
|
||||
with STM32.GPIO;
|
||||
|
||||
with Ravenscar_Time;
|
||||
|
||||
package body Display_ILI9341 is
|
||||
|
||||
----------------
|
||||
-- Initialize --
|
||||
----------------
|
||||
|
||||
procedure Initialize (This : in out Display) is
|
||||
begin
|
||||
STM32.Device.Enable_Clock (STM32.Board.TFT_BLK);
|
||||
|
||||
STM32.Board.TFT_BLK.Configure_IO
|
||||
((STM32.GPIO.Mode_Out,
|
||||
Resistors => STM32.GPIO.Floating,
|
||||
Output_Type => STM32.GPIO.Push_Pull,
|
||||
Speed => STM32.GPIO.Speed_100MHz));
|
||||
|
||||
STM32.Board.TFT_BLK.Set; -- Turn LCD backlight on
|
||||
|
||||
STM32.Board.Initialize_FSMC (STM32.Board.TFT_Pins);
|
||||
|
||||
STM32.FSMC.Configure
|
||||
(Bank_1 =>
|
||||
(1 => -- TFT is connected to sub-bank 1
|
||||
(Is_Set => True,
|
||||
Value =>
|
||||
(Write_Enable => True,
|
||||
Bus_Width => STM32.FSMC.Half_Word,
|
||||
Memory_Type => STM32.FSMC.SRAM,
|
||||
Bus_Turn => 15, -- 90ns
|
||||
Data_Setup => 57, -- 342ns
|
||||
Address_Setup => 0,
|
||||
Extended =>
|
||||
(STM32.FSMC.Mode_A,
|
||||
Write_Bus_Turn => 3, -- 18ns
|
||||
Write_Data_Setup => 2, -- 12ns
|
||||
Write_Address_Setup => 0),
|
||||
others => <>)),
|
||||
others => <>));
|
||||
|
||||
This.Device.Initialize (Ravenscar_Time.Delays);
|
||||
This.Set_Orientation (HAL.Framebuffer.Default);
|
||||
end Initialize;
|
||||
|
||||
---------------------
|
||||
-- Set_Orientation --
|
||||
---------------------
|
||||
|
||||
procedure Set_Orientation
|
||||
(This : in out Display;
|
||||
Orientation : HAL.Framebuffer.Display_Orientation) is
|
||||
begin
|
||||
This.Device.Set_Orientation
|
||||
(case Orientation is
|
||||
when HAL.Framebuffer.Landscape =>
|
||||
ILI9341_Device.Landscape_1,
|
||||
when others => ILI9341_Device.Portrait_2);
|
||||
end Set_Orientation;
|
||||
|
||||
end Display_ILI9341;
|
|
@ -29,44 +29,51 @@
|
|||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- This file provides declarations for devices on the STM32F4XX M board
|
||||
-- manufactured by DevEBox.
|
||||
with System.Storage_Elements;
|
||||
|
||||
with STM32.Device; use STM32.Device;
|
||||
with STM32.GPIO; use STM32.GPIO;
|
||||
with HAL.Framebuffer;
|
||||
with ILI9341.Device.Bitmap;
|
||||
with ILI9341.Device;
|
||||
with ILI9341.B16_Connector;
|
||||
with STM32.FSMC;
|
||||
|
||||
with Ada.Interrupts.Names; use Ada.Interrupts;
|
||||
package Display_ILI9341 is
|
||||
|
||||
package STM32.Board is
|
||||
pragma Elaborate_Body;
|
||||
type Display is tagged limited private;
|
||||
|
||||
subtype User_LED is GPIO_Point;
|
||||
procedure Initialize (This : in out Display);
|
||||
-- Configure FSMC, turn backlight on and initialize the display
|
||||
|
||||
Green_LED : User_LED renames PA1;
|
||||
procedure Set_Orientation
|
||||
(This : in out Display;
|
||||
Orientation : HAL.Framebuffer.Display_Orientation);
|
||||
|
||||
All_LEDs : GPIO_Points := (1 => Green_LED);
|
||||
LCH_LED : GPIO_Point renames Green_LED;
|
||||
use System.Storage_Elements;
|
||||
|
||||
procedure Initialize_LEDs;
|
||||
-- MUST be called prior to any use of the LEDs
|
||||
package ILI9341_Device is new ILI9341.Device
|
||||
(ILI9341_Connector => ILI9341.B16_Connector.ILI9341_Connector,
|
||||
Send_Command => ILI9341.B16_Connector.Send_Command,
|
||||
Connection => ILI9341.Parallel,
|
||||
Connector =>
|
||||
(Command => STM32.FSMC.Bank_1_Start (Subbank => 1),
|
||||
RAM => STM32.FSMC.Bank_1_Start (Subbank => 1) + 2 ** 19));
|
||||
-- RAM region starts when A18 = 1, TFT attached with 16 bits bus, so 2**19
|
||||
|
||||
procedure Turn_On (This : in out User_LED) renames STM32.GPIO.Set;
|
||||
procedure Turn_Off (This : in out User_LED) renames STM32.GPIO.Clear;
|
||||
procedure Toggle (This : in out User_LED) renames STM32.GPIO.Toggle;
|
||||
package ILI9341_Bitmap is new ILI9341_Device.Bitmap
|
||||
(ILI9341.B16_Connector.Write_Pixels,
|
||||
ILI9341.B16_Connector.Read_Pixels);
|
||||
|
||||
procedure All_LEDs_Off with Inline;
|
||||
procedure All_LEDs_On with Inline;
|
||||
procedure Toggle_LEDs (These : in out GPIO_Points)
|
||||
renames STM32.GPIO.Toggle;
|
||||
subtype Bitmap_Buffer is ILI9341_Bitmap.Bitmap_Buffer;
|
||||
|
||||
-- User button
|
||||
function Buffer (This : in out Display) return Bitmap_Buffer;
|
||||
|
||||
User_Button_Point : GPIO_Point renames PA0;
|
||||
User_Button_Interrupt : constant Interrupt_ID := Names.EXTI0_Interrupt;
|
||||
private
|
||||
|
||||
procedure Configure_User_Button_GPIO;
|
||||
-- Configures the GPIO port/pin for the K1 user button. Sufficient
|
||||
-- for polling the button, and necessary for having the button generate
|
||||
-- interrupts.
|
||||
type Display is tagged limited record
|
||||
Device : aliased ILI9341_Device.ILI9341_Device;
|
||||
end record;
|
||||
|
||||
end STM32.Board;
|
||||
function Buffer (This : in out Display) return Bitmap_Buffer is
|
||||
(ILI9341_Bitmap.Get_Bitmap (This.Device'Access));
|
||||
|
||||
end Display_ILI9341;
|
|
@ -0,0 +1,21 @@
|
|||
-- This package was generated by the Ada_Drivers_Library project wizard script
|
||||
package ADL_Config is
|
||||
Architecture : constant String := "ARM"; -- From board definition
|
||||
Board : constant String := "STM32_F4VE"; -- From command line
|
||||
CPU_Core : constant String := "ARM Cortex-M4F"; -- From mcu definition
|
||||
Device_Family : constant String := "STM32F4"; -- From board definition
|
||||
Device_Name : constant String := "STM32F407VGTx"; -- From board definition
|
||||
Has_Ravenscar_Full_Runtime : constant String := "True"; -- From board definition
|
||||
Has_Ravenscar_SFP_Runtime : constant String := "True"; -- From board definition
|
||||
Has_ZFP_Runtime : constant String := "False"; -- From board definition
|
||||
High_Speed_External_Clock : constant := 8000000; -- From board definition
|
||||
Max_Mount_Name_Length : constant := 128; -- From default value
|
||||
Max_Mount_Points : constant := 2; -- From default value
|
||||
Max_Path_Length : constant := 1024; -- From default value
|
||||
Number_Of_Interrupts : constant := 0; -- From default value
|
||||
Runtime_Name : constant String := "embedded-stm32f4"; -- From default value
|
||||
Runtime_Name_Suffix : constant String := "stm32f4"; -- From board definition
|
||||
Runtime_Profile : constant String := "embedded"; -- From default value
|
||||
Use_Startup_Gen : constant Boolean := False; -- From default value
|
||||
Vendor : constant String := "STMicro"; -- From board definition
|
||||
end ADL_Config;
|
|
@ -0,0 +1,21 @@
|
|||
-- This package was generated by the Ada_Drivers_Library project wizard script
|
||||
package ADL_Config is
|
||||
Architecture : constant String := "ARM"; -- From board definition
|
||||
Board : constant String := "STM32_F4VE"; -- From command line
|
||||
CPU_Core : constant String := "ARM Cortex-M4F"; -- From mcu definition
|
||||
Device_Family : constant String := "STM32F4"; -- From board definition
|
||||
Device_Name : constant String := "STM32F407VGTx"; -- From board definition
|
||||
Has_Ravenscar_Full_Runtime : constant String := "True"; -- From board definition
|
||||
Has_Ravenscar_SFP_Runtime : constant String := "True"; -- From board definition
|
||||
Has_ZFP_Runtime : constant String := "False"; -- From board definition
|
||||
High_Speed_External_Clock : constant := 8000000; -- From board definition
|
||||
Max_Mount_Name_Length : constant := 128; -- From default value
|
||||
Max_Mount_Points : constant := 2; -- From default value
|
||||
Max_Path_Length : constant := 1024; -- From default value
|
||||
Number_Of_Interrupts : constant := 0; -- From default value
|
||||
Runtime_Name : constant String := "light-tasking-stm32f4"; -- From command line
|
||||
Runtime_Name_Suffix : constant String := "stm32f4"; -- From board definition
|
||||
Runtime_Profile : constant String := "embedded"; -- From default value
|
||||
Use_Startup_Gen : constant Boolean := False; -- From default value
|
||||
Vendor : constant String := "STMicro"; -- From board definition
|
||||
end ADL_Config;
|
|
@ -0,0 +1,185 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with HAL.SPI;
|
||||
with STM32.SPI;
|
||||
|
||||
package body STM32.Board is
|
||||
|
||||
------------------
|
||||
-- All_LEDs_Off --
|
||||
------------------
|
||||
|
||||
procedure All_LEDs_Off is
|
||||
begin
|
||||
Set (All_LEDs);
|
||||
end All_LEDs_Off;
|
||||
|
||||
-----------------
|
||||
-- All_LEDs_On --
|
||||
-----------------
|
||||
|
||||
procedure All_LEDs_On is
|
||||
begin
|
||||
Clear (All_LEDs);
|
||||
end All_LEDs_On;
|
||||
|
||||
--------------------------------
|
||||
-- Configure_User_Button_GPIO --
|
||||
--------------------------------
|
||||
|
||||
procedure Configure_User_Button_GPIO is
|
||||
begin
|
||||
Enable_Clock (All_Buttons);
|
||||
Configure_IO (All_Buttons, (Mode_In, Resistors => Floating));
|
||||
end Configure_User_Button_GPIO;
|
||||
|
||||
---------------------
|
||||
-- Initialize_LEDs --
|
||||
---------------------
|
||||
|
||||
procedure Initialize_LEDs is
|
||||
begin
|
||||
Enable_Clock (All_LEDs);
|
||||
|
||||
Configure_IO
|
||||
(All_LEDs,
|
||||
(Mode_Out,
|
||||
Resistors => Floating,
|
||||
Output_Type => Push_Pull,
|
||||
Speed => Speed_100MHz));
|
||||
|
||||
All_LEDs_Off;
|
||||
end Initialize_LEDs;
|
||||
|
||||
-----------------------------
|
||||
-- Initialize_Flash_Memory --
|
||||
-----------------------------
|
||||
|
||||
procedure Initialize_Flash_Memory is
|
||||
SPI : STM32.SPI.SPI_Port renames STM32.Device.SPI_1;
|
||||
|
||||
SPI_SCK : STM32.GPIO.GPIO_Point renames STM32.Device.PB3;
|
||||
SPI_MISO : STM32.GPIO.GPIO_Point renames STM32.Device.PB4;
|
||||
SPI_MOSI : STM32.GPIO.GPIO_Point renames STM32.Device.PB5;
|
||||
SPI_CS : STM32.GPIO.GPIO_Point renames STM32.Device.PA15;
|
||||
|
||||
SPI_Pins : constant STM32.GPIO.GPIO_Points :=
|
||||
(SPI_SCK, SPI_MISO, SPI_MOSI);
|
||||
begin
|
||||
STM32.Device.Enable_Clock (SPI_Pins & SPI_CS);
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(SPI_CS,
|
||||
(Mode => STM32.GPIO.Mode_Out,
|
||||
Resistors => STM32.GPIO.Floating,
|
||||
Output_Type => STM32.GPIO.Push_Pull,
|
||||
Speed => STM32.GPIO.Speed_100MHz));
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(SPI_Pins,
|
||||
(Mode => STM32.GPIO.Mode_AF,
|
||||
Resistors => STM32.GPIO.Pull_Up,
|
||||
AF_Output_Type => STM32.GPIO.Push_Pull,
|
||||
AF_Speed => STM32.GPIO.Speed_100MHz,
|
||||
AF => STM32.Device.GPIO_AF_SPI1_5));
|
||||
|
||||
STM32.Device.Enable_Clock (SPI);
|
||||
|
||||
STM32.SPI.Configure
|
||||
(SPI,
|
||||
(Direction => STM32.SPI.D2Lines_FullDuplex,
|
||||
Mode => STM32.SPI.Master,
|
||||
Data_Size => HAL.SPI.Data_Size_8b,
|
||||
Clock_Polarity => STM32.SPI.High, -- Mode 3
|
||||
Clock_Phase => STM32.SPI.P2Edge,
|
||||
Slave_Management => STM32.SPI.Software_Managed,
|
||||
Baud_Rate_Prescaler => STM32.SPI.BRP_2,
|
||||
First_Bit => STM32.SPI.MSB,
|
||||
CRC_Poly => 0));
|
||||
-- SPI1 sits on APB2, which is 84MHz, so SPI rate in 84/2=42MHz
|
||||
end Initialize_Flash_Memory;
|
||||
|
||||
---------------------
|
||||
-- Initialize_FSMC --
|
||||
---------------------
|
||||
|
||||
procedure Initialize_FSMC (Pins : GPIO_Points) is
|
||||
begin
|
||||
Enable_FSMC_Clock;
|
||||
Enable_Clock (Pins);
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(Pins,
|
||||
(STM32.GPIO.Mode_AF,
|
||||
Resistors => STM32.GPIO.Floating,
|
||||
AF_Output_Type => STM32.GPIO.Push_Pull,
|
||||
AF_Speed => STM32.GPIO.Speed_100MHz,
|
||||
AF => STM32.Device.GPIO_AF_FMC_12));
|
||||
end Initialize_FSMC;
|
||||
|
||||
---------------------
|
||||
-- Initialize_UART --
|
||||
---------------------
|
||||
|
||||
procedure Initialize_UART
|
||||
(Speed : STM32.USARTs.Baud_Rates := 115_200;
|
||||
Stop : STM32.USARTs.Stop_Bits := STM32.USARTs.Stopbits_1;
|
||||
Parity : STM32.USARTs.Parities := STM32.USARTs.No_Parity;
|
||||
Flow : STM32.USARTs.Flow_Control := STM32.USARTs.No_Flow_Control)
|
||||
is
|
||||
TX_Pin : GPIO_Point renames STM32.Device.PA9;
|
||||
RX_Pin : GPIO_Point renames STM32.Device.PA10;
|
||||
begin
|
||||
Enable_Clock (UART);
|
||||
Enable_Clock (RX_Pin & TX_Pin);
|
||||
|
||||
Configure_IO
|
||||
(TX_Pin & RX_Pin,
|
||||
(Mode => Mode_AF,
|
||||
AF => GPIO_AF_USART1_7,
|
||||
Resistors => Pull_Up,
|
||||
AF_Speed => Speed_50MHz,
|
||||
AF_Output_Type => Push_Pull));
|
||||
|
||||
UART.Disable;
|
||||
|
||||
UART.Set_Baud_Rate (Speed);
|
||||
UART.Set_Mode (STM32.USARTs.Tx_Rx_Mode);
|
||||
UART.Set_Stop_Bits (Stop);
|
||||
UART.Set_Word_Length (STM32.USARTs.Word_Length_8);
|
||||
UART.Set_Parity (Parity);
|
||||
UART.Set_Flow_Control (Flow);
|
||||
|
||||
UART.Enable;
|
||||
end Initialize_UART;
|
||||
|
||||
end STM32.Board;
|
|
@ -0,0 +1,189 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- This file provides declarations for devices on the STM32 F4VE board
|
||||
-- manufactured by DevEBox.
|
||||
|
||||
with Ada.Interrupts.Names; use Ada.Interrupts;
|
||||
|
||||
with System;
|
||||
|
||||
with STM32.Device; use STM32.Device;
|
||||
with STM32.DMA; use STM32.DMA;
|
||||
with STM32.DMA.Interrupts; use STM32.DMA.Interrupts;
|
||||
with STM32.GPIO; use STM32.GPIO;
|
||||
with STM32.USARTs;
|
||||
|
||||
with SDCard;
|
||||
with W25Q16;
|
||||
with Display_ILI9341;
|
||||
with Touch_Panel_XPT2046;
|
||||
|
||||
package STM32.Board is
|
||||
pragma Elaborate_Body;
|
||||
|
||||
subtype User_LED is GPIO_Point;
|
||||
|
||||
D1_LED : User_LED renames PA6;
|
||||
D2_LED : User_LED renames PA7;
|
||||
|
||||
All_LEDs : GPIO_Points := (D1_LED, D2_LED);
|
||||
LCH_LED : GPIO_Point renames D1_LED;
|
||||
|
||||
procedure Initialize_LEDs;
|
||||
-- MUST be called prior to any use of the LEDs
|
||||
|
||||
procedure Turn_On (This : in out User_LED) renames STM32.GPIO.Clear;
|
||||
procedure Turn_Off (This : in out User_LED) renames STM32.GPIO.Set;
|
||||
procedure Toggle (This : in out User_LED) renames STM32.GPIO.Toggle;
|
||||
|
||||
procedure All_LEDs_Off with Inline;
|
||||
procedure All_LEDs_On with Inline;
|
||||
procedure Toggle_LEDs (These : in out GPIO_Points)
|
||||
renames STM32.GPIO.Toggle;
|
||||
|
||||
----------
|
||||
-- FSMC --
|
||||
----------
|
||||
|
||||
FSMC_D : constant GPIO_Points :=
|
||||
(PD14, PD15, PD0, PD1, PE7, PE8, PE9, PE10,
|
||||
PE11, PE12, PE13, PE14, PE15, PD8, PD9, PD10);
|
||||
-- Data pins (D0 .. D15)
|
||||
|
||||
FSMC_A18 : GPIO_Point renames PD13;
|
||||
-- Only one address pin is connected to the TFT header
|
||||
|
||||
FSMC_NE1 : GPIO_Point renames PD7; -- Chip select pin for TFT LCD
|
||||
FSMC_NWE : GPIO_Point renames PD5; -- Write enable pin
|
||||
FSMC_NOE : GPIO_Point renames PD4; -- Output enable pin
|
||||
|
||||
TFT_Pins : constant GPIO_Points :=
|
||||
FSMC_A18 & FSMC_D & FSMC_NE1 & FSMC_NWE & FSMC_NOE;
|
||||
|
||||
procedure Initialize_FSMC (Pins : GPIO_Points);
|
||||
-- Enable FSMC and initialize given FSMC pins
|
||||
|
||||
---------
|
||||
-- TFT --
|
||||
---------
|
||||
|
||||
SPI2_SCK : GPIO_Point renames PB13;
|
||||
SPI2_MISO : GPIO_Point renames PB14;
|
||||
SPI2_MOSI : GPIO_Point renames PB15;
|
||||
|
||||
TFT_RS : GPIO_Point renames PC5; -- PEN IRQ
|
||||
TFT_BLK : GPIO_Point renames PB1; -- LCD backlight
|
||||
TFT_CS : GPIO_Point renames PB12;
|
||||
|
||||
Display : Display_ILI9341.Display;
|
||||
|
||||
TFT_Bitmap : Display_ILI9341.Bitmap_Buffer := Display.Buffer;
|
||||
|
||||
Touch_Panel : Touch_Panel_XPT2046.Touch_Panel;
|
||||
|
||||
--------------------------
|
||||
-- micro SD card reader --
|
||||
--------------------------
|
||||
|
||||
SD_Detect_Pin : STM32.GPIO.GPIO_Point renames PC11;
|
||||
-- There is no dedicated pin for card detection, reuse DAT3 pin
|
||||
|
||||
SD_DMA : DMA_Controller renames DMA_2;
|
||||
SD_DMA_Rx_Stream : DMA_Stream_Selector renames Stream_3;
|
||||
SD_DMA_Rx_Channel : DMA_Channel_Selector renames Channel_4;
|
||||
SD_DMA_Tx_Stream : DMA_Stream_Selector renames Stream_6;
|
||||
SD_DMA_Tx_Channel : DMA_Channel_Selector renames Channel_4;
|
||||
SD_Pins : constant GPIO_Points :=
|
||||
(PC8, PC9, PC10, PC11, PC12, PD2);
|
||||
SD_Pins_AF : constant GPIO_Alternate_Function := GPIO_AF_SDIO_12;
|
||||
SD_Pins_2 : constant GPIO_Points := (1 .. 0 => <>);
|
||||
SD_Pins_AF_2 : constant GPIO_Alternate_Function := GPIO_AF_SDIO_12;
|
||||
SD_Interrupt : Ada.Interrupts.Interrupt_ID renames
|
||||
Ada.Interrupts.Names.SDIO_Interrupt;
|
||||
|
||||
DMA2_Stream3 : aliased DMA_Interrupt_Controller
|
||||
(DMA_2'Access, Stream_3,
|
||||
Ada.Interrupts.Names.DMA2_Stream3_Interrupt,
|
||||
System.Interrupt_Priority'Last);
|
||||
|
||||
DMA2_Stream6 : aliased DMA_Interrupt_Controller
|
||||
(DMA_2'Access, Stream_6,
|
||||
Ada.Interrupts.Names.DMA2_Stream6_Interrupt,
|
||||
System.Interrupt_Priority'Last);
|
||||
|
||||
SD_Rx_DMA_Int : DMA_Interrupt_Controller renames DMA2_Stream3;
|
||||
SD_Tx_DMA_Int : DMA_Interrupt_Controller renames DMA2_Stream6;
|
||||
|
||||
SDCard_Device : aliased SDCard.SDCard_Controller (SDIO'Access);
|
||||
|
||||
------------------
|
||||
-- User buttons --
|
||||
------------------
|
||||
|
||||
K0_Button_Point : GPIO_Point renames PE4;
|
||||
K1_Button_Point : GPIO_Point renames PE3;
|
||||
Wake_Up_Button_Point : GPIO_Point renames PA0;
|
||||
User_Button_Point : GPIO_Point renames Wake_Up_Button_Point;
|
||||
User_Button_Interrupt : constant Interrupt_ID := Names.EXTI0_Interrupt;
|
||||
|
||||
All_Buttons : GPIO_Points :=
|
||||
(K0_Button_Point, K1_Button_Point, Wake_Up_Button_Point);
|
||||
|
||||
procedure Configure_User_Button_GPIO;
|
||||
-- Configures the GPIO port/pin for user buttons. Sufficient
|
||||
-- for polling the button, and necessary for having the button generate
|
||||
-- interrupts.
|
||||
|
||||
------------------
|
||||
-- Flash memory --
|
||||
------------------
|
||||
|
||||
Flash : W25Q16.Flash_Memory
|
||||
(SPI => STM32.Device.SPI_1'Access,
|
||||
CS => STM32.Device.PA15'Access);
|
||||
|
||||
procedure Initialize_Flash_Memory;
|
||||
-- MUST be called prior to any use of the Flash
|
||||
|
||||
----------
|
||||
-- UART --
|
||||
----------
|
||||
|
||||
UART : STM32.USARTs.USART renames STM32.Device.USART_1;
|
||||
|
||||
procedure Initialize_UART
|
||||
(Speed : STM32.USARTs.Baud_Rates := 115_200;
|
||||
Stop : STM32.USARTs.Stop_Bits := STM32.USARTs.Stopbits_1;
|
||||
Parity : STM32.USARTs.Parities := STM32.USARTs.No_Parity;
|
||||
Flow : STM32.USARTs.Flow_Control := STM32.USARTs.No_Flow_Control);
|
||||
|
||||
end STM32.Board;
|
|
@ -0,0 +1,114 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with HAL.SPI;
|
||||
with STM32.Board;
|
||||
with STM32.GPIO;
|
||||
with STM32.SPI;
|
||||
|
||||
package body Touch_Panel_XPT2046 is
|
||||
|
||||
----------------
|
||||
-- Initialize --
|
||||
----------------
|
||||
|
||||
procedure Initialize
|
||||
(This : in out Touch_Panel;
|
||||
Orientation : HAL.Framebuffer.Display_Orientation :=
|
||||
HAL.Framebuffer.Default)
|
||||
is
|
||||
SPI_Pins : constant STM32.GPIO.GPIO_Points :=
|
||||
(STM32.Board.SPI2_SCK,
|
||||
STM32.Board.SPI2_MISO,
|
||||
STM32.Board.SPI2_MOSI);
|
||||
begin
|
||||
STM32.Device.Enable_Clock (STM32.Board.TFT_RS);
|
||||
STM32.Device.Enable_Clock (STM32.Board.TFT_CS);
|
||||
STM32.Device.Enable_Clock (SPI_Pins);
|
||||
STM32.Device.Enable_Clock (STM32.Device.SPI_2);
|
||||
|
||||
STM32.Board.TFT_RS.Configure_IO -- Pen IRQ pin
|
||||
((Mode => STM32.GPIO.Mode_In,
|
||||
Resistors => STM32.GPIO.Floating));
|
||||
|
||||
STM32.Board.TFT_CS.Configure_IO
|
||||
((Mode => STM32.GPIO.Mode_Out,
|
||||
Resistors => STM32.GPIO.Floating,
|
||||
Output_Type => STM32.GPIO.Push_Pull,
|
||||
Speed => STM32.GPIO.Speed_100MHz));
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(SPI_Pins,
|
||||
(Mode => STM32.GPIO.Mode_AF,
|
||||
Resistors => STM32.GPIO.Pull_Up,
|
||||
AF_Output_Type => STM32.GPIO.Push_Pull,
|
||||
AF_Speed => STM32.GPIO.Speed_100MHz,
|
||||
AF => STM32.Device.GPIO_AF_SPI2_5));
|
||||
|
||||
STM32.SPI.Configure
|
||||
(STM32.Device.SPI_2,
|
||||
(Direction => STM32.SPI.D2Lines_FullDuplex,
|
||||
Mode => STM32.SPI.Master,
|
||||
Data_Size => HAL.SPI.Data_Size_8b,
|
||||
Clock_Polarity => STM32.SPI.Low, -- Mode 0
|
||||
Clock_Phase => STM32.SPI.P1Edge,
|
||||
Slave_Management => STM32.SPI.Software_Managed,
|
||||
Baud_Rate_Prescaler => STM32.SPI.BRP_32,
|
||||
First_Bit => STM32.SPI.MSB,
|
||||
CRC_Poly => 0));
|
||||
-- SPI2 sits on APB1, which is 42MHz, so SPI rate in 42/32=1.3MHz
|
||||
|
||||
This.Set_Orientation (Orientation);
|
||||
|
||||
This.Calibrate
|
||||
(Min_X => 300,
|
||||
Max_X => 3768,
|
||||
Min_Y => 140,
|
||||
Max_Y => 3813);
|
||||
end Initialize;
|
||||
|
||||
---------------------
|
||||
-- Set_Orientation --
|
||||
---------------------
|
||||
|
||||
procedure Set_Orientation
|
||||
(This : in out Touch_Panel;
|
||||
Orientation : HAL.Framebuffer.Display_Orientation) is
|
||||
begin
|
||||
case Orientation is
|
||||
when HAL.Framebuffer.Default | HAL.Framebuffer.Portrait =>
|
||||
This.Set_Bounds (240, 320, HAL.Touch_Panel.Invert_Y);
|
||||
when HAL.Framebuffer.Landscape =>
|
||||
This.Set_Bounds (240, 320, HAL.Touch_Panel.Swap_XY);
|
||||
end case;
|
||||
end Set_Orientation;
|
||||
|
||||
end Touch_Panel_XPT2046;
|
|
@ -0,0 +1,58 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with HAL.Touch_Panel;
|
||||
with HAL.Framebuffer;
|
||||
|
||||
private with XPT2046;
|
||||
private with STM32.Device;
|
||||
|
||||
package Touch_Panel_XPT2046 is
|
||||
|
||||
type Touch_Panel is limited new HAL.Touch_Panel.Touch_Panel_Device
|
||||
with private;
|
||||
|
||||
procedure Initialize
|
||||
(This : in out Touch_Panel;
|
||||
Orientation : HAL.Framebuffer.Display_Orientation :=
|
||||
HAL.Framebuffer.Default);
|
||||
|
||||
procedure Set_Orientation
|
||||
(This : in out Touch_Panel;
|
||||
Orientation : HAL.Framebuffer.Display_Orientation);
|
||||
|
||||
private
|
||||
|
||||
type Touch_Panel is limited new XPT2046.XPT2046_Device
|
||||
(SPI => STM32.Device.SPI_2'Access,
|
||||
CS => STM32.Device.PB12'Access) with null record;
|
||||
|
||||
end Touch_Panel_XPT2046;
|
|
@ -0,0 +1,127 @@
|
|||
-- This project file was generated by the Ada_Drivers_Library project wizard script
|
||||
library project STM32_F4VE_Full is
|
||||
|
||||
type Build_Type is ("Debug", "Production");
|
||||
Build : Build_Type := external ("ADL_BUILD", "Debug");
|
||||
|
||||
type Build_Checks_Type is ("Disabled", "Enabled");
|
||||
Build_Checks : Build_Checks_Type := external ("ADL_BUILD_CHECKS", "Disabled");
|
||||
|
||||
-- Target architecture
|
||||
for Target use "arm-eabi";
|
||||
Target := Project'Target;
|
||||
|
||||
-- Callgraph info is not available on all architectures
|
||||
Callgraph_Switch := ();
|
||||
case Target is
|
||||
when "riscv32-unknown-elf" => null;
|
||||
when others => Callgraph_Switch := ("-fcallgraph-info=su");
|
||||
end case;
|
||||
|
||||
Build_Checks_Switches := ();
|
||||
case Build_Checks is
|
||||
when "Disabled" => null;
|
||||
when others =>
|
||||
Build_Checks_Switches :=
|
||||
("-gnaty", "-gnatyM120", "-gnatyO", -- Style checks
|
||||
"-gnatwe"); -- Warnings as errors
|
||||
end case;
|
||||
|
||||
package Compiler is
|
||||
case Build is
|
||||
when "Production" =>
|
||||
for Default_Switches ("Ada") use
|
||||
("-O3", -- Optimization
|
||||
"-gnatp", -- Supress checks
|
||||
"-gnatn"); -- Enable inlining
|
||||
when "Debug" =>
|
||||
for Default_Switches ("Ada") use
|
||||
("-O0", -- No optimization
|
||||
"-gnata") -- Enable assertions
|
||||
& Callgraph_Switch;
|
||||
end case;
|
||||
|
||||
for Default_Switches ("ada") use Compiler'Default_Switches ("Ada") &
|
||||
Callgraph_Switch &
|
||||
Build_Checks_Switches &
|
||||
("-g", -- Debug info
|
||||
"-gnatwa", -- All warnings
|
||||
"-gnatw_A", -- Turn off warnings for anonymous allocators
|
||||
"-gnatQ", -- Don't quit. Generate ALI and tree files even if illegalities
|
||||
"-gnatw.X", -- Disable warnings for No_Exception_Propagation
|
||||
"-ffunction-sections", -- Create a linker section for each function
|
||||
"-fdata-sections"); -- Create a linker section for each data
|
||||
end Compiler;
|
||||
|
||||
|
||||
for Languages use ("Ada");
|
||||
for Create_Missing_Dirs use "True";
|
||||
for Object_Dir use "obj/full_" & Build;
|
||||
for Library_Dir use "obj/full_lib_" & Build;
|
||||
for Library_Kind use "static";
|
||||
for Library_Name use "ada_drivers_library";
|
||||
|
||||
Linker_Switches := ();
|
||||
for Runtime ("Ada") use "embedded-stm32f4";
|
||||
|
||||
package Device_Configuration is
|
||||
for CPU_Name use "ARM Cortex-M4F";
|
||||
for Number_Of_Interrupts use "0";
|
||||
end Device_Configuration;
|
||||
|
||||
Architecture := "ARM"; -- From board definition
|
||||
Board := "STM32_F4VE"; -- From command line
|
||||
CPU_Core := "ARM Cortex-M4F"; -- From mcu definition
|
||||
Device_Family := "STM32F4"; -- From board definition
|
||||
Device_Name := "STM32F407VGTx"; -- From board definition
|
||||
Has_Ravenscar_Full_Runtime := "True"; -- From board definition
|
||||
Has_Ravenscar_SFP_Runtime := "True"; -- From board definition
|
||||
Has_ZFP_Runtime := "False"; -- From board definition
|
||||
High_Speed_External_Clock := "8000000"; -- From board definition
|
||||
Max_Mount_Name_Length := "128"; -- From default value
|
||||
Max_Mount_Points := "2"; -- From default value
|
||||
Max_Path_Length := "1024"; -- From default value
|
||||
Number_Of_Interrupts := "0"; -- From default value
|
||||
Runtime_Name := "embedded-stm32f4"; -- From default value
|
||||
Runtime_Name_Suffix := "stm32f4"; -- From board definition
|
||||
Runtime_Profile := "embedded"; -- From default value
|
||||
Use_Startup_Gen := "False"; -- From default value
|
||||
Vendor := "STMicro"; -- From board definition
|
||||
|
||||
-- Project source directories
|
||||
Src_Dirs_Root := "../..";
|
||||
for Source_Dirs use (
|
||||
Src_Dirs_Root & "/hal/src/", -- From HAL config
|
||||
Src_Dirs_Root & "/boards/stm32_f4ve/src/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/common/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/sdcard/", -- From board definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/cm4f", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/fpu", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/nocache", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/nvic_cm4_cm7", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/devices/stm32f40x/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/svd/stm32f40x", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/sd/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/sd/sdio/", -- From MCU definition
|
||||
Src_Dirs_Root & "/middleware/src/filesystem", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/BLE", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/utils", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/audio", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/monitor", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/bitmap", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/command_line", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/sdmmc", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/neopixel", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/ravenscar-common", -- From middleware config
|
||||
Src_Dirs_Root & "/components/src/**", -- From components config
|
||||
"src/full/");
|
||||
end STM32_F4VE_Full;
|
|
@ -0,0 +1,127 @@
|
|||
-- This project file was generated by the Ada_Drivers_Library project wizard script
|
||||
library project STM32_F4VE_SFP is
|
||||
|
||||
type Build_Type is ("Debug", "Production");
|
||||
Build : Build_Type := external ("ADL_BUILD", "Debug");
|
||||
|
||||
type Build_Checks_Type is ("Disabled", "Enabled");
|
||||
Build_Checks : Build_Checks_Type := external ("ADL_BUILD_CHECKS", "Disabled");
|
||||
|
||||
-- Target architecture
|
||||
for Target use "arm-eabi";
|
||||
Target := Project'Target;
|
||||
|
||||
-- Callgraph info is not available on all architectures
|
||||
Callgraph_Switch := ();
|
||||
case Target is
|
||||
when "riscv32-unknown-elf" => null;
|
||||
when others => Callgraph_Switch := ("-fcallgraph-info=su");
|
||||
end case;
|
||||
|
||||
Build_Checks_Switches := ();
|
||||
case Build_Checks is
|
||||
when "Disabled" => null;
|
||||
when others =>
|
||||
Build_Checks_Switches :=
|
||||
("-gnaty", "-gnatyM120", "-gnatyO", -- Style checks
|
||||
"-gnatwe"); -- Warnings as errors
|
||||
end case;
|
||||
|
||||
package Compiler is
|
||||
case Build is
|
||||
when "Production" =>
|
||||
for Default_Switches ("Ada") use
|
||||
("-O3", -- Optimization
|
||||
"-gnatp", -- Supress checks
|
||||
"-gnatn"); -- Enable inlining
|
||||
when "Debug" =>
|
||||
for Default_Switches ("Ada") use
|
||||
("-O0", -- No optimization
|
||||
"-gnata") -- Enable assertions
|
||||
& Callgraph_Switch;
|
||||
end case;
|
||||
|
||||
for Default_Switches ("ada") use Compiler'Default_Switches ("Ada") &
|
||||
Callgraph_Switch &
|
||||
Build_Checks_Switches &
|
||||
("-g", -- Debug info
|
||||
"-gnatwa", -- All warnings
|
||||
"-gnatw_A", -- Turn off warnings for anonymous allocators
|
||||
"-gnatQ", -- Don't quit. Generate ALI and tree files even if illegalities
|
||||
"-gnatw.X", -- Disable warnings for No_Exception_Propagation
|
||||
"-ffunction-sections", -- Create a linker section for each function
|
||||
"-fdata-sections"); -- Create a linker section for each data
|
||||
end Compiler;
|
||||
|
||||
|
||||
for Languages use ("Ada");
|
||||
for Create_Missing_Dirs use "True";
|
||||
for Object_Dir use "obj/sfp_" & Build;
|
||||
for Library_Dir use "obj/sfp_lib_" & Build;
|
||||
for Library_Kind use "static";
|
||||
for Library_Name use "ada_drivers_library";
|
||||
|
||||
Linker_Switches := ();
|
||||
for Runtime ("Ada") use "light-tasking-stm32f4";
|
||||
|
||||
package Device_Configuration is
|
||||
for CPU_Name use "ARM Cortex-M4F";
|
||||
for Number_Of_Interrupts use "0";
|
||||
end Device_Configuration;
|
||||
|
||||
Architecture := "ARM"; -- From board definition
|
||||
Board := "STM32_F4VE"; -- From command line
|
||||
CPU_Core := "ARM Cortex-M4F"; -- From mcu definition
|
||||
Device_Family := "STM32F4"; -- From board definition
|
||||
Device_Name := "STM32F407VGTx"; -- From board definition
|
||||
Has_Ravenscar_Full_Runtime := "True"; -- From board definition
|
||||
Has_Ravenscar_SFP_Runtime := "True"; -- From board definition
|
||||
Has_ZFP_Runtime := "False"; -- From board definition
|
||||
High_Speed_External_Clock := "8000000"; -- From board definition
|
||||
Max_Mount_Name_Length := "128"; -- From default value
|
||||
Max_Mount_Points := "2"; -- From default value
|
||||
Max_Path_Length := "1024"; -- From default value
|
||||
Number_Of_Interrupts := "0"; -- From default value
|
||||
Runtime_Name := "light-tasking-stm32f4"; -- From command line
|
||||
Runtime_Name_Suffix := "stm32f4"; -- From board definition
|
||||
Runtime_Profile := "embedded"; -- From default value
|
||||
Use_Startup_Gen := "False"; -- From default value
|
||||
Vendor := "STMicro"; -- From board definition
|
||||
|
||||
-- Project source directories
|
||||
Src_Dirs_Root := "../..";
|
||||
for Source_Dirs use (
|
||||
Src_Dirs_Root & "/hal/src/", -- From HAL config
|
||||
Src_Dirs_Root & "/boards/stm32_f4ve/src/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/common/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/sdcard/", -- From board definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/cm4f", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/fpu", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/nocache", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/nvic_cm4_cm7", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/devices/stm32f40x/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/svd/stm32f40x", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/sd/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/sd/sdio/", -- From MCU definition
|
||||
Src_Dirs_Root & "/middleware/src/filesystem", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/BLE", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/utils", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/audio", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/monitor", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/bitmap", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/command_line", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/sdmmc", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/neopixel", -- From middleware config
|
||||
Src_Dirs_Root & "/middleware/src/ravenscar-common", -- From middleware config
|
||||
Src_Dirs_Root & "/components/src/**", -- From components config
|
||||
"src/sfp/");
|
||||
end STM32_F4VE_SFP;
|
|
@ -105,6 +105,7 @@ library project STM32F407_Discovery_Full is
|
|||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
|
|
|
@ -105,6 +105,7 @@ library project STM32F407_Discovery_SFP is
|
|||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with HAL.SPI;
|
||||
|
||||
package body STM32.Board is
|
||||
|
||||
------------------
|
||||
-- All_LEDs_Off --
|
||||
------------------
|
||||
|
||||
procedure All_LEDs_Off is
|
||||
begin
|
||||
Set (All_LEDs);
|
||||
end All_LEDs_Off;
|
||||
|
||||
-----------------
|
||||
-- All_LEDs_On --
|
||||
-----------------
|
||||
|
||||
procedure All_LEDs_On is
|
||||
begin
|
||||
Clear (All_LEDs);
|
||||
end All_LEDs_On;
|
||||
|
||||
---------------------
|
||||
-- Initialize_LEDs --
|
||||
---------------------
|
||||
|
||||
procedure Initialize_LEDs is
|
||||
begin
|
||||
Enable_Clock (All_LEDs);
|
||||
|
||||
Configure_IO
|
||||
(All_LEDs,
|
||||
(Mode_Out,
|
||||
Resistors => Floating,
|
||||
Output_Type => Push_Pull,
|
||||
Speed => Speed_100MHz));
|
||||
end Initialize_LEDs;
|
||||
|
||||
-----------------------------
|
||||
-- Initialize_Flash_Memory --
|
||||
-----------------------------
|
||||
|
||||
procedure Initialize_Flash_Memory is
|
||||
SPI : STM32.SPI.SPI_Port renames STM32.Device.SPI_1;
|
||||
|
||||
SPI_SCK : STM32.GPIO.GPIO_Point renames STM32.Device.PB3;
|
||||
SPI_MISO : STM32.GPIO.GPIO_Point renames STM32.Device.PB4;
|
||||
SPI_MOSI : STM32.GPIO.GPIO_Point renames STM32.Device.PB5;
|
||||
SPI_CS : STM32.GPIO.GPIO_Point renames STM32.Device.PA15;
|
||||
|
||||
SPI_Pins : constant STM32.GPIO.GPIO_Points :=
|
||||
(SPI_SCK, SPI_MISO, SPI_MOSI);
|
||||
begin
|
||||
STM32.Device.Enable_Clock (SPI_Pins & SPI_CS);
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(SPI_CS,
|
||||
(Mode => STM32.GPIO.Mode_Out,
|
||||
Resistors => STM32.GPIO.Floating,
|
||||
Output_Type => STM32.GPIO.Push_Pull,
|
||||
Speed => STM32.GPIO.Speed_100MHz));
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(SPI_Pins,
|
||||
(Mode => STM32.GPIO.Mode_AF,
|
||||
Resistors => STM32.GPIO.Pull_Up,
|
||||
AF_Output_Type => STM32.GPIO.Push_Pull,
|
||||
AF_Speed => STM32.GPIO.Speed_100MHz,
|
||||
AF => STM32.Device.GPIO_AF_SPI1_5));
|
||||
|
||||
STM32.Device.Enable_Clock (SPI);
|
||||
|
||||
STM32.SPI.Configure
|
||||
(SPI,
|
||||
(Direction => STM32.SPI.D2Lines_FullDuplex,
|
||||
Mode => STM32.SPI.Master,
|
||||
Data_Size => HAL.SPI.Data_Size_8b,
|
||||
Clock_Polarity => STM32.SPI.High, -- Mode 3
|
||||
Clock_Phase => STM32.SPI.P2Edge,
|
||||
Slave_Management => STM32.SPI.Software_Managed,
|
||||
Baud_Rate_Prescaler => STM32.SPI.BRP_2,
|
||||
First_Bit => STM32.SPI.MSB,
|
||||
CRC_Poly => 0));
|
||||
-- SPI1 sits on APB2, which is 84MHz, so SPI rate in 84/2=42MHz
|
||||
end Initialize_Flash_Memory;
|
||||
|
||||
--------------------------------
|
||||
-- Configure_User_Button_GPIO --
|
||||
--------------------------------
|
||||
|
||||
procedure Configure_User_Button_GPIO is
|
||||
begin
|
||||
Enable_Clock (User_Button_Point);
|
||||
Configure_IO (User_Button_Point, (Mode_In, Resistors => Floating));
|
||||
end Configure_User_Button_GPIO;
|
||||
|
||||
end STM32.Board;
|
|
@ -0,0 +1,142 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- This file provides declarations for devices on the STM32F4XX M board
|
||||
-- manufactured by DevEBox.
|
||||
|
||||
with System;
|
||||
with Ada.Interrupts.Names; use Ada.Interrupts;
|
||||
|
||||
with STM32.Device; use STM32.Device;
|
||||
with STM32.DMA; use STM32.DMA;
|
||||
with STM32.DMA.Interrupts; use STM32.DMA.Interrupts;
|
||||
with STM32.GPIO; use STM32.GPIO;
|
||||
with STM32.SPI; use STM32.SPI;
|
||||
|
||||
with SDCard;
|
||||
with W25Q16;
|
||||
|
||||
package STM32.Board is
|
||||
pragma Elaborate_Body;
|
||||
|
||||
subtype User_LED is GPIO_Point;
|
||||
|
||||
Green_LED : User_LED renames PA1;
|
||||
|
||||
All_LEDs : GPIO_Points := (1 => Green_LED);
|
||||
LCH_LED : GPIO_Point renames Green_LED;
|
||||
|
||||
procedure Initialize_LEDs;
|
||||
-- MUST be called prior to any use of the LEDs
|
||||
|
||||
procedure Turn_On (This : in out User_LED) renames STM32.GPIO.Clear;
|
||||
procedure Turn_Off (This : in out User_LED) renames STM32.GPIO.Set;
|
||||
procedure Toggle (This : in out User_LED) renames STM32.GPIO.Toggle;
|
||||
|
||||
procedure All_LEDs_Off with Inline;
|
||||
procedure All_LEDs_On with Inline;
|
||||
procedure Toggle_LEDs (These : in out GPIO_Points)
|
||||
renames STM32.GPIO.Toggle;
|
||||
|
||||
--------------------------
|
||||
-- micro SD card reader --
|
||||
--------------------------
|
||||
|
||||
SD_Detect_Pin : STM32.GPIO.GPIO_Point renames PC11;
|
||||
-- There is no dedicated pin for card detection, reuse DAT3 pin
|
||||
|
||||
SD_DMA : DMA_Controller renames DMA_2;
|
||||
SD_DMA_Rx_Stream : DMA_Stream_Selector renames Stream_3;
|
||||
SD_DMA_Rx_Channel : DMA_Channel_Selector renames Channel_4;
|
||||
SD_DMA_Tx_Stream : DMA_Stream_Selector renames Stream_6;
|
||||
SD_DMA_Tx_Channel : DMA_Channel_Selector renames Channel_4;
|
||||
SD_Pins : constant GPIO_Points :=
|
||||
(PC8, PC9, PC10, PC11, PC12, PD2);
|
||||
SD_Pins_AF : constant GPIO_Alternate_Function := GPIO_AF_SDIO_12;
|
||||
SD_Pins_2 : constant GPIO_Points := (1 .. 0 => <>);
|
||||
SD_Pins_AF_2 : constant GPIO_Alternate_Function := GPIO_AF_SDIO_12;
|
||||
SD_Interrupt : Ada.Interrupts.Interrupt_ID renames
|
||||
Ada.Interrupts.Names.SDIO_Interrupt;
|
||||
|
||||
DMA2_Stream3 : aliased DMA_Interrupt_Controller
|
||||
(DMA_2'Access, Stream_3,
|
||||
Ada.Interrupts.Names.DMA2_Stream3_Interrupt,
|
||||
System.Interrupt_Priority'Last);
|
||||
|
||||
DMA2_Stream6 : aliased DMA_Interrupt_Controller
|
||||
(DMA_2'Access, Stream_6,
|
||||
Ada.Interrupts.Names.DMA2_Stream6_Interrupt,
|
||||
System.Interrupt_Priority'Last);
|
||||
|
||||
SD_Rx_DMA_Int : DMA_Interrupt_Controller renames DMA2_Stream3;
|
||||
SD_Tx_DMA_Int : DMA_Interrupt_Controller renames DMA2_Stream6;
|
||||
|
||||
SDCard_Device : aliased SDCard.SDCard_Controller (SDIO'Access);
|
||||
|
||||
---------------
|
||||
-- SPI2 Pins --
|
||||
---------------
|
||||
|
||||
-- External TFT connector
|
||||
|
||||
TFT_RS : GPIO_Point renames PC5;
|
||||
TFT_BLK : GPIO_Point renames PB1; -- LCD backlight
|
||||
TFT_CS : GPIO_Point renames PB12;
|
||||
SPI2_SCK : GPIO_Point renames PB13;
|
||||
SPI2_MISO : GPIO_Point renames PB14;
|
||||
SPI2_MOSI : GPIO_Point renames PB15;
|
||||
|
||||
TFT_SPI : SPI_Port renames SPI_2;
|
||||
|
||||
-----------------
|
||||
-- User button --
|
||||
-----------------
|
||||
|
||||
User_Button_Point : GPIO_Point renames PA0;
|
||||
User_Button_Interrupt : constant Interrupt_ID := Names.EXTI0_Interrupt;
|
||||
|
||||
procedure Configure_User_Button_GPIO;
|
||||
-- Configures the GPIO port/pin for the K1 user button. Sufficient
|
||||
-- for polling the button, and necessary for having the button generate
|
||||
-- interrupts.
|
||||
|
||||
------------------
|
||||
-- Flash memory --
|
||||
------------------
|
||||
|
||||
Flash : W25Q16.Flash_Memory
|
||||
(SPI => STM32.Device.SPI_1'Access,
|
||||
CS => STM32.Device.PA15'Access);
|
||||
|
||||
procedure Initialize_Flash_Memory;
|
||||
-- MUST be called prior to any use of the Flash
|
||||
|
||||
end STM32.Board;
|
|
@ -92,8 +92,9 @@ library project STM32F4XX_M_Full is
|
|||
Src_Dirs_Root := "../..";
|
||||
for Source_Dirs use (
|
||||
Src_Dirs_Root & "/hal/src/", -- From HAL config
|
||||
Src_Dirs_Root & "/boards/stm32_common/stm32f4xx_m/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32f4xx_m/src/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/common/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/sdcard/", -- From board definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/cm4f", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/fpu", -- From arch definition
|
||||
|
@ -105,6 +106,7 @@ library project STM32F4XX_M_Full is
|
|||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
|
|
|
@ -92,8 +92,9 @@ library project STM32F4XX_M_SFP is
|
|||
Src_Dirs_Root := "../..";
|
||||
for Source_Dirs use (
|
||||
Src_Dirs_Root & "/hal/src/", -- From HAL config
|
||||
Src_Dirs_Root & "/boards/stm32_common/stm32f4xx_m/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32f4xx_m/src/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/common/", -- From board definition
|
||||
Src_Dirs_Root & "/boards/stm32_common/sdcard/", -- From board definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/cm4f", -- From arch definition
|
||||
Src_Dirs_Root & "/arch/ARM/cortex_m/src/fpu", -- From arch definition
|
||||
|
@ -105,6 +106,7 @@ library project STM32F4XX_M_SFP is
|
|||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/dma_interrupts/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/crc_stm32f4/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/fsmc/", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/i2c_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/power_control_stm32f4", -- From MCU definition
|
||||
Src_Dirs_Root & "/arch/ARM/STM32/drivers/uart_stm32f4/", -- From MCU definition
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# W25Q16 - 2Mbyte SPI flash memory
|
||||
|
||||
[Datasheet](https://www.winbond.com/hq/support/documentation/downloadV2022.jsp?xmlPath=/support/resources/.content/item/DA00-W25Q80-16-32.html)
|
||||
|
||||
There is an example in [examples/stm32f4xx_m/flash/](../../../../examples/stm32f4xx_m/flash/).
|
|
@ -0,0 +1,16 @@
|
|||
# ILI9341
|
||||
|
||||
TFT LCD Single Chip Driver 240RGBx320 Resolution and 262K color.
|
||||
It has parallel and serial interfaces for MCU. It's also able to
|
||||
receive data over RGB interface.
|
||||
|
||||
The STM32F429 Discovery board utilizes an RGB interface and stores
|
||||
graphic data in the main memory. The STM32 F4VE board uses a parallel
|
||||
interface and employs ILI9341 memory, which significantly slows down
|
||||
drawing but conserves main memory. When using the parallel interface,
|
||||
ILI9341 registers are mapped to the MCU's address space through the
|
||||
memory controller (FSMC), simplifying and speeding up the drawing.
|
||||
|
||||
* [Datasheet](http://www.datasheet-pdf.info/attach/1/3707537954.pdf)
|
||||
* [Example for RGB interface](../../../../examples/STM32F429_Discovery/draw_stm32f429disco.gpr) for STM32F429 Discovery
|
||||
* [Example for parallel interface](../../../../examples/stm32_f4ve/lcd) for STM32 F4VE board
|
|
@ -0,0 +1,256 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with Bitmap_Color_Conversion;
|
||||
|
||||
package body ILI9341.B16_Connector is
|
||||
|
||||
-- Colors order in RGB_888 buffer
|
||||
R : constant := 3;
|
||||
G : constant := 2;
|
||||
B : constant := 1;
|
||||
|
||||
-----------------
|
||||
-- Read_Pixels --
|
||||
-----------------
|
||||
|
||||
procedure Read_Pixels
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Address : System.Address;
|
||||
Count : Positive)
|
||||
is
|
||||
type Raw_Buffer is array (1 .. Count, 1 .. 3) of HAL.UInt8
|
||||
with Pack;
|
||||
|
||||
Raw_Pixels : Raw_Buffer
|
||||
with Import, Address => Address;
|
||||
|
||||
Command : HAL.UInt16
|
||||
with Import, Address => This.Command, Volatile;
|
||||
|
||||
RAM : HAL.UInt16
|
||||
with Import, Address => This.RAM, Volatile;
|
||||
|
||||
Ignore : HAL.UInt16;
|
||||
begin
|
||||
Command := HAL.UInt16 (Cmd);
|
||||
Ignore := RAM; -- First read returns invalid value
|
||||
|
||||
for J in 1 .. (Count + 1) / 2 loop
|
||||
declare
|
||||
use HAL;
|
||||
Raw : UInt16 := RAM;
|
||||
begin
|
||||
Raw_Pixels (2 * J - 1, R) := UInt8 (Shift_Right (Raw, 8));
|
||||
Raw_Pixels (2 * J - 1, G) := UInt8 (Raw and 255);
|
||||
Raw := RAM;
|
||||
Raw_Pixels (2 * J - 1, B) := UInt8 (Shift_Right (Raw, 8));
|
||||
|
||||
if 2 * J <= Count then
|
||||
Raw_Pixels (2 * J, R) := UInt8 (Raw and 255);
|
||||
Raw := RAM;
|
||||
Raw_Pixels (2 * J, G) := UInt8 (Shift_Right (Raw, 8));
|
||||
Raw_Pixels (2 * J, B) := UInt8 (Raw and 255);
|
||||
end if;
|
||||
end;
|
||||
end loop;
|
||||
end Read_Pixels;
|
||||
|
||||
------------------
|
||||
-- Send_Command --
|
||||
------------------
|
||||
|
||||
procedure Send_Command
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Data : HAL.UInt8_Array)
|
||||
is
|
||||
Command : HAL.UInt16
|
||||
with Import, Address => This.Command, Volatile;
|
||||
RAM : HAL.UInt16
|
||||
with Import, Address => This.RAM, Volatile;
|
||||
begin
|
||||
Command := HAL.UInt16 (Cmd);
|
||||
|
||||
for X of Data loop
|
||||
RAM := HAL.UInt16 (X);
|
||||
end loop;
|
||||
end Send_Command;
|
||||
|
||||
------------------
|
||||
-- Write_Pixels --
|
||||
------------------
|
||||
|
||||
procedure Write_Pixels
|
||||
(This : ILI9341_Connector;
|
||||
Mode : HAL.Bitmap.Bitmap_Color_Mode;
|
||||
Address : System.Address;
|
||||
Count : Positive;
|
||||
Repeat : Positive)
|
||||
is
|
||||
RAM : HAL.UInt16
|
||||
with Import, Address => This.RAM, Volatile;
|
||||
begin
|
||||
case Mode is
|
||||
when HAL.Bitmap.RGB_565 =>
|
||||
-- Native format for parallel interface
|
||||
declare
|
||||
subtype Raw_Buffer is HAL.UInt16_Array (1 .. Count);
|
||||
|
||||
Raw_Pixels : Raw_Buffer
|
||||
with Import, Address => Address;
|
||||
begin
|
||||
for Step in 1 .. Repeat loop
|
||||
for Raw of Raw_Pixels loop
|
||||
RAM := Raw;
|
||||
end loop;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
when HAL.Bitmap.RGB_888 =>
|
||||
declare
|
||||
-- subtype Raw_Buffer is HAL.UInt8_Array (1 .. 3 * Count);
|
||||
type Raw_Buffer is array (1 .. Count, 1 .. 3) of HAL.UInt8
|
||||
with Pack;
|
||||
|
||||
Raw_Pixels : Raw_Buffer
|
||||
with Import, Address => Address;
|
||||
begin
|
||||
if Count = 1 then
|
||||
-- Shortcut for Fill, Fill_Rect, Vertical_Line, etc.
|
||||
declare
|
||||
Color : constant HAL.Bitmap.Bitmap_Color :=
|
||||
(Alpha => 255,
|
||||
Red => Raw_Pixels (1, R),
|
||||
Green => Raw_Pixels (1, G),
|
||||
Blue => Raw_Pixels (1, B));
|
||||
|
||||
Word : HAL.UInt16 := HAL.UInt16
|
||||
(Bitmap_Color_Conversion.Bitmap_Color_To_Word
|
||||
(HAL.Bitmap.RGB_565, Color));
|
||||
begin
|
||||
Write_Pixels
|
||||
(This, HAL.Bitmap.RGB_565, Word'Address, 1, Repeat);
|
||||
|
||||
return;
|
||||
end;
|
||||
end if;
|
||||
|
||||
for Step in 1 .. Repeat loop
|
||||
for Index in 1 .. Count loop
|
||||
declare
|
||||
Color : constant HAL.Bitmap.Bitmap_Color :=
|
||||
(Alpha => 255,
|
||||
Red => Raw_Pixels (Index, R),
|
||||
Green => Raw_Pixels (Index, G),
|
||||
Blue => Raw_Pixels (Index, B));
|
||||
begin
|
||||
RAM := HAL.UInt16
|
||||
(Bitmap_Color_Conversion.Bitmap_Color_To_Word
|
||||
(HAL.Bitmap.RGB_565, Color));
|
||||
end;
|
||||
end loop;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
when HAL.Bitmap.ARGB_8888 =>
|
||||
declare
|
||||
subtype Raw_Buffer is HAL.UInt32_Array (1 .. Count);
|
||||
|
||||
Raw_Pixels : Raw_Buffer
|
||||
with Import, Address => Address;
|
||||
begin
|
||||
for Step in 1 .. Repeat loop
|
||||
for Raw of Raw_Pixels loop
|
||||
declare
|
||||
Color : constant HAL.Bitmap.Bitmap_Color :=
|
||||
Bitmap_Color_Conversion.Word_To_Bitmap_Color
|
||||
(Mode, Raw);
|
||||
begin
|
||||
RAM := HAL.UInt16
|
||||
(Bitmap_Color_Conversion.Bitmap_Color_To_Word
|
||||
(HAL.Bitmap.RGB_565, Color));
|
||||
end;
|
||||
end loop;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
when HAL.Bitmap.ARGB_1555 | HAL.Bitmap.ARGB_4444 | HAL.Bitmap.AL_88 =>
|
||||
declare
|
||||
subtype Raw_Buffer is HAL.UInt16_Array (1 .. Count);
|
||||
|
||||
Raw_Pixels : Raw_Buffer
|
||||
with Import, Address => Address;
|
||||
begin
|
||||
for Step in 1 .. Repeat loop
|
||||
for Raw of Raw_Pixels loop
|
||||
declare
|
||||
Color : constant HAL.Bitmap.Bitmap_Color :=
|
||||
Bitmap_Color_Conversion.Word_To_Bitmap_Color
|
||||
(Mode, HAL.UInt32 (Raw));
|
||||
begin
|
||||
RAM := HAL.UInt16
|
||||
(Bitmap_Color_Conversion.Bitmap_Color_To_Word
|
||||
(HAL.Bitmap.RGB_565, Color));
|
||||
end;
|
||||
end loop;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
when HAL.Bitmap.L_8 | HAL.Bitmap.AL_44 =>
|
||||
declare
|
||||
subtype Raw_Buffer is HAL.UInt8_Array (1 .. Count);
|
||||
|
||||
Raw_Pixels : Raw_Buffer
|
||||
with Import, Address => Address;
|
||||
begin
|
||||
for Step in 1 .. Repeat loop
|
||||
for Raw of Raw_Pixels loop
|
||||
declare
|
||||
Color : constant HAL.Bitmap.Bitmap_Color :=
|
||||
Bitmap_Color_Conversion.Word_To_Bitmap_Color
|
||||
(Mode, HAL.UInt32 (Raw));
|
||||
begin
|
||||
RAM := HAL.UInt16
|
||||
(Bitmap_Color_Conversion.Bitmap_Color_To_Word
|
||||
(HAL.Bitmap.RGB_565, Color));
|
||||
end;
|
||||
end loop;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
when others =>
|
||||
raise Program_Error;
|
||||
end case;
|
||||
end Write_Pixels;
|
||||
|
||||
end ILI9341.B16_Connector;
|
|
@ -29,50 +29,35 @@
|
|||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
package body STM32.Board is
|
||||
with System;
|
||||
|
||||
------------------
|
||||
-- All_LEDs_Off --
|
||||
------------------
|
||||
with HAL;
|
||||
with HAL.Bitmap;
|
||||
|
||||
procedure All_LEDs_Off is
|
||||
begin
|
||||
Clear (All_LEDs);
|
||||
end All_LEDs_Off;
|
||||
package ILI9341.B16_Connector is
|
||||
|
||||
-----------------
|
||||
-- All_LEDs_On --
|
||||
-----------------
|
||||
type ILI9341_Connector is record
|
||||
Command : System.Address;
|
||||
RAM : System.Address;
|
||||
end record;
|
||||
-- ILI9341 in parallel 16-bit mode mapped to the memory
|
||||
|
||||
procedure All_LEDs_On is
|
||||
begin
|
||||
Set (All_LEDs);
|
||||
end All_LEDs_On;
|
||||
procedure Send_Command
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Data : HAL.UInt8_Array);
|
||||
|
||||
---------------------
|
||||
-- Initialize_LEDs --
|
||||
---------------------
|
||||
procedure Write_Pixels
|
||||
(This : ILI9341_Connector;
|
||||
Mode : HAL.Bitmap.Bitmap_Color_Mode;
|
||||
Address : System.Address;
|
||||
Count : Positive;
|
||||
Repeat : Positive);
|
||||
|
||||
procedure Initialize_LEDs is
|
||||
begin
|
||||
Enable_Clock (All_LEDs);
|
||||
procedure Read_Pixels
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Address : System.Address;
|
||||
Count : Positive);
|
||||
|
||||
Configure_IO
|
||||
(All_LEDs,
|
||||
(Mode_Out,
|
||||
Resistors => Floating,
|
||||
Output_Type => Push_Pull,
|
||||
Speed => Speed_100MHz));
|
||||
end Initialize_LEDs;
|
||||
|
||||
--------------------------------
|
||||
-- Configure_User_Button_GPIO --
|
||||
--------------------------------
|
||||
|
||||
procedure Configure_User_Button_GPIO is
|
||||
begin
|
||||
Enable_Clock (User_Button_Point);
|
||||
Configure_IO (User_Button_Point, (Mode_In, Resistors => Floating));
|
||||
end Configure_User_Button_GPIO;
|
||||
|
||||
end STM32.Board;
|
||||
end ILI9341.B16_Connector;
|
|
@ -0,0 +1,243 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
pragma Ada_2022;
|
||||
|
||||
with ILI9341.Regs; use ILI9341.Regs;
|
||||
with Bitmap_Color_Conversion;
|
||||
with System.Storage_Elements;
|
||||
|
||||
package body ILI9341.Device.Bitmap is
|
||||
use HAL;
|
||||
|
||||
procedure Set_Cursor_Position
|
||||
(From : HAL.Bitmap.Point;
|
||||
To : HAL.Bitmap.Point);
|
||||
|
||||
---------------
|
||||
-- Copy_Rect --
|
||||
---------------
|
||||
|
||||
overriding
|
||||
procedure Copy_Rect
|
||||
(Src_Buffer : HAL.Bitmap.Bitmap_Buffer'Class;
|
||||
Src_Pt : HAL.Bitmap.Point;
|
||||
Dst_Buffer : in out Bitmap_Buffer;
|
||||
Dst_Pt : HAL.Bitmap.Point;
|
||||
Width : Natural;
|
||||
Height : Natural;
|
||||
Synchronous : Boolean)
|
||||
is
|
||||
use type HAL.Bitmap.Bitmap_Color_Mode;
|
||||
use type System.Storage_Elements.Storage_Offset;
|
||||
|
||||
Mode : constant HAL.Bitmap.Bitmap_Color_Mode := Src_Buffer.Color_Mode;
|
||||
Pixel_Size : constant Positive := HAL.Bitmap.Bits_Per_Pixel (Mode);
|
||||
Src_Width : constant Natural := Src_Buffer.Width;
|
||||
begin
|
||||
-- TODO: speed up if Src_Buffet=This by r/w a bunch of pixels
|
||||
|
||||
if Pixel_Size < 8
|
||||
or Mode = HAL.Bitmap.A_8
|
||||
or not Src_Buffer.Mapped_In_RAM
|
||||
then
|
||||
-- Fallback to the slow copying
|
||||
Soft_Drawing_Bitmap.Copy_Rect
|
||||
(Src_Buffer, Src_Pt, Parent (Dst_Buffer), Dst_Pt,
|
||||
Width, Height, Synchronous);
|
||||
|
||||
return;
|
||||
end if;
|
||||
|
||||
if Width = Src_Buffer.Width then
|
||||
-- Copy rectangle in one go
|
||||
Set_Cursor_Position
|
||||
(Dst_Pt,
|
||||
(Dst_Pt.X + Width - 1, Dst_Pt.Y + Height - 1));
|
||||
|
||||
Send_Command (Connector, ILI9341_GRAM, []);
|
||||
|
||||
Write_Pixels
|
||||
(This => Connector,
|
||||
Mode => Src_Buffer.Color_Mode,
|
||||
Address => Src_Buffer.Memory_Address +
|
||||
System.Storage_Elements.Storage_Offset
|
||||
(Src_Pt.Y * Width * Pixel_Size / 8),
|
||||
Count => Width * Height,
|
||||
Repeat => 1);
|
||||
else
|
||||
for DY in 0 .. 0 + Height - 1 loop
|
||||
Set_Cursor_Position
|
||||
((Y => Dst_Pt.Y + DY, X => Dst_Pt.X),
|
||||
(Y => Dst_Pt.Y + DY, X => Dst_Pt.X + Width - 1));
|
||||
|
||||
Send_Command (Connector, ILI9341_GRAM, []);
|
||||
|
||||
Write_Pixels
|
||||
(This => Connector,
|
||||
Mode => Src_Buffer.Color_Mode,
|
||||
Address => Src_Buffer.Memory_Address +
|
||||
System.Storage_Elements.Storage_Offset
|
||||
((Src_Pt.Y + DY) * Src_Width * Pixel_Size / 8),
|
||||
Count => Width,
|
||||
Repeat => 1);
|
||||
end loop;
|
||||
end if;
|
||||
end Copy_Rect;
|
||||
|
||||
----------
|
||||
-- Fill --
|
||||
----------
|
||||
|
||||
overriding
|
||||
procedure Fill (This : in out Bitmap_Buffer) is
|
||||
begin
|
||||
Set_Cursor_Position ((0, 0), (This.Width - 1, This.Height - 1));
|
||||
Send_Command (Connector, ILI9341_GRAM, []);
|
||||
|
||||
Write_Pixels
|
||||
(This => Connector,
|
||||
Mode => HAL.Bitmap.RGB_888,
|
||||
Address => This.Source'Address,
|
||||
Count => 1,
|
||||
Repeat => This.Width * This.Height);
|
||||
end Fill;
|
||||
|
||||
----------------
|
||||
-- Get_Bitmap --
|
||||
----------------
|
||||
|
||||
function Get_Bitmap
|
||||
(This : not null access ILI9341_Device) return Bitmap_Buffer is
|
||||
begin
|
||||
return (This, Source => 0);
|
||||
end Get_Bitmap;
|
||||
|
||||
-----------
|
||||
-- Pixel --
|
||||
-----------
|
||||
|
||||
overriding
|
||||
function Pixel
|
||||
(This : Bitmap_Buffer;
|
||||
Point : HAL.Bitmap.Point) return UInt32 is
|
||||
begin
|
||||
return Bitmap_Color_Conversion.Bitmap_Color_To_Word
|
||||
(HAL.Bitmap.RGB_888, This.Pixel (Point));
|
||||
end Pixel;
|
||||
|
||||
-----------
|
||||
-- Pixel --
|
||||
-----------
|
||||
|
||||
overriding
|
||||
function Pixel
|
||||
(This : Bitmap_Buffer;
|
||||
Point : HAL.Bitmap.Point)
|
||||
return HAL.Bitmap.Bitmap_Color
|
||||
is
|
||||
Color : HAL.Bitmap.Bitmap_Color := (HAL.Bitmap.White);
|
||||
begin
|
||||
Set_Cursor_Position (Point, Point);
|
||||
|
||||
Read_Pixels
|
||||
(This => Connector,
|
||||
Cmd => ILI9341_RAMRD,
|
||||
Address => Color'Address,
|
||||
Count => 1);
|
||||
|
||||
Color.Alpha := 255;
|
||||
|
||||
return Color;
|
||||
end Pixel;
|
||||
|
||||
-------------------------
|
||||
-- Set_Cursor_Position --
|
||||
-------------------------
|
||||
|
||||
procedure Set_Cursor_Position
|
||||
(From : HAL.Bitmap.Point;
|
||||
To : HAL.Bitmap.Point)
|
||||
is
|
||||
X1_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (From.X), 8));
|
||||
X1_Low : constant UInt8 := UInt8 (UInt16 (From.X) and 16#FF#);
|
||||
X2_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (To.X), 8));
|
||||
X2_Low : constant UInt8 := UInt8 (UInt16 (To.X) and 16#FF#);
|
||||
|
||||
Y1_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (From.Y), 8));
|
||||
Y1_Low : constant UInt8 := UInt8 (UInt16 (From.Y) and 16#FF#);
|
||||
Y2_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (To.Y), 8));
|
||||
Y2_Low : constant UInt8 := UInt8 (UInt16 (To.Y) and 16#FF#);
|
||||
begin
|
||||
Send_Command
|
||||
(Connector,
|
||||
ILI9341_COLUMN_ADDR,
|
||||
[X1_High, X1_Low, X2_High, X2_Low]);
|
||||
|
||||
Send_Command
|
||||
(Connector,
|
||||
ILI9341_PAGE_ADDR,
|
||||
[Y1_High, Y1_Low, Y2_High, Y2_Low]);
|
||||
end Set_Cursor_Position;
|
||||
|
||||
---------------
|
||||
-- Set_Pixel --
|
||||
---------------
|
||||
|
||||
overriding
|
||||
procedure Set_Pixel
|
||||
(This : in out Bitmap_Buffer;
|
||||
Point : HAL.Bitmap.Point)
|
||||
is
|
||||
begin
|
||||
Set_Cursor_Position (Point, Point);
|
||||
Send_Command (Connector, ILI9341_GRAM, []);
|
||||
|
||||
Write_Pixels
|
||||
(This => Connector,
|
||||
Mode => HAL.Bitmap.RGB_888,
|
||||
Address => This.Source'Address,
|
||||
Count => 1,
|
||||
Repeat => 1);
|
||||
end Set_Pixel;
|
||||
|
||||
----------------
|
||||
-- Set_Source --
|
||||
----------------
|
||||
|
||||
overriding
|
||||
procedure Set_Source
|
||||
(This : in out Bitmap_Buffer; Native : UInt32) is
|
||||
begin
|
||||
This.Source := Native;
|
||||
end Set_Source;
|
||||
|
||||
end ILI9341.Device.Bitmap;
|
|
@ -0,0 +1,145 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- This file provides the bitmap interface to the ILI9341 RAM.
|
||||
|
||||
with HAL;
|
||||
with HAL.Bitmap;
|
||||
with Soft_Drawing_Bitmap;
|
||||
with System;
|
||||
|
||||
generic
|
||||
with procedure Write_Pixels
|
||||
(This : ILI9341_Connector;
|
||||
Mode : HAL.Bitmap.Bitmap_Color_Mode;
|
||||
Address : System.Address;
|
||||
Count : Positive;
|
||||
Repeat : Positive) is null;
|
||||
-- Transfer to the display memory information about Count pixels located at
|
||||
-- the specified Address, taking into account the representation format
|
||||
-- Mode. Repeat the transfer the specified number of times.
|
||||
|
||||
with procedure Read_Pixels
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Address : System.Address;
|
||||
Count : Positive) is null;
|
||||
-- Read from the display memory information about Count pixels into the
|
||||
-- location at the specified Address in RGB_888 color mode.
|
||||
|
||||
package ILI9341.Device.Bitmap is
|
||||
|
||||
subtype Parent is Soft_Drawing_Bitmap.Soft_Drawing_Bitmap_Buffer;
|
||||
|
||||
type Bitmap_Buffer
|
||||
(Device : not null access ILI9341_Device) is new Parent with private;
|
||||
|
||||
function Get_Bitmap
|
||||
(This : not null access ILI9341_Device) return Bitmap_Buffer;
|
||||
|
||||
private
|
||||
|
||||
type Bitmap_Buffer
|
||||
(Device : not null access ILI9341_Device) is new Parent with
|
||||
record
|
||||
Source : HAL.UInt32;
|
||||
end record;
|
||||
|
||||
overriding
|
||||
function Source (This : Bitmap_Buffer) return HAL.UInt32 is (This.Source);
|
||||
|
||||
overriding
|
||||
function Width (This : Bitmap_Buffer) return Natural is
|
||||
(if This.Device.Orientation in Portrait_1 | Portrait_2 then 240
|
||||
else 320);
|
||||
|
||||
overriding
|
||||
function Height (This : Bitmap_Buffer) return Natural is
|
||||
(if This.Device.Orientation in Portrait_1 | Portrait_2 then 320
|
||||
else 240);
|
||||
|
||||
overriding
|
||||
function Swapped (This : Bitmap_Buffer) return Boolean is (False);
|
||||
|
||||
overriding
|
||||
function Color_Mode
|
||||
(This : Bitmap_Buffer) return HAL.Bitmap.Bitmap_Color_Mode is
|
||||
(HAL.Bitmap.RGB_888);
|
||||
|
||||
overriding
|
||||
function Mapped_In_RAM (This : Bitmap_Buffer) return Boolean is (False);
|
||||
|
||||
overriding
|
||||
function Memory_Address (This : Bitmap_Buffer) return System.Address is
|
||||
(System.Null_Address);
|
||||
|
||||
overriding
|
||||
procedure Set_Source (This : in out Bitmap_Buffer; Native : HAL.UInt32);
|
||||
|
||||
overriding
|
||||
procedure Set_Pixel
|
||||
(This : in out Bitmap_Buffer;
|
||||
Point : HAL.Bitmap.Point);
|
||||
|
||||
overriding
|
||||
procedure Set_Pixel_Blend
|
||||
(This : in out Bitmap_Buffer;
|
||||
Point : HAL.Bitmap.Point) renames Set_Pixel;
|
||||
|
||||
overriding
|
||||
function Pixel
|
||||
(This : Bitmap_Buffer;
|
||||
Point : HAL.Bitmap.Point) return HAL.UInt32;
|
||||
|
||||
overriding
|
||||
function Pixel
|
||||
(This : Bitmap_Buffer;
|
||||
Point : HAL.Bitmap.Point)
|
||||
return HAL.Bitmap.Bitmap_Color;
|
||||
|
||||
overriding
|
||||
function Buffer_Size (This : Bitmap_Buffer) return Natural is
|
||||
(This.Width * This.Height * 18 / 8);
|
||||
|
||||
overriding
|
||||
procedure Fill (This : in out Bitmap_Buffer);
|
||||
|
||||
overriding
|
||||
procedure Copy_Rect
|
||||
(Src_Buffer : HAL.Bitmap.Bitmap_Buffer'Class;
|
||||
Src_Pt : HAL.Bitmap.Point;
|
||||
Dst_Buffer : in out Bitmap_Buffer;
|
||||
Dst_Pt : HAL.Bitmap.Point;
|
||||
Width : Natural;
|
||||
Height : Natural;
|
||||
Synchronous : Boolean);
|
||||
|
||||
end ILI9341.Device.Bitmap;
|
|
@ -0,0 +1,146 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
pragma Ada_2022;
|
||||
|
||||
with ILI9341.Regs; use ILI9341.Regs;
|
||||
|
||||
package body ILI9341.Device is
|
||||
|
||||
---------------------
|
||||
-- Disable_Display --
|
||||
---------------------
|
||||
|
||||
procedure Disable_Display (This : in out ILI9341_Device) is
|
||||
begin
|
||||
Send_Command (Connector, ILI9341_DISPLAY_OFF, []);
|
||||
end Disable_Display;
|
||||
|
||||
--------------------
|
||||
-- Enable_Display --
|
||||
--------------------
|
||||
|
||||
procedure Enable_Display (This : in out ILI9341_Device) is
|
||||
begin
|
||||
Send_Command (Connector, ILI9341_DISPLAY_ON, []);
|
||||
end Enable_Display;
|
||||
|
||||
----------------
|
||||
-- Initialize --
|
||||
----------------
|
||||
|
||||
procedure Initialize
|
||||
(This : ILI9341_Device;
|
||||
Time : not null HAL.Time.Any_Delays)
|
||||
is
|
||||
Data renames Connector;
|
||||
begin
|
||||
Send_Command (Data, ILI9341_RESET, []);
|
||||
Time.Delay_Milliseconds (5);
|
||||
|
||||
Send_Command
|
||||
(Data, ILI9341_POWERA, [16#39#, 16#2C#, 16#00#, 16#34#, 16#02#]);
|
||||
|
||||
Send_Command (Data, ILI9341_POWERB, [16#00#, 16#C1#, 16#30#]);
|
||||
|
||||
Send_Command (Data, ILI9341_DTCA, [16#85#, 16#00#, 16#78#]);
|
||||
Send_Command (Data, ILI9341_DTCB, [16#00#, 16#00#]);
|
||||
Send_Command (Data, ILI9341_POWER_SEQ, [16#64#, 16#03#, 16#12#, 16#81#]);
|
||||
Send_Command (Data, ILI9341_PRC, [16#20#]);
|
||||
Send_Command (Data, ILI9341_POWER1, [16#23#]);
|
||||
Send_Command (Data, ILI9341_POWER2, [16#10#]);
|
||||
Send_Command (Data, ILI9341_VCOM1, [16#3E#, 16#28#]);
|
||||
Send_Command (Data, ILI9341_VCOM2, [16#86#]);
|
||||
Send_Command (Data, ILI9341_MAC, [16#C8#]);
|
||||
-- FIXME: Doesn't match Portrait_1 ???
|
||||
Send_Command (Data, ILI9341_FRC, [16#00#, 16#18#]);
|
||||
|
||||
case Connection is
|
||||
when RGB =>
|
||||
Send_Command (Data, ILI9341_RGB_INTERFACE, [16#C2#]);
|
||||
Send_Command (Data, ILI9341_INTERFACE, [16#01#, 16#00#, 16#06#]);
|
||||
Send_Command (Data, ILI9341_DFC, [16#0A#, 16#A7#, 16#27#, 16#04#]);
|
||||
when Serial | Parallel =>
|
||||
Send_Command (Data, ILI9341_PIXEL_FORMAT, [16#55#]);
|
||||
Send_Command (Data, ILI9341_DFC, [16#08#, 16#82#, 16#27#]);
|
||||
end case;
|
||||
|
||||
Send_Command (Data, ILI9341_3GAMMA_EN, [16#00#]);
|
||||
|
||||
Send_Command
|
||||
(Data, ILI9341_COLUMN_ADDR, [16#00#, 16#00#, 16#00#, 16#EF#]);
|
||||
|
||||
Send_Command (Data, ILI9341_PAGE_ADDR, [16#00#, 16#00#, 16#01#, 16#3F#]);
|
||||
Send_Command (Data, ILI9341_GAMMA, [16#01#]);
|
||||
Send_Command
|
||||
(Data,
|
||||
ILI9341_PGAMMA,
|
||||
[16#0F#, 16#31#, 16#2B#, 16#0C#, 16#0E#, 16#08#, 16#4E#, 16#F1#,
|
||||
16#37#, 16#07#, 16#10#, 16#03#, 16#0E#, 16#09#, 16#00#]);
|
||||
|
||||
Send_Command
|
||||
(Data,
|
||||
ILI9341_NGAMMA,
|
||||
[16#00#, 16#0E#, 16#14#, 16#03#, 16#11#, 16#07#, 16#31#, 16#C1#,
|
||||
16#48#, 16#08#, 16#0F#, 16#0C#, 16#31#, 16#36#, 16#0F#]);
|
||||
|
||||
Send_Command (Data, ILI9341_SLEEP_OUT, []);
|
||||
|
||||
Time.Delay_Milliseconds (150);
|
||||
|
||||
Send_Command (Data, ILI9341_DISPLAY_ON, []);
|
||||
Send_Command (Data, ILI9341_GRAM, []);
|
||||
end Initialize;
|
||||
|
||||
---------------------
|
||||
-- Set_Orientation --
|
||||
---------------------
|
||||
|
||||
procedure Set_Orientation
|
||||
(This : in out ILI9341_Device;
|
||||
To : Orientations)
|
||||
is
|
||||
Map : constant array (Orientations) of HAL.UInt8 :=
|
||||
[Portrait_1 => 16#58#,
|
||||
Portrait_2 => 16#88#,
|
||||
Landscape_1 => 16#28#,
|
||||
Landscape_2 => 16#E8#];
|
||||
|
||||
begin
|
||||
if This.Orientation = To then
|
||||
return;
|
||||
end if;
|
||||
|
||||
Send_Command (Connector, ILI9341_MAC, [Map (To)]);
|
||||
This.Orientation := To;
|
||||
end Set_Orientation;
|
||||
|
||||
end ILI9341.Device;
|
|
@ -0,0 +1,98 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
-- This file is based on: --
|
||||
-- --
|
||||
-- @file ili9341.h --
|
||||
-- @author MCD Application Team --
|
||||
-- @version V1.0.2 --
|
||||
-- @date 02-December-2014 --
|
||||
-- @brief This file includes the LCD driver for ILI9341 LCD. --
|
||||
-- --
|
||||
-- COPYRIGHT(c) 2014 STMicroelectronics --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- This file provides the generic implementation of the component driver for
|
||||
-- the ILI9341 LCD on the STM32F429 Discovery boards, among others. Support
|
||||
-- does not include the TFT hardware.
|
||||
|
||||
-- See the "a-Si TFT LCD Single Chip Driver" specification by ILITEK, file
|
||||
-- name "ILI9341_DS_V1.02" for details.
|
||||
|
||||
with HAL;
|
||||
with HAL.Time;
|
||||
|
||||
generic
|
||||
type ILI9341_Connector is limited private;
|
||||
-- The abstraction of the transport to ILI9341 chip
|
||||
|
||||
with procedure Send_Command
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Data : HAL.UInt8_Array);
|
||||
-- Send an ILI9341 command and corresponding arguments if any
|
||||
|
||||
Connection : Interface_Kind;
|
||||
-- The method of connection to ILI9341
|
||||
|
||||
Connector : ILI9341_Connector;
|
||||
-- The transport to ILI9341 chip
|
||||
|
||||
package ILI9341.Device is
|
||||
|
||||
type ILI9341_Device is tagged limited private;
|
||||
-- The 240x320 TFT LCD display
|
||||
|
||||
procedure Initialize
|
||||
(This : ILI9341_Device;
|
||||
Time : not null HAL.Time.Any_Delays);
|
||||
-- Initializes the device. Afterward, the device is also enabled so there
|
||||
-- is no immediate need to call Enable_Display.
|
||||
|
||||
type Orientations is
|
||||
(Portrait_1, -- origin at lower right, text going right to left
|
||||
Portrait_2, -- origin at upper left, text going left to right
|
||||
Landscape_1, -- origin at lower left, text going up
|
||||
Landscape_2); -- origin at upper right, text going down
|
||||
|
||||
procedure Set_Orientation
|
||||
(This : in out ILI9341_Device;
|
||||
To : Orientations);
|
||||
|
||||
procedure Enable_Display (This : in out ILI9341_Device);
|
||||
|
||||
procedure Disable_Display (This : in out ILI9341_Device);
|
||||
|
||||
private
|
||||
|
||||
type ILI9341_Device is tagged limited record
|
||||
Orientation : Orientations := Portrait_1;
|
||||
end record;
|
||||
|
||||
end ILI9341.Device;
|
|
@ -1,6 +1,6 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2016, AdaCore --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
|
@ -29,7 +29,8 @@
|
|||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
package ILI9341_Regs is
|
||||
package ILI9341.Regs is
|
||||
pragma Pure;
|
||||
|
||||
ILI9341_RESET : constant := 16#01#;
|
||||
ILI9341_SLEEP_OUT : constant := 16#11#;
|
||||
|
@ -39,6 +40,7 @@ package ILI9341_Regs is
|
|||
ILI9341_COLUMN_ADDR : constant := 16#2A#;
|
||||
ILI9341_PAGE_ADDR : constant := 16#2B#;
|
||||
ILI9341_GRAM : constant := 16#2C#;
|
||||
ILI9341_RAMRD : constant := 16#2E#;
|
||||
ILI9341_MAC : constant := 16#36#;
|
||||
ILI9341_PIXEL_FORMAT : constant := 16#3A#;
|
||||
ILI9341_WDB : constant := 16#51#;
|
||||
|
@ -62,4 +64,4 @@ package ILI9341_Regs is
|
|||
ILI9341_INTERFACE : constant := 16#F6#;
|
||||
ILI9341_PRC : constant := 16#F7#;
|
||||
|
||||
end ILI9341_Regs;
|
||||
end ILI9341.Regs;
|
|
@ -0,0 +1,66 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
package body ILI9341.SPI_Connector is
|
||||
|
||||
------------------
|
||||
-- Send_Command --
|
||||
------------------
|
||||
|
||||
procedure Send_Command
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Data : HAL.UInt8_Array)
|
||||
is
|
||||
use HAL.SPI;
|
||||
Status : SPI_Status;
|
||||
begin
|
||||
This.WRX.Clear;
|
||||
This.Chip_Select.Clear;
|
||||
This.Port.Transmit (SPI_Data_8b'(1 => Cmd), Status);
|
||||
|
||||
if Status /= Ok then
|
||||
raise Program_Error;
|
||||
end if;
|
||||
|
||||
if Data'Length > 0 then
|
||||
This.WRX.Set;
|
||||
This.Port.Transmit (SPI_Data_8b (Data), Status);
|
||||
|
||||
if Status /= Ok then
|
||||
raise Program_Error;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
This.Chip_Select.Set;
|
||||
end Send_Command;
|
||||
|
||||
end ILI9341.SPI_Connector;
|
|
@ -0,0 +1,50 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with HAL.SPI;
|
||||
with HAL.GPIO;
|
||||
|
||||
package ILI9341.SPI_Connector is
|
||||
|
||||
type ILI9341_Connector is record
|
||||
Port : HAL.SPI.Any_SPI_Port;
|
||||
Chip_Select : HAL.GPIO.Any_GPIO_Point;
|
||||
WRX : HAL.GPIO.Any_GPIO_Point;
|
||||
end record;
|
||||
-- ILI9341 connected over SPI
|
||||
|
||||
procedure Send_Command
|
||||
(This : ILI9341_Connector;
|
||||
Cmd : HAL.UInt8;
|
||||
Data : HAL.UInt8_Array);
|
||||
-- Send ILI9341 command over SPI
|
||||
|
||||
end ILI9341.SPI_Connector;
|
|
@ -1,402 +0,0 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
-- --
|
||||
-- This file is based on: --
|
||||
-- --
|
||||
-- @file ili9341.c --
|
||||
-- @author MCD Application Team --
|
||||
-- @version V1.0.2 --
|
||||
-- @date 02-December-2014 --
|
||||
-- @brief This file provides a set of functions needed to manage the --
|
||||
-- L3GD20, ST MEMS motion sensor, 3-axis digital output --
|
||||
-- gyroscope. --
|
||||
-- --
|
||||
-- COPYRIGHT(c) 2014 STMicroelectronics --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with Ada.Unchecked_Conversion;
|
||||
|
||||
with ILI9341_Regs; use ILI9341_Regs;
|
||||
|
||||
package body ILI9341 is
|
||||
|
||||
function As_UInt16 is new Ada.Unchecked_Conversion
|
||||
(Source => Colors, Target => UInt16);
|
||||
|
||||
-------------------
|
||||
-- Current_Width --
|
||||
-------------------
|
||||
|
||||
function Current_Width (This : ILI9341_Device) return Natural is
|
||||
(This.Selected_Width);
|
||||
|
||||
--------------------
|
||||
-- Current_Height --
|
||||
--------------------
|
||||
|
||||
function Current_Height (This : ILI9341_Device) return Natural is
|
||||
(This.Selected_Height);
|
||||
|
||||
-------------------------
|
||||
-- Current_Orientation --
|
||||
-------------------------
|
||||
|
||||
function Current_Orientation (This : ILI9341_Device) return Orientations is
|
||||
(This.Selected_Orientation);
|
||||
|
||||
----------------
|
||||
-- Initialize --
|
||||
----------------
|
||||
|
||||
procedure Initialize
|
||||
(This : in out ILI9341_Device;
|
||||
Mode : ILI9341_Mode)
|
||||
is
|
||||
begin
|
||||
if This.Initialized then
|
||||
return;
|
||||
end if;
|
||||
|
||||
This.Chip_Select_High;
|
||||
|
||||
This.Init_LCD (Mode);
|
||||
|
||||
This.Selected_Width := Device_Width;
|
||||
This.Selected_Height := Device_Height;
|
||||
This.Selected_Orientation := Portrait_2;
|
||||
|
||||
This.Initialized := True;
|
||||
end Initialize;
|
||||
|
||||
---------------
|
||||
-- Set_Pixel --
|
||||
---------------
|
||||
|
||||
procedure Set_Pixel
|
||||
(This : in out ILI9341_Device;
|
||||
X : Width;
|
||||
Y : Height;
|
||||
Color : Colors)
|
||||
is
|
||||
Color_High_UInt8 : constant UInt8 :=
|
||||
UInt8 (Shift_Right (As_UInt16 (Color), 8));
|
||||
Color_Low_UInt8 : constant UInt8 :=
|
||||
UInt8 (As_UInt16 (Color) and 16#FF#);
|
||||
begin
|
||||
This.Set_Cursor_Position (X, Y, X, Y);
|
||||
This.Send_Command (ILI9341_GRAM);
|
||||
This.Send_Data (Color_High_UInt8);
|
||||
This.Send_Data (Color_Low_UInt8);
|
||||
end Set_Pixel;
|
||||
|
||||
----------
|
||||
-- Fill --
|
||||
----------
|
||||
|
||||
procedure Fill (This : in out ILI9341_Device; Color : Colors) is
|
||||
Color_High_UInt8 : constant UInt8 :=
|
||||
UInt8 (Shift_Right (As_UInt16 (Color), 8));
|
||||
Color_Low_UInt8 : constant UInt8 :=
|
||||
UInt8 (As_UInt16 (Color) and 16#FF#);
|
||||
begin
|
||||
This.Set_Cursor_Position (X1 => 0,
|
||||
Y1 => 0,
|
||||
X2 => This.Selected_Width - 1,
|
||||
Y2 => This.Selected_Height - 1);
|
||||
|
||||
This.Send_Command (ILI9341_GRAM);
|
||||
for N in 1 .. (Device_Width * Device_Height) loop
|
||||
This.Send_Data (Color_High_UInt8);
|
||||
This.Send_Data (Color_Low_UInt8);
|
||||
end loop;
|
||||
end Fill;
|
||||
|
||||
---------------------
|
||||
-- Set_Orientation --
|
||||
---------------------
|
||||
|
||||
procedure Set_Orientation (This : in out ILI9341_Device;
|
||||
To : Orientations)
|
||||
is
|
||||
begin
|
||||
This.Send_Command (ILI9341_MAC);
|
||||
case To is
|
||||
when Portrait_1 => This.Send_Data (16#58#);
|
||||
when Portrait_2 => This.Send_Data (16#88#);
|
||||
when Landscape_1 => This.Send_Data (16#28#);
|
||||
when Landscape_2 => This.Send_Data (16#E8#);
|
||||
end case;
|
||||
|
||||
case To is
|
||||
when Portrait_1 | Portrait_2 =>
|
||||
This.Selected_Width := Device_Width;
|
||||
This.Selected_Height := Device_Height;
|
||||
when Landscape_1 | Landscape_2 =>
|
||||
This.Selected_Width := Device_Height;
|
||||
This.Selected_Height := Device_Width;
|
||||
end case;
|
||||
|
||||
This.Selected_Orientation := To;
|
||||
end Set_Orientation;
|
||||
|
||||
--------------------
|
||||
-- Enable_Display --
|
||||
--------------------
|
||||
|
||||
procedure Enable_Display (This : in out ILI9341_Device) is
|
||||
begin
|
||||
This.Send_Command (ILI9341_DISPLAY_ON);
|
||||
end Enable_Display;
|
||||
|
||||
---------------------
|
||||
-- Disable_Display --
|
||||
---------------------
|
||||
|
||||
procedure Disable_Display (This : in out ILI9341_Device) is
|
||||
begin
|
||||
This.Send_Command (ILI9341_DISPLAY_OFF);
|
||||
end Disable_Display;
|
||||
|
||||
-------------------------
|
||||
-- Set_Cursor_Position --
|
||||
-------------------------
|
||||
|
||||
procedure Set_Cursor_Position
|
||||
(This : in out ILI9341_Device;
|
||||
X1 : Width;
|
||||
Y1 : Height;
|
||||
X2 : Width;
|
||||
Y2 : Height)
|
||||
is
|
||||
X1_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (X1), 8));
|
||||
X1_Low : constant UInt8 := UInt8 (UInt16 (X1) and 16#FF#);
|
||||
X2_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (X2), 8));
|
||||
X2_Low : constant UInt8 := UInt8 (UInt16 (X2) and 16#FF#);
|
||||
|
||||
Y1_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (Y1), 8));
|
||||
Y1_Low : constant UInt8 := UInt8 (UInt16 (Y1) and 16#FF#);
|
||||
Y2_High : constant UInt8 := UInt8 (Shift_Right (UInt16 (Y2), 8));
|
||||
Y2_Low : constant UInt8 := UInt8 (UInt16 (Y2) and 16#FF#);
|
||||
begin
|
||||
This.Send_Command (ILI9341_COLUMN_ADDR);
|
||||
This.Send_Data (X1_High);
|
||||
This.Send_Data (X1_Low);
|
||||
This.Send_Data (X2_High);
|
||||
This.Send_Data (X2_Low);
|
||||
|
||||
This.Send_Command (ILI9341_PAGE_ADDR);
|
||||
This.Send_Data (Y1_High);
|
||||
This.Send_Data (Y1_Low);
|
||||
This.Send_Data (Y2_High);
|
||||
This.Send_Data (Y2_Low);
|
||||
end Set_Cursor_Position;
|
||||
|
||||
----------------------
|
||||
-- Chip_Select_High --
|
||||
----------------------
|
||||
|
||||
procedure Chip_Select_High (This : in out ILI9341_Device) is
|
||||
begin
|
||||
This.Chip_Select.Set;
|
||||
end Chip_Select_High;
|
||||
|
||||
---------------------
|
||||
-- Chip_Select_Low --
|
||||
---------------------
|
||||
|
||||
procedure Chip_Select_Low (This : in out ILI9341_Device) is
|
||||
begin
|
||||
This.Chip_Select.Clear;
|
||||
end Chip_Select_Low;
|
||||
|
||||
---------------
|
||||
-- Send_Data --
|
||||
---------------
|
||||
|
||||
procedure Send_Data (This : in out ILI9341_Device; Data : UInt8) is
|
||||
Status : SPI_Status;
|
||||
begin
|
||||
This.WRX.Set;
|
||||
This.Chip_Select_Low;
|
||||
This.Port.Transmit (SPI_Data_8b'(1 => Data), Status);
|
||||
if Status /= Ok then
|
||||
raise Program_Error;
|
||||
end if;
|
||||
This.Chip_Select_High;
|
||||
end Send_Data;
|
||||
|
||||
------------------
|
||||
-- Send_Command --
|
||||
------------------
|
||||
|
||||
procedure Send_Command (This : in out ILI9341_Device; Cmd : UInt8) is
|
||||
Status : SPI_Status;
|
||||
begin
|
||||
This.WRX.Clear;
|
||||
This.Chip_Select_Low;
|
||||
This.Port.Transmit (SPI_Data_8b'(1 => Cmd), Status);
|
||||
if Status /= Ok then
|
||||
raise Program_Error;
|
||||
end if;
|
||||
This.Chip_Select_High;
|
||||
end Send_Command;
|
||||
|
||||
--------------
|
||||
-- Init_LCD --
|
||||
--------------
|
||||
|
||||
procedure Init_LCD (This : in out ILI9341_Device;
|
||||
Mode : ILI9341_Mode) is
|
||||
begin
|
||||
This.Reset.Set;
|
||||
This.Send_Command (ILI9341_RESET);
|
||||
This.Time.Delay_Milliseconds (5);
|
||||
|
||||
This.Send_Command (ILI9341_POWERA);
|
||||
This.Send_Data (16#39#);
|
||||
This.Send_Data (16#2C#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#34#);
|
||||
This.Send_Data (16#02#);
|
||||
This.Send_Command (ILI9341_POWERB);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#C1#);
|
||||
This.Send_Data (16#30#);
|
||||
This.Send_Command (ILI9341_DTCA);
|
||||
This.Send_Data (16#85#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#78#);
|
||||
This.Send_Command (ILI9341_DTCB);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Command (ILI9341_POWER_SEQ);
|
||||
This.Send_Data (16#64#);
|
||||
This.Send_Data (16#03#);
|
||||
This.Send_Data (16#12#);
|
||||
This.Send_Data (16#81#);
|
||||
This.Send_Command (ILI9341_PRC);
|
||||
This.Send_Data (16#20#);
|
||||
This.Send_Command (ILI9341_POWER1);
|
||||
This.Send_Data (16#23#);
|
||||
This.Send_Command (ILI9341_POWER2);
|
||||
This.Send_Data (16#10#);
|
||||
This.Send_Command (ILI9341_VCOM1);
|
||||
This.Send_Data (16#3E#);
|
||||
This.Send_Data (16#28#);
|
||||
This.Send_Command (ILI9341_VCOM2);
|
||||
This.Send_Data (16#86#);
|
||||
This.Send_Command (ILI9341_MAC);
|
||||
This.Send_Data (16#C8#);
|
||||
This.Send_Command (ILI9341_FRC);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#18#);
|
||||
case Mode is
|
||||
when RGB_Mode =>
|
||||
This.Send_Command (ILI9341_RGB_INTERFACE);
|
||||
This.Send_Data (16#C2#);
|
||||
This.Send_Command (ILI9341_INTERFACE);
|
||||
This.Send_Data (16#01#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#06#);
|
||||
This.Send_Command (ILI9341_DFC);
|
||||
This.Send_Data (16#0A#);
|
||||
This.Send_Data (16#A7#);
|
||||
This.Send_Data (16#27#);
|
||||
This.Send_Data (16#04#);
|
||||
when SPI_Mode =>
|
||||
This.Send_Command (ILI9341_PIXEL_FORMAT);
|
||||
This.Send_Data (16#55#);
|
||||
This.Send_Command (ILI9341_DFC);
|
||||
This.Send_Data (16#08#);
|
||||
This.Send_Data (16#82#);
|
||||
This.Send_Data (16#27#);
|
||||
end case;
|
||||
This.Send_Command (ILI9341_3GAMMA_EN);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Command (ILI9341_COLUMN_ADDR);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#EF#);
|
||||
This.Send_Command (ILI9341_PAGE_ADDR);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#01#);
|
||||
This.Send_Data (16#3F#);
|
||||
This.Send_Command (ILI9341_GAMMA);
|
||||
This.Send_Data (16#01#);
|
||||
This.Send_Command (ILI9341_PGAMMA);
|
||||
This.Send_Data (16#0F#);
|
||||
This.Send_Data (16#31#);
|
||||
This.Send_Data (16#2B#);
|
||||
This.Send_Data (16#0C#);
|
||||
This.Send_Data (16#0E#);
|
||||
This.Send_Data (16#08#);
|
||||
This.Send_Data (16#4E#);
|
||||
This.Send_Data (16#F1#);
|
||||
This.Send_Data (16#37#);
|
||||
This.Send_Data (16#07#);
|
||||
This.Send_Data (16#10#);
|
||||
This.Send_Data (16#03#);
|
||||
This.Send_Data (16#0E#);
|
||||
This.Send_Data (16#09#);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Command (ILI9341_NGAMMA);
|
||||
This.Send_Data (16#00#);
|
||||
This.Send_Data (16#0E#);
|
||||
This.Send_Data (16#14#);
|
||||
This.Send_Data (16#03#);
|
||||
This.Send_Data (16#11#);
|
||||
This.Send_Data (16#07#);
|
||||
This.Send_Data (16#31#);
|
||||
This.Send_Data (16#C1#);
|
||||
This.Send_Data (16#48#);
|
||||
This.Send_Data (16#08#);
|
||||
This.Send_Data (16#0F#);
|
||||
This.Send_Data (16#0C#);
|
||||
This.Send_Data (16#31#);
|
||||
This.Send_Data (16#36#);
|
||||
This.Send_Data (16#0F#);
|
||||
This.Send_Command (ILI9341_SLEEP_OUT);
|
||||
|
||||
case Mode is
|
||||
when RGB_Mode =>
|
||||
This.Time.Delay_Milliseconds (150);
|
||||
when SPI_Mode =>
|
||||
This.Time.Delay_Milliseconds (20);
|
||||
end case;
|
||||
-- document ILI9341_DS_V1.02, section 11.2, pg 205 says we need
|
||||
-- either 120ms or 5ms, depending on the mode, but seems incorrect.
|
||||
|
||||
This.Send_Command (ILI9341_DISPLAY_ON);
|
||||
This.Send_Command (ILI9341_GRAM);
|
||||
end Init_LCD;
|
||||
|
||||
end ILI9341;
|
|
@ -1,6 +1,6 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015, AdaCore --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
|
@ -11,7 +11,7 @@
|
|||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of STMicroelectronics nor the names of its --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
|
@ -27,158 +27,17 @@
|
|||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
-- This file is based on: --
|
||||
-- --
|
||||
-- @file ili9341.h --
|
||||
-- @author MCD Application Team --
|
||||
-- @version V1.0.2 --
|
||||
-- @date 02-December-2014 --
|
||||
-- @brief This file includes the LCD driver for ILI9341 LCD. --
|
||||
-- --
|
||||
-- COPYRIGHT(c) 2014 STMicroelectronics --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- This file provides the component driver for the ILI9341 LCD on the
|
||||
-- STM32F429 Discovery boards, among others. Support does not include the
|
||||
-- TFT hardware.
|
||||
|
||||
-- See the "a-Si TFT LCD Single Chip Driver" specification by ILITEK, file
|
||||
-- name "ILI9341_DS_V1.02" for details.
|
||||
|
||||
with HAL; use HAL;
|
||||
with HAL.SPI; use HAL.SPI;
|
||||
with HAL.GPIO; use HAL.GPIO;
|
||||
with HAL.Time;
|
||||
-- Root package for the ILI9341 - 320x240 RGB TFT LCD driver.
|
||||
|
||||
package ILI9341 is
|
||||
pragma Pure;
|
||||
|
||||
type ILI9341_Device
|
||||
(Port : not null access SPI_Port'Class;
|
||||
Chip_Select : not null Any_GPIO_Point;
|
||||
WRX : not null Any_GPIO_Point;
|
||||
Reset : not null Any_GPIO_Point;
|
||||
Time : not null HAL.Time.Any_Delays)
|
||||
is tagged limited private;
|
||||
|
||||
type ILI9341_Mode is
|
||||
(RGB_Mode,
|
||||
SPI_Mode);
|
||||
|
||||
procedure Initialize
|
||||
(This : in out ILI9341_Device;
|
||||
Mode : ILI9341_Mode);
|
||||
-- Initializes the device. Afterward, the device is also enabled so there
|
||||
-- is no immediate need to call Enable_Display.
|
||||
|
||||
procedure Send_Command (This : in out ILI9341_Device; Cmd : UInt8);
|
||||
|
||||
procedure Send_Data (This : in out ILI9341_Device; Data : UInt8);
|
||||
|
||||
Device_Width : constant := 240;
|
||||
Device_Height : constant := 320;
|
||||
|
||||
-- The operational upper bounds for width and height depend on the selected
|
||||
-- orientation so these subtypes cannot specify an upper bound using the
|
||||
-- device max height/width. In particular, if the orientation is rotated,
|
||||
-- the width becomes the height, and vice versa. Hence these are mainly for
|
||||
-- readability.
|
||||
subtype Width is Natural;
|
||||
subtype Height is Natural;
|
||||
|
||||
type Colors is
|
||||
(Black,
|
||||
Blue,
|
||||
Light_Blue,
|
||||
Green,
|
||||
Cyan,
|
||||
Gray,
|
||||
Magenta,
|
||||
Light_Green,
|
||||
Brown,
|
||||
Red,
|
||||
Orange,
|
||||
Yellow,
|
||||
White);
|
||||
|
||||
for Colors use
|
||||
(Black => 16#0000#,
|
||||
Blue => 16#001F#,
|
||||
Light_Blue => 16#051D#,
|
||||
Green => 16#07E0#,
|
||||
Cyan => 16#07FF#,
|
||||
Gray => 16#7BEF#,
|
||||
Magenta => 16#A254#,
|
||||
Light_Green => 16#B723#,
|
||||
Brown => 16#BBCA#,
|
||||
Red => 16#F800#,
|
||||
Orange => 16#FBE4#,
|
||||
Yellow => 16#FFE0#,
|
||||
White => 16#FFFF#);
|
||||
|
||||
procedure Set_Pixel
|
||||
(This : in out ILI9341_Device;
|
||||
X : Width;
|
||||
Y : Height;
|
||||
Color : Colors) with Inline;
|
||||
|
||||
procedure Fill (This : in out ILI9341_Device; Color : Colors);
|
||||
|
||||
-- Descriptions assume the USB power/debug connector at the top
|
||||
type Orientations is
|
||||
(Portrait_1, -- origin at lower right, text going right to left
|
||||
Portrait_2, -- origin at upper left, text going left to right
|
||||
Landscape_1, -- origin at lower left, text going up
|
||||
Landscape_2); -- origin at upper right, text going down
|
||||
|
||||
procedure Set_Orientation
|
||||
(This : in out ILI9341_Device;
|
||||
To : Orientations);
|
||||
|
||||
procedure Enable_Display (This : in out ILI9341_Device);
|
||||
|
||||
procedure Disable_Display (This : in out ILI9341_Device);
|
||||
|
||||
-- These values reflect the currently selected orientation
|
||||
|
||||
function Current_Width (This : ILI9341_Device) return Natural
|
||||
with Inline;
|
||||
|
||||
function Current_Height (This : ILI9341_Device) return Natural
|
||||
with Inline;
|
||||
|
||||
function Current_Orientation (This : ILI9341_Device) return Orientations;
|
||||
|
||||
private
|
||||
|
||||
type ILI9341_Device
|
||||
(Port : not null access SPI_Port'Class;
|
||||
Chip_Select : not null Any_GPIO_Point;
|
||||
WRX : not null Any_GPIO_Point;
|
||||
Reset : not null Any_GPIO_Point;
|
||||
Time : not null HAL.Time.Any_Delays)
|
||||
is tagged limited record
|
||||
Selected_Orientation : Orientations;
|
||||
|
||||
-- The following objects' upper bounds vary with the selected
|
||||
-- orientation.
|
||||
Selected_Width : Natural;
|
||||
Selected_Height : Natural;
|
||||
|
||||
Initialized : Boolean := False;
|
||||
end record;
|
||||
|
||||
procedure Set_Cursor_Position
|
||||
(This : in out ILI9341_Device;
|
||||
X1 : Width;
|
||||
Y1 : Height;
|
||||
X2 : Width;
|
||||
Y2 : Height)
|
||||
with Inline;
|
||||
|
||||
procedure Chip_Select_High (This : in out ILI9341_Device) with Inline;
|
||||
procedure Chip_Select_Low (This : in out ILI9341_Device) with Inline;
|
||||
|
||||
procedure Init_LCD (This : in out ILI9341_Device;
|
||||
Mode : ILI9341_Mode);
|
||||
type Interface_Kind is
|
||||
(Parallel,
|
||||
Serial,
|
||||
RGB);
|
||||
-- Defines how the chip is connected to the MCU.
|
||||
|
||||
end ILI9341;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# XPT2046
|
||||
|
||||
The XPT2046 is a 4-wire resistive touch screen controller that incorporates
|
||||
a 12-bit 125 kHz sampling SAR type A/D converter. Many cheap LCD displays
|
||||
contain this controller. Typically, it is connected via SPI.
|
||||
|
||||
To align the touch point with the display coordinates, it might be
|
||||
necessary to calibrate the touch screen. The XPT2046 sensor provides
|
||||
raw values within the range of 0 to 4095. If you identify the raw
|
||||
values associated with the screen edges, you can perform touch
|
||||
panel calibration by invoking the Calibrate procedure.
|
||||
|
||||
```ada
|
||||
subtype Sensor_Value is HAL.UInt16 range 0 .. 2 ** 12 - 1;
|
||||
|
||||
procedure Calibrate
|
||||
(This : in out XPT2046_Device'Class;
|
||||
Min_X : Sensor_Value;
|
||||
Max_X : Sensor_Value;
|
||||
Min_Y : Sensor_Value;
|
||||
Max_Y : Sensor_Value);
|
||||
```
|
||||
|
||||
* [Datasheet](https://www.datasheet-pdf.info/attach/1/3898350023.pdf)
|
||||
* [Example for STM32 F4VE board](../../../../examples/stm32_f4ve/lcd)
|
|
@ -0,0 +1,47 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- XPT2046 has an internal temperature sensor.
|
||||
-- This function reads the temperature from it, if you provide a reference
|
||||
-- voltage (in milivolts).
|
||||
|
||||
function XPT2046.Temperature
|
||||
(This : in out XPT2046_Device'Class;
|
||||
V_Ref_mV : Natural) return Integer
|
||||
is
|
||||
Result : Natural := 0;
|
||||
Temp : constant Sensor_Value := This.Read_Sensor_3
|
||||
(Channel_Temp, Reference => Single_Ended, Last => True);
|
||||
begin
|
||||
Result := 25 - (Natural (Temp) * V_Ref_mV * 10 / 4096 - 6000) / 21;
|
||||
|
||||
return Result;
|
||||
end XPT2046.Temperature;
|
|
@ -0,0 +1,284 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with Ada.Unchecked_Conversion;
|
||||
|
||||
package body XPT2046 is
|
||||
|
||||
type Power_Down_Mode is
|
||||
(Power_Down, -- Power Down Between Conversions
|
||||
Reference_Off, -- Reference off, ADC on
|
||||
ADC_Off, -- Reference on, ADC off
|
||||
Always_On);
|
||||
|
||||
for Power_Down_Mode use
|
||||
(Power_Down => 0,
|
||||
Reference_Off => 1,
|
||||
ADC_Off => 2,
|
||||
Always_On => 3);
|
||||
|
||||
type Conversion_Mode is (Use_12_Bits, Use_8_Bits);
|
||||
pragma Unreferenced (Use_8_Bits);
|
||||
|
||||
type Control_Byte is record
|
||||
Power_Down : Power_Down_Mode;
|
||||
Reference : Reference_Kind;
|
||||
Mode : Conversion_Mode;
|
||||
Channel : Natural range 0 .. 7;
|
||||
Start : Boolean;
|
||||
end record;
|
||||
|
||||
for Control_Byte use record
|
||||
Power_Down at 0 range 0 .. 1;
|
||||
Reference at 0 range 2 .. 2;
|
||||
Mode at 0 range 3 .. 3;
|
||||
Channel at 0 range 4 .. 6;
|
||||
Start at 0 range 7 .. 7;
|
||||
end record;
|
||||
|
||||
function Cast is new Ada.Unchecked_Conversion (Control_Byte, HAL.UInt8);
|
||||
|
||||
procedure Read_Sensors
|
||||
(This : XPT2046_Device'Class;
|
||||
X, Y, Z1, Z2 : out Sensor_Value);
|
||||
|
||||
Z_Treshold : constant Sensor_Value := 3200;
|
||||
|
||||
-------------------------
|
||||
-- Active_Touch_Points --
|
||||
-------------------------
|
||||
|
||||
overriding
|
||||
function Active_Touch_Points
|
||||
(This : in out XPT2046_Device) return HAL.Touch_Panel.Touch_Identifier
|
||||
is
|
||||
X, Y, Z1, Z2 : Sensor_Value;
|
||||
begin
|
||||
This.Read_Sensors (X, Y, Z1, Z2);
|
||||
return (if Z2 - Z1 < Z_Treshold then 1 else 0);
|
||||
end Active_Touch_Points;
|
||||
|
||||
---------------
|
||||
-- Calibrate --
|
||||
---------------
|
||||
|
||||
procedure Calibrate
|
||||
(This : in out XPT2046_Device'Class;
|
||||
Min_X : Sensor_Value;
|
||||
Max_X : Sensor_Value;
|
||||
Min_Y : Sensor_Value;
|
||||
Max_Y : Sensor_Value) is
|
||||
begin
|
||||
This.Min_X := Min_X;
|
||||
This.Max_X := Max_X;
|
||||
This.Min_Y := Min_Y;
|
||||
This.Max_Y := Max_Y;
|
||||
end Calibrate;
|
||||
|
||||
--------------------------
|
||||
-- Get_All_Touch_Points --
|
||||
--------------------------
|
||||
|
||||
overriding
|
||||
function Get_All_Touch_Points
|
||||
(This : in out XPT2046_Device) return HAL.Touch_Panel.TP_State
|
||||
is
|
||||
Result : constant TP_Touch_State := This.Get_Touch_Point (1);
|
||||
begin
|
||||
if Result = Null_Touch_State then
|
||||
return (1 .. 0 => <>);
|
||||
else
|
||||
return (1 => Result);
|
||||
end if;
|
||||
end Get_All_Touch_Points;
|
||||
|
||||
---------------------
|
||||
-- Get_Touch_Point --
|
||||
---------------------
|
||||
|
||||
overriding
|
||||
function Get_Touch_Point
|
||||
(This : in out XPT2046_Device;
|
||||
Touch_Id : HAL.Touch_Panel.Touch_Identifier)
|
||||
return HAL.Touch_Panel.TP_Touch_State
|
||||
is
|
||||
pragma Unreferenced (Touch_Id);
|
||||
|
||||
Result : HAL.Touch_Panel.TP_Touch_State;
|
||||
X, Y, Z1, Z2 : Sensor_Value;
|
||||
begin
|
||||
This.Read_Sensors (X, Y, Z1, Z2);
|
||||
|
||||
if Z2 - Z1 >= Z_Treshold or Z1 = 0 or X < This.Min_X then
|
||||
return Null_Touch_State;
|
||||
end if;
|
||||
|
||||
Result.X := Natural (X - Sensor_Value'Min (This.Min_X, X))
|
||||
* This.LCD_Natural_Width / Natural (This.Max_X - This.Min_X);
|
||||
|
||||
Result.Y := Natural (Y - Sensor_Value'Min (This.Min_Y, Y))
|
||||
* This.LCD_Natural_Height / Natural (This.Max_Y - This.Min_Y);
|
||||
|
||||
Result.X := Natural'Min (Result.X, This.LCD_Natural_Width - 1);
|
||||
Result.Y := Natural'Min (Result.Y, This.LCD_Natural_Height - 1);
|
||||
|
||||
if (This.Swap and Invert_X) /= 0 then
|
||||
Result.X := This.LCD_Natural_Width - 1 - Result.X;
|
||||
end if;
|
||||
|
||||
if (This.Swap and Invert_Y) /= 0 then
|
||||
Result.Y := This.LCD_Natural_Height - 1 - Result.Y;
|
||||
end if;
|
||||
|
||||
if (This.Swap and Swap_XY) /= 0 then
|
||||
declare
|
||||
Temp : constant Natural := Result.X;
|
||||
begin
|
||||
Result.X := Result.Y;
|
||||
Result.Y := Temp;
|
||||
end;
|
||||
end if;
|
||||
|
||||
Result.Weight := Natural (X) * Natural (Z2 - Z1) / Natural (Z1);
|
||||
Result.Weight := Result.Weight / 500;
|
||||
Result.Weight := Natural'Max (4, Result.Weight);
|
||||
Result.Weight := Natural'Min (19, Result.Weight);
|
||||
Result.Weight := 20 - Result.Weight;
|
||||
|
||||
return Result;
|
||||
end Get_Touch_Point;
|
||||
|
||||
-----------------
|
||||
-- Read_Sensor --
|
||||
-----------------
|
||||
|
||||
function Read_Sensor
|
||||
(This : XPT2046_Device'Class;
|
||||
Channel : Natural;
|
||||
Last : Boolean := False;
|
||||
Reference : Reference_Kind := Differential) return Sensor_Value
|
||||
is
|
||||
use all type HAL.SPI.SPI_Status;
|
||||
|
||||
Status : HAL.SPI.SPI_Status;
|
||||
Response : HAL.SPI.SPI_Data_8b (1 .. 2);
|
||||
|
||||
Mode : constant Power_Down_Mode :=
|
||||
(if Last then Power_Down else Reference_Off);
|
||||
-- elsif Reference = Differential then Reference_Off
|
||||
-- else Always_On);
|
||||
|
||||
Control : constant Control_Byte :=
|
||||
(Power_Down => Mode,
|
||||
Reference => Reference,
|
||||
Mode => Use_12_Bits,
|
||||
Channel => Channel,
|
||||
Start => True);
|
||||
begin
|
||||
This.SPI.Transmit (HAL.SPI.SPI_Data_8b'(1 => Cast (Control)), Status);
|
||||
pragma Assert (Status = Ok);
|
||||
This.SPI.Receive (Response, Status);
|
||||
pragma Assert (Status = Ok);
|
||||
|
||||
return HAL.Shift_Left (HAL.UInt16 (Response (1)) and 127, 5) +
|
||||
HAL.Shift_Right (HAL.UInt16 (Response (2)), 3);
|
||||
end Read_Sensor;
|
||||
|
||||
-------------------
|
||||
-- Read_Sensor_3 --
|
||||
-------------------
|
||||
|
||||
function Read_Sensor_3
|
||||
(This : XPT2046_Device'Class;
|
||||
Channel : Natural;
|
||||
Last : Boolean := False;
|
||||
Reference : Reference_Kind := Differential) return Sensor_Value
|
||||
is
|
||||
List : array (1 .. 3) of Sensor_Value;
|
||||
Max : Sensor_Value := Sensor_Value'First;
|
||||
Min : Sensor_Value := Sensor_Value'Last;
|
||||
begin
|
||||
for J in 1 .. 3 loop
|
||||
List (J) := This.Read_Sensor
|
||||
(Channel,
|
||||
Last => J = 3 and Last,
|
||||
Reference => Reference);
|
||||
|
||||
Min := Sensor_Value'Min (Min, List (J));
|
||||
Max := Sensor_Value'Max (Max, List (J));
|
||||
end loop;
|
||||
|
||||
for X of List loop
|
||||
if X < Max and X > Min then
|
||||
return X;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
if List (1) in List (2) | List (3) then
|
||||
return List (1);
|
||||
else
|
||||
return List (2);
|
||||
end if;
|
||||
end Read_Sensor_3;
|
||||
|
||||
------------------
|
||||
-- Read_Sensors --
|
||||
------------------
|
||||
|
||||
procedure Read_Sensors
|
||||
(This : XPT2046_Device'Class;
|
||||
X, Y, Z1, Z2 : out Sensor_Value) is
|
||||
begin
|
||||
This.CS.Clear;
|
||||
X := This.Read_Sensor (Channel_X);
|
||||
Y := This.Read_Sensor_3 (Channel_Y); -- Y is so noisy
|
||||
Z1 := This.Read_Sensor (Channel_Z1);
|
||||
Z2 := This.Read_Sensor (Channel_Z2, Last => True);
|
||||
This.CS.Set;
|
||||
end Read_Sensors;
|
||||
|
||||
----------------
|
||||
-- Set_Bounds --
|
||||
----------------
|
||||
|
||||
overriding
|
||||
procedure Set_Bounds
|
||||
(This : in out XPT2046_Device;
|
||||
Width : Natural;
|
||||
Height : Natural;
|
||||
Swap : HAL.Touch_Panel.Swap_State) is
|
||||
begin
|
||||
This.LCD_Natural_Width := Width;
|
||||
This.LCD_Natural_Height := Height;
|
||||
This.Swap := Swap;
|
||||
end Set_Bounds;
|
||||
|
||||
end XPT2046;
|
|
@ -0,0 +1,121 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- Generic driver for the XPT2046 touch panel
|
||||
|
||||
with HAL;
|
||||
with HAL.GPIO;
|
||||
with HAL.SPI;
|
||||
with HAL.Touch_Panel; use HAL.Touch_Panel;
|
||||
|
||||
package XPT2046 is
|
||||
|
||||
type XPT2046_Device
|
||||
(SPI : not null HAL.SPI.Any_SPI_Port;
|
||||
CS : not null HAL.GPIO.Any_GPIO_Point) is
|
||||
limited new Touch_Panel_Device with private;
|
||||
|
||||
use type HAL.UInt16;
|
||||
|
||||
subtype Sensor_Value is HAL.UInt16 range 0 .. 2 ** 12 - 1;
|
||||
|
||||
procedure Calibrate
|
||||
(This : in out XPT2046_Device'Class;
|
||||
Min_X : Sensor_Value;
|
||||
Max_X : Sensor_Value;
|
||||
Min_Y : Sensor_Value;
|
||||
Max_Y : Sensor_Value);
|
||||
-- Usually, sensor values at the boundary points differ from the
|
||||
-- minimum/maximum. With the help of this procedure, we can calibrate
|
||||
-- the touch panel to return accurate values.
|
||||
|
||||
private
|
||||
|
||||
type XPT2046_Device
|
||||
(SPI : not null HAL.SPI.Any_SPI_Port;
|
||||
CS : not null HAL.GPIO.Any_GPIO_Point) is
|
||||
limited new HAL.Touch_Panel.Touch_Panel_Device with
|
||||
record
|
||||
LCD_Natural_Width : Natural := 0;
|
||||
LCD_Natural_Height : Natural := 0;
|
||||
Swap : Swap_State := 0;
|
||||
Min_X : Sensor_Value := Sensor_Value'First;
|
||||
Max_X : Sensor_Value := Sensor_Value'Last;
|
||||
Min_Y : Sensor_Value := Sensor_Value'First;
|
||||
Max_Y : Sensor_Value := Sensor_Value'Last;
|
||||
end record;
|
||||
|
||||
overriding
|
||||
procedure Set_Bounds (This : in out XPT2046_Device;
|
||||
Width : Natural;
|
||||
Height : Natural;
|
||||
Swap : HAL.Touch_Panel.Swap_State);
|
||||
|
||||
overriding
|
||||
function Active_Touch_Points (This : in out XPT2046_Device)
|
||||
return HAL.Touch_Panel.Touch_Identifier;
|
||||
|
||||
overriding
|
||||
function Get_Touch_Point (This : in out XPT2046_Device;
|
||||
Touch_Id : HAL.Touch_Panel.Touch_Identifier)
|
||||
return HAL.Touch_Panel.TP_Touch_State;
|
||||
|
||||
overriding
|
||||
function Get_All_Touch_Points
|
||||
(This : in out XPT2046_Device) return HAL.Touch_Panel.TP_State;
|
||||
|
||||
type Reference_Kind is (Differential, Single_Ended);
|
||||
-- XPT2046 can measure in two modes: differential and single-ended.
|
||||
-- Differential mode is better for X, Y, Z measurement, but temperature
|
||||
-- and battery voltage measurement could be done in single-ended mode only.
|
||||
|
||||
Channel_Temp : constant := 0;
|
||||
Channel_Y : constant := 1;
|
||||
Channel_Z1 : constant := 3;
|
||||
Channel_Z2 : constant := 4;
|
||||
Channel_X : constant := 5;
|
||||
|
||||
function Read_Sensor
|
||||
(This : XPT2046_Device'Class;
|
||||
Channel : Natural;
|
||||
Last : Boolean := False;
|
||||
Reference : Reference_Kind := Differential) return Sensor_Value;
|
||||
-- Read ADC sensor value from given cannel using given reference mode.
|
||||
-- If Last is True then shutdown the power.
|
||||
|
||||
function Read_Sensor_3
|
||||
(This : XPT2046_Device'Class;
|
||||
Channel : Natural;
|
||||
Last : Boolean := False;
|
||||
Reference : Reference_Kind := Differential) return Sensor_Value;
|
||||
-- Read 3 values from the same channel and return a middle one.
|
||||
|
||||
end XPT2046;
|
|
@ -71,6 +71,7 @@ board you have:
|
|||
- [STM32F4_DISCO](STM32F4_DISCO)
|
||||
- [STM32F746_Discovery](STM32F746_Discovery)
|
||||
- [STM32F769_Discovery](STM32F769_Discovery)
|
||||
- [stm32f4xx_m](stm32f4xx_m)
|
||||
|
||||
## Compile the project
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
The [STM32 F4VE](https://stm32-base.org/boards/STM32F407VET6-STM32-F4VE-V2.0) is
|
||||
a low cost development kit for the STM32F407 micro-controller.
|
||||
Typically, it can be purchased together with a 2.8" or 3.2" TFT LCD with a touchscreen.
|
||||
|
||||
|
||||
You can get it here:
|
||||
|
||||
- [Ebay](https://www.ebay.com/itm/295082465827)
|
||||
- [AliExpress](https://www.aliexpress.com/item/4000953664266.html)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
with "../../boards/stm32_f4ve/stm32_f4ve_full.gpr";
|
||||
|
||||
project Blinky_STM32_F4VE extends "../shared/common/common.gpr" is
|
||||
|
||||
for Runtime ("Ada") use STM32_F4VE_Full'Runtime("Ada");
|
||||
for Target use "arm-eabi";
|
||||
for Main use ("blinky.adb");
|
||||
for Languages use ("Ada");
|
||||
for Source_Dirs use ("../shared/hello_world_blinky/src");
|
||||
for Object_Dir use "../shared/hello_world_blinky/obj/stm32_f4ve";
|
||||
for Create_Missing_Dirs use "True";
|
||||
|
||||
package Compiler renames STM32_F4VE_Full.Compiler;
|
||||
|
||||
end Blinky_STM32_F4VE;
|
|
@ -0,0 +1,12 @@
|
|||
# Draw on the screen
|
||||
|
||||
This example is a modified version of the draw example for
|
||||
STM32F429 Discovery. Unlike the original, it does not use
|
||||
the Framebuffer interface. Touch the screen to draw. The
|
||||
thickness of points and lines during drawing depends on
|
||||
the pressure applied and what you touch on the screen.
|
||||
|
||||
Press the K-UP button for a demo of drawing primitives.
|
||||
|
||||
For this demo, you need an LCD with a touch panel, which
|
||||
is usually sold as part of the STM32 F4VE board kit.
|
|
@ -0,0 +1,183 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- A very simple draw application.
|
||||
-- Use your finger to draw pixels.
|
||||
|
||||
with HAL.Bitmap; use HAL.Bitmap;
|
||||
with HAL.Touch_Panel;
|
||||
with STM32.Board; use STM32.Board;
|
||||
with STM32.User_Button;
|
||||
|
||||
with Bitmapped_Drawing;
|
||||
with BMP_Fonts;
|
||||
with Display_ILI9341;
|
||||
|
||||
procedure Draw is
|
||||
|
||||
BG : constant Bitmap_Color := (Alpha => 255, others => 64);
|
||||
|
||||
procedure Clear;
|
||||
|
||||
-----------
|
||||
-- Clear --
|
||||
-----------
|
||||
|
||||
procedure Clear is
|
||||
|
||||
procedure Put_Line (Text : String);
|
||||
|
||||
Y : Natural := 10;
|
||||
|
||||
procedure Put_Line (Text : String) is
|
||||
begin
|
||||
Bitmapped_Drawing.Draw_String
|
||||
(TFT_Bitmap, (5, Y), Text, BMP_Fonts.Font8x8, Green, BG);
|
||||
|
||||
Y := Y + 10;
|
||||
end Put_Line;
|
||||
begin
|
||||
TFT_Bitmap.Set_Source (BG);
|
||||
TFT_Bitmap.Fill;
|
||||
TFT_Bitmap.Set_Source (White);
|
||||
|
||||
Put_Line ("Touch the screen to draw or");
|
||||
Put_Line ("press the K-UP button for");
|
||||
Put_Line ("a demo of drawing primitives.");
|
||||
end Clear;
|
||||
|
||||
Last_X : Integer := -1;
|
||||
Last_Y : Integer := -1;
|
||||
|
||||
type Mode is (Drawing_Mode, Bitmap_Showcase_Mode);
|
||||
|
||||
Current_Mode : Mode := Drawing_Mode;
|
||||
|
||||
begin
|
||||
-- Initialize LCD
|
||||
Display.Initialize;
|
||||
|
||||
-- Initialize touch panel
|
||||
Touch_Panel.Initialize;
|
||||
|
||||
-- Initialize button
|
||||
STM32.User_Button.Initialize;
|
||||
|
||||
-- Clear LCD (set background)
|
||||
Clear;
|
||||
|
||||
-- The application: set pixel where the finger is (so that you
|
||||
-- cannot see what you are drawing).
|
||||
loop
|
||||
if STM32.User_Button.Has_Been_Pressed then
|
||||
case Current_Mode is
|
||||
when Drawing_Mode =>
|
||||
Current_Mode := Bitmap_Showcase_Mode;
|
||||
when Bitmap_Showcase_Mode =>
|
||||
Clear;
|
||||
Current_Mode := Drawing_Mode;
|
||||
end case;
|
||||
end if;
|
||||
|
||||
if Current_Mode = Drawing_Mode then
|
||||
|
||||
TFT_Bitmap.Set_Source (HAL.Bitmap.Green);
|
||||
|
||||
declare
|
||||
State : constant HAL.Touch_Panel.TP_State :=
|
||||
Touch_Panel.Get_All_Touch_Points;
|
||||
begin
|
||||
if State'Length /= 1 then
|
||||
Last_X := -1;
|
||||
Last_Y := -1;
|
||||
|
||||
else
|
||||
-- Lines can be drawn between two consecutive points only when
|
||||
-- one touch point is active: the order of the touch data is not
|
||||
-- necessarily preserved by the hardware.
|
||||
if Last_X > 0 then
|
||||
TFT_Bitmap.Draw_Line
|
||||
(Start => (Last_X, Last_Y),
|
||||
Stop => (State (State'First).X, State (State'First).Y),
|
||||
Thickness => State (State'First).Weight,
|
||||
Fast => False);
|
||||
end if;
|
||||
|
||||
Last_X := State (State'First).X;
|
||||
Last_Y := State (State'First).Y;
|
||||
end if;
|
||||
|
||||
for Id in State'Range loop
|
||||
TFT_Bitmap.Fill_Circle
|
||||
(Center => (State (Id).X, State (Id).Y),
|
||||
Radius => State (Id).Weight);
|
||||
end loop;
|
||||
end;
|
||||
else
|
||||
|
||||
-- Show some of the supported drawing primitives
|
||||
|
||||
TFT_Bitmap.Set_Source (Black);
|
||||
TFT_Bitmap.Fill;
|
||||
|
||||
TFT_Bitmap.Set_Source (Green);
|
||||
TFT_Bitmap.Fill_Rounded_Rect
|
||||
(((10, 10), 100, 100), 20);
|
||||
|
||||
TFT_Bitmap.Set_Source (HAL.Bitmap.Red);
|
||||
TFT_Bitmap.Draw_Rounded_Rect
|
||||
(((10, 10), 100, 100), 20, Thickness => 4);
|
||||
|
||||
TFT_Bitmap.Set_Source (HAL.Bitmap.Yellow);
|
||||
TFT_Bitmap.Fill_Circle ((60, 60), 20);
|
||||
|
||||
TFT_Bitmap.Set_Source (HAL.Bitmap.Blue);
|
||||
TFT_Bitmap.Draw_Circle ((60, 60), 20);
|
||||
|
||||
TFT_Bitmap.Set_Source (HAL.Bitmap.Violet);
|
||||
TFT_Bitmap.Cubic_Bezier (P1 => (10, 10),
|
||||
P2 => (60, 10),
|
||||
P3 => (60, 60),
|
||||
P4 => (100, 100),
|
||||
N => 200,
|
||||
Thickness => 5);
|
||||
|
||||
Display_ILI9341.ILI9341_Bitmap.Copy_Rect
|
||||
(Src_Buffer => TFT_Bitmap,
|
||||
Src_Pt => (0, 0),
|
||||
Dst_Buffer => TFT_Bitmap,
|
||||
Dst_Pt => (100, 100),
|
||||
Width => 100,
|
||||
Height => 100,
|
||||
Synchronous => True);
|
||||
end if;
|
||||
end loop;
|
||||
end Draw;
|
|
@ -0,0 +1,20 @@
|
|||
with "../../../boards/stm32_f4ve/stm32_f4ve_full.gpr";
|
||||
|
||||
project Draw is
|
||||
|
||||
for Runtime ("Ada") use STM32_f4VE_Full'Runtime ("Ada");
|
||||
for Target use "arm-eabi";
|
||||
for Main use ("draw.adb");
|
||||
for Languages use ("Ada");
|
||||
for Source_Dirs use (".", "../../shared/common/gui");
|
||||
for Object_Dir use "obj/";
|
||||
for Create_Missing_Dirs use "True";
|
||||
|
||||
package Compiler renames STM32_F4VE_Full.Compiler;
|
||||
|
||||
package Ide is
|
||||
for Program_Host use "localhost:4242";
|
||||
for Communication_Protocol use "remote";
|
||||
for Connection_Tool use "st-util";
|
||||
end Ide;
|
||||
end Draw;
|
|
@ -0,0 +1,9 @@
|
|||
# LCD demo
|
||||
|
||||
This example demonstrates working with the LCD using the
|
||||
HAL.Bitmap.Bitmap_Buffer interface.
|
||||
Colorful rectangles are displayed on the screen, and their
|
||||
colors change based on the X and Y coordinates.
|
||||
|
||||
For this demo, you need an LCD, which is usually sold as
|
||||
part of the STM32 F4VE board kit.
|
|
@ -0,0 +1,20 @@
|
|||
with "../../../boards/stm32_f4ve/stm32_f4ve_full.gpr";
|
||||
|
||||
project LCD is
|
||||
|
||||
for Runtime ("Ada") use STM32_f4VE_Full'Runtime ("Ada");
|
||||
for Target use "arm-eabi";
|
||||
for Main use ("main.adb");
|
||||
for Languages use ("Ada");
|
||||
for Source_Dirs use (".");
|
||||
for Object_Dir use "obj/";
|
||||
for Create_Missing_Dirs use "True";
|
||||
|
||||
package Compiler renames STM32_F4VE_Full.Compiler;
|
||||
|
||||
package Ide is
|
||||
for Program_Host use "localhost:4242";
|
||||
for Communication_Protocol use "remote";
|
||||
for Connection_Tool use "st-util";
|
||||
end Ide;
|
||||
end LCD;
|
|
@ -0,0 +1,71 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with Ada.Real_Time;
|
||||
|
||||
with HAL.Bitmap;
|
||||
|
||||
with STM32.Board;
|
||||
with Display_ILI9341;
|
||||
|
||||
procedure Main is
|
||||
use type Ada.Real_Time.Time;
|
||||
|
||||
Next : Ada.Real_Time.Time := Ada.Real_Time.Clock;
|
||||
|
||||
Bitmap : Display_ILI9341.Bitmap_Buffer renames STM32.Board.TFT_Bitmap;
|
||||
|
||||
begin
|
||||
STM32.Board.Initialize_LEDs;
|
||||
STM32.Board.Display.Initialize;
|
||||
|
||||
Bitmap.Set_Source (HAL.Bitmap.Black);
|
||||
Bitmap.Fill;
|
||||
|
||||
for X in 0 .. 31 loop
|
||||
for Y in 0 .. 31 loop
|
||||
Bitmap.Set_Source
|
||||
((Alpha => 255,
|
||||
Green => 128,
|
||||
Red => HAL.UInt8 (X * 8),
|
||||
Blue => HAL.UInt8 (Y * 8)));
|
||||
|
||||
Bitmap.Fill_Rect (((X * 7, Y * 10), 6, 9));
|
||||
end loop;
|
||||
end loop;
|
||||
|
||||
loop
|
||||
STM32.Board.Toggle (STM32.Board.D1_LED);
|
||||
|
||||
Next := Next + Ada.Real_Time.Milliseconds (500);
|
||||
delay until Next;
|
||||
end loop;
|
||||
end Main;
|
|
@ -0,0 +1,7 @@
|
|||
The [STM32F4XX M](https://stm32-base.org/boards/STM32F407VGT6-STM32F4XX-M) is
|
||||
a low cost development kit for the STM32F407 micro-controller.
|
||||
|
||||
You can get it here:
|
||||
|
||||
- [AliExpress](https://www.aliexpress.com/item/4000602517153.html)
|
||||
- [ebay](https://www.ebay.com/itm/385792548401)
|
|
@ -0,0 +1,7 @@
|
|||
# Flash memory erase/write/read example
|
||||
|
||||
In this example we erase and flash part of the W25Q16 flash memory
|
||||
when K1 button is pressed on reset. If the button is not pressed, the
|
||||
program reads the flash memory and checks its content. If everything is
|
||||
OK, the program blinks the green LED slowly (1 Hz), but otherwise it blinks
|
||||
the LED faster (5 Hz).
|
|
@ -37,13 +37,10 @@
|
|||
|
||||
with Ada.Real_Time;
|
||||
|
||||
with HAL.SPI;
|
||||
with HAL.Flash;
|
||||
|
||||
with STM32.Board;
|
||||
with STM32.GPIO;
|
||||
with STM32.SPI;
|
||||
with STM32.Device;
|
||||
|
||||
with W25Q16;
|
||||
|
||||
|
@ -134,53 +131,13 @@ procedure Main is
|
|||
Next : Ada.Real_Time.Time := Ada.Real_Time.Clock;
|
||||
Span : Ada.Real_Time.Time_Span;
|
||||
|
||||
SPI : STM32.SPI.SPI_Port renames STM32.Device.SPI_1;
|
||||
SPI_SCK : STM32.GPIO.GPIO_Point renames STM32.Device.PB3;
|
||||
SPI_MISO : STM32.GPIO.GPIO_Point renames STM32.Device.PB4;
|
||||
SPI_MOSI : STM32.GPIO.GPIO_Point renames STM32.Device.PB5;
|
||||
SPI_CS : STM32.GPIO.GPIO_Point renames STM32.Device.PA15;
|
||||
|
||||
SPI_Pins : constant STM32.GPIO.GPIO_Points :=
|
||||
(SPI_SCK, SPI_MISO, SPI_MOSI);
|
||||
|
||||
Flash : W25Q16.Flash_Memory
|
||||
(SPI'Unchecked_Access, SPI_CS'Unchecked_Access);
|
||||
Flash : W25Q16.Flash_Memory renames STM32.Board.Flash;
|
||||
|
||||
Ok : Boolean := False;
|
||||
begin
|
||||
STM32.Board.Initialize_LEDs;
|
||||
STM32.Board.Configure_User_Button_GPIO;
|
||||
STM32.Device.Enable_Clock (SPI_Pins);
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(SPI_CS,
|
||||
(Mode => STM32.GPIO.Mode_Out,
|
||||
Resistors => STM32.GPIO.Floating,
|
||||
Output_Type => STM32.GPIO.Push_Pull,
|
||||
Speed => STM32.GPIO.Speed_100MHz));
|
||||
|
||||
STM32.GPIO.Configure_IO
|
||||
(SPI_Pins,
|
||||
(Mode => STM32.GPIO.Mode_AF,
|
||||
Resistors => STM32.GPIO.Pull_Up,
|
||||
AF_Output_Type => STM32.GPIO.Push_Pull,
|
||||
AF_Speed => STM32.GPIO.Speed_100MHz,
|
||||
AF => STM32.Device.GPIO_AF_SPI1_5));
|
||||
|
||||
STM32.Device.Enable_Clock (SPI);
|
||||
|
||||
STM32.SPI.Configure
|
||||
(SPI,
|
||||
(Direction => STM32.SPI.D2Lines_FullDuplex,
|
||||
Mode => STM32.SPI.Master,
|
||||
Data_Size => HAL.SPI.Data_Size_8b,
|
||||
Clock_Polarity => STM32.SPI.High, -- Mode 3
|
||||
Clock_Phase => STM32.SPI.P2Edge,
|
||||
Slave_Management => STM32.SPI.Software_Managed,
|
||||
Baud_Rate_Prescaler => STM32.SPI.BRP_2,
|
||||
First_Bit => STM32.SPI.MSB,
|
||||
CRC_Poly => 0));
|
||||
-- SPI1 sits on APB2, which is 84MHz, so SPI rate in 84/2=42MHz
|
||||
STM32.Board.Initialize_Flash_Memory;
|
||||
|
||||
Flash.Check_JEDEC_ID (Ok);
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# SD card filesystem example
|
||||
|
||||
Turns on the LED and waits for the SD card. Then, it mounts the first FAT
|
||||
partition as '/card/', opens the `/file.txt` file and reads 512 bytes from
|
||||
it. If everything is okay, the program blinks the green LED slowly
|
||||
at a rate of 1 Hz. Otherwise, it blinks the LED faster at 5 Hz.
|
|
@ -0,0 +1,20 @@
|
|||
with "../../../boards/stm32f4xx_m/stm32f4xx_m_full.gpr";
|
||||
|
||||
project SDCard_FS is
|
||||
|
||||
for Runtime ("Ada") use STM32F4XX_M_Full'Runtime ("Ada");
|
||||
for Target use "arm-eabi";
|
||||
for Main use ("main.adb");
|
||||
for Languages use ("Ada");
|
||||
for Source_Dirs use ("src");
|
||||
for Object_Dir use "obj/";
|
||||
for Create_Missing_Dirs use "True";
|
||||
|
||||
package Compiler renames STM32F4XX_M_Full.Compiler;
|
||||
|
||||
package Ide is
|
||||
for Program_Host use "localhost:4242";
|
||||
for Communication_Protocol use "remote";
|
||||
for Connection_Tool use "st-util";
|
||||
end Ide;
|
||||
end SDCard_FS;
|
|
@ -0,0 +1,97 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- Turns on the LED and waits for the SD card. Then, it mounts the first FAT
|
||||
-- partition as '/card/', opens the `/file.txt` file and reads 512 bytes from
|
||||
-- it. If everything is okay, the program blinks the green LED slowly
|
||||
-- at a rate of 1 Hz. Otherwise, it blinks the LED faster at 5 Hz.
|
||||
|
||||
pragma Ada_2022;
|
||||
|
||||
with Ada.Real_Time;
|
||||
|
||||
with File_IO;
|
||||
with HAL;
|
||||
with SDCard;
|
||||
with STM32.Board;
|
||||
|
||||
procedure Main is
|
||||
use type Ada.Real_Time.Time;
|
||||
use all type File_IO.Status_Code;
|
||||
|
||||
Next : Ada.Real_Time.Time := Ada.Real_Time.Clock;
|
||||
|
||||
SD_Card renames STM32.Board.SDCard_Device;
|
||||
-- Typeless renaming works since Ada 2022
|
||||
|
||||
Success : Boolean;
|
||||
begin
|
||||
STM32.Board.Initialize_LEDs;
|
||||
SD_Card.Initialize;
|
||||
STM32.Board.Green_LED.Set;
|
||||
|
||||
-- Wait for card
|
||||
while not SD_Card.Card_Present loop
|
||||
Next := Next + Ada.Real_Time.Milliseconds (200);
|
||||
delay until Next;
|
||||
end loop;
|
||||
|
||||
Success := File_IO.Mount_Drive ("card", SD_Card'Unchecked_Access) = OK;
|
||||
-- Mounting the SD card as '/card/'
|
||||
|
||||
declare
|
||||
use type File_IO.File_Size;
|
||||
|
||||
FD : File_IO.File_Descriptor;
|
||||
Data : HAL.UInt8_Array (1 .. 512);
|
||||
Last : File_IO.File_Size;
|
||||
begin
|
||||
if Success then
|
||||
Success := File_IO.Open
|
||||
(FD, "/card/file.txt", File_IO.Read_Only) = OK;
|
||||
end if;
|
||||
|
||||
if Success then
|
||||
Last := File_IO.Read (FD, Data'Address, Data'Length);
|
||||
|
||||
Success := Last = Data'Length;
|
||||
end if;
|
||||
|
||||
loop
|
||||
STM32.Board.Toggle (STM32.Board.Green_LED);
|
||||
|
||||
Next := Next + Ada.Real_Time.Milliseconds
|
||||
(if Success then 500 else 100);
|
||||
|
||||
delay until Next;
|
||||
end loop;
|
||||
end;
|
||||
end Main;
|
|
@ -0,0 +1,6 @@
|
|||
# SD card read example
|
||||
|
||||
Turns on the LED and waits for the SD card. Then, it reads the first 512
|
||||
bytes from the SD card and checks for the 0x55 0xAA pattern at the end of
|
||||
the block. If everything is okay, the program blinks the green LED slowly
|
||||
at a rate of 1 Hz. Otherwise, it blinks the LED faster at 5 Hz.
|
|
@ -0,0 +1,20 @@
|
|||
with "../../../boards/stm32f4xx_m/stm32f4xx_m_full.gpr";
|
||||
|
||||
project SDCard_Raw_IO is
|
||||
|
||||
for Runtime ("Ada") use STM32F4XX_M_Full'Runtime ("Ada");
|
||||
for Target use "arm-eabi";
|
||||
for Main use ("main.adb");
|
||||
for Languages use ("Ada");
|
||||
for Source_Dirs use ("src");
|
||||
for Object_Dir use "obj/";
|
||||
for Create_Missing_Dirs use "True";
|
||||
|
||||
package Compiler renames STM32F4XX_M_Full.Compiler;
|
||||
|
||||
package Ide is
|
||||
for Program_Host use "localhost:4242";
|
||||
for Communication_Protocol use "remote";
|
||||
for Connection_Tool use "st-util";
|
||||
end Ide;
|
||||
end SDCard_Raw_IO;
|
|
@ -0,0 +1,82 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
-- met: --
|
||||
-- 1. Redistributions of source code must retain the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer. --
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright --
|
||||
-- notice, this list of conditions and the following disclaimer in --
|
||||
-- the documentation and/or other materials provided with the --
|
||||
-- distribution. --
|
||||
-- 3. Neither the name of the copyright holder nor the names of its --
|
||||
-- contributors may be used to endorse or promote products derived --
|
||||
-- from this software without specific prior written permission. --
|
||||
-- --
|
||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
|
||||
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
|
||||
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
|
||||
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
|
||||
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
|
||||
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
|
||||
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
|
||||
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
||||
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
|
||||
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- Turns on the LED and waits for the SD card. Then, it reads the first 512
|
||||
-- bytes from the SD card and checks for the 0x55 0xAA pattern at the end of
|
||||
-- the block. If everything is okay, the program blinks the green LED slowly
|
||||
-- at a rate of 1 Hz. Otherwise, it blinks the LED faster at 5 Hz.
|
||||
|
||||
pragma Ada_2022;
|
||||
|
||||
with Ada.Real_Time;
|
||||
|
||||
with HAL;
|
||||
with STM32.Board;
|
||||
with SDCard;
|
||||
|
||||
procedure Main is
|
||||
use type Ada.Real_Time.Time;
|
||||
Next : Ada.Real_Time.Time := Ada.Real_Time.Clock;
|
||||
|
||||
SD_Card renames STM32.Board.SDCard_Device;
|
||||
-- Typeless renaming works since Ada 2022
|
||||
begin
|
||||
STM32.Board.Initialize_LEDs;
|
||||
SD_Card.Initialize;
|
||||
STM32.Board.Green_LED.Set;
|
||||
|
||||
-- Wait for card
|
||||
while not SD_Card.Card_Present loop
|
||||
Next := Next + Ada.Real_Time.Milliseconds (200);
|
||||
delay until Next;
|
||||
end loop;
|
||||
|
||||
declare
|
||||
use type HAL.UInt8_Array;
|
||||
|
||||
Data : HAL.UInt8_Array (1 .. 512);
|
||||
Ok : Boolean := SD_Card.Read (Block_Number => 0, Data => Data);
|
||||
begin
|
||||
if Ok then
|
||||
-- Check for 0x55 0xAA pattern at the end of MBR (Master Boot Record)
|
||||
Ok := Data (511 .. 512) = [16#55#, 16#AA#];
|
||||
end if;
|
||||
|
||||
loop
|
||||
STM32.Board.Toggle (STM32.Board.Green_LED);
|
||||
|
||||
Next := Next + Ada.Real_Time.Milliseconds
|
||||
(if Ok then 500 else 100);
|
||||
|
||||
delay until Next;
|
||||
end loop;
|
||||
end;
|
||||
end Main;
|
|
@ -1,6 +1,6 @@
|
|||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- Copyright (C) 2015-2016, AdaCore --
|
||||
-- Copyright (C) 2015-2023, AdaCore --
|
||||
-- --
|
||||
-- Redistribution and use in source and binary forms, with or without --
|
||||
-- modification, are permitted provided that the following conditions are --
|
||||
|
@ -34,13 +34,6 @@ with System;
|
|||
package HAL.Bitmap is
|
||||
pragma Preelaborate;
|
||||
|
||||
type Orientation_Mode is
|
||||
(Default,
|
||||
Portrait,
|
||||
Landscape);
|
||||
|
||||
subtype Actual_Orientation is Orientation_Mode range Portrait .. Landscape;
|
||||
|
||||
type Bitmap_Color_Mode is
|
||||
(ARGB_8888,
|
||||
RGB_888,
|
||||
|
|
|
@ -67,11 +67,20 @@ projects = [
|
|||
"/examples/STM32F4_DISCO/blinky_f4disco.gpr",
|
||||
"/examples/STM32F4_DISCO/serial_ports_f4disco.gpr",
|
||||
|
||||
# STM32 F4VE
|
||||
"/boards/stm32_f4ve/stm32_f4ve_full.gpr",
|
||||
"/boards/stm32_f4ve/stm32_f4ve_sfp.gpr",
|
||||
"/examples/stm32_f4ve/blinky_stm32_f4ve.gpr",
|
||||
"/examples/stm32_f4ve/draw/draw.gpr",
|
||||
"/examples/stm32_f4ve/lcd/lcd.gpr",
|
||||
|
||||
# STM32F4XX M
|
||||
"/boards/stm32f4xx_m/stm32f4xx_m_full.gpr",
|
||||
"/boards/stm32f4xx_m/stm32f4xx_m_sfp.gpr",
|
||||
"/examples/stm32f4xx_m/blinky/blinky.gpr",
|
||||
"/examples/stm32f4xx_m/flash/flash.gpr",
|
||||
"/examples/stm32f4xx_m/sdcard_fs/sdcard_fs.gpr",
|
||||
"/examples/stm32f4xx_m/sdcard_raw_io/sdcard_raw_io.gpr",
|
||||
|
||||
# Feather STM32F405
|
||||
"/examples/feather_stm32f405/blinky/blinky.gpr",
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import config
|
||||
import config.user_input.console
|
||||
from build_all_examples import run_program
|
||||
|
||||
from config.boards import list_of_boards
|
||||
|
||||
script_dir = os.path.dirname(__file__)
|
||||
ADL_root_dir = os.path.abspath(os.path.join(script_dir, ".."))
|
||||
top_readme_file = os.path.join(ADL_root_dir, "README.md")
|
||||
|
||||
undocumented = []
|
||||
|
||||
error = \
|
||||
"""Next boards were not mentioned in the top README.md file!
|
||||
Please, append each of them to the table in the Board List section.
|
||||
"""
|
||||
|
||||
with open(top_readme_file, 'r', encoding='utf-8') as file:
|
||||
lines = [line for line in file]
|
||||
|
||||
# No error on Custom_Board:
|
||||
lines.append("[Custom_Board]")
|
||||
|
||||
for board in list_of_boards():
|
||||
text = f"[{board}]"
|
||||
found = [line for line in lines if text in line]
|
||||
if not found:
|
||||
undocumented.append(board)
|
||||
|
||||
if undocumented:
|
||||
print(error)
|
||||
print(undocumented)
|
||||
sys.exit(1)
|
|
@ -7,6 +7,7 @@ def list_of_boards():
|
|||
'STM32F429_Discovery',
|
||||
'STM32F469_Discovery',
|
||||
'STM32F4XX_M',
|
||||
'STM32_F4VE',
|
||||
'STM32F746_Discovery',
|
||||
'STM32F769_Discovery',
|
||||
'STM32_H405',
|
||||
|
@ -90,8 +91,23 @@ def load_board_config(config):
|
|||
config.pre_define('Has_Ravenscar_SFP_Runtime', 'True', origin)
|
||||
config.pre_define('Has_Ravenscar_Full_Runtime', 'True', origin)
|
||||
config.pre_define('Runtime_Name_Suffix', 'stm32f4', origin)
|
||||
config.add_source_dir('boards/stm32_common/stm32f4xx_m/', origin)
|
||||
config.add_source_dir('boards/stm32f4xx_m/src/', origin)
|
||||
config.add_source_dir('boards/stm32_common/common/', origin)
|
||||
config.add_source_dir('boards/stm32_common/sdcard/', origin)
|
||||
|
||||
elif board == "STM32_F4VE":
|
||||
config.pre_define('Architecture', 'ARM', origin)
|
||||
config.pre_define('Vendor', 'STMicro', origin)
|
||||
config.pre_define('Device_Family', 'STM32F4', origin)
|
||||
config.pre_define('Device_Name', 'STM32F407VGTx', origin)
|
||||
config.pre_define('High_Speed_External_Clock', '8000000', origin)
|
||||
config.pre_define('Has_ZFP_Runtime', 'False', origin)
|
||||
config.pre_define('Has_Ravenscar_SFP_Runtime', 'True', origin)
|
||||
config.pre_define('Has_Ravenscar_Full_Runtime', 'True', origin)
|
||||
config.pre_define('Runtime_Name_Suffix', 'stm32f4', origin)
|
||||
config.add_source_dir('boards/stm32_f4ve/src/', origin)
|
||||
config.add_source_dir('boards/stm32_common/common/', origin)
|
||||
config.add_source_dir('boards/stm32_common/sdcard/', origin)
|
||||
|
||||
elif board == "STM32F746_Discovery":
|
||||
config.pre_define('Architecture', 'ARM', origin)
|
||||
|
|
|
@ -83,6 +83,7 @@ def load_device_config(config, source_dir):
|
|||
'arch/ARM/STM32/drivers/dma/',
|
||||
'arch/ARM/STM32/drivers/dma_interrupts/',
|
||||
'arch/ARM/STM32/drivers/crc_stm32f4/',
|
||||
'arch/ARM/STM32/drivers/fsmc/',
|
||||
'arch/ARM/STM32/drivers/i2c_stm32f4',
|
||||
'arch/ARM/STM32/drivers/power_control_stm32f4',
|
||||
'arch/ARM/STM32/drivers/uart_stm32f4/',
|
||||
|
|
Loading…
Reference in New Issue