Versioning - mikroSDK v2.0 Framework
Introduction
This example demonstrates how to utilize the versioning
system of the mikroSDK v2.0
framework within the NECTO Studio IDE. It shows how to retrieve the major, minor, and patch version numbers of the framework and execute conditional code based on the SDK version. This is helpful when managing dependencies or ensuring compatibility across various versions of the framework.
By using version macros provided by mikroSDK
, developers can optimize their code for different versions of the SDK and utilize the latest features while maintaining backward compatibility.
API Name
- MikroSDK.mikroSDKVersion
The mikroSDK_version.h
header provides macros and functions for version control, allowing developers to retrieve version information and perform conditional compilation based on the SDK version.
Location of Files and Directories
-
GitHub Repository:
-
The
mikroSDK_version.h
and related source files can be found in the official mikroSDK v2.0 repository on GitHub.
-
Prerequisites
-
Library Manager:
- To add the mikroSDK versioning library to your project, follow these steps:
- Open NECTO Studio and navigate to the Library Manager.
- Select the mikroSDK_version library from the library list.
- To add the mikroSDK versioning library to your project, follow these steps:
-
Headers:
- Include the following header in your source files to access the versioning functionality:
#include "mikroSDK_version.h"
(alternatively, include#include "MikroSDK.mikroSDKVersion"
)
- Include the following header in your source files to access the versioning functionality:
-
CMakeLists:
- No manual configuration of the CMake file is required, as this is automatically handled when adding the library via the Library Manager.
-
If needed, ensure your
CMakeLists.txt
includes the following configuration to link themikroSDK_version
library:
Code Examples
- Versioning Example - mikroSDK v2.0
/******************************************************************************
* Project name: Versioning Example - mikroSDK v2.0
* Copyright:
* (c) MIKROE, 2024.
* Description:
* - This example demonstrates how to use the versioning feature of mikroSDK v2.0.
* - It retrieves the current version of the mikroSDK framework and prints the
* major, minor, and patch versions, and shows conditional compilation based on the SDK version.
* Library dependencies:
* - mikroSDK version library (mikroSDK_version.h)
* How to test this code example:
* - Connect the MCU to your development board.
* - Compile the code in NECTO Studio.
* - Program (flash) the code onto the MCU.
* - Use a serial terminal or debugger to view the version information printed by the example.
******************************************************************************/
/* ---------------------------------------------------------------- INCLUDES */
/**
* Ensure proper initialization of all necessary headers and dependencies.
* These are required for mikroSDK functions to work correctly.
*/
#ifdef PREINIT_SUPPORTED
#include "preinit.h" // Optional, include if pre-initialization is supported
#endif
#include <stdio.h> // Standard input/output library for printing
#include "mikroSDK_version.h" // Include mikroSDK versioning header
/* ------------------------------------------------------------- USER CODE */
int main() {
/* Ensure any necessary pre-initialization is executed to set up clocks or other peripherals. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
/* Retrieve and print the major, minor, and patch version of the mikroSDK framework.
* This function uses predefined macros from the mikroSDK library.
*/
printf_me("mikroSDK Version: %d.%d.%d\n",
mikroSDK_MAJOR_VERSION, // Macro for major version number
mikroSDK_MINOR_VERSION, // Macro for minor version number
mikroSDK_PATCH_VERSION); // Macro for patch version number
/* The complete version is retrieved and printed in a single value for easier reference.
* This can be useful for logging or version comparison.
*/
int sdk_version = mikroSDK_GET_VERSION;
printf_me("mikroSDK Complete Version: %d\n", sdk_version);
/* Conditional code: This block checks the mikroSDK version and executes specific code paths.
* This is helpful if certain features are only available in specific versions of mikroSDK.
*/
#if (mikroSDK_MAJOR_VERSION >= 2)
printf_me("This is mikroSDK version 2 or later.\n");
#if (mikroSDK_MINOR_VERSION >= 11)
printf_me("This is mikroSDK minor version 11 or later.\n");
#else
printf_me("This is an older mikroSDK minor version.\n");
#endif
#else
printf_me("This is an older mikroSDK version.\n");
#endif
/* End of the main function, all processing is complete, and the program exits successfully. */
return 0;
}
/* ----------------------------------------------------------------------- END */