Esempio n. 1
0
/** 
 * \brief Initialize SPI external resource for AT25DFx SerialFlash driver.
 *
 *  This function initializes the SerialFlash component as well as the SPI service that
 *  the memory is connected to.
 *  \pre The conf_at25dfx.h file should provide the following information:
 *  - Selection of the SPI service the SerialFlash is connected
 *  (AT25DFX_USES_SPI_MASTER_SERVICE or  AT25DFX_USES_USART_SPI_SERVICE).
 *  - AT25DFX_MEM_SIZE: The SerialFlash type that the driver is connected to.
 *  - AT25DFX_MEM_CNT: The number of SerialFlash components (number of chipselect).
 *  - AT25DFX_SPI_MODULE:  The name of the SPI module used by the SerialFlash driver.
 *  - AT25DFX_SPI_MASTER_SPEED: The SPI bus speed.
 */
void at25dfx_spi_init(void)
{
#if defined( AT25DFX_USES_SPI_MASTER_SERVICE)
	spi_master_init(AT25DFX_SPI_MODULE);
	#if (AT25DFX_MEM_CNT==1)
		spi_master_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE1,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
	#if (AT25DFX_MEM_CNT>1)
		spi_master_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE2,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
	#if (AT25DFX_MEM_CNT>2)
		spi_master_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE3,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
	#if (AT25DFX_MEM_CNT>3)
		spi_master_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE4,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
	spi_enable(AT25DFX_SPI_MODULE);

/* Implementation with USART in SPI mode service */
#elif defined(AT25DFX_USES_USART_SPI_SERVICE)
	usart_spi_init(AT25DFX_SPI_MODULE);
	#if (AT25DFX_MEM_CNT==1)
		usart_spi_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE1,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
	#if (AT25DFX_MEM_CNT>1)
		usart_spi_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE2,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
	#if (AT25DFX_MEM_CNT>2)
		usart_spi_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE3,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
	#if (AT25DFX_MEM_CNT>3)
		usart_spi_setup_device(AT25DFX_SPI_MODULE,&AT25DFX_DEVICE4,SPI_MODE_0,AT25DFX_SPI_MASTER_SPEED,0);
	#endif
#endif
}
Esempio n. 2
0
/*
*	Initialise the SPI interface for the switch
*
*/
void spi_init(void)
{
	/* Config the USART_SPI for KSZ8795 interface */
	usart_spi_init(USART_SPI);
	usart_spi_setup_device(USART_SPI, &USART_SPI_DEVICE, SPI_MODE_3, USART_SPI_BAUDRATE, 0);
	usart_spi_enable(USART_SPI);
}
/**
 * \internal
 * \brief Initialize the hardware interface
 *
 * Depending on what interface used for interfacing the OLED controller this
 * function will initialize the necessary hardware.
 */
static void ssd1306_interface_init(void)
{
#ifdef SSD1306_SERIAL_INTERFACE
	spi_flags_t spi_flags = SPI_MODE_0;
	board_spi_select_id_t spi_select_id = 0;
#endif

#if defined(SSD1306_USART_SPI_INTERFACE)
	struct usart_spi_device device = {
		.id = SSD1306_CS_PIN,
	};
	usart_spi_init(SSD1306_USART_SPI);
	usart_spi_setup_device(SSD1306_USART_SPI, &device, spi_flags,
			SSD1306_CLOCK_SPEED, spi_select_id);
#elif defined(SSD1306_SPI_INTERFACE)
	struct spi_device device = {
		.id = SSD1306_CS_PIN,
	};
	spi_master_init(SSD1306_SPI);
	spi_master_setup_device(SSD1306_SPI, &device, spi_flags,
			SSD1306_CLOCK_SPEED, spi_select_id);
#ifdef SAM
	spi_enable(SSD1306_SPI);
#endif
#endif
}
/*! \brief Main function.
 */
int main(void)
{
	sysclk_init();

	/*
	 * Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();

	/* Config the USART_SPI. */
	usart_spi_init(USART_SPI_EXAMPLE);
	usart_spi_setup_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE,
			SPI_MODE_0, USART_SPI_EXAMPLE_BAUDRATE, 0);
	usart_spi_enable(USART_SPI_EXAMPLE);

	/* Show the test result by LED. */
	if (usart_spi_at45dbx_mem_check() == false) {
#ifndef USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_1,
				IOPORT_PIN_LEVEL_HIGH);
#else
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_1,
				IOPORT_PIN_LEVEL_LOW);
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2,
				IOPORT_PIN_LEVEL_HIGH);
#endif
	} else {
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_1,
				IOPORT_PIN_LEVEL_LOW);
#ifdef USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2,
				IOPORT_PIN_LEVEL_LOW);
#endif
	}

	while (1) {
		/* Do nothing */
	}
}
/**
 * \internal
 * \brief Initialize the hardware interface
 *
 * Depending on what interface used for interfacing the LCD controller this
 * function will initialize the necessary hardware.
 */
static void st7565r_interface_init(void)
{
#ifdef ST7565R_SERIAL_INTERFACE
	spi_flags_t spi_flags = SPI_MODE_3;
	board_spi_select_id_t spi_select_id = 0;
#endif

#if defined(ST7565R_USART_SPI_INTERFACE)
	struct usart_spi_device device = {
		.id = ST7565R_CS_PIN,
	};
	usart_spi_init(ST7565R_USART_SPI);
	usart_spi_setup_device(ST7565R_USART_SPI, &device, spi_flags,
			ST7565R_CLOCK_SPEED, spi_select_id);
#elif defined(ST7565R_SPI_INTERFACE)
	struct spi_device device = {
		.id = ST7565R_CS_PIN,
	};
	spi_master_init(ST7565R_SPI);
	spi_master_setup_device(ST7565R_SPI, &device, spi_flags,
			ST7565R_CLOCK_SPEED, spi_select_id);
#endif
}
Esempio n. 6
0
/*! \brief Main function.
 */
int main(void)
{
	sysclk_init();
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();

	/* Config the USART_SPI in master mode. */
	usart_spi_init(USART_SPI_EXAMPLE);
	usart_spi_setup_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE,
			SPI_MODE_0, USART_SPI_EXAMPLE_BAUDRATE, 0);
	usart_spi_enable(USART_SPI_EXAMPLE);

	/* Config the SPI module in slave mode. */
	spi_slave_init(SPI_SLAVE_EXAMPLE, SPI_MODE_0);
	spi_enable(SPI_SLAVE_EXAMPLE);

	/* Enable global interrupt */
	cpu_irq_enable();

	/* Show the test result by LED. */
	if (spi_usart_master_transfer() == true && spi_slave_transfer() ==
			true) {
		ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN,
				IOPORT_PIN_LEVEL_LOW);
	} else {
		ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN,
				IOPORT_PIN_LEVEL_HIGH);
	}

	while (1) {
		/* Do nothing */
	}
}
/**
 * \internal
 * \brief Initialize the hardware interface to the controller
 *
 * This will initialize the module used for communication with the controller.
 * Currently supported interfaces by this component driver are the SPI
 * interface through either the SPI module in master mode or the USART in
 * Master SPI mode.  Configuration must be done in the associated
 * conf_ili9341.h file.
 */
static void ili9341_interface_init(void)
{
#if defined(CONF_ILI9341_USART_SPI) || defined(CONF_ILI9341_SPI)
	spi_flags_t spi_flags = SPI_MODE_0;
	board_spi_select_id_t spi_select_id = 0;
#else
	#error Interface for ILI9341 has not been selected or interface not\
	supported, please configure component driver using the conf_ili9341.h\
	file!
#endif

#if defined(CONF_ILI9341_USART_SPI)
	struct usart_spi_device device = {
		.id = 0,
	};

	usart_spi_init(CONF_ILI9341_USART_SPI);
	usart_spi_setup_device(CONF_ILI9341_USART_SPI, &device, spi_flags,
			CONF_ILI9341_CLOCK_SPEED, spi_select_id);

#elif defined(CONF_ILI9341_SPI)
	struct spi_device device = {
		.id = 0,
	};

	spi_master_init(CONF_ILI9341_SPI);
	spi_master_setup_device(CONF_ILI9341_SPI, &device, spi_flags,
			CONF_ILI9341_CLOCK_SPEED, spi_select_id);
	spi_enable(CONF_ILI9341_SPI);

#  if UC3
	spi_set_chipselect(CONF_ILI9341_SPI, ~(1 << 0));

#    if defined(ILI9341_DMA_ENABLED)
	sysclk_enable_peripheral_clock(&AVR32_PDCA);
#    endif
#  endif

	/* Send one dummy byte for the spi_is_tx_ok() to work as expected */
	spi_write_single(CONF_ILI9341_SPI, 0);
#endif
}

/**
 * \internal
 * \brief Initialize all the display registers
 *
 * This function will set up all the internal registers according the the
 * manufacturer's description.
 */
static void ili9341_controller_init_registers(void)
{
	ili9341_send_command(ILI9341_CMD_POWER_CONTROL_A);
	ili9341_send_byte(0x39);
	ili9341_send_byte(0x2C);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0x34);
	ili9341_send_byte(0x02);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_POWER_CONTROL_B);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0xAA);
	ili9341_send_byte(0XB0);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_PUMP_RATIO_CONTROL);
	ili9341_send_byte(0x30);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_POWER_CONTROL_1);
	ili9341_send_byte(0x25);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_POWER_CONTROL_2);
	ili9341_send_byte(0x11);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_VCOM_CONTROL_1);
	ili9341_send_byte(0x5C);
	ili9341_send_byte(0x4C);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_VCOM_CONTROL_2);
	ili9341_send_byte(0x94);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_DRIVER_TIMING_CONTROL_A);
	ili9341_send_byte(0x85);
	ili9341_send_byte(0x01);
	ili9341_send_byte(0x78);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_DRIVER_TIMING_CONTROL_B);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0x00);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(ILI9341_CMD_COLMOD_PIXEL_FORMAT_SET);
	ili9341_send_byte(0x05);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_set_orientation(0);
	ili9341_set_limits(0, 0, ILI9341_DEFAULT_WIDTH,
			ILI9341_DEFAULT_HEIGHT);
}

/**
 * \internal
 * \brief Send display commands to exit standby mode
 *
 * This function is used to exit the display standby mode, which is the default
 * mode after a reset signal to the display.
 */
static void ili9341_exit_standby(void)
{
	ili9341_send_command(ILI9341_CMD_SLEEP_OUT);
	ili9341_deselect_chip();
	delay_ms(150);
	ili9341_send_command(ILI9341_CMD_DISPLAY_ON);
	ili9341_deselect_chip();
}
Esempio n. 8
0
/**
 * \internal
 * \brief Initialize the hardware interface to the controller
 *
 * This will initialize the module used for communication with the controller.
 * Currently supported interfaces by this component driver are the SPI
 * interface through either the SPI module in master mode or the USART in
 * Master SPI mode.  Configuration must be done in the associated
 * conf_ili9341.h file.
 */
static void ili9341_interface_init(void)
{
#if defined(CONF_ILI9341_USART_SPI) || defined(CONF_ILI9341_SPI)
	spi_flags_t spi_flags = SPI_MODE_0;
	board_spi_select_id_t spi_select_id = 0;
#else
	#error Interface for ILI9341 has not been selected or interface not\
	supported, please configure component driver using the conf_ili9341.h\
	file!
#endif

#if defined(CONF_ILI9341_USART_SPI)
	struct usart_spi_device device = {
		.id = 0,
	};

	usart_spi_init(CONF_ILI9341_USART_SPI);
	usart_spi_setup_device(CONF_ILI9341_USART_SPI, &device, spi_flags,
			CONF_ILI9341_CLOCK_SPEED, spi_select_id);

#elif defined(CONF_ILI9341_SPI)
	struct spi_device device = {
		.id = 0,
	};

	spi_master_init(CONF_ILI9341_SPI);
	spi_master_setup_device(CONF_ILI9341_SPI, &device, spi_flags,
			CONF_ILI9341_CLOCK_SPEED, spi_select_id);
	spi_enable(CONF_ILI9341_SPI);

#  if UC3
	spi_set_chipselect(CONF_ILI9341_SPI, ~(1 << 0));

#    if defined(ILI9341_DMA_ENABLED)
	sysclk_enable_peripheral_clock(&AVR32_PDCA);
#    endif
#  endif

	/* Send one dummy byte for the spi_is_tx_ok() to work as expected */
	spi_write_single(CONF_ILI9341_SPI, 0);
#endif
}

/**
 * \internal
 * \brief Initialize all the display registers
 *
 * This function will set up all the internal registers according the the
 * manufacturer's description.
 */
static void ili9341_controller_init_registers(void)
{
	ili9341_send_command(0xEF);
	ili9341_send_byte(0x03);
	ili9341_send_byte(0x80);
	ili9341_send_byte(0x02);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xCF);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0xC1);
	ili9341_send_byte(0x30);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xED);
	ili9341_send_byte(0x64);
	ili9341_send_byte(0x03);
	ili9341_send_byte(0x12);
	ili9341_send_byte(0x81);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xE8);
	ili9341_send_byte(0x85);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0x78);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xCB);
	ili9341_send_byte(0x39);
	ili9341_send_byte(0x2C);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0x34);
	ili9341_send_byte(0x02);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xF7);
	ili9341_send_byte(0x20);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xEA);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0x00);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xC0);
	ili9341_send_byte(0x23);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xC1);
	ili9341_send_byte(0x10);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xC5);
	ili9341_send_byte(0x3E);
	ili9341_send_byte(0x28);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xC7);
	ili9341_send_byte(0x86);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0x36);
	ili9341_send_byte(0x48);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0x3A);
	ili9341_send_byte(0x55);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xB1);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0x18);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xB6);
	ili9341_send_byte(0x08);
	ili9341_send_byte(0x82);
	ili9341_send_byte(0x27);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xF2);
	ili9341_send_byte(0x00);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0x26);
	ili9341_send_byte(0x01);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xE0);
	ili9341_send_byte(0x0F);
	ili9341_send_byte(0x31);
	ili9341_send_byte(0x2B);
	ili9341_send_byte(0x0C);
	ili9341_send_byte(0x0E);
	ili9341_send_byte(0x08);
	ili9341_send_byte(0x4E);
	ili9341_send_byte(0xF1);
	ili9341_send_byte(0x37);
	ili9341_send_byte(0x07);
	ili9341_send_byte(0x10);
	ili9341_send_byte(0x03);
	ili9341_send_byte(0x0E);
	ili9341_send_byte(0x09);
	ili9341_send_byte(0x00);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();

	ili9341_send_command(0xE1);
	ili9341_send_byte(0x00);
	ili9341_send_byte(0x0E);
	ili9341_send_byte(0x14);
	ili9341_send_byte(0x03);
	ili9341_send_byte(0x11);
	ili9341_send_byte(0x07);
	ili9341_send_byte(0x31);
	ili9341_send_byte(0xC1);
	ili9341_send_byte(0x48);
	ili9341_send_byte(0x08);
	ili9341_send_byte(0x0F);
	ili9341_send_byte(0x0C);
	ili9341_send_byte(0x31);
	ili9341_send_byte(0x36);
	ili9341_send_byte(0x0F);
	ili9341_wait_for_send_done();
	ili9341_deselect_chip();




	// ili9341_send_command(ILI9341_CMD_POWER_CONTROL_A);
	// ili9341_send_byte(0x39);
	// ili9341_send_byte(0x2C);
	// ili9341_send_byte(0x00);
	// ili9341_send_byte(0x34);
	// ili9341_send_byte(0x02);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_POWER_CONTROL_B);
	// ili9341_send_byte(0x00);
	// ili9341_send_byte(0xAA);
	// ili9341_send_byte(0XB0);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_PUMP_RATIO_CONTROL);
	// ili9341_send_byte(0x30);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_POWER_CONTROL_1);
	// ili9341_send_byte(0x25);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_POWER_CONTROL_2);
	// ili9341_send_byte(0x11);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_VCOM_CONTROL_1);
	// ili9341_send_byte(0x5C);
	// ili9341_send_byte(0x4C);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_VCOM_CONTROL_2);
	// ili9341_send_byte(0x94);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_DRIVER_TIMING_CONTROL_A);
	// ili9341_send_byte(0x85);
	// ili9341_send_byte(0x01);
	// ili9341_send_byte(0x78);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_DRIVER_TIMING_CONTROL_B);
	// ili9341_send_byte(0x00);
	// ili9341_send_byte(0x00);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	// ili9341_send_command(ILI9341_CMD_COLMOD_PIXEL_FORMAT_SET);
	// ili9341_send_byte(0x05);
	// ili9341_wait_for_send_done();
	// ili9341_deselect_chip();

	ili9341_set_orientation(0);
	ili9341_set_limits(0, 0, ILI9341_DEFAULT_WIDTH,
			ILI9341_DEFAULT_HEIGHT);
}


void ili9341_enter_standby(void) {
	ili9341_send_command(ILI9341_CMD_ENTER_SLEEP_MODE);
	ili9341_deselect_chip();
}