diff --git a/main.c b/main.c index f13cd1f..3121cef 100644 --- a/main.c +++ b/main.c @@ -16,6 +16,12 @@ #include "Crystalfontz128x128_ST7735.h" #include #include "buttons.h" +#include +#include "inc/hw_memmap.h" +#include "driverlib/gpio.h" +#include "driverlib/pwm.h" +#include "driverlib/pin_map.h" +#define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz uint32_t gSystemClock; // [Hz] system clock frequency volatile uint32_t gTime = 0; // time in hundredths of a second @@ -24,6 +30,25 @@ int main(void) { IntMasterDisable(); + // configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2 + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); + GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2); + GPIOPinConfigure(GPIO_PF2_M0PWM2); + GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2, + GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); + // configure the PWM0 peripheral, gen 1, outputs 2 and 3 + SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); + // use system clock without division + PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1); + PWMGenConfigure(PWM0_BASE, PWM_GEN_1, + PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); + PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, roundf((float)gSystemClock/PWM_FREQUENCY)); + PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, + roundf((float)gSystemClock/PWM_FREQUENCY*0.4f)); + PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true); + PWMGenEnable(PWM0_BASE, PWM_GEN_1); + + // Enable the Floating Point Unit, and permit ISRs to use it FPUEnable(); FPULazyStackingEnable();