Parcourir la source

#267 new output commands PWM_MODE_BAL & PWM_MODE_MS

pull/270/head
mstroh76 il y a 3 mois
Parent
révision
6992794f1d
2 fichiers modifiés avec 21 ajouts et 12 suppressions
  1. +15
    -8
      wiringPi/wiringPi.c
  2. +6
    -4
      wiringPi/wiringPi.h

+ 15
- 8
wiringPi/wiringPi.c Voir le fichier

@@ -1794,6 +1794,9 @@ void pinMode (int pin, int mode)
} else {
*(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) ; // Sets bits to zero = input
}
if (PM_OFF==mode && !usingGpioMem && pwm && PI_MODEL_5!=RaspberryPiModel && gpioToPwmALT[pin]>0) { //PWM pin -> reset
pwmWrite(origPin, 0);
}
} else if (mode == OUTPUT) {
if (PI_MODEL_5 == RaspberryPiModel) {
pads[1+pin] = (pin<=8) ? RP1_PAD_DEFAULT_0TO8 : RP1_PAD_DEFAULT_FROM9;
@@ -1811,22 +1814,26 @@ void pinMode (int pin, int mode)
pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode
pwmSetMode (PWM_MODE_MS) ;
}
else if (mode == PWM_OUTPUT)
{
else if (PWM_OUTPUT==mode || PWM_MS_OUTPUT==mode || PWM_BAL_OUTPUT==mode) {
RETURN_ON_MODEL5
if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin
return ;

usingGpioMemCheck ("pinMode PWM") ;

// Set pin to PWM mode
usingGpioMemCheck("pinMode PWM") ; // exit on error!

// Set pin to PWM mode
*(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (alt << shift) ;
delayMicroseconds (110) ; // See comments in pwmSetClockWPi

pwmSetMode (PWM_MODE_BAL) ; // Pi default mode
pwmSetRange (1024) ; // Default range of 1024
pwmSetClock (32) ; // 19.2 / 32 = 600KHz - Also starts the PWM
if (PWM_OUTPUT==mode || PWM_BAL_OUTPUT==mode) {
pwmSetMode(PWM_MODE_BAL); // Pi default mode
} else {
pwmSetMode(PWM_MODE_MS);
}
if (PWM_OUTPUT==mode) { // predefine
pwmSetRange (1024) ; // Default range of 1024
pwmSetClock (32) ; // 19.2 / 32 = 600KHz - Also starts the PWM
}
}
else if (mode == GPIO_CLOCK)
{


+ 6
- 4
wiringPi/wiringPi.h Voir le fichier

@@ -58,10 +58,12 @@

// Pin modes

#define INPUT 0
#define OUTPUT 1
#define PWM_OUTPUT 2
#define GPIO_CLOCK 3
#define INPUT 0
#define OUTPUT 1
#define PWM_OUTPUT 2
#define PWM_MS_OUTPUT 8
#define PWM_BAL_OUTPUT 9
#define GPIO_CLOCK 3
#define SOFT_PWM_OUTPUT 4
#define SOFT_TONE_OUTPUT 5
#define PWM_TONE_OUTPUT 6


Chargement…
Annuler
Enregistrer