definition of adccallback_t has been changed?

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
User avatar
Cesare
Posts: 36
Joined: Tue Jul 11, 2017 11:51 am
Location: Milan, Italy
Has thanked: 3 times
Been thanked: 3 times

definition of adccallback_t has been changed?

Postby Cesare » Thu Feb 20, 2020 6:15 pm

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: definition of adccallback_t has been changed?

Postby Giovanni » Thu Feb 20, 2020 6:31 pm

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: 36
Joined: Tue Jul 11, 2017 11:51 am
Location: Milan, Italy
Has thanked: 3 times
Been thanked: 3 times

Re: definition of adccallback_t has been changed?

Postby Cesare » Fri Feb 21, 2020 8:36 am

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;
  }
}


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 6 guests