quasar_adc.h

This file contain the functions to configure and use the ADC peripheral.

Copyright

Copyright (C) 2026 SPARK Microsystems International Inc. All rights reserved.

License

This source code is proprietary and subject to the SPARK Microsystems Software EULA found in this package in file EULA.txt.

Author

SPARK FW Team.

Typedefs

typedef enum quasar_adc_peripheral quasar_adc_peripheral_t

The ADC peripheral.

Note

Note: The ADC4 was not included since its implementation is different.

typedef enum quasar_adc_resolution quasar_adc_resolution_t

The ADC resolution.

typedef struct quasar_adc_cfg quasar_adc_cfg_t

The ADC peripheral configuration.

typedef enum quasar_adc_channel quasar_adc_channel_t

The available ADC channels.

typedef enum quasar_revision quasar_revision_t

Quasar board supported revisions.

Enums

enum quasar_adc_peripheral

The ADC peripheral.

Note

Note: The ADC4 was not included since its implementation is different.

Values:

enumerator QUASAR_ADC_PERIPHERAL_1

The ADC1 peripheral.

enumerator QUASAR_ADC_PERIPHERAL_2

The ADC2 peripheral.

enum quasar_adc_resolution

The ADC resolution.

Values:

enumerator QUASAR_ADC_RESOLUTION_14B = ADC_RESOLUTION_14B

The ADC resolution is set to 14 bits.

enumerator QUASAR_ADC_RESOLUTION_12B = ADC_RESOLUTION_12B

The ADC resolution is set to 12 bits.

enumerator QUASAR_ADC_RESOLUTION_10B = ADC_RESOLUTION_10B

The ADC resolution is set to 10 bits.

enumerator QUASAR_ADC_RESOLUTION_8B = ADC_RESOLUTION_8B

The ADC resolution is set to 8 bits.

enum quasar_adc_channel

The available ADC channels.

Values:

enumerator QUASAR_ADC_CHANNEL_1 = ADC_CHANNEL_1

The ADC channel 1.

enumerator QUASAR_ADC_CHANNEL_2 = ADC_CHANNEL_2

The ADC channel 2.

enumerator QUASAR_ADC_CHANNEL_3 = ADC_CHANNEL_3

The ADC channel 3.

enumerator QUASAR_ADC_CHANNEL_4 = ADC_CHANNEL_4

The ADC channel 4.

enumerator QUASAR_ADC_CHANNEL_5 = ADC_CHANNEL_5

The ADC channel 5.

enumerator QUASAR_ADC_CHANNEL_6 = ADC_CHANNEL_6

The ADC channel 6.

enumerator QUASAR_ADC_CHANNEL_7 = ADC_CHANNEL_7

The ADC channel 7.

enumerator QUASAR_ADC_CHANNEL_8 = ADC_CHANNEL_8

The ADC channel 8.

enumerator QUASAR_ADC_CHANNEL_9 = ADC_CHANNEL_9

The ADC channel 9.

enumerator QUASAR_ADC_CHANNEL_10 = ADC_CHANNEL_10

The ADC channel 10.

enumerator QUASAR_ADC_CHANNEL_11 = ADC_CHANNEL_11

The ADC channel 11.

enumerator QUASAR_ADC_CHANNEL_12 = ADC_CHANNEL_12

The ADC channel 12.

enumerator QUASAR_ADC_CHANNEL_13 = ADC_CHANNEL_13

The ADC channel 13.

enumerator QUASAR_ADC_CHANNEL_14 = ADC_CHANNEL_14

The ADC channel 14.

enumerator QUASAR_ADC_CHANNEL_15 = ADC_CHANNEL_15

The ADC channel 15.

enumerator QUASAR_ADC_CHANNEL_16 = ADC_CHANNEL_16

The ADC channel 16.

enumerator QUASAR_ADC_CHANNEL_17 = ADC_CHANNEL_17

The ADC channel 17.

enumerator QUASAR_ADC_CHANNEL_TEMPSENSOR = ADC_CHANNEL_TEMPSENSOR

MCU internal temperature sensor.

enum quasar_revision

Quasar board supported revisions.

Values:

enumerator QUASAR_REVA = 1

Quasar board revision A.

enumerator QUASAR_REVB = 2

Quasar board revision B.

enumerator _QUASAR_REV_COUNT

Number of supported Quasar board revisions.

Functions

quasar_revision_t quasar_adc_init(quasar_bsp_status_t *err)

Initialize the ADC peripheral for the Quasar main board, including GPIOs used for board revision and battery level monitoring. Initiate an ADC acquisition by polling method to get the board revision, and configure the ADC channel for battery level monitoring.

Parameters:

err[out] Pointer to store error status.

Returns:

Board revision.

void quasar_adc_deinit(quasar_bsp_status_t *err)

Deinitialize the ADC peripheral used for battery monitoring and board revision, deinitialize the GPIOs used for ADC, and disable the RCC clock for ADC1 and ADC2.

Parameters:

err[out] Pointer to store error status.

void quasar_adc_set_voltage_reference(uint16_t voltage_reference_in_mv)

Set the ADC voltage reference.

Note

By default, the voltage reference is set to 3300 mV.

Parameters:

voltage_reference_in_mv[in] The board’s voltage reference in millivolts.

uint16_t quasar_adc_get_voltage_reference(void)

Get the ADC voltage reference.

Returns:

The ADC voltage reference in millivolts.

uint32_t quasar_adc_start_conversion_polling(quasar_adc_peripheral_t adc_peripheral, quasar_adc_channel_t adc_channel, quasar_bsp_status_t *err)

Start an ADC acquisition and return the raw value. After the data acquisition, the channel is unselected to free the peripheral for other uses.

Note

- The ADC channel must be selected before calling this function.

  • The GPIO related to the ADC channel must be configured before calling this function.

Parameters:
  • adc_peripheral[in] The selected ADC peripheral.

  • adc_channel[in] The selected ADC channel.

  • err[out] Pointer to store error status.

Returns:

The raw ADC value. This value needs to be converted depending on the usage.

void quasar_adc_start_conversion_it(quasar_adc_peripheral_t adc_peripheral, quasar_bsp_status_t *err)

Start an ADC acquisition by interrupt.

Note

- The ADC channel must be selected before calling this function.

  • The GPIO related to the ADC channel must be configured before calling this function.

  • The value must be retrieved when the associated IRQ handler is called.

  • After the data acquisition, the channel must be unselected to free the peripheral for other uses.

Parameters:
  • adc_peripheral[in] The selected ADC peripheral.

  • err[out] Pointer to store error status.

uint16_t quasar_adc_get_battery_level_mv_polling(quasar_bsp_status_t *err)

Retrieve the battery level by initiating an ADC acquisition by polling method. The channel is configured and unselected before and after the data acquisition.

Parameters:

err[out] Pointer to store error status.

Returns:

The battery voltage in millivolt.

uint16_t quasar_adc_get_battery_level_mv_it(quasar_bsp_status_t *err)

Retrieve the local variable of the battery level.

Note

To use this function, start an ADC acquisition by interrupt first and retrieve the data in the associated IRQ handler, updating the local variable that contains the battery level.

Parameters:

err[out] Pointer to store error status.

Returns:

The battery voltage in millivolt.

quasar_revision_t quasar_adc_get_board_revision(quasar_bsp_status_t *err)

Retrieve the board revision by initiating an ADC acquisition by polling method. The channel is configured and unselected before and after the data acquisition.

Parameters:

err[out] Pointer to store error status.

Returns:

Board revision.

bool quasar_adc_is_battery_level_value_ready(void)

Verify if the battery level value has been updated.

Note

Use this function to validate that the ADC had time to acquire the data. It is mainly useful for the interrupt mode.

Returns:

True if the battery level has been updated.

void quasar_adc_set_adc1_irq_callback(void (*irq_callback)(void))

Sets the function callback for ADC1 interrupt. This callback is called at the end of the data acquisition, allowing data retrieval and finalizing the transaction by, for example, unselecting the channel.

Parameters:

irq_callback[in] External interrupt callback function pointer.

void quasar_adc_set_adc2_irq_callback(void (*irq_callback)(void))

Sets the function callback for ADC2 interrupt. This callback is called at the end of the data acquisition, allowing data retrieval and finalizing the transaction by, for example, unselecting the channel.

Parameters:

irq_callback[in] External interrupt callback function pointer.

struct quasar_adc_cfg
#include <quasar_adc.h>

The ADC peripheral configuration.

Public Members

quasar_adc_peripheral_t peripheral

The ADC peripheral to configure.

quasar_adc_resolution_t resolution

The ADC’s peripheral resolution.