no-OS
ad2s1210.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef AD2S1210_H_
35 #define AD2S1210_H_
36 
37 #include <stdint.h>
38 #include <stdbool.h>
39 #include "no_os_spi.h"
40 #include "no_os_gpio.h"
41 
42 #define AD2S1210_REG_POSITION 0x80
43 #define AD2S1210_REG_VELOCITY 0x82
44 #define AD2S1210_REG_LOS_THRD 0x88
45 #define AD2S1210_REG_DOS_OVR_THRD 0x89
46 #define AD2S1210_REG_DOS_MIS_THRD 0x8A
47 #define AD2S1210_REG_DOS_RST_MAX_THRD 0x8B
48 #define AD2S1210_REG_DOS_RST_MIN_THRD 0x8C
49 #define AD2S1210_REG_LOT_HIGH_THRD 0x8D
50 #define AD2S1210_REG_LOT_LOW_THRD 0x8E
51 #define AD2S1210_REG_EXCIT_FREQ 0x91
52 #define AD2S1210_REG_CONTROL 0x92
53 #define AD2S1210_CONTROL_RES_MASK NO_OS_GENMASK(1, 0)
54 #define AD2S1210_CONTROL_RES0_MASK NO_OS_BIT(0)
55 #define AD2S1210_CONTROL_RES1_MASK NO_OS_BIT(1)
56 #define AD2S1210_ENABLE_HYSTERESIS NO_OS_BIT(4)
57 
58 #define AD2S1210_REG_SOFT_RESET 0xF0
59 #define AD2S1210_REG_FAULT 0xFF
60 
61 #define AD2S1210_REG_MIN AD2S1210_REG_POSITION
62 
63 #define AD2S1210_MIN_CLKIN 6144000
64 #define AD2S1210_MAX_CLKIN 10240000
65 #define AD2S1210_MIN_EXCIT 2000
66 #define AD2S1210_MAX_EXCIT 20000
67 #define AD2S1210_STEP_EXCIT 250
68 #define AD2S1210_MIN_FCW 0x4
69 #define AD2S1210_MAX_FCW 0x50
70 
71 #define AD2S1210_POS_MASK NO_OS_BIT(0)
72 #define AD2S1210_VEL_MASK NO_OS_BIT(1)
73 
79 };
80 
86 };
87 
91 };
92 
100  int8_t resolution;
101  uint32_t clkin_hz;
102 };
103 
104 struct ad2s1210_dev {
105  const char *name;
116  uint32_t clkin_hz;
117 };
118 
119 int ad2s1210_init(struct ad2s1210_dev **dev,
121 int ad2s1210_remove(struct ad2s1210_dev *dev);
122 int ad2s1210_reg_write(struct ad2s1210_dev *dev, uint8_t addr,
123  uint8_t val);
124 int ad2s1210_reg_read(struct ad2s1210_dev *dev, uint8_t addr,
125  uint8_t *val);
127  uint32_t active_mask,
128  void *data, uint32_t size);
130 int ad2s1210_set_hysteresis(struct ad2s1210_dev *dev, bool enable);
132  uint16_t fexcit);
134  uint16_t *fexcit);
135 #endif
ad2s1210_init_param::gpio_res1
struct no_os_gpio_init_param gpio_res1
Definition: ad2s1210.h:98
ad2s1210_res
ad2s1210_res
Definition: ad2s1210.h:81
AD2S1210_REG_POSITION
#define AD2S1210_REG_POSITION
Definition: ad2s1210.h:42
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
AD2S1210_POS
@ AD2S1210_POS
Definition: ad2s1210.h:89
AD2S1210_REG_SOFT_RESET
#define AD2S1210_REG_SOFT_RESET
Definition: ad2s1210.h:58
AD2S1210_POS_MASK
#define AD2S1210_POS_MASK
Definition: ad2s1210.h:71
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
ad2s1210_mode
ad2s1210_mode
Definition: ad2s1210.h:74
no_os_spi.h
Header file of SPI Interface.
AD2S1210_REG_CONTROL
#define AD2S1210_REG_CONTROL
Definition: ad2s1210.h:52
AD2S1210_REG_EXCIT_FREQ
#define AD2S1210_REG_EXCIT_FREQ
Definition: ad2s1210.h:51
ad2s1210_reg_read
int ad2s1210_reg_read(struct ad2s1210_dev *dev, uint8_t addr, uint8_t *val)
Definition: ad2s1210.c:84
ad2s1210_dev::name
const char * name
Definition: ad2s1210.h:105
pr_err
#define pr_err(fmt, args...)
Definition: no_os_print_log.h:88
ad2s1210_dev::have_resolution_pins
bool have_resolution_pins
Definition: ad2s1210.h:107
ad2s1210_reg_write
int ad2s1210_reg_write(struct ad2s1210_dev *dev, uint8_t addr, uint8_t val)
Definition: ad2s1210.c:54
no_os_delay.h
Header file of Delay functions.
MODE_RESERVED
@ MODE_RESERVED
Definition: ad2s1210.h:76
ad2s1210_init_param::resolution
int8_t resolution
Definition: ad2s1210.h:100
ad2s1210_init
int ad2s1210_init(struct ad2s1210_dev **dev, struct ad2s1210_init_param *init_param)
Definition: ad2s1210.c:303
ad2s1210_reg_write
int ad2s1210_reg_write(struct ad2s1210_dev *dev, uint8_t addr, uint8_t val)
Definition: ad2s1210.c:54
AD2S1210_CONTROL_RES1_MASK
#define AD2S1210_CONTROL_RES1_MASK
Definition: ad2s1210.h:55
ad2s1210_dev::gpio_sample
struct no_os_gpio_desc * gpio_sample
Definition: ad2s1210.h:115
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
no_os_print_log.h
Print messages helpers.
AD2S1210_REG_VELOCITY
#define AD2S1210_REG_VELOCITY
Definition: ad2s1210.h:43
ad2s1210_dev::gpio_a1
struct no_os_gpio_desc * gpio_a1
Definition: ad2s1210.h:111
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
AD2S1210_MIN_CLKIN
#define AD2S1210_MIN_CLKIN
Definition: ad2s1210.h:63
ad2s1210_reinit_excitation_frequency
int ad2s1210_reinit_excitation_frequency(struct ad2s1210_dev *dev, uint16_t fexcit)
Definition: ad2s1210.c:124
MODE_CONFIG
@ MODE_CONFIG
Definition: ad2s1210.h:78
AD2S1210_RES_12BIT
@ AD2S1210_RES_12BIT
Definition: ad2s1210.h:83
ad2s1210_dev::gpio_a0
struct no_os_gpio_desc * gpio_a0
Definition: ad2s1210.h:112
ad2s1210_channel
ad2s1210_channel
Definition: ad2s1210.h:88
ad2s1210_set_hysteresis
int ad2s1210_set_hysteresis(struct ad2s1210_dev *dev, bool enable)
Definition: ad2s1210.c:197
AD2S1210_RES_16BIT
@ AD2S1210_RES_16BIT
Definition: ad2s1210.h:85
ad2s1210_init_param::gpio_a1
struct no_os_gpio_init_param gpio_a1
Definition: ad2s1210.h:96
ad2s1210_dev::have_mode_pins
bool have_mode_pins
Definition: ad2s1210.h:106
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:115
ad2s1210_dev::gpio_res1
struct no_os_gpio_desc * gpio_res1
Definition: ad2s1210.h:114
ad2s1210_dev::mode
enum ad2s1210_mode mode
Definition: ad2s1210.h:108
AD2S1210_VEL_MASK
#define AD2S1210_VEL_MASK
Definition: ad2s1210.h:72
ad2s1210_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad2s1210.h:94
ad2s1210_dev::resolution
enum ad2s1210_res resolution
Definition: ad2s1210.h:109
no_os_error.h
Error codes definition.
ad2s1210_dev::gpio_res0
struct no_os_gpio_desc * gpio_res0
Definition: ad2s1210.h:113
ad2s1210_get_excitation_frequency
int ad2s1210_get_excitation_frequency(struct ad2s1210_dev *dev, uint16_t *fexcit)
Definition: ad2s1210.c:153
AD2S1210_RES_14BIT
@ AD2S1210_RES_14BIT
Definition: ad2s1210.h:84
ad2s1210_init
int ad2s1210_init(struct ad2s1210_dev **dev, struct ad2s1210_init_param *init_param)
Definition: ad2s1210.c:303
ad2s1210_spi_single_conversion
int ad2s1210_spi_single_conversion(struct ad2s1210_dev *dev, uint32_t active_mask, void *data, uint32_t size)
Returns the result of a conversion.
Definition: ad2s1210.c:449
AD2S1210_RES_10BIT
@ AD2S1210_RES_10BIT
Definition: ad2s1210.h:82
AD2S1210_VEL
@ AD2S1210_VEL
Definition: ad2s1210.h:90
ad2s1210_hysteresis_is_enabled
int ad2s1210_hysteresis_is_enabled(struct ad2s1210_dev *dev)
Definition: ad2s1210.c:174
AD2S1210_REG_MIN
#define AD2S1210_REG_MIN
Definition: ad2s1210.h:61
ad2s1210_dev::clkin_hz
uint32_t clkin_hz
Definition: ad2s1210.h:116
AD2S1210_MAX_CLKIN
#define AD2S1210_MAX_CLKIN
Definition: ad2s1210.h:64
ad2s1210_init_param::gpio_a0
struct no_os_gpio_init_param gpio_a0
Definition: ad2s1210.h:95
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
ad2s1210_reg_read
int ad2s1210_reg_read(struct ad2s1210_dev *dev, uint8_t addr, uint8_t *val)
Definition: ad2s1210.c:84
ad2s1210_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad2s1210.h:110
ad2s1210_remove
int ad2s1210_remove(struct ad2s1210_dev *dev)
Remove the driver's descriptor by freeing the associated resources.
Definition: ad2s1210.c:495
AD2S1210_MAX_FCW
#define AD2S1210_MAX_FCW
Definition: ad2s1210.h:69
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ad2s1210_init_param
Definition: ad2s1210.h:93
ad2s1210_init_param::clkin_hz
uint32_t clkin_hz
Definition: ad2s1210.h:101
AD2S1210_CONTROL_RES0_MASK
#define AD2S1210_CONTROL_RES0_MASK
Definition: ad2s1210.h:54
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:49
AD2S1210_CONTROL_RES_MASK
#define AD2S1210_CONTROL_RES_MASK
Definition: ad2s1210.h:53
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
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
ad2s1210_init_param::gpio_sample
struct no_os_gpio_init_param gpio_sample
Definition: ad2s1210.h:99
ad2s1210_init_param::gpio_res0
struct no_os_gpio_init_param gpio_res0
Definition: ad2s1210.h:97
ad2s1210_set_hysteresis
int ad2s1210_set_hysteresis(struct ad2s1210_dev *dev, bool enable)
Definition: ad2s1210.c:197
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
MODE_POS
@ MODE_POS
Definition: ad2s1210.h:75
ad2s1210_dev
Definition: ad2s1210.h:104
ad2s1210_remove
int ad2s1210_remove(struct ad2s1210_dev *dev)
Remove the driver's descriptor by freeing the associated resources.
Definition: ad2s1210.c:495
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.
ad2s1210_spi_single_conversion
int ad2s1210_spi_single_conversion(struct ad2s1210_dev *dev, uint32_t active_mask, void *data, uint32_t size)
Returns the result of a conversion.
Definition: ad2s1210.c:449
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
no_os_util.h
Header file of utility functions.
AD2S1210_ENABLE_HYSTERESIS
#define AD2S1210_ENABLE_HYSTERESIS
Definition: ad2s1210.h:56
no_os_gpio_direction_output
int32_t no_os_gpio_direction_output(struct no_os_gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: no_os_gpio.c:147
ad2s1210_reinit_excitation_frequency
int ad2s1210_reinit_excitation_frequency(struct ad2s1210_dev *dev, uint16_t fexcit)
Definition: ad2s1210.c:124
MODE_VEL
@ MODE_VEL
Definition: ad2s1210.h:77
ad2s1210.h
Header file for the ad2s1210 driver.
ad2s1210_hysteresis_is_enabled
int ad2s1210_hysteresis_is_enabled(struct ad2s1210_dev *dev)
Definition: ad2s1210.c:174
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
ad2s1210_get_excitation_frequency
int ad2s1210_get_excitation_frequency(struct ad2s1210_dev *dev, uint16_t *fexcit)
Definition: ad2s1210.c:153
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