Related pages:
// *************************************************************** // ** CONFIGURATION WITH USB ** // *************************************************************** //! The following clock configuraiton can be used for USB operation //! It allows to operate USB using On-Chip RC oscillator at 48MHz //! The RC oscillator is calibrated via USB Start Of Frame //! Clk USB = 48MHz (used by USB) //! Clk sys = 48MHz //! Clk cpu/per = 24MHz #define CONFIG_USBCLK_SOURCE USBCLK_SRC_RCOSC #define CONFIG_OSC_RC32_CAL 48000000UL #define CONFIG_OSC_AUTOCAL OSC_ID_RC32MHZ #define CONFIG_OSC_AUTOCAL_REF_OSC OSC_ID_USBSOF #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC32MHZ #define CONFIG_SYSCLK_PSADIV SYSCLK_PSADIV_2 #define CONFIG_SYSCLK_PSBCDIV SYSCLK_PSBCDIV_1_1
//! Device definition (mandatory) #define USB_DEVICE_VENDOR_ID 0x03EB #define USB_DEVICE_PRODUCT_ID 0x2404
/** * \file stdio_demo.h * \date 2011-11-13 * \brief Stdin / Stdout Demo * \author Rolf Hemmerling, http://www.hemmerling.com */ #ifndef STDIO_DEMO_H_ #define STDIO_DEMO_H_ // #define USE_EXTERNAL_STDIOLIB #undef USE_EXTERNAL_STDIOLIB #include <asf.h> #include <stdio.h> #include <sleepmgr.h> #include <sysclk.h> void system_init(void); void graphics_welcome(void); void graphics_print(uint32_t aValue); void communication_welcome(void); int communication_start(void); void avrstdio_demo(void); int main(void); #endif /* STDIO_DEMO_H_ */
/** * \file stdio_demo.h * \date 2011-11-13 * \brief Stdin / Stdout Demo * \author Rolf Hemmerling, http://www.hemmerling.com */ #include "avrstdio.h" #include "stdio_demo.h" FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); FILE uart_str_external = FDEV_SETUP_STREAM(uart_putchar_external, uart_getchar_external, _FDEV_SETUP_RW); /** * \brief General system initialization */ void system_init(void) { /* Initialize the microcontroller board */ board_init(); /* Initialize and enable the ITs routine */ irq_initialize_vectors(); cpu_irq_enable(); /* Initialize the sleep manager service */ sleepmgr_init(); /* Initialize the clock service */ sysclk_init(); } /** * \brief Print a welcome message on the graphics system of XMEGA-A3BU */ void graphics_welcome(void) { /** * After initialization the example will write the "Stdin / Stdout Demo" * to position 0, 0 on the display. * Use the system font sysfont. */ gfx_mono_init(); ioport_set_pin_high(NHD_C12832A1Z_BACKLIGHT); st7565r_set_contrast ( ST7565R_DISPLAY_CONTRAST_MIN ); gfx_mono_draw_string("Stdin / Stdout Demo", 0, 0, &sysfont); } /** * \brief Print a number on the graphics system of XMEGA-A3BU */ void graphics_print(uint32_t aValue) { char aStringBuf[15]; snprintf(aStringBuf, sizeof(aStringBuf), "%12lu", aValue); gfx_mono_draw_string(aStringBuf, 8, 8, &sysfont); } /** * \brief Print a welcome message by Stdout */ void communication_welcome(void) { printf("Stdin / Stdout Demo\n"); } /** * \brief Start of the Stdin / Stdout communication */ int communication_start(void) { int aKeyboardInput = 0; /* Wait for a single "blindly typed" keyboard input */ while (aKeyboardInput == 0) { aKeyboardInput = getchar(); }; return (aKeyboardInput); } /** * \brief Demo of communication by Stdin / Stdout */ void avrstdio_demo(void) { int aStartCommand; graphics_welcome(); #ifdef USE_EXTERNAL_STDIOLIB avrstdio_start_external(); stdout = &uart_str_external; stdin = &uart_str_external; #else avrstdio_start(); stdout = &uart_str; stdin = &uart_str; #endif aStartCommand = communication_start(); communication_welcome(); uint32_t aCounter = 0u; while (true) { graphics_print(aCounter); printf("-Hello World %12lu-", aCounter); aCounter++; } } /** * \brief Main entry of example application */ int main(void) { system_init(); avrstdio_demo(); }
/** * \file avrstdio.h * \date 2011-11-13 * \brief Stdin / Stdout for Atmel AVR XMEGA-A3BU Xplained kit", by CDC protocol via USB * \author Rolf Hemmerling, http://www.hemmerling.com * * \details Include these statements in your applicatation * FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); * stdout = &uart_str; * stdin = &uart_str; */ #ifndef AVRSTDIO_H_ #define AVRSTDIO_H_ #include <asf.h> #include <stdio.h> #include <sleepmgr.h> #include <sysclk.h> #include <udc.h> int uart_putchar(char c, FILE *stream); int uart_getchar(FILE *stream); void avrstdio_start(void); void avrstdio_stop(void); int uart_putchar_external(char c, FILE *stream); int uart_getchar_external(FILE *stream); void avrstdio_start_external(void); void avrstdio_stop_external(void); #endif /* AVRSTDIO_H_ */
/** * \file avrstdio.c * \date 2011-11-13 * \brief Stdin / Stdout for Atmel AVR XMEGA-A3BU Xplained kit", by CDC protocol via USB * \author Rolf Hemmerling, http://www.hemmerling.com */ #include "avrstdio.h" /** * \brief Send character c to CDC */ int uart_putchar(char c, FILE *stream) { if (c == '\n') uart_putchar('\r', stream); udi_cdc_putc(c); return 0; } /** * \brief Receive a character by CDC. */ int uart_getchar(FILE *stream) { uint8_t c; c = udi_cdc_getc(); return c; } /** * \brief Initialization of the Stdio communication */ void avrstdio_start(void) { /* Initialize the microcontroller board */ // board_init(); /* Initialize and enable the ITs routine */ // irq_initialize_vectors(); // cpu_irq_enable(); /* Initialize the sleep manager service */ // sleepmgr_init(); /* Initialize the clock service */ // sysclk_init(); /* Enable the USB device stack */ udc_start(); /* Attach the USB device to the host ( to start communications ) */ udc_attach(); } /** * \brief Stop of the Stdio communication */ void avrstdio_stop(void) { // By stopping USB communications during the application runtime, // you risk that some previous output is not delivered :-( // If you don't delay the stop of the USB connection, there will be no output. // cdc_delay(); /* Detach the USB device to the host ( to start communications ) */ // udc_detach(); /* Disable the USB device stack */ // udc_stop(); // cpu_irq_disable(); }
int aKeyboardInput = 0; while (aKeyboardInput == 0) { aKeyboardInput = udi_cdc_getc(); };
int aKeyboardInput = 0; while (aKeyboardInput == 0) { aKeyboardInput = getchar(); };