Updated the GPIO command to add in new features for PWM

Updated wiringPi to add new PWM controls.
This commit is contained in:
Gordon Henderson
2012-08-19 15:12:45 +01:00
parent c433519cf1
commit f99ffeda40
5 changed files with 170 additions and 45 deletions

View File

@@ -79,6 +79,8 @@ void (*setPadDrive) (int group, int value) ;
int (*digitalRead) (int pin) ;
int (*waitForInterrupt) (int pin, int mS) ;
void (*delayMicroseconds) (unsigned int howLong) ;
void (*pwmSetMode) (int mode) ;
void (*pwmSetRange) (unsigned int range) ;
#ifndef TRUE
@@ -377,22 +379,25 @@ void pinModeGpio (int pin, int mode)
if (!pwmRunning)
{
*(pwm + PWM_CONTROL) = 0 ; // Stop PWM
delayMicroseconds (10) ;
// Gert/Doms Values
*(clk + PWMCLK_DIV) = BCM_PASSWORD | (32<<12) ; // set pwm div to 32 (19.2/3 = 600KHz)
*(clk + PWMCLK_DIV) = BCM_PASSWORD | (32<<12) ; // set pwm div to 32 (19.2/32 = 600KHz)
*(clk + PWMCLK_CNTL) = BCM_PASSWORD | 0x11 ; // Source=osc and enable
digitalWrite (pin, LOW) ;
*(pwm + PWM_CONTROL) = 0 ; // Disable PWM
delayMicroseconds (10) ;
*(pwm + PWM0_RANGE) = 0x400 ;
delayMicroseconds (10) ;
*(pwm + PWM1_RANGE) = 0x400 ;
delayMicroseconds (10) ;
*(pwm + PWM0_RANGE) = 0x400 ; delayMicroseconds (10) ;
*(pwm + PWM1_RANGE) = 0x400 ; delayMicroseconds (10) ;
// Enable PWMs
*(pwm + PWM0_DATA) = 512 ;
*(pwm + PWM1_DATA) = 512 ;
// Balanced mode (default)
*(pwm + PWM_CONTROL) = PWM0_ENABLE | PWM1_ENABLE ;
pwmRunning = TRUE ;
@@ -423,6 +428,38 @@ void pinModeSys (int pin, int mode)
}
/*
* pwmControl:
* Allow the user to control some of the PWM functions
*********************************************************************************
*/
void pwmSetModeWPi (int mode)
{
if (mode == PWM_MODE_MS)
*(pwm + PWM_CONTROL) = PWM0_ENABLE | PWM1_ENABLE | PWM0_MS_MODE | PWM1_MS_MODE ;
else
*(pwm + PWM_CONTROL) = PWM0_ENABLE | PWM1_ENABLE ;
}
void pwmSetModeSys (int mode)
{
return ;
}
void pwmSetRangeWPi (unsigned int range)
{
*(pwm + PWM0_RANGE) = range ; delayMicroseconds (10) ;
*(pwm + PWM1_RANGE) = range ; delayMicroseconds (10) ;
}
void pwmSetRangeSys (unsigned int range)
{
return ;
}
#ifdef notYetReady
/*
* pinED01:
@@ -774,6 +811,8 @@ int wiringPiSetup (void)
digitalRead = digitalReadWPi ;
waitForInterrupt = waitForInterruptWPi ;
delayMicroseconds = delayMicrosecondsWPi ;
pwmSetMode = pwmSetModeWPi ;
pwmSetRange = pwmSetRangeWPi ;
// Open the master /dev/memory device
@@ -928,6 +967,8 @@ int wiringPiSetupGpio (void)
digitalRead = digitalReadGpio ;
waitForInterrupt = waitForInterruptGpio ;
delayMicroseconds = delayMicrosecondsWPi ; // Same
pwmSetMode = pwmSetModeWPi ;
pwmSetRange = pwmSetRangeWPi ;
return 0 ;
}
@@ -956,6 +997,9 @@ int wiringPiSetupSys (void)
digitalRead = digitalReadSys ;
waitForInterrupt = waitForInterruptSys ;
delayMicroseconds = delayMicrosecondsSys ;
pwmSetMode = pwmSetModeSys ;
pwmSetRange = pwmSetRangeSys ;
// Open and scan the directory, looking for exported GPIOs, and pre-open
// the 'value' interface to speed things up for later

View File

@@ -41,6 +41,12 @@
#define PUD_DOWN 1
#define PUD_UP 2
// PWM
#define PWM_MODE_MS 0
#define PWM_MODE_BAL 1
// Function prototypes
// c++ wrappers thanks to a commend by Nick Lott
// (and others on the Raspberry Pi forums)
@@ -65,6 +71,8 @@ extern void (*pwmWrite) (int pin, int value) ;
extern void (*setPadDrive) (int group, int value) ;
extern int (*digitalRead) (int pin) ;
extern void (*delayMicroseconds) (unsigned int howLong) ;
extern void (*pwmSetMode) (int mode) ;
extern void (*pwmSetRange) (unsigned int range) ;
// Interrupts