Skip to content

Commit 2da430a

Browse files
committed
added 7 seg display and buttons handling
1 parent 6ccd23f commit 2da430a

37 files changed

+12846
-7814
lines changed

.cproject

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1225673681" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="NUCLEO-F446RE" valueType="string"/>
2626
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1869189307" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || NUCLEO-F446RE || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32F446xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32F446RETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
2727
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1143402383" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="84" valueType="string"/>
28-
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat.455380597" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat" value="true" valueType="boolean"/>
29-
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoscanffloat.546233456" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoscanffloat" value="true" valueType="boolean"/>
28+
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat.455380597" name="Use float with printf from newlib-nano (-u _printf_float)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
29+
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoscanffloat.546233456" name="Use float with scanf from newlib-nano (-u _scanf_float)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoscanffloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
3030
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.204779960" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
3131
<builder buildPath="${workspace_loc:/hum_temp_sensor}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.222754992" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
3232
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.779404786" name="MCU/MPU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">

.mxproject

Lines changed: 4 additions & 5 deletions
Large diffs are not rendered by default.

.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>hum_temp_sensor</name>
3+
<name>digital_thermometer</name>
44
<comment></comment>
55
<projects>
66
</projects>

Core/Inc/aht20.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* aht20_driver_stm32f446ret
3-
* driver for aht20 temperature and humidity sensor
2+
* digital_thermomether
3+
* digital thermometer built using stm32f446ret, AHT20 sensor and multi-function shield
44
* Copyright (C) 2025 Andrew Kushyk
55
*
66
* This program is free software: you can redistribute it and/or modify

Core/Inc/aht20_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* aht20_driver_stm32f446ret
3-
* driver for aht20 temperature and humidity sensor
2+
* digital_thermomether
3+
* digital thermometer built using stm32f446ret, AHT20 sensor and multi-function shield
44
* Copyright (C) 2025 Andrew Kushyk
55
*
66
* This program is free software: you can redistribute it and/or modify

Core/Inc/bl.h renamed to Core/Inc/business_logic.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* aht20_driver_stm32f446ret
3-
* driver for aht20 temperature and humidity sensor
4-
* Copyright (C) 2025 Andrew Kushyk
2+
* digital_thermomether
3+
* digital thermometer built using stm32f446ret, AHT20 sensor and multi-function shield
4+
* Copyright (C) 2025 Andrew Kushyk, Andrii Ostapchuk
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published
@@ -27,17 +27,27 @@ typedef enum {
2727
BL_STATUS_RUN_FAILED,
2828
} bl_status_t;
2929

30+
/*
31+
* initializes buttons
32+
*/
33+
bl_status_t bl_init_buttons(void);
34+
3035
/*
3136
* runs calibration check. if wasn't calibrated, calibrates the sensor
3237
*/
33-
bl_status_t bl_run_sensor(I2C_HandleTypeDef *hi2c, UART_HandleTypeDef *huart);
38+
bl_status_t bl_run_sensor(I2C_HandleTypeDef *hi2c);
3439

3540
/*
3641
* processes and calculates sensor data
3742
*/
38-
bl_status_t bl_process_sensor_data(I2C_HandleTypeDef *hi2c, UART_HandleTypeDef *huart);
43+
bl_status_t bl_process_sensor_data(I2C_HandleTypeDef *hi2c);
44+
45+
/*
46+
* transmits formatted data to display via SPI
47+
*/
48+
void bl_spi_transmit_sensor_data(void);
3949

4050
/*
41-
* transmits formatted data to UART
51+
* interrupt callback
4252
*/
43-
void bl_uart_transmit_sensor_data(UART_HandleTypeDef *huart);
53+
void HAL_GPIO_EXTI_Callback(uint16_t gpio_pin);

Core/Inc/button_hmi_api.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* digital_thermomether
3+
* digital thermometer built using stm32f446ret, AHT20 sensor and multi-function shield
4+
* Copyright (C) 2025 Andrew Kushyk, Eldar Vanin
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published
8+
* by the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
22+
#include "general_hmi_device_api.h"
23+
#include "buttons.h"
24+
25+
/**
26+
* @brief HMI device handler for button devices
27+
*
28+
* This structure uses hmi_device_handler_t interface
29+
* to define functions to initialize and interact with
30+
* button device
31+
*
32+
* - `b_hmi_init` - Initializes the button GPIO
33+
* - `b_hmi_check_button_state_change` - Checks button state on button state change
34+
* - `b_hmi_check_button_current_state` - Get current button state
35+
* - `read_button` - Handles GPIO interrupt triggered by button
36+
*
37+
* These functions are static and decribed in button_hmi_api.c file
38+
*
39+
* @see hmi_device_handler_t
40+
*/
41+
extern hmi_device_handler_t button_hmi_api;

Core/Inc/buttons.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* digital_thermomether
3+
* digital thermometer built using stm32f446ret, AHT20 sensor and multi-function shield
4+
* Copyright (C) 2025 Andrew Kushyk, Eldar Vanin
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published
8+
* by the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
#include "main.h"
22+
23+
// @brief Status codes for button press
24+
typedef enum {
25+
BUTTON_RELEASED = 0, /// Button released status
26+
BUTTON_SHORT_PRESS, /// Button short pressed status
27+
} Button_State;
28+
29+
// @brief GPIO port and pin for button
30+
typedef struct {
31+
GPIO_TypeDef* port; /// GPIO port
32+
uint16_t pin; /// GPIO pin
33+
} Button_Gpio;
34+
35+
// @brief Grouped button data
36+
typedef struct Button {
37+
uint32_t press_time; /// Last button press time
38+
uint32_t release_time; /// Last button release time
39+
Button_State button_state; /// Last saved button state
40+
GPIO_PinState last_gpio_state; /// Last saved pin state
41+
Button_Gpio gpio; /// Button GPIO
42+
volatile struct Button *next_button; /// Pointer to next button in linked list
43+
} Button;
44+
45+
/**
46+
* @brief Initializes button and adds it to linked list
47+
*
48+
* @param[out] button button to be initialized
49+
*
50+
* @param[in] gpio_pin GPIO pin that caused interrupt
51+
*
52+
* @param gpio_pin GPIO pin button connected to
53+
*/
54+
void button_init(volatile Button *button, GPIO_TypeDef* gpio_port, uint16_t gpio_pin);
55+
56+
/**
57+
* @brief Checks button and returns detected button state
58+
*
59+
* @param[in]button is a button to check
60+
*
61+
* @return detected button state
62+
*/
63+
Button_State check_button_state(volatile Button *button);
64+
65+
/**
66+
* @brief detect button GPIO state change using debouncing and save time when button pressed
67+
*
68+
* @param gpio_pin is a pin that caused interrupt
69+
*/
70+
void read_button(uint16_t gpio_pin);

Core/Inc/character_generator.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* digital_thermomether
3+
* digital thermometer built using stm32f446ret, AHT20 sensor and multi-function shield
4+
* Copyright (C) 2025 Andrew Kushyk
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published
8+
* by the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
21+
/**
22+
* @file character_generator.h
23+
* @brief Declares the character generator module for 7-segment displays.
24+
*
25+
* This header provides the interface for initializing and controlling a 7-segment display.
26+
* It declares functions to initialize the module and transmit character data, using the API
27+
* defined in character_generator_api.h. The module converts ASCII characters to 7-segment
28+
* codes and manages decimal point and brightness settings for display output.
29+
*/
30+
31+
/**
32+
* @addtogroup Character_Generator
33+
* @{
34+
*/
35+
36+
#pragma once
37+
#include "character_generator_api.h"
38+
39+
/**
40+
* @brief Extern declaration of the character generator API structure.
41+
*
42+
* Provides access to the module's function pointers for initialization and data transmission.
43+
* This variable is defined in character_generator.c and should be used to call the module's
44+
* functions from the application code.
45+
*/
46+
extern const char_gen_api_t api_char_gen;
47+
48+
/**
49+
* @brief Initializes the character generator module.
50+
*
51+
* Configures the 7-segment driver with the provided SPI, timer, and GPIO settings for communication
52+
* with the display hardware.
53+
*
54+
* @param[in] hspi Pointer to the SPI handle for communication with the display.
55+
* @param[in] htim Pointer to the timer handle for timing/control signals.
56+
* @param[in] GPIOx Pointer to the GPIO port for the latch/control signal.
57+
* @param[in] GPIO_Pin The GPIO pin number for the latch/control signal.
58+
* @return char_generator_status_t Status of initialization:
59+
* - CHAR_GEN_STATUS_OK: Initialization successful.
60+
* - CHAR_GEN_STATUS_NOT_INITIALIZED: Driver initialization failed.
61+
* @pre The driver API (`api_7_seg`) must be properly configured.
62+
* @note Must be called before any transmit operations.
63+
* @see char_gen_transmit
64+
*/
65+
char_generator_status_t char_gen_init(SPI_HandleTypeDef *const hspi, TIM_HandleTypeDef *const htim,
66+
GPIO_TypeDef *const GPIOx, const uint16_t GPIO_Pin);
67+
68+
/**
69+
* @brief Transmits a 4-digit configuration to the 7-segment display.
70+
*
71+
* Converts ASCII characters and period statuses from the configuration into 16-bit data for the
72+
* 7-segment display, where the upper 8 bits contain segment data (including decimal point) and
73+
* the lower 8 bits select the digit position (bit index set to 1). The data is sent via the driver API.
74+
*
75+
* @param[in] config Pointer to the configuration containing 4 digits and brightness setting.
76+
* @return char_generator_status_t Status of transmission:
77+
* - CHAR_GEN_STATUS_OK: Transmission successful.
78+
* - CHAR_GEN_STATUS_INVALID_PARAMETERS: `config` is NULL or contains invalid characters.
79+
* - CHAR_GEN_STATUS_NOT_TRANSMITTED: Driver failed to send data.
80+
* @pre char_gen_init must be called successfully prior to transmission.
81+
* @note Supported characters: '0'-'9', 'A', 'a', 'T', 't', 'P', 'p', '-'.
82+
* @note The `config->digits` array must contain exactly 4 elements.
83+
* @note The `config->periods` array must contain valid `period_status` values (PERIOD_ON or PERIOD_OFF).
84+
* @see char_gen_init
85+
*/
86+
char_generator_status_t char_gen_transmit(const char_gen_data_t *const config);
87+
88+
/** @} */ // end of Character_Generator

0 commit comments

Comments
 (0)