SmartSnippets DA1459x SDK
hw_quad_v2.h
Go to the documentation of this file.
1 
42 #ifndef HW_QUAD_V2_H_
43 #define HW_QUAD_V2_H_
44 
45 #if dg_configUSE_HW_QUAD
46 
47 #include <stdbool.h>
48 #include <stdint.h>
49 #include "sdk_defs.h"
50 
59 typedef enum {
60  HW_QUAD_REG_CLK_OFF = 0,
61  HW_QUAD_REG_CLK_ON = 1
63 
68 typedef enum {
69  HW_QUAD_REG_CTRL_IRQ_STATUS_OFF_NO_CLR = 0,
70  HW_QUAD_REG_CTRL_IRQ_STATUS_ON_CLR = 1
72 
77 typedef enum {
78  HW_QUAD_REG_CTRL_EVENT_CNT_CLR_OFF = 0,
79  HW_QUAD_REG_CTRL_EVENT_CNT_CLR_ON = 1
81 
86 typedef enum {
87  HW_QUAD_REG_CTRL_IRQ_EN_OFF = 0,
88  HW_QUAD_REG_CTRL_IRQ_EN_ON = 1
90 
95 typedef enum {
96  HW_QUAD_REG_CTRL2_CHANNEL_EVENT_MODE_NORMAL_CNT = 0,
97  HW_QUAD_REG_CTRL2_CHANNEL_EVENT_MODE_EDGE_CNT = 1
99 
104 typedef enum {
105  HW_QUAD_REG_INPUT_NONE = 0,
106  HW_QUAD_REG_INPUT_A_P000_B_P001 = 1,
107  HW_QUAD_REG_INPUT_A_P002_B_P003 = 2,
108  HW_QUAD_REG_INPUT_A_P004_B_P005 = 3,
109  HW_QUAD_REG_INPUT_A_P008_B_P009 = 4,
110  HW_QUAD_REG_INPUT_A_P010_B_P011 = 5,
111  HW_QUAD_REG_INPUT_A_P100_B_P102 = 6,
112  HW_QUAD_REG_INPUT_A_P103_B_P105 = 7,
113  HW_QUAD_REG_INPUT_A_P106_B_P107 = 8,
114  HW_QUAD_REG_INPUT_A_P108_B_P109 = 9,
115  HW_QUAD_REG_INPUT_A_P110_B_P111 = 10,
116  HW_QUAD_REG_INPUT_A_P112_B_P101 = 11,
117  HW_QUAD_REG_INPUT_A_P104_B_P115 = 12
119 
124 typedef enum {
125  HW_QUAD_REG_CLOCKDIV_PRESCALER_OFF = 0,
126  HW_QUAD_REG_CLOCKDIV_PRESCALER_ON = 1
128 
132 typedef struct {
133  int16_t hw_quad_xcnt_raw;
134  int16_t hw_quad_ycnt_raw;
135  int16_t hw_quad_zcnt_raw;
136  uint8_t hw_quad_event_cnt_raw;
137  int16_t hw_quad_xcnt_delta;
138  int16_t hw_quad_ycnt_delta;
139  int16_t hw_quad_zcnt_delta;
141 
147 typedef void (*hw_quad_handler_cb)(const volatile hw_quad_values_t *quad_values, void *user_data);
148 
172 typedef struct {
173  HW_QUAD_REG_CLOCKDIV_PRESCALER clk_prescaler;
174  uint16_t clk_div;
178  HW_QUAD_GPIO_INPUT chz_port_sel;
179  HW_QUAD_GPIO_INPUT chy_port_sel;
180  HW_QUAD_GPIO_INPUT chx_port_sel;
182 
189 __STATIC_FORCEINLINE int16_t hw_quad_get_xcnt_reg(void)
190 {
191  return QUADEC->QDEC_XCNT_REG;
192 }
193 
200 __STATIC_FORCEINLINE int16_t hw_quad_get_ycnt_reg(void)
201 {
202  return QUADEC->QDEC_YCNT_REG;
203 }
204 
211 __STATIC_FORCEINLINE int16_t hw_quad_get_zcnt_reg(void)
212 {
213  return QUADEC->QDEC_ZCNT_REG;
214 }
215 
222 __STATIC_FORCEINLINE uint8_t hw_quad_get_event_cnt_reg(void)
223 {
224  return QUADEC->QDEC_EVENT_CNT_REG;
225 }
226 
237 __STATIC_FORCEINLINE void hw_quad_qdec_clk_en(HW_QUAD_REG_CLK enable)
238 {
240  REG_SETF(CRG_TOP, CLK_AMBA_REG, QDEC_CLK_ENABLE, enable);
242 }
243 
252 __STATIC_FORCEINLINE void hw_quad_clr_event_cnt(void)
253 {
254  REG_SETF(QUADEC, QDEC_CTRL_REG, QDEC_EVENT_CNT_CLR, HW_QUAD_REG_CTRL_EVENT_CNT_CLR_ON);
255 }
256 
263 __STATIC_FORCEINLINE void hw_quad_clr_irq_status(void)
264 {
265  REG_SETF(QUADEC, QDEC_CTRL_REG, QDEC_IRQ_STATUS, HW_QUAD_REG_CTRL_IRQ_STATUS_ON_CLR);
266 }
267 
275 {
276  return REG_GETF(QUADEC, QDEC_CTRL_REG, QDEC_IRQ_STATUS);
277 }
278 
297 void hw_quad_interrupt_enable_and_register(hw_quad_handler_cb cb, uint8_t thres_num, void *user_data_p);
298 
309 
321 void hw_quad_start(void);
322 
332 void hw_quad_stop(void);
333 
342 void hw_quad_disable(void);
343 
356 void hw_quad_init(const hw_quad_config_t *init_data);
357 
358 #endif /* dg_configUSE_HW_QUAD */
359 
360 
361 #endif /* HW_QUAD_V2_H_ */
362 
hw_quad_clr_irq_status
__STATIC_FORCEINLINE void hw_quad_clr_irq_status(void)
Clear IRQ.
Definition: hw_quad_v2.h:263
REG_SETF
#define REG_SETF(base, reg, field, new_val)
Set the value of a register field.
Definition: sdk_defs.h:738
HW_QUAD_REG_CTRL_IRQ_EN
HW_QUAD_REG_CTRL_IRQ_EN
Quadrature Decoder CTRL Register IRQ Status.
Definition: hw_quad_v2.h:86
hw_quad_clr_event_cnt
__STATIC_FORCEINLINE void hw_quad_clr_event_cnt(void)
Clear Event Count Register.
Definition: hw_quad_v2.h:252
hw_quad_get_ycnt_reg
__STATIC_FORCEINLINE int16_t hw_quad_get_ycnt_reg(void)
Get YCNT Register.
Definition: hw_quad_v2.h:200
HW_QUAD_REG_CTRL2_CHANNEL_EVENT_MODE
HW_QUAD_REG_CTRL2_CHANNEL_EVENT_MODE
Quadrature Decoder CTRL2 Register Channel X-Y-Z Event Mode.
Definition: hw_quad_v2.h:95
hw_quad_disable
void hw_quad_disable(void)
Disable Quadrature Decoder.
sdk_defs.h
Central include header file with platform definitions.
hw_quad_values_t
Local Quadrature Decoder Counter and Deltas repository definition.
Definition: hw_quad_v2.h:132
HW_QUAD_GPIO_INPUT
HW_QUAD_GPIO_INPUT
Quadrature Decoder CTRL2 Register Channel X-Y-Z Port Selection.
Definition: hw_quad_v2.h:104
hw_quad_init
void hw_quad_init(const hw_quad_config_t *init_data)
Initialize Quadrature Decoder.
hw_quad_handler_cb
void(* hw_quad_handler_cb)(const volatile hw_quad_values_t *quad_values, void *user_data)
Quadrature Decoder Interrupt Callback.
Definition: hw_quad_v2.h:147
HW_QUAD_REG_CTRL_EVENT_CNT_CLR
HW_QUAD_REG_CTRL_EVENT_CNT_CLR
Quadrature Decoder CTRL Register Event Counter Clear.
Definition: hw_quad_v2.h:77
hw_quad_interrupt_enable_and_register
void hw_quad_interrupt_enable_and_register(hw_quad_handler_cb cb, uint8_t thres_num, void *user_data_p)
Enable Interrupt.
hw_quad_interrupt_disable_and_unregister
void hw_quad_interrupt_disable_and_unregister(void)
Disable Interrupt.
hw_quad_return_irq_status
__STATIC_FORCEINLINE HW_QUAD_REG_CTRL_IRQ_EN hw_quad_return_irq_status(void)
Return IRQ Status.
Definition: hw_quad_v2.h:274
hw_quad_get_xcnt_reg
__STATIC_FORCEINLINE int16_t hw_quad_get_xcnt_reg(void)
Get XCNT Register.
Definition: hw_quad_v2.h:189
hw_quad_config_t
Initialization Struct for use with "hw_quad_init()".
Definition: hw_quad_v2.h:172
HW_QUAD_REG_CLK
HW_QUAD_REG_CLK
Quadrature Decoder CTRL Clock Enable Status.
Definition: hw_quad_v2.h:59
HW_QUAD_REG_CTRL_IRQ_STATUS
HW_QUAD_REG_CTRL_IRQ_STATUS
Quadrature Decoder CTRL Register IRQ Status.
Definition: hw_quad_v2.h:68
GLOBAL_INT_RESTORE
#define GLOBAL_INT_RESTORE()
Macro to restore all interrupts.
Definition: sdk_defs.h:477
REG_GETF
#define REG_GETF(base, reg, field)
Return the value of a register field.
Definition: sdk_defs.h:711
hw_quad_get_zcnt_reg
__STATIC_FORCEINLINE int16_t hw_quad_get_zcnt_reg(void)
Get ZCNT Register.
Definition: hw_quad_v2.h:211
HW_QUAD_REG_CLOCKDIV_PRESCALER
HW_QUAD_REG_CLOCKDIV_PRESCALER
Quadrature Decoder CLOCKDIV Register Prescaler.
Definition: hw_quad_v2.h:124
hw_quad_stop
void hw_quad_stop(void)
Stop Quadrature Decoder.
hw_quad_qdec_clk_en
__STATIC_FORCEINLINE void hw_quad_qdec_clk_en(HW_QUAD_REG_CLK enable)
Quadrature Decoder Clock Enable/Disable.
Definition: hw_quad_v2.h:237
hw_quad_start
void hw_quad_start(void)
Start Quadrature Decoder.
hw_quad_get_event_cnt_reg
__STATIC_FORCEINLINE uint8_t hw_quad_get_event_cnt_reg(void)
Get Event Count Register.
Definition: hw_quad_v2.h:222
GLOBAL_INT_DISABLE
#define GLOBAL_INT_DISABLE()
Macro to disable all interrupts.
Definition: sdk_defs.h:452