<!DOCTYPE module SYSTEM "module.dtd">

<module name="imu_analog" dir="imu">
  <doc>
    <description>
      Analog IMU connected to MCU ADC ports.
      Only add the configure and define lines for the sensors you actually use.
      E.g. to replace the old gyro_pitch subsystem only add GYRO_P and GYRO_Q
    </description>
    <configure name="GYRO_P" value="ADC_0"/>
    <configure name="GYRO_Q" value="ADC_1"/>
    <configure name="GYRO_R" value="ADC_2"/>
    <configure name="ACCEL_X" value="ADC_5"/>
    <configure name="ACCEL_Y" value="ADC_6"/>
    <configure name="ACCEL_Z" value="ADC_7"/>
    <configure name="ADC_GYRO_NB_SAMPLES" value="16"/>
    <configure name="ADC_ACCEL_NB_SAMPLES" value="16"/>
    <section name="IMU" prefix="IMU_">
      <define name="GYRO_P_NEUTRAL" value="512"/>
      <define name="GYRO_Q_NEUTRAL" value="512"/>
      <define name="GYRO_R_NEUTRAL" value="512"/>

      <define name="GYRO_P_SENS" value="0.017" integer="16"/>
      <define name="GYRO_Q_SENS" value="0.017" integer="16"/>
      <define name="GYRO_R_SENS" value="0.017" integer="16"/>

      <define name="GYRO_P_SIGN" value="1" />
      <define name="GYRO_Q_SIGN" value="1" />
      <define name="GYRO_R_SIGN" value="-1" />

      <define name="ACCEL_X_SENS" value="0.1" integer="16"/>
      <define name="ACCEL_Y_SENS" value="0.1" integer="16"/>
      <define name="ACCEL_Z_SENS" value="0.1" integer="16"/>

      <define name="ACCEL_X_NEUTRAL" value="512"/>
      <define name="ACCEL_Y_NEUTRAL" value="512"/>
      <define name="ACCEL_Z_NEUTRAL" value="512"/>

      <define name="ACCEL_X_SIGN" value="1"/>
      <define name="ACCEL_Y_SIGN" value="-1"/>
      <define name="ACCEL_Z_SIGN" value="1"/>
    </section>
  </doc>
  <autoload name="imu_common"/>
  <autoload name="imu_nps"/>
  <header>
    <file name="imu_analog.h" dir="subsystems/imu"/>
  </header>

  <init fun="imu_analog_init()"/>
  <periodic fun="imu_analog_periodic()"/>

  <makefile target="!sim|nps|fbw">
    <configure name="ADC_GYRO_NB_SAMPLES" default="16"/>
    <configure name="ADC_ACCEL_NB_SAMPLES" default="16"/>
    <define name="ADC_CHANNEL_GYRO_NB_SAMPLES" value="$(ADC_GYRO_NB_SAMPLES)"/>
    <define name="ADC_CHANNEL_ACCEL_NB_SAMPLES" value="$(ADC_ACCEL_NB_SAMPLES)"/>

    <define name="IMU_TYPE_H" value="subsystems/imu/imu_analog.h" type="string"/>

    <file name="imu_analog.c" dir="subsystems/imu"/>
    <raw>
ifeq ($(ARCH), lpc21)
ifneq ($(GYRO_P),)
$(TARGET).CFLAGS += -DADC_CHANNEL_GYRO_P=$(GYRO_P) -DUSE_$(GYRO_P)
endif

ifneq ($(GYRO_Q),)
$(TARGET).CFLAGS += -DADC_CHANNEL_GYRO_Q=$(GYRO_Q) -DUSE_$(GYRO_Q)
endif

ifneq ($(GYRO_R),)
$(TARGET).CFLAGS += -DADC_CHANNEL_GYRO_R=$(GYRO_R) -DUSE_$(GYRO_R)
endif

ifneq ($(ACCEL_X),)
$(TARGET).CFLAGS += -DADC_CHANNEL_ACCEL_X=$(ACCEL_X) -DUSE_$(ACCEL_X)
endif

ifneq ($(ACCEL_Y),)
$(TARGET).CFLAGS += -DADC_CHANNEL_ACCEL_Y=$(ACCEL_Y) -DUSE_$(ACCEL_Y)
endif

ifneq ($(ACCEL_Z),)
$(TARGET).CFLAGS += -DADC_CHANNEL_ACCEL_Z=$(ACCEL_Z) -DUSE_$(ACCEL_Z)
endif

else ifeq ($(ARCH), stm32)
$(error Not implemented for the stm32 yet... should be trivial, just do it...)
endif
    </raw>
  </makefile>
</module>
