no-OS
ad5293.h
Go to the documentation of this file.
1 /***************************************************************************/
29 #ifndef _AD5293_H_
30 #define _AD5293_H_
31 
32 /****************************** Include Files ********************************/
33 #include <stdint.h>
34 #include "no_os_gpio.h"
35 #include "no_os_spi.h"
36 #include "no_os_util.h"
37 
38 /* SPI Read/Write commands */
39 #define CMD_NOP 0
40 #define CMD_W_WIPER 1
41 #define CMD_R_WIPER 2
42 #define CMD_RESET 4
43 #define CMD_W_CTRL 6
44 #define CMD_R_CTRL 7
45 #define CMD_PD 8
46 #define CMD_SDO_Z 0x8001
47 
48 /* Bit mask*/
49 #define CALI_MSK NO_OS_BIT(2)
50 #define PROTECT_MSK NO_OS_BIT(1)
51 
52 /* calibration mode */
56 };
57 
58 /* protect mode */
61  PROTECT_UNLOCK // enable update wiper position through digital interface
62 };
63 
64 /* shutdown mode */
65 enum shutdown_t {
68 };
69 
70 /* operation mode */
72  BUS,
74 };
75 
76 /* SDO mode */
77 enum sdo_mode_t {
80 };
81 
82 /* SPI frame */
83 #define AD5293_W_CTRL_FRAME(pm,cali) (uint16_t)((CMD_W_CTRL<<10)|(pm<<1)|(cali<<2))
84 #define AD5293_R_CTRL_FRAME (uint16_t)CMD_R_CTRL<<10
85 #define AD5293_W_WIPER_FRAME(data) (uint16_t)((CMD_W_WIPER<<10)|data)
86 #define AD5293_R_WIPER_FRAME (uint16_t)CMD_R_WIPER<<10
87 #define SHUTDOWN_FRAME(sd) (uint16_t)((CMD_PD<<10)|sd)
88 #define RESET_FRAME (uint16_t)CMD_RESET<<10
89 
90 /**********************************struct*****************************************/
93  uint16_t Wiper_value; //10bit
94 };
95 
96 struct ad5293_dev {
97  /* SPI */
99  /* GPIO */
101  /* number of chips */
102  uint16_t chip_num;
103  /* pointer of chip struct */
104  struct ad5293_chip_info* chip; //point to chip 0
105 };
106 
108  /* SPI */
110  /* GPIO */
112  /* number of chips */
113  uint16_t chip_num;
114 };
115 
116 /*******************************functions prototype*******************************/
117 /* Initialize the ad5293 device structure. */
118 int32_t ad5293_init(struct ad5293_dev **device,
119  struct ad5293_init_param* init_param);
120 /* Free any resource used by the driver. */
121 int32_t ad5293_remove(struct ad5293_dev* dev);
122 /* Reset ad5293 through Hardware Reset Pin. */
123 int32_t ad5293_hard_reset(struct ad5293_dev* dev);
124 /* Reset ad5293 through software reset command. */
125 int32_t ad5293_soft_reset(struct ad5293_dev* dev);
126 /* Place SDO pin in high impedence mode. */
127 int32_t ad5293_sdo_setfloat(struct ad5293_dev* dev);
128 /* Place ad5293 in shutdown mode or recovery. */
129 int32_t ad5293_shutdown(struct ad5293_dev* dev, enum shutdown_t sd);
130 /* Update ad5293 chip info struct calibration information. */
131 int32_t ad5293_update_cali(struct ad5293_dev* dev, enum calibration_mode_t cali,
132  uint8_t num);
133 /* Update ad5293 chip info struct wiper value information. */
134 int32_t ad5293_update_wiper(struct ad5293_dev* dev, uint16_t val, uint8_t num);
135 /* Write ad5293 chip info struct calibration value through SPI interface. */
136 int32_t ad5293_write_cali(struct ad5293_dev* dev);
137 /* Write ad5293 chip info struct wiper value through SPI interface. */
138 int32_t ad5293_write_wiper(struct ad5293_dev* dev);
139 /* Read ad5293 device register calibration mode through SPI interface. */
140 int32_t ad5293_read_reg_cali(struct ad5293_dev* dev);
141 /* Read ad5293 device register wiper value through SPI interface. */
142 int32_t ad5293_read_reg_wiper(struct ad5293_dev* dev);
143 /* Get calibration of a certain chip. */
144 int8_t ad5293_get_cali(struct ad5293_dev* dev, uint8_t num);
145 /* Get wiper of a certain chip. */
146 int16_t ad5293_get_wiper(struct ad5293_dev* dev, uint8_t num);
147 
148 #endif // _AD5293_H_
ad5293_sdo_setfloat
int32_t ad5293_sdo_setfloat(struct ad5293_dev *dev)
Place SDO pin in high impedence mode.
Definition: ad5293.c:252
ad5293_get_wiper
int16_t ad5293_get_wiper(struct ad5293_dev *dev, uint8_t num)
Get wiper of a certain chip.
Definition: ad5293.c:547
AD5293_R_CTRL_FRAME
#define AD5293_R_CTRL_FRAME
Definition: ad5293.h:84
NO_OS_SPI_MODE_1
@ NO_OS_SPI_MODE_1
Definition: no_os_spi.h:63
ad5293_read_reg_wiper
int32_t ad5293_read_reg_wiper(struct ad5293_dev *dev)
Read ad5293 device register wiper value through SPI interface.
Definition: ad5293.c:488
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
DAISY_CHAIN
@ DAISY_CHAIN
Definition: ad5293.h:73
ad5293_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad5293.h:109
ad5293_get_cali
int8_t ad5293_get_cali(struct ad5293_dev *dev, uint8_t num)
Get calibration of a certain chip.
Definition: ad5293.c:527
ad5293_sdo_setfloat
int32_t ad5293_sdo_setfloat(struct ad5293_dev *dev)
Place SDO pin in high impedence mode.
Definition: ad5293.c:252
operation_mode_t
operation_mode_t
Definition: ad5293.h:71
ad5293_get_cali
int8_t ad5293_get_cali(struct ad5293_dev *dev, uint8_t num)
Get calibration of a certain chip.
Definition: ad5293.c:527
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
ad5293_read_reg_cali
int32_t ad5293_read_reg_cali(struct ad5293_dev *dev)
Read ad5293 device register calibration mode through SPI interface.
Definition: ad5293.c:448
AD5293_W_WIPER_FRAME
#define AD5293_W_WIPER_FRAME(data)
Definition: ad5293.h:85
protect_mode_t
protect_mode_t
Definition: ad5293.h:59
no_os_spi.h
Header file of SPI Interface.
shutdown_t
shutdown_t
Definition: ad5293.h:65
ad5293_update_cali
int32_t ad5293_update_cali(struct ad5293_dev *dev, enum calibration_mode_t cali, uint8_t num)
Update ad5293 chip info struct calibration information.
Definition: ad5293.c:314
ad5293_hard_reset
int32_t ad5293_hard_reset(struct ad5293_dev *dev)
Reset ad5293 through Hardware Reset Pin.
Definition: ad5293.c:183
ad5293_soft_reset
int32_t ad5293_soft_reset(struct ad5293_dev *dev)
Reset ad5293 through software reset command.
Definition: ad5293.c:217
ad5293_init_param::gpio_reset
struct no_os_gpio_init_param * gpio_reset
Definition: ad5293.h:111
no_os_delay.h
Header file of Delay functions.
CALI_MSK
#define CALI_MSK
Definition: ad5293.h:49
ad5293_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad5293.h:98
AD5293_W_CTRL_FRAME
#define AD5293_W_CTRL_FRAME(pm, cali)
Definition: ad5293.h:83
ad5293_dev::gpio_reset
struct no_os_gpio_desc * gpio_reset
Definition: ad5293.h:100
device
Definition: ad9361_util.h:69
BUS
@ BUS
Definition: ad5293.h:72
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
ad5293_dev::chip
struct ad5293_chip_info * chip
Definition: ad5293.h:104
ad5293_chip_info::Wiper_value
uint16_t Wiper_value
Definition: ad5293.h:93
ad5293_update_cali
int32_t ad5293_update_cali(struct ad5293_dev *dev, enum calibration_mode_t cali, uint8_t num)
Update ad5293 chip info struct calibration information.
Definition: ad5293.c:314
ad7616_init_param::mode
enum ad7616_mode mode
Definition: ad7616.h:226
ad5293_hard_reset
int32_t ad5293_hard_reset(struct ad5293_dev *dev)
Reset ad5293 through Hardware Reset Pin.
Definition: ad5293.c:183
PROTECT_LOCK
@ PROTECT_LOCK
Definition: ad5293.h:60
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:115
ad5293_chip_info
Definition: ad5293.h:91
SDO_ENABLE
@ SDO_ENABLE
Definition: ad5293.h:79
AD5293_R_WIPER_FRAME
#define AD5293_R_WIPER_FRAME
Definition: ad5293.h:86
ad5293_dev
Definition: ad5293.h:96
ad5293_init
int32_t ad5293_init(struct ad5293_dev **device, struct ad5293_init_param *init_param)
Initialize the ad5293 device structure.
Definition: ad5293.c:72
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
calibration_mode_t
calibration_mode_t
Definition: ad5293.h:53
CMD_SDO_Z
#define CMD_SDO_Z
Definition: ad5293.h:46
ad5293_read_reg_cali
int32_t ad5293_read_reg_cali(struct ad5293_dev *dev)
Read ad5293 device register calibration mode through SPI interface.
Definition: ad5293.c:448
ad5293_dev::chip_num
uint16_t chip_num
Definition: ad5293.h:102
ad5293_update_wiper
int32_t ad5293_update_wiper(struct ad5293_dev *dev, uint16_t val, uint8_t num)
Update ad5293 chip info struct wiper value information.
Definition: ad5293.c:339
ad5293_write_cali
int32_t ad5293_write_cali(struct ad5293_dev *dev)
Write ad5293 chip info struct calibration value through SPI interface.
Definition: ad5293.c:380
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:104
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
SDO_DISENABLE
@ SDO_DISENABLE
Definition: ad5293.h:78
ad5293.h
ad5293_write_wiper
int32_t ad5293_write_wiper(struct ad5293_dev *dev)
Write ad5293 chip info struct wiper value through SPI interface.
Definition: ad5293.c:409
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ad5293_get_wiper
int16_t ad5293_get_wiper(struct ad5293_dev *dev, uint8_t num)
Get wiper of a certain chip.
Definition: ad5293.c:547
CALI_NORMAL
@ CALI_NORMAL
Definition: ad5293.h:55
CALI_PERFORMANCE
@ CALI_PERFORMANCE
Definition: ad5293.h:54
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
SHUTDOWN_FRAME
#define SHUTDOWN_FRAME(sd)
Definition: ad5293.h:87
sdo_mode_t
sdo_mode_t
Definition: ad5293.h:77
no_os_field_get
uint32_t no_os_field_get(uint32_t mask, uint32_t word)
ad5293_write_cali
int32_t ad5293_write_cali(struct ad5293_dev *dev)
Write ad5293 chip info struct calibration value through SPI interface.
Definition: ad5293.c:380
NORMAL
@ NORMAL
Definition: ad5293.h:66
ad5293_shutdown
int32_t ad5293_shutdown(struct ad5293_dev *dev, enum shutdown_t sd)
Place ad5293 in shutdown mode or recovery.
Definition: ad5293.c:286
RESET_FRAME
#define RESET_FRAME
Definition: ad5293.h:88
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
ad5293_remove
int32_t ad5293_remove(struct ad5293_dev *dev)
Free any resource used by the driver.
Definition: ad5293.c:153
ad5293_shutdown
int32_t ad5293_shutdown(struct ad5293_dev *dev, enum shutdown_t sd)
Place ad5293 in shutdown mode or recovery.
Definition: ad5293.c:286
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:114
NULL
#define NULL
Definition: wrapper.h:64
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:197
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ad5293_update_wiper
int32_t ad5293_update_wiper(struct ad5293_dev *dev, uint16_t val, uint8_t num)
Update ad5293 chip info struct wiper value information.
Definition: ad5293.c:339
PROTECT_UNLOCK
@ PROTECT_UNLOCK
Definition: ad5293.h:61
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
no_os_gpio.h
Header file of GPIO Interface.
ad5293_chip_info::cali
enum calibration_mode_t cali
Definition: ad5293.h:92
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
SHUTDOWN
@ SHUTDOWN
Definition: ad5293.h:67
no_os_util.h
Header file of utility functions.
ad5293_remove
int32_t ad5293_remove(struct ad5293_dev *dev)
Free any resource used by the driver.
Definition: ad5293.c:153
ad5293_init_param
Definition: ad5293.h:107
ad5293_init
int32_t ad5293_init(struct ad5293_dev **device, struct ad5293_init_param *init_param)
Initialize the ad5293 device structure.
Definition: ad5293.c:72
ad5293_soft_reset
int32_t ad5293_soft_reset(struct ad5293_dev *dev)
Reset ad5293 through software reset command.
Definition: ad5293.c:217
errno.h
Error macro definition for ARM Compiler.
ad5293_init_param::chip_num
uint16_t chip_num
Definition: ad5293.h:113
ad5293_read_reg_wiper
int32_t ad5293_read_reg_wiper(struct ad5293_dev *dev)
Read ad5293 device register wiper value through SPI interface.
Definition: ad5293.c:488
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
ad5293_write_wiper
int32_t ad5293_write_wiper(struct ad5293_dev *dev)
Write ad5293 chip info struct wiper value through SPI interface.
Definition: ad5293.c:409
no_os_gpio_get_optional
int32_t no_os_gpio_get_optional(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Get the value of an optional GPIO.
Definition: no_os_gpio.c:75