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

Implementation of MAXM86161 IIO driver. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "iio_maxm86161.h"
#include "maxm86161.h"
#include "no_os_alloc.h"
#include "no_os_circular_buffer.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_irq.h"
#include "no_os_mutex.h"
#include "no_os_util.h"
Include dependency graph for iio_maxm86161.c:

Macros

#define MAXM86161_IIO_SAMPLE_SIZE   sizeof(uint32_t)
 

Enumerations

enum  maxm86161_iio_attr_id {
  MAXM86161_IIO_SAMPLE_RATE ,
  MAXM86161_IIO_INTEGRATION_TIME ,
  MAXM86161_IIO_ADC_RANGE ,
  MAXM86161_IIO_SAMPLE_AVERAGING ,
  MAXM86161_IIO_ALC_DISABLE ,
  MAXM86161_IIO_ADD_OFFSET ,
  MAXM86161_IIO_LED_SETTLING ,
  MAXM86161_IIO_DIG_FILTER ,
  MAXM86161_IIO_FIFO_WATERMARK ,
  MAXM86161_IIO_FIFO_ROLLOVER ,
  MAXM86161_IIO_FIFO_A_FULL_TYPE ,
  MAXM86161_IIO_FIFO_COUNT ,
  MAXM86161_IIO_FIFO_OVERFLOW_COUNT ,
  MAXM86161_IIO_LED_SEQ1 ,
  MAXM86161_IIO_LED_SEQ2 ,
  MAXM86161_IIO_LED_SEQ3 ,
  MAXM86161_IIO_LED_SEQ4 ,
  MAXM86161_IIO_LED_SEQ5 ,
  MAXM86161_IIO_LED_SEQ6 ,
  MAXM86161_IIO_LED1_PA ,
  MAXM86161_IIO_LED2_PA ,
  MAXM86161_IIO_LED3_PA ,
  MAXM86161_IIO_LED_PILOT_PA ,
  MAXM86161_IIO_LED1_RANGE ,
  MAXM86161_IIO_LED2_RANGE ,
  MAXM86161_IIO_LED3_RANGE ,
  MAXM86161_IIO_PD_BIAS ,
  MAXM86161_IIO_PROX_THRESHOLD ,
  MAXM86161_IIO_PF_ENABLE ,
  MAXM86161_IIO_PF_ORDER ,
  MAXM86161_IIO_PF_IIR_TC ,
  MAXM86161_IIO_PF_IIR_INIT ,
  MAXM86161_IIO_PF_THRESHOLD_SIGMA ,
  MAXM86161_IIO_SHUTDOWN ,
  MAXM86161_IIO_LP_MODE ,
  MAXM86161_IIO_BURST_EN ,
  MAXM86161_IIO_BURST_RATE ,
  MAXM86161_IIO_PART_ID ,
  MAXM86161_IIO_REV_ID ,
  MAXM86161_IIO_INT_STATUS ,
  MAXM86161_IIO_DIE_TEMP ,
  MAXM86161_IIO_BUFFER_ENABLE
}
 

Functions

void maxm86161_iio_fifo_irq_handler (void *ctx)
 FIFO almost-full interrupt handler for the MAXM86161 IIO device.
 
int maxm86161_iio_init (struct maxm86161_iio_desc **iio_desc, struct maxm86161_iio_init_param *init_param)
 Initialize the MAXM86161 IIO device descriptor.
 
int maxm86161_iio_remove (struct maxm86161_iio_desc *iio_desc)
 Free resources allocated by maxm86161_iio_init().
 
int maxm86161_iio_get_dev_descriptor (struct maxm86161_iio_desc *iio_desc, struct iio_device **iio_dev)
 Retrieve the IIO device structure from the IIO descriptor.
 

Detailed Description

Implementation of MAXM86161 IIO driver.

Author
Jan Carlo Roleda (janca.nosp@m.rlo..nosp@m.roled.nosp@m.a@an.nosp@m.alog..nosp@m.com)

Copyright 2026(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Macro Definition Documentation

◆ MAXM86161_IIO_SAMPLE_SIZE

#define MAXM86161_IIO_SAMPLE_SIZE   sizeof(uint32_t)

Enumeration Type Documentation

◆ maxm86161_iio_attr_id

Enumerator
MAXM86161_IIO_SAMPLE_RATE 
MAXM86161_IIO_INTEGRATION_TIME 
MAXM86161_IIO_ADC_RANGE 
MAXM86161_IIO_SAMPLE_AVERAGING 
MAXM86161_IIO_ALC_DISABLE 
MAXM86161_IIO_ADD_OFFSET 
MAXM86161_IIO_LED_SETTLING 
MAXM86161_IIO_DIG_FILTER 
MAXM86161_IIO_FIFO_WATERMARK 
MAXM86161_IIO_FIFO_ROLLOVER 
MAXM86161_IIO_FIFO_A_FULL_TYPE 
MAXM86161_IIO_FIFO_COUNT 
MAXM86161_IIO_FIFO_OVERFLOW_COUNT 
MAXM86161_IIO_LED_SEQ1 
MAXM86161_IIO_LED_SEQ2 
MAXM86161_IIO_LED_SEQ3 
MAXM86161_IIO_LED_SEQ4 
MAXM86161_IIO_LED_SEQ5 
MAXM86161_IIO_LED_SEQ6 
MAXM86161_IIO_LED1_PA 
MAXM86161_IIO_LED2_PA 
MAXM86161_IIO_LED3_PA 
MAXM86161_IIO_LED_PILOT_PA 
MAXM86161_IIO_LED1_RANGE 
MAXM86161_IIO_LED2_RANGE 
MAXM86161_IIO_LED3_RANGE 
MAXM86161_IIO_PD_BIAS 
MAXM86161_IIO_PROX_THRESHOLD 
MAXM86161_IIO_PF_ENABLE 
MAXM86161_IIO_PF_ORDER 
MAXM86161_IIO_PF_IIR_TC 
MAXM86161_IIO_PF_IIR_INIT 
MAXM86161_IIO_PF_THRESHOLD_SIGMA 
MAXM86161_IIO_SHUTDOWN 
MAXM86161_IIO_LP_MODE 
MAXM86161_IIO_BURST_EN 
MAXM86161_IIO_BURST_RATE 
MAXM86161_IIO_PART_ID 
MAXM86161_IIO_REV_ID 
MAXM86161_IIO_INT_STATUS 
MAXM86161_IIO_DIE_TEMP 
MAXM86161_IIO_BUFFER_ENABLE 

Function Documentation

◆ maxm86161_iio_fifo_irq_handler()

void maxm86161_iio_fifo_irq_handler ( void * ctx)

FIFO almost-full interrupt handler for the MAXM86161 IIO device.

Invoked by the driver-level IRQ dispatcher when the FIFO almost-full (A_FULL) condition is asserted. It queries the current FIFO sample count, clamps it to the physical FIFO depth, reads the pending samples from the device, decodes each sample (tag + 24-bit data) and writes the raw data words into the IIO circular buffer for later consumption by the submit callback. Samples that fail to decode are skipped. The function returns silently on any error or when there are no samples to read.

Parameters
ctx- Opaque context pointer to the MAXM86161 IIO descriptor (struct maxm86161_iio_desc *).

◆ maxm86161_iio_get_dev_descriptor()

int maxm86161_iio_get_dev_descriptor ( struct maxm86161_iio_desc * iio_desc,
struct iio_device ** iio_dev )

Retrieve the IIO device structure from the IIO descriptor.

Provides access to the underlying struct iio_device so it can be registered with the IIO framework.

Parameters
iio_desc- IIO descriptor.
iio_dev- Pointer that receives the address of the IIO device structure.
Returns
0 on success, -EINVAL if iio_desc or iio_dev is NULL.

◆ maxm86161_iio_init()

int maxm86161_iio_init ( struct maxm86161_iio_desc ** iio_desc,
struct maxm86161_iio_init_param * init_param )

Initialize the MAXM86161 IIO device descriptor.

Allocates the IIO descriptor, initializes the underlying MAXM86161 driver device, sets up the FIFO circular buffer, configures the FIFO watermark and registers the FIFO almost-full interrupt handler. The IRQ must be enabled in the driver init parameters for IIO operation. On failure, all previously acquired resources are released before returning.

Parameters
iio_desc- Pointer that receives the address of the allocated IIO descriptor on success.
init_param- Initialization parameters, including the driver init parameters and the FIFO watermark level.
Returns
0 on success, negative error code otherwise: -EINVAL if arguments are invalid or IRQ is not enabled, -ENOMEM if descriptor allocation fails, or a propagated error from the driver/FIFO/IRQ setup.

◆ maxm86161_iio_remove()

int maxm86161_iio_remove ( struct maxm86161_iio_desc * iio_desc)

Free resources allocated by maxm86161_iio_init().

Detaches the FIFO almost-full callback from the driver-level IRQ dispatcher, removes the FIFO circular buffer, removes the underlying MAXM86161 driver device and frees the IIO descriptor.

Parameters
iio_desc- IIO descriptor to free.
Returns
0 on success, -EINVAL if iio_desc is NULL.