Disable ADC missing #415

Open
opened 2021-05-17 05:22:16 -05:00 by Reneg973 · 4 comments
Reneg973 commented 2021-05-17 05:22:16 -05:00 (Migrated from github.com)

According to datasheet 4.9.3

The ADC can be disabled again at any time by clearing CS.EN, to save power.

The implemenation for this is missing.

What would be the accepted implementation, #if or #else?

static inline void adc_set_enabled(bool enable) {
#if 0
  adc_hw->cs = enable ? adc_hw->cs | ADC_CS_EN_BITS : adc_hw->cs &~ ADC_CS_EN_BITS;
#else
    if (enable)
        hw_set_bits(&adc_hw->cs, ADC_CS_EN_BITS)
    else
        hw_clear_bits(&adc_hw->cs, ADC_CS_EN_BITS);
#endif
}

Or maybe a 3rd variant?

According to datasheet 4.9.3 >The ADC can be disabled again at any time by clearing CS.EN, to save power. The implemenation for this is missing. What would be the accepted implementation, #if or #else? ``` static inline void adc_set_enabled(bool enable) { #if 0 adc_hw->cs = enable ? adc_hw->cs | ADC_CS_EN_BITS : adc_hw->cs &~ ADC_CS_EN_BITS; #else if (enable) hw_set_bits(&adc_hw->cs, ADC_CS_EN_BITS) else hw_clear_bits(&adc_hw->cs, ADC_CS_EN_BITS); #endif } ``` Or maybe a 3rd variant?
bruelltuete commented 2022-04-24 16:36:24 -05:00 (Migrated from github.com)

I would call it adc_deinit(), similar to i2c_deinit().

I would call it `adc_deinit()`, similar to `i2c_deinit()`.
Reneg973 commented 2022-04-26 02:34:40 -05:00 (Migrated from github.com)

I would call it adc_deinit(), similar to i2c_deinit().

Not really, I don't expect a deinit function to have a parameter. This function really can enable or disable the ADC, so it doesn't fit

> > I would call it `adc_deinit()`, similar to `i2c_deinit()`. Not really, I don't expect a deinit function to have a parameter. This function really can enable or disable the ADC, so it doesn't fit
bruelltuete commented 2022-04-26 09:59:16 -05:00 (Migrated from github.com)

I would call it adc_deinit(), similar to i2c_deinit().

Not really, I don't expect a deinit function to have a parameter. This function really can enable or disable the ADC, so it doesn't fit

Do you mean you don't like adc_deinit(bool enable)? Yeah me neither... it would just be adc_deinit() without param.

> > > > > I would call it `adc_deinit()`, similar to `i2c_deinit()`. > > Not really, I don't expect a deinit function to have a parameter. This function really can enable or disable the ADC, so it doesn't fit Do you mean you don't like `adc_deinit(bool enable)`? Yeah me neither... it would just be `adc_deinit()` without param.
Reneg973 commented 2022-04-26 11:51:28 -05:00 (Migrated from github.com)

I would call it adc_deinit(), similar to i2c_deinit().

Not really, I don't expect a deinit function to have a parameter. This function really can enable or disable the ADC, so it doesn't fit

Do you mean you don't like adc_deinit(bool enable)? Yeah me neither... it would just be adc_deinit() without param.

No I think you are out of context. The point is with setting/resetting the flag you enable or disable the ADC conversion. It doesn't do any deinitialization. You can simply enable it by setting the bit again. The same applies for gpio_deinit(). There is no deinit on a GPIO.

> > > I would call it `adc_deinit()`, similar to `i2c_deinit()`. > > > > > > Not really, I don't expect a deinit function to have a parameter. This function really can enable or disable the ADC, so it doesn't fit > > Do you mean you don't like `adc_deinit(bool enable)`? Yeah me neither... it would just be `adc_deinit()` without param. No I think you are out of context. The point is with setting/resetting the flag you enable or disable the ADC conversion. It doesn't do any deinitialization. You can simply enable it by setting the bit again. The same applies for gpio_deinit(). There is no deinit on a GPIO.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#415
No description provided.