16 #include "./hal/hal_power.h" 35 QDEC_ERR_INVALID_PARAM = -1,
43 typedef struct qdec_init {
44 uint16_t report_intvl;
45 uint16_t sample_intvl;
49 void(*callback)(
void*, int, uint32_t, int);
51 typedef struct qdec_cfg {
65 typedef struct qdec_idx_cfg {
71 static INLINE uint32_t qdec_intr_status(
void)
73 return RD_WORD(QUADDEC_REG_INTERRUPT_STATUS);
75 static INLINE uint32_t qdec_intr_mask_status(
void)
77 return RD_WORD(QUADDEC_REG_INTERRUPT_MASK_STATUS);
80 static INLINE
void qdec_intr_clear(uint32_t val)
82 WR_WORD(QUADDEC_REG_INTERRUPT_CLEAR, val);
84 static INLINE
void qdec_intr_set(uint32_t val)
86 WR_WORD(QUADDEC_REG_INTERRUPT_SET, val);
88 static INLINE
void qdec_intr_mask_clear(uint32_t val)
90 WR_WORD(QUADDEC_REG_INTERRUPT_MASK_CLEAR, val);
92 static INLINE
void qdec_intr_mask_set(uint32_t val)
94 WR_WORD(QUADDEC_REG_INTERRUPT_MASK_SET, val);
105 static INLINE
void qdec_sample_interval(uint16_t intv)
107 uint32_t reg = RD_WORD(QUADDEC_REG_INTERVAL_SETTING);
108 reg &= ~QUADDEC_REG_INTERVAL_SETTING_CTL_SAMPLE_INTERVAL_M1;
110 WR_WORD(QUADDEC_REG_INTERVAL_SETTING,reg);
115 static INLINE
void qdec_report_interval(uint32_t intv)
117 WR_WORD(QUADDEC_REG_REPORT_INTERVAL,intv);
121 static INLINE
void qdec_led_inertval(uint8_t
id, uint32_t intv)
123 WR_WORD(QUADDEC_REG_INTERVAL_LED_SETTING_M0 +
id*4,intv);
126 static INLINE
void qdec_counter_lmt(uint32_t lmt)
129 WR_WORD(QUADDEC_REG_COUNTER_LMT,lmt);
132 static INLINE
void qdec_counter_init(uint32_t init)
134 WR_WORD(QUADDEC_REG_COUNTER_INIT,init);
137 static INLINE
void qdec_counter_clear(uint32_t val)
139 WR_WORD(QUADDEC_REG_COUNTER_CLEAR,val);
143 static INLINE uint32_t qdec_curr_sample(
int id)
145 return RD_WORD(QUADDEC_REG_SAMPLE_COUNTER0 +
id*4)&0xff;
149 static INLINE uint32_t qdec_report_sample(
int id)
151 return (RD_WORD(QUADDEC_REG_SAMPLE_COUNTER0 +
id*4)>>16)&0xff;
154 static INLINE uint32_t qdec_get_db_counter(
int id)
156 return RD_WORD(QUADDEC_REG_DB_COUNTER_AND_CURRENT_INPUT0 +
id*4);
159 static INLINE
void qdec_idx_ctrl(uint32_t val)
161 WR_WORD(QUADDEC_REG_INDEX_CTRL, val);
164 static INLINE uint32_t qdec_get_index_counter(
int id)
166 return RD_WORD(QUADDEC_REG_INDEX_COUNTER0 +
id*4);
169 static INLINE uint32_t qdec_get_misc_ctrl(
void)
171 return RD_WORD(QUADDEC_REG_MISC_CTRL);
174 static INLINE
void qdec_set_misc_ctrl(uint32_t misc)
176 WR_WORD(QUADDEC_REG_MISC_CTRL, misc);
179 static INLINE
void qdec_set_pin_a(
int id, uint32_t a)
181 uint32_t reg = RD_WORD(QUADDEC_REG_INPUT_PIN_ASSIGNMENT0 +
id*4);
182 reg &= ~QUADDEC_REG_INPUT_PIN_ASSIGNMENT0_CTL_PIN_A_SEL0;
184 WR_WORD(QUADDEC_REG_INPUT_PIN_ASSIGNMENT0 +
id*4, reg);
186 static INLINE
void qdec_set_pin_b(
int id, uint32_t b)
188 uint32_t reg = RD_WORD(QUADDEC_REG_INPUT_PIN_ASSIGNMENT0 +
id*4);
189 reg &= ~QUADDEC_REG_INPUT_PIN_ASSIGNMENT0_CTL_PIN_B_SEL0;
191 WR_WORD(QUADDEC_REG_INPUT_PIN_ASSIGNMENT0 +
id*4, reg);
193 static INLINE
void qdec_set_pin_idx(
int id, uint32_t idx)
195 uint32_t reg = RD_WORD(QUADDEC_REG_INPUT_PIN_ASSIGNMENT0 +
id*4);
196 reg &= ~QUADDEC_REG_INPUT_PIN_ASSIGNMENT0_CTL_PIN_IDX_SEL0;
198 WR_WORD(QUADDEC_REG_INPUT_PIN_ASSIGNMENT0 +
id*4, reg);
203 static INLINE
void qdec_enable(
int id)
205 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
207 reg |= 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_QUADDEC_ENABLE_SHIFT);
208 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
211 static INLINE
void qdec_disable(
int id)
213 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
215 uint32_t mask = 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_QUADDEC_ENABLE_SHIFT);
217 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
220 static INLINE
void qdec_led_enable(
int id)
222 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
224 reg |= 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_LED_EN_SHIFT);
225 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
228 static INLINE
void qdec_led_disable(
int id)
230 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
232 uint32_t mask = 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_LED_EN_SHIFT);
234 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
237 static INLINE
void qdec_led_pol(
int id, uint8_t pol)
239 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
241 reg &= ~(0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_LED_POLARITY_SHIFT));
242 reg |= (pol&0x1UL)<<(
id+QUADDEC_REG_MISC_CTRL_CTL_LED_POLARITY_SHIFT);
243 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
245 static INLINE
void qdec_idx_enable(
int id)
247 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
249 reg |= 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_INDEX_EN_SHIFT);
250 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
253 static INLINE
void qdec_idx_disable(
int id)
255 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
257 uint32_t mask = 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_INDEX_EN_SHIFT);
259 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
262 static INLINE
void qdec_idx_pol(
int id, uint8_t pol)
264 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
266 reg &= ~(0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_INDEX_POLARITY_SHIFT));
267 reg |= (pol&0x1UL)<<(
id+QUADDEC_REG_MISC_CTRL_CTL_INDEX_POLARITY_SHIFT);
268 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
270 static INLINE
void qdec_debounce_enable(
int id)
272 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
274 reg |= 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_DEBOUNCE_EN_SHIFT);
275 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
278 static INLINE
void qdec_debounce_disable(
int id)
280 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
282 uint32_t mask = 0x1UL<<(
id+QUADDEC_REG_MISC_CTRL_CTL_DEBOUNCE_EN_SHIFT);
284 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
287 static INLINE
void qdec_clk_num_in_us(uint8_t num)
289 uint32_t reg = RD_WORD(QUADDEC_REG_MISC_CTRL);
290 reg &= ~QUADDEC_REG_MISC_CTRL_CTL_NUM_CLK_IN_US_M1;
291 reg |= (num&QUADDEC_REG_MISC_CTRL_CTL_NUM_CLK_IN_US_M1_MASK)<<QUADDEC_REG_MISC_CTRL_CTL_NUM_CLK_IN_US_M1_SHIFT;
292 WR_WORD(QUADDEC_REG_MISC_CTRL, reg);
void hal_qdec_close(void)
Close qdec.
Max ID.
Definition: hal_qdec.h:30
int hal_qdec_disable(int id)
Disable qdec.
int hal_qdec_cfg(int id, qdec_cfg_t *cfg)
Config qdec.
ID 1.
Definition: hal_qdec.h:28
ID 2.
Definition: hal_qdec.h:29
int hal_qdec_open(qdec_init_t *init)
Open qdec device.
int hal_qdec_idx_cfg(qdec_idx_cfg_t *cfg)
Config qdec index signal.
ID 0.
Definition: hal_qdec.h:27
int hal_qdec_enable(int id)
Enable qdec.
qdec_id_t
Mouse device ID.
Definition: hal_qdec.h:26