Skip to content

Commit

Permalink
Merge pull request #134 from MikroElektronika/new-feature/layer-restr…
Browse files Browse the repository at this point in the history
…ucture

Layer Reduction
  • Loading branch information
StrahinjaJacimovic authored Nov 7, 2024
2 parents 2b8078a + 887456c commit 7932334
Show file tree
Hide file tree
Showing 191 changed files with 2,792 additions and 1,039 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ if (NOT DEFINED IS_BARE_METAL)
set(IS_BARE_METAL FALSE)
endif()

if (NOT DEFINED MIKROSDK_CURRENT_VERSION)
set(MIKROSDK_CURRENT_VERSION 2.0.0)
endif()

if (NOT DEFINED REDUCE_LAYER)
set(REDUCE_LAYER true)
endif()

if (${IS_BARE_METAL})
set(PROJECT_NAME_CUSTOM "BareMetal")
else()
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

**VERSIONS:**

+ **[v2.12.0](./changelog/v2.12.0/changelog.md)**
+ **[v2.11.5](./changelog/v2.11.5/changelog.md)**
+ **[v2.11.4](./changelog/v2.11.4/changelog.md)**
+ **[v2.11.3](./changelog/v2.11.3/changelog.md)**
Expand Down
50 changes: 50 additions & 0 deletions changelog/v2.12.0/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<p align="center">
<img src="http://www.mikroe.com/img/designs/beta/logo_small.png?raw=true" alt="MikroElektronika"/>
</p>

---

**[BACK TO MAIN FILE](../../changelog.md)**

---

# `v2.12.0`

+ released: 2024-11-08

## Changes

+ [`v2.12.0`](#v2120)
+ [Changes](#changes)
+ [Improvements](#improvements)
+ [mikroSDK](#mikrosdk)
+ [Fixes](#fixes)
+ [NEW HARDWARE](#new-hardware)

### Improvements

#### mikroSDK

**mikroSDK** now has the option to skip `DRV` to `HAL` layer jumps completely.

> Note that this feature is enabled by default in NECTO.
### Fixes

+ Fixed PIC XC8 SPI module so the code can be generated
+ Previous code was too complex for XC8 compiler, so it has been simplified
+ Fixed all timer module number definitions for all STM32L1x MCUs
+ Previously, timer/pwm was not working correctly as these values were incorrect

### NEW HARDWARE

> NOTE:
>> If any new hardware was added to current version, it will be listed here.
Support added for following hardware:

---

**[BACK TO MAIN FILE](../../changelog.md)**

---
26 changes: 26 additions & 0 deletions cmake/layers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function(resolve_compiler_definitions drv_to_hal)
## Find the list of targets defined in the current directory.
get_directory_property(TARGETS_LIST DIRECTORY ${CMAKE_CURRENT_LIST_DIR} BUILDSYSTEM_TARGETS)

## We assume that there's only one target in this directory.
foreach(target IN LISTS TARGETS_LIST)
## Perform operations only if the target is a library.
get_target_property(TYPE ${target} TYPE)
if(TYPE STREQUAL "STATIC_LIBRARY" OR TYPE STREQUAL "SHARED_LIBRARY" OR TYPE STREQUAL "OBJECT_LIBRARY")
message(STATUS "Resolving compiler definitions for target: ${target}")
## By default, set it to DRV->HAL->HAL_LL
## Backward compatibility.
if(NOT ${drv_to_hal})
message(INFO ":All layers included.")
target_compile_definitions(${target} PUBLIC
"DRV_TO_HAL=1"
)
else()
message(INFO ":HAL layer skipped.")
target_compile_definitions(${target} PUBLIC
"DRV_TO_HAL=0"
)
endif()
endif()
endforeach()
endfunction()
1 change: 1 addition & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include(fsUtils)
include(dsPicUtils)
include(rtcUtils)
include(aiUtils)
include(layers)

#############################################################################
## Macro to get a list of files in the provided folder
Expand Down
6 changes: 3 additions & 3 deletions drv/lib/src/lib_drv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ target_link_libraries(lib_drv INTERFACE
)

target_include_directories(lib_drv
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/drv>
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/drv>
)

mikrosdk_install(MikroSDK.Driver)
Expand Down
14 changes: 8 additions & 6 deletions drv/lib/src/lib_drv_analog_in/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ target_link_libraries(lib_drv_adc PUBLIC
MikroSDK.Hal.ADC
)
target_compile_definitions(lib_drv_adc
PUBLIC
${drv_def_list}
PUBLIC
${drv_def_list}
)

target_include_directories(lib_drv_adc
PRIVATE
../../include
INTERFACE
$<INSTALL_INTERFACE:include/drv>
PRIVATE
../../include
INTERFACE
$<INSTALL_INTERFACE:include/drv>
)

resolve_compiler_definitions(REDUCE_LAYER)

mikrosdk_install(MikroSDK.Driver.ADC)
install_headers(${CMAKE_INSTALL_PREFIX}/include/drv MikroSDK.Driver.ADC ../../include/drv_analog_in.h)
167 changes: 166 additions & 1 deletion drv/lib/src/lib_drv_analog_in/drv_analog_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@

static analog_in_t *_owner = NULL;

#if !DRV_TO_HAL
extern hal_adc_handle_register_t DRV_TO_HAL_PREFIXED(adc, hal_module_state)[ADC_MODULE_COUNT];

extern const uint8_t DRV_TO_HAL_PREFIXED(adc, module_state_count);

static handle_t hal_is_handle_null( handle_t *hal_module_handle )
{
uint8_t hal_module_state_count = DRV_TO_HAL_PREFIXED(adc, module_state_count);

while ( hal_module_state_count-- )
{
if ( *hal_module_handle == ( handle_t )&DRV_TO_HAL_PREFIXED(adc, hal_module_state)[ hal_module_state_count ].hal_adc_handle )
{
return ( handle_t )&DRV_TO_HAL_PREFIXED(adc, hal_module_state)[ hal_module_state_count ].hal_adc_handle;
}
}
return ACQUIRE_SUCCESS;
}
#endif

static err_t _acquire( analog_in_t *obj, bool obj_open_state )
{
err_t status = ACQUIRE_SUCCESS;
Expand All @@ -68,7 +88,7 @@ void analog_in_configure_default( analog_in_config_t *config )
{
if ( config )
{
config->input_pin = 0xFFFFFFFF;
config->input_pin = (pin_name_t)0xFFFFFFFF;
config->resolution = ANALOG_IN_RESOLUTION_DEFAULT;
config->vref_input = ANALOG_IN_VREF_EXTERNAL;
config->vref_value = -1.0;
Expand All @@ -88,7 +108,29 @@ err_t analog_in_set_resolution( analog_in_t *obj, analog_in_resolution_t resolut
if ( _acquire(obj, false) != ACQUIRE_FAIL )
{
obj->config.resolution = resolution;
#if DRV_TO_HAL
return hal_adc_set_resolution( &obj->handle, &obj->config );
#else
hal_adc_handle_register_t *hal_handle = ( hal_adc_handle_register_t * )hal_is_handle_null((handle_t *)&obj->handle);
err_t hal_status = HAL_ADC_SUCCESS;

if ( !hal_handle )
{
return HAL_ADC_ERROR;
}

hal_handle->init_state = false;

hal_status = hal_ll_adc_set_resolution( (handle_t *)&hal_handle, (hal_ll_adc_resolution_t)obj->config.resolution );

if ( hal_status != HAL_ADC_SUCCESS )
{
return HAL_ADC_ERROR;
} else {
hal_handle->init_state = true;
return hal_status;
}
#endif
} else {
return ADC_ERROR;
}
Expand All @@ -99,7 +141,29 @@ err_t analog_in_set_vref_input( analog_in_t *obj, analog_in_vref_t vref )
if ( _acquire( obj, false ) != ACQUIRE_FAIL )
{
obj->config.vref_input = vref;
#if DRV_TO_HAL
return hal_adc_set_vref_input( &obj->handle, &obj->config );
#else
hal_adc_handle_register_t *hal_handle = ( hal_adc_handle_register_t * )hal_is_handle_null((handle_t *)&obj->handle);
err_t hal_status = HAL_ADC_SUCCESS;

if ( !hal_handle )
{
return HAL_ADC_ERROR;
}

hal_handle->init_state = false;

hal_status = hal_ll_adc_set_vref_input( (handle_t *)&hal_handle, (hal_ll_adc_voltage_reference_t)obj->config.vref_input );

if ( hal_status != HAL_ADC_SUCCESS )
{
return HAL_ADC_ERROR;
} else {
hal_handle->init_state = true;
return hal_status;
}
#endif
} else {
return ADC_ERROR;
}
Expand All @@ -110,7 +174,16 @@ err_t analog_in_set_vref_value( analog_in_t *obj, float vref_value )
if ( _acquire( obj, false ) != ACQUIRE_FAIL )
{
obj->config.vref_value = vref_value;
#if DRV_TO_HAL
hal_adc_set_vref_value( &obj->handle, &obj->config );
#else
hal_adc_handle_register_t *hal_handle = ( hal_adc_handle_register_t * )hal_is_handle_null( (handle_t *)&obj->handle );

if ( hal_handle )
{
hal_ll_adc_set_vref_value( (handle_t *)&hal_handle, obj->config.vref_value );
}
#endif
return ADC_SUCCESS;
} else {
return ADC_ERROR;
Expand All @@ -121,7 +194,36 @@ err_t analog_in_read( analog_in_t *obj, uint16_t *readDatabuf )
{
if ( _acquire( obj, false ) != ACQUIRE_FAIL )
{
#if DRV_TO_HAL
return hal_adc_read( &obj->handle, readDatabuf );
#else
hal_adc_handle_register_t *hal_handle = ( hal_adc_handle_register_t * )hal_is_handle_null( (handle_t *)&obj->handle );
err_t hal_status = HAL_ADC_SUCCESS;

if ( !hal_handle )
{
return HAL_ADC_ERROR;
}

if ( !readDatabuf )
{
return HAL_ADC_ERROR;
}

if ( hal_handle->init_state == false )
{
hal_status = hal_ll_module_configure_adc( (handle_t *)&hal_handle );
}

if ( hal_status != HAL_ADC_SUCCESS )
{
return HAL_ADC_ERROR;
} else {
hal_handle->init_state = true;
}

return hal_ll_adc_read( (handle_t *)&hal_handle, readDatabuf );
#endif
} else {
return ADC_ERROR;
}
Expand All @@ -131,7 +233,70 @@ err_t analog_in_read_voltage( analog_in_t *obj, float *readDatabuf )
{
if ( _acquire( obj, false ) != ACQUIRE_FAIL )
{
#if DRV_TO_HAL
return hal_adc_read_voltage( &obj->handle, readDatabuf );
#else
uint16_t adc_value;
uint16_t local_resolution;

hal_adc_t *hal_obj = ( hal_adc_t * ) obj;

hal_adc_handle_register_t *hal_handle = ( hal_adc_handle_register_t * )hal_is_handle_null( (handle_t *)&obj->handle );
err_t hal_status = HAL_ADC_SUCCESS;

if ( !hal_handle )
{
return HAL_ADC_ERROR;
}

if ( !readDatabuf )
{
return HAL_ADC_ERROR;
}

if ( hal_handle->init_state == false )
{
hal_status = hal_ll_module_configure_adc( (handle_t *)&hal_handle );
}

if ( hal_status != HAL_ADC_SUCCESS )
{
return HAL_ADC_ERROR;
} else {
hal_handle->init_state = true;
}

if ( hal_ll_adc_read( (handle_t *)&hal_handle, &adc_value ) == HAL_ADC_SUCCESS )
{
switch( hal_obj->config.resolution ) {
case HAL_ADC_RESOLUTION_6_BIT:
local_resolution = HAL_ADC_6BIT_RES_VAL;
break;
case HAL_ADC_RESOLUTION_8_BIT:
local_resolution = HAL_ADC_8BIT_RES_VAL;
break;
case HAL_ADC_RESOLUTION_10_BIT:
local_resolution = HAL_ADC_10BIT_RES_VAL;
break;
case HAL_ADC_RESOLUTION_12_BIT:
local_resolution = HAL_ADC_12BIT_RES_VAL;
break;
case HAL_ADC_RESOLUTION_14_BIT:
local_resolution = HAL_ADC_14BIT_RES_VAL;
break;
case HAL_ADC_RESOLUTION_16_BIT:
local_resolution = HAL_ADC_16BIT_RES_VAL;
break;

default:
return HAL_ADC_ERROR;
}
*readDatabuf = ( adc_value * ( hal_obj->config.vref_value ) ) / ( local_resolution );
return HAL_ADC_SUCCESS;
} else {
return HAL_ADC_ERROR;
}
#endif
} else {
return ADC_ERROR;
}
Expand Down
2 changes: 2 additions & 0 deletions drv/lib/src/lib_drv_can/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ target_include_directories(lib_drv_can
$<INSTALL_INTERFACE:include/drv>
)

resolve_compiler_definitions(REDUCE_LAYER)

mikrosdk_install(MikroSDK.Driver.CAN)
install_headers(${CMAKE_INSTALL_PREFIX}/include/drv MikroSDK.Driver.CAN ../../include/drv_can.h)
Loading

0 comments on commit 7932334

Please sign in to comment.