<!DOCTYPE module SYSTEM "module.dtd">

<module name="intermcu_uart" dir="intermcu">
  <doc>
    <description>
      Inter-MCU communication over UART

      To enable this, please set the "SEPARATE_FBW" configure option to TRUE
      in your airframe file for both AP and FBW targets
    </description>
    <configure name="SEPARATE_FBW" value="FALSE|TRUE" description="Enable separation between AP and FBW on separated MCU"/>
    <configure name="INTERMCU_PORT" value="UARTx" description="UART used for inter mcu communication (default: UART2 for FBW, UART5 for AP)"/>
    <configure name="INTERMCU_BAUD" value="B57600" description="UART baud rate"/>
    <configure name="FBW_MODE_LED" value="none|num" description="LED number or 'none'"/>
  </doc>

  <makefile target="fbw" firmware="fixedwing">
    <configure name="INTERMCU_PORT" default="UART2" case="upper|lower"/>
    <configure name="FBW_MODE_LED" default="none"/>
    <define name="FBW_MODE_LED" value="$(FBW_MODE_LED)" cond="ifneq ($(FBW_MODE_LED),none)"/>
  </makefile>
  <makefile target="ap" firmware="fixedwing">
    <configure name="INTERMCU_PORT" default="UART5" case="upper|lower"/>
  </makefile>
  <makefile target="ap|fbw" firmware="fixedwing">
    <raw>
      ifeq (,$(findstring $(SEPARATE_FBW),1 TRUE))
      $(error Using intermcu via UART, so dual mcu with separate fbw. Please set option "SEPARATE_FBW" to TRUE.
      endif
    </raw>
    <configure name="INTERMCU_BAUD" default="B57600"/>
    <define name="INTERMCU"/>
    <define name="MCU_UART_LINK"/>
    <define name="INTERMCU_LINK" value="$(INTERMCU_PORT_LOWER)"/>
    <define name="USE_$(INTERMCU_PORT_UPPER)"/>
    <define name="$(INTERMCU_PORT_UPPER)_BAUD" value="$(INTERMCU_BAUD)"/>
    <file name="link_mcu_usart.c" dir="."/>
  </makefile>

  <makefile target="fbw" firmware="rotorcraft">
    <configure name="INTERMCU_PORT" default="UART3" case="upper|lower"/>
    <configure name="FBW_MODE_LED" default="none"/>
    <define name="FBW_MODE_LED" value="$(FBW_MODE_LED)" cond="ifneq ($(FBW_MODE_LED),none)"/>
    <define name="INTER_MCU_FBW"/>
    <define name="DOWNLINK"/>
    <file name="intermcu_fbw.c" dir="subsystems/intermcu"/>
  </makefile>
  <makefile target="ap" firmware="rotorcraft">
    <configure name="INTERMCU_PORT" default="UART3" case="upper|lower"/>
    <configure name="RADIO_CONTROL_LED" value="none"/>
    <define name="INTER_MCU_AP"/>
    <define name="RADIO_CONTROL_TYPE_H" value="subsystems/intermcu/intermcu_ap.h" type="string"/>
    <define name="RADIO_CONTROL"/>
    <define name="RADIO_CONTROL_LED" value="$(RADIO_CONTROL_LED)" cond="ifneq ($(RADIO_CONTROL_LED),none)"/>
    <define name="GPS_SECONDARY_TYPE_H" value="subsystems/intermcu/intermcu_ap.h" type="string" cond="ifneq (,$(findstring $(SECONDARY_GPS), imcu))"/>
    <define name="GPS_SECONDARY_GPS" value="GPS_IMU" cond="ifneq (,$(findstring $(SECONDARY_GPS), imcu))"/>
    <define name="IMCU_GPS" cond="ifneq (,$(findstring $(SECONDARY_GPS), imcu))"/>
    <file name="intermcu_ap.c" dir="subsystems/intermcu"/>
    <file name="radio_control.c" dir="subsystems"/>
  </makefile>
  <makefile target="ap|fbw" firmware="rotorcraft">
    <configure name="INTERMCU_BAUD" default="B230400"/>
    <define name="INTERMCU_LINK" value="$(INTERMCU_PORT_LOWER)"/>
    <define name="USE_$(INTERMCU_PORT_UPPER)"/>
    <define name="$(INTERMCU_PORT_UPPER)_BAUD" value="$(INTERMCU_BAUD)"/>
    <file name="pprz_transport.c" dir="pprzlink/src"/>
  </makefile>
</module>

