no-OS
adgs1408.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef ADGS1408_H_
34 #define ADGS1408_H_
35 
36 /******************************************************************************/
37 /***************************** Include Files **********************************/
38 /******************************************************************************/
39 #include <stdint.h>
40 #include "no_os_spi.h"
41 
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 #define ADGS1408_REG_SW_DATA 0x01
46 #define ADGS1408_REG_ERR_CONFIG 0x02
47 #define ADGS1408_REG_ERR_FLAGS 0x03
48 #define ADGS1408_REG_BURST_EN 0x05
49 #define ADGS1408_REG_ROUND_ROBIN_EN 0x06
50 #define ADGS1408_REG_RROBIN_CHANNEL_CONFIG 0x07
51 #define ADGS1408_REG_CNV_EDGE_SEL 0x09
52 #define ADGS1408_REG_SOFT_RESETB 0x0B
53 
54 /* ADGS1408_REG_SW_DATA for ADGS1408 */
55 #define ADGS1408_SW1_EN 0x01
56 #define ADGS1408_SW2_EN 0x03
57 #define ADGS1408_SW3_EN 0x05
58 #define ADGS1408_SW4_EN 0x07
59 #define ADGS1408_SW5_EN 0x09
60 #define ADGS1408_SW6_EN 0x0B
61 #define ADGS1408_SW7_EN 0x0D
62 #define ADGS1408_SW8_EN 0x0F
63 
64 /* ADGS1408_REG_SW_DATA for ADGS1409 */
65 #define ADGS1409_SW1_EN 0x01
66 #define ADGS1409_SW2_EN 0x03
67 #define ADGS1409_SW3_EN 0x05
68 #define ADGS1409_SW4_EN 0x07
69 
70 /* ADGS1408_REG_ERR_CONFIG */
71 #define ADGS1408_RW_ERR_EN (1 << 2)
72 #define ADGS1408_SCLK_ERR_EN (1 << 1)
73 #define ADGS1408_CRC_ERR_EN (1 << 0)
74 
75 /* ADGS1408_REG_ERR_FLAGS */
76 #define ADGS1408_RW_ERR_FLAG (1 << 2)
77 #define ADGS1408_SCLK_ERR_FLAG (1 << 1)
78 #define ADGS1408_CRC_ERR_FLAG (1 << 0)
79 #define ADGS1408_CLR_1 0x6C
80 #define ADGS1408_CLR_2 0xA9
81 
82 /* ADGS1408_REG_BURST_EN */
83 #define ADGS1408_BURST_MODE_EN (1 << 0)
84 
85 /* ADGS1408_REG_ROUND_ROBIN_EN */
86 #define ADGS1408_ROUND_ROBIN_EN (1 << 0)
87 
88 /* ADGS1408_REG_RROBIN_CHANNEL_CONFIG for ADGS1408 */
89 #define ADGS1408_RROBIN_SW1(x) (((x) & 0x1) << 0)
90 #define ADGS1408_RROBIN_SW2(x) (((x) & 0x1) << 1)
91 #define ADGS1408_RROBIN_SW3(x) (((x) & 0x1) << 2)
92 #define ADGS1408_RROBIN_SW4(x) (((x) & 0x1) << 3)
93 #define ADGS1408_RROBIN_SW5(x) (((x) & 0x1) << 4)
94 #define ADGS1408_RROBIN_SW6(x) (((x) & 0x1) << 5)
95 #define ADGS1408_RROBIN_SW7(x) (((x) & 0x1) << 6)
96 #define ADGS1408_RROBIN_SW8(x) (((x) & 0x1) << 7)
97 
98 /* ADGS1408_REG_RROBIN_CHANNEL_CONFIG for ADGS1409 */
99 #define ADGS1408_RROBIN_SW1(x) (((x) & 0x1) << 0)
100 #define ADGS1408_RROBIN_SW2(x) (((x) & 0x1) << 1)
101 #define ADGS1408_RROBIN_SW3(x) (((x) & 0x1) << 2)
102 #define ADGS1408_RROBIN_SW4(x) (((x) & 0x1) << 3)
103 
104 /* ADGS1408_REG_CNV_EDGE_SEL */
105 #define ADGS1408_CNV_EDGE_RISING (1 << 0)
106 
107 /* ADGS1408_REG_SOFT_RESETB */
108 #define ADGS1408_SOFT_RESETB(x) (((x) & 0xFF) << 0)
109 #define ADGS1408_RESET_1 0xA3
110 #define ADGS1408_RESET_2 0x05
111 
112 #define ADGS1408_DAISY_CHAIN_1 0x25
113 #define ADGS1408_DAISY_CHAIN_2 0x00
114 
115 /* ADGS1408 exit Round Robin*/
116 #define ADGS1408_RROBIN_EXIT_1 0xA3
117 #define ADGS1408_RROBIN_EXIT_2 0x18
118 #define ADGS1408_RROBIN_EXIT_3 0xE3
119 #define ADGS1408_RROBIN_EXIT_4 0xB4
120 
121 #define ADGS1408_ALIGNMENT 0x25
122 
123 #define ADGS1408_CRC8_POLY 0x07
124 
125 /******************************************************************************/
126 /*************************** Types Declarations *******************************/
127 /******************************************************************************/
131 };
132 
136 };
137 
147 };
148 
149 struct adgs1408_dev {
150  /* SPI */
152  /* Device Settings */
159 };
160 
162  /* SPI */
164  /* Device Settings */
171 };
172 
173 /******************************************************************************/
174 /************************ Functions Declarations ******************************/
175 /******************************************************************************/
176 /* Compute CRC8 checksum. */
177 uint8_t adgs1408_compute_crc8(uint8_t *data,
178  uint8_t data_size);
179 /* SPI register read from device. */
180 int32_t adgs1408_spi_reg_read(struct adgs1408_dev *dev,
181  uint8_t reg_addr,
182  uint8_t *reg_data);
183 /* SPI register write to device. */
184 int32_t adgs1408_spi_reg_write(struct adgs1408_dev *dev,
185  uint8_t reg_addr,
186  uint8_t reg_data);
187 /* SPI register read from device using a mask. */
188 int32_t adgs1408_spi_reg_read_mask(struct adgs1408_dev *dev,
189  uint8_t reg_addr,
190  uint8_t mask,
191  uint8_t *data);
192 /* SPI internal register write to device using a mask. */
193 int32_t adgs1408_spi_reg_write_mask(struct adgs1408_dev *dev,
194  uint8_t reg_addr,
195  uint8_t mask,
196  uint8_t data);
197 /* Do a software reset. */
198 int32_t adgs1408_do_soft_reset(struct adgs1408_dev *dev);
199 /* Clear the Error Flags Register. */
200 int32_t adgs1408_clear_err_flags(struct adgs1408_dev *dev);
201 /* Enter Daisy-Chain Mode. */
202 int32_t adgs1408_enter_daisy_chain(struct adgs1408_dev *dev);
203 /* Send Daisy-Chain commands. */
204 int32_t adgs1408_send_daisy_chain_cmds(struct adgs1408_dev *dev,
205  uint8_t *cmds,
206  uint8_t cmds_size);
207 /* Enter round robin mode. */
208 int32_t adgs1408_enter_round_robin(struct adgs1408_dev *dev);
209 /* Configure Round Robin Mode. */
210 int32_t adgs1408_configure_round_robin(struct adgs1408_dev *dev,
211  uint8_t cnv_polarity);
212 /* Exit Round Robin Mode. */
213 int32_t adgs1408_exit_round_robin(struct adgs1408_dev *dev);
214 /* Initialize the device. */
215 int32_t adgs1408_init(struct adgs1408_dev **device,
217 /* Free the resources allocated by adgs1408_init(). */
218 int32_t adgs1408_remove(struct adgs1408_dev *dev);
219 #endif // ADGS1408_H_
ADGS1408_REG_ROUND_ROBIN_EN
#define ADGS1408_REG_ROUND_ROBIN_EN
Definition: adgs1408.h:49
adgs1408_dev::burst_mode_en
enum adgs1408_state burst_mode_en
Definition: adgs1408.h:154
adgs1408_configure_round_robin
int32_t adgs1408_configure_round_robin(struct adgs1408_dev *dev, uint8_t cnv_polarity)
Definition: adgs1408.c:320
adgs1408_clear_err_flags
int32_t adgs1408_clear_err_flags(struct adgs1408_dev *dev)
Definition: adgs1408.c:226
adgs1408_remove
int32_t adgs1408_remove(struct adgs1408_dev *dev)
Free the resources allocated by adgs1408_init().
Definition: adgs1408.c:448
no_os_alloc.h
adgs1408_dev::rrobin_sw_config
struct adgs1408_rrobin_config rrobin_sw_config
Definition: adgs1408.h:157
adgs1408_spi_reg_write_mask
int32_t adgs1408_spi_reg_write_mask(struct adgs1408_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t data)
Definition: adgs1408.c:172
ADGS1408_RESET_2
#define ADGS1408_RESET_2
Definition: adgs1408.h:110
ADGS1408_BURST_MODE_EN
#define ADGS1408_BURST_MODE_EN
Definition: adgs1408.h:83
adgs1408_compute_crc8
uint8_t adgs1408_compute_crc8(uint8_t *data, uint8_t data_size)
Definition: adgs1408.c:53
ADGS1408_DAISY_CHAIN_2
#define ADGS1408_DAISY_CHAIN_2
Definition: adgs1408.h:113
adgs1408_do_soft_reset
int32_t adgs1408_do_soft_reset(struct adgs1408_dev *dev)
Definition: adgs1408.c:200
adgs1408_exit_round_robin
int32_t adgs1408_exit_round_robin(struct adgs1408_dev *dev)
Definition: adgs1408.c:361
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:159
adgs1408_rrobin_config::rrobin_sw8
bool rrobin_sw8
Definition: adgs1408.h:146
no_os_spi.h
Header file of SPI Interface.
adgs1408_spi_reg_read
int32_t adgs1408_spi_reg_read(struct adgs1408_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
Definition: adgs1408.c:82
adgs1408_init_param::burst_mode_en
enum adgs1408_state burst_mode_en
Definition: adgs1408.h:166
adgs1408_dev::daisy_chain_en
enum adgs1408_state daisy_chain_en
Definition: adgs1408.h:155
ADGS1408_REG_ERR_CONFIG
#define ADGS1408_REG_ERR_CONFIG
Definition: adgs1408.h:46
adgs1408_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: adgs1408.h:163
ID_ADGS1409
@ ID_ADGS1409
Definition: adgs1408.h:130
ADGS1408_RROBIN_SW8
#define ADGS1408_RROBIN_SW8(x)
Definition: adgs1408.h:96
adgs1408_enter_daisy_chain
int32_t adgs1408_enter_daisy_chain(struct adgs1408_dev *dev)
Definition: adgs1408.c:253
ADGS1408_ROUND_ROBIN_EN
#define ADGS1408_ROUND_ROBIN_EN
Definition: adgs1408.h:86
adgs1408_rrobin_config::rrobin_sw5
bool rrobin_sw5
Definition: adgs1408.h:143
adgs1408_do_soft_reset
int32_t adgs1408_do_soft_reset(struct adgs1408_dev *dev)
Definition: adgs1408.c:200
ADGS1408_DAISY_CHAIN_1
#define ADGS1408_DAISY_CHAIN_1
Definition: adgs1408.h:112
device
Definition: ad9361_util.h:69
ADGS1408_ENABLE
@ ADGS1408_ENABLE
Definition: adgs1408.h:134
ADGS1408_ALIGNMENT
#define ADGS1408_ALIGNMENT
Definition: adgs1408.h:121
adgs1408_rrobin_config::rrobin_sw7
bool rrobin_sw7
Definition: adgs1408.h:145
adgs1408_init_param
Definition: adgs1408.h:161
ADGS1408_REG_CNV_EDGE_SEL
#define ADGS1408_REG_CNV_EDGE_SEL
Definition: adgs1408.h:51
ADGS1408_RROBIN_SW3
#define ADGS1408_RROBIN_SW3(x)
Definition: adgs1408.h:101
adgs1408_init
int32_t adgs1408_init(struct adgs1408_dev **device, struct adgs1408_init_param init_param)
Definition: adgs1408.c:386
adgs1408.h
Header file of ADGS1408 Driver.
ADGS1408_RROBIN_SW7
#define ADGS1408_RROBIN_SW7(x)
Definition: adgs1408.h:95
ADGS1408_DISABLE
@ ADGS1408_DISABLE
Definition: adgs1408.h:135
ADGS1408_CLR_1
#define ADGS1408_CLR_1
Definition: adgs1408.h:79
adgs1408_rrobin_config::rrobin_sw6
bool rrobin_sw6
Definition: adgs1408.h:144
adgs1408_rrobin_config::rrobin_sw3
bool rrobin_sw3
Definition: adgs1408.h:141
adgs1408_send_daisy_chain_cmds
int32_t adgs1408_send_daisy_chain_cmds(struct adgs1408_dev *dev, uint8_t *cmds, uint8_t cmds_size)
Definition: adgs1408.c:277
adgs1408_rrobin_config
Definition: adgs1408.h:138
ADGS1408_RESET_1
#define ADGS1408_RESET_1
Definition: adgs1408.h:109
adgs1408_spi_reg_read_mask
int32_t adgs1408_spi_reg_read_mask(struct adgs1408_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t *data)
adgs1408_enter_daisy_chain
int32_t adgs1408_enter_daisy_chain(struct adgs1408_dev *dev)
Definition: adgs1408.c:253
adgs1408_dev::act_device
enum adgs1408_type act_device
Definition: adgs1408.h:158
adgs1408_enter_round_robin
int32_t adgs1408_enter_round_robin(struct adgs1408_dev *dev)
Definition: adgs1408.c:297
no_os_error.h
Error codes definition.
adgs1408_enter_round_robin
int32_t adgs1408_enter_round_robin(struct adgs1408_dev *dev)
Definition: adgs1408.c:297
ID_ADGS1408
@ ID_ADGS1408
Definition: adgs1408.h:129
adgs1408_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: adgs1408.h:151
adgs1408_init
int32_t adgs1408_init(struct adgs1408_dev **device, struct adgs1408_init_param init_param)
Definition: adgs1408.c:386
adgs1408_init_param::daisy_chain_en
enum adgs1408_state daisy_chain_en
Definition: adgs1408.h:167
ADGS1408_RROBIN_SW6
#define ADGS1408_RROBIN_SW6(x)
Definition: adgs1408.h:94
adgs1408_init_param::act_device
enum adgs1408_type act_device
Definition: adgs1408.h:170
adgs1408_spi_reg_write
int32_t adgs1408_spi_reg_write(struct adgs1408_dev *dev, uint8_t reg_addr, uint8_t reg_data)
Definition: adgs1408.c:134
adgs1408_dev::round_robin_en
enum adgs1408_state round_robin_en
Definition: adgs1408.h:156
ADGS1408_REG_BURST_EN
#define ADGS1408_REG_BURST_EN
Definition: adgs1408.h:48
adgs1408_init_param::round_robin_en
enum adgs1408_state round_robin_en
Definition: adgs1408.h:168
adgs1408_configure_round_robin
int32_t adgs1408_configure_round_robin(struct adgs1408_dev *dev, uint8_t cnv_polarity)
Definition: adgs1408.c:320
adgs1408_spi_reg_write
int32_t adgs1408_spi_reg_write(struct adgs1408_dev *dev, uint8_t reg_addr, uint8_t reg_data)
Definition: adgs1408.c:134
adgs1408_type
adgs1408_type
Definition: adgs1408.h:128
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
adgs1408_rrobin_config::rrobin_sw2
bool rrobin_sw2
Definition: adgs1408.h:140
adgs1408_exit_round_robin
int32_t adgs1408_exit_round_robin(struct adgs1408_dev *dev)
Definition: adgs1408.c:361
ADGS1408_RROBIN_SW4
#define ADGS1408_RROBIN_SW4(x)
Definition: adgs1408.h:102
adgs1408_dev
Definition: adgs1408.h:149
adgs1408_spi_reg_write_mask
int32_t adgs1408_spi_reg_write_mask(struct adgs1408_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t data)
Definition: adgs1408.c:172
ADGS1408_RROBIN_SW5
#define ADGS1408_RROBIN_SW5(x)
Definition: adgs1408.h:93
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
ADGS1408_REG_SOFT_RESETB
#define ADGS1408_REG_SOFT_RESETB
Definition: adgs1408.h:52
adgs1408_init_param::crc_en
enum adgs1408_state crc_en
Definition: adgs1408.h:165
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
adgs1408_dev::crc_en
enum adgs1408_state crc_en
Definition: adgs1408.h:153
adgs1408_rrobin_config::rrobin_sw4
bool rrobin_sw4
Definition: adgs1408.h:142
ADGS1408_CRC_ERR_EN
#define ADGS1408_CRC_ERR_EN
Definition: adgs1408.h:73
ADGS1408_RROBIN_EXIT_4
#define ADGS1408_RROBIN_EXIT_4
Definition: adgs1408.h:119
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
adgs1408_state
adgs1408_state
Definition: adgs1408.h:133
adgs1408_init_param::rrobin_sw_config
struct adgs1408_rrobin_config rrobin_sw_config
Definition: adgs1408.h:169
adgs1408_remove
int32_t adgs1408_remove(struct adgs1408_dev *dev)
Free the resources allocated by adgs1408_init().
Definition: adgs1408.c:448
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:116
ADGS1408_RROBIN_EXIT_1
#define ADGS1408_RROBIN_EXIT_1
Definition: adgs1408.h:116
ADGS1408_RROBIN_EXIT_3
#define ADGS1408_RROBIN_EXIT_3
Definition: adgs1408.h:118
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:52
ADGS1408_RROBIN_EXIT_2
#define ADGS1408_RROBIN_EXIT_2
Definition: adgs1408.h:117
ADGS1408_RROBIN_SW2
#define ADGS1408_RROBIN_SW2(x)
Definition: adgs1408.h:100
adgs1408_send_daisy_chain_cmds
int32_t adgs1408_send_daisy_chain_cmds(struct adgs1408_dev *dev, uint8_t *cmds, uint8_t cmds_size)
Definition: adgs1408.c:277
adgs1408_compute_crc8
uint8_t adgs1408_compute_crc8(uint8_t *data, uint8_t data_size)
Definition: adgs1408.c:53
ADGS1408_REG_RROBIN_CHANNEL_CONFIG
#define ADGS1408_REG_RROBIN_CHANNEL_CONFIG
Definition: adgs1408.h:50
ADGS1408_CLR_2
#define ADGS1408_CLR_2
Definition: adgs1408.h:80
adgs1408_clear_err_flags
int32_t adgs1408_clear_err_flags(struct adgs1408_dev *dev)
Definition: adgs1408.c:226
adgs1408_spi_reg_read
int32_t adgs1408_spi_reg_read(struct adgs1408_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
Definition: adgs1408.c:82
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
ADGS1408_CRC8_POLY
#define ADGS1408_CRC8_POLY
Definition: adgs1408.h:123
adgs1408_rrobin_config::rrobin_sw1
bool rrobin_sw1
Definition: adgs1408.h:139
ADGS1408_RROBIN_SW1
#define ADGS1408_RROBIN_SW1(x)
Definition: adgs1408.h:99