File Dma_Fifo_Receive.cpp¶
File List > Dma_Fifo_Receive > Dma_Fifo_Receive.cpp
Go to the documentation of this file
Source Code¶
#include "daisy_patch.h"
using namespace daisy;
const size_t kUartBufferSize = 512;
DaisyPatch hw;
UartHandler uart;
uint8_t uart_buffer[kUartBufferSize];
char receive_str[kUartBufferSize];
void uartCallback(uint8_t* data,
size_t size,
void* context,
UartHandler::Result res)
{
std::fill(&receive_str[0], &receive_str[kUartBufferSize - 1], 0);
std::copy(&data[0], &data[size - 1], &receive_str[0]);
}
int main(void)
{
// Initialize the Daisy Patch
hw.Init();
// Configure the Uart Peripheral
UartHandler::Config uart_conf;
uart_conf.periph = UartHandler::Config::Peripheral::USART_1;
uart_conf.mode = UartHandler::Config::Mode::RX;
uart_conf.pin_config.tx = Pin(PORTB, 6);
uart_conf.pin_config.rx = Pin(PORTB, 7);
// Initialize the Uart Peripheral
uart.Init(uart_conf);
uart.DmaListenStart(uart_buffer, kUartBufferSize, uartCallback, nullptr);
while(1)
{
// clear the display
hw.display.Fill(false);
// draw the title text
char cstr[26];
sprintf(cstr, "Uart DMA Fifo Rx");
hw.display.SetCursor(0, 0);
hw.display.WriteString(cstr, Font_7x10, true);
// draw the last popped data
hw.display.SetCursor(0, 12);
hw.display.WriteString(receive_str, Font_7x10, true);
// update the display
hw.display.Update();
// wait 100 ms
System::Delay(100);
}
}