mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
drivers: rm3100 add i2c/spi ifdefs
This commit is contained in:
parent
b320ace4d1
commit
be9fa620fd
@ -91,8 +91,12 @@
|
||||
#define RM3100_REVID 0x22
|
||||
|
||||
/* interface factories */
|
||||
#if defined(CONFIG_SPI)
|
||||
extern device::Device *RM3100_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode);
|
||||
#endif // CONFIG_SPI
|
||||
#if defined(CONFIG_I2C)
|
||||
extern device::Device *RM3100_I2C_interface(int bus, int bus_frequency);
|
||||
#endif // CONFIG_I2C
|
||||
|
||||
#define RM3100_ADDRESS 0x20
|
||||
|
||||
|
||||
@ -39,6 +39,8 @@
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#if defined(CONFIG_I2C)
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
@ -129,3 +131,5 @@ int RM3100_I2C::write(unsigned address, void *data, unsigned count)
|
||||
|
||||
return transfer(&buf[0], count + 1, nullptr, 0);
|
||||
}
|
||||
|
||||
#endif // CONFIG_I2C
|
||||
|
||||
@ -45,12 +45,16 @@ I2CSPIDriverBase *RM3100::instantiate(const I2CSPIDriverConfig &config, int runt
|
||||
{
|
||||
device::Device *interface = nullptr;
|
||||
|
||||
#if defined(CONFIG_I2C)
|
||||
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = RM3100_I2C_interface(config.bus, config.bus_frequency);
|
||||
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = RM3100_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
} else
|
||||
#endif // CONFIG_I2C
|
||||
if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = RM3100_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
@ -93,8 +97,12 @@ extern "C" int rm3100_main(int argc, char *argv[])
|
||||
using ThisDriver = RM3100;
|
||||
int ch;
|
||||
BusCLIArguments cli{true, true};
|
||||
#if defined(CONFIG_I2C)
|
||||
cli.default_i2c_frequency = 400000;
|
||||
#endif // CONFIG_I2C
|
||||
#if defined(CONFIG_SPI)
|
||||
cli.default_spi_frequency = 1 * 1000 * 1000;
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
while ((ch = cli.getOpt(argc, argv, "R:")) != EOF) {
|
||||
switch (ch) {
|
||||
@ -111,7 +119,9 @@ extern "C" int rm3100_main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_I2C)
|
||||
cli.i2c_address = RM3100_ADDRESS;
|
||||
#endif // CONFIG_I2C
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_MAG_DEVTYPE_RM3100);
|
||||
|
||||
|
||||
@ -39,6 +39,8 @@
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#if defined(CONFIG_SPI)
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
@ -135,3 +137,5 @@ int RM3100_SPI::write(unsigned address, void *data, unsigned count)
|
||||
|
||||
return transfer(&buf[0], &buf[0], count + 1);
|
||||
}
|
||||
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user