mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 06:33:33 +08:00
boards: add new spi+i2c config
Chip-select and SPI initialization uses the new config, whereas the drivers still use the existing defines. The configuration in board_config.h can be removed after all drivers are updated.
This commit is contained in:
@@ -51,7 +51,7 @@ namespace device
|
||||
* All calls to init() will NOT set the buss frequency
|
||||
*/
|
||||
|
||||
unsigned int I2C::_bus_clocks[BOARD_NUMBER_I2C_BUSES] = BOARD_I2C_BUS_CLOCK_INIT;
|
||||
unsigned int I2C::_bus_clocks[PX4_NUMBER_I2C_BUSES] = PX4_I2C_BUS_CLOCK_INIT;
|
||||
|
||||
I2C::I2C(const char *name, const char *devname, const int bus, const uint16_t address, const uint32_t frequency) :
|
||||
CDev(name, devname),
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#define _DEVICE_I2C_H
|
||||
|
||||
#include "../CDev.hpp"
|
||||
#include <px4_platform_common/i2c.h>
|
||||
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
@@ -69,8 +70,6 @@ public:
|
||||
|
||||
static int set_bus_clock(unsigned bus, unsigned clock_hz);
|
||||
|
||||
static unsigned int _bus_clocks[BOARD_NUMBER_I2C_BUSES];
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The number of times a read or write operation will be retried on
|
||||
@@ -109,10 +108,12 @@ protected:
|
||||
*/
|
||||
int transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len);
|
||||
|
||||
virtual bool external() const override { return px4_i2c_bus_external(_device_id.devid_s.bus); }
|
||||
bool external() const override { return px4_i2c_bus_external(_device_id.devid_s.bus); }
|
||||
|
||||
private:
|
||||
uint32_t _frequency{0};
|
||||
static unsigned int _bus_clocks[PX4_NUMBER_I2C_BUSES];
|
||||
|
||||
const uint32_t _frequency;
|
||||
i2c_master_s *_dev{nullptr};
|
||||
|
||||
};
|
||||
|
||||
@@ -70,6 +70,10 @@ SPI::SPI(const char *name, const char *devname, int bus, uint32_t device, enum s
|
||||
_device_id.devid_s.address = (uint8_t)device;
|
||||
// devtype needs to be filled in by the driver
|
||||
_device_id.devid_s.devtype = 0;
|
||||
|
||||
if (!px4_spi_bus_requires_locking(bus)) {
|
||||
_locking_mode = LOCK_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
SPI::~SPI()
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "../CDev.hpp"
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <px4_platform_common/spi.h>
|
||||
|
||||
namespace device __EXPORT
|
||||
{
|
||||
@@ -166,7 +167,7 @@ protected:
|
||||
|
||||
int _transferhword(uint16_t *send, uint16_t *recv, unsigned len);
|
||||
|
||||
virtual bool external() const override { return px4_spi_bus_external(get_device_bus()); }
|
||||
bool external() const override { return px4_spi_bus_external(get_device_bus()); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#define _DEVICE_I2C_H
|
||||
|
||||
#include "../CDev.hpp"
|
||||
#include <px4_platform_common/i2c.h>
|
||||
|
||||
namespace device __EXPORT
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#define _DEVICE_SPI_H
|
||||
|
||||
#include "../CDev.hpp"
|
||||
#include <px4_platform_common/spi.h>
|
||||
|
||||
#ifdef __PX4_LINUX
|
||||
|
||||
|
||||
Reference in New Issue
Block a user