Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Code generated from Atmel Start. |
| 3 | * |
| 4 | * This file will be overwritten when reconfiguring your Atmel Start project. |
| 5 | * Please copy examples or other code you want to keep to a separate file |
| 6 | * to avoid losing it when reconfiguring. |
| 7 | */ |
| 8 | |
| 9 | #include "driver_examples.h" |
| 10 | #include "driver_init.h" |
| 11 | #include "utils.h" |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Example of using UART_debug to write "Hello World" using the IO abstraction. |
Kévin Redon | ccbed0b | 2019-01-24 18:30:26 +0100 | [diff] [blame] | 15 | * |
| 16 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 17 | * because driver initiates transfer and then returns before the transmission is completed. |
| 18 | * |
| 19 | * Once transfer has been completed the tx_cb function will be called. |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 20 | */ |
Kévin Redon | ccbed0b | 2019-01-24 18:30:26 +0100 | [diff] [blame] | 21 | |
| 22 | static uint8_t example_UART_debug[12] = "Hello World!"; |
| 23 | |
| 24 | static void tx_cb_UART_debug(const struct usart_async_descriptor *const io_descr) |
| 25 | { |
| 26 | /* Transfer completed */ |
| 27 | } |
| 28 | |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 29 | void UART_debug_example(void) |
| 30 | { |
| 31 | struct io_descriptor *io; |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 32 | |
Kévin Redon | ccbed0b | 2019-01-24 18:30:26 +0100 | [diff] [blame] | 33 | usart_async_register_callback(&UART_debug, USART_ASYNC_TXC_CB, tx_cb_UART_debug); |
| 34 | /*usart_async_register_callback(&UART_debug, USART_ASYNC_RXC_CB, rx_cb); |
| 35 | usart_async_register_callback(&UART_debug, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 36 | usart_async_get_io_descriptor(&UART_debug, &io); |
| 37 | usart_async_enable(&UART_debug); |
| 38 | |
| 39 | io_write(io, example_UART_debug, 12); |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 40 | } |