Browse code

Add source code of the firmware for the IO Board

Pawel Jablonski authored on 05/06/2023 17:01:27
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,98 @@
1
+/*
2
+ * Author: Pawel Jablonski
3
+ * E-mail: pj@xirx.net
4
+ * WWW: xirx.net
5
+ * GIT: git.xirx.net
6
+ *
7
+ * License: You can use this code however you like
8
+ * but leave information about the original author.
9
+ * Code is free for non-commercial and commercial use.
10
+ */
11
+
12
+#include <stm32f0xx.h>
13
+#include <stm32f0xx_hal.h>
14
+#include <stm32f0xx_hal_gpio.h>
15
+#include <stm32f0xx_hal_rcc.h>
16
+#include <system_stm32f0xx.h>
17
+
18
+#include "type.h"
19
+
20
+#include "led.h"
21
+
22
+//! Init LED and set up the pin outs
23
+void ledInit(void)
24
+{
25
+	__HAL_RCC_GPIOA_CLK_ENABLE();
26
+	
27
+	GPIO_InitTypeDef gpioInit = {0};
28
+	
29
+	gpioInit.Pin = (GPIO_PIN_8 | GPIO_PIN_15);
30
+	gpioInit.Mode = GPIO_MODE_OUTPUT_PP;
31
+	gpioInit.Pull = GPIO_NOPULL;
32
+	gpioInit.Speed = GPIO_SPEED_FREQ_LOW;
33
+	
34
+	HAL_GPIO_Init(GPIOA, &gpioInit);
35
+	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
36
+	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
37
+	
38
+	__HAL_RCC_GPIOC_CLK_ENABLE();
39
+	
40
+	gpioInit.Pin = GPIO_PIN_9;
41
+	gpioInit.Mode = GPIO_MODE_OUTPUT_PP;
42
+	gpioInit.Pull = GPIO_NOPULL;
43
+	gpioInit.Speed = GPIO_SPEED_FREQ_LOW;
44
+	
45
+	HAL_GPIO_Init(GPIOC, &gpioInit);
46
+	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET);
47
+}
48
+
49
+/**
50
+ * Set enable status of the run LED
51
+ *
52
+ * @param enable Enable status
53
+ */
54
+void ledSetRun(bool enable)
55
+{
56
+	if(enable)
57
+	{
58
+		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
59
+	}
60
+	else
61
+	{
62
+		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
63
+	}
64
+}
65
+
66
+/**
67
+ * Set enable status of the error LED
68
+ *
69
+ * @param enable Enable status
70
+ */
71
+void ledSetError(bool enable)
72
+{
73
+	if(enable)
74
+	{
75
+		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_SET);
76
+	}
77
+	else
78
+	{
79
+		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET);
80
+	}
81
+}
82
+
83
+/**
84
+ * Set enable status of the capslock LED
85
+ *
86
+ * @param enable Enable status
87
+ */
88
+void ledSetCapslock(bool enable)
89
+{
90
+	if(enable)
91
+	{
92
+		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
93
+	}
94
+	else
95
+	{
96
+		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
97
+	}
98
+}