Exemplo n.º 1
0
bool PIOS_Hsync_ISR() {

	if(dev_cfg->hsync->pin.gpio->IDR & dev_cfg->hsync->pin.init.GPIO_Pin) {
		//rising
		if(gLineType == LINE_TYPE_GRAPHICS)
		{
			// Activate new line
			DMA_Cmd(dev_cfg->level.dma.tx.channel, ENABLE);
			DMA_Cmd(dev_cfg->mask.dma.tx.channel, ENABLE);
		}
	} else {
		//falling
		gLineType = LINE_TYPE_UNKNOWN; // Default case
		gActiveLine++;

		if ((gActiveLine >= GRAPHICS_LINE) && (gActiveLine < (GRAPHICS_LINE + GRAPHICS_HEIGHT))) {
			gLineType = LINE_TYPE_GRAPHICS;
			gActivePixmapLine = (gActiveLine - GRAPHICS_LINE);
			line = gActivePixmapLine*GRAPHICS_WIDTH;
		}

		if(gLineType == LINE_TYPE_GRAPHICS)
		{
			// Load new line
			DMA_Cmd(dev_cfg->mask.dma.tx.channel, DISABLE);
			DMA_Cmd(dev_cfg->level.dma.tx.channel, DISABLE);
			DMA_MemoryTargetConfig(dev_cfg->level.dma.tx.channel,(uint32_t)&disp_buffer_level[line],DMA_Memory_0);
			DMA_MemoryTargetConfig(dev_cfg->mask.dma.tx.channel,(uint32_t)&disp_buffer_mask[line],DMA_Memory_0);
			DMA_SetCurrDataCounter(dev_cfg->level.dma.tx.channel,BUFFER_LINE_LENGTH);
			DMA_SetCurrDataCounter(dev_cfg->mask.dma.tx.channel,BUFFER_LINE_LENGTH);
		}
	}

	return false;
}
Exemplo n.º 2
0
/**
 * Prepare the system to watch for a HSYNC pulse to trigger the pixel
 * clock and clock out the next line
 */
static void prepare_line(uint32_t line_num)
{
    if (line_num < GRAPHICS_HEIGHT) {
        uint32_t buf_offset = line_num * GRAPHICS_WIDTH;

        dev_cfg->pixel_timer.timer->CNT = dc;

        DMA_ClearFlag(dev_cfg->mask.dma.tx.channel, DMA_FLAG_TCIF7 | DMA_FLAG_HTIF7 | DMA_FLAG_FEIF7 | DMA_FLAG_TEIF7);
        DMA_ClearFlag(dev_cfg->level.dma.tx.channel, DMA_FLAG_FEIF5 | DMA_FLAG_TEIF5);

        // Load new line
        DMA_MemoryTargetConfig(dev_cfg->level.dma.tx.channel, (uint32_t)&disp_buffer_level[buf_offset], DMA_Memory_0);
        DMA_MemoryTargetConfig(dev_cfg->mask.dma.tx.channel, (uint32_t)&disp_buffer_mask[buf_offset], DMA_Memory_0);

        // Enable DMA, Slave first
        DMA_SetCurrDataCounter(dev_cfg->level.dma.tx.channel, BUFFER_LINE_LENGTH);
        DMA_SetCurrDataCounter(dev_cfg->mask.dma.tx.channel, BUFFER_LINE_LENGTH);

        SPI_Cmd(dev_cfg->level.regs, ENABLE);
        SPI_Cmd(dev_cfg->mask.regs, ENABLE);

        /* Enable SPI interrupts to DMA */
        SPI_I2S_DMACmd(dev_cfg->mask.regs, SPI_I2S_DMAReq_Tx, ENABLE);
        SPI_I2S_DMACmd(dev_cfg->level.regs, SPI_I2S_DMAReq_Tx, ENABLE);

        DMA_Cmd(dev_cfg->level.dma.tx.channel, ENABLE);
        DMA_Cmd(dev_cfg->mask.dma.tx.channel, ENABLE);
    }
    reset_hsync_timers();
}
Exemplo n.º 3
0
//эта функция читает из фрам через SPI в буфер flashBuffIn не более SIZE_BUF_FLASH байт
//после чтения из буфера flashBuffIn копируется в destination
void flashMx25Read(void *destination, uint32_t adrSource, uint16_t size)
{
	xSemaphoreTake(mutexFlash, portMAX_DELAY);
	if( !isInitial )
		initSpi2();
	uint16_t status;
	do
	{
		status = spiRDSR();
	} while(status & 1);
	if( size > SIZE_BUF_FLASH )
	{
		xSemaphoreGive(mutexFlash);
		return;
	}
	DMA_MemoryTargetConfig(DMA1_Stream3, (uint32_t)flashBuffIn, 0);
	flashBuffOut[0] = 3; //Command Read
	flashBuffOut[1] = adrSource >> 16;
	flashBuffOut[2] = adrSource >> 8;
	flashBuffOut[3] = adrSource;
	startSpi(size + 4);
	spiWait();
	memcpy(destination, (void*)(flashBuffIn + 4), size);
	xSemaphoreGive(mutexFlash);
}
Exemplo n.º 4
0
void uartStartTxDMA(uartPort_t *s)
{
#ifdef STM32F40_41xxx
    DMA_Cmd(s->txDMAStream, DISABLE);
    DMA_MemoryTargetConfig(s->txDMAStream,(uint32_t)&s->port.txBuffer[s->port.txBufferTail],DMA_Memory_0);
    //s->txDMAStream->M0AR = (uint32_t)&s->port.txBuffer[s->port.txBufferTail];
    if (s->port.txBufferHead > s->port.txBufferTail) {
        s->txDMAStream->NDTR = s->port.txBufferHead - s->port.txBufferTail;
        s->port.txBufferTail = s->port.txBufferHead;
    } else {
        s->txDMAStream->NDTR = s->port.txBufferSize - s->port.txBufferTail;
        s->port.txBufferTail = 0;
    }
    s->txDMAEmpty = false;
    DMA_Cmd(s->txDMAStream, ENABLE);
#else
    s->txDMAChannel->CMAR = (uint32_t)&s->port.txBuffer[s->port.txBufferTail];
    if (s->port.txBufferHead > s->port.txBufferTail) {
        s->txDMAChannel->CNDTR = s->port.txBufferHead - s->port.txBufferTail;
        s->port.txBufferTail = s->port.txBufferHead;
    } else {
        s->txDMAChannel->CNDTR = s->port.txBufferSize - s->port.txBufferTail;
        s->port.txBufferTail = 0;
    }
    s->txDMAEmpty = false;
    DMA_Cmd(s->txDMAChannel, ENABLE);
#endif
}
Exemplo n.º 5
0
void spi_write(uint8_t* pBuffer, unsigned int size) {
	if (size > SIZE_BIG_BUFFER)
		return;
	pb_spi = alloc_buf(SIZE_BIG_BUFFER);
	memcpy(pb_spi->pbuf, pBuffer, size);
	DMA_MemoryTargetConfig(DMA1_Stream5, (uint32_t)pb_spi->pbuf, 0);
	DMA_Cmd(DMA1_Stream5, ENABLE);
}
Exemplo n.º 6
0
//эта функция читает сразу из фрамки по SPI через DMA в destination
void flashMx25ReadData(uint8_t *destination, uint32_t adrSource, uint16_t size,
		bool fromISR)
{
	xSemaphoreTake(mutexFlash, portMAX_DELAY);
	uint16_t status;
	do
	{
		status = spiRDSR();
	} while(status & 1);
	if( size > 4096 )
	{
		xSemaphoreGive(mutexFlash);
		return;
	}
	DMA_MemoryTargetConfig(DMA1_Stream3, (uint32_t)destination, 0);
	flashBuffOut[0] = 3; //Command Read
	flashBuffOut[1] = adrSource >> 16;
	flashBuffOut[2] = adrSource >> 8;
	flashBuffOut[3] = adrSource;
	startSpi(size + 4);
	spiWait();
	DMA_MemoryTargetConfig(DMA1_Stream3, (uint32_t)flashBuffIn, 0);
	xSemaphoreGive(mutexFlash);
}
Exemplo n.º 7
0
/**
 * @brief Swap DMA image buffer addresses
 */
void dma_swap_buffers(void)
{
	/* check which buffer is in use */
	if (DMA_GetCurrentMemoryTarget(DMA2_Stream1))
	{
		/* swap dcmi image buffer */
		if (dcmi_image_buffer_unused == 1)
			DMA_MemoryTargetConfig(DMA2_Stream1, (uint32_t) dcmi_image_buffer_8bit_1, DMA_Memory_0);
		else if (dcmi_image_buffer_unused == 2)
			DMA_MemoryTargetConfig(DMA2_Stream1, (uint32_t) dcmi_image_buffer_8bit_2, DMA_Memory_0);
		else
			DMA_MemoryTargetConfig(DMA2_Stream1, (uint32_t) dcmi_image_buffer_8bit_3, DMA_Memory_0);

		int tmp_buffer = dcmi_image_buffer_memory0;
		dcmi_image_buffer_memory0 = dcmi_image_buffer_unused;
		dcmi_image_buffer_unused = tmp_buffer;
	}
	else
	{
		/* swap dcmi image buffer */
		if (dcmi_image_buffer_unused == 1)
			DMA_MemoryTargetConfig(DMA2_Stream1, (uint32_t) dcmi_image_buffer_8bit_1, DMA_Memory_1);
		else if (dcmi_image_buffer_unused == 2)
			DMA_MemoryTargetConfig(DMA2_Stream1, (uint32_t) dcmi_image_buffer_8bit_2, DMA_Memory_1);
		else
			DMA_MemoryTargetConfig(DMA2_Stream1, (uint32_t) dcmi_image_buffer_8bit_3, DMA_Memory_1);

		int tmp_buffer = dcmi_image_buffer_memory1;
		dcmi_image_buffer_memory1 = dcmi_image_buffer_unused;
		dcmi_image_buffer_unused = tmp_buffer;
	}

	/* set next time_between_images */
	cycle_time = get_boot_time_us() - time_last_frame;
	time_last_frame = get_boot_time_us();

	if(image_counter) // image was not fetched jet
	{
		time_between_next_images = time_between_next_images + cycle_time;
	}
	else
	{
		time_between_next_images = cycle_time;
	}

	/* set new image true and increment frame counter*/
	image_counter += 1;

	return;
}