/// Configure the device for bootloader mode and loop responding to bootloader commands void runBootloader(void){ // Turn on LED LED_PORT.DIRSET = (1<<LED_PIN); LED_PORT.OUTCLR = (1<<LED_PIN); // active low // power down RF section. VCC_EN_PORT.DIRSET |= (1<<VCC_EN_PIN); VCC_EN_PORT.OUTCLR = (1<<VCC_EN_PIN); USB_ConfigureClock(); _delay_us(100000); // 0.1s USB_Init(); USB_ep_out_init(1, USB_EP_TYPE_BULK_gc, EP1_SIZE); sei(); uint16_t i=0; while (1){ USB_Task(); pollEndpoint(); if (++i == 0) LED_PORT.OUTTGL = (1 << LED_PIN); } }
/* Configures the board hardware and chip peripherals for the project's functionality. */ void configHardware(void){ USB_ConfigureClock(); PORTR.DIRSET = 1 << 1; PORTR.OUTSET = 1 << 1; _delay_ms(50); PORTR.OUTCLR = 1 << 1; DAC_init(); initADC(); initChannels(); USB_Init(); }
int main(void){ USB_ConfigureClock(); USB_Init(); USB.INTCTRLA = USB_BUSEVIE_bm | USB_INTLVL_MED_gc; USB.INTCTRLB = USB_TRNIE_bm | USB_SETUPIE_bm; PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm; sei(); for (;;){ } }
int main(void){ PORTE.DIRSET = (1<<0) | (1<<1); PORTE.OUTSET = (1<<0); PORTR.DIRSET = 1 << 1; USB_ConfigureClock(); // Enable USB interrupts USB.INTCTRLA = /*USB_SOFIE_bm |*/ USB_BUSEVIE_bm | USB_INTLVL_MED_gc; USB.INTCTRLB = USB_TRNIE_bm | USB_SETUPIE_bm; USB_Init(); PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; sei(); while (1){ } }
int main(void){ _delay_ms(100); USB_ConfigureClock(); PORTR.DIRSET = 1 << 1; USB_Init(); // Enable USB interrupts USB.INTCTRLA = USB_BUSEVIE_bm | USB_INTLVL_MED_gc; USB.INTCTRLB = USB_TRNIE_bm | USB_SETUPIE_bm; PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm; sei(); // setup TWI bus for master-mode I2C comms TWIC.MASTER.BAUD = TWI_BAUD; TWIC.MASTER.CTRLA = TWI_MASTER_ENABLE_bm; TWIC.MASTER.STATUS = TWI_MASTER_BUSSTATE_IDLE_gc; // setup TCC0 for sample timing TCC0.CTRLA = TC_CLKSEL_DIV256_gc; TCC0.CTRLB = TC0_CCAEN_bm | TC_WGMODE_SINGLESLOPE_gc; TCC0.INTCTRLB = TC_CCAINTLVL_LO_gc; TCC0.CCA = 120; TCC0.PER = 0; // config PORTE for serial transmission PORTE.DIRSET = 1 << 3; USARTE0.BAUDCTRLA = 0x01; USARTE0.CTRLC = USART_PMODE_EVEN_gc | USART_CHSIZE_8BIT_gc; USARTE0.CTRLB = USART_TXEN_bm | USART_CLK2X_bm; // configure general DMA settings DMA.CTRL = DMA_ENABLE_bm | DMA_DBUFMODE_DISABLED_gc | DMA_PRIMODE_RR0123_gc; // use DMA CH0 for transmitting data after a frame snapshot // reload SRC address register every transaction // increment SRC every packet // don't reload the destination address // the destination address is fixed DMA.CH0.ADDRCTRL = DMA_CH_SRCRELOAD_TRANSACTION_gc | DMA_CH_SRCDIR_INC_gc | DMA_CH_DESTRELOAD_NONE_gc | DMA_CH_DESTDIR_FIXED_gc; // DMA.CH1.ADDRCTRL = DMA_CH_SRCRELOAD_NONE_gc | DMA_CH_SRCDIR_FIXED_gc | DMA_CH_DESTRELOAD_TRANSACTION_gc | DMA_CH_DESTDIR_INC_gc; // trigger DMA transfer on data ready event - USARTE0.DATA is ready to get another byte DMA.CH0.TRIGSRC = DMA_CH_TRIGSRC_USARTE0_DRE_gc; // DMA.CH1.TRIGSRC = DMA_CH_TRIGSRC_USARTE0_RXC_gc; // eww. DMA.CH0.SRCADDR0 = ((uint32_t)(&sensorData) >> (8*0)) & 0xFF; DMA.CH0.SRCADDR1 = ((uint32_t)(&sensorData) >> (8*1)) & 0xFF; DMA.CH0.SRCADDR2 = ((uint32_t)(&sensorData) >> (8*2)) & 0xFF; DMA.CH0.DESTADDR0 = ((uint32_t)(&USARTE0.DATA) >> (8*0)) & 0xFF; DMA.CH0.DESTADDR1 = ((uint32_t)(&USARTE0.DATA) >> (8*1)) & 0xFF; DMA.CH0.DESTADDR2 = ((uint32_t)(&USARTE0.DATA) >> (8*2)) & 0xFF; // enable CH0, set to one byte bursts DMA.CH0.CTRLA = DMA_CH_ENABLE_bm | DMA_CH_SINGLE_bm | DMA_CH_BURSTLEN_1BYTE_gc; getAlive(); getCalibrationData(); PORTR.OUTSET = 1 << 1; for (;;){} }