示例#1
0
/**
 * \brief Set the baudrate using precalculated BAUDCTRL values from PROGMEM
 *
 * \note This function only works for cpu_hz 2Mhz or 32Mhz and baudrate values
 * 1200, 2400, 4800, 9600, 19200, 38400 and 57600.
 *
 * \param usart  The USART module.
 * \param baud   The baudrate.
 * \param cpu_hz The CPU frequency.
 *
 */
void usart_set_baudrate_precalculated(USART_t *usart, uint32_t baud,
                                      uint32_t cpu_hz)
{
    uint8_t baud_offset;
    uint16_t baudctrl = 0;

    baud_offset = usart_get_baud_offset(baud);

    if (cpu_hz == 2000000UL) {
        baudctrl = PROGMEM_READ_WORD(baudctrl_2mhz + baud_offset);
    } else if (cpu_hz == 32000000UL) {
        baudctrl = PROGMEM_READ_WORD(baudctrl_32mhz + baud_offset);
    } else {
        /* Error, system clock speed or USART baud rate is not supported
        by the look-up table */
        Assert(false);
    }
    if (baud_offset != USART_BAUD_UNDEFINED) {
        (usart)->BAUDCTRLB = (uint8_t)((uint16_t)baudctrl);
        (usart)->BAUDCTRLA = (uint8_t)((uint16_t)baudctrl >> 8);
    }
示例#2
0
/**
 * \brief Set the baudrate using pre calculated BAUDCTRL values stored in program 
 * memory
 *
 * \note This function only works for cpu_hz 1Mhz, 8Mhz or 16Mhz and baudrate values
 * 1200, 2400, 4800, 9600, 19200, 38400 and 57600.
 *
 * \param usart  The USART module.
 * \param baud   The baudrate.
 * \param cpu_hz The CPU frequency.
 *
 */
void usart_set_baudrate_precalculated(USART_t *usart, uint32_t baud,
		uint32_t cpu_hz)
{
	uint8_t baud_offset;
	uint16_t baudctrl = 0;

	baud_offset = usart_get_baud_offset(baud);

	if (cpu_hz == 1000000UL) {
		baudctrl = PROGMEM_READ_WORD(baudctrl_1mhz + baud_offset);
	} else if (cpu_hz == 8000000UL) {
		baudctrl = PROGMEM_READ_WORD(baudctrl_8mhz + baud_offset);
	} else if (cpu_hz == 16000000UL) {
		baudctrl = PROGMEM_READ_WORD(baudctrl_16mhz + baud_offset);
	} else {
		/* Error, system clock speed or USART baud rate is not supported
		 * by the look-up table */
		Assert(false);
	}

	if (baud_offset != USART_BAUD_UNDEFINED) {
		usart->UBRR = baudctrl;
	}
}
/**
 * \brief Copy pixels from progmem to the screen
 *
 * This function can be used to copy data from program memory (flash) to the
 * display.
 *
 * Limits have to be set prior to calling this function, e.g.:
 * \code
 * ili9341_set_top_left_limit(0, 0);
 * ili9341_set_bottom_right_limit(320, 240);
 * ...
 * \endcode
 *
 * \param pixels Pointer to the progmem data
 * \param count Number of pixels to write
 */
void ili9341_copy_progmem_pixels_to_screen(
		ili9341_color_t PROGMEM_PTR_T pixels, uint32_t count)
{
	ili9341_color_t color;

	/* Sanity check to make sure that the pixel count is not zero */
	Assert(count > 0);

	ili9341_send_command(ILI9341_CMD_MEMORY_WRITE);

	while (count--) {
		color = PROGMEM_READ_WORD(pixels);

		ili9341_send_byte(color);
		ili9341_send_byte(color >> 8);

		pixels++;
	}

	ili9341_wait_for_send_done();
	ili9341_deselect_chip();
}