@@ -29,6 +29,8 @@ extern "C" {
29
29
uint32_t g_anOutputPinConfigured [MAX_NB_PORT ] = {0 };
30
30
#endif
31
31
32
+ #define MAX_PWM_RESOLUTION 16
33
+
32
34
static int _readResolution = 10 ;
33
35
int _writeResolution = PWM_RESOLUTION ;
34
36
static uint32_t _writeFreq = PWM_FREQUENCY ;
@@ -40,7 +42,11 @@ void analogReadResolution(int res)
40
42
41
43
void analogWriteResolution (int res )
42
44
{
43
- _writeResolution = res ;
45
+ if ((res > 0 ) && (res <= 32 )) {
46
+ _writeResolution = res ;
47
+ } else {
48
+ Error_Handler ();
49
+ }
44
50
}
45
51
46
52
void analogWriteFrequency (uint32_t freq )
@@ -112,10 +118,15 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue)
112
118
#endif //HAL_DAC_MODULE_ENABLED && !HAL_DAC_MODULE_ONLY
113
119
#if defined(HAL_TIM_MODULE_ENABLED ) && !defined(HAL_TIM_MODULE_ONLY )
114
120
if (pin_in_pinmap (p , PinMap_PWM )) {
121
+ int internalResolution = _writeResolution ;
115
122
if (is_pin_configured (p , g_anOutputPinConfigured ) == false) {
116
123
set_pin_configured (p , g_anOutputPinConfigured );
117
124
}
118
- pwm_start (p , _writeFreq , ulValue , _writeResolution );
125
+ if (_writeResolution > MAX_PWM_RESOLUTION ) {
126
+ internalResolution = MAX_PWM_RESOLUTION ;
127
+ ulValue = mapResolution (ulValue , _writeResolution , internalResolution );
128
+ }
129
+ pwm_start (p , _writeFreq , ulValue , internalResolution );
119
130
} else
120
131
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
121
132
{
0 commit comments