Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions components/src/io_expander/pcf8574/pcf8574.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--
-- Copyright 2022 (C) Rolf Ebert
--
-- SPDX-License-Identifier: BSD-3-Clause
--


package body PCF8574 is

-----------
-- Get --
-----------

function Get (This : PCF8574_Module) return UInt8
is
Val : I2C_Data (1 .. 1);
Status : I2C_Status;
begin
This.Port.Master_Receive (This.Addr, Val, Status);
return Val (1);
end Get;

procedure Get (This : PCF8574_Module; Data : out UInt8)
is begin
Data := Get (This);
end Get;

-----------
-- Set --
-----------

procedure Set (This : PCF8574_Module; Data : UInt8)
is
Status : I2C_Status;
begin
This.Port.Master_Transmit (This.Addr, (1 => Data), Status);
end Set;

end PCF8574;
38 changes: 38 additions & 0 deletions components/src/io_expander/pcf8574/pcf8574.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--
-- Copyright 2022 (C) Rolf Ebert
--
-- SPDX-License-Identifier: BSD-3-Clause
--

with HAL; use HAL;
with HAL.I2C; use HAL.I2C;

-- I2C 8-bit IO expander with quasi bidirectional I/O, no data
-- direction, no latch

package PCF8574 is

subtype PCF8574_Address is I2C_Address range 16#40# .. 16#5F#;

type PCF8574_Module (Port : not null Any_I2C_Port;
Addr : I2C_Address) is tagged limited private;

type Any_PCF8574_Module is access all PCF8574_Module'Class;


procedure Set (This : PCF8574_Module; Data : UInt8);

function Get (This : PCF8574_Module) return UInt8;
procedure Get (This : PCF8574_Module; Data : out UInt8);
-- when reading the input from keys (buttons) carefully read the
-- datasheet. The input line should be set high before reading.
-- E.g. if all lines are key input:
-- M.Set (16#FF#);
-- Keys := M.Get;

private

type PCF8574_Module (Port : not null Any_I2C_Port;
Addr : I2C_Address) is tagged limited null record;

end PCF8574;