How to drive the LED in ADPD4101 sensor?

Hi,

We are using ADPD4101 sensor which is using I2C interface. I am unable to drive the LED which is present in ADPD4101 sensor.

I have attached my code snippet here. I am looking ahead for your suggestion on ADPD4101 sensor LED drive.

int32_t adpd410x_reg_read(nrf_drv_twi_t const *p_instance, uint16_t address, uint16_t *store_data)
{
	uint32_t ret_code;
	uint8_t buff[] = {0, 0, 0, 0};

        buff[0] = ((address >> 8) & 0x00ff) | 0x80;
        buff[1] = address & 0xff;
        /* No stop bit */
        ret_code = nrf_drv_twi_tx(p_instance, HRM_I2C_ADDRESS, buff, 2, true);
        if(ret_code != NRF_SUCCESS)
           return ret_code;
        ret_code = nrf_drv_twi_rx(p_instance, HRM_I2C_ADDRESS, (buff + 2), 2);
        if(ret_code != NRF_SUCCESS)
           return ret_code;

	*store_data = ((uint16_t)buff[2] << 8) & 0xff00;
	*store_data |= buff[3] & 0xff;

	return NRF_SUCCESS;
}
/**
 * @brief Write device register.
 * @param address - Register address.
 * @param data - New register value.
 * @return NRF_SUCCESS in case of success, FAILURE otherwise.
 */
int32_t adpd410x_reg_write(nrf_drv_twi_t const *p_instance, uint16_t address, uint16_t data)
{
	uint8_t buff[] = {0, 0, 0, 0};

          buff[0] = ((address >> 8) & 0x00ff) | 0x80;
          buff[1] = address & 0xff;
          buff[2] = (data >> 8) & 0x00ff;
          buff[3] = data & 0xff;

        return nrf_drv_twi_tx(p_instance, HRM_I2C_ADDRESS, buff, 4, false);
}

/**
 * @brief Do a software reset.
 * @return NRF_SUCCESS in case of success, FAILURE otherwise.
 */
int32_t adpd410x_reset(nrf_drv_twi_t const *p_instance)
{
	int32_t ret;

	ret = adpd410x_reg_write(p_instance, ADPD410X_REG_SYS_CTL, BITM_SYS_CTL_SW_RESET);
	if(ret != NRF_SUCCESS)
          return ret;
}

uint16_t reg_temp_1, val_1;
void get_ADPD4_chip_ID(nrf_drv_twi_t const *p_instance, uint8_t i2c_line)
{
        int32_t ret_code;
       
	ret_code = adpd410x_reg_read(p_instance, ADPD410X_REG_CHIP_ID, &reg_temp_1);
	if(ret_code != NRF_SUCCESS){ 
          NRF_LOG_INFO("HRM I2C read failure");
          return;
        }
        val_1 = reg_temp_1 & BITM_CHIP_ID;
        if((val_1) == (uint16_t)ADPD410X_CHIP_ID){
            NRF_LOG_INFO("ADPD4101 CHIP-ID read success");
        }
        else{
            NRF_LOG_INFO("ADPD4101 CHIP-ID read failure");   
        }
}

/**
 * @brief Set operation mode.
 * @return NRF_SUCCESS in case of success, FAILURE otherwise.
 */
int32_t adpd410x_set_opmode(nrf_drv_twi_t const *p_instance, uint16_t opmode)
{
	return adpd410x_reg_write(p_instance, ADPD410X_REG_OPMODE, opmode); 
}


/**
 * @brief Set number of active time slots.
 * @param timeslot_no - Last time slot to be enabled.
 * @return NRF_SUCCESS in case of success, FAILURE otherwise.
 */
int32_t adpd410x_set_last_timeslot(nrf_drv_twi_t const *p_instance, enum adpd410x_timeslots timeslot_no)
{
	return adpd410x_reg_write(p_instance, ADPD410X_REG_OPMODE, timeslot_no);
}

/**
 * @brief Set device sampling frequency.
 * @param sampling_freq - New sampling frequency.
 * @return NRF_SUCCESS in case of success, FAILURE otherwise.
 */
int32_t adpd410x_set_sampling_freq(nrf_drv_twi_t const *p_instance, uint32_t sampling_freq)
{
	int32_t ret;
	uint32_t reg_load;
	uint16_t reg_temp;
#if 1

        ret = adpd410x_reg_read(p_instance, ADPD410X_REG_SYS_CTL, &reg_temp);
        if(ret != NRF_SUCCESS)
            return ret;
        if(reg_temp & BITP_SYS_CTL_LFOSC_SEL)
            reg_load = ADPD410X_LOW_FREQ_OSCILLATOR_FREQ1;
        else
            reg_load = ADPD410X_LOW_FREQ_OSCILLATOR_FREQ2;

        reg_load /= sampling_freq;
#endif
        reg_load = ADPD410X_LOW_FREQ_OSCILLATOR_FREQ2;
	ret = adpd410x_reg_write(p_instance, ADPD410X_REG_TS_FREQ, (reg_load & 0xFFFF));
	if(ret != NRF_SUCCESS)
          return ret;
}

int32_t ADPD410x_device_setup(nrf_drv_twi_t const *p_instance, enum adpd410x_timeslots m_timeslot_no, uint8_t i2c_line)
{
        int32_t ret;
        uint16_t data;

        data = 0x4000;                           //Enable Channel 2
	ret = adpd410x_reg_write(p_instance, ADPD410X_REG_TS_CTRL(m_timeslot_no), data);       //0x0100
        if(ret != NRF_SUCCESS)
            return ret;

        if(i2c_line == 1)
        {
            data = 0x1000;                       //IN2 connected to VC1...IN7
            ret = adpd410x_reg_write(p_instance, ADPD410X_REG_INPUTS(m_timeslot_no), data);   //0x0102
            if(ret != NRF_SUCCESS)
                return ret;         
        }
        else
        {
            //m_timeslot_no = 6;                 //Setup inputs 
            data = 0x4043;                       //IN2 connected to VC1...IN4, IN8 connected to VC2
            ret = adpd410x_reg_write(p_instance, ADPD410X_REG_INPUTS(m_timeslot_no), data);   //0x01C2-G slot //0x0102
            if(ret != NRF_SUCCESS)
                return ret;
        }

	data = 0x0E0E;                       //21 mA output current & slot A has been selected 1A, 2A
	ret = adpd410x_reg_write(p_instance, ADPD410X_REG_LED_POW12(m_timeslot_no), data);  //0x0105
        if(ret != NRF_SUCCESS)
            return ret;

        data = 0x0E0E;                       //21 mA output current & slot A has been selected 3A, 4A
	ret = adpd410x_reg_write(p_instance, ADPD410X_REG_LED_POW34(m_timeslot_no), data);  //0x0106
        if(ret != NRF_SUCCESS)
            return ret;

        data = 0xFF0A;                       //Pulse width max & offset max/2
        ret = adpd410x_reg_write(p_instance, ADPD410X_REG_LED_PULSE(m_timeslot_no), data); //0x0109
        if(ret != NRF_SUCCESS)
            return ret;

#if 0
        data = 0x1E00;                       //21 mA output current & slot B has been selected 4B
        ret = adpd410x_reg_write(p_instance, ADPD410X_REG_LED_POW34(m_timeslot_no), data);  //0x0126
        if(ret != NRF_SUCCESS)
            return ret;
#endif
}

int32_t adpd410x_set_clock_freq(nrf_drv_twi_t const *p_instance)
{
      int32_t ret;
      ret = adpd410x_reg_write(p_instance, ADPD410X_REG_SYS_CTL, 0x0002);    //1 Mhz low freq internal oscillator selected
      if(ret != NRF_SUCCESS)
        return ret;
}

void init_ADPD410x(nrf_drv_twi_t const *p_instance)
{
        adpd410x_reset(p_instance);                 //SW reset
        adpd410x_set_opmode(p_instance, BITP_OPMODE_OP_MODE);  //standby mode 
        adpd410x_set_clock_freq(p_instance);        //1 Mhz sampling freq
        //adpd410x_set_sampling_freq(p_instance, SAMPLING_FREQ);   //For 1MHz freq - Sampling rate will be 100Hz   
        adpd410x_set_last_timeslot(p_instance, ADPD410X_TS_A); //Time slot A
}

main()
{

/*Check ADPD4101 sensor */
      get_ADPD4_chip_ID(&m_twi, I2C_LINE0);
      get_ADPD4_chip_ID(&m_twi_1, I2C_LINE1);
      ADPD410x_device_setup(&m_twi, ADPD410X_TS_A, I2C_LINE1);
      nrf_delay_ms(10);
      ADPD410x_device_setup(&m_twi_1, ADPD410X_TS_A, I2C_LINE0);
      nrf_delay_ms(10);
      adpd410x_set_opmode(&m_twi, 0x0001);  // Changing from standby mode to Go mode
      adpd410x_set_opmode(&m_twi_1, 0x0001); // Changing from standby mode to Go mode
      
}

Regards

Sudharsan