15 #include "./hal/hal_global.h" 23 #define KB_MAX_CURR_KEY 6 25 #define KB_INTR_SCAN_DONE 0x1 26 #define KB_INTR_UPDATE 0x2 27 #define KB_INTR_TOO_MANY_KEYS 0x4 28 #define KB_INTR_PAUSE 0x8 30 #define KB_MAX_ROW_NUM 14 31 #define KB_MAX_COL_NUM 14 35 KB_ERR_INVALID_PARAM = -1,
58 void (*cb)(
void* arg, uint8_t row, uint8_t col,
int event);
67 static __inline
void kb_intr_mask_clear(uint32_t val)
69 WR_WORD(KEYBOARD_REG_INTR_MASK_CLEAR, val);
71 static __inline
void kb_intr_clear(uint32_t val)
73 WR_WORD(KEYBOARD_REG_INTR_CLEAR, val);
75 static __inline
void kb_intr_set(uint32_t val)
77 WR_WORD(KEYBOARD_REG_INTR_SET, val);
79 static __inline
void kb_intr_mask_set(uint32_t val)
81 WR_WORD(KEYBOARD_REG_INTR_MASK_SET, val);
84 static __inline
void kb_enable(
void)
86 uint32_t reg = RD_WORD(KEYBOARD_REG_MISC_CTRL);
87 reg |= KEYBOARD_REG_MISC_CTRL_CTL_ENABLE;
88 WR_WORD(KEYBOARD_REG_MISC_CTRL, reg);
90 static __inline
void kb_disable(
void)
92 uint32_t reg = RD_WORD(KEYBOARD_REG_MISC_CTRL);
93 reg &= ~KEYBOARD_REG_MISC_CTRL_CTL_ENABLE;
94 WR_WORD(KEYBOARD_REG_MISC_CTRL, reg);
96 static __inline
void kb_wait_key(
int wait)
98 uint32_t reg = RD_WORD(KEYBOARD_REG_MISC_CTRL);
101 reg |= KEYBOARD_REG_MISC_CTRL_CTL_WAIT_KEY_PRESS_BETWEEN_SCAN;
103 reg &= ~KEYBOARD_REG_MISC_CTRL_CTL_WAIT_KEY_PRESS_BETWEEN_SCAN;
105 WR_WORD(KEYBOARD_REG_MISC_CTRL, reg);
107 static __inline
void kb_set_num_col(uint32_t val)
109 uint32_t reg = RD_WORD(KEYBOARD_REG_MISC_CTRL);
110 reg &= ~KEYBOARD_REG_MISC_CTRL_CTL_NUM_COL;
111 reg |= (val&KEYBOARD_REG_MISC_CTRL_CTL_NUM_COL_MASK)<<KEYBOARD_REG_MISC_CTRL_CTL_NUM_COL_SHIFT;
112 WR_WORD(KEYBOARD_REG_MISC_CTRL, reg);
114 static __inline
void kb_set_num_row(uint32_t val)
116 uint32_t reg = RD_WORD(KEYBOARD_REG_MISC_CTRL);
117 reg &= ~KEYBOARD_REG_MISC_CTRL_CTL_NUM_ROW;
118 reg |= (val&KEYBOARD_REG_MISC_CTRL_CTL_NUM_ROW_MASK)<<KEYBOARD_REG_MISC_CTRL_CTL_NUM_ROW_SHIFT;
119 WR_WORD(KEYBOARD_REG_MISC_CTRL, reg);
121 static __inline
void kb_set_max_num_key(uint32_t val)
123 uint32_t reg = RD_WORD(KEYBOARD_REG_MISC_CTRL);
124 reg &= ~KEYBOARD_REG_MISC_CTRL_CTL_MAX_NUM_KEY_PRESSED;
125 reg |= (val&KEYBOARD_REG_MISC_CTRL_CTL_MAX_NUM_KEY_PRESSED_MASK)<<KEYBOARD_REG_MISC_CTRL_CTL_MAX_NUM_KEY_PRESSED_SHIFT;
126 WR_WORD(KEYBOARD_REG_MISC_CTRL, reg);
128 static __inline
void kb_col_output_inv(
int val)
130 uint32_t reg = RD_WORD(KEYBOARD_REG_MISC_CTRL);
133 reg |= KEYBOARD_REG_MISC_CTRL_CTL_COL_OUTPUT_INV;
135 reg &= ~KEYBOARD_REG_MISC_CTRL_CTL_COL_OUTPUT_INV;
137 WR_WORD(KEYBOARD_REG_MISC_CTRL, reg);
141 static __inline
void kb_reset(
void)
143 uint32_t val = RD_WORD(GLOBAL_REG_RESET_CTRL_1);
145 WR_WORD(GLOBAL_REG_RESET_CTRL_1, val & (~0x2));
147 WR_WORD(GLOBAL_REG_RESET_CTRL_1, val | 0x2);
150 static __inline
void kb_set_col_mask(uint32_t val)
152 uint32_t reg = RD_WORD(KEYBOARD_REG_COL_ROW_MASK);
153 reg &= ~KEYBOARD_REG_COL_ROW_MASK_CTL_KEYBOARD_COL_MASK;
154 reg |= (val&KEYBOARD_REG_COL_ROW_MASK_CTL_KEYBOARD_COL_MASK_MASK)<<KEYBOARD_REG_COL_ROW_MASK_CTL_KEYBOARD_COL_MASK_SHIFT;
155 WR_WORD(KEYBOARD_REG_COL_ROW_MASK, reg);
157 static __inline
void kb_set_row_mask(uint32_t val)
159 uint32_t reg = RD_WORD(KEYBOARD_REG_COL_ROW_MASK);
160 reg &= ~KEYBOARD_REG_COL_ROW_MASK_CTL_KEYBOARD_ROW_MASK;
161 reg |= (val&KEYBOARD_REG_COL_ROW_MASK_CTL_KEYBOARD_ROW_MASK_MASK)<<KEYBOARD_REG_COL_ROW_MASK_CTL_KEYBOARD_ROW_MASK_SHIFT;
162 WR_WORD(KEYBOARD_REG_COL_ROW_MASK, reg);
164 static __inline
void kb_set_scan_interval(uint32_t val)
166 WR_WORD(KEYBOARD_REG_SCAN_INTERVAL, val&KEYBOARD_REG_SCAN_INTERVAL_CTL_SCAN_INTERVAL_MASK);
168 static __inline
void kb_set_us_cnt_lmt(uint32_t val)
170 uint32_t reg = RD_WORD(KEYBOARD_REG_SCAN_TIMING_CONTROL);
171 reg &= ~KEYBOARD_REG_SCAN_TIMING_CONTROL_CTL_US_CNT_LMT;
172 reg |= (val&KEYBOARD_REG_SCAN_TIMING_CONTROL_CTL_US_CNT_LMT_MASK)<<KEYBOARD_REG_SCAN_TIMING_CONTROL_CTL_US_CNT_LMT_SHIFT;
173 WR_WORD(KEYBOARD_REG_SCAN_TIMING_CONTROL, reg);
176 static __inline
void kb_set_deglitch(uint32_t val)
178 uint32_t reg = RD_WORD(KEYBOARD_REG_SCAN_TIMING_CONTROL);
179 reg &= ~KEYBOARD_REG_SCAN_TIMING_CONTROL_CTL_DEGLITCH_CNT_LMT;
180 reg |= (val&KEYBOARD_REG_SCAN_TIMING_CONTROL_CTL_DEGLITCH_CNT_LMT_MASK)<<KEYBOARD_REG_SCAN_TIMING_CONTROL_CTL_DEGLITCH_CNT_LMT_SHIFT;
181 WR_WORD(KEYBOARD_REG_SCAN_TIMING_CONTROL, reg);
184 static __inline
void kb_manual_start(
int en)
186 uint32_t reg = RD_WORD(KEYBOARD_REG_MANUAL_START);
188 reg |= KEYBOARD_REG_MANUAL_START_CTL_MANUAL_START;
190 reg &= ~KEYBOARD_REG_MANUAL_START_CTL_MANUAL_START;
192 WR_WORD(KEYBOARD_REG_MANUAL_START, reg);
194 static __inline
void kb_manual_set_pre_key(
int en)
196 uint32_t reg = RD_WORD(KEYBOARD_REG_MANUAL_START);
198 reg |= KEYBOARD_REG_MANUAL_START_CTL_MANUAL_SET_PREV_KEY;
200 reg &= ~KEYBOARD_REG_MANUAL_START_CTL_MANUAL_SET_PREV_KEY;
202 WR_WORD(KEYBOARD_REG_MANUAL_START, reg);
204 static __inline
void kb_manual_pre_num_key(uint8_t num)
206 uint32_t reg = RD_WORD(KEYBOARD_REG_MANUAL_START);
207 reg &= ~KEYBOARD_REG_MANUAL_START_CTL_MANUAL_PREV_NUM_KEY;
208 reg |= (num&KEYBOARD_REG_MANUAL_START_CTL_MANUAL_PREV_NUM_KEY_MASK)<<KEYBOARD_REG_MANUAL_START_CTL_MANUAL_PREV_NUM_KEY_SHIFT;
209 WR_WORD(KEYBOARD_REG_MANUAL_START, reg);
211 static __inline
void kb_manual_key_press03(uint32_t val)
213 WR_WORD(KEYBOARD_REG_MANUAL_KEY_PRESS_0TO3, val);
215 static __inline
void kb_manual_key_press45(uint32_t val)
217 WR_WORD(KEYBOARD_REG_MANUAL_KEY_PRESS_45, val);
219 static __inline uint32_t kb_get_curr_num(
void)
221 return RD_WORD(KEYBOARD_REG_NUM_KEY_PRESS)&KEYBOARD_REG_NUM_KEY_PRESS_STS_CURR_NUM_KEY;
223 static __inline uint32_t kb_get_pre_num(
void)
225 return (RD_WORD(KEYBOARD_REG_NUM_KEY_PRESS)&KEYBOARD_REG_NUM_KEY_PRESS_STS_PREV_NUM_KEY)>>KEYBOARD_REG_NUM_KEY_PRESS_STS_PREV_NUM_KEY_SHIFT;
227 static __inline
void kb_pin_mux_0(
int id, uint32_t mux)
229 uint32_t reg = RD_WORD(GLOBAL_REG_KEYBOARD_MUX_0);
230 reg &= ~(0x3<<(
id*2));
231 reg |= (mux&0x3)<<(
id*2);
232 WR_WORD(GLOBAL_REG_KEYBOARD_MUX_0, reg);
234 static __inline
void kb_pin_mux_1(
int id, uint32_t mux)
236 uint32_t reg = RD_WORD(GLOBAL_REG_KEYBOARD_MUX_1);
237 reg &= ~(0x3<<(
id*2));
238 reg |= (mux&0x3)<<(
id*2);
239 WR_WORD(GLOBAL_REG_KEYBOARD_MUX_1, reg);
247 int hal_kb_enable(
void);
254 int hal_kb_disable(
void);
262 int hal_kb_open(kb_init_t *init);
268 void hal_kb_close(
void);
275 int hal_kb_set_scan_interval(uint32_t interval);
282 int hal_kb_set_deglitch(uint32_t cnt);
void RAM_PM delay_us(uint32_t us)
Delay in tight loop.