/** Initializes the sensor platform - as this calls the board and sysclock * init functions internally, it will also wait for any pending serial * transfer(s) to complete before calling sensor_platform_init() and will * re-initialize the USART afterwards to ensure no corrupt or lost data. */ static void configure_sensor_platform(void) { #if XMEGA usart_clear_tx_complete(CONF_TEST_USART); while (!usart_tx_is_complete(CONF_TEST_USART)); #elif UC3 while (!(usart_tx_empty(CONF_TEST_USART))); #endif sensor_platform_init(); stdio_serial_init(CONF_TEST_USART, &usart_serial_options); }
/*! \brief Main function. */ int main(void) { uint8_t tx_buf[] = "\n\rHello AVR world ! : "; uint8_t i; /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ board_init(); sysclk_init(); pmic_init(); cpu_irq_enable(); sleepmgr_init(); sleepmgr_lock_mode(SLEEPMGR_STDBY); /* USART options. */ static usart_xmegae_rs232_options_t USART_SERIAL_OPTIONS = { .baudrate = USART_SERIAL_EXAMPLE_BAUDRATE, .charlength = USART_SERIAL_CHAR_LENGTH, .paritytype = USART_SERIAL_PARITY, .stopbits = USART_SERIAL_STOP_BIT, .start_frame_detection = false, .one_wire = false, .pec_length = USART_SERIAL_VARIABLE_CHAR_LENGTH, .pec_action = USART_PECACT_PERC01_gc, .encoding_type = USART_DECTYPE_DATA_gc, .encoding_stream = USART_LUTACT_OFF_gc, }; /* Initialize usart driver in RS232 mode */ usart_xmegae_init_rs232(USART_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS); usart_set_rx_interrupt_level(USART_SERIAL_EXAMPLE, USART_INT_LVL_LO); /* Send "message header" */ for (i = 0; i < sizeof(tx_buf); i++) { usart_putchar(USART_SERIAL_EXAMPLE, tx_buf[i]); while (!usart_tx_is_complete(USART_SERIAL_EXAMPLE)) { } usart_clear_tx_complete(USART_SERIAL_EXAMPLE); } /* Incoming character is process under interrupt * main loop simply enters sleep mode */ while (true) { sleepmgr_enter_sleep(); } }
/** * \internal * \brief Helper function to wait for the last send operation to complete */ __always_inline static void ili9341_wait_for_send_done(void) { #if defined(CONF_ILI9341_USART_SPI) # if XMEGA while (!usart_tx_is_complete(CONF_ILI9341_USART_SPI)) { /* Do nothing */ } usart_clear_tx_complete(CONF_ILI9341_USART_SPI); # else /* Wait for TX to complete */ while (!usart_spi_is_tx_empty(CONF_ILI9341_USART_SPI)) { /* Do nothing */ } # endif #elif defined(CONF_ILI9341_SPI) /* Wait for TX to complete */ while (!spi_is_tx_empty(CONF_ILI9341_SPI)) { /* Do nothing */ } #endif }
/** * \internal * \brief Helper function to send a byte over an arbitrary interface * * This function is used to hide what interface is used by the component * driver, e.g. the component driver does not need to know if USART in SPI * mode is used or the native SPI module. * * \param data The byte to be transfered */ __always_inline static void ili9341_send_byte(uint8_t data) { #if defined(CONF_ILI9341_USART_SPI) # if XMEGA while (!usart_data_register_is_empty(CONF_ILI9341_USART_SPI)) { /* Do nothing */ } irqflags_t flags = cpu_irq_save(); usart_clear_tx_complete(CONF_ILI9341_USART_SPI); usart_put(CONF_ILI9341_USART_SPI, data); cpu_irq_restore(flags); # else usart_spi_write_single(CONF_ILI9341_USART_SPI, data); # endif #elif defined(CONF_ILI9341_SPI) /* Wait for any previously running send data */ ili9341_wait_for_send_done(); spi_write_single(CONF_ILI9341_SPI, data); #endif }
/*! \brief Main function. */ int main(void) { uint8_t encoded_message[] = { 0xF2, 0xF5, 0xAB, 0x97, 0x96, 0x8C, 0xDF, 0x96, 0x91, 0xDF, 0x9E, 0x91, 0xDF, 0x9A, 0x91, 0x9C, 0x90, 0x9B, 0x9A, 0x9B, 0xDF, 0x92, 0x9A, 0x8C, 0x8C, 0x9E, 0x98, 0x9A, 0xDF, 0x8C, 0x9A, 0x91, 0x8B, 0xDF, 0x99, 0x8D, 0x90, 0x92, 0xDF, 0xA7, 0xB2, 0xBA, 0xB8, 0xBE, 0xDF, 0xAA, 0xAC, 0xBE, 0xAD, 0xAB, 0xDE }; uint8_t i; /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ board_init(); sysclk_init(); pmic_init(); cpu_irq_enable(); sleepmgr_init(); sleepmgr_lock_mode(SLEEPMGR_STDBY); /* USART options. */ static usart_xmegae_rs232_options_t USART_SERIAL_OPTIONS = { .baudrate = USART_SERIAL_EXAMPLE_BAUDRATE, .charlength = USART_SERIAL_CHAR_LENGTH, .paritytype = USART_SERIAL_PARITY, .stopbits = USART_SERIAL_STOP_BIT, .start_frame_detection = false, .one_wire = false, .pec_length = USART_SERIAL_VARIABLE_CHAR_LENGTH, .pec_action = USART_PECACT_PERC01_gc, .encoding_type = USART_DECTYPE_DATA_gc, .encoding_stream = USART_LUTACT_BOTH_gc, }; /* Initialize usart driver in RS232 mode */ usart_xmegae_init_rs232(USART_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS); usart_set_rx_interrupt_level(USART_SERIAL_EXAMPLE, USART_INT_LVL_LO); xcl_port(USART_SERIAL_XCL_PORT); xcl_lut_type(LUT_2LUT2IN); xcl_lut_in0(USART_SERIAL_LUT_IN_PIN); xcl_lut_in1(LUT_IN_XCL); xcl_lut0_output(LUT0_OUT_DISABLE); xcl_lut_config_delay(DLY11, LUT_DLY_DISABLE, LUT_DLY_DISABLE); xcl_lut0_truth(NOT_IN0); xcl_lut_in2(LUT_IN_XCL); xcl_lut_in3(LUT_IN_XCL); xcl_lut1_truth(NOT_IN3); /* Send "message header" */ for (i = 0; i < sizeof(encoded_message); i++) { usart_putchar(USART_SERIAL_EXAMPLE, encoded_message[i]); while (!usart_tx_is_complete(USART_SERIAL_EXAMPLE)) { } usart_clear_tx_complete(USART_SERIAL_EXAMPLE); } /* Incoming character is process under interrupt * main loop simply enters sleep mode */ while (true) { sleepmgr_enter_sleep(); } }