Change PN532 package to generic.

This generic works with SPI and I2C PN532 functions.

Emulation is unstable with I2C, but otherwise the functionality
should be identical on SPI and I2C versions (reading and writing
works).
7 files changed, 47 insertions(+), 24 deletions(-)

M pn532.adb => generic_pn532.adb
M pn532.ads => generic_pn532.ads
M nfc_tags.adb
M pn532_bus_i2c.adb
M pn532_bus_i2c.ads
M pn532_bus_spi.adb
M pn532_bus_spi.ads
M pn532.adb => generic_pn532.adb +7 -14
@@ 26,19 26,7 @@ with PN532_BUS_SPI;
 
 use Interfaces;
 
-package body PN532 is
-
-   procedure Init renames PN532_BUS_SPI.Init;
-   function PN532_Busy return Boolean renames PN532_BUS_SPI.PN532_Busy;
-   procedure PN532_Write (Cmd : PN532_Buf) renames PN532_BUS_SPI.PN532_Write;
-   procedure PN532_Read_Raw (Buf : out PN532_Buf) renames PN532_BUS_SPI.PN532_Read_Raw;
-   procedure PN532_Read_Data
-     (Buf    : out PN532_Buf;
-      Len    : out Unsigned_8;
-      Status : out Boolean) renames PN532_BUS_SPI.PN532_Read_Data;
-   procedure PN532_Read_Reply (Reply : out Reply_Type; Code : out Unsigned_8)
-     renames PN532_BUS_SPI.PN532_Read_Reply;
-
+package body Generic_PN532 is
 
    PN532_FIRMWARE_VERSION : constant := 16#02#;
    PN532_SAMCONFIG        : constant := 16#14#;

          
@@ 713,6 701,11 @@ package body PN532 is
 
    Init_Cmd_PM : Buf_In_Progmem := (Init_Cmd'Length, Init_Cmd);
    pragma Linker_Section (Init_Cmd_PM, ".progmem");
+   
+   procedure Init is
+   begin
+      PN532_Init;
+   end Init;
 
    function PN532_Init_As_Target return Boolean is
       use type System.Address;

          
@@ 879,4 872,4 @@ package body PN532 is
       end loop;
    end PN532_NFC_Forum_Type_4_Emulate;
 
-end PN532;
+end Generic_PN532;

          
M pn532.ads => generic_pn532.ads +18 -2
@@ 20,7 20,23 @@ with PN532_Types;
 
 use PN532_Types;
 
-package PN532 is
+generic
+   with procedure PN532_Init;
+   
+   with function PN532_Busy return Boolean;
+
+   with procedure PN532_Write (Cmd : PN532_Buf);
+   
+   with procedure PN532_Read_Reply
+     (Reply : out Reply_Type; Code : out Interfaces.Unsigned_8);
+   
+   with procedure PN532_Read_Raw (Buf : out PN532_Buf);
+   
+   with procedure PN532_Read_Data
+     (Buf    : out PN532_Buf;
+      Len    : out Interfaces.Unsigned_8;
+      Status : out Boolean);
+package Generic_PN532 is
 
    subtype PN532_Buf_4 is PN532_Buf (1..4);
    subtype PN532_Buf_6 is PN532_Buf (1..6);

          
@@ 79,4 95,4 @@ package PN532 is
      (Offset : Interfaces.Unsigned_16;
       Buf    : PN532_Buf;
       Status : out Boolean);
-end PN532;
+end Generic_PN532;

          
M nfc_tags.adb +16 -2
@@ 18,7 18,8 @@ 
 with System;
 with PM_Strings;
 with NDEF;
-with PN532_TWI;
+with PN532_BUS_SPI;
+with Generic_PN532;
 with AVR.UART;
 with AVR.Interrupts;
 with Interfaces;

          
@@ 31,7 32,20 @@ package body NFC_Tags is
    use Interfaces;
    use PN532_Types;
 
-   package PN532 renames PN532_TWI;
+   package PN532 is new Generic_PN532
+     (PN532_Init => PN532_BUS_SPI.PN532_Init,
+      PN532_Busy => PN532_BUS_SPI.PN532_Busy,
+      PN532_Write => PN532_BUS_SPI.PN532_Write,
+      PN532_Read_Reply => PN532_BUS_SPI.PN532_Read_Reply,
+      PN532_Read_Raw => PN532_BUS_SPI.PN532_Read_Raw,
+      PN532_Read_Data => PN532_BUS_SPI.PN532_Read_Data);
+--   package PN532 is new Generic_PN532
+--     (PN532_Init => PN532_BUS_I2C.PN532_Init,
+--      PN532_Busy => PN532_BUS_I2C.PN532_Busy,
+--      PN532_Write => PN532_BUS_I2C.PN532_Write,
+--      PN532_Read_Reply => PN532_BUS_I2C.PN532_Read_Reply,
+--      PN532_Read_Raw => PN532_BUS_I2C.PN532_Read_Raw,
+--      PN532_Read_Data => PN532_BUS_I2C.PN532_Read_Data);
 
    procedure Print_Str (Place : System.Address);
 

          
M pn532_bus_i2c.adb +2 -2
@@ 16,7 16,7 @@ package body PN532_BUS_I2C is
 
    PN532_I2C_ADDRESS : constant := (16#48# / 2);
 
-   procedure Init is
+   procedure PN532_Init is
    begin
       delay 0.1;
       AVR.I2C.Master.Init;

          
@@ 30,7 30,7 @@ package body PN532_BUS_I2C is
       Reset_Bit := True;
 
       delay 0.02;
-   end Init;
+   end PN532_Init;
 
    function PN532_Busy return Boolean is
    begin

          
M pn532_bus_i2c.ads +1 -1
@@ 5,7 5,7 @@ use PN532_Types;
 use Interfaces;
 
 package PN532_BUS_I2C is
-   procedure Init;
+   procedure PN532_Init;
    
    function PN532_Busy return Boolean;
 

          
M pn532_bus_spi.adb +2 -2
@@ 28,7 28,7 @@ package body PN532_BUS_SPI is
    end PN532_SPI_Disable;
    pragma Inline (PN532_SPI_Disable);
 
-   procedure Init is
+   procedure PN532_Init is
    begin
       delay 0.1;
       SPI.Init;

          
@@ 41,7 41,7 @@ package body PN532_BUS_SPI is
 
       delay 0.9;
       PN532_SPI_Disable;
-   end Init;
+   end PN532_Init;
 
    procedure PN532_Write (Cmd : PN532_Buf)  is
       Checksum : Unsigned_8 := 16#FF#;

          
M pn532_bus_spi.ads +1 -1
@@ 5,7 5,7 @@ use PN532_Types;
 use Interfaces;
 
 package PN532_BUS_SPI is
-   procedure Init;
+   procedure PN532_Init;
 
    function PN532_Busy return Boolean;