Пример #1
0
__END_DECLS

/****************************************************************************
 * Protected Functions
 ****************************************************************************/
/****************************************************************************
 * Public Functions
 ****************************************************************************/
/************************************************************************************
 * Name: board_peripheral_reset
 *
 * Description:
 *
 ************************************************************************************/
__EXPORT void board_peripheral_reset(int ms)
{
	/* set the peripheral rails off */
	px4_arch_configgpio(GPIO_VDD_5V_PERIPH_EN);
	px4_arch_gpiowrite(GPIO_VDD_5V_PERIPH_EN, 1);

	/* wait for the peripheral rail to reach GND */
	usleep(ms * 1000);
	warnx("reset done, %d ms", ms);

	/* re-enable power */

	/* switch the peripheral rail back on */
	px4_arch_gpiowrite(GPIO_VDD_5V_PERIPH_EN, 0);
}
Пример #2
0
__EXPORT void stm32_spiinitialize(void)
{
#ifdef CONFIG_STM32_SPI1

	px4_arch_configgpio(GPIO_SPI_CS_ICM_20608_G);
	px4_arch_configgpio(GPIO_SPI_CS_BARO);
	px4_arch_configgpio(GPIO_SPI_CS_MPU);

	/* De-activate all peripherals,
	 * required for some peripheral
	 * state machines
	 */
	px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_BARO, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_MPU, 1);

	px4_arch_configgpio(GPIO_EXTI_MPU_DRDY);
	px4_arch_configgpio(GPIO_EXTI_ICM_20608_G_DRDY);
#endif

#ifdef CONFIG_STM32_SPI2
	px4_arch_configgpio(GPIO_SPI_CS_FRAM);
	px4_arch_gpiowrite(GPIO_SPI_CS_FRAM, 1);
#endif

}
Пример #3
0
__EXPORT void stm32_spiinitialize(void)
{
#ifdef CONFIG_STM32_SPI1
	px4_arch_configgpio(GPIO_SPI_CS_MPU9250);
	px4_arch_configgpio(GPIO_SPI_CS_HMC5983);
	px4_arch_configgpio(GPIO_SPI_CS_MS5611);
	px4_arch_configgpio(GPIO_SPI_CS_ICM_20608_G);

	/* De-activate all peripherals,
	 * required for some peripheral
	 * state machines
	 */
	px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1);

	px4_arch_configgpio(GPIO_DRDY_MPU9250);
	px4_arch_configgpio(GPIO_DRDY_HMC5983);
	px4_arch_configgpio(GPIO_DRDY_ICM_20608_G);
#endif

#ifdef CONFIG_STM32_SPI2
	px4_arch_configgpio(GPIO_SPI_CS_FRAM);
	px4_arch_gpiowrite(GPIO_SPI_CS_FRAM, 1);
#endif

}
Пример #4
0
void resetwifi(void){
	//pull down the rst pin more than 300 milisec
	px4_arch_gpiowrite(GPIO_wifi_rst, 0);
	usleep(800);
	px4_arch_gpiowrite(GPIO_wifi_rst, 1);
	//usleep(1000000);
}
Пример #5
0
__EXPORT void stm32_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
	UNUSED(devid);
	/* SPI select is active low, so write !selected to select the device */
	px4_arch_gpiowrite(GPIO_SPI3_CS_BARO, !selected);
	px4_arch_gpiowrite(GPIO_SPI3_CS_OSD, !selected);
}
Пример #6
0
void TAP_ESC::select_responder(uint8_t sel)
{
#if defined(GPIO_S0)
	px4_arch_gpiowrite(GPIO_S0, sel & 1);
	px4_arch_gpiowrite(GPIO_S1, sel & 2);
	px4_arch_gpiowrite(GPIO_S2, sel & 4);
#endif
}
Пример #7
0
__EXPORT void board_spi_reset(int ms)
{
	/* disable SPI bus */
	px4_arch_configgpio(GPIO_SPI_CS_ICM_2060X_OFF);
	px4_arch_configgpio(GPIO_SPI_CS_BARO_OFF);
	px4_arch_configgpio(GPIO_SPI_CS_MPU_OFF);

	px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI_CS_BARO_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI_CS_MPU_OFF, 0);

	px4_arch_configgpio(GPIO_SPI1_SCK_OFF);
	px4_arch_configgpio(GPIO_SPI1_MISO_OFF);
	px4_arch_configgpio(GPIO_SPI1_MOSI_OFF);

	px4_arch_gpiowrite(GPIO_SPI1_SCK_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI1_MISO_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI1_MOSI_OFF, 0);

	px4_arch_configgpio(GPIO_EXTI_ICM_2060X_DRDY_OFF);
	px4_arch_configgpio(GPIO_EXTI_MPU_DRDY_OFF);

	px4_arch_gpiowrite(GPIO_EXTI_ICM_2060X_DRDY_OFF, 0);
	px4_arch_gpiowrite(GPIO_EXTI_MPU_DRDY_OFF, 0);

	/* set the sensor rail off */
	px4_arch_configgpio(GPIO_VDD_3V3_SENSORS_EN);
	px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);

	/* wait for the sensor rail to reach GND */
	usleep(ms * 1000);
	syslog(LOG_DEBUG, "reset done, %d ms\n", ms);

	/* re-enable power */

	/* switch the sensor rail back on */
	px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);

	/* wait a bit before starting SPI, different times didn't influence results */
	usleep(100);

	/* reconfigure the SPI pins */
#ifdef CONFIG_STM32_SPI1
	px4_arch_configgpio(GPIO_SPI_CS_ICM_2060X);
	px4_arch_configgpio(GPIO_SPI_CS_BARO);
	px4_arch_configgpio(GPIO_SPI_CS_MPU);

	px4_arch_configgpio(GPIO_SPI1_SCK);
	px4_arch_configgpio(GPIO_SPI1_MISO);
	px4_arch_configgpio(GPIO_SPI1_MOSI);

	// // XXX bring up the EXTI pins again
	// px4_arch_configgpio(GPIO_EXTI_MPU_DRDY);
	// px4_arch_configgpio(GPIO_EXTI_ICM_2060X_DRDY);

#endif
}
Пример #8
0
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	switch (devid) {

	/* intended fallthrough */
	case PX4_SPIDEV_ICM_20602:

	/* intended fallthrough */
	case PX4_SPIDEV_ICM_20608:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_BARO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU, 1);
		break;

	case PX4_SPIDEV_BARO:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_BARO, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU, 1);
		break;

	case PX4_SPIDEV_MPU:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_BARO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU, !selected);
		break;

	default:
		break;
	}
}
Пример #9
0
__EXPORT void led_toggle(int led)
{
	if (led == 1) {
		if (px4_arch_gpioread(GPIO_LED1)) {
			px4_arch_gpiowrite(GPIO_LED1, false);

		} else {
			px4_arch_gpiowrite(GPIO_LED1, true);
		}
	}
}
Пример #10
0
void
GPS::cmd_reset()
{
#ifdef GPIO_GPS_NRESET
	PX4_WARN("Toggling GPS reset pin");
	px4_arch_configgpio(GPIO_GPS_NRESET);
	px4_arch_gpiowrite(GPIO_GPS_NRESET, 0);
	usleep(100);
	px4_arch_gpiowrite(GPIO_GPS_NRESET, 1);
	PX4_WARN("Toggled GPS reset pin");
#endif
}
Пример #11
0
__EXPORT void stm32_spiinitialize(void)
{
#ifdef CONFIG_STM32_SPI1
	px4_arch_configgpio(GPIO_SPI_CS_MS5611);
	px4_arch_configgpio(GPIO_SPI_CS_EXP_MS5611);
	px4_arch_configgpio(GPIO_SPI_CS_EXP_MPU6000);
	px4_arch_configgpio(GPIO_SPI_CS_EXP_HMC5983);

	/* De-activate all peripherals,
	 * required for some peripheral
	 * state machines
	 */
	px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MS5611, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MPU6000, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_EXP_HMC5983, 1);
#endif

#ifdef CONFIG_STM32_SPI2
	px4_arch_configgpio(GPIO_SPI_CS_MPU6000);
	px4_arch_configgpio(GPIO_SPI_CS_IMU_MS5611);
	px4_arch_configgpio(GPIO_SPI_CS_IMU_MPU6000);
	px4_arch_configgpio(GPIO_SPI_CS_IMU_HMC5983);

	/* De-activate all peripherals,
	 * required for some peripheral
	 * state machines
	 */
	px4_arch_gpiowrite(GPIO_SPI_CS_MPU6000, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_IMU_MS5611, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_IMU_MPU6000, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_IMU_HMC5983, 1);

	px4_arch_configgpio(GPIO_DRDY_MPU6000);
#endif

#ifdef CONFIG_STM32_SPI3
	px4_arch_configgpio(GPIO_SPI_CS_RAMTRON);
	px4_arch_configgpio(GPIO_SPI_CS_SDCARD);

	/* De-activate all peripherals,
	 * required for some peripheral
	 * state machines
	 */
	px4_arch_gpiowrite(GPIO_SPI_CS_RAMTRON, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_SDCARD, 1);
#endif
}
Пример #12
0
void CameraInterfaceGPIO::setup()
{
	for (unsigned i = 0; i < arraySize(_pins); i++) {
		px4_arch_configgpio(_gpios[_pins[i]]);
		px4_arch_gpiowrite(_gpios[_pins[i]], !_polarity);
	}
}
Пример #13
0
__EXPORT void led_off(int led)
{
	if (led == 1) {
		/* Pull up to switch off */
		px4_arch_gpiowrite(GPIO_LED1, true);
	}
}
Пример #14
0
void
TEST_PPM::do_out(void)
{
	if ((_call_times % 2) == 0) {
		px4_arch_gpiowrite(TEST_PPM_PIN, false);
		hrt_call_after(&_call, _values[_call_times / 2] - _plus_width, (hrt_callout)&TEST_PPM::loops, this);

	} else {
		px4_arch_gpiowrite(TEST_PPM_PIN, true);
		hrt_call_after(&_call, _plus_width, (hrt_callout)&TEST_PPM::loops, this);
	}

	if ((_call_times / 2) < _channels + 1) { _call_times++; }

	else { _call_times = 0; }
}
Пример #15
0
__EXPORT void led_on(int led)
{
	if (led == 1) {
		/* Pull down to switch on */
		px4_arch_gpiowrite(GPIO_LED1, false);
	}
}
Пример #16
0
void CameraInterfaceGPIO::trigger(bool enable)
{
	if (enable) {
		for (unsigned i = 0; i < arraySize(_pins); i++) {
			if (_pins[i] >= 0) {
				// ACTIVE_LOW == 1
				px4_arch_gpiowrite(_gpios[_pins[i]], _polarity);
			}
		}

	} else {
		for (unsigned i = 0; i < arraySize(_pins); i++) {
			if (_pins[i] >= 0) {
				// ACTIVE_LOW == 1
				px4_arch_gpiowrite(_gpios[_pins[i]], !_polarity);
			}
		}
	}
}
Пример #17
0
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	switch (devid) {
	case SPIDEV_FLASH:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_FRAM, !selected);
		break;

	case PX4_SPIDEV_BARO:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_FRAM, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, !selected);
		break;

	default:
		break;
	}
}
Пример #18
0
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	switch (devid) {

	/* Shared PC2 CS devices */

	case PX4_SPIDEV_BMI:
	case PX4_SPIDEV_MPU:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN2,  !selected);
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN15, 1);
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTE_PIN15, 1);
		break;

	/* Shared PC15 CS devices */

	case PX4_SPIDEV_ICM:
	case PX4_SPIDEV_ICM_20602:
	case PX4_SPIDEV_ICM_20608:
	case PX4_SPIDEV_BMI055_ACC:
	case PX4_SPIDEV_MPU2:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN2, 1);
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN15, !selected);
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTE_PIN15, 1);
		break;

	/* Shared PE15 CS devices */

	case PX4_SPIDEV_HMC:
	case PX4_SPIDEV_LIS:
	case PX4_SPIDEV_BMI055_GYR:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN2, 1);
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN15, 1);
		px4_arch_gpiowrite(GPIO_SPI1_CS_PORTE_PIN15, !selected);
		break;

	default:
		break;
	}
}
Пример #19
0
__EXPORT void stm32_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	switch (devid) {
	case SPIDEV_MMCSD:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_SDCARD, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_RAMTRON, 1);
		break;

	case SPIDEV_FLASH:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_SDCARD, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_RAMTRON, !selected);
		break;

	default:
		break;

	}
}
Пример #20
0
// XXX refactor this out of this driver
void
PWMIN::_turn_off()
{
	px4_arch_gpiowrite(GPIO_VDD_RANGEFINDER_EN, 0);
}
Пример #21
0
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	switch (devid) {
	case PX4_SPIDEV_ICM:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, !selected);
		break;

	case PX4_SPIDEV_ACCEL_MAG:
		/* Making sure the other peripherals are not selected */
		break;

	case PX4_SPIDEV_BARO:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1);
		break;

	case PX4_SPIDEV_HMC:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1);
		break;

	case PX4_SPIDEV_MPU:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1);
		break;

	default:
		break;
	}
}
Пример #22
0
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	switch (devid) {
	case SPIDEV_MS5611:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MPU6000, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_HMC5983, 1);
		break;

	case SPIDEV_EXP_MS5611:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MS5611, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MPU6000, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_HMC5983, 1);
		break;

	case SPIDEV_EXP_MPU6000:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MPU6000, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_HMC5983, 1);
		break;

	case SPIDEV_EXP_HMC5983:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MS5611, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_MPU6000, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_EXP_HMC5983, !selected);
		break;

	default:
		break;

	}
}
Пример #23
0
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
	/* there can only be one device on this bus, so always select it */
	px4_arch_gpiowrite(GPIO_SPI_CS_FRAM, !selected);
}
Пример #24
0
__EXPORT void stm32_spi4select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	switch (devid) {
	case PX4_SPIDEV_GYRO:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_GYRO, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_ACCEL_MAG, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_BARO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU, 1);
		break;

	case PX4_SPIDEV_ACCEL_MAG:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_GYRO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_ACCEL_MAG, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_BARO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU, 1);
		break;

	case PX4_SPIDEV_BARO:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_GYRO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_ACCEL_MAG, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_BARO, !selected);
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU, 1);
		break;

	case PX4_SPIDEV_MPU:
		/* Making sure the other peripherals are not selected */
		px4_arch_gpiowrite(GPIO_SPI_CS_GYRO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_ACCEL_MAG, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_BARO, 1);
		px4_arch_gpiowrite(GPIO_SPI_CS_MPU, !selected);
		break;

	default:
		break;
	}
}
Пример #25
0
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */
	UNUSED(devid);
	px4_arch_gpiowrite(GPIO_SPI_CS_SDCARD, !selected);
}
Пример #26
0
__EXPORT void board_spi_reset(int ms)
{
	/* disable SPI bus */
	px4_arch_configgpio(GPIO_SPI_CS_GYRO_OFF);
	px4_arch_configgpio(GPIO_SPI_CS_ACCEL_MAG_OFF);
	px4_arch_configgpio(GPIO_SPI_CS_BARO_OFF);
	px4_arch_configgpio(GPIO_SPI_CS_MPU_OFF);

	px4_arch_gpiowrite(GPIO_SPI_CS_GYRO_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI_CS_ACCEL_MAG_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI_CS_BARO_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI_CS_MPU_OFF, 0);

	px4_arch_configgpio(GPIO_SPI1_SCK_OFF);
	px4_arch_configgpio(GPIO_SPI1_MISO_OFF);
	px4_arch_configgpio(GPIO_SPI1_MOSI_OFF);

	px4_arch_gpiowrite(GPIO_SPI1_SCK_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI1_MISO_OFF, 0);
	px4_arch_gpiowrite(GPIO_SPI1_MOSI_OFF, 0);

	px4_arch_configgpio(GPIO_GYRO_DRDY_OFF);
	px4_arch_configgpio(GPIO_ACCEL_DRDY_OFF);
	px4_arch_configgpio(GPIO_MAG_DRDY_OFF);
	px4_arch_configgpio(GPIO_EXTI_MPU_DRDY_OFF);

	px4_arch_gpiowrite(GPIO_GYRO_DRDY_OFF, 0);
	px4_arch_gpiowrite(GPIO_ACCEL_DRDY_OFF, 0);
	px4_arch_gpiowrite(GPIO_MAG_DRDY_OFF, 0);
	px4_arch_gpiowrite(GPIO_EXTI_MPU_DRDY_OFF, 0);

	/* set the sensor rail off */
	px4_arch_configgpio(GPIO_VDD_3V3_SENSORS_EN);
	px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);

	/* wait for the sensor rail to reach GND */
	usleep(ms * 1000);
	warnx("reset done, %d ms", ms);

	/* re-enable power */

	/* switch the sensor rail back on */
	px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);

	/* wait a bit before starting SPI, different times didn't influence results */
	usleep(100);

	/* reconfigure the SPI pins */
#ifdef CONFIG_STM32_SPI4
	px4_arch_configgpio(GPIO_SPI_CS_GYRO);
	px4_arch_configgpio(GPIO_SPI_CS_ACCEL_MAG);
	px4_arch_configgpio(GPIO_SPI_CS_BARO);
	px4_arch_configgpio(GPIO_SPI_CS_MPU);

	/* De-activate all peripherals,
	 * required for some peripheral
	 * state machines
	 */
	px4_arch_gpiowrite(GPIO_SPI_CS_GYRO, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_ACCEL_MAG, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_BARO, 1);
	px4_arch_gpiowrite(GPIO_SPI_CS_MPU, 1);

	px4_arch_configgpio(GPIO_SPI4_SCK);
	px4_arch_configgpio(GPIO_SPI4_MISO);
	px4_arch_configgpio(GPIO_SPI4_MOSI);


#endif
}