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?
pull/24/head
Adam Green 2013-08-11 01:08:49 -07:00
parent 3be88a4a6e
commit 15f833bc1b
5 changed files with 6 additions and 6 deletions

View File

@ -45,7 +45,7 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b) {
}
uint32_t pinmap_peripheral(PinName pin, const PinMap* map) {
if (pin == (uint32_t)NC)
if (pin == (PinName)NC)
return (uint32_t)NC;
while (map->pin != NC) {

View File

@ -44,7 +44,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (uint32_t)NC) {
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed");
}

View File

@ -26,7 +26,7 @@ static const PinMap PinMap_DAC[] = {
void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (uint32_t)NC) {
if (obj->dac == (DACName)NC) {
error("DAC pin mapping failed");
}

View File

@ -17,7 +17,7 @@
#include "error.h"
void pin_function(PinName pin, int function) {
if (pin == (uint32_t)NC) return;
if (pin == (PinName)NC) return;
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
int index = pin_number >> 4;
@ -28,7 +28,7 @@ void pin_function(PinName pin, int function) {
}
void pin_mode(PinName pin, PinMode mode) {
if (pin == (uint32_t)NC) { return; }
if (pin == (PinName)NC) { return; }
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
int index = pin_number >> 5;

View File

@ -57,7 +57,7 @@ static unsigned int pwm_clock_mhz;
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (uint32_t)NC)
if (pwm == (PWMName)NC)
error("PwmOut pin mapping failed");
obj->pwm = pwm;