2015-10-05 23:41:18 +08:00
|
|
|
/* adc-ti-adc108s102.h - Private */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-10-05 23:41:18 +08:00
|
|
|
*/
|
|
|
|
#ifndef __ADC108S102_PRIV_H__
|
|
|
|
#define __ADC108S102_PRIV_H__
|
|
|
|
|
|
|
|
#include <spi.h>
|
|
|
|
#include <adc.h>
|
|
|
|
|
|
|
|
#include <misc/byteorder.h>
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-12-08 20:30:41 +08:00
|
|
|
/* Internal return code */
|
|
|
|
#define ADC108S102_DONE (-1)
|
2015-10-05 23:41:18 +08:00
|
|
|
/* 8 chans maximum + 1 dummy, 16 bits per-chans -> 18 bytes */
|
|
|
|
#define ADC108S102_CMD_BUFFER_SIZE 9
|
2015-10-23 20:06:27 +08:00
|
|
|
/* 1 dummy + 8 results maximum, 16 bits per-chans -> 18 bytes */
|
|
|
|
#define ADC108S102_SAMPLING_BUFFER_SIZE 9
|
2015-10-05 23:41:18 +08:00
|
|
|
#define ADC108S102_CHANNELS 8
|
|
|
|
#define ADC108S102_CHANNELS_SIZE \
|
2017-04-21 23:03:20 +08:00
|
|
|
(ADC108S102_CHANNELS * sizeof(u32_t))
|
2015-10-05 23:41:18 +08:00
|
|
|
#define ADC108S102_CHANNEL_CMD(_channel_) \
|
|
|
|
sys_cpu_to_be16((_channel_ << 8) << 3)
|
2015-10-23 20:06:27 +08:00
|
|
|
#define ADC108S102_RESULT_MASK 0xfff /* 12 bits resolution */
|
|
|
|
#define ADC108S102_RESULT(_res_) \
|
|
|
|
(sys_be16_to_cpu(_res_) & ADC108S102_RESULT_MASK)
|
2015-10-05 23:41:18 +08:00
|
|
|
|
|
|
|
struct ti_adc108s102_config {
|
|
|
|
const char *spi_port;
|
2017-04-21 23:03:20 +08:00
|
|
|
u32_t spi_config_flags;
|
|
|
|
u32_t spi_freq;
|
|
|
|
u32_t spi_slave;
|
2015-10-05 23:41:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ti_adc108s102_chan {
|
2017-04-21 23:03:20 +08:00
|
|
|
u32_t buf_idx;
|
2015-10-05 23:41:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ti_adc108s102_data {
|
2017-04-21 23:03:20 +08:00
|
|
|
u16_t cmd_buffer[ADC108S102_CMD_BUFFER_SIZE];
|
|
|
|
u16_t sampling_buffer[ADC108S102_SAMPLING_BUFFER_SIZE];
|
2015-10-05 23:41:18 +08:00
|
|
|
struct device *spi;
|
|
|
|
struct ti_adc108s102_chan chans[ADC108S102_CHANNELS];
|
|
|
|
struct adc_seq_table *seq_table;
|
2016-01-29 04:53:34 +08:00
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
u8_t cmd_buf_len;
|
|
|
|
u8_t sampling_buf_len;
|
|
|
|
u8_t stride[2];
|
2015-10-05 23:41:18 +08:00
|
|
|
};
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-05 23:41:18 +08:00
|
|
|
#endif /* __ADC108S102_PRIV_H__ */
|