112 lines
2.9 KiB
C
112 lines
2.9 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file : bsp_board_manager.c
|
|
* @brief : Board support package manager source file
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
#include "bsp_board_manager.h"
|
|
#include "bsp_board.h"
|
|
|
|
/* Forward declarations for board configurations */
|
|
extern const bsp_board_config_t stm32f407vet6_board_config;
|
|
|
|
/**
|
|
* @brief List of supported board configurations
|
|
*/
|
|
static const bsp_board_config_t* supported_boards[] = {
|
|
&stm32f407vet6_board_config,
|
|
/* Add more board configurations here */
|
|
};
|
|
|
|
/**
|
|
* @brief Current board configuration index
|
|
*/
|
|
static uint8_t current_board_index = 0;
|
|
|
|
/**
|
|
* @brief Get number of supported boards
|
|
* @retval Number of supported boards
|
|
*/
|
|
uint8_t bsp_board_get_count(void) {
|
|
return sizeof(supported_boards) / sizeof(supported_boards[0]);
|
|
}
|
|
|
|
/**
|
|
* @brief Get board configuration by index
|
|
* @param index: Board configuration index
|
|
* @retval Pointer to board configuration structure, NULL if invalid index
|
|
*/
|
|
const bsp_board_config_t* bsp_board_get_by_index(uint8_t index) {
|
|
if (index < bsp_board_get_count()) {
|
|
return supported_boards[index];
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* @brief Get board configuration by name
|
|
* @param name: Board name string
|
|
* @retval Pointer to board configuration structure, NULL if not found
|
|
*/
|
|
const bsp_board_config_t* bsp_board_get_by_name(const char* name) {
|
|
for (uint8_t i = 0; i < bsp_board_get_count(); i++) {
|
|
if (supported_boards[i]->name != NULL &&
|
|
strcmp(supported_boards[i]->name, name) == 0) {
|
|
return supported_boards[i];
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* @brief Set current board configuration by index
|
|
* @param index: Board configuration index
|
|
* @retval HAL status code
|
|
*/
|
|
hal_ret_t bsp_board_set_by_index(uint8_t index) {
|
|
if (index < bsp_board_get_count()) {
|
|
current_board_index = index;
|
|
return HAL_RET_OK;
|
|
}
|
|
return HAL_RET_INVALID_PARAM;
|
|
}
|
|
|
|
/**
|
|
* @brief Set current board configuration by name
|
|
* @param name: Board name string
|
|
* @retval HAL status code
|
|
*/
|
|
hal_ret_t bsp_board_set_by_name(const char* name) {
|
|
if (name == NULL) {
|
|
return HAL_RET_INVALID_PARAM;
|
|
}
|
|
|
|
for (uint8_t i = 0; i < bsp_board_get_count(); i++) {
|
|
if (supported_boards[i]->name != NULL &&
|
|
strcmp(supported_boards[i]->name, name) == 0) {
|
|
current_board_index = i;
|
|
return HAL_RET_OK;
|
|
}
|
|
}
|
|
return HAL_RET_ERROR;
|
|
}
|
|
|
|
/**
|
|
* @brief Get current board configuration
|
|
* @retval Pointer to current board configuration structure
|
|
*/
|
|
const bsp_board_config_t* bsp_board_get_config(void) {
|
|
return supported_boards[current_board_index];
|
|
}
|
|
|
|
/**
|
|
* @brief Get current board index
|
|
* @retval Current board index
|
|
*/
|
|
uint8_t bsp_board_get_current_index(void) {
|
|
return current_board_index;
|
|
}
|