definition of adccallback_t has been changed?

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
User avatar
Cesare
Posts: 38
Joined: Tue Jul 11, 2017 11:51 am
Has thanked: 4 times
Been thanked: 4 times

definition of adccallback_t has been changed?

Post by Cesare »

I used to base my projects on ChibiOs branch stable_18.2.x
The definition of the ADC callback was:

Code: Select all

typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n);

I recently moved to branch stable_19.1.x but the ADC callback seems to be defined as:

Code: Select all

typedef void (*adccallback_t)(ADCDriver *adcp);

When the callback is executed, how can I know if the data are at the beginning of the buffer or at half buffer?
I am using STM32F429ZI (hal ADCv2), I tried to read the code but I can't find out any clue.

Thanks in advance.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: definition of adccallback_t has been changed?

Post by Giovanni »

Hi,

You know the size of your buffer (N) so you know also where its half begins: &buffer[N/2].

Giovanni
User avatar
Cesare
Posts: 38
Joined: Tue Jul 11, 2017 11:51 am
Has thanked: 4 times
Been thanked: 4 times

Re: definition of adccallback_t has been changed?

Post by Cesare »

Thank you Giovanni for your prompt reply.

I found the answer in the thread "Releases" where for 19.1.x it is said:

The callbacks of drivers with circular buffers (ADC, DAC, I2S, SPI) have been simplified, no parameters. A driver function xxxIsBufferComplete() has been added to determine if it is the half buffer callback or the final callback.


So the ADC callback will be something like:

Code: Select all

size_t nx = 0, ny = 0;

static void adccallback(ADCDriver *adcp) {

  if (adcIsBufferComplete(adcp)) {
    nx += 1;
  }
  else {
    ny += 1;
  }
}
Post Reply