|
| 1 | +/** TODO fix / remove this example |
| 2 | + * anticipated issue that it only shows 1 byte every 100ms |
| 3 | + * which may be misleading to user |
| 4 | + * |
| 5 | + * also, it should probably use serial print to pipe out |
| 6 | + * data instead of the patch's display. |
| 7 | + */ |
1 | 8 | #include "daisy_patch.h" |
2 | 9 |
|
3 | 10 | using namespace daisy; |
4 | 11 |
|
5 | | -DaisyPatch hw; |
| 12 | +/** Consts */ |
| 13 | +const size_t kUartBufferSize = 512; |
| 14 | + |
| 15 | +DaisyPatch hw; |
6 | 16 | UartHandler uart; |
| 17 | +uint8_t uart_buffer[kUartBufferSize]; |
| 18 | +char receive_str[kUartBufferSize]; |
| 19 | + |
| 20 | +/** Happens automatically whenever transaction completes */ |
| 21 | +void uartCallback(uint8_t* data, |
| 22 | + size_t size, |
| 23 | + void* context, |
| 24 | + UartHandler::Result res) |
| 25 | +{ |
| 26 | + /** Clear receive_str */ |
| 27 | + std::fill(&receive_str[0], &receive_str[kUartBufferSize - 1], 0); |
| 28 | + /** Copy new data into the receive str */ |
| 29 | + std::copy(&data[0], &data[size - 1], &receive_str[0]); |
| 30 | +} |
7 | 31 |
|
8 | 32 | int main(void) |
9 | 33 | { |
10 | | - // Initialize the Daisy Patch |
11 | | - hw.Init(); |
12 | | - |
13 | | - // Configure the Uart Peripheral |
14 | | - UartHandler::Config uart_conf; |
15 | | - uart_conf.periph = UartHandler::Config::Peripheral::USART_1; |
16 | | - uart_conf.mode = UartHandler::Config::Mode::RX; |
17 | | - uart_conf.pin_config.tx = Pin(PORTB, 6); |
18 | | - uart_conf.pin_config.rx = Pin(PORTB, 7); |
19 | | - |
20 | | - // Initialize the Uart Peripheral |
21 | | - uart.Init(uart_conf); |
22 | | - |
23 | | - // Start the FIFO Receive |
24 | | - uart.DmaReceiveFifo(); |
25 | | - |
26 | | - uint8_t pop = 0; |
27 | | - while(1) { |
28 | | - // if there's data, pop it from the FIFO |
29 | | - if(uart.ReadableFifo()){ |
30 | | - pop = uart.PopFifo(); |
31 | | - hw.seed.SetLed(false); |
32 | | - } |
33 | | - else{ |
34 | | - hw.seed.SetLed(true); |
35 | | - } |
36 | | - |
37 | | - // clear the display |
| 34 | + // Initialize the Daisy Patch |
| 35 | + hw.Init(); |
| 36 | + |
| 37 | + // Configure the Uart Peripheral |
| 38 | + UartHandler::Config uart_conf; |
| 39 | + uart_conf.periph = UartHandler::Config::Peripheral::USART_1; |
| 40 | + uart_conf.mode = UartHandler::Config::Mode::RX; |
| 41 | + uart_conf.pin_config.tx = Pin(PORTB, 6); |
| 42 | + uart_conf.pin_config.rx = Pin(PORTB, 7); |
| 43 | + |
| 44 | + // Initialize the Uart Peripheral |
| 45 | + uart.Init(uart_conf); |
| 46 | + uart.DmaListenStart(uart_buffer, kUartBufferSize, uartCallback, nullptr); |
| 47 | + |
| 48 | + while(1) |
| 49 | + { |
| 50 | + // clear the display |
38 | 51 | hw.display.Fill(false); |
39 | 52 |
|
40 | | - // draw the title text |
| 53 | + // draw the title text |
41 | 54 | char cstr[26]; |
42 | 55 | sprintf(cstr, "Uart DMA Fifo Rx"); |
43 | 56 | hw.display.SetCursor(0, 0); |
44 | 57 | hw.display.WriteString(cstr, Font_7x10, true); |
45 | 58 |
|
46 | | - // draw the last popped data |
47 | | - sprintf(cstr, "%d", pop); |
| 59 | + // draw the last popped data |
48 | 60 | hw.display.SetCursor(0, 12); |
49 | | - hw.display.WriteString(cstr, Font_7x10, true); |
50 | | - |
51 | | - // update the display |
52 | | - hw.display.Update(); |
| 61 | + hw.display.WriteString(receive_str, Font_7x10, true); |
| 62 | + |
| 63 | + // update the display |
| 64 | + hw.display.Update(); |
53 | 65 |
|
54 | | - // wait 100 ms |
| 66 | + // wait 100 ms |
55 | 67 | System::Delay(100); |
56 | | - } |
| 68 | + } |
57 | 69 | } |
0 commit comments