@@ -15,76 +15,19 @@ using namespace m5::unit::types;
1515using namespace m5 ::unit::ads111x;
1616using namespace m5 ::unit::ads111x::command;
1717
18- namespace {
19- constexpr Gain gain_table[] = {
20- Gain::PGA_6144, Gain::PGA_4096, Gain::PGA_2048, Gain::PGA_1024, Gain::PGA_512, Gain::PGA_256,
21- };
22- }
23-
2418namespace m5 {
2519namespace unit {
2620// class UnitADS1115
2721const char UnitADS1115::name[] = " UnitADS1115" ;
2822const types::uid_t UnitADS1115::uid{" UnitADS1115" _mmh3};
29- const types::uid_t UnitADS1115::attr{0 };
23+ const types::attr_t UnitADS1115::attr{attribute::AccessI2C};
24+
3025bool UnitADS1115::start_periodic_measurement (const ads111x::Sampling rate, const ads111x::Mux mux,
3126 const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que)
3227{
3328 return writeSamplingRate (_cfg.rate ) && writeMultiplexer (_cfg.mux ) && writeGain (_cfg.gain ) &&
3429 writeComparatorQueue (_cfg.comp_que ) && UnitADS111x::start_periodic_measurement ();
3530}
3631
37- // class UnitAVmeterBase
38- const char UnitAVmeterBase::name[] = " UnitAVmeterBase" ;
39- const types::uid_t UnitAVmeterBase::uid{" UnitAVmeterBase" _mmh3};
40- const types::uid_t UnitAVmeterBase::attr{0 };
41-
42- UnitAVmeterBase::UnitAVmeterBase (const uint8_t addr, const uint8_t eepromAddr) : UnitADS1115(addr), _eeprom(eepromAddr)
43- {
44- // Form a parent-child relationship
45- auto cfg = component_config ();
46- cfg.max_children = 1 ;
47- component_config (cfg);
48- _valid = add (_eeprom, 0 ) && m5::utility::isValidI2CAddress (_eeprom.address ());
49- }
50-
51- bool UnitAVmeterBase::begin ()
52- {
53- if (!validChild ()) {
54- M5_LIB_LOGE (" Child unit is invalid %x" , _eeprom.address ());
55- return false ;
56- }
57- if (!_eeprom.readCalibration ()) {
58- return false ;
59- }
60- apply_calibration (_ads_cfg.pga ());
61-
62- return UnitADS111x::begin ();
63- }
64-
65- bool UnitAVmeterBase::writeGain (const ads111x::Gain gain)
66- {
67- if (UnitADS1115::writeGain (gain)) {
68- apply_calibration (gain);
69- return true ;
70- }
71- return false ;
72- }
73-
74- Adapter* UnitAVmeterBase::duplicate_adapter (const uint8_t ch)
75- {
76- if (ch != 0 ) {
77- M5_LIB_LOGE (" Invalid channel %u" , ch);
78- return nullptr ;
79- }
80- auto myadapter = adapter ();
81- return myadapter ? myadapter->duplicate (_eeprom.address ()) : nullptr ;
82- }
83-
84- void UnitAVmeterBase::apply_calibration (const Gain gain)
85- {
86- _calibrationFactor = _eeprom.calibrationFactor (gain);
87- }
88-
8932} // namespace unit
9033} // namespace m5
0 commit comments