示例#1
0
static void leuartInit(void)
{
    LEUART_Init_TypeDef leuart0Init;
    leuart0Init.enable = leuartEnable;       /* Activate data reception on LEUn_TX pin. */
    leuart0Init.refFreq = 0;                 /* Inherit the clock frequenzy from the LEUART clock source */
    leuart0Init.baudrate = LEUART0_BAUDRATE; /* Baudrate = 9600 bps */
    leuart0Init.databits = leuartDatabits8;  /* Each LEUART frame containes 8 databits */
    leuart0Init.parity = leuartNoParity;     /* No parity bits in use */
    leuart0Init.stopbits = leuartStopbits2;  /* Setting the number of stop bits in a frame to 2 bitperiods */

    CMU_ClockEnable(cmuClock_CORELE, true);
    CMU_ClockEnable(cmuClock_LEUART0, true);

    LEUART_Reset(LEUART0);
    LEUART_Init(LEUART0, &leuart0Init);

    LEUART0->SIGFRAME = '\n';

    /* Enable LEUART Signal Frame Interrupt */
    LEUART_IntEnable(LEUART0, LEUART_IEN_SIGF);

    /* Enable LEUART0 interrupt vector */
    NVIC_SetPriority(LEUART0_IRQn, LEUART0_INT_PRIORITY);

    LEUART0->ROUTE = LEUART_ROUTE_RXPEN | LEUART_ROUTE_TXPEN | LEUART0_LOCATION;

    GPIO_PinModeSet(LEUART0_PORT, LEUART0_TX, gpioModePushPull, 1);
    GPIO_PinModeSet(LEUART0_PORT, LEUART0_RX, gpioModeInputPull, 1);

    lineEndReceived = xSemaphoreCreateBinary();

    DMADRV_AllocateChannel(&dmaChannel, NULL);
}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
	/* Chip errata */
	CHIP_Init();

	// Turn on the peripheral clocks
	CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
	CMU_ClockEnable(cmuClock_GPIO, true);
	CMU_ClockEnable(cmuClock_USART1, true);

	Ecode_t result;

	// Initialize DMA.
	result = DMADRV_Init();
	if (result != ECODE_EMDRV_DMADRV_OK)
	{
		DEBUG_BREAK
	}

	// Request a DMA channel.
	result = DMADRV_AllocateChannel( &dma_channel, NULL );
	if (result != ECODE_EMDRV_DMADRV_OK)
	{
		DEBUG_BREAK
	}

	// Configure the USART peripheral
	USART_InitSync_TypeDef init = USART_INITSYNC_DEFAULT;
	init.baudrate = 50000;
	init.msbf = true;		// MSB first, per the TLC5940 spec
	USART_InitSync(USART1, &init);

	// Route the peripheral to the GPIO block
	USART1->ROUTE = USART_ROUTE_TXPEN | 		// US1_TX
			        USART_ROUTE_CLKPEN | 		// US1_CLK
			        USART_ROUTE_LOCATION_LOC1;	// Location #1

	// Configure both the USART and control pins in GPIO
	GPIO_DriveModeSet(gpioPortD, gpioDriveModeLowest);
	GPIO_PinModeSet(CONTROL_PORT, SIN_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, SCLK_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, XLAT_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, VPRG_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, BLANK_PIN, gpioModePushPullDrive, 0);
	GPIO_PinModeSet(CONTROL_PORT, GSCLK_PIN, gpioModePushPullDrive, 0);

	// Start with DC Data
	stream.mode = DOT_CORRECTION_MODE;
	for (int i=0; i<MAX_CHANNELS; i++)
	{
//	      stream.channel[i].dot_correction = 0b100001;		// Test pattern
//	      stream.channel[i].grayscale = 0b100000000001;		// Test pattern
		stream.channel[i].dot_correction = 0xF; //MAX_DOT_CORRECTION;
		stream.channel[i].grayscale = 0; //MAX_GRAYSCALE;
	}

	// Write the DC Data
	write_serial_stream();

	//all_white();
	//rgb_display();
	yellow_purple();

	int count = 0;
	while (1)
	{
		if (count %2)
		{
			GPIO_PinOutSet(CONTROL_PORT, GSCLK_PIN);
		}
		else
		{
			GPIO_PinOutClear(CONTROL_PORT, GSCLK_PIN);
		}
		count++;

		if (count > 4096)
		{
			GPIO_PinOutSet(CONTROL_PORT, BLANK_PIN);
			for (volatile int i=0; i < 10; i++)
					;
			GPIO_PinOutClear(CONTROL_PORT, BLANK_PIN);
			count = 0;
		}

		for (volatile int i=0; i < 10; i++)
			;
	}
}