diff --git a/.vscode/settings.json b/.vscode/settings.json index 02bb9b3..90879a8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,6 +21,7 @@ "led.h": "c", "stm32f730xx.h": "c", "keyboard.h": "c", - "gpio_helper.h": "c" + "gpio_helper.h": "c", + "stdint.h": "c" } } \ No newline at end of file diff --git a/numworks_port/README.md b/numworks_port/README.md index e3da20b..6957788 100644 --- a/numworks_port/README.md +++ b/numworks_port/README.md @@ -17,6 +17,9 @@ This is a bare metal os attempt on the numworks n0110 - [ ] adapt ms_wait() and us_wait() - [ ] Screen interface - [ ] UI toolkit + - [ ] set pixel - [ ] text display - [ ] fill rect - - [ ] image display \ No newline at end of file + - [ ] image display +- [ ] File system + - [ ] Plan what to do \ No newline at end of file diff --git a/numworks_port/build/Laplace/gpio_helper.o b/numworks_port/build/Laplace/gpio_helper.o index 3a0b959..d291bcf 100644 Binary files a/numworks_port/build/Laplace/gpio_helper.o and b/numworks_port/build/Laplace/gpio_helper.o differ diff --git a/numworks_port/build/Laplace/keyboard.o b/numworks_port/build/Laplace/keyboard.o index c52184b..84570ff 100644 Binary files a/numworks_port/build/Laplace/keyboard.o and b/numworks_port/build/Laplace/keyboard.o differ diff --git a/numworks_port/build/Laplace/laplace.o b/numworks_port/build/Laplace/laplace.o index ac29955..699b906 100644 Binary files a/numworks_port/build/Laplace/laplace.o and b/numworks_port/build/Laplace/laplace.o differ diff --git a/numworks_port/build/Laplace/led.o b/numworks_port/build/Laplace/led.o index 6284c55..0fcbf30 100644 Binary files a/numworks_port/build/Laplace/led.o and b/numworks_port/build/Laplace/led.o differ diff --git a/numworks_port/build/Laplace/time.o b/numworks_port/build/Laplace/time.o index 1c566c5..bc8f70a 100644 Binary files a/numworks_port/build/Laplace/time.o and b/numworks_port/build/Laplace/time.o differ diff --git a/numworks_port/build/main.bin b/numworks_port/build/main.bin index 632f485..e7aefdb 100755 Binary files a/numworks_port/build/main.bin and b/numworks_port/build/main.bin differ diff --git a/numworks_port/build/main.elf b/numworks_port/build/main.elf index e8a3275..3051e3e 100755 Binary files a/numworks_port/build/main.elf and b/numworks_port/build/main.elf differ diff --git a/numworks_port/build/main.o b/numworks_port/build/main.o index 1f8ae0c..1d3f27a 100644 Binary files a/numworks_port/build/main.o and b/numworks_port/build/main.o differ diff --git a/numworks_port/src/Laplace/gpio_helper.c b/numworks_port/src/Laplace/gpio_helper.c index d5ba4c2..7d844b9 100644 --- a/numworks_port/src/Laplace/gpio_helper.c +++ b/numworks_port/src/Laplace/gpio_helper.c @@ -6,6 +6,9 @@ uint8_t GPIOC_state = 0; uint8_t GPIOD_state = 0; uint8_t GPIOE_state = 0; +/* Set a pin High (true) or Low (false) ie: + set_output_pin(GPIO_B, 2, true); + this sets the pin B2 to high */ void set_output_pin(uint8_t gpio_x, uint8_t pin, bool state){ switch (gpio_x) { @@ -59,6 +62,9 @@ void set_output_pin(uint8_t gpio_x, uint8_t pin, bool state){ } } +/* Read the value of an input pin, it returns High (true) or Low (false) ie: + bool state = read_input_pin(GPIO_C, 3); + This stores the state of the pin C3 */ bool read_input_pin(uint8_t gpio_x, uint8_t pin){ // Invert the IDR register since '0' means 'pressed'. uint8_t idr_val = 0; @@ -87,6 +93,7 @@ bool read_input_pin(uint8_t gpio_x, uint8_t pin){ return idr_val & (1 << pin); } +/* Enable the specified GPIO */ void enable_gpio_x_rcc(uint8_t gpio_x){ switch (gpio_x) { diff --git a/numworks_port/src/Laplace/gpio_helper.h b/numworks_port/src/Laplace/gpio_helper.h index a09f88f..8f40c8e 100644 --- a/numworks_port/src/Laplace/gpio_helper.h +++ b/numworks_port/src/Laplace/gpio_helper.h @@ -16,8 +16,17 @@ #define GPIO_D 3 #define GPIO_E 4 +/* Set a pin High (true) or Low (false) ie: + set_output_pin(GPIO_B, 2, true); + this sets the pin B2 to high */ void set_output_pin(uint8_t gpio_x, uint8_t pin, bool state); + +/* Read the value of an input pin, it returns High (true) or Low (false) ie: + bool state = read_input_pin(GPIO_C, 3); + This stores the state of the pin C3 */ bool read_input_pin(uint8_t gpio_x, uint8_t pin); + +/* Enable the specified GPIO */ void enable_gpio_x_rcc(uint8_t gpio_x); #endif \ No newline at end of file diff --git a/numworks_port/src/Laplace/keyboard.c b/numworks_port/src/Laplace/keyboard.c index ced4e49..5d4563b 100644 --- a/numworks_port/src/Laplace/keyboard.c +++ b/numworks_port/src/Laplace/keyboard.c @@ -43,6 +43,8 @@ const uint8_t number_of_rows = 9; const uint8_t number_of_columns = 6; const char row_list[9] = {'B', 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I'}; +/* This should be called before accessing any other keyboard related feature + as it sets up all keyboard related peripherals */ void keyboard_init(){ for (int i = 0; i < number_of_rows; i++){ // setup rows (output open drain) @@ -58,7 +60,8 @@ void keyboard_init(){ } } - +/* This disable the all the row except for the specified one + It is usefull to test if a specific key is pressed */ void activate_row(uint8_t row_nb){ // set all row to 0 and then reenable selected row for(int i =0; i < number_of_rows; i++){ @@ -68,6 +71,8 @@ void activate_row(uint8_t row_nb){ us_wait(100); } +/* Scans the current state of the keyboard and returns an array of buttons struct + You can find the button struct definition in keyboard.h */ struct button* keyboard_scan(){ static struct button result_button_list[54] = {}; uint8_t i = 0; diff --git a/numworks_port/src/Laplace/keyboard.h b/numworks_port/src/Laplace/keyboard.h index a06b45b..35be241 100644 --- a/numworks_port/src/Laplace/keyboard.h +++ b/numworks_port/src/Laplace/keyboard.h @@ -10,13 +10,17 @@ #include "gpio_helper.h" struct button{ - uint8_t column; - char row; - bool state; + uint8_t column; // ie: 2 + char row; // ie: 'A' + bool state; // true is pressed and false released }; - +/* This should be called before accessing any other keyboard related feature + as it sets up all keyboard related peripherals */ void keyboard_init(); + +/* Scans the current state of the keyboard and returns an array of buttons struct + You can find the button struct definition in keyboard.h */ struct button* keyboard_scan(); #endif \ No newline at end of file diff --git a/numworks_port/src/Laplace/laplace.c b/numworks_port/src/Laplace/laplace.c index deb4ae3..03f9459 100644 --- a/numworks_port/src/Laplace/laplace.c +++ b/numworks_port/src/Laplace/laplace.c @@ -1,12 +1,13 @@ #include "laplace.h" +/* Initialize all needed peripherals, should be called early in your program */ void laplace_init(){ - // Enable the GPIO peripheral in RCC. + /* led init */ enable_gpio_x_rcc(GPIO_B); led_init(); - //col (in) - enable_gpio_x_rcc(GPIO_C); - //row (out) - enable_gpio_x_rcc(GPIO_A); + + /* keyboard init */ + enable_gpio_x_rcc(GPIO_C); //column (in) + enable_gpio_x_rcc(GPIO_A); //row (out) keyboard_init(); } \ No newline at end of file diff --git a/numworks_port/src/Laplace/laplace.h b/numworks_port/src/Laplace/laplace.h index 626bf7e..860f370 100644 --- a/numworks_port/src/Laplace/laplace.h +++ b/numworks_port/src/Laplace/laplace.h @@ -11,6 +11,7 @@ #include "led.h" #include "keyboard.h" +/* Initialize all needed peripherals, should be called early in your program */ void laplace_init(); #endif \ No newline at end of file diff --git a/numworks_port/src/Laplace/led.c b/numworks_port/src/Laplace/led.c index db8ac59..0c796ed 100644 --- a/numworks_port/src/Laplace/led.c +++ b/numworks_port/src/Laplace/led.c @@ -3,6 +3,8 @@ // GPIOB for all the leds uint8_t gpio_b = GPIO_B; +/* This should be called before accessing any other led related feature + as it sets up all led related peripherals */ void led_init(){ // It should be set to push-pull low-speed output. @@ -22,18 +24,30 @@ void led_init(){ GPIOB->OTYPER &= ~(1 << BLUE_LED_PIN); } +/* Set the status of the red led + true -> ON + false -> OFF */ void set_led_red(bool state){ set_output_pin(gpio_b, RED_LED_PIN, state); } +/* Set the status of the green led + true -> ON + false -> OFF */ void set_led_green(bool state){ set_output_pin(gpio_b, GREEN_LED_PIN, state); } +/* Set the status of the blue led + true -> ON + false -> OFF */ void set_led_blue(bool state){ set_output_pin(gpio_b, BLUE_LED_PIN, state); } +/* Set the status of all 3 leds at the same time + true -> ON + false -> OFF */ void set_led_all(bool state){ set_output_pin(gpio_b, RED_LED_PIN, state); set_output_pin(gpio_b, GREEN_LED_PIN, state); diff --git a/numworks_port/src/Laplace/led.h b/numworks_port/src/Laplace/led.h index 2be3080..72f5e0b 100644 --- a/numworks_port/src/Laplace/led.h +++ b/numworks_port/src/Laplace/led.h @@ -15,10 +15,28 @@ #include "../device/stm32f730xx.h" #include "gpio_helper.h" +/* This should be called before accessing any other led related feature + as it sets up all led related peripherals */ void led_init(); + +/* Set the status of the red led + true -> ON + false -> OFF */ void set_led_red(bool state); + +/* Set the status of the green led + true -> ON + false -> OFF */ void set_led_green(bool state); + +/* Set the status of the blue led + true -> ON + false -> OFF */ void set_led_blue(bool state); + +/* Set the status of all 3 leds at the same time + true -> ON + false -> OFF */ void set_led_all(bool state); #endif \ No newline at end of file diff --git a/numworks_port/src/Laplace/time.c b/numworks_port/src/Laplace/time.c index c257d18..3df54ba 100644 --- a/numworks_port/src/Laplace/time.c +++ b/numworks_port/src/Laplace/time.c @@ -1,11 +1,13 @@ #include "time.h" +/* Pause the os for x micro seconds */ void us_wait(uint8_t micro_seconds) { for (volatile uint32_t i=0; i