LCOV - code coverage report
Current view: top level - SITL - SIM_LM2755.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 6 8 75.0 %
Date: 2026-09-09 11:02:08 Functions: 2 3 66.7 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : /*
       4             :  * To test in SITL:
       5             :  *
       6             :  * ./Tools/autotest/sim_vehicle.py -v ArduCopter --rgbled
       7             :  */
       8             : 
       9             : #include "SIM_config.h"
      10             : 
      11             : #if AP_SIM_LM2755_ENABLED
      12             : 
      13             : #include "SIM_I2CDevice.h"
      14             : #include "SIM_RGBLED.h"
      15             : 
      16             : namespace SITL {
      17             : 
      18             : class LM2755DevReg : public I2CRegEnum {
      19             : public:
      20             :     static constexpr uint8_t GENERAL_PURPOSE = 0x10;
      21             :     static constexpr uint8_t TIME_STEP = 0x20;
      22             : 
      23             :     static constexpr uint8_t D1_HIGH_LEVEL = 0xA9;
      24             :     static constexpr uint8_t D1_LOW_LEVEL = 0xA8;
      25             :     static constexpr uint8_t D1_DELAY = 0xA1;
      26             :     static constexpr uint8_t D1_RAMP_UP_STEP_TIME = 0xA5;
      27             :     static constexpr uint8_t D1_TIME_HIGH = 0xA3;
      28             :     static constexpr uint8_t D1_RAMP_DOWN_STEP_TIME = 0xA4;
      29             :     static constexpr uint8_t D1_TIMING = 0xA2;
      30             : 
      31             :     static constexpr uint8_t D2_HIGH_LEVEL = 0xB9;
      32             :     static constexpr uint8_t D2_LOW_LEVEL = 0xB8;
      33             :     static constexpr uint8_t D2_DELAY = 0xB1;
      34             :     static constexpr uint8_t D2_RAMP_UP_STEP_TIME = 0xB5;
      35             :     static constexpr uint8_t D2_TIME_HIGH = 0xB3;
      36             :     static constexpr uint8_t D2_RAMP_DOWN_STEP_TIME = 0xB4;
      37             :     static constexpr uint8_t D2_TIMING = 0xB2;
      38             : 
      39             :     static constexpr uint8_t D3_HIGH_LEVEL = 0xC9;
      40             :     static constexpr uint8_t D3_LOW_LEVEL = 0xC8;
      41             :     static constexpr uint8_t D3_DELAY = 0xC1;
      42             :     static constexpr uint8_t D3_RAMP_UP_STEP_TIME = 0xC5;
      43             :     static constexpr uint8_t D3_TIME_HIGH = 0xC3;
      44             :     static constexpr uint8_t D3_RAMP_DOWN_STEP_TIME = 0xC4;
      45             :     static constexpr uint8_t D3_TIMING = 0xC2;
      46             : };
      47             : 
      48             : class LM2755 : public I2CDevice, protected I2CRegisters_8Bit
      49             : {
      50             : public:
      51             : 
      52             :     void init() override;
      53             : 
      54             :     void update(const class Aircraft &aircraft) override;
      55             : 
      56           0 :     int rdwr(I2C::i2c_rdwr_ioctl_data *&data) override {
      57           0 :         return I2CRegisters_8Bit::rdwr(data);
      58             :     }
      59             : 
      60             : private:
      61             : 
      62             :     // nested class to hold calculations for a single channel:
      63             :     class LEDChannel {
      64             :     public:
      65        6282 :         LEDChannel(uint8_t &_high_level,
      66             :                    uint8_t &_low_level,
      67             :                    uint8_t &_delay,
      68             :                    uint8_t &_ramp_up_step_time,
      69             :                    uint8_t &_time_high,
      70             :                    uint8_t &_ramp_down_step_time,
      71        6282 :                    uint8_t &_timing) :
      72        6282 :             high_level{_high_level},
      73        6282 :             low_level{_low_level}
      74        6282 :             { }
      75             : 
      76             :         void update();
      77             : 
      78             :         // returns a value 0-255 for LED brightness:
      79   536279826 :         uint8_t current_value() const { return output_value; }
      80             : 
      81             :     private:
      82             :         uint8_t &high_level;
      83             :         uint8_t &low_level;
      84             : 
      85             :         uint8_t output_value;
      86             :     };
      87             : 
      88             :     // these could come in as rgb or bgr?
      89             :     LEDChannel *d1;
      90             :     LEDChannel *d2;
      91             :     LEDChannel *d3;
      92             : 
      93             :     SIM_RGBLED rgbled{"LM2755"};
      94             : };
      95             : 
      96             : } // namespace SITL
      97             : 
      98             : #endif  // AP_SIM_LM2755_ENABLED

Generated by: LCOV version 1.14