void dma1_channel1_isr(void) { //usbd_ep_write_packet(usb_device,0x82,&(x[0]), 4); //usbd_ep_write_packet(usb_device,0x82, &(adc_samples[0]), 64); //gpio_port_write(GPIOE, 0xA500); /* if (state == 0){ state = 20; TIM3_SMCR |= TIM_SMCR_SMS_TM; } */ if ( dma_get_interrupt_flag(DMA1, 1, DMA_TCIF) != 0 ) { state = 0; gpio_port_write(GPIOE, 0xA500); dma_clear_interrupt_flags(DMA1, 1, DMA_TCIF); //gpio_port_write(GPIOE, 0xFF00); //usbd_ep_write_packet(usb_device,0x82,&(x[0]), 4); //((uint32_t *) adc_samples)[0] = ADC1_CR; //((uint32_t *) adc_samples)[1] = ADC1_ISR; //((uint32_t *) adc_samples)[2] = DMA1_CCR1; usbd_ep_write_packet(usb_device,0x82, (uint8_t *) &(adc_samples[0]), 62); // ((uint32_t *) x)[0] = DMA1_CCR1; //usbd_ep_write_packet(usb_device,0x82, x, 4); // reset DMA so we're ready to transmit again } }
//DAC control interrupt void tim2_isr(void){ if(timer_interrupt_source(TIM3, TIM_SR_CC1IF)){ gpio_set(GPIOA, GPIO12); //set the pin high. Must do this first for timing timer_clear_flag(TIM2, TIM_SR_CC1IF); //detect end of packet transmission /* if(end of packet){ currently_transmitting = false; if(buffers_full){ buffers_full=false; enable spi1 interrupts set 'full' pin low } timer_disable_counter(TIM2); timer_set_counter(TIM2, 0); gpio_clear(GPIOA, GPIO12); //set DAC-CLK low } */ } if(timer_interrupt_source(TIM3, TIM_SR_UIF)){ gpio_port_write(GPIOC, (next_transmit[1] | (next_transmit[0]<<8))); //set the dac-db pins gpio_clear(GPIOA, GPIO12); //set DAC-CLK low timer_clear_flag(TIM2, TIM_SR_UIF); //reset the interrupt flag generate_sample(); } return; }
void adc1_2_isr(void) { //usbd_ep_write_packet(usb_device,0x82, x, 4); if ( adc_eoc(ADC1) != 0 ) { gpio_port_write(GPIOE, 0xFF00); //usbd_ep_write_packet(usb_device,0x82, (uint8_t *) &(adc_samples[0]), 64); // reset DMA so we're ready to transmit again } }
void adc1_2_isr(void) { if ( adc_eoc(ADC1) != 0 ) { sig = adc_read_regular(ADC1); gpio_port_write(GPIOE, (sig << 8) | 0x0001); DAC_DHR8R1 = DAC_DHR8R1_DACC1DHR_MSK & sig; //DAC_DHR12R1 = DAC_DHR12R1_DACC1DHR_MSK & 0x0FFF; ADC1_CR |= ADC_CR_ADSTART; } }
void dma1_channel1_isr(void) { //usbd_ep_write_packet(usb_device,0x82,&(x[0]), 4); //usbd_ep_write_packet(usb_device,0x82, &(adc_samples[0]), 64); //gpio_port_write(GPIOE, 0xA500); if ( dma_get_interrupt_flag(DMA1, 1, DMA_TCIF) != 0 ) { dma_clear_interrupt_flags(DMA1, 1, DMA_TCIF); gpio_port_write(GPIOE, 0xFF00); //usbd_ep_write_packet(usb_device,0x82,&(x[0]), 4); usbd_ep_write_packet(usb_device,0x82, (uint8_t *) &(adc_samples[0]), 62); // ((uint32_t *) x)[0] = DMA1_CCR1; //usbd_ep_write_packet(usb_device,0x82, x, 4); // reset DMA so we're ready to transmit again } }
void tim2_isr(void){ if(timer_interrupt_source(TIM2, TIM_SR_CC1IF)){ gpio_set(GPIOA, GPIO14); timer_clear_flag(TIM2, TIM_SR_CC1IF); //now to generate the next sample generate_sample(); i++; if(i==n) i=0; } if(timer_interrupt_source(TIM2, TIM_SR_UIF)){ gpio_clear(GPIOA, GPIO14); //set DAC-CLK low gpio_port_write(GPIOC, (next_transmit[1] | (next_transmit[0]<<8))); //set the dac-db pins timer_clear_flag(TIM2, TIM_SR_UIF); } return; }
inline void lcd_write_byte(uint8_t b, bool rs_data) { //place data gpio_port_write(GPIOD, (gpio_port_read(GPIOD) & ~0xFF) | (b & 0xFF)); //R/W = write gpio_clear(GPIOE, GPIO1); // rs_data = true --> R/S = 1, else 0 if (rs_data) { gpio_set(GPIOE, GPIO2); } else { gpio_clear(GPIOE, GPIO2); } //set E=true gpio_set(GPIOE, GPIO0); //wait 500ns or more before falling edge of E delay_us(1); gpio_clear(GPIOE, GPIO0); }
int main(void) { uint16_t temp; clock_setup(); gpio_setup(); adc_setup(); usart_setup(); while (1) { adc_start_conversion_regular(ADC1); while (!(adc_eoc(ADC1))); temp=adc_read_regular(ADC1); gpio_port_write(GPIOE, temp << 4); my_usart_print_int(USART2, temp); } return 0; }
static inline void update_pins(struct mb_display *disp, u32_t val) { if (IS_ENABLED(CONFIG_MICROBIT_DISPLAY_PIN_GRANULARITY)) { u32_t pin, prev = (disp->cur + 2) % 3; /* Disable the previous row */ gpio_pin_write(disp->dev, ROW_PIN(prev), 0); /* Set the column pins to their correct values */ for (pin = LED_COL1_GPIO_PIN; pin <= LED_COL9_GPIO_PIN; pin++) { gpio_pin_write(disp->dev, pin, !!(val & BIT(pin))); } /* Enable the new row */ gpio_pin_write(disp->dev, ROW_PIN(disp->cur), 1); } else { gpio_port_write(disp->dev, val); } }
void tim3_isr(void) { if (timer_get_flag(TIM3, TIM_SR_CC1IF)) { /* Clear compare interrupt flag. */ timer_clear_flag(TIM3, TIM_SR_CC1IF); leds = leds+0x0100; gpio_port_write(GPIOE, leds); //TIM3_SMCR &= ~TIM_SMCR_SMS_MASK; //gpio_port_write(GPIOE, 0xFF00); //state = 0; //usb transfer stuff /*if ( usb_ready_to_send == 1 ) { usb_ready_to_send = 0; char hi[4] = {'h', 'i', '\r', '\n'}; usbd_ep_write_packet(usb_device, 0x82, hi, 4); } */ } }
void tim1_trg_com_tim11_isr(void) { static int step = 0; /* Clear the COM trigger interrupt flag. */ timer_clear_flag(TIM1, TIM_SR_COMIF); /* * A simplified and inefficient implementation of PWM On * scheme. Look at the implementation in Open-BLDC on * http://open-bldc.org for the proper implementation. This * one only serves as an example. * * Table of the PWM scheme zone configurations when driving: * @verbatim * | 1| 2| 3| 4| 5| 6| * -+--+--+--+--+--+--+ * A|p+|++| |p-|--| | * -+--+--+--+--+--+--+ * B| |p-|--| |p+|++| * -+--+--+--+--+--+--+ * C|--| |p+|++| |p-| * -+--+--+--+--+--+--+ * | | | | | | '- 360 Deg * | | | | | '---- 300 Deg * | | | | '------- 240 Deg * | | | '---------- 180 Deg * | | '------------- 120 Deg * | '---------------- 60 Deg * '------------------- 0 Deg * * Legend: * p+: PWM on the high side * p-: PWM on the low side * --: Low side on * ++: High side on * : Floating/NC * @endverbatim */ //gpio_port_write(GPIOD, GPIO13); //GPIOD_BSRR = GPIO13; /* LED on */ gpio_port_write(GPIOD, GPIO13); switch (step) { case 0: /* A PWM HIGH, B OFF, C LOW */ timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM1); timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_FROZEN); timer_set_oc_mode(TIM1, TIM_OC3, TIM_OCM_FORCE_LOW); timer_enable_oc_output(TIM1, TIM_OC1); timer_disable_oc_output(TIM1, TIM_OC1N); timer_disable_oc_output(TIM1, TIM_OC2); timer_disable_oc_output(TIM1, TIM_OC2N); timer_enable_oc_output(TIM1, TIM_OC3); timer_enable_oc_output(TIM1, TIM_OC3N); step++; //gpio_port_write(GPIOD, GPIO12); break; case 1: /* A HIGH, B PWM LOW, C OFF */ timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_FORCE_HIGH); timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_PWM1); timer_set_oc_mode(TIM1, TIM_OC3, TIM_OCM_FROZEN); timer_enable_oc_output(TIM1, TIM_OC1); timer_enable_oc_output(TIM1, TIM_OC1N); timer_disable_oc_output(TIM1, TIM_OC2); timer_enable_oc_output(TIM1, TIM_OC2N); timer_disable_oc_output(TIM1, TIM_OC3); timer_disable_oc_output(TIM1, TIM_OC3N); step++; //gpio_port_write(GPIOD, GPIO13); break; case 2: /* A OFF, B LOW, C PWM HIGH */ timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_FROZEN); timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_FORCE_LOW); timer_set_oc_mode(TIM1, TIM_OC3, TIM_OCM_PWM1); timer_disable_oc_output(TIM1, TIM_OC1); timer_disable_oc_output(TIM1, TIM_OC1N); timer_enable_oc_output(TIM1, TIM_OC2); timer_enable_oc_output(TIM1, TIM_OC2N); timer_enable_oc_output(TIM1, TIM_OC3); timer_disable_oc_output(TIM1, TIM_OC3N); step++; //gpio_port_write(GPIOD, GPIO14); break; case 3: /* A PWM LOW, B OFF, C HIGH */ timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM1); timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_FROZEN); timer_set_oc_mode(TIM1, TIM_OC3, TIM_OCM_FORCE_HIGH); timer_disable_oc_output(TIM1, TIM_OC1); timer_enable_oc_output(TIM1, TIM_OC1N); timer_disable_oc_output(TIM1, TIM_OC2); timer_disable_oc_output(TIM1, TIM_OC2N); timer_enable_oc_output(TIM1, TIM_OC3); timer_enable_oc_output(TIM1, TIM_OC3N); step++; //gpio_port_write(GPIOD, GPIO15); break; case 4: /* A LOW, B PWM HIGH, C OFF */ timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_FORCE_LOW); timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_PWM1); timer_set_oc_mode(TIM1, TIM_OC3, TIM_OCM_FROZEN); timer_enable_oc_output(TIM1, TIM_OC1); timer_enable_oc_output(TIM1, TIM_OC1N); timer_enable_oc_output(TIM1, TIM_OC2); timer_disable_oc_output(TIM1, TIM_OC2N); timer_disable_oc_output(TIM1, TIM_OC3); timer_disable_oc_output(TIM1, TIM_OC3N); step++; //gpio_port_write(GPIOD, GPIO15); break; case 5: /* A OFF, B HIGH, C PWM LOW */ timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_FROZEN); timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_FORCE_HIGH); timer_set_oc_mode(TIM1, TIM_OC3, TIM_OCM_PWM1); timer_disable_oc_output(TIM1, TIM_OC1); timer_disable_oc_output(TIM1, TIM_OC1N); timer_enable_oc_output(TIM1, TIM_OC2); timer_enable_oc_output(TIM1, TIM_OC2N); timer_disable_oc_output(TIM1, TIM_OC3); timer_enable_oc_output(TIM1, TIM_OC3N); step = 0; //gpio_port_write(GPIOD, GPIO15); break; } }
static inline void rgb_go_level ( unsigned int rgb ) { //gpio_set ( GPIOC, rgb ); gpio_port_write ( GPIOC, rgb ); }