no-OS
Loading...
Searching...
No Matches
adar300x.c File Reference

Implementation of ADAR3000/ADAR3001 Driver. More...

#include <errno.h>
#include <stddef.h>
#include "adar300x.h"
#include "no_os_alloc.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_gpio.h"
#include "no_os_print_log.h"
#include "no_os_spi.h"
#include "no_os_util.h"
Include dependency graph for adar300x.c:

Functions

int adar300x_reg_write (struct adar300x_dev *dev, uint16_t reg_addr, uint8_t data)
 Writes data to ADAR300X over SPI.
 
int adar300x_reg_read (struct adar300x_dev *dev, uint16_t reg_addr, uint8_t *data)
 Reads data from ADAR300X over SPI.
 
int adar300x_reg_update (struct adar300x_dev *dev, uint16_t reg_addr, uint8_t mask, uint8_t data)
 Updates the value of an ADAR300X register.
 
int adar300x_set_page (struct adar300x_dev *dev, uint8_t page)
 Selects the address page used by the beamstate RAM windows.
 
int adar300x_page_reg_write (struct adar300x_dev *dev, uint8_t page, uint16_t reg_addr, uint8_t data)
 Writes a register on a given address page.
 
int adar300x_page_reg_read (struct adar300x_dev *dev, uint8_t page, uint16_t reg_addr, uint8_t *data)
 Reads a register from a given address page.
 
int adar300x_set_element (struct adar300x_dev *dev, enum adar300x_beamstate beamstate, uint8_t beam, uint8_t element, enum adar300x_element_param param, uint8_t val)
 Writes one element value in one of the beamstate banks.
 
int adar300x_get_element (struct adar300x_dev *dev, enum adar300x_beamstate beamstate, uint8_t beam, uint8_t element, enum adar300x_element_param param, uint8_t *val)
 Reads one element value back from one of the beamstate banks.
 
int adar300x_set_beam_amp (struct adar300x_dev *dev, enum adar300x_beam_amp_state state, uint8_t beam, uint8_t bias, bool enable)
 Sets the bias and enable of one beam amplifier in one state.
 
int adar300x_get_beam_amp (struct adar300x_dev *dev, enum adar300x_beam_amp_state state, uint8_t beam, uint8_t *bias, bool *enable)
 Reads back the bias and enable of one beam amplifier.
 
int adar300x_set_element_amp (struct adar300x_dev *dev, enum adar300x_element_amp_state state, uint8_t element, uint8_t bias, bool enable)
 Sets the bias and enable of one element amplifier in one state.
 
int adar300x_get_element_amp (struct adar300x_dev *dev, enum adar300x_element_amp_state state, uint8_t element, uint8_t *bias, bool *enable)
 Reads back the bias and enable of one element amplifier.
 
int adar300x_set_beam_mode (struct adar300x_dev *dev, uint8_t beam, enum adar300x_beam_mode mode)
 Selects where a beam takes its next beamstate from.
 
int adar300x_get_beam_mode (struct adar300x_dev *dev, uint8_t beam, enum adar300x_beam_mode *mode)
 Reads back the mode of a beam.
 
int adar300x_beam_command (struct adar300x_dev *dev, uint8_t beam_mask, enum adar300x_beam_command cmd)
 Applies a command to every beam set in the mask.
 
int adar300x_set_update_source_spi (struct adar300x_dev *dev, bool spi)
 Chooses whether update, mute and reset come from the pins or SPI.
 
int adar300x_get_update_source_spi (struct adar300x_dev *dev, bool *spi)
 Reads back the update source selection.
 
int adar300x_set_ram_beamstate (struct adar300x_dev *dev, uint8_t beam, uint8_t state, const uint8_t *values)
 Writes one beamstate into a beam's RAM page.
 
int adar300x_get_ram_beamstate (struct adar300x_dev *dev, uint8_t beam, uint8_t state, uint8_t *values)
 Reads one beamstate back from a beam's RAM page.
 
int adar300x_set_seq_range (struct adar300x_dev *dev, uint8_t beam, uint8_t start, uint8_t stop)
 Sets the range of pointers a beam's RAM sequencer steps through.
 
int adar300x_get_seq_range (struct adar300x_dev *dev, uint8_t beam, uint8_t *start, uint8_t *stop)
 Reads the range of pointers a beam's RAM sequencer steps through.
 
int adar300x_load_fifo_beamstate (struct adar300x_dev *dev, uint8_t beam, const uint8_t *values)
 Queues one beamstate onto a beam's FIFO.
 
int adar300x_get_fifo_pointers (struct adar300x_dev *dev, uint8_t beam, uint8_t *write_ptr, uint8_t *read_ptr)
 Reads a beam's FIFO write and read pointers.
 
int adar300x_get_temp (struct adar300x_dev *dev, uint8_t *code)
 Reads the temperature sensor through the on-chip ADC.
 
int adar300x_hard_reset (struct adar300x_dev *dev)
 Pulses the RSTB pin.
 
int adar300x_soft_reset (struct adar300x_dev *dev)
 Issues the soft reset sequence.
 
int adar300x_init (struct adar300x_dev **dev, struct adar300x_init_param *init_param)
 Initializes the ADAR300X.
 
int adar300x_remove (struct adar300x_dev *dev)
 Frees the resources allocated by adar300x_init().
 

Detailed Description

Implementation of ADAR3000/ADAR3001 Driver.

Author
Stefan Popa (stefa.nosp@m.n.po.nosp@m.pa@an.nosp@m.alog.nosp@m..com)

Copyright 2026(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ adar300x_beam_command()

int adar300x_beam_command ( struct adar300x_dev * dev,
uint8_t beam_mask,
enum adar300x_beam_command cmd )

Applies a command to every beam set in the mask.

Reset and mute are qualifiers rather than commands of their own: they are staged per beam and then take effect on the update strobe, mirroring how the RESET and MUTE pins qualify the UPDATE pin. Beams outside the mask have their qualifiers cleared so the staged state is always known.

Only has an effect when the update source is SPI rather than the pins, see adar300x_set_update_source_spi().

Parameters
dev- The device structure.
beam_mask- Bit per beam, bit 0 is beam 0.
cmd- Command to apply to the masked beams.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_beam_amp()

int adar300x_get_beam_amp ( struct adar300x_dev * dev,
enum adar300x_beam_amp_state state,
uint8_t beam,
uint8_t * bias,
bool * enable )

Reads back the bias and enable of one beam amplifier.

Parameters
dev- The device structure.
state- Which beam amplifier state to read.
beam- Beam index.
bias- Bias setting read from the device, may be NULL.
enable- Enable state read from the device, may be NULL.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_beam_mode()

int adar300x_get_beam_mode ( struct adar300x_dev * dev,
uint8_t beam,
enum adar300x_beam_mode * mode )

Reads back the mode of a beam.

Parameters
dev- The device structure.
beam- Beam index.
mode- Beamstate source read from the device.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_element()

int adar300x_get_element ( struct adar300x_dev * dev,
enum adar300x_beamstate beamstate,
uint8_t beam,
uint8_t element,
enum adar300x_element_param param,
uint8_t * val )

Reads one element value back from one of the beamstate banks.

Parameters
dev- The device structure.
beamstate- Which beamstate bank to read.
beam- Beam index.
element- Element index within the beam.
param- Delay or attenuation.
val- Value read from the device.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_element_amp()

int adar300x_get_element_amp ( struct adar300x_dev * dev,
enum adar300x_element_amp_state state,
uint8_t element,
uint8_t * bias,
bool * enable )

Reads back the bias and enable of one element amplifier.

Parameters
dev- The device structure.
state- Which element amplifier state to read.
element- Element index.
bias- Bias setting read from the device, may be NULL.
enable- Enable state read from the device, may be NULL.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_fifo_pointers()

int adar300x_get_fifo_pointers ( struct adar300x_dev * dev,
uint8_t beam,
uint8_t * write_ptr,
uint8_t * read_ptr )

Reads a beam's FIFO write and read pointers.

Parameters
dev- The device structure.
beam- Beam index.
write_ptr- Write pointer, may be NULL.
read_ptr- Read pointer, may be NULL.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_ram_beamstate()

int adar300x_get_ram_beamstate ( struct adar300x_dev * dev,
uint8_t beam,
uint8_t state,
uint8_t * values )

Reads one beamstate back from a beam's RAM page.

The data sheet gives the RAM its own readback protocol: a first read acts as a fetch that latches the whole 48-bit beamstate and returns invalid data, after which the six locations read back singly from that latched copy. One fetch covers the whole beamstate, so fetching per location is not needed.

Parameters
dev- The device structure.
beam- Beam index, selects the address page.
state- Beamstate index within the beam.
values- Eight 6-bit values, delay then attenuation per element.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_seq_range()

int adar300x_get_seq_range ( struct adar300x_dev * dev,
uint8_t beam,
uint8_t * start,
uint8_t * stop )

Reads the range of pointers a beam's RAM sequencer steps through.

Parameters
dev- The device structure.
beam- Beam index.
start- Start pointer, may be NULL.
stop- Stop pointer, may be NULL.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_temp()

int adar300x_get_temp ( struct adar300x_dev * dev,
uint8_t * code )

Reads the temperature sensor through the on-chip ADC.

The ADC requires a manual reset pulse before each conversion, and clocking is provided by dummy SPI transactions after the start bit is set. The conversion complete flag is polled before reading the result.

Parameters
dev- The device structure.
code- Raw conversion result, see ADAR300X_TEMP_* for the scale.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_get_update_source_spi()

int adar300x_get_update_source_spi ( struct adar300x_dev * dev,
bool * spi )

Reads back the update source selection.

Parameters
dev- The device structure.
spi- True when the commands are driven over SPI.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_hard_reset()

int adar300x_hard_reset ( struct adar300x_dev * dev)

Pulses the RSTB pin.

Parameters
dev- The device structure.
Returns
- 0 in case of success, -ENODEV when no reset GPIO is wired, or another negative error code otherwise.

◆ adar300x_init()

int adar300x_init ( struct adar300x_dev ** dev,
struct adar300x_init_param * init_param )

Initializes the ADAR300X.

Parameters
dev- The device structure.
init_param- The structure containing the device initial parameters.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_load_fifo_beamstate()

int adar300x_load_fifo_beamstate ( struct adar300x_dev * dev,
uint8_t beam,
const uint8_t * values )

Queues one beamstate onto a beam's FIFO.

The six bytes must be written in order: the write to the last address is what commits the beamstate and advances the write pointer. A load onto a full FIFO is discarded by the device.

Parameters
dev- The device structure.
beam- Beam index, selects the load address group.
values- Eight 6-bit values, delay then attenuation per element.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_page_reg_read()

int adar300x_page_reg_read ( struct adar300x_dev * dev,
uint8_t page,
uint16_t reg_addr,
uint8_t * data )

Reads a register from a given address page.

Parameters
dev- The device structure.
page- The address page.
reg_addr- The register address.
data- Data read from the device.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_page_reg_write()

int adar300x_page_reg_write ( struct adar300x_dev * dev,
uint8_t page,
uint16_t reg_addr,
uint8_t data )

Writes a register on a given address page.

Parameters
dev- The device structure.
page- The address page.
reg_addr- The register address.
data- Data value to write.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_reg_read()

int adar300x_reg_read ( struct adar300x_dev * dev,
uint16_t reg_addr,
uint8_t * data )

Reads data from ADAR300X over SPI.

Parameters
dev- The device structure.
reg_addr- The register address.
data- Data read from the device.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_reg_update()

int adar300x_reg_update ( struct adar300x_dev * dev,
uint16_t reg_addr,
uint8_t mask,
uint8_t data )

Updates the value of an ADAR300X register.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- Bits to be updated.
data- Update value for the mask.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_reg_write()

int adar300x_reg_write ( struct adar300x_dev * dev,
uint16_t reg_addr,
uint8_t data )

Writes data to ADAR300X over SPI.

Parameters
dev- The device structure.
reg_addr- The register address.
data- Data value to write.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_remove()

int adar300x_remove ( struct adar300x_dev * dev)

Frees the resources allocated by adar300x_init().

Parameters
dev- The device structure.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_beam_amp()

int adar300x_set_beam_amp ( struct adar300x_dev * dev,
enum adar300x_beam_amp_state state,
uint8_t beam,
uint8_t bias,
bool enable )

Sets the bias and enable of one beam amplifier in one state.

Parameters
dev- The device structure.
state- Which beam amplifier state to write.
beam- Beam index.
bias- Bias setting, 0 to ADAR300X_AMP_BIAS_MAX.
enable- True to enable the amplifier in this state.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_beam_mode()

int adar300x_set_beam_mode ( struct adar300x_dev * dev,
uint8_t beam,
enum adar300x_beam_mode mode )

Selects where a beam takes its next beamstate from.

Parameters
dev- The device structure.
beam- Beam index.
mode- Beamstate source.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_element()

int adar300x_set_element ( struct adar300x_dev * dev,
enum adar300x_beamstate beamstate,
uint8_t beam,
uint8_t element,
enum adar300x_element_param param,
uint8_t val )

Writes one element value in one of the beamstate banks.

In direct mode the written value is applied on the next update; in instant direct mode it takes effect immediately.

Parameters
dev- The device structure.
beamstate- Which beamstate bank to write.
beam- Beam index.
element- Element index within the beam.
param- Delay or attenuation.
val- Value to write, 0 to ADAR300X_RAW_MAX.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_element_amp()

int adar300x_set_element_amp ( struct adar300x_dev * dev,
enum adar300x_element_amp_state state,
uint8_t element,
uint8_t bias,
bool enable )

Sets the bias and enable of one element amplifier in one state.

Parameters
dev- The device structure.
state- Which element amplifier state to write.
element- Element index.
bias- Bias setting, 0 to ADAR300X_AMP_BIAS_MAX.
enable- True to enable the amplifier in this state.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_page()

int adar300x_set_page ( struct adar300x_dev * dev,
uint8_t page )

Selects the address page used by the beamstate RAM windows.

Parameters
dev- The device structure.
page- The address page.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_ram_beamstate()

int adar300x_set_ram_beamstate ( struct adar300x_dev * dev,
uint8_t beam,
uint8_t state,
const uint8_t * values )

Writes one beamstate into a beam's RAM page.

Parameters
dev- The device structure.
beam- Beam index, selects the address page.
state- Beamstate index within the beam.
values- Eight 6-bit values, delay then attenuation per element.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_seq_range()

int adar300x_set_seq_range ( struct adar300x_dev * dev,
uint8_t beam,
uint8_t start,
uint8_t stop )

Sets the range of pointers a beam's RAM sequencer steps through.

A stop pointer below the start pointer is valid: the sequencer then wraps from pointer 63 to pointer 0, skipping the middle of the range.

Parameters
dev- The device structure.
beam- Beam index.
start- Pointer the sequencer starts from.
stop- Last pointer before the sequencer wraps to start.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_set_update_source_spi()

int adar300x_set_update_source_spi ( struct adar300x_dev * dev,
bool spi )

Chooses whether update, mute and reset come from the pins or SPI.

Parameters
dev- The device structure.
spi- True to drive the commands over SPI, false to use the pins.
Returns
- 0 in case of success or negative error code otherwise.

◆ adar300x_soft_reset()

int adar300x_soft_reset ( struct adar300x_dev * dev)

Issues the soft reset sequence.

Chip 0 uses the bus wide reset in ADAR300X_REG_SPI_CONFIG, which the datasheet documents for power up. Chips 1 to 15 ignore that register and must use the individual reset in ADAR300X_REG_CHIP_RESET instead, so the register is chosen from dev_addr. The bus wide reset also resets every other chip sharing the bus, which matters when bringing up several devices.

The reset is issued several times back to back, as the datasheet recommends when RSTB could not be held low across the supply ramp. The SPI_CONFIG readback is logged but not enforced; the scratchpad test in adar300x_init() is the authoritative check that the bus works.

Parameters
dev- The device structure.
Returns
- 0 in case of success or negative error code otherwise.