Skip to content

Commit

Permalink
Removed unnecessary nestng and fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JKazem committed Jul 20, 2022
1 parent 492070d commit f0ebbcc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
10 changes: 6 additions & 4 deletions examples/nucleo_g474re/ads7828/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class AdcThread : public modm::pt::Protothread
PT_CALL(adc.readConversionResult());
MODM_LOG_INFO.printf("Ch7 measuremnt is \t %.4f", data.getVoltage(3.3f));
MODM_LOG_INFO << modm::endl;

MODM_LOG_INFO << "----Diff Inputs-------------" << modm::endl;

PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0Ch1));
Expand Down Expand Up @@ -125,30 +126,31 @@ class AdcThread : public modm::pt::Protothread
PT_CALL(adc.readConversionResult());
MODM_LOG_INFO.printf("Ch7 - Ch6 is \t %.4f", data.getVoltage(3.3f));
MODM_LOG_INFO << modm::endl;

MODM_LOG_INFO << "---Toggling Power Down and Internal Ref----" << modm::endl;

PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOffAdcConverterOff));
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
PT_CALL(adc.readConversionResult());
MODM_LOG_INFO.printf("Default: \t\t\t %.4f", data.getVoltage(3.3f));
MODM_LOG_INFO.printf("Default: \t\t\t\t %.4f", data.getVoltage(3.3f));
MODM_LOG_INFO << modm::endl;

PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOnAdcConverterOff));
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
PT_CALL(adc.readConversionResult());
MODM_LOG_INFO.printf("Internal ref on: \t\t %.4f", data.getVoltage(2.5f));
MODM_LOG_INFO.printf("Internal ref on: \t\t\t %.4f", data.getVoltage(2.5f));
MODM_LOG_INFO << modm::endl;

PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOffAdcConverterOn));
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
PT_CALL(adc.readConversionResult());
MODM_LOG_INFO.printf("No power down \t\t\t %.4f", data.getVoltage(3.3f));
MODM_LOG_INFO.printf("No power down \t\t\t\t %.4f", data.getVoltage(3.3f));
MODM_LOG_INFO << modm::endl;

PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOnAdcConverterOn));
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
PT_CALL(adc.readConversionResult());
MODM_LOG_INFO.printf("Internal ref on, now power down: \t %.4f", data.getVoltage(2.5f));
MODM_LOG_INFO.printf("Internal ref on, no power down: \t %.4f", data.getVoltage(2.5f));
MODM_LOG_INFO << modm::endl;

MODM_LOG_INFO << "-------------------------------" << modm::endl << modm::endl;
Expand Down
11 changes: 2 additions & 9 deletions src/modm/driver/adc/ads7828.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct ads7828
Ch6 = int(CommandByte::SD) | int(CommandByte::C1) | int(CommandByte::C0),
Ch7 = int(CommandByte::SD) | int(CommandByte::C2) | int(CommandByte::C1) | int(CommandByte::C0),
};
typedef Configuration<CommandByte_t, InputChannel, Bit7 | Bit6 | Bit5> InputChannel_t;
typedef Configuration<CommandByte_t, InputChannel, Bit7 | Bit6 | Bit5 | Bit4> InputChannel_t;

enum class
PowerDown : uint8_t
Expand Down Expand Up @@ -105,7 +105,7 @@ struct ads7828
* @ingroup modm_driver_ads101x
*/
template <typename I2cMaster>
class Ads7828 : public ads7828, public modm::I2cDevice<I2cMaster, 2>
class Ads7828 : public ads7828, public modm::I2cDevice<I2cMaster, 1>
{
public:
/**
Expand Down Expand Up @@ -152,14 +152,7 @@ class Ads7828 : public ads7828, public modm::I2cDevice<I2cMaster, 2>
}

private:
/**
* @brief Writes to the command byte
**/
modm::ResumableResult<bool>
writeRegister(uint8_t data);

Data &data;
uint8_t buffer[2];

CommandByte_t commandByte;
};
Expand Down
20 changes: 5 additions & 15 deletions src/modm/driver/adc/ads7828_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace modm
{

template <typename I2cMaster>
Ads7828<I2cMaster>::Ads7828(Data &data, uint8_t address) : data(data), modm::I2cDevice<I2cMaster, 2>(address)
Ads7828<I2cMaster>::Ads7828(Data &data, uint8_t address) : data(data), modm::I2cDevice<I2cMaster, 1>(address)
{
}

Expand All @@ -33,7 +33,8 @@ Ads7828<I2cMaster>::startMeasurement(InputChannel channel)
{
RF_BEGIN();
InputChannel_t::set(commandByte, channel);
RF_END_RETURN_CALL(writeRegister(commandByte.value));
this->transaction.configureWrite(&commandByte.value, 1);
RF_END_RETURN_CALL(this->runTransaction());
}

// ----------------------------------------------------------------------------
Expand All @@ -44,7 +45,8 @@ Ads7828<I2cMaster>::setPowerDownSelection(PowerDown powerDownSelection)
{
RF_BEGIN();
PowerDown_t::set(commandByte, powerDownSelection);
RF_END_RETURN_CALL(writeRegister(commandByte.value));
this->transaction.configureWrite(&commandByte.value, 1);
RF_END_RETURN_CALL(this->runTransaction());
}

// ----------------------------------------------------------------------------
Expand All @@ -58,16 +60,4 @@ Ads7828<I2cMaster>::readConversionResult()
RF_END_RETURN_CALL(this->runTransaction());
}

// ----------------------------------------------------------------------------

template <typename I2cMaster>
modm::ResumableResult<bool>
Ads7828<I2cMaster>::writeRegister(uint8_t data)
{
RF_BEGIN();
buffer[0] = data;
this->transaction.configureWrite(buffer, 1);
RF_END_RETURN_CALL(this->runTransaction());
}

} // modm namespace

0 comments on commit f0ebbcc

Please sign in to comment.