This commit is contained in:
Andy Killorin 2025-03-24 17:28:33 -04:00
parent ed4d083358
commit 09cce163fc
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

25
main.c
View file

@ -16,6 +16,12 @@
#include "Crystalfontz128x128_ST7735.h"
#include <stdio.h>
#include "buttons.h"
#include <math.h>
#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();