进一步迭代优化统一管理
This commit is contained in:
332
HAL/Src/hal.c
332
HAL/Src/hal.c
@ -8,15 +8,343 @@
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "hal.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief HAL module registry
|
||||
*/
|
||||
static hal_module_config_t hal_module_registry[HAL_MODULE_MAX];
|
||||
static uint32_t hal_module_count = 0;
|
||||
|
||||
/**
|
||||
* @brief HAL error context
|
||||
*/
|
||||
static hal_error_context_t hal_error_ctx = {
|
||||
.callback = NULL,
|
||||
.error_count = 0,
|
||||
.enabled = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief HAL module initialization
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_init(void) {
|
||||
hal_ret_t hal_init(void) {
|
||||
hal_ret_t status = HAL_RET_OK;
|
||||
|
||||
/* Clear module registry */
|
||||
memset(hal_module_registry, 0, sizeof(hal_module_registry));
|
||||
hal_module_count = 0;
|
||||
|
||||
/* Initialize error handling system */
|
||||
status = hal_error_init();
|
||||
if (status != HAL_RET_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Call architecture specific initialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_init();
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
hal_stm32f4_init();
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
hal_stm32f7_init();
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
hal_stm32l4_init();
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register a HAL module
|
||||
* @param module_config: Module configuration
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_module_register(const hal_module_config_t* module_config) {
|
||||
if (module_config == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (module_config->type >= HAL_MODULE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Check if module already registered */
|
||||
if (hal_module_registry[module_config->type].ops.init != NULL) {
|
||||
return HAL_RET_RESOURCE_LOCKED;
|
||||
}
|
||||
|
||||
/* Register the module */
|
||||
memcpy(&hal_module_registry[module_config->type], module_config, sizeof(hal_module_config_t));
|
||||
hal_module_count++;
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize a specific HAL module
|
||||
* @param module_type: Module type
|
||||
* @param handle: HAL handle for the module
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_module_init(hal_module_type_t module_type, hal_handle_t* handle) {
|
||||
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (hal_module_registry[module_type].ops.init == NULL) {
|
||||
return HAL_RET_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/* Initialize handle if not already initialized */
|
||||
if (handle->status == HAL_PERIPH_STATE_RESET) {
|
||||
HAL_HANDLE_INIT(handle);
|
||||
handle->status = HAL_PERIPH_STATE_READY;
|
||||
}
|
||||
|
||||
return hal_module_registry[module_type].ops.init(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize a specific HAL module
|
||||
* @param module_type: Module type
|
||||
* @param handle: HAL handle for the module
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_module_deinit(hal_module_type_t module_type, hal_handle_t* handle) {
|
||||
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (hal_module_registry[module_type].ops.deinit == NULL) {
|
||||
return HAL_RET_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
hal_ret_t status = hal_module_registry[module_type].ops.deinit(handle);
|
||||
if (status == HAL_RET_OK) {
|
||||
handle->status = HAL_PERIPH_STATE_RESET;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure a specific HAL module
|
||||
* @param module_type: Module type
|
||||
* @param handle: HAL handle for the module
|
||||
* @param config: Module configuration data
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_module_configure(hal_module_type_t module_type, hal_handle_t* handle, void* config) {
|
||||
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (hal_module_registry[module_type].ops.configure == NULL) {
|
||||
return HAL_RET_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return hal_module_registry[module_type].ops.configure(handle, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Control a specific HAL module
|
||||
* @param module_type: Module type
|
||||
* @param handle: HAL handle for the module
|
||||
* @param cmd: Control command
|
||||
* @param param: Control parameter
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_module_control(hal_module_type_t module_type, hal_handle_t* handle, uint32_t cmd, void* param) {
|
||||
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (hal_module_registry[module_type].ops.control == NULL) {
|
||||
return HAL_RET_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return hal_module_registry[module_type].ops.control(handle, cmd, param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get status of a specific HAL module
|
||||
* @param module_type: Module type
|
||||
* @param handle: HAL handle for the module
|
||||
* @param status: Pointer to store module status
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_module_get_status(hal_module_type_t module_type, hal_handle_t* handle, uint32_t* status) {
|
||||
if (module_type >= HAL_MODULE_MAX || handle == NULL || status == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (hal_module_registry[module_type].ops.get_status == NULL) {
|
||||
return HAL_RET_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return hal_module_registry[module_type].ops.get_status(handle, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get default configuration for a module
|
||||
* @param module_type: Module type
|
||||
* @return Pointer to default configuration, or NULL if not available
|
||||
*/
|
||||
void* hal_module_get_default_config(hal_module_type_t module_type) {
|
||||
if (module_type >= HAL_MODULE_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return hal_module_registry[module_type].default_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get HAL version information
|
||||
* @param major: Pointer to store major version
|
||||
* @param minor: Pointer to store minor version
|
||||
* @param patch: Pointer to store patch version
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_get_version(uint8_t* major, uint8_t* minor, uint8_t* patch) {
|
||||
if (major == NULL || minor == NULL || patch == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
*major = HAL_VERSION_MAJOR;
|
||||
*minor = HAL_VERSION_MINOR;
|
||||
*patch = HAL_VERSION_PATCH;
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get HAL version string
|
||||
* @retval Version string
|
||||
*/
|
||||
const char* hal_get_version_string(void) {
|
||||
return HAL_VERSION_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get HAL module count
|
||||
* @retval Number of registered HAL modules
|
||||
*/
|
||||
uint32_t hal_get_module_count(void) {
|
||||
return hal_module_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get HAL module configuration
|
||||
* @param module_type: Module type
|
||||
* @retval Pointer to module configuration, or NULL if not found
|
||||
*/
|
||||
const hal_module_config_t* hal_get_module_config(hal_module_type_t module_type) {
|
||||
if (module_type >= HAL_MODULE_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (hal_module_registry[module_type].ops.init == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &hal_module_registry[module_type];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize HAL error handling system
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_error_init(void) {
|
||||
memset(&hal_error_ctx.last_error, 0, sizeof(hal_error_t));
|
||||
hal_error_ctx.error_count = 0;
|
||||
hal_error_ctx.enabled = 1;
|
||||
hal_error_ctx.callback = NULL;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize HAL error handling system
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_error_deinit(void) {
|
||||
hal_error_ctx.enabled = 0;
|
||||
hal_error_ctx.callback = NULL;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register an error callback function
|
||||
* @param callback: Error callback function
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_error_register_callback(hal_error_callback_t callback) {
|
||||
hal_error_ctx.callback = callback;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Record an error
|
||||
* @param error: Pointer to error information
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_error_record(const hal_error_t* error) {
|
||||
if (error == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!hal_error_ctx.enabled) {
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/* Copy error information */
|
||||
memcpy(&hal_error_ctx.last_error, error, sizeof(hal_error_t));
|
||||
hal_error_ctx.error_count++;
|
||||
|
||||
/* Call error callback if registered */
|
||||
if (hal_error_ctx.callback != NULL) {
|
||||
hal_error_ctx.callback(error);
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get last error information
|
||||
* @retval Pointer to last error information
|
||||
*/
|
||||
const hal_error_t* hal_error_get_last(void) {
|
||||
return &hal_error_ctx.last_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get total error count
|
||||
* @retval Total error count
|
||||
*/
|
||||
uint32_t hal_error_get_count(void) {
|
||||
return hal_error_ctx.error_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear error information
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_error_clear(void) {
|
||||
memset(&hal_error_ctx.last_error, 0, sizeof(hal_error_t));
|
||||
hal_error_ctx.error_count = 0;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable/disable error logging
|
||||
* @param enable: Enable flag (1 to enable, 0 to disable)
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_error_enable(uint8_t enable) {
|
||||
hal_error_ctx.enabled = enable;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
313
HAL/Src/hal_adc.c
Normal file
313
HAL/Src/hal_adc.c
Normal file
@ -0,0 +1,313 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : hal_adc.c
|
||||
* @brief : ADC hardware abstraction layer source file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal_adc.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize ADC hardware
|
||||
* @param config: ADC configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_init(const hal_adc_config_t *config) {
|
||||
if (config == NULL) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (config->instance >= HAL_ADC_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC initialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC initialization */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize ADC hardware
|
||||
* @param instance: ADC instance identifier
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_deinit(hal_adc_instance_t instance) {
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC deinitialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC deinitialization */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start ADC conversion
|
||||
* @param instance: ADC instance identifier
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_start(hal_adc_instance_t instance) {
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC start implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC start */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC start */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC start */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC start */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop ADC conversion
|
||||
* @param instance: ADC instance identifier
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_stop(hal_adc_instance_t instance) {
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC stop implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC stop */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC stop */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC stop */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC stop */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get ADC conversion value
|
||||
* @param instance: ADC instance identifier
|
||||
* @param channel: ADC channel
|
||||
* @param value: Pointer to store conversion value
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_get_value(hal_adc_instance_t instance, hal_adc_channel_t channel, uint16_t *value, uint32_t timeout) {
|
||||
if (value == NULL) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX || channel >= HAL_ADC_CHANNEL_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC get value implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC get value */
|
||||
*value = 0;
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC get value */
|
||||
*value = 0;
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC get value */
|
||||
*value = 0;
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC get value */
|
||||
*value = 0;
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get multiple ADC conversion values
|
||||
* @param instance: ADC instance identifier
|
||||
* @param values: Pointer to store conversion values
|
||||
* @param length: Number of values to get
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_get_values(hal_adc_instance_t instance, uint16_t *values, uint8_t length, uint32_t timeout) {
|
||||
if (values == NULL || length == 0) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC get values implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC get values */
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
values[i] = 0;
|
||||
}
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC get values */
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
values[i] = 0;
|
||||
}
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC get values */
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
values[i] = 0;
|
||||
}
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC get values */
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
values[i] = 0;
|
||||
}
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure ADC channel
|
||||
* @param instance: ADC instance identifier
|
||||
* @param config: ADC channel configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_configure_channel(hal_adc_instance_t instance, const hal_adc_channel_config_t *config) {
|
||||
if (config == NULL) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX || config->channel >= HAL_ADC_CHANNEL_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC channel configuration implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC channel configuration */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC channel configuration */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC channel configuration */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC channel configuration */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable ADC channel
|
||||
* @param instance: ADC instance identifier
|
||||
* @param channel: ADC channel
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_enable_channel(hal_adc_instance_t instance, hal_adc_channel_t channel) {
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX || channel >= HAL_ADC_CHANNEL_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC channel enable implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC channel enable */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC channel enable */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC channel enable */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC channel enable */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable ADC channel
|
||||
* @param instance: ADC instance identifier
|
||||
* @param channel: ADC channel
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t hal_adc_disable_channel(hal_adc_instance_t instance, hal_adc_channel_t channel) {
|
||||
if (instance >= HAL_ADC_INSTANCE_MAX || channel >= HAL_ADC_CHANNEL_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific ADC channel disable implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 ADC channel disable */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 ADC channel disable */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 ADC channel disable */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 ADC channel disable */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
275
HAL/Src/hal_can.c
Normal file
275
HAL/Src/hal_can.c
Normal file
@ -0,0 +1,275 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : hal_can.c
|
||||
* @brief : CAN hardware abstraction layer source file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal_can.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize CAN hardware
|
||||
* @param config: CAN configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_init(const hal_can_config_t *config) {
|
||||
if (config == NULL) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (config->instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN initialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN initialization */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize CAN hardware
|
||||
* @param instance: CAN instance identifier
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_deinit(hal_can_instance_t instance) {
|
||||
if (instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN deinitialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN deinitialization */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start CAN peripheral
|
||||
* @param instance: CAN instance identifier
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_start(hal_can_instance_t instance) {
|
||||
if (instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN start implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN start */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN start */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN start */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN start */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop CAN peripheral
|
||||
* @param instance: CAN instance identifier
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_stop(hal_can_instance_t instance) {
|
||||
if (instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN stop implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN stop */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN stop */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN stop */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN stop */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send CAN message
|
||||
* @param instance: CAN instance identifier
|
||||
* @param message: Pointer to CAN message structure
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_send(hal_can_instance_t instance, const hal_can_message_t *message, uint32_t timeout) {
|
||||
if (message == NULL) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN send implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN send */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN send */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN send */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN send */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive CAN message
|
||||
* @param instance: CAN instance identifier
|
||||
* @param fifo: FIFO number (0 or 1)
|
||||
* @param message: Pointer to CAN message structure
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_receive(hal_can_instance_t instance, uint8_t fifo, hal_can_message_t *message, uint32_t timeout) {
|
||||
if (message == NULL || fifo > 1) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN receive implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN receive */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get CAN receive FIFO message pending count
|
||||
* @param instance: CAN instance identifier
|
||||
* @param fifo: FIFO number (0 or 1)
|
||||
* @param count: Pointer to store pending message count
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_get_pending_count(hal_can_instance_t instance, uint8_t fifo, uint8_t *count) {
|
||||
if (count == NULL || fifo > 1) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN get pending count implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN get pending count */
|
||||
*count = 0;
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN get pending count */
|
||||
*count = 0;
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN get pending count */
|
||||
*count = 0;
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN get pending count */
|
||||
*count = 0;
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure CAN filter
|
||||
* @param instance: CAN instance identifier
|
||||
* @param filter_config: Pointer to CAN filter configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_can_configure_filter(hal_can_instance_t instance, const hal_can_filter_config_t *filter_config) {
|
||||
if (filter_config == NULL) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_CAN_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific CAN filter configuration implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 CAN filter configuration */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 CAN filter configuration */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 CAN filter configuration */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 CAN filter configuration */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
@ -9,11 +9,13 @@
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal_gpio.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize GPIO hardware
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_gpio_init(void) {
|
||||
hal_ret_t hal_gpio_init(void) {
|
||||
/* Call architecture specific GPIO initialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_gpio_init();
|
||||
@ -25,14 +27,21 @@ void hal_gpio_init(void) {
|
||||
hal_stm32l4_gpio_init();
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure GPIO pin
|
||||
* @param config: GPIO configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
|
||||
hal_ret_t hal_gpio_configure_pin(const hal_gpio_config_t *config) {
|
||||
if (config == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific GPIO configuration */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_gpio_configure_pin(config);
|
||||
@ -44,7 +53,9 @@ void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
|
||||
hal_stm32l4_gpio_configure_pin(config);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,8 +63,14 @@ void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
|
||||
* @param port: GPIO port
|
||||
* @param pin: GPIO pin
|
||||
* @param state: GPIO pin state
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state) {
|
||||
hal_ret_t hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state) {
|
||||
/* Validate parameters */
|
||||
if (port >= HAL_GPIO_PORT_K + 1 || pin >= HAL_GPIO_PIN_ALL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific GPIO write implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_gpio_write_pin(port, pin, state);
|
||||
@ -65,15 +82,23 @@ void hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_s
|
||||
hal_stm32l4_gpio_write_pin(port, pin, state);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle GPIO pin state
|
||||
* @param port: GPIO port
|
||||
* @param pin: GPIO pin
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
|
||||
hal_ret_t hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
|
||||
/* Validate parameters */
|
||||
if (port >= HAL_GPIO_PORT_K + 1 || pin >= HAL_GPIO_PIN_ALL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific GPIO toggle implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_gpio_toggle_pin(port, pin);
|
||||
@ -85,7 +110,9 @@ void hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
|
||||
hal_stm32l4_gpio_toggle_pin(port, pin);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
218
HAL/Src/hal_i2c.c
Normal file
218
HAL/Src/hal_i2c.c
Normal file
@ -0,0 +1,218 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : hal_i2c.c
|
||||
* @brief : I2C hardware abstraction layer source file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal_i2c.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize I2C hardware
|
||||
* @param config: I2C configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_i2c_init(const hal_i2c_config_t *config) {
|
||||
if (config == NULL) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (config->instance >= HAL_I2C_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific I2C initialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 I2C initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 I2C initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 I2C initialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 I2C initialization */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize I2C hardware
|
||||
* @param instance: I2C instance identifier
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_i2c_deinit(hal_i2c_instance_t instance) {
|
||||
if (instance >= HAL_I2C_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific I2C deinitialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 I2C deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 I2C deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 I2C deinitialization */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 I2C deinitialization */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transmit data to I2C slave
|
||||
* @param instance: I2C instance identifier
|
||||
* @param dev_address: Slave device address
|
||||
* @param data: Pointer to data buffer
|
||||
* @param length: Data length in bytes
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_i2c_master_transmit(hal_i2c_instance_t instance, uint16_t dev_address, const uint8_t *data, uint16_t length, uint32_t timeout) {
|
||||
if (data == NULL || length == 0) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_I2C_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific I2C transmit implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 I2C transmit */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 I2C transmit */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 I2C transmit */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 I2C transmit */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive data from I2C slave
|
||||
* @param instance: I2C instance identifier
|
||||
* @param dev_address: Slave device address
|
||||
* @param data: Pointer to data buffer
|
||||
* @param length: Data length to receive in bytes
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_i2c_master_receive(hal_i2c_instance_t instance, uint16_t dev_address, uint8_t *data, uint16_t length, uint32_t timeout) {
|
||||
if (data == NULL || length == 0) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_I2C_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific I2C receive implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 I2C receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 I2C receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 I2C receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 I2C receive */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transmit and receive data from I2C slave
|
||||
* @param instance: I2C instance identifier
|
||||
* @param dev_address: Slave device address
|
||||
* @param tx_data: Pointer to transmit data buffer
|
||||
* @param tx_length: Transmit data length in bytes
|
||||
* @param rx_data: Pointer to receive data buffer
|
||||
* @param rx_length: Receive data length in bytes
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_i2c_master_transmit_receive(hal_i2c_instance_t instance, uint16_t dev_address, const uint8_t *tx_data, uint16_t tx_length, uint8_t *rx_data, uint16_t rx_length, uint32_t timeout) {
|
||||
if (tx_data == NULL || rx_data == NULL || tx_length == 0 || rx_length == 0) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_I2C_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific I2C transmit and receive implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 I2C transmit and receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 I2C transmit and receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 I2C transmit and receive */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 I2C transmit and receive */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if I2C bus is ready
|
||||
* @param instance: I2C instance identifier
|
||||
* @param dev_address: Slave device address
|
||||
* @param trials: Number of trials
|
||||
* @param timeout: Timeout in milliseconds
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_status_t hal_i2c_is_device_ready(hal_i2c_instance_t instance, uint16_t dev_address, uint32_t trials, uint32_t timeout) {
|
||||
if (instance >= HAL_I2C_INSTANCE_MAX) {
|
||||
return HAL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific I2C device ready check implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
/* TODO: Implement STM32F1 I2C device ready check */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
/* TODO: Implement STM32F4 I2C device ready check */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
/* TODO: Implement STM32F7 I2C device ready check */
|
||||
return HAL_OK;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
/* TODO: Implement STM32L4 I2C device ready check */
|
||||
return HAL_OK;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_ERROR;
|
||||
#endif
|
||||
}
|
||||
@ -15,42 +15,54 @@
|
||||
* @brief Initialize SPI hardware
|
||||
* @param instance SPI instance identifier
|
||||
* @param config SPI configuration structure
|
||||
* @return true if initialization is successful, false otherwise
|
||||
* @retval HAL status code
|
||||
*/
|
||||
bool hal_spi_init(hal_spi_instance_t instance, const hal_spi_config_t *config) {
|
||||
hal_ret_t hal_spi_init(hal_spi_instance_t instance, const hal_spi_config_t *config) {
|
||||
if (config == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_SPI_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific SPI initialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_spi_init(instance, config);
|
||||
return hal_stm32f1_spi_init(instance, config) ? HAL_RET_OK : HAL_RET_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_spi_init(instance, config);
|
||||
return hal_stm32f4_spi_init(instance, config) ? HAL_RET_OK : HAL_RET_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_spi_init(instance, config);
|
||||
return hal_stm32f7_spi_init(instance, config) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_spi_init(instance, config);
|
||||
return hal_stm32l4_spi_init(instance, config) ? HAL_OK : HAL_ERROR;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return false;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize SPI hardware
|
||||
* @param instance SPI instance identifier
|
||||
* @return true if deinitialization is successful, false otherwise
|
||||
* @retval HAL status code
|
||||
*/
|
||||
bool hal_spi_deinit(hal_spi_instance_t instance) {
|
||||
hal_ret_t hal_spi_deinit(hal_spi_instance_t instance) {
|
||||
if (instance >= HAL_SPI_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific SPI deinitialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_spi_deinit(instance);
|
||||
return hal_stm32f1_spi_deinit(instance) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_spi_deinit(instance);
|
||||
return hal_stm32f4_spi_deinit(instance) ? HAL_RET_OK : HAL_RET_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_spi_deinit(instance);
|
||||
return hal_stm32f7_spi_deinit(instance) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_spi_deinit(instance);
|
||||
return hal_stm32l4_spi_deinit(instance) ? HAL_OK : HAL_ERROR;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return false;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -59,21 +71,29 @@ bool hal_spi_deinit(hal_spi_instance_t instance) {
|
||||
* @param instance SPI instance identifier
|
||||
* @param p_data Pointer to data buffer to transmit
|
||||
* @param size Size of data to transmit
|
||||
* @return true if transmission is successful, false otherwise
|
||||
* @retval HAL status code
|
||||
*/
|
||||
bool hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *p_data, uint16_t size) {
|
||||
hal_ret_t hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *p_data, uint16_t size) {
|
||||
if (p_data == NULL || size == 0) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_SPI_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific SPI transmit implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_spi_transmit(instance, p_data, size);
|
||||
return hal_stm32f1_spi_transmit(instance, p_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_spi_transmit(instance, p_data, size);
|
||||
return hal_stm32f4_spi_transmit(instance, p_data, size) ? HAL_RET_OK : HAL_RET_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_spi_transmit(instance, p_data, size);
|
||||
return hal_stm32f7_spi_transmit(instance, p_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_spi_transmit(instance, p_data, size);
|
||||
return hal_stm32l4_spi_transmit(instance, p_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return false;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -82,21 +102,29 @@ bool hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *p_data, uint16
|
||||
* @param instance SPI instance identifier
|
||||
* @param p_data Pointer to data buffer to receive
|
||||
* @param size Size of data to receive
|
||||
* @return true if reception is successful, false otherwise
|
||||
* @retval HAL status code
|
||||
*/
|
||||
bool hal_spi_receive(hal_spi_instance_t instance, uint8_t *p_data, uint16_t size) {
|
||||
hal_ret_t hal_spi_receive(hal_spi_instance_t instance, uint8_t *p_data, uint16_t size) {
|
||||
if (p_data == NULL || size == 0) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_SPI_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific SPI receive implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_spi_receive(instance, p_data, size);
|
||||
return hal_stm32f1_spi_receive(instance, p_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_spi_receive(instance, p_data, size);
|
||||
return hal_stm32f4_spi_receive(instance, p_data, size) ? HAL_RET_OK : HAL_RET_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_spi_receive(instance, p_data, size);
|
||||
return hal_stm32f7_spi_receive(instance, p_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_spi_receive(instance, p_data, size);
|
||||
return hal_stm32l4_spi_receive(instance, p_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return false;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -106,20 +134,28 @@ bool hal_spi_receive(hal_spi_instance_t instance, uint8_t *p_data, uint16_t size
|
||||
* @param p_tx_data Pointer to data buffer to transmit
|
||||
* @param p_rx_data Pointer to data buffer to receive
|
||||
* @param size Size of data to transmit/receive
|
||||
* @return true if transmission and reception are successful, false otherwise
|
||||
* @retval HAL status code
|
||||
*/
|
||||
bool hal_spi_transmit_receive(hal_spi_instance_t instance, const uint8_t *p_tx_data, uint8_t *p_rx_data, uint16_t size) {
|
||||
hal_ret_t hal_spi_transmit_receive(hal_spi_instance_t instance, const uint8_t *p_tx_data, uint8_t *p_rx_data, uint16_t size) {
|
||||
if (p_tx_data == NULL || p_rx_data == NULL || size == 0) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_SPI_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific SPI transmit and receive implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_spi_transmit_receive(instance, p_tx_data, p_rx_data, size);
|
||||
return hal_stm32f1_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size);
|
||||
return hal_stm32f4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_RET_OK : HAL_RET_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_spi_transmit_receive(instance, p_tx_data, p_rx_data, size);
|
||||
return hal_stm32f7_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size);
|
||||
return hal_stm32l4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_OK : HAL_ERROR;
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return false;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
}
|
||||
@ -12,8 +12,9 @@
|
||||
|
||||
/**
|
||||
* @brief Initialize UART hardware
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_uart_init(void) {
|
||||
hal_ret_t hal_uart_init(void) {
|
||||
/* Call architecture specific UART initialization */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_uart_init();
|
||||
@ -25,14 +26,25 @@ void hal_uart_init(void) {
|
||||
hal_stm32l4_uart_init();
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure UART parameters for specific instance
|
||||
* @param config: UART configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_uart_config(const hal_uart_config_t *config) {
|
||||
hal_ret_t hal_uart_config(const hal_uart_config_t *config) {
|
||||
if (config == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (config->instance >= HAL_UART_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific UART configuration */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_uart_config(config);
|
||||
@ -44,7 +56,9 @@ void hal_uart_config(const hal_uart_config_t *config) {
|
||||
hal_stm32l4_uart_config(config);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,8 +66,17 @@ void hal_uart_config(const hal_uart_config_t *config) {
|
||||
* @param instance: UART instance identifier
|
||||
* @param data: Pointer to data buffer
|
||||
* @param length: Data length in bytes
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length) {
|
||||
hal_ret_t hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length) {
|
||||
if (data == NULL || length == 0) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_UART_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific UART send implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
hal_stm32f1_uart_send(instance, data, length);
|
||||
@ -65,7 +88,9 @@ void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t len
|
||||
hal_stm32l4_uart_send(instance, data, length);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,62 +98,92 @@ void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t len
|
||||
* @param instance: UART instance identifier
|
||||
* @param data: Pointer to data buffer
|
||||
* @param length: Data length to receive in bytes
|
||||
* @retval Number of bytes received
|
||||
* @param received: Pointer to store number of bytes received
|
||||
* @retval HAL status code
|
||||
*/
|
||||
size_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length) {
|
||||
hal_ret_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length, size_t *received) {
|
||||
if (data == NULL || received == NULL || length == 0) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_UART_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific UART receive implementation */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_uart_receive(instance, data, length);
|
||||
*received = hal_stm32f1_uart_receive(instance, data, length);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_uart_receive(instance, data, length);
|
||||
*received = hal_stm32f4_uart_receive(instance, data, length);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_uart_receive(instance, data, length);
|
||||
*received = hal_stm32f7_uart_receive(instance, data, length);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_uart_receive(instance, data, length);
|
||||
*received = hal_stm32l4_uart_receive(instance, data, length);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return 0;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if specific UART instance is ready to send
|
||||
* @param instance: UART instance identifier
|
||||
* @retval 1 if ready, 0 otherwise
|
||||
* @param ready: Pointer to store ready status (1 if ready, 0 otherwise)
|
||||
* @retval HAL status code
|
||||
*/
|
||||
uint8_t hal_uart_is_tx_ready(hal_uart_instance_t instance) {
|
||||
hal_ret_t hal_uart_is_tx_ready(hal_uart_instance_t instance, uint8_t *ready) {
|
||||
if (ready == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_UART_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific UART TX ready check */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_uart_is_tx_ready(instance);
|
||||
*ready = hal_stm32f1_uart_is_tx_ready(instance);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_uart_is_tx_ready(instance);
|
||||
*ready = hal_stm32f4_uart_is_tx_ready(instance);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_uart_is_tx_ready(instance);
|
||||
*ready = hal_stm32f7_uart_is_tx_ready(instance);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_uart_is_tx_ready(instance);
|
||||
*ready = hal_stm32l4_uart_is_tx_ready(instance);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return 0;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if specific UART instance has data to receive
|
||||
* @param instance: UART instance identifier
|
||||
* @retval 1 if data available, 0 otherwise
|
||||
* @param ready: Pointer to store ready status (1 if data available, 0 otherwise)
|
||||
* @retval HAL status code
|
||||
*/
|
||||
uint8_t hal_uart_is_rx_ready(hal_uart_instance_t instance) {
|
||||
hal_ret_t hal_uart_is_rx_ready(hal_uart_instance_t instance, uint8_t *ready) {
|
||||
if (ready == NULL) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (instance >= HAL_UART_INSTANCE_MAX) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Call architecture specific UART RX ready check */
|
||||
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
|
||||
return hal_stm32f1_uart_is_rx_ready(instance);
|
||||
*ready = hal_stm32f1_uart_is_rx_ready(instance);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
|
||||
return hal_stm32f4_uart_is_rx_ready(instance);
|
||||
*ready = hal_stm32f4_uart_is_rx_ready(instance);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
|
||||
return hal_stm32f7_uart_is_rx_ready(instance);
|
||||
*ready = hal_stm32f7_uart_is_rx_ready(instance);
|
||||
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
|
||||
return hal_stm32l4_uart_is_rx_ready(instance);
|
||||
*ready = hal_stm32l4_uart_is_rx_ready(instance);
|
||||
#else
|
||||
#error "Unsupported HAL architecture"
|
||||
return 0;
|
||||
return HAL_RET_ERROR;
|
||||
#endif
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user