43 #define DIR_READ (1<<7) 44 #define DIR_WRITE (0<<7) 45 #define ADDR_INCREMENT (1<<6) 47 #if defined(PX4_SPIDEV_BARO) || defined(PX4_SPIDEV_EXT_BARO) 51 class MS5611_SPI :
public device::SPI
55 virtual ~MS5611_SPI() =
default;
58 virtual int read(
unsigned offset,
void *
data,
unsigned count);
59 virtual int ioctl(
unsigned operation,
unsigned &arg);
76 int _measure(
unsigned addr);
90 uint16_t _reg16(
unsigned reg);
98 int _transfer(uint8_t *
send, uint8_t *recv,
unsigned len);
104 #ifdef PX4_SPI_BUS_EXT 106 if (busnum == PX4_SPI_BUS_EXT) {
107 #ifdef PX4_SPIDEV_EXT_BARO 108 return new MS5611_SPI(busnum, PX4_SPIDEV_EXT_BARO, prom_buf);
115 return new MS5611_SPI(busnum, PX4_SPIDEV_BARO, prom_buf);
119 SPI(
"MS5611_SPI", nullptr, bus, device,
SPIDEV_MODE3, 20 * 1000 * 1000 ),
130 PX4_DEBUG(
"SPI init failed");
138 PX4_DEBUG(
"reset failed");
146 PX4_DEBUG(
"prom readout failed");
160 } *cvt = (_cvt *)data;
161 uint8_t buf[4] = { 0 |
DIR_WRITE, 0, 0, 0 };
164 int ret = _transfer(&buf[0], &buf[0],
sizeof(buf));
180 MS5611_SPI::ioctl(
unsigned operation,
unsigned &arg)
210 return _transfer(&cmd,
nullptr, 1);
214 MS5611_SPI::_measure(
unsigned addr)
218 return _transfer(&cmd,
nullptr, 1);
223 MS5611_SPI::_read_prom()
232 bool all_zero =
true;
234 for (
int i = 0; i < 8; i++) {
236 _prom.c[i] = _reg16(cmd);
238 if (_prom.c[i] != 0) {
249 PX4_DEBUG(
"crc failed");
253 PX4_DEBUG(
"prom all zero");
261 MS5611_SPI::_reg16(
unsigned reg)
263 uint8_t cmd[3] = { (uint8_t)(reg |
DIR_READ), 0, 0 };
265 _transfer(cmd, cmd,
sizeof(cmd));
267 return (uint16_t)(cmd[1] << 8) | cmd[2];
271 MS5611_SPI::_transfer(uint8_t *
send, uint8_t *recv,
unsigned len)
273 return transfer(send, recv, len);
bool crc4(uint16_t *n_prom)
MS5611 crc4 cribbed from the datasheet.
Namespace encapsulating all device framework classes, functions and data.
static void read(bootloader_app_shared_t *pshared)
Shared defines for the ms5611 driver.
void init()
Activates/configures the hardware registers.
device::Device * MS5611_spi_interface(ms5611::prom_u &prom_buf, uint8_t busnum)
Fundamental base class for all physical drivers (I2C, SPI).