Skip to content

Commit 57ba367

Browse files
committed
better basetypes, improved adns9800_data.hpp
1 parent 6517354 commit 57ba367

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

src/modm/driver/motion/adns9800.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <modm/platform.hpp>
1515
#include <modm/processing/fiber.hpp>
16+
#include <modm/processing/timer/timeout.hpp>
1617
#include <modm/architecture/interface/spi_device.hpp>
1718
#include <modm/architecture/interface/accessor_flash.hpp>
1819
#include <modm/debug/logger.hpp>
@@ -101,6 +102,11 @@ struct adns9800 {
101102
};
102103
MODM_FLAGS8(ConfigurationII);
103104

105+
// Adns9800 takes periods up to 65535
106+
using PeriodType = uint16_t;
107+
// The internal timer is running at 50MHz, hence the ratio:
108+
using Duration = std::chrono::duration<PeriodType, std::ratio<1, 50_MHz>>;
109+
104110
// forward declarations
105111
struct Data;
106112
struct DataAndFaildetect;
@@ -120,7 +126,6 @@ template <class SpiMaster, class Cs>
120126
class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
121127
public:
122128
static constexpr size_t FrameSize = 30 * 30; // Size of CMOS
123-
124129
/**
125130
* @brief ShutterConfig boundaries which may be selected by the automatic frame rate control.
126131
* Periods are expressed as ticks of the device, running at 50MHz.
@@ -133,9 +138,6 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
133138
* @ingroup modm_driver_adns9800
134139
*/
135140
struct ShutterConfig {
136-
using PeriodType = uint16_t;
137-
using Duration = std::chrono::duration<PeriodType, std::ratio<1, 50_MHz>>;
138-
139141
PeriodType period_min, period_max, exposure_max;
140142

141143
// The datasheet refers to "wait for one frame" without better specification.
@@ -234,7 +236,7 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
234236
}
235237

236238
void
237-
set(const ShutterConfig shutter_new) {
239+
set(ShutterConfig shutter_new) {
238240
if (shutter_new.isValid()) {
239241
shutter_config = shutter_new;
240242

@@ -252,8 +254,8 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
252254

253255
/// In fixed framerate mode (Register ConfigurationII::Fixed_FrameRate: 1), period_max selects the framerate
254256
void
255-
setFramePeriodMax(const uint16_t period_max) {
256-
const uint16_t recover = shutter_config.period_max;
257+
setFramePeriodMax(const PeriodType period_max) {
258+
const PeriodType recover = shutter_config.period_max;
257259
shutter_config.period_max = period_max;
258260

259261
if (shutter_config.isValid()) {
@@ -266,8 +268,8 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
266268
}
267269

268270
void
269-
setFramePeriodMin(const uint16_t period_min) {
270-
const uint16_t recover = shutter_config.period_min;
271+
setFramePeriodMin(const PeriodType period_min) {
272+
const PeriodType recover = shutter_config.period_min;
271273
shutter_config.period_min = period_min;
272274

273275
if (shutter_config.isValid()) {
@@ -280,8 +282,8 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
280282
}
281283

282284
void
283-
setExposureMax(const uint16_t shutter_max) {
284-
const uint16_t recover = shutter_config.shutter_max;
285+
setExposureMax(const PeriodType shutter_max) {
286+
const PeriodType recover = shutter_config.shutter_max;
285287
shutter_config.shutter_max = shutter_max;
286288

287289
if (shutter_config.assert()) {
@@ -413,7 +415,7 @@ class Adns9800 : public adns9800, public modm::SpiDevice<SpiMaster> {
413415
});
414416
modm::this_fiber::sleep_for(shutter_config.getOneFrameTime());
415417

416-
// Additionaly one could request a CRC check of the firmware. @see datasheet P31
418+
// @optimize Request a CRC result of the firmware. @see datasheet P31
417419
}
418420

419421
private:

src/modm/driver/motion/adns9800_data.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@
2020
#include "adns9800.hpp"
2121

2222
/**
23-
* You can stream Data in 3 levels of detail with increasing size: Data,
24-
* DataObserve and DataAnalysis. Of course, there's a tradeof with RAM
25-
* consumption and bus time.
23+
* Choose the level of detail you need from your Adns9800.
24+
* Of course, there's a tradeof with RAM and bus time.
2625
*
2726
* @author Thomas Sommer
2827
*
2928
* @ingroup modm_driver_adns9800
3029
*/
3130
namespace modm {
3231

33-
/// Minimum Payload: only retrieve relative movement from the sensor
32+
/// Bare minimum: Relative motion
3433
struct adns9800::Data {
35-
modm::Vector<int16_t, 2> delta;
34+
const modm::Vector<int16_t, 2> delta;
3635

3736

3837
protected:
@@ -47,7 +46,7 @@ struct adns9800::Data {
4746
friend class Adns9800;
4847
};
4948

50-
/// Retrieve relative movement from the sensor plus Laser fault detection
49+
/// Relative motion And Laser fault detection flags:
5150
struct adns9800::DataAndFaildetect : public adns9800::Data {
5251
// @todo Looks wastefull - use a bitfield or similar instead
5352
const bool LaserFaultDetected;
@@ -66,8 +65,7 @@ struct adns9800::DataAndFaildetect : public adns9800::Data {
6665
friend class Adns9800;
6766
};
6867

69-
/// Retrieve relative movement from the sensor, Laser fault detection
70-
/// and monitoring metrics from the shutter unit.
68+
/// Relative motion, Laser fault detection flags and metrics from the shutter unit:
7169
struct adns9800::DataAndFaildetectAndMonitoring
7270
: public adns9800::DataAndFaildetect {
7371
struct Statistics {
@@ -83,7 +81,7 @@ struct adns9800::DataAndFaildetectAndMonitoring
8381
* no surface below the sensor. SQUAL remains fairly high throughout the
8482
* Z-height range which allows illumination of most pixels in the sensor.
8583
*/
86-
uint8_t surface_quality;
84+
const uint8_t surface_quality;
8785
/**
8886
* This register is used to find the average pixel value. It reports the
8987
* upper byte of a 17-bit counter which sums all 900 pixels in the current
@@ -93,24 +91,26 @@ struct adns9800::DataAndFaildetectAndMonitoring
9391
* 223 (127 * 900 / 512 truncated to an integer). The minimum register value
9492
* is 0. The pixel sum value can change every frame.
9593
*/
96-
uint8_t pixel_sum;
94+
const uint8_t pixel_sum;
9795
/**
9896
* Minium and maximum Pixel value in current frame. Range:
9997
* 0 to 127.
10098
* The minimum and maximum pixel value can change every frame.
10199
*/
102-
uint8_t max_pixel;
103-
uint8_t min_pixel;
100+
const uint8_t max_pixel;
101+
const uint8_t min_pixel;
104102
} statistics;
105103

106104
// Automated shutter selections
107105
struct Shutter {
108-
/// The current exposure in cycles of Clock.
109-
/// exposure <= Adns9800::Shutter::exposure_max
110-
uint16_t exposure;
111-
/// The Frame period in cycles of Clock.
112-
/// Adns9800::Shutter::period_min <= period <= Adns9800::Shutter::period_max
113-
uint16_t period;
106+
Duration getExposureTime() const { return Duration(exposure); };
107+
Duration getFrameTime() const { return Duration(period); };
108+
109+
protected:
110+
/// exposure <= ShutterConfig::exposure_max
111+
const PeriodType exposure;
112+
/// ShutterConfig::period_min <= period <= ShutterConfig::period_max
113+
const PeriodType period;
114114
} shutter;
115115

116116
protected:

0 commit comments

Comments
 (0)