/****************************************************************************** * @brief initializing spi settings * *****************************************************************************/ void init(void) { /* Enabling clock to USART 1 */ CMU_ClockEnable(cmuClock_USART1, true); CMU_ClockEnable(cmuClock_GPIO, true); /* Configure LED_PORT pin LED_PIN (User LED) as push/pull outputs */ GPIO_PinModeSet(LED_PORT, /* Port */ LED_PIN, /* Pin */ gpioModePushPull, /* Mode */ 0 ); /* Output value */ /* Configure LED_PORT pin LED_PIN (User LED) as push/pull outputs */ GPIO_PinModeSet(gpioPortD, /* Port */ 3, /* Pin */ gpioModePushPull, /* Mode */ 0 ); /* Output value */ /* Configure LED_PORT pin LED_PIN (User LED) as push/pull outputs */ GPIO_PinModeSet(gpioPortF, /* Port */ 6, /* Pin */ gpioModePushPull, /* Mode */ 0 ); /* Output value */ /* Configure LED_PORT pin LED_PIN (User LED) as push/pull outputs */ GPIO_PinModeSet(gpioPortB, /* Port */ 12, /* Pin */ gpioModePushPull, /* Mode */ 0 ); /* Output value */ /* Setup UART */ SPI_setup(USART1_NUM, GPIO_POS1, true); }
// Setup inline void LCD_setup() { // Register Scan CLI dictionary CLI_registerDictionary( lcdCLIDict, lcdCLIDictName ); // Initialize SPI SPI_setup(); // Setup Register Control Signal (A0) // Start in display register mode (1) GPIOC_PDDR |= (1<<7); PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); GPIOC_PSOR |= (1<<7); // Setup LCD Reset pin (RST) // 0 - Reset, 1 - Normal Operation // Start in normal mode (1) GPIOC_PDDR |= (1<<8); PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); GPIOC_PSOR |= (1<<8); // Run LCD intialization sequence LCD_initialize(); }
void StoredFilter_Start(void) { Leds_SetLeds(0x4); CMU_ClockEnable(cmuClock_USART2, true); CMU_ClockEnable(cmuClock_GPIO, true); SPI_setup(2, 0, true); setupMEM(); setupFPGA(); setupSD(); done = false; setupTimer(); FPGA_Enable(); while(1) { if (done) break; } FPGA_Disable(); TIMER_Enable( TIMER0, false ); TIMER_Reset( TIMER0 ); FPGADriver_Destroy(); SDDriver_Finalize(); MEM_Destroy(); }
/**************************************************************************//** * @brief Sets/resets the ChipSelect of the SPI * * @param[in] value if true CS will be set, and reseted otherwise *****************************************************************************/ void SPI_SetChipSelect(bool value) { if (value) { SPI_setup(); /* Enable chip select */ ClrOutput(SDF_CS); } else { SPI_close(); /* Disable chip select */ SetOutput(SDF_CS); } }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P2DIR = 0x00; adc_setup(); SPI_setup(); int count = 0; volatile int freq = adc_value(); while(1) { if (count == 24) { freq = adc_value(); count = 0; } count++; toggle_waves(freq); } return 0; }
// Setup inline void LCD_setup() { // Register Scan CLI dictionary CLI_registerDictionary( lcdCLIDict, lcdCLIDictName ); // Initialize SPI SPI_setup(); // Setup Register Control Signal (A0) // Start in display register mode (1) GPIOC_PDDR |= (1<<7); PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); GPIOC_PSOR |= (1<<7); // Setup LCD Reset pin (RST) // 0 - Reset, 1 - Normal Operation // Start in normal mode (1) GPIOC_PDDR |= (1<<8); PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); GPIOC_PSOR |= (1<<8); // Run LCD intialization sequence LCD_initialize(); // Write default image to LCD for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) LCD_writeDisplayReg( page, (uint8_t*)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); // Setup Backlight SIM_SCGC6 |= SIM_SCGC6_FTM0; FTM0_CNT = 0; // Reset counter // PWM Period // 16-bit maximum FTM0_MOD = 0xFFFF; // Set FTM to PWM output - Edge Aligned, Low-true pulses FTM0_C0SC = 0x24; // MSnB:MSnA = 10, ELSnB:ELSnA = 01 FTM0_C1SC = 0x24; FTM0_C2SC = 0x24; // Base FTM clock selection (72 MHz system clock) // @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period // Higher pre-scalar will use the most power (also look the best) // Pre-scalar calculations // 0 - 72 MHz -> 549 Hz // 1 - 36 MHz -> 275 Hz // 2 - 18 MHz -> 137 Hz // 3 - 9 MHz -> 69 Hz (Slightly visible flicker) // 4 - 4 500 kHz -> 34 Hz (Visible flickering) // 5 - 2 250 kHz -> 17 Hz // 6 - 1 125 kHz -> 9 Hz // 7 - 562 500 Hz -> 4 Hz // Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced // Which will reduce the brightness range // System clock, /w prescalar setting FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS( STLcdBacklightPrescalar_define ); // Red FTM0_C0V = STLcdBacklightRed_define; PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); // Green FTM0_C1V = STLcdBacklightGreen_define; PORTC_PCR2 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); // Blue FTM0_C2V = STLcdBacklightBlue_define; PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); }