uint8_t jtagtap_next(const uint8_t dTMS, const uint8_t dTDO) { uint16_t ret; gpio_set_val(TMS_PORT, TMS_PIN, dTMS); gpio_set_val(TDI_PORT, TDI_PIN, dTDO); gpio_set(TCK_PORT, TCK_PIN); ret = gpio_get(TDO_PORT, TDO_PIN); gpio_clear(TCK_PORT, TCK_PIN); DEBUG("jtagtap_next(TMS = %d, TDO = %d) = %d\n", dTMS, dTDO, ret); return ret != 0; }
void usart1_isr(void) { long xHigherPriorityTaskWoken = pdFALSE; char cChar; // ----- transmission complete: if (usart_get_flag(USART1, USART_SR_TC) == true) { gpio_clear(GPIOA, GPIO12); // clear RTS gpio_clear(GPIOA, GPIO_USART1_TX); // clear DI USART_SR(USART1) &= ~USART_SR_TC; // reset flag TC usart_disable_tx_interrupt(USART1); } if (usart_get_flag(USART1, USART_SR_TXE) == true) { /* The interrupt was caused by the THR becoming empty. Are there any more characters to transmit? */ if (xQueueReceiveFromISR(xCharsForTx[0], &cChar, &xHigherPriorityTaskWoken)) { /* A character was retrieved from the buffer so can be sent to the THR now. */ gpio_set(GPIOA, GPIO12); // set RTS usart_send(USART1, (uint8_t) cChar); } else { // gpio_clear(GPIOA, GPIO12); // clear RTS // usart_disable_tx_interrupt(USART1); // USART_SR(USART1) &= ~USART_SR_TXE; // reset flag TXE // USART_CR1(USART1) |= USART_CR1_TCIE; } } if (usart_get_flag(USART1, USART_SR_RXNE) == true) { cChar = (char) usart_recv(USART1); xQueueSendFromISR(xRxedChars[0], &cChar, &xHigherPriorityTaskWoken); } portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); }
void* timer_func(void* arg) { #if defined(WORKER_THREAD_PIN) gpio_t worker_pin = WORKER_THREAD_PIN; gpio_init(worker_pin, GPIO_OUT); #endif LOG_DEBUG("run thread %" PRIkernel_pid "\n", thread_getpid()); while(1) { #if defined(WORKER_THREAD_PIN) gpio_set(worker_pin); gpio_clear(worker_pin); #endif xtimer_usleep(*(uint32_t *)(arg)); } }
static void gpio_setup(void) { /* Enable GPIOB clock. */ rcc_enable_clock(RCC_GPIOB); /* Set PB6 and PB7 to 'output push-pull'. */ gpio_config_output(GPIO_PUSHPULL, GPIO_400KHZ, GPIO_NOPUPD, GPIO_PB(6, 7)); /* LED(PB6) on */ gpio_set(GPIO_PB6); /* LED(PB7) off */ gpio_clear(GPIO_PB7); }
int main(void) { gpio_enable_ahb_aperture(); clock_setup(); gpio_setup(); irq_setup(); /* Blink each color of the RGB LED in order. */ while (1) { /* * Flash the Red diode */ gpio_set(RGB_PORT, LED_R); delay(); /* Wait a bit. */ gpio_clear(RGB_PORT, LED_R); delay(); /* Wait a bit. */ /* * Flash the Green diode */ gpio_set(RGB_PORT, LED_G); delay(); /* Wait a bit. */ gpio_clear(RGB_PORT, LED_G); delay(); /* Wait a bit. */ /* * Flash the Blue diode */ gpio_set(RGB_PORT, LED_B); delay(); /* Wait a bit. */ gpio_clear(RGB_PORT, LED_B); delay(); /* Wait a bit. */ } return 0; }
void baro_init(void) { bmp085_init(&baro_bmp085, &i2c2, BMP085_SLAVE_ADDR); /* setup eoc check function */ baro_bmp085.eoc = &baro_eoc; gpio_clear(GPIOB, GPIO0); gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO0); #ifdef BARO_LED LED_OFF(BARO_LED); #endif }
void writeCommand(uint8_t c) { if (!g_HWSPI) { bbCmd(c); return; } memory_barrier(); gpio_clear(PIN_DC); gpio_clear(24); memory_barrier(); pack.command = 0x000 | c; // LoSSI 9-bit Command mode spi_start(0); // Start SPI transfer to CS0 destination // Bypass spi_write function here //while (!HW.SPI0.CS.B.TXD); // ensure no reads //HW.SPI0.FIFO = pack.command; spi_write(c) ; spi_flush(); memory_barrier(); gpio_set(24); memory_barrier(); printf("Command:%.2X ",pack.command); }
void pic_write(uint8_t addr, uint8_t value) { /* toggle the pin for 4 us */ gpio_clear(PIC_INT_WAKE_PIN); _usleep(4); /* write to gpio expander */ i2c_acquire(PIC_I2C); uint8_t bytes[] = { addr, value }; i2c_write_bytes(PIC_I2C, PIC_I2C_ADDR, bytes, 2, 0); i2c_release(PIC_I2C); /* put PIC in sleep mode again */ gpio_set(PIC_INT_WAKE_PIN); }
int i2c_init_master(i2c_t dev, i2c_speed_t speed) { /* check if device is valid */ if (dev >= I2C_NUMOF) { return -1; } /* enable clocks */ CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(i2c_config[dev].cmu, true); /* configure the pins */ gpio_init(i2c_config[dev].scl_pin, GPIO_OD); gpio_init(i2c_config[dev].sda_pin, GPIO_OD); /* ensure slave is in a known state, which it may not be after a reset */ for (int i = 0; i < 9; i++) { gpio_set(i2c_config[dev].scl_pin); gpio_clear(i2c_config[dev].scl_pin); } /* reset and initialize the peripheral */ EFM32_CREATE_INIT(init, I2C_Init_TypeDef, I2C_INIT_DEFAULT, .conf.enable = false, .conf.freq = (uint32_t) speed ); I2C_Reset(i2c_config[dev].dev); I2C_Init(i2c_config[dev].dev, &init.conf); /* configure pin functions */ #ifdef _SILICON_LABS_32B_PLATFORM_1 i2c_config[dev].dev->ROUTE = (i2c_config[dev].loc | I2C_ROUTE_SDAPEN | I2C_ROUTE_SCLPEN); #else i2c_config[dev].dev->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN; i2c_config[dev].dev->ROUTELOC0 = i2c_config[dev].loc; #endif /* enable interrupts */ NVIC_ClearPendingIRQ(i2c_config[dev].irq); NVIC_EnableIRQ(i2c_config[dev].irq); /* enable peripheral */ I2C_Enable(i2c_config[dev].dev, true); return 0; }
int main(void) { /* Check the force bootloader pin*/ uint16_t pin_b; rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); /* Switch PB5 (SWIM_RST_IN) up */ gpio_set(GPIOB, GPIO5); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); gpio_set(GPIOB, GPIO5); pin_b = gpio_get(GPIOB, GPIO6); /* Check state on PB6 ((SWIM_RST) and release PB5*/ pin_b = gpio_get(GPIOB, GPIO6); gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO5); if(((GPIOA_CRL & 0x40) == 0x40) && pin_b) dfu_jump_app_if_valid(); dfu_protect(DFU_MODE); rcc_clock_setup_in_hse_8mhz_out_72mhz(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); /* Handle USB disconnect/connect */ /* Just in case: Disconnect USB cable by resetting USB Device * and pulling USB_DP low * Device will reconnect automatically as Pull-Up is hard wired*/ rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); /* Handle LED*/ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); systick_interrupt_enable(); systick_counter_enable(); dfu_init(&stm32f103_usb_driver, DFU_MODE); dfu_main(); }
void spi_start(void) { /* Reset flash chip */ gpio_clear(GPIOD, BL_SPI2_RST); wait(10); gpio_set(GPIOD, BL_SPI2_RST); wait(10); gpio_set(GPIOD, BL_SPI2_WP); /* No WriteProtect, Set Chip select to 1(no select) */ gpio_set(GPIOB, BL_SPI2_NSS); /* Reset and disable SPI */ spi_reset(SPI2); /* Disable I2S */ SPI2_I2SCFGR = 0; /* CR1 */ spi_set_clock_phase_0(SPI2); /* CPHA = 0 */ spi_set_clock_polarity_0(SPI2); /* CPOL = 0 */ spi_send_msb_first(SPI2); /* LSB = 0 */ spi_set_full_duplex_mode(SPI2); /* RXONLY = 0 */ spi_set_unidirectional_mode(SPI2); /* BIDI = 0 */ spi_enable_software_slave_management(SPI2); /* SSM = 1 */ spi_set_nss_high(SPI2); /* SSI = 1 */ spi_set_master_mode(SPI2); /* MSTR = 1 */ spi_set_dff_8bit(SPI2); /* DFf = 8 bit */ // spi_enable_crc(SPI2); /* XXX: Too fast? Maybe DIV_4 will be better? */ spi_set_baudrate_prescaler(SPI2, SPI_CR1_BR_FPCLK_DIV_2); /* CR2 */ spi_enable_ss_output(SPI2); /* SSOE = 1 */ /* Disable regular interrupt flags */ spi_disable_tx_buffer_empty_interrupt(SPI2); spi_disable_rx_buffer_not_empty_interrupt(SPI2); spi_disable_error_interrupt(SPI2); /* Enabling RX/TX DMA flags */ spi_enable_tx_dma(SPI2); spi_enable_rx_dma(SPI2); d_print("REG: %lu:%lu\r\n", SPI_CR1(SPI2), SPI_CR2(SPI2)); spi_enable(SPI2); }
void spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont, const void *out, void *in, size_t len) { (void)bus; const uint8_t *out_buf = out; uint8_t *in_buf = in; assert(out_buf || in_buf); if (cs != SPI_CS_UNDEF) { gpio_clear((gpio_t)cs); } /* if we only send out data, we do this the fast way... */ if (!in_buf) { for (size_t i = 0; i < len; i++) { while (!(SPI_IF & SPI_IE_TX_BIT)) {} SPI_BASE->TXBUF = out_buf[i]; } /* finally we need to wait, until all transfers are complete */ #ifndef SPI_USE_USCI while (!(SPI_IF & SPI_IE_TX_BIT) || !(SPI_IF & SPI_IE_RX_BIT)) {} #else while (SPI_BASE->STAT & USCI_SPI_STAT_UCBUSY) {} #endif SPI_BASE->RXBUF; } else if (!out_buf) { for (size_t i = 0; i < len; i++) { SPI_BASE->TXBUF = 0; while (!(SPI_IF & SPI_IE_RX_BIT)) {} in_buf[i] = (char)SPI_BASE->RXBUF; } } else { for (size_t i = 0; i < len; i++) { while (!(SPI_IF & SPI_IE_TX_BIT)) {} SPI_BASE->TXBUF = out_buf[i]; while (!(SPI_IF & SPI_IE_RX_BIT)) {} in_buf[i] = (char)SPI_BASE->RXBUF; } } if ((!cont) && (cs != SPI_CS_UNDEF)) { gpio_set((gpio_t)cs); } }
int main(void) { int i; clock_init(); gpio_init(); servo_init(); //gpio_set(GPIOC, GPIO13); for(i=0;i<100;i++){ gpio_toggle(GPIOC, GPIO13); /* LED on/off */ delay(1500000); } gpio_clear(GPIOC, GPIO13); // let pan-til "look around a little" while(1) { set_servos(SERVO_MIN, SERVO_MAX); set_servos(SERVO_NULL, SERVO_NULL); set_servos(SERVO_MAX, SERVO_MIN); set_servos(SERVO_NULL, SERVO_NULL); set_servos(SERVO_MIN, SERVO_MIN); set_servos(SERVO_MAX, SERVO_MAX); set_servos(SERVO_NULL, SERVO_NULL); set_servos(SERVO_MIN, SERVO_NULL); set_servos(SERVO_MAX, SERVO_NULL); set_servos(SERVO_NULL, SERVO_NULL); set_servos(SERVO_NULL, SERVO_MIN); set_servos(SERVO_NULL, SERVO_MAX); set_servos(SERVO_NULL, SERVO_NULL); } return 0; }
void autopilot_init(void) { /* mode is finally set at end of init if MODE_STARTUP is not KILL */ autopilot_mode = AP_MODE_KILL; autopilot_motors_on = FALSE; kill_throttle = ! autopilot_motors_on; autopilot_in_flight = FALSE; autopilot_in_flight_counter = 0; autopilot_mode_auto2 = MODE_AUTO2; autopilot_ground_detected = FALSE; autopilot_detect_ground_once = FALSE; autopilot_flight_time = 0; autopilot_rc = TRUE; autopilot_power_switch = FALSE; #ifdef POWER_SWITCH_GPIO gpio_setup_output(POWER_SWITCH_GPIO); gpio_clear(POWER_SWITCH_GPIO); // POWER OFF #endif autopilot_arming_init(); nav_init(); guidance_h_init(); guidance_v_init(); stabilization_init(); stabilization_none_init(); stabilization_rate_init(); stabilization_attitude_init(); /* set startup mode, propagates through to guidance h/v */ autopilot_set_mode(MODE_STARTUP); register_periodic_telemetry(DefaultPeriodic, "AUTOPILOT_VERSION", send_autopilot_version); register_periodic_telemetry(DefaultPeriodic, "ALIVE", send_alive); register_periodic_telemetry(DefaultPeriodic, "ROTORCRAFT_STATUS", send_status); register_periodic_telemetry(DefaultPeriodic, "ENERGY", send_energy); register_periodic_telemetry(DefaultPeriodic, "ROTORCRAFT_FP", send_fp); register_periodic_telemetry(DefaultPeriodic, "ROTORCRAFT_CMD", send_rotorcraft_cmd); register_periodic_telemetry(DefaultPeriodic, "DL_VALUE", send_dl_value); #ifdef ACTUATORS register_periodic_telemetry(DefaultPeriodic, "ACTUATORS", send_actuators); #endif #ifdef RADIO_CONTROL register_periodic_telemetry(DefaultPeriodic, "RC", send_rc); register_periodic_telemetry(DefaultPeriodic, "ROTORCRAFT_RADIO_CONTROL", send_rotorcraft_rc); #endif }
void tim1_cc_isr(void) { if(timer_get_flag(TIM1, TIM_SR_CC2IF)) { int ccr = TIM_CCR2(TIM1); int save_n_overflow = n_overflow; n_overflow = 0; int delta = (ccr + (save_n_overflow<<16)) - last_ccr; if(dma_enabled) start_dma(); timer_clear_flag(TIM1, TIM_SR_CC2IF); //gpio_set(DEBUG0_OUT_PORT, DEBUG0_OUT_PIN); //gpio_clear(DEBUG0_OUT_PORT, DEBUG0_OUT_PIN); last_ccr = ccr; int speed_delta = motor_ctrl_step(delta); // Wait for motor speed to get stable. if(!dma_enabled && speed_delta > -10 && speed_delta < 10) { if(motor_ok == 0) { set_status(LED_GREEN, 1); set_status(LED_RED, 0); dma_enabled = 1; } else { motor_ok--; } } if(dma_enabled && (speed_delta < -100 || speed_delta > 100)) { set_status(LED_GREEN, 0); set_status(LED_RED, 1); dma_enabled = 0; motor_ok = 16; } if(delta < 100) { gpio_set(GPIOB, GPIO0); __asm("nop"); __asm("nop"); __asm("nop"); __asm("nop"); gpio_clear(GPIOB, GPIO0); } } }
bool swdptap_bit_in(void) { uint16_t ret; swdptap_turnaround(1); ret = gpio_get(SWDIO_PORT, SWDIO_PIN); gpio_set(SWCLK_PORT, SWCLK_PIN); gpio_clear(SWCLK_PORT, SWCLK_PIN); #ifdef DEBUG_SWD_BITS DEBUG("%d", ret?1:0); #endif return ret != 0; }
void *timer_func(void *arg) { LOG_DEBUG("run thread %" PRIkernel_pid "\n", thread_getpid()); #if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2) gpio_init((*(timer_arg_t *)(arg)).pin, GPIO_OUT); #endif while (1) { #if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2) gpio_set((*(timer_arg_t *)(arg)).pin); gpio_clear((*(timer_arg_t *)(arg)).pin); #endif xtimer_usleep(*(uint32_t *)(arg)); } }
int ata8510_send_cmd(const ata8510_t *dev, const uint8_t *tx_buffer, const uint8_t *rx_buffer, const size_t len) { int count; spi_acquire(dev->params.spi); gpio_clear(dev->params.cs_pin); xtimer_usleep(1); count = spi_transfer_bytes( dev->params.spi, (char *)tx_buffer, (char *)rx_buffer, len ); gpio_set(dev->params.cs_pin); spi_release(dev->params.spi); return count; }
void humid_sht_init(void) { /* Configure DAT/SCL pin as GPIO */ gpio_setup_input(SHT_DAT_GPIO); gpio_setup_output(SHT_SCK_GPIO); gpio_clear(SHT_SCK_GPIO); humid_sht_available = false; humid_sht_status = SHT_IDLE; #if SHT_SDLOG log_sht_started = false; #endif }
int main(void) { for (u32 i = 0; i < 600000; i++) __asm__("nop"); led_setup(); rcc_clock_setup_hse_3v3(&hse_16_368MHz_in_65_472MHz_out_3v3); debug_setup(); timer_setup(); // Debug pins (CC1111 TX/RX) RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN; gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO10|GPIO11); gpio_clear(GPIOC, GPIO10|GPIO11); printf("\n\nFirmware info - git: " GIT_VERSION ", built: " __DATE__ " " __TIME__ "\n"); printf("--- DEBUG RX STRESS TEST ---\n"); static msg_callbacks_node_t callback_node; debug_register_callback(0x22, &callback, &callback_node); for (u8 i=0; i<30; i++) { guard_below[i] = 0; guard_above[i] = 0; } while(1) { /* Check the guards for buffer over/underrun. */ for (u8 i=0; i<30; i++) { if (guard_below[i] != 0) screaming_death(); if (guard_above[i] != 0) screaming_death(); } debug_process_messages(); //for (u32 i = 0; i < 1000; i++) // __asm__("nop"); } while (1); return 0; }
/* SPI receive completed with DMA */ void dma1_channel2_isr(void) { gpio_set(GPIOA,GPIO4); if ((DMA1_ISR &DMA_ISR_TCIF2) != 0) { DMA1_IFCR |= DMA_IFCR_CTCIF2; } dma_disable_transfer_complete_interrupt(DMA1, DMA_CHANNEL2); spi_disable_rx_dma(SPI1); dma_disable_channel(DMA1, DMA_CHANNEL2); /* Increment the status to indicate one of the transfers is complete */ transceive_status++; gpio_clear(GPIOA,GPIO4); }
static void codecWriteReg(unsigned reg, unsigned value) { gpio_clear(GPIOA, GPIO4); spi_send(SPI1, (reg << 9) | value); while (!(SPI_SR(SPI1) & SPI_SR_TXE)); while (SPI_SR(SPI1) & SPI_SR_BSY); for (int i = 0; i < 100; i++) { __asm__("nop"); } gpio_set(GPIOA, GPIO4); for (int i = 0; i < 1000; i++) { __asm__("nop"); } }
static void _accel_io_read(struct lsm303c_accelerometer *accel, uint8_t address, uint8_t *data, uint16_t size) { address |= (uint8_t)(0x80); /* Set chip select Low at the start of the transmission */ gpio_clear(accel->cs); /* Send the Address of the indexed register */ device_write(accel->dev, &address, 1); /* Receive the data that will be read from the device (MSB First) */ device_read(accel->dev, data, size); /* Set chip select High at the end of the transmission */ gpio_set(accel->cs); }
void radio_read_burst_reg(uint8_t reg, uint8_t *buff, uint16_t len) { while(SPI_SR(R_SPI) & SPI_SR_BSY); gpio_clear(R_CS_PORT, R_CS_PIN); spi_send8(R_SPI, reg & 0x7F); spi_read8(R_SPI); // Wait until send FIFO is empty while(SPI_SR(R_SPI) & SPI_SR_BSY); uint16_t i; for ( i = 0; i < len; i++) { spi_send8(R_SPI, 0x0); while(SPI_SR(R_SPI) & SPI_SR_BSY); buff[i] = spi_read8(R_SPI); } gpio_set(R_CS_PORT, R_CS_PIN); }
int main(void) { rcc_clock_setup_pll(&this_clock_config); /* LED on custom board for boot progress */ rcc_periph_clock_enable(RCC_GPIOB); gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO1); gpio_set(GPIOB, GPIO1); usbd_device *usbd_dev = gadget0_init(&st_usbfs_v1_usb_driver, "stm32l1-generic"); ER_DPRINTF("bootup complete\n"); gpio_clear(GPIOB, GPIO1); while (1) { usbd_poll(usbd_dev); } }
static void swdptap_turnaround(uint8_t dir) { static uint8_t olddir = 0; DEBUG("%s", dir ? "\n-> ":"\n<- "); /* Don't turnaround if direction not changing */ if(dir == olddir) return; olddir = dir; if(dir) SWDIO_MODE_FLOAT(); gpio_set(SWCLK_PORT, SWCLK_PIN); gpio_clear(SWCLK_PORT, SWCLK_PIN); if(!dir) SWDIO_MODE_DRIVE(); }
int main(void) { #if defined(MAIN_THREAD_PIN) gpio_t main_pin = MAIN_THREAD_PIN; gpio_init(main_pin, GPIO_OUT); #endif #if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2) timer_arg_t sleep_timer1 = { TEST_SLEEP_TIME_1, WORKER_THREAD_PIN_1 }; timer_arg_t sleep_timer2 = { TEST_SLEEP_TIME_2, WORKER_THREAD_PIN_2 }; #else uint32_t sleep_timer1 = TEST_SLEEP_TIME_1; uint32_t sleep_timer2 = TEST_SLEEP_TIME_2; #endif LOG_DEBUG("[INIT]\n"); thread_create(stack_timer1, TEST_TIMER_STACKSIZE, 2, THREAD_CREATE_STACKTEST, timer_func, &sleep_timer1, "timer1"); thread_create(stack_timer2, TEST_TIMER_STACKSIZE, 3, THREAD_CREATE_STACKTEST, timer_func, &sleep_timer2, "timer2"); uint32_t now = 0; uint32_t start = xtimer_now_usec(); uint32_t until = start + (TEST_TIME_S * US_PER_SEC); uint32_t interval = TEST_INTERVAL_MS * US_PER_MS; xtimer_ticks32_t last_wakeup = xtimer_now(); puts("[START]"); while ((now = xtimer_now_usec()) < until) { unsigned percent = (100 * (now - start)) / (until - start); #if defined(MAIN_THREAD_PIN) gpio_set(main_pin); #endif xtimer_periodic_wakeup(&last_wakeup, interval); #if defined(MAIN_THREAD_PIN) gpio_clear(main_pin); #endif printf("Testing (%3u%%)\n", percent); } puts("Testing (100%)"); puts("[SUCCESS]"); return 0; }
void BUTTON_DISCO_USER_isr(void) { exti_reset_request(BUTTON_DISCO_USER_EXTI); if (state.falling) { gpio_clear(LED_DISCO_BLUE_PORT, LED_DISCO_BLUE_PIN); state.falling = false; exti_set_trigger(BUTTON_DISCO_USER_EXTI, EXTI_TRIGGER_RISING); unsigned int x = TIM_CNT(TIM7); printf("held: %u ms\n", x); } else { gpio_set(LED_DISCO_BLUE_PORT, LED_DISCO_BLUE_PIN); printf("Pushed down!\n"); TIM_CNT(TIM7) = 0; state.falling = true; exti_set_trigger(BUTTON_DISCO_USER_EXTI, EXTI_TRIGGER_FALLING); } }
static int simple_control_callback(struct usb_setup_data *req, u8 **buf, u16 *len, void (**complete)(struct usb_setup_data *req)) { (void)buf; (void)len; (void)complete; if(req->bmRequestType != 0x40) return 0; /* Only accept vendor request */ if(req->wValue & 1) gpio_set(GPIOC, GPIO6); else gpio_clear(GPIOC, GPIO6); return 1; }
uint16_t vs1053_SCI_read(uint8_t addr) { uint16_t temp; gpio_clear(CODEC_PORT, CODEC_CS); spi_msg(0x03); spi_msg(addr); temp = spi_msg(0x00); temp <<= 8; temp += spi_msg(0x00); gpio_set(CODEC_PORT, CODEC_CS); return temp; }