(* Copyright (C)2018-2024, Philip Munts dba Munts Technologies.                *)
(*                                                                             *)
(* Redistribution and use in source and binary forms, with or without          *)
(* modification, are permitted provided that the following conditions are met: *)
(*                                                                             *)
(* * Redistributions of source code must retain the above copyright notice,    *)
(*   this list of conditions and the following disclaimer.                     *)
(*                                                                             *)
(* 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.                                                 *)

DEFINITION MODULE RaspberryPi;

  FROM Channel IMPORT Designator;

  CONST
    (* Raspberry Pi boards don't have a built-in ADC (Analog to Digital    *)
    (* Converter) subsystem, so the following analog input designators are *)
    (* placeholders for the first IIO (Industrial I/O) ADC device.         *)

    AIN0   = Designator{0,  0};
    AIN1   = Designator{0,  1};
    AIN2   = Designator{0,  2};
    AIN3   = Designator{0,  3};
    AIN4   = Designator{0,  4};
    AIN5   = Designator{0,  5};
    AIN6   = Designator{0,  6};
    AIN7   = Designator{0,  7};

    GPIO2  = Designator{0,  2};  (* I2C1 SDA *)
    GPIO3  = Designator{0,  3};  (* I2C1 SCL *)
    GPIO4  = Designator{0,  4};
    GPIO5  = Designator{0,  5};
    GPIO6  = Designator{0,  6};
    GPIO7  = Designator{0,  7};  (* SPI0 SS1 *)
    GPIO8  = Designator{0,  8};  (* SPI0 SS0 *)
    GPIO9  = Designator{0,  9};  (* SPI0 MISO *)
    GPIO10 = Designator{0, 10};  (* SPI0 MOSI *)
    GPIO11 = Designator{0, 11};  (* SPI0 SCLK *)
    GPIO12 = Designator{0, 12};  (* PWM0 *)
    GPIO13 = Designator{0, 13};  (* PWM1 *)
    GPIO14 = Designator{0, 14};  (* UART0 TXD *)
    GPIO15 = Designator{0, 15};  (* UART0 RXD *)
    GPIO16 = Designator{0, 16};  (* SPI1 SS2 *)
    GPIO17 = Designator{0, 17};  (* SPI1 SS1 *)
    GPIO18 = Designator{0, 18};  (* PWM0, SPI1 SS0 *)
    GPIO19 = Designator{0, 19};  (* PWM1, SPI1 MISO *)
    GPIO20 = Designator{0, 20};  (* SPI1 MOSI *)
    GPIO21 = Designator{0, 21};  (* SPI1 SCLK *)
    GPIO22 = Designator{0, 22};
    GPIO23 = Designator{0, 23};
    GPIO24 = Designator{0, 24};
    GPIO25 = Designator{0, 25};
    GPIO26 = Designator{0, 26};
    GPIO27 = Designator{0, 27};

    (* All of the following subsystems require device tree overlays *)

    I2C1   = Designator{0,  1};  (* GPIO2/GPIO3 *)

    PWM0   = Designator{0,  0};  (* GPIO12 or GPIO18 *)
    PWM1   = Designator{0,  1};  (* GPIO13 or GPIO19 *)

    SPI0_0 = Designator{0,  0};  (* GPIO8,  GPIO9,  GPIO10, and GPIO11 *)
    SPI0_1 = Designator{0,  1};  (* GPIO7,  GPIO9,  GPIO10, and GPIO11 *)
    SPI1_0 = Designator{1,  0};  (* GPIO18, GPIO19, GPIO20, and GPIO21 *)
    SPI1_1 = Designator{1,  1};  (* GPIO17, GPIO19, GPIO20, and GPIO21 *)
    SPI1_2 = Designator{1,  2};  (* GPIO16, GPIO19, GPIO20, and GPIO21 *)

END RaspberryPi.
