Documentation and clean up

This commit is contained in:
2024-04-05 20:59:57 +02:00
parent 1ef815d5a8
commit 6e5e5ddda6
22 changed files with 100 additions and 17 deletions

@@ -21,6 +21,7 @@
"led.h": "c",
"stm32f730xx.h": "c",
"keyboard.h": "c",
"gpio_helper.h": "c"
"gpio_helper.h": "c",
"stdint.h": "c"
}
}

@@ -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
- [ ] image display
- [ ] File system
- [ ] Plan what to do

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@@ -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)
{

@@ -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

@@ -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;

@@ -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

@@ -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();
}

@@ -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

@@ -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);

@@ -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

@@ -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<loops_per_microsecond*micro_seconds; i++) {
__asm volatile("nop");
}
}
/* Pause the os for x milli seconds */
void ms_wait(uint16_t milli_seconds) {
for (volatile uint32_t i=0; i<loops_per_millisecond*milli_seconds; i++) {
__asm volatile("nop");

@@ -12,7 +12,9 @@
#include "stdint.h"
/* Pause the os for x micro seconds */
void us_wait(uint8_t micro_seconds);
/* Pause the os for x milli seconds */
void ms_wait(uint16_t milli_seconds);
#endif

@@ -6,17 +6,32 @@ void main_entry(){
laplace_init();
ms_wait(2000);
set_led_green(true);
while (1)
{
// infinite loop
while (1){
struct button * keyboard_state = keyboard_scan();
for(int i =0; i < 54; i++){
if(keyboard_state[i].column == 4 && keyboard_state[i].row == 'H'){
if(keyboard_state[i].state){
set_led_blue(true);
}else{
set_led_blue(false);
}
}
if(keyboard_state[i].column == 3 && keyboard_state[i].row == 'H'){
if(keyboard_state[i].state){
set_led_green(true);
}else{
set_led_green(false);
}
break;
}
if(keyboard_state[i].column == 2 && keyboard_state[i].row == 'H'){
if(keyboard_state[i].state){
set_led_red(true);
}else{
set_led_red(false);
}
}
}
}

@@ -1,6 +1,6 @@
/** @file led.h
/** @file main.h
*
* @brief Control the led
* @brief The main programm
*
*/
@@ -12,6 +12,7 @@
#include "Laplace/keyboard.h"
#include "Laplace/time.h"
/* our main function */
void main_entry();
#endif