|
53 | 53 | # include <pios_mpu9250_config.h> |
54 | 54 | #endif |
55 | 55 |
|
| 56 | +#ifdef PIOS_INCLUDE_QMC5883 |
| 57 | +#include "pios_qmc5883.h" |
| 58 | +# ifdef PIOS_QMC5883_HAS_GPIOS |
| 59 | +pios_qmc5883_dev_t pios_qmc5883_internal_id; |
| 60 | +# endif |
| 61 | +#endif |
| 62 | + |
56 | 63 | #ifdef PIOS_INCLUDE_HMC5X83 |
57 | 64 | # include "pios_hmc5x83.h" |
58 | 65 | # ifdef PIOS_HMC5X83_HAS_GPIOS |
@@ -123,6 +130,69 @@ void PIOS_BOARD_Sensors_Configure() |
123 | 130 | } |
124 | 131 | #endif |
125 | 132 |
|
| 133 | +// internal QMC5883 mag |
| 134 | +# ifdef PIOS_INCLUDE_QMC5883_INTERNAL |
| 135 | + const struct pios_qmc5883_cfg *qmc5883_internal_cfg = PIOS_BOARD_HW_DEFS_GetInternalQMC5883Cfg(pios_board_info_blob.board_rev); |
| 136 | + |
| 137 | + if (qmc5883_internal_cfg) { |
| 138 | + // attach the 5883 mag to internal i2c bus |
| 139 | + |
| 140 | + pios_qmc5883_dev_t internal_mag = PIOS_QMC5883_Init(qmc5883_internal_cfg, PIOS_I2C_QMC5883_INTERNAL_ADAPTER, 0); |
| 141 | +# ifdef PIOS_INCLUDE_WDG |
| 142 | + // give QMC5883 on I2C some extra time to allow for reset, etc. if needed |
| 143 | + // this is not in a loop, so it is safe |
| 144 | + PIOS_WDG_Clear(); |
| 145 | +# endif /* PIOS_INCLUDE_WDG */ |
| 146 | + |
| 147 | +#ifdef PIOS_QMC5883_HAS_GPIOS |
| 148 | + pios_qmc5883_internal_id = internal_mag; |
| 149 | +#endif |
| 150 | + // add this sensor to the sensor task's list |
| 151 | + PIOS_QMC5883_Register(internal_mag, PIOS_SENSORS_TYPE_3AXIS_MAG); |
| 152 | + } |
| 153 | + |
| 154 | +# endif /* PIOS_INCLUDE_QMC5883_INTERNAL */ |
| 155 | + |
| 156 | +# ifdef PIOS_INCLUDE_QMC5883 |
| 157 | + |
| 158 | + AuxMagSettingsTypeOptions option; |
| 159 | + AuxMagSettingsTypeGet(&option); |
| 160 | + |
| 161 | + const struct pios_qmc5883_cfg *qmc5883_external_cfg = PIOS_BOARD_HW_DEFS_GetExternalQMC5883Cfg(pios_board_info_blob.board_rev); |
| 162 | + |
| 163 | + if (qmc5883_external_cfg) { |
| 164 | + uint32_t i2c_id = 0; |
| 165 | + |
| 166 | + if (option == AUXMAGSETTINGS_TYPE_FLEXI) { |
| 167 | + // i2c_external |
| 168 | +#ifdef PIOS_I2C_FLEXI_ADAPTER |
| 169 | + i2c_id = PIOS_I2C_FLEXI_ADAPTER; |
| 170 | +#endif |
| 171 | + } else if (option == AUXMAGSETTINGS_TYPE_I2C) { |
| 172 | + // i2c_internal (or Sparky2/F3 dedicated I2C port) |
| 173 | +#ifdef PIOS_I2C_EXTERNAL_ADAPTER |
| 174 | + i2c_id = PIOS_I2C_EXTERNAL_ADAPTER; |
| 175 | +#endif |
| 176 | + } |
| 177 | + |
| 178 | + if (i2c_id) { |
| 179 | + uint32_t external_mag = PIOS_QMC5883_Init(qmc5883_external_cfg, i2c_id, 0); |
| 180 | +# ifdef PIOS_INCLUDE_WDG |
| 181 | + // give QMC5883 on I2C some extra time to allow for reset, etc. if needed |
| 182 | + // this is not in a loop, so it is safe |
| 183 | + PIOS_WDG_Clear(); |
| 184 | +# endif /* PIOS_INCLUDE_WDG */ |
| 185 | + // add this sensor to the sensor task's list |
| 186 | + // be careful that you don't register a slow, unimportant sensor after registering the fastest sensor |
| 187 | + // and before registering some other fast and important sensor |
| 188 | + // as that would cause delay and time jitter for the second fast sensor |
| 189 | + PIOS_QMC5883_Register(external_mag, PIOS_SENSORS_TYPE_3AXIS_AUXMAG); |
| 190 | + // mag alarm is cleared later, so use I2C |
| 191 | + AlarmsSet(SYSTEMALARMS_ALARM_I2C, (external_mag) ? SYSTEMALARMS_ALARM_OK : SYSTEMALARMS_ALARM_WARNING); |
| 192 | + } |
| 193 | + } |
| 194 | +# endif /* PIOS_INCLUDE_QMC5883 */ |
| 195 | + |
126 | 196 | // internal HMC5x83 mag |
127 | 197 | # ifdef PIOS_INCLUDE_HMC5X83_INTERNAL |
128 | 198 | const struct pios_hmc5x83_cfg *hmc5x83_internal_cfg = PIOS_BOARD_HW_DEFS_GetInternalHMC5x83Cfg(pios_board_info_blob.board_rev); |
|
0 commit comments