1 /*
2  * Copyright (c) 2023 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_QEOV2_DRV_H
9 #define HPM_QEOV2_DRV_H
10 
11 #include "hpm_common.h"
12 #include "hpm_qeov2_regs.h"
13 /**
14  * @brief QEOV2 driver APIs
15  * @defgroup qeov2_interface QEOV2 driver APIs
16  * @ingroup qeov2_interfaces
17  * @{
18  */
19 
20 typedef enum {
21     qeo_wave_cosine = 0,
22     qeo_wave_saddle = 1,
23     qeo_wave_abs_cosine = 2,
24     qeo_wave_saw = 3,
25 } qeo_wave_type_t;
26 
27 typedef enum {
28     qeo_saddle_standard = 0,
29     qeo_saddle_triple
30 } qeo_saddle_type_t;
31 
32 typedef enum {
33     qeo_wave_above_max_limit_max_val = 0,
34     qeo_wave_above_max_limit_zero = 1,
35     qeo_wave_above_max_limit_max_level0_val = 2,
36 
37     qeo_wave_high_area_limit_max_val = 0,
38     qeo_wave_high_area_limit_max_level0_val = 1,
39 
40     qeo_wave_low_area_limit_zero = 0,
41     qeo_wave_low_area_limit_min_level1_val = 1,
42 
43     qeo_wave_below_min_limit_zero = 0,
44     qeo_wave_below_min_limit_max_val = 1,
45     qeo_wave_below_min_limit_min_level1_val = 2,
46 } qeo_wave_limit_t;
47 
48 typedef struct {
49     qeo_wave_limit_t above_max_limit;
50     qeo_wave_limit_t high_area0_limit;
51     qeo_wave_limit_t high_area1_limit;
52     qeo_wave_limit_t low_area0_limit;
53     qeo_wave_limit_t low_area1_limit;
54     qeo_wave_limit_t below_min_limit;
55 } qeo_wave_limit_config_t;
56 
57 typedef struct {
58     qeo_wave_limit_config_t wave0;
59     qeo_wave_limit_config_t wave1;
60     qeo_wave_limit_config_t wave2;
61     bool dq_valid_trig_enable; /*!< DQ valid trigger calculate */
62     bool pos_valid_trig_enable; /*!< Position valid trigger calculate */
63     bool vd_vq_inject_enable;
64     bool vd_vq_from_sw; /*!< true: DQ from register; false: DQ from CLC module */
65     qeo_wave_type_t wave_type;
66     qeo_saddle_type_t saddle_type;
67 } qeo_wave_mode_t;
68 
69 typedef enum {
70     qeo_abz_output_abz = 0, /*!< A and B are orthogonal signals, Z is zero pulse */
71     qeo_abz_output_pulse_revise = 1, /*!< A is speed pulse, B is directional pulse, Z not used */
72     qeo_abz_output_up_down = 2, /*!< A is forward pulse, B is reverse pusle, Z not used */
73     qeo_abz_output_three_phase = 3, /*!< A/B/Z are 3-phase orthogonal pulse */
74 } qeo_abz_type_t;
75 
76 typedef enum {
77     qeo_z_as_zero_signal_mode0 = 0,
78     qeo_z_as_zero_signal_mode1 = 1,
79     qeo_z_as_no_output_signal = 2,
80     qeo_z_as_third_phase_signal = 3,
81 } qeo_z_pulse_type_t;
82 
83 typedef struct {
84     bool z_inv_pol;
85     bool b_inv_pol;
86     bool a_inv_pol;
87     bool enable_wdog;
88     bool sync_step_position;
89     bool reverse_align_clk_falling_edge;
90     qeo_abz_type_t output_type; /*!< @ref qeo_abz_type_t */
91 } qeo_abz_mode_t;
92 
93 /*!< zero pusle legth mode */
94 typedef struct {
95     uint8_t type;
96     uint32_t start_line;
97     uint32_t end_line;
98     uint8_t  start_step;
99     uint8_t  end_step;
100     uint32_t width;
101 } qeo_z_output_mode_t;
102 
103 typedef enum {
104     qeo_pwm_output_force_0 = 2,
105     qeo_pwm_output_force_1 = 3,
106     qeo_pwm_output_not_force = 0,
107 } qeo_pwm_force_output_t;
108 
109 typedef enum {
110     qeo_pwm_safety_output_0 = 0,
111     qeo_pwm_safety_output_1 = 1,
112     qeo_pwm_safety_output_highz = 2,
113 } qeo_pwm_safety_output_t;
114 
115 typedef struct {
116     qeo_pwm_force_output_t pwm0_output; /*!< @ref qeo_pwm_force_output_t */
117     qeo_pwm_force_output_t pwm1_output;
118     qeo_pwm_force_output_t pwm2_output;
119     qeo_pwm_force_output_t pwm3_output;
120     qeo_pwm_force_output_t pwm4_output;
121     qeo_pwm_force_output_t pwm5_output;
122     qeo_pwm_force_output_t pwm6_output;
123     qeo_pwm_force_output_t pwm7_output;
124 } qeo_pwm_phase_output_table_t;
125 
126 typedef struct {
127     qeo_pwm_safety_output_t pwm0_output; /*!< @ref qeo_pwm_safety_output_t */
128     qeo_pwm_safety_output_t pwm1_output;
129     qeo_pwm_safety_output_t pwm2_output;
130     qeo_pwm_safety_output_t pwm3_output;
131     qeo_pwm_safety_output_t pwm4_output;
132     qeo_pwm_safety_output_t pwm5_output;
133     qeo_pwm_safety_output_t pwm6_output;
134     qeo_pwm_safety_output_t pwm7_output;
135 } qeo_pwm_safety_output_table_t;
136 
137 typedef struct {
138     uint8_t phase_num;
139     bool shield_hardware_trig_safety;
140     bool revise_pairs_output;
141 } qeo_pwm_mode_t;
142 
143 #ifdef __cplusplus
144 extern "C" {
145 #endif
146 
147 /* WAVE API */
148 /**
149  * @brief QEO set resolution lines for wave mode
150  * @param [in] base QEO base address
151  * @param [in] lines resolution lines
152  */
qeo_wave_set_resolution_lines(QEOV2_Type * base,uint32_t lines)153 static inline void qeo_wave_set_resolution_lines(QEOV2_Type *base, uint32_t lines)
154 {
155     base->WAVE.RESOLUTION = QEOV2_WAVE_RESOLUTION_LINES_SET(lines);
156 }
157 
158 /**
159  * @brief QEO set output type for wave mode
160  * @param [in] base QEO base address
161  * @param [in] type qeo_wave_type_t
162  */
qeo_wave_set_output_type(QEOV2_Type * base,qeo_wave_type_t type)163 static inline void qeo_wave_set_output_type(QEOV2_Type *base, qeo_wave_type_t type)
164 {
165     base->WAVE.MODE = (base->WAVE.MODE & ~QEOV2_WAVE_MODE_WAVES_OUTPUT_TYPE_MASK) | QEOV2_WAVE_MODE_WAVES_OUTPUT_TYPE_SET(type);
166 }
167 
168 /**
169  * @brief QEO set saddle type for wave mode
170  * @param [in] base QEO base address
171  * @param [in] standard true for standard saddle, false for triangular wave stacking
172  */
qeo_wave_set_saddle_type(QEOV2_Type * base,bool standard)173 static inline void qeo_wave_set_saddle_type(QEOV2_Type *base, bool standard)
174 {
175     if (standard) {
176         base->WAVE.MODE &= ~QEOV2_WAVE_MODE_SADDLE_TYPE_MASK;
177     } else {
178         base->WAVE.MODE |= QEOV2_WAVE_MODE_SADDLE_TYPE_MASK;
179     }
180 }
181 
182 /**
183  * @brief QEO set phase shift for wave mode
184  * @param [in] base QEO base address
185  * @param [in] index wave index(0/1/2)
186  * @param [in] angle left shift angle
187  */
qeo_wave_set_phase_shift(QEOV2_Type * base,uint8_t index,double angle)188 static inline void qeo_wave_set_phase_shift(QEOV2_Type *base, uint8_t index, double angle)
189 {
190     assert((angle >= 0) && (angle <= 360));
191     uint32_t val = (uint32_t)(angle * 0x100000000UL / 360);
192     base->WAVE.PHASE_SHIFT[index] = QEOV2_WAVE_PHASE_SHIFT_VAL_SET(val);
193 }
194 
195 /**
196  * @brief QEO enable vd vq inject and select vq vq source for wave mode
197  * @param [in] base QEO base address
198  * @param [in] from_sw false for vd vq data from clc module, true for vd vq from software inject register
199  */
qeo_wave_enable_vd_vq_inject(QEOV2_Type * base,bool from_sw)200 static inline void qeo_wave_enable_vd_vq_inject(QEOV2_Type *base, bool from_sw)
201 {
202     if (from_sw) {
203         base->WAVE.MODE |= QEOV2_WAVE_MODE_VD_VQ_SEL_MASK;
204     } else {
205         base->WAVE.MODE &= ~QEOV2_WAVE_MODE_VD_VQ_SEL_MASK;
206     }
207     base->WAVE.MODE |= QEOV2_WAVE_MODE_EN_WAVE_VD_VQ_INJECT_MASK;
208 }
209 
210 /**
211  * @brief QEO disable vd vq inject for wave mode
212  * @param [in] base QEO base address
213  */
qeo_wave_disable_vd_vq_inject(QEOV2_Type * base)214 static inline void qeo_wave_disable_vd_vq_inject(QEOV2_Type *base)
215 {
216     base->WAVE.MODE &= ~QEOV2_WAVE_MODE_EN_WAVE_VD_VQ_INJECT_MASK;
217 }
218 
219 /**
220  * @brief QEO config vd vq value when vd vq from register
221  * @param [in] base QEO base address
222  * @param [in] vd_val vd value
223  * @param [in] vq_val vq value
224  */
qeo_wave_config_vd_vq_value(QEOV2_Type * base,int32_t vd_val,int32_t vq_val)225 static inline void qeo_wave_config_vd_vq_value(QEOV2_Type *base, int32_t vd_val, int32_t vq_val)
226 {
227     base->WAVE.VD_INJECT = QEOV2_WAVE_VD_INJECT_VD_VAL_SET(vd_val);
228     base->WAVE.VQ_INJECT = QEOV2_WAVE_VQ_INJECT_VQ_VAL_SET(vq_val);
229 }
230 
231 /**
232  * @brief QEO load vd vq inject value when vd vq from register
233  * @param [in] base QEO base address
234  */
qeo_wave_load_vd_vq(QEOV2_Type * base)235 static inline void qeo_wave_load_vd_vq(QEOV2_Type *base)
236 {
237     base->WAVE.VD_VQ_LOAD = QEOV2_WAVE_VD_VQ_LOAD_LOAD_MASK;
238 }
239 
240 /**
241  * @brief QEO enable amplitude for wave mode
242  * @param [in] base QEO base address
243  * @param [in] index wave index(0/1/2)
244  * @param [in] amp amplitude value
245  */
qeo_wave_enable_amplitude(QEOV2_Type * base,uint8_t index,double amp)246 static inline void qeo_wave_enable_amplitude(QEOV2_Type *base, uint8_t index, double amp)
247 {
248     assert(amp > 0);
249     uint32_t val = (uint32_t)(amp * (1U << 12U));
250     base->WAVE.AMPLITUDE[index] = QEOV2_WAVE_AMPLITUDE_EN_SCAL_MASK | QEOV2_WAVE_AMPLITUDE_AMP_VAL_SET(val);
251 }
252 
253 /**
254  * @brief QEO disable amplitude for wave mode
255  * @param [in] base QEO base address
256  * @param [in] index wave index(0/1/2)
257  */
qeo_wave_disable_amplitude(QEOV2_Type * base,uint8_t index)258 static inline void qeo_wave_disable_amplitude(QEOV2_Type *base, uint8_t index)
259 {
260     base->WAVE.AMPLITUDE[index] &= ~QEOV2_WAVE_AMPLITUDE_EN_SCAL_MASK;
261 }
262 
263 /**
264  * @brief QEO set mid point shift for wave mode
265  * @param [in] base QEO base address
266  * @param [in] index wave index(0/1/2)
267  * @param [in] shift mid point shift value
268  */
qeo_wave_set_mid_point_shift(QEOV2_Type * base,uint8_t index,double shift)269 static inline void qeo_wave_set_mid_point_shift(QEOV2_Type *base, uint8_t index, double shift)
270 {
271     int32_t val = (int32_t)(shift * (1U << 27U));
272     base->WAVE.MID_POINT[index] = QEOV2_WAVE_MID_POINT_VAL_SET(val);
273 }
274 
275 /**
276  * @brief QEO set max limmit for wave mode
277  * @param [in] base QEO base address
278  * @param [in] index wave index(0/1/2)
279  * @param [in] limit0 limit0 value
280  * @param [in] limit1 limit1 value
281  */
qeo_wave_set_max_limit(QEOV2_Type * base,uint8_t index,uint32_t limit0,uint32_t limit1)282 static inline void qeo_wave_set_max_limit(QEOV2_Type *base, uint8_t index, uint32_t limit0, uint32_t limit1)
283 {
284     base->WAVE.LIMIT0[index].MAX_LEVEL0 = QEOV2_WAVE_LIMIT0_MAX_LEVEL0_LIMIT_LEVEL0_SET(limit0);
285     base->WAVE.LIMIT1[index].MAX_LEVEL1 = QEOV2_WAVE_LIMIT1_MAX_LEVEL1_LIMIT_LEVEL1_SET(limit1);
286 }
287 
288 /**
289  * @brief QEO set min limmit for wave mode
290  * @param [in] base QEO base address
291  * @param [in] index wave index(0/1/2)
292  * @param [in] limit0 limit0 value
293  * @param [in] limit1 limit1 value
294  */
qeo_wave_set_min_limit(QEOV2_Type * base,uint8_t index,uint32_t limit0,uint32_t limit1)295 static inline void qeo_wave_set_min_limit(QEOV2_Type *base, uint8_t index, uint32_t limit0, uint32_t limit1)
296 {
297     base->WAVE.LIMIT0[index].MIN_LEVEL0 = QEOV2_WAVE_LIMIT0_MIN_LEVEL0_LIMIT_LEVEL0_SET(limit0);
298     base->WAVE.LIMIT1[index].MIN_LEVEL1 = QEOV2_WAVE_LIMIT1_MIN_LEVEL1_LIMIT_LEVEL1_SET(limit1);
299 }
300 
301 /**
302  * @brief QEO set deadzone shift for wave mode
303  * @param [in] base QEO base address
304  * @param [in] index wave index(0/1/2)
305  * @param [in] shift deadzone shift value
306  */
qeo_wave_set_deadzone_shift(QEOV2_Type * base,uint8_t index,int32_t shift)307 static inline void qeo_wave_set_deadzone_shift(QEOV2_Type *base, uint8_t index, int32_t shift)
308 {
309     base->WAVE.DEADZONE_SHIFT[index] = QEOV2_WAVE_DEADZONE_SHIFT_VAL_SET(shift);
310 }
311 
312 /**
313  * @brief QEO wave set pwm cycle
314  *
315  * @note when cycle is 0, output value is 0 - 0xFFFFFFFF, others, output value is 0 - cycle
316  *
317  * @param [in] base QEO base address
318  * @param [in] cycle pwm period cycle
319  */
qeo_wave_set_pwm_cycle(QEOV2_Type * base,uint32_t cycle)320 static inline void qeo_wave_set_pwm_cycle(QEOV2_Type *base, uint32_t cycle)
321 {
322     base->WAVE.PWM_CYCLE = QEOV2_WAVE_PWM_CYCLE_VAL_SET(cycle);
323 }
324 
325 /**
326  * @brief QEO get wave output value
327  * @param [in] base QEO base address
328  * @param [in] index wave index(0/1/2)
329  * @retval wave output value
330  */
qeo_get_wave_output_val(QEOV2_Type * base,uint8_t index)331 static inline uint32_t qeo_get_wave_output_val(QEOV2_Type *base, uint8_t index)
332 {
333     if (index == 0) {
334         return QEOV2_DEBUG0_VALUE_DAC0_GET(base->DEBUG0);
335     } else if (index == 1) {
336         return QEOV2_DEBUG4_VALUE_DAC1_GET(base->DEBUG4);
337     } else if (index  == 2) {
338         return QEOV2_DEBUG5_VALUE_DAC2_GET(base->DEBUG5);
339     }
340     return 0;
341 }
342 
343 /**
344  * @brief QEO wave get defalut mode config
345  * @param [in] base QEO base address
346  * @param [in] config qeo_wave_mode_t
347  */
348 void qeo_wave_get_default_mode_config(QEOV2_Type *base, qeo_wave_mode_t *config);
349 
350 /**
351  * @brief QEO wave config mode
352  * @param [in] base QEO base address
353  * @param [in] config qeo_wave_mode_t
354  */
355 void qeo_wave_config_mode(QEOV2_Type *base, qeo_wave_mode_t *config);
356 
357 /* ABZ API */
358 /**
359  * @brief QEO set resolution lines for ABZ mode
360  * @param [in] base QEO base address
361  * @param [in] lines resolution lines
362  */
qeo_abz_set_resolution_lines(QEOV2_Type * base,uint32_t lines)363 static inline void qeo_abz_set_resolution_lines(QEOV2_Type *base, uint32_t lines)
364 {
365     base->ABZ.RESOLUTION = QEOV2_ABZ_RESOLUTION_LINES_SET(lines);
366 }
367 
368 /**
369  * @brief QEO set phase shift for three phase output mode
370  * @param [in] base QEO base address
371  * @param [in] index ABZ index(0/1/2)
372  * @param [in] angle left shift angle
373  */
qeo_abz_set_phase_shift(QEOV2_Type * base,uint8_t index,double angle)374 static inline void qeo_abz_set_phase_shift(QEOV2_Type *base, uint8_t index, double angle)
375 {
376     assert((angle >= 0) && (angle <= 360));
377     uint32_t val = (uint32_t)(angle * 0x100000000U / 360);
378     base->ABZ.PHASE_SHIFT[index] = QEOV2_ABZ_PHASE_SHIFT_VAL_SET(val);
379 }
380 
381 /**
382  * @brief QEO set offset for output signal in ABZ mode
383  * @param [in] base QEO base address
384  * @param [in] physical_angle physical angle
385  */
qeo_abz_set_offset(QEOV2_Type * base,double physical_angle)386 static inline void qeo_abz_set_offset(QEOV2_Type *base, double physical_angle)
387 {
388     assert((physical_angle >= 0) && (physical_angle <= 360));
389     uint32_t val = (uint32_t)(physical_angle * 0x100000000U / 360);
390     base->ABZ.OVERALL_OFFSET = QEOV2_ABZ_OVERALL_OFFSET_VAL_SET(val);
391 }
392 
393 /**
394  * @brief QEO set max frequency for ABZ mode
395  * @param [in] base QEO base address
396  * @param [in] src_freq QEO(MOTO system) frequency
397  * @param [in] freq abz signal frequency (A pulse frequency)
398  * @retval status_success or status_invalid_argument
399  */
400 hpm_stat_t qeo_abz_set_max_frequency(QEOV2_Type *base, uint32_t src_freq, uint32_t freq);
401 
402 /**
403  * @brief QEO set wdog frequency for ABZ mode
404  * @param [in] base QEO base address
405  * @param [in] src_freq QEO(MOTO system) frequency
406  * @param [in] freq wdog frequency
407  * @retval status_success or status_invalid_argument
408  */
409 hpm_stat_t qeo_abz_set_wdog_frequency(QEOV2_Type *base, uint32_t src_freq, uint32_t freq);
410 
411 /**
412  * @brief QEO disable wdog for ABZ mode
413  * @param [in] base QEO base address
414  */
qeo_abz_disable_wdog(QEOV2_Type * base)415 static inline void qeo_abz_disable_wdog(QEOV2_Type *base)
416 {
417     base->ABZ.MODE &= ~QEOV2_ABZ_MODE_EN_WDOG_MASK;
418 }
419 
420 /**
421  * @brief QEO config reverse edge for ABZ mode
422  * @param [in] base QEO base address
423  * @param [in] speed_pulse_negedge true for reverse edge point speed pulse's negedge
424  * false for reverse edge point between speed pulse's posedge and negedge, min period dedicated by the num line_width
425  *
426  * @note take effect when ABZ work on qeo_abz_output_pulse_revise mode
427  */
qeo_abz_config_reverse_edge(QEOV2_Type * base,bool speed_pulse_negedge)428 static inline void qeo_abz_config_reverse_edge(QEOV2_Type *base, bool speed_pulse_negedge)
429 {
430     if (speed_pulse_negedge) {
431         base->ABZ.MODE |= QEOV2_ABZ_MODE_REVERSE_EDGE_TYPE_MASK;
432     } else {
433         base->ABZ.MODE &= ~QEOV2_ABZ_MODE_REVERSE_EDGE_TYPE_MASK;
434     }
435 }
436 
437 /**
438  * @brief QEO ABZ get default mode config
439  * @param [in] base QEO base address
440  * @param [in] config qeo_abz_mode_t
441  */
442 void qeo_abz_get_default_mode_config(QEOV2_Type *base, qeo_abz_mode_t *config);
443 
444 /**
445  * @brief QEO ABZ config mode
446  * @param [in] base QEO base address
447  * @param [in] config qeo_abz_mode_t
448  */
449 void qeo_abz_config_mode(QEOV2_Type *base, qeo_abz_mode_t *config);
450 
451 /**
452  * @brief QEO ABZ mode enable output
453  * @param [in] base QEO base address
454  */
qeo_abz_enable_output(QEOV2_Type * base)455 static inline void qeo_abz_enable_output(QEOV2_Type *base)
456 {
457     base->ABZ.MODE |= QEOV2_ABZ_MODE_ABZ_OUTPUT_ENABLE_MASK;
458 }
459 
460 /**
461  * @brief QEO ABZ mode disable output
462  * @param [in] base QEO base address
463  */
qeo_abz_disable_output(QEOV2_Type * base)464 static inline void qeo_abz_disable_output(QEOV2_Type *base)
465 {
466     base->ABZ.MODE &= ~QEOV2_ABZ_MODE_ABZ_OUTPUT_ENABLE_MASK;
467 }
468 
469 /**
470  * @brief QEO ABZ mode enable and configure position sync mode
471  * @param [in] base QEO base address
472  * @param [in] sync_identical_pos true: sync identical posistion; false: sync step of position
473  */
qeo_abz_enable_position_sync(QEOV2_Type * base,bool sync_identical_pos)474 static inline void qeo_abz_enable_position_sync(QEOV2_Type *base, bool sync_identical_pos)
475 {
476     if (sync_identical_pos) {
477         base->ABZ.MODE |= QEOV2_ABZ_MODE_POSITION_SYNC_MODE_MASK;
478     } else {
479         base->ABZ.MODE &= ~QEOV2_ABZ_MODE_POSITION_SYNC_MODE_MASK;
480     }
481 
482     base->ABZ.POSTION_SYNC = QEOV2_ABZ_POSTION_SYNC_POSTION_MASK;
483 }
484 
485 /**
486  * @brief QEO ABZ mode get default zero pulse output mode
487  * @param [in] base QEO base address
488  * @param [out] mode qeo_z_output_mode_t
489  */
490 void qeo_abz_get_default_z_output_mode(QEOV2_Type *base, qeo_z_output_mode_t *mode);
491 
492 /**
493  * @brief QEO ABZ mode configure zero pulse output mode
494  * @param [in] base QEO base address
495  * @param [in] mode qeo_z_output_mode_t
496  */
497 void qeo_abz_config_z_output_mode(QEOV2_Type *base, qeo_z_output_mode_t *mode);
498 
499 /* PWM API */
500 /**
501  * @brief QEO set resolution lines for PWM mode
502  * @param [in] base QEO base address
503  * @param [in] lines resolution lines
504  */
qeo_pwm_set_resolution_lines(QEOV2_Type * base,uint32_t lines)505 static inline void qeo_pwm_set_resolution_lines(QEOV2_Type *base, uint32_t lines)
506 {
507     base->PWM.RESOLUTION = QEOV2_PWM_RESOLUTION_LINES_SET(lines);
508 }
509 
510 /**
511  * @brief QEO set phase shift for PWM mode
512  * @param [in] base QEO base address
513  * @param [in] index PWM index(0/1/2/3)
514  * @param [in] angle left shift angle
515  */
qeo_pwm_set_phase_shift(QEOV2_Type * base,uint8_t index,double angle)516 static inline void qeo_pwm_set_phase_shift(QEOV2_Type *base, uint8_t index, double angle)
517 {
518     assert((angle >= 0) && (angle <= 360));
519     uint32_t val = (uint32_t)(angle * 0x1000010000U / 360);
520     base->PWM.PHASE_SHIFT[index] = QEOV2_PWM_PHASE_SHIFT_VAL_SET(val);
521 }
522 
523 /**
524  * @brief QEO PWM mode enable output
525  * @param [in] base QEO base address
526  */
qeo_pwm_enable_output(QEOV2_Type * base)527 static inline void qeo_pwm_enable_output(QEOV2_Type *base)
528 {
529     base->PWM.MODE |= QEOV2_PWM_MODE_ENABLE_PWM_MASK;
530 }
531 
532 /**
533  * @brief QEO PWM mode disable output
534  * @param [in] base QEO base address
535  */
qeo_pwm_disable_output(QEOV2_Type * base)536 static inline void qeo_pwm_disable_output(QEOV2_Type *base)
537 {
538     base->PWM.MODE &= ~QEOV2_PWM_MODE_ENABLE_PWM_MASK;
539 }
540 
541 /**
542  * @brief QEO PWM check if it is triggered by hardware to enter safety mode
543  *
544  * @note This bit is only valid if the hardware trigger source has not been cleared
545  *
546  * @param [in] base QEO base address
547  * @retval true or false
548  */
qeo_pwm_check_hardware_trig_safety(QEOV2_Type * base)549 static inline bool qeo_pwm_check_hardware_trig_safety(QEOV2_Type *base)
550 {
551     return ((base->STATUS & QEOV2_STATUS_PWM_SAFETY_MASK) != 0) ? true : false;
552 }
553 
554 /**
555  * @brief QEO PWM select phase table
556  * @param [in] base QEO base address
557  * @param [in] positive true for using positive phase table, false for using negative phase table
558  */
qeo_pwm_select_phase_table(QEOV2_Type * base,bool positive)559 static inline void qeo_pwm_select_phase_table(QEOV2_Type *base, bool positive)
560 {
561     if (positive) {
562         base->PWM.MODE &= ~QEOV2_PWM_MODE_REVISE_UP_DN_MASK;
563     } else {
564         base->PWM.MODE |= QEOV2_PWM_MODE_REVISE_UP_DN_MASK;
565     }
566 }
567 
568 /**
569  * @brief QEO PWM enter safety mode by software
570  *
571  * @note call qeo_pwm_software_exit_safety to exit safety mode
572  *
573  * @param [in] base QEO base address
574  */
qeo_pwm_software_enter_safety(QEOV2_Type * base)575 static inline void qeo_pwm_software_enter_safety(QEOV2_Type *base)
576 {
577     base->PWM.MODE |= QEOV2_PWM_MODE_PWM_ENTER_SAFETY_MODE_MASK;
578 }
579 
580 /**
581  * @brief QEO PWM exit safety mode by software
582  * @param [in] base QEO base address
583  */
qeo_pwm_software_exit_safety(QEOV2_Type * base)584 static inline void qeo_pwm_software_exit_safety(QEOV2_Type *base)
585 {
586     base->PWM.MODE &= ~QEOV2_PWM_MODE_PWM_ENTER_SAFETY_MODE_MASK;
587 }
588 
589 /**
590  * @brief QEO PWM get default mode config
591  * @param [in] base QEO base address
592  * @param [in] config qeo_pwm_mode_t
593  */
594 void qeo_pwm_get_default_mode_config(QEOV2_Type *base, qeo_pwm_mode_t *config);
595 
596 /**
597  * @brief QEO PWM config mode
598  * @param [in] base QEO base address
599  * @param [in] config qeo_pwm_mode_t
600  */
601 void qeo_pwm_config_mode(QEOV2_Type *base, qeo_pwm_mode_t *config);
602 
603 /**
604  * @brief QEO PWM get default safety table
605  * @param [in] base QEO base address
606  * @param [in] table qeo_pwm_safety_output_table_t
607  */
608 void qeo_pwm_get_default_safety_table_config(QEOV2_Type *base, qeo_pwm_safety_output_table_t *table);
609 
610 /**
611  * @brief QEO PWM get default phase table
612  * @param [in] base QEO base address
613  * @param [in] table qeo_pwm_phase_output_table_t
614  */
615 void qeo_pwm_get_default_phase_table_config(QEOV2_Type *base, qeo_pwm_phase_output_table_t *table);
616 
617 /**
618  * @brief QEO PWM config safety table
619  * @param [in] base QEO base address
620  * @param [in] table qeo_pwm_safety_output_table_t
621  */
622 void qeo_pwm_config_safety_table(QEOV2_Type *base, qeo_pwm_safety_output_table_t *table);
623 
624 /**
625  * @brief QEO PWM onfig phase table
626  * @param [in] base QEO base address
627  * @param [in] index phase table index
628  * @param [in] table qeo_pwm_phase_output_table_t
629  */
630 void qeo_pwm_config_phase_table(QEOV2_Type *base, uint8_t index, qeo_pwm_phase_output_table_t *table);
631 
632 /**
633  * @brief QEO enable software position inject
634  * @param [in] base QEO base address
635  */
qeo_enable_software_position_inject(QEOV2_Type * base)636 static inline void qeo_enable_software_position_inject(QEOV2_Type *base)
637 {
638     base->POSTION_SEL |= QEOV2_POSTION_SEL_POSTION_SEL_MASK;
639 }
640 
641 /**
642  * @brief QEO software inject position
643  * @param [in] base QEO base address
644  * @param [in] position position value
645  */
qeo_software_position_inject(QEOV2_Type * base,uint32_t position)646 static inline void qeo_software_position_inject(QEOV2_Type *base, uint32_t position)
647 {
648     base->POSTION_SOFTWARE = QEOV2_POSTION_SOFTWARE_POSTION_SOFTWAVE_SET(position);
649 }
650 
651 /**
652  * @brief QEO disable software position inject, QEO will using position from hardware
653  * @param [in] base QEO base address
654  */
qeo_disable_software_position_inject(QEOV2_Type * base)655 static inline void qeo_disable_software_position_inject(QEOV2_Type *base)
656 {
657     base->POSTION_SEL &= ~QEOV2_POSTION_SEL_POSTION_SEL_MASK;
658 }
659 
660 /**
661  * @brief QEO check calculate finish status
662  * @param [in] base QEO base address
663  * @retval true or false
664  */
qeo_check_calculate_finish(QEOV2_Type * base)665 static inline bool qeo_check_calculate_finish(QEOV2_Type *base)
666 {
667     return (QEOV2_DEBUG1_QEO_FINISH_GET(base->DEBUG1) != 0) ? true : false;
668 }
669 
670 #ifdef __cplusplus
671 }
672 #endif
673 /**
674  * @}
675  */
676 #endif /* HPM_QEOV2_DRV_H */
677