2021-12-14 07:40:40 -08:00
|
|
|
#ifndef ENCODER_ENCODER_DATATYPE_H_
|
|
|
|
#define ENCODER_ENCODER_DATATYPE_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
2022-01-09 08:10:40 -08:00
|
|
|
typedef uint8_t encoder_pin_t;
|
|
|
|
typedef uint32_t encoder_refresh_rate_hz_t;
|
2021-12-14 07:40:40 -08:00
|
|
|
|
2021-12-15 05:17:43 -08:00
|
|
|
typedef enum {
|
2022-01-09 08:10:40 -08:00
|
|
|
ENCODER_OK = 0, ENCODER_NONE, ENCODER_ERROR
|
|
|
|
} encoder_ret_t;
|
2021-12-14 07:40:40 -08:00
|
|
|
|
2021-12-15 05:17:43 -08:00
|
|
|
typedef enum {
|
2022-01-09 08:10:40 -08:00
|
|
|
ENCODER_TYPE_NONE = 0,
|
|
|
|
ENCODER_TYPE_AS504x,
|
|
|
|
ENCODER_TYPE_MT6816,
|
|
|
|
ENCODER_TYPE_AD2S1205_SPI,
|
|
|
|
ENCODER_TYPE_SINCOS,
|
|
|
|
ENCODER_TYPE_TS5700N8501,
|
|
|
|
ENCODER_TYPE_ABI
|
|
|
|
} encoder_type_t;
|
2021-12-14 07:40:40 -08:00
|
|
|
|
2021-12-15 05:17:43 -08:00
|
|
|
typedef struct {
|
|
|
|
stm32_gpio_t *port;
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_pin_t pin;
|
|
|
|
} encoder_gpio_t;
|
2021-12-14 07:40:40 -08:00
|
|
|
|
2021-12-15 05:17:43 -08:00
|
|
|
typedef struct {
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_gpio_t gpio_nss;
|
|
|
|
encoder_gpio_t gpio_miso;
|
|
|
|
encoder_gpio_t gpio_mosi;
|
|
|
|
encoder_gpio_t gpio_sck;
|
|
|
|
} encoder_spi_config_t;
|
2021-12-14 07:40:40 -08:00
|
|
|
|
2021-12-15 05:17:43 -08:00
|
|
|
typedef struct {
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_gpio_t gpio_A;
|
|
|
|
encoder_gpio_t gpio_B;
|
|
|
|
} encoder_incremental_config_t;
|
2021-12-15 04:40:16 -08:00
|
|
|
|
2021-12-17 04:13:11 -08:00
|
|
|
typedef struct {
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_gpio_t gpio_TX;
|
|
|
|
encoder_gpio_t gpio_RX;
|
|
|
|
encoder_gpio_t gpio_EXT;
|
|
|
|
} encoder_UART_config_t;
|
2021-12-17 04:13:11 -08:00
|
|
|
|
2021-12-14 07:40:40 -08:00
|
|
|
typedef struct {
|
|
|
|
bool is_init;
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_refresh_rate_hz_t refresh_rate_hz;
|
|
|
|
encoder_spi_config_t spi_config;
|
2021-12-17 07:18:07 -08:00
|
|
|
#ifdef HW_SPI_DEV
|
|
|
|
SPIConfig hw_spi_cfg;
|
|
|
|
#endif
|
|
|
|
} ENCSPI_config_t;
|
|
|
|
|
|
|
|
typedef ENCSPI_config_t MT6816_config_t;
|
|
|
|
typedef ENCSPI_config_t AD2S1205_config_t;
|
|
|
|
typedef ENCSPI_config_t AS504x_config_t;
|
2021-12-14 07:40:40 -08:00
|
|
|
|
2021-12-15 04:40:16 -08:00
|
|
|
typedef struct {
|
|
|
|
bool is_init;
|
|
|
|
uint32_t counts;
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_incremental_config_t incremental_config;
|
2021-12-15 05:17:43 -08:00
|
|
|
} ABI_config_t;
|
2021-12-15 04:40:16 -08:00
|
|
|
|
2021-12-15 07:26:36 -08:00
|
|
|
typedef struct {
|
|
|
|
bool is_init;
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_refresh_rate_hz_t refresh_rate_hz;
|
2021-12-15 07:26:36 -08:00
|
|
|
float s_gain;
|
|
|
|
float s_offset;
|
|
|
|
float c_gain;
|
|
|
|
float c_offset;
|
|
|
|
float filter_constant;
|
2021-12-17 05:05:39 -08:00
|
|
|
} ENCSINCOS_config_t;
|
2021-12-15 07:26:36 -08:00
|
|
|
|
2021-12-17 04:13:11 -08:00
|
|
|
typedef struct {
|
|
|
|
bool is_init;
|
2022-01-09 08:10:40 -08:00
|
|
|
encoder_UART_config_t uart_config;
|
2021-12-17 04:13:11 -08:00
|
|
|
SerialConfig uart_param;
|
|
|
|
} TS5700N8501_config_t;
|
2021-12-14 07:40:40 -08:00
|
|
|
#endif /* ENCODER_ENCODER_DATATYPE_H_ */
|