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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : /*
       4             : 
       5             :   ./Tools/autotest/sim_vehicle.py -v ArduCopter --gdb --debug --rgbled
       6             : 
       7             :   param set NTF_LED_TYPES 8198  # enable ToshibaLED and LP5562
       8             :   reboot
       9             : 
      10             :   param set NTF_LED_OVERRIDE 1
      11             :   led 255 0 0   # red
      12             :   led 0 255 0   # green
      13             :   led 0 0 255   # blue
      14             : 
      15             :  */
      16             : 
      17             : 
      18             : #include "SIM_config.h"
      19             : 
      20             : #if AP_SIM_LP5562_ENABLED
      21             : 
      22             : #include "SIM_I2CDevice.h"
      23             : #include "SIM_RGBLED.h"
      24             : 
      25             : namespace SITL {
      26             : 
      27             : class LP5562DevReg : public I2CRegEnum {
      28             : public:
      29             :     static constexpr uint8_t ENABLE = 0x00;
      30             :     static constexpr uint8_t OP_MODE = 0x01;
      31             : 
      32             :     static constexpr uint8_t B_PWM = 0x02;
      33             :     static constexpr uint8_t G_PWM = 0x03;
      34             :     static constexpr uint8_t R_PWM = 0x04;
      35             : 
      36             :     static constexpr uint8_t B_CURRENT = 0x05;
      37             :     static constexpr uint8_t G_CURRENT = 0x06;
      38             :     static constexpr uint8_t R_CURRENT = 0x07;
      39             : 
      40             :     static constexpr uint8_t CONFIG = 0x08;
      41             : 
      42             :     static constexpr uint8_t ENG1_PC = 0x09;
      43             :     static constexpr uint8_t ENG2_PC = 0x0A;
      44             :     static constexpr uint8_t ENG3_PC = 0x0B;
      45             : 
      46             :     static constexpr uint8_t STATUS = 0x0C;
      47             : 
      48             :     static constexpr uint8_t RESET = 0x0D;
      49             : 
      50             :     static constexpr uint8_t W_PWM = 0x0E;
      51             :     static constexpr uint8_t W_CURRENT = 0x0F;
      52             : 
      53             :     static constexpr uint8_t LED_MAP = 0x70;
      54             : 
      55             :     static constexpr uint8_t PROG_MEM_ENG1_01H = 0x10;
      56             :     static constexpr uint8_t PROG_MEM_ENG1_01L = 0x11;
      57             :     static constexpr uint8_t PROG_MEM_ENG1_02H = 0x12;
      58             :     static constexpr uint8_t PROG_MEM_ENG1_02L = 0x13;
      59             :     // .
      60             :     // .
      61             :     static constexpr uint8_t PROG_MEM_ENG1_16H = 0x2E;
      62             :     static constexpr uint8_t PROG_MEM_ENG1_16L = 0x2F;
      63             : 
      64             :     static constexpr uint8_t PROG_MEM_ENG2_01H = 0x30;
      65             :     static constexpr uint8_t PROG_MEM_ENG2_01L = 0x31;
      66             :     static constexpr uint8_t PROG_MEM_ENG2_02H = 0x32;
      67             :     static constexpr uint8_t PROG_MEM_ENG2_02L = 0x43;
      68             :     // .
      69             :     // .
      70             :     static constexpr uint8_t PROG_MEM_ENG2_16H = 0x4E;
      71             :     static constexpr uint8_t PROG_MEM_ENG2_16L = 0x4F;
      72             : 
      73             :     static constexpr uint8_t PROG_MEM_ENG3_01H = 0x50;
      74             :     static constexpr uint8_t PROG_MEM_ENG3_01L = 0x51;
      75             :     static constexpr uint8_t PROG_MEM_ENG3_02H = 0x52;
      76             :     static constexpr uint8_t PROG_MEM_ENG3_02L = 0x53;
      77             :     // .
      78             :     // .
      79             :     static constexpr uint8_t PROG_MEM_ENG3_16H = 0x6E;
      80             :     static constexpr uint8_t PROG_MEM_ENG3_16L = 0x6F;
      81             : };
      82             : 
      83             : class LP5562 : public I2CDevice, protected I2CRegisters_8Bit
      84             : {
      85             : public:
      86             : 
      87             :     void init() override;
      88             : 
      89             :     void update(const class Aircraft &aircraft) override;
      90             : 
      91      524121 :     int rdwr(I2C::i2c_rdwr_ioctl_data *&data) override {
      92      524121 :         return I2CRegisters_8Bit::rdwr(data);
      93             :     }
      94             : 
      95             : private:
      96             : 
      97             :     // nested class to hold calculations for a single channel:
      98             :     class LEDChannel {
      99             :     public:
     100        6282 :         LEDChannel(uint8_t &_direct_pwm_value) :
     101        6282 :             direct_pwm_value{_direct_pwm_value}
     102        6282 :             { }
     103             : 
     104             :         void update();
     105             : 
     106             :         // returns a value 0-255 for LED brightness:
     107   535667529 :         uint8_t current_value() const { return direct_pwm_value; }
     108             : 
     109             :     private:
     110             :         uint8_t &direct_pwm_value;
     111             :     };
     112             : 
     113             :     // these could come in as rgb or bgr?
     114             :     LEDChannel *b;
     115             :     LEDChannel *g;
     116             :     LEDChannel *r;
     117             : 
     118             :     void reset_registers();
     119             : 
     120             :     SIM_RGBLED rgbled{"LP5562"};
     121             : };
     122             : 
     123             : } // namespace SITL
     124             : 
     125             : #endif  // AP_SIM_LP5562_ENABLED

Generated by: LCOV version 1.14