00001
00038 #include <led.h>
00039 #include <gpio.h>
00040 #include <board.h>
00041 #include <interrupt.h>
00042
00043 #include <chip/regs.h>
00044
00045 void board_init(void)
00046 {
00047 uint8_t mcucr;
00048 irqflags_t iflags;
00049
00050
00051
00052
00053
00054 iflags = cpu_irq_save();
00055
00056
00057 mcucr = avr_read_reg8(MCUCR) | AVR_BIT(MCUCR_JTD);
00058 avr_write_reg8(MCUCR, mcucr);
00059 avr_write_reg8(MCUCR, mcucr);
00060
00061 cpu_irq_restore(iflags);
00062
00063
00064 port_select_gpio_pin(BOARD_XMEGA_RESET_ID,
00065 GPIO_DIR_OUTPUT | GPIO_INIT_LOW);
00066
00067
00068
00069
00070
00071 port_select_gpio_pin(BOARD_LED_RED, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
00072 port_select_gpio_pin(BOARD_USB_MODE_ID, GPIO_DIR_INPUT | GPIO_PULL_UP);
00073
00074
00075 board_gpio_set_spi_master_mode(true);
00076 }
00077
00085 void board_gpio_mcu_reset(bool set)
00086 {
00087 gpio_set_value(BOARD_XMEGA_RESET_ID, !set);
00088 }
00089
00096 bool board_gpio_is_usb_msc_mode(void)
00097 {
00098 return !gpio_get_value(BOARD_USB_MODE_ID);
00099 }
00100
00107 void board_gpio_set_spi_master_mode(bool master_mode)
00108 {
00109 if (master_mode) {
00110
00111 port_select_gpio_pin(BOARD_SPI_SCK_ID, GPIO_DIR_OUTPUT);
00112 port_select_gpio_pin(BOARD_SPI_MOSI_ID, GPIO_DIR_OUTPUT);
00113 port_select_gpio_pin(BOARD_SPI_MISO_ID, GPIO_DIR_INPUT);
00114 } else {
00115
00116 port_select_gpio_pin(BOARD_SPI_SCK_ID, GPIO_DIR_INPUT);
00117 port_select_gpio_pin(BOARD_SPI_MOSI_ID, GPIO_DIR_INPUT);
00118 port_select_gpio_pin(BOARD_SPI_MISO_ID, GPIO_DIR_OUTPUT);
00119 }
00120 }