implemented the keyboard interface

This commit is contained in:
ayabusa 2024-04-05 18:15:37 +02:00
parent 24773004b4
commit 1ef815d5a8
10 changed files with 40 additions and 26 deletions

View File

@ -12,7 +12,7 @@ This is a bare metal os attempt on the numworks n0110
### Zeta bare minimum ### Zeta bare minimum
- [x] Working thing - [x] Working thing
- [x] Led interface - [x] Led interface
- [ ] Keyboard interface - [x] Keyboard interface
- [ ] Set clock and all - [ ] Set clock and all
- [ ] adapt ms_wait() and us_wait() - [ ] adapt ms_wait() and us_wait()
- [ ] Screen interface - [ ] Screen interface

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -41,6 +41,7 @@
const uint8_t number_of_rows = 9; const uint8_t number_of_rows = 9;
const uint8_t number_of_columns = 6; const uint8_t number_of_columns = 6;
const char row_list[9] = {'B', 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I'};
void keyboard_init(){ void keyboard_init(){
for (int i = 0; i < number_of_rows; i++){ for (int i = 0; i < number_of_rows; i++){
@ -57,12 +58,6 @@ void keyboard_init(){
} }
} }
bool keyboard_scan(){
set_output_pin(GPIO_A, 6, true);
bool key_state = read_input_pin(GPIO_C, 3);
return key_state;
// A LOT TODO
}
void activate_row(uint8_t row_nb){ void activate_row(uint8_t row_nb){
// set all row to 0 and then reenable selected row // set all row to 0 and then reenable selected row
@ -72,3 +67,21 @@ void activate_row(uint8_t row_nb){
set_output_pin(GPIO_A, row_nb, false); set_output_pin(GPIO_A, row_nb, false);
us_wait(100); us_wait(100);
} }
struct button* keyboard_scan(){
static struct button result_button_list[54] = {};
uint8_t i = 0;
for(int r = 0; r < number_of_rows; r++){
activate_row(r);
for(int c = 0; c < number_of_columns; c++){
bool key_state = read_input_pin(GPIO_C, c);
result_button_list[i].row = row_list[r];
result_button_list[i].column = c + 1;
result_button_list[i].state = key_state;
i++;
}
}
return result_button_list;
}

View File

@ -7,21 +7,16 @@
#ifndef KEYBOARD_H #ifndef KEYBOARD_H
#define KEYBOARD_H #define KEYBOARD_H
enum PIN_ROW {
A = 1,
B = 0,
C = 2,
D = 3,
E = 4,
F = 5,
G = 6,
H = 7,
I = 8
};
#include "gpio_helper.h" #include "gpio_helper.h"
struct button{
uint8_t column;
char row;
bool state;
};
void keyboard_init(); void keyboard_init();
bool keyboard_scan(); struct button* keyboard_scan();
#endif #endif

View File

@ -8,11 +8,17 @@ void main_entry(){
set_led_green(true); set_led_green(true);
while (1) while (1)
{ {
/*if(keyboard_scan()){ struct button * keyboard_state = keyboard_scan();
set_led_green(true); for(int i =0; i < 54; i++){
}else{ if(keyboard_state[i].column == 4 && keyboard_state[i].row == 'H'){
set_led_green(false); if(keyboard_state[i].state){
}*/ set_led_green(true);
}else{
set_led_green(false);
}
break;
}
}
} }
} }