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