Skip to content

Commit

Permalink
HAL: add always_inline attribute for deprecated APIs in case that the…
Browse files Browse the repository at this point in the history
…se APIs are invoked in c file but not inlined by compiler.
  • Loading branch information
XuGuohui authored and avtolstoy committed Oct 5, 2020
1 parent 3594760 commit 4344e65
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 72 deletions.
6 changes: 4 additions & 2 deletions hal/inc/adc_hal_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#define ADC_HAL_COMPAT_H

// Deprecated *dynalib* APIs for backwards compatibility
inline void __attribute__((deprecated("Use hal_adc_set_sample_time() instead"))) HAL_ADC_Set_Sample_Time(uint8_t sample_time) {
inline void __attribute__((deprecated("Use hal_adc_set_sample_time() instead"), always_inline))
HAL_ADC_Set_Sample_Time(uint8_t sample_time) {
hal_adc_set_sample_time(sample_time);
}

inline int32_t __attribute__((deprecated("Use hal_adc_read() instead"))) HAL_ADC_Read(pin_t pin) {
inline int32_t __attribute__((deprecated("Use hal_adc_read() instead"), always_inline))
HAL_ADC_Read(pin_t pin) {
return hal_adc_read(pin);
}

Expand Down
63 changes: 42 additions & 21 deletions hal/inc/i2c_hal_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,87 +24,108 @@ typedef hal_i2c_config_t HAL_I2C_Config __attribute__((deprecated("Use hal_i2c_c
typedef hal_i2c_transmission_config_t HAL_I2C_Transmission_Config __attribute__((deprecated("Use hal_i2c_transmission_config_t instead")));

// Deprecated *dynalib* APIs for backwards compatibility
inline int __attribute__((deprecated("Use hal_i2c_init() instead"))) HAL_I2C_Init(hal_i2c_interface_t i2c, const hal_i2c_config_t* config) {
inline int __attribute__((deprecated("Use hal_i2c_init() instead"), always_inline))
HAL_I2C_Init(hal_i2c_interface_t i2c, const hal_i2c_config_t* config) {
return hal_i2c_init(i2c, config);
}

inline void __attribute__((deprecated("Use hal_i2c_set_speed() instead"))) HAL_I2C_Set_Speed(hal_i2c_interface_t i2c, uint32_t speed, void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_set_speed() instead"), always_inline))
HAL_I2C_Set_Speed(hal_i2c_interface_t i2c, uint32_t speed, void* reserved) {
hal_i2c_set_speed(i2c, speed, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_enable_dma_mode() instead"))) HAL_I2C_Enable_DMA_Mode(hal_i2c_interface_t i2c, bool enable, void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_enable_dma_mode() instead"), always_inline))
HAL_I2C_Enable_DMA_Mode(hal_i2c_interface_t i2c, bool enable, void* reserved) {
hal_i2c_enable_dma_mode(i2c, enable, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_stretch_clock() instead"))) HAL_I2C_Stretch_Clock(hal_i2c_interface_t i2c, bool stretch, void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_stretch_clock() instead"), always_inline))
HAL_I2C_Stretch_Clock(hal_i2c_interface_t i2c, bool stretch, void* reserved) {
hal_i2c_stretch_clock(i2c, stretch, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_begin() instead"))) HAL_I2C_Begin(hal_i2c_interface_t i2c, hal_i2c_mode_t mode, uint8_t address, void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_begin() instead"), always_inline))
HAL_I2C_Begin(hal_i2c_interface_t i2c, hal_i2c_mode_t mode, uint8_t address, void* reserved) {
hal_i2c_begin(i2c, mode, address, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_end() instead"))) HAL_I2C_End(hal_i2c_interface_t i2c, void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_end() instead"), always_inline))
HAL_I2C_End(hal_i2c_interface_t i2c, void* reserved) {
hal_i2c_end(i2c, reserved);
}

inline uint32_t __attribute__((deprecated("Use hal_i2c_request() instead"))) HAL_I2C_Request_Data(hal_i2c_interface_t i2c, uint8_t address, uint8_t quantity, uint8_t stop, void* reserved) {
inline uint32_t __attribute__((deprecated("Use hal_i2c_request() instead"), always_inline))
HAL_I2C_Request_Data(hal_i2c_interface_t i2c, uint8_t address, uint8_t quantity, uint8_t stop, void* reserved) {
return hal_i2c_request(i2c, address, quantity, stop, reserved);
}

inline int32_t __attribute__((deprecated("Use hal_i2c_request_ex() instead"))) HAL_I2C_Request_Data_Ex(hal_i2c_interface_t i2c, const hal_i2c_transmission_config_t* config, void* reserved) {
inline int32_t __attribute__((deprecated("Use hal_i2c_request_ex() instead"), always_inline))
HAL_I2C_Request_Data_Ex(hal_i2c_interface_t i2c, const hal_i2c_transmission_config_t* config, void* reserved) {
return hal_i2c_request_ex(i2c, config, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_begin_transmission() instead"))) HAL_I2C_Begin_Transmission(hal_i2c_interface_t i2c, uint8_t address, const hal_i2c_transmission_config_t* config) {
inline void __attribute__((deprecated("Use hal_i2c_begin_transmission() instead"), always_inline))
HAL_I2C_Begin_Transmission(hal_i2c_interface_t i2c, uint8_t address, const hal_i2c_transmission_config_t* config) {
hal_i2c_begin_transmission(i2c, address, config);
}

inline uint8_t __attribute__((deprecated("Use hal_i2c_end_transmission() instead"))) HAL_I2C_End_Transmission(hal_i2c_interface_t i2c, uint8_t stop, void* reserved) {
inline uint8_t __attribute__((deprecated("Use hal_i2c_end_transmission() instead"), always_inline))
HAL_I2C_End_Transmission(hal_i2c_interface_t i2c, uint8_t stop, void* reserved) {
return hal_i2c_end_transmission(i2c, stop, reserved);
}

inline uint32_t __attribute__((deprecated("Use hal_i2c_write() instead"))) HAL_I2C_Write_Data(hal_i2c_interface_t i2c, uint8_t data, void* reserved) {
inline uint32_t __attribute__((deprecated("Use hal_i2c_write() instead"), always_inline))
HAL_I2C_Write_Data(hal_i2c_interface_t i2c, uint8_t data, void* reserved) {
return hal_i2c_write(i2c, data, reserved);
}

inline int32_t __attribute__((deprecated("Use hal_i2c_available() instead"))) HAL_I2C_Available_Data(hal_i2c_interface_t i2c, void* reserved) {
inline int32_t __attribute__((deprecated("Use hal_i2c_available() instead"), always_inline))
HAL_I2C_Available_Data(hal_i2c_interface_t i2c, void* reserved) {
return hal_i2c_available(i2c, reserved);
}

inline int32_t __attribute__((deprecated("Use hal_i2c_read() instead"))) HAL_I2C_Read_Data(hal_i2c_interface_t i2c, void* reserved) {
inline int32_t __attribute__((deprecated("Use hal_i2c_read() instead"), always_inline))
HAL_I2C_Read_Data(hal_i2c_interface_t i2c, void* reserved) {
return hal_i2c_read(i2c, reserved);
}

inline int32_t __attribute__((deprecated("Use hal_i2c_peek() instead"))) HAL_I2C_Peek_Data(hal_i2c_interface_t i2c, void* reserved) {
inline int32_t __attribute__((deprecated("Use hal_i2c_peek() instead"), always_inline))
HAL_I2C_Peek_Data(hal_i2c_interface_t i2c, void* reserved) {
return hal_i2c_peek(i2c, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_flush() instead"))) HAL_I2C_Flush_Data(hal_i2c_interface_t i2c, void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_flush() instead"), always_inline))
HAL_I2C_Flush_Data(hal_i2c_interface_t i2c, void* reserved) {
hal_i2c_flush(i2c, reserved);
}

inline bool __attribute__((deprecated("Use hal_i2c_is_enabled() instead"))) HAL_I2C_Is_Enabled(hal_i2c_interface_t i2c, void* reserved) {
inline bool __attribute__((deprecated("Use hal_i2c_is_enabled() instead"), always_inline))
HAL_I2C_Is_Enabled(hal_i2c_interface_t i2c, void* reserved) {
return hal_i2c_is_enabled(i2c, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_set_callback_on_received() instead"))) HAL_I2C_Set_Callback_On_Receive(hal_i2c_interface_t i2c, void (*function)(int), void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_set_callback_on_received() instead"), always_inline))
HAL_I2C_Set_Callback_On_Receive(hal_i2c_interface_t i2c, void (*function)(int), void* reserved) {
hal_i2c_set_callback_on_received(i2c, function, reserved);
}

inline void __attribute__((deprecated("Use hal_i2c_set_callback_on_requested() instead"))) HAL_I2C_Set_Callback_On_Request(hal_i2c_interface_t i2c, void (*function)(void), void* reserved) {
inline void __attribute__((deprecated("Use hal_i2c_set_callback_on_requested() instead"), always_inline))
HAL_I2C_Set_Callback_On_Request(hal_i2c_interface_t i2c, void (*function)(void), void* reserved) {
hal_i2c_set_callback_on_requested(i2c, function, reserved);
}

inline uint8_t __attribute__((deprecated("Use hal_i2c_reset() instead"))) HAL_I2C_Reset(hal_i2c_interface_t i2c, uint32_t reserved, void* reserved1) {
inline uint8_t __attribute__((deprecated("Use hal_i2c_reset() instead"), always_inline))
HAL_I2C_Reset(hal_i2c_interface_t i2c, uint32_t reserved, void* reserved1) {
return hal_i2c_reset(i2c, reserved, reserved1);
}

inline int32_t __attribute__((deprecated("Use hal_i2c_lock() instead"))) HAL_I2C_Acquire(hal_i2c_interface_t i2c, void* reserved) {
inline int32_t __attribute__((deprecated("Use hal_i2c_lock() instead"), always_inline))
HAL_I2C_Acquire(hal_i2c_interface_t i2c, void* reserved) {
return hal_i2c_lock(i2c, reserved);
}

inline int32_t __attribute__((deprecated("Use hal_i2c_unlock() instead"))) HAL_I2C_Release(hal_i2c_interface_t i2c, void* reserved) {
inline int32_t __attribute__((deprecated("Use hal_i2c_unlock() instead"), always_inline))
HAL_I2C_Release(hal_i2c_interface_t i2c, void* reserved) {
return hal_i2c_unlock(i2c, reserved);
}

Expand Down
33 changes: 22 additions & 11 deletions hal/inc/pwm_hal_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,58 @@
#define PWM_HAL_COMPAT_H

// Deprecated *dynalib* APIs for backwards compatibility
inline void __attribute__((deprecated("Use hal_pwm_write() instead"))) HAL_PWM_Write(uint16_t pin, uint8_t value) {
inline void __attribute__((deprecated("Use hal_pwm_write() instead"), always_inline))
HAL_PWM_Write(uint16_t pin, uint8_t value) {
hal_pwm_write(pin, value);
}

inline void __attribute__((deprecated("Use hal_pwm_write_ext() instead"))) HAL_PWM_Write_Ext(uint16_t pin, uint32_t value) {
inline void __attribute__((deprecated("Use hal_pwm_write_ext() instead"), always_inline))
HAL_PWM_Write_Ext(uint16_t pin, uint32_t value) {
hal_pwm_write_ext(pin, value);
}

inline void __attribute__((deprecated("Use hal_pwm_write_with_frequency() instead"))) HAL_PWM_Write_With_Frequency(uint16_t pin, uint8_t value, uint16_t frequency) {
inline void __attribute__((deprecated("Use hal_pwm_write_with_frequency() instead"), always_inline))
HAL_PWM_Write_With_Frequency(uint16_t pin, uint8_t value, uint16_t frequency) {
hal_pwm_write_with_frequency(pin, value, frequency);
}

inline void __attribute__((deprecated("Use hal_pwm_write_with_frequency_ext() instead"))) HAL_PWM_Write_With_Frequency_Ext(uint16_t pin, uint32_t value, uint32_t frequency) {
inline void __attribute__((deprecated("Use hal_pwm_write_with_frequency_ext() instead"), always_inline))
HAL_PWM_Write_With_Frequency_Ext(uint16_t pin, uint32_t value, uint32_t frequency) {
hal_pwm_write_with_frequency_ext(pin, value, frequency);
}

inline uint16_t __attribute__((deprecated("Use hal_pwm_get_frequency() instead"))) HAL_PWM_Get_Frequency(uint16_t pin) {
inline uint16_t __attribute__((deprecated("Use hal_pwm_get_frequency() instead"), always_inline))
HAL_PWM_Get_Frequency(uint16_t pin) {
return hal_pwm_get_frequency(pin);
}

inline uint32_t __attribute__((deprecated("Use hal_pwm_get_frequency_ext() instead"))) HAL_PWM_Get_Frequency_Ext(uint16_t pin) {
inline uint32_t __attribute__((deprecated("Use hal_pwm_get_frequency_ext() instead"), always_inline))
HAL_PWM_Get_Frequency_Ext(uint16_t pin) {
return hal_pwm_get_frequency_ext(pin);
}

inline uint16_t __attribute__((deprecated("Use hal_pwm_get_analog_value() instead"))) HAL_PWM_Get_AnalogValue(uint16_t pin) {
inline uint16_t __attribute__((deprecated("Use hal_pwm_get_analog_value() instead"), always_inline))
HAL_PWM_Get_AnalogValue(uint16_t pin) {
return hal_pwm_get_analog_value(pin);
}

inline uint32_t __attribute__((deprecated("Use hal_pwm_get_analog_value_ext() instead"))) HAL_PWM_Get_AnalogValue_Ext(uint16_t pin) {
inline uint32_t __attribute__((deprecated("Use hal_pwm_get_analog_value_ext() instead"), always_inline))
HAL_PWM_Get_AnalogValue_Ext(uint16_t pin) {
return hal_pwm_get_analog_value_ext(pin);
}

inline uint32_t __attribute__((deprecated("Use hal_pwm_get_max_frequency() instead"))) HAL_PWM_Get_Max_Frequency(uint16_t pin) {
inline uint32_t __attribute__((deprecated("Use hal_pwm_get_max_frequency() instead"), always_inline))
HAL_PWM_Get_Max_Frequency(uint16_t pin) {
return hal_pwm_get_max_frequency(pin);
}

inline uint8_t __attribute__((deprecated("Use hal_pwm_get_resolution() instead"))) HAL_PWM_Get_Resolution(uint16_t pin) {
inline uint8_t __attribute__((deprecated("Use hal_pwm_get_resolution() instead"), always_inline))
HAL_PWM_Get_Resolution(uint16_t pin) {
return hal_pwm_get_resolution(pin);
}

inline void __attribute__((deprecated("Use hal_pwm_set_resolution() instead"))) HAL_PWM_Set_Resolution(uint16_t pin, uint8_t resolution) {
inline void __attribute__((deprecated("Use hal_pwm_set_resolution() instead"), always_inline))
HAL_PWM_Set_Resolution(uint16_t pin, uint8_t resolution) {
hal_pwm_set_resolution(pin, resolution);
}

Expand Down
13 changes: 8 additions & 5 deletions hal/inc/rtc_hal_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@
#include "time_compat.h"

// Deprecated *dynalib* APIs for backwards compatibility
inline void __attribute__((deprecated("use hal_rtc_init() instead"))) HAL_RTC_Configuration(void) {
inline void __attribute__((deprecated("use hal_rtc_init() instead"), always_inline))
HAL_RTC_Configuration(void) {
hal_rtc_init();
}

// There is no replacement for these
inline time32_t __attribute__((deprecated)) HAL_RTC_Get_UnixTime(void) {
inline time32_t __attribute__((deprecated, always_inline)) HAL_RTC_Get_UnixTime(void) {
return hal_rtc_get_unixtime_deprecated();
}

inline void __attribute__((deprecated)) HAL_RTC_Set_UnixTime(time32_t value) {
inline void __attribute__((deprecated, always_inline)) HAL_RTC_Set_UnixTime(time32_t value) {
hal_rtc_set_unixtime_deprecated(value);
}

inline void __attribute__((deprecated("use hal_rtc_cancel_alarm() instead"))) HAL_RTC_Cancel_UnixAlarm(void) {
inline void __attribute__((deprecated("use hal_rtc_cancel_alarm() instead"), always_inline))
HAL_RTC_Cancel_UnixAlarm(void) {
hal_rtc_cancel_alarm();
}

inline uint8_t __attribute__((deprecated("use hal_rtc_time_is_valid() instead"))) HAL_RTC_Time_Is_Valid(void* reserved) {
inline uint8_t __attribute__((deprecated("use hal_rtc_time_is_valid() instead"), always_inline))
HAL_RTC_Time_Is_Valid(void* reserved) {
return (uint8_t)hal_rtc_time_is_valid(reserved);
}

Expand Down
Loading

0 comments on commit 4344e65

Please sign in to comment.