Skip to content

Commit 15f833b

Browse files
committed
Cast to matching enumeration type instead of uint32_t
These were done to silence GCC warnings and fix potential bugs where they would never be equal when the enumeration wasn't a 32-bit type. For example, common/pinmap_common.c used to contain this code: if (pin == (uint32_t)NC) I switched it to: if (pin == (PinName)NC) I wonder why this casting to uint32_t was done in the first place? Maybe another supported compiler requires it?
1 parent 3be88a4 commit 15f833b

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

libraries/mbed/common/pinmap_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b) {
4545
}
4646

4747
uint32_t pinmap_peripheral(PinName pin, const PinMap* map) {
48-
if (pin == (uint32_t)NC)
48+
if (pin == (PinName)NC)
4949
return (uint32_t)NC;
5050

5151
while (map->pin != NC) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static const PinMap PinMap_ADC[] = {
4444

4545
void analogin_init(analogin_t *obj, PinName pin) {
4646
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
47-
if (obj->adc == (uint32_t)NC) {
47+
if (obj->adc == (ADCName)NC) {
4848
error("ADC pin mapping failed");
4949
}
5050

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static const PinMap PinMap_DAC[] = {
2626

2727
void analogout_init(dac_t *obj, PinName pin) {
2828
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
29-
if (obj->dac == (uint32_t)NC) {
29+
if (obj->dac == (DACName)NC) {
3030
error("DAC pin mapping failed");
3131
}
3232

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pinmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "error.h"
1818

1919
void pin_function(PinName pin, int function) {
20-
if (pin == (uint32_t)NC) return;
20+
if (pin == (PinName)NC) return;
2121

2222
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
2323
int index = pin_number >> 4;
@@ -28,7 +28,7 @@ void pin_function(PinName pin, int function) {
2828
}
2929

3030
void pin_mode(PinName pin, PinMode mode) {
31-
if (pin == (uint32_t)NC) { return; }
31+
if (pin == (PinName)NC) { return; }
3232

3333
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
3434
int index = pin_number >> 5;

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static unsigned int pwm_clock_mhz;
5757
void pwmout_init(pwmout_t* obj, PinName pin) {
5858
// determine the channel
5959
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
60-
if (pwm == (uint32_t)NC)
60+
if (pwm == (PWMName)NC)
6161
error("PwmOut pin mapping failed");
6262

6363
obj->pwm = pwm;

0 commit comments

Comments
 (0)