[core] Rename PinInfo features fields
This commit is contained in:
@@ -26,15 +26,15 @@ PinInfo *pinInfo(pin_size_t pinNumber) {
|
||||
/**
|
||||
* @brief Check if pin supports all features represented by 'mask'.
|
||||
*/
|
||||
bool pinHasFeat(PinInfo *pin, uint32_t mask) {
|
||||
return (pin->features & mask) == mask;
|
||||
bool pinSupported(PinInfo *pin, uint32_t mask) {
|
||||
return (pin->supported & mask) == mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if pin has all features represented by 'mask' enabled.
|
||||
*/
|
||||
bool pinIsFeat(PinInfo *pin, uint32_t mask) {
|
||||
return (pin->types & mask) == mask;
|
||||
bool pinEnabled(PinInfo *pin, uint32_t mask) {
|
||||
return (pin->enabled & mask) == mask;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,13 +38,13 @@ typedef struct {
|
||||
*/
|
||||
uint32_t gpio;
|
||||
/**
|
||||
* @brief Supported pin features.
|
||||
* @brief Supported pin functions.
|
||||
*/
|
||||
uint32_t features;
|
||||
uint32_t supported;
|
||||
/**
|
||||
* @brief Enabled pin features. Used values are family-specific.
|
||||
* @brief Enabled pin functions. Used values are family-specific.
|
||||
*/
|
||||
uint32_t types;
|
||||
uint32_t enabled;
|
||||
/**
|
||||
* @brief Pin mode (direction, IRQ level, etc.).
|
||||
*/
|
||||
@@ -57,8 +57,8 @@ extern PinInfo pinTable[];
|
||||
|
||||
bool pinInvalid(pin_size_t pinNumber);
|
||||
PinInfo *pinInfo(pin_size_t pinNumber);
|
||||
bool pinHasFeat(PinInfo *pin, uint32_t mask);
|
||||
bool pinIsFeat(PinInfo *pin, uint32_t mask);
|
||||
bool pinSupported(PinInfo *pin, uint32_t mask);
|
||||
bool pinEnabled(PinInfo *pin, uint32_t mask);
|
||||
bool pinIsOutput(PinInfo *pin);
|
||||
bool pinIsInput(PinInfo *pin);
|
||||
|
||||
|
||||
@@ -30,22 +30,22 @@ void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback,
|
||||
gpio_irq_handler_list[interruptNumber] = callback;
|
||||
gpio_irq_handler_args[interruptNumber] = param;
|
||||
|
||||
if (pinTable[interruptNumber].types == PIN_IRQ && pinTable[interruptNumber].mode == mode)
|
||||
if (pinTable[interruptNumber].enabled == PIN_IRQ && pinTable[interruptNumber].mode == mode)
|
||||
// Nothing changes in pin mode
|
||||
return;
|
||||
|
||||
if (pinTable[interruptNumber].types != PIN_IRQ)
|
||||
if (pinTable[interruptNumber].enabled != PIN_IRQ)
|
||||
// pin mode changes; deinit gpio and free memory
|
||||
pinRemoveMode(interruptNumber);
|
||||
|
||||
gpio_irq_t *gpio;
|
||||
|
||||
if (pinTable[interruptNumber].types == PIN_NONE) {
|
||||
if (pinTable[interruptNumber].enabled == PIN_NONE) {
|
||||
// allocate memory if pin not used before
|
||||
gpio = malloc(sizeof(gpio_irq_t));
|
||||
gpio_pin_struct[interruptNumber] = gpio;
|
||||
gpio_irq_init(gpio, pinTable[interruptNumber].gpio, gpioIrqHandler, interruptNumber);
|
||||
pinTable[interruptNumber].types = PIN_IRQ;
|
||||
pinTable[interruptNumber].enabled = PIN_IRQ;
|
||||
} else {
|
||||
// pin already used as irq
|
||||
gpio = (gpio_irq_t *)gpio_pin_struct[interruptNumber];
|
||||
@@ -79,7 +79,7 @@ void detachInterrupt(pin_size_t interruptNumber) {
|
||||
if (pinInvalid(interruptNumber))
|
||||
return;
|
||||
|
||||
if (pinTable[interruptNumber].types == PIN_IRQ) {
|
||||
if (pinTable[interruptNumber].enabled == PIN_IRQ) {
|
||||
pinRemoveMode(interruptNumber);
|
||||
}
|
||||
gpio_irq_handler_list[interruptNumber] = NULL;
|
||||
|
||||
@@ -88,10 +88,10 @@ void analogWrite(pin_size_t pinNumber, int value) {
|
||||
return;
|
||||
pwmout_t *obj;
|
||||
|
||||
if (pinHasFeat(pin, PIN_PWM)) {
|
||||
if (pinSupported(pin, PIN_PWM)) {
|
||||
float percent = value * 1.0 / (1 << _analogWriteResolution);
|
||||
if (pin->types != PIN_PWM) {
|
||||
if ((pin->types == PIN_GPIO) || (pin->types == PIN_IRQ)) {
|
||||
if (pin->enabled != PIN_PWM) {
|
||||
if ((pin->enabled == PIN_GPIO) || (pin->enabled == PIN_IRQ)) {
|
||||
pinRemoveMode(pinNumber);
|
||||
}
|
||||
gpio_pin_struct[pinNumber] = malloc(sizeof(pwmout_t));
|
||||
@@ -99,7 +99,7 @@ void analogWrite(pin_size_t pinNumber, int value) {
|
||||
pwmout_init(obj, pin->gpio);
|
||||
pwmout_period_us(obj, _analogWritePeriod);
|
||||
pwmout_write(obj, percent);
|
||||
pin->types = PIN_PWM;
|
||||
pin->enabled = PIN_PWM;
|
||||
} else {
|
||||
pwmout_t *obj = (pwmout_t *)gpio_pin_struct[pinNumber];
|
||||
// pwmout_period_us(obj, _writePeriod);
|
||||
@@ -128,12 +128,12 @@ void _tone_timer_handler(const void *argument) {
|
||||
void _tone(uint32_t ulPin, unsigned int frequency, unsigned long duration) {
|
||||
pwmout_t *obj;
|
||||
|
||||
if ((pinTable[ulPin].features & PIN_PWM) != PIN_PWM) {
|
||||
if ((pinTable[ulPin].supported & PIN_PWM) != PIN_PWM) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pinTable[ulPin].types != PIN_PWM) {
|
||||
if ((pinTable[ulPin].types == PIN_GPIO) || (pinTable[ulPin].types == PIN_IRQ)) {
|
||||
if (pinTable[ulPin].enabled != PIN_PWM) {
|
||||
if ((pinTable[ulPin].enabled == PIN_GPIO) || (pinTable[ulPin].enabled == PIN_IRQ)) {
|
||||
pinRemoveMode(ulPin);
|
||||
}
|
||||
gpio_pin_struct[ulPin] = malloc(sizeof(pwmout_t));
|
||||
@@ -141,7 +141,7 @@ void _tone(uint32_t ulPin, unsigned int frequency, unsigned long duration) {
|
||||
pwmout_init(obj, pinTable[ulPin].gpio);
|
||||
pwmout_period(obj, 1.0 / frequency);
|
||||
pwmout_pulsewidth(obj, 1.0 / (frequency * 2));
|
||||
pinTable[ulPin].types = PIN_PWM;
|
||||
pinTable[ulPin].enabled = PIN_PWM;
|
||||
|
||||
} else {
|
||||
// There is already a PWM configured
|
||||
|
||||
@@ -10,22 +10,22 @@ void pinRemoveMode(pin_size_t pinNumber) {
|
||||
PinInfo *pin = pinInfo(pinNumber);
|
||||
if (!pin)
|
||||
return;
|
||||
if (pinIsFeat(pin, PIN_PWM)) {
|
||||
if (pinEnabled(pin, PIN_PWM)) {
|
||||
pwmout_t *obj = (pwmout_t *)gpio_pin_struct[pinNumber];
|
||||
pwmout_free(obj);
|
||||
}
|
||||
if (pinIsFeat(pin, PIN_GPIO)) {
|
||||
if (pinEnabled(pin, PIN_GPIO)) {
|
||||
gpio_t *obj = (gpio_t *)gpio_pin_struct[pinNumber];
|
||||
gpio_deinit(obj, pin->gpio);
|
||||
free(obj);
|
||||
}
|
||||
if (pinIsFeat(pin, PIN_IRQ)) {
|
||||
if (pinEnabled(pin, PIN_IRQ)) {
|
||||
gpio_irq_t *obj = (gpio_irq_t *)gpio_pin_struct[pinNumber];
|
||||
gpio_irq_deinit(obj);
|
||||
free(obj);
|
||||
}
|
||||
gpio_pin_struct[pinNumber] = NULL;
|
||||
pin->types = PIN_NONE;
|
||||
pin->enabled = PIN_NONE;
|
||||
}
|
||||
|
||||
void pinMode(pin_size_t pinNumber, PinModeArduino pinMode) {
|
||||
@@ -33,31 +33,31 @@ void pinMode(pin_size_t pinNumber, PinModeArduino pinMode) {
|
||||
if (!pin)
|
||||
return;
|
||||
|
||||
if (pinIsFeat(pin, PIN_GPIO) && pin->mode == pinMode)
|
||||
if (pinEnabled(pin, PIN_GPIO) && pin->mode == pinMode)
|
||||
// Nothing changes in pin mode
|
||||
return;
|
||||
|
||||
if (!pinHasFeat(pin, PIN_GPIO))
|
||||
if (!pinSupported(pin, PIN_GPIO))
|
||||
// cannot set ADC as I/O
|
||||
return;
|
||||
|
||||
/* if (pin->types == PIN_PWM) {
|
||||
/* if (pin->enabled == PIN_PWM) {
|
||||
// If this pin has been configured as PWM, then it cannot change to another mode
|
||||
return;
|
||||
} */
|
||||
|
||||
if (pin->types != PIN_GPIO)
|
||||
if (pin->enabled != PIN_GPIO)
|
||||
// pin mode changes; deinit gpio and free memory
|
||||
pinRemoveMode(pinNumber);
|
||||
|
||||
gpio_t *gpio;
|
||||
|
||||
if (pin->types == PIN_NONE) {
|
||||
if (pin->enabled == PIN_NONE) {
|
||||
// allocate memory if pin not used before
|
||||
gpio = malloc(sizeof(gpio_t));
|
||||
gpio_pin_struct[pinNumber] = gpio;
|
||||
gpio_init(gpio, pin->gpio);
|
||||
pin->types = PIN_GPIO;
|
||||
pin->enabled = PIN_GPIO;
|
||||
} else {
|
||||
// pin already used as gpio
|
||||
gpio = (gpio_t *)gpio_pin_struct[pinNumber];
|
||||
@@ -100,7 +100,7 @@ void digitalWrite(pin_size_t pinNumber, PinStatus status) {
|
||||
PinInfo *pin = pinInfo(pinNumber);
|
||||
if (!pin)
|
||||
return;
|
||||
if (pin->types != PIN_GPIO)
|
||||
if (pin->enabled != PIN_GPIO)
|
||||
return;
|
||||
|
||||
gpio_t *gpio = (gpio_t *)gpio_pin_struct[pinNumber];
|
||||
@@ -111,7 +111,7 @@ PinStatus digitalRead(pin_size_t pinNumber) {
|
||||
PinInfo *pin = pinInfo(pinNumber);
|
||||
if (!pin)
|
||||
return;
|
||||
if (pin->types != PIN_GPIO)
|
||||
if (pin->enabled != PIN_GPIO)
|
||||
return;
|
||||
|
||||
gpio_t *gpio = (gpio_t *)gpio_pin_struct[pinNumber];
|
||||
|
||||
@@ -40,7 +40,7 @@ extern unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
|
||||
return 0;
|
||||
|
||||
/* Handle */
|
||||
if (pinTable[pin].types != PIN_GPIO) {
|
||||
if (pinTable[pin].enabled != PIN_GPIO) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user