refactor l3gd20: use driver base class

This commit is contained in:
Beat Küng
2020-03-24 09:46:20 -04:00
committed by Daniel Agar
parent 6cf4de9e02
commit 609eafd4cd
6 changed files with 89 additions and 174 deletions
+7 -25
View File
@@ -35,9 +35,10 @@
constexpr uint8_t L3GD20::_checked_registers[];
L3GD20::L3GD20(int bus, uint32_t device, enum Rotation rotation) :
SPI("L3GD20", nullptr, bus, device, SPIDEV_MODE3, 11 * 1000 * 1000),
ScheduledWorkItem(MODULE_NAME, px4::device_bus_to_wq(this->get_device_id())),
L3GD20::L3GD20(I2CSPIBusOption bus_option, int bus, uint32_t device, enum Rotation rotation, int bus_frequency,
spi_mode_e spi_mode) :
SPI("L3GD20", nullptr, bus, device, spi_mode, bus_frequency),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
_px4_gyro(get_device_id(), ORB_PRIO_DEFAULT, rotation),
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
_errors(perf_alloc(PC_COUNT, MODULE_NAME": err")),
@@ -49,10 +50,6 @@ L3GD20::L3GD20(int bus, uint32_t device, enum Rotation rotation) :
L3GD20::~L3GD20()
{
/* make sure we are truly inactive */
stop();
/* delete the perf counter */
perf_free(_sample_perf);
perf_free(_errors);
perf_free(_bad_registers);
@@ -226,20 +223,11 @@ L3GD20::set_samplerate(unsigned frequency)
void
L3GD20::start()
{
/* make sure we are stopped first */
stop();
/* start polling at the specified rate */
uint64_t interval = 1000000 / L3GD20_DEFAULT_RATE;
ScheduleOnInterval(interval - L3GD20_TIMER_REDUCTION, 10000);
}
void
L3GD20::stop()
{
ScheduleClear();
}
void
L3GD20::disable_i2c()
{
@@ -288,13 +276,6 @@ L3GD20::reset()
_read = 0;
}
void
L3GD20::Run()
{
/* make another measurement */
measure();
}
void
L3GD20::check_registers()
{
@@ -326,7 +307,7 @@ L3GD20::check_registers()
}
void
L3GD20::measure()
L3GD20::RunImpl()
{
/* status register and data as read back from the device */
#pragma pack(push, 1)
@@ -412,8 +393,9 @@ L3GD20::measure()
}
void
L3GD20::print_info()
L3GD20::print_status()
{
I2CSPIDriverBase::print_status();
printf("gyro reads: %u\n", _read);
perf_print_counter(_sample_perf);
perf_print_counter(_errors);