diff --git a/Silverware/src/main.c b/Silverware/src/main.c index ef4d699..632ed5a 100644 --- a/Silverware/src/main.c +++ b/Silverware/src/main.c @@ -22,11 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - // STM32 acro firmware // files of this project should be assumed MIT licence unless otherwise noted - #include "project.h" #include "defines.h" #include "led.h" @@ -58,31 +56,23 @@ THE SOFTWARE. #ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE #include "drv_softserial.h" #include "serial_4way.h" -#endif - - -#if defined (__GNUC__)&& !( defined (SOFT_LPF_NONE) || defined (GYRO_FILTER_PASS1) || defined (GYRO_FILTER_PASS2) ) -#warning the soft lpf may not work correctly with gcc due to longer loop time #endif - +#if defined (__GNUC__)&& !(defined (SOFT_LPF_NONE) || defined (GYRO_FILTER_PASS1) || defined (GYRO_FILTER_PASS2)) +#warning the soft lpf may not work correctly with gcc due to longer loop time +#endif #ifdef DEBUG #include "debug.h" debug_type debug; #endif - - - - // hal void clk_init(void); void imu_init(void); -extern void flash_load( void); +extern void flash_load(void); extern void flash_hard_coded_pid_identifier(void); - // looptime in seconds float looptime; // filtered battery in volts @@ -95,16 +85,16 @@ float thrfilt = 0; unsigned int lastlooptime; // signal for lowbattery -int lowbatt = 1; +int lowbatt = 1; -//int minindex = 0; +// int minindex = 0; // holds the main four channels, roll, pitch , yaw , throttle float rx[4]; // holds auxilliary channels // the last 2 are always on and off respectively -char aux[AUXNUMBER] = { 0 ,0 ,0 , 0 , 0 , 0}; +char aux[AUXNUMBER] = {0, 0, 0, 0, 0, 0}; char lastaux[AUXNUMBER]; // if an aux channel has just changed char auxchange[AUXNUMBER]; @@ -126,7 +116,7 @@ int arming_release; int binding_while_armed = 1; float lipo_cell_count = 1; -//Experimental Flash Memory Feature +// Experimental Flash Memory Feature int flash_feature_1 = 0; int flash_feature_2 = 0; int flash_feature_3 = 0; @@ -136,440 +126,445 @@ int ledcommand = 0; int ledblink = 0; unsigned long ledcommandtime = 0; -void failloop( int val); +void failloop(int val); #ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE volatile int switch_to_4way = 0; static void setup_4way_external_interrupt(void); -#endif +#endif int random_seed = 0; int main(void) { - - delay(1000); + delay(1000); + + #ifdef ENABLE_OVERCLOCK + clk_init(); + #endif + + gpio_init(); + ledon(255); // Turn on LED during boot so that if a delay is used as part of + // using programming pins for other functions, the FC does not + // appear inactive while programming times out + spi_init(); -#ifdef ENABLE_OVERCLOCK -clk_init(); -#endif - - gpio_init(); - ledon(255); //Turn on LED during boot so that if a delay is used as part of using programming pins for other functions, the FC does not appear inactive while programming times out - spi_init(); - time_init(); + #if defined(RX_DSMX_2048) || defined(RX_DSM2_1024) + rx_spektrum_bind(); + #endif -#if defined(RX_DSMX_2048) || defined(RX_DSM2_1024) - rx_spektrum_bind(); -#endif - - - delay(100000); - - i2c_init(); - - pwm_init(); - - pwm_set( MOTOR_BL , 0); - pwm_set( MOTOR_FL , 0); - pwm_set( MOTOR_FR , 0); - pwm_set( MOTOR_BR , 0); - - - sixaxis_init(); - - if ( sixaxis_check() ) - { - - } - else - { - //gyro not found - failloop(4); - } - - adc_init(); -//set always on channel to on -aux[CH_ON] = 1; - -#ifdef AUX1_START_ON -aux[CH_AUX1] = 1; -#endif - - - #ifdef FLASH_SAVE1 -// read pid identifier for values in file pid.c - flash_hard_coded_pid_identifier(); - -// load flash saved variables - flash_load( ); -#endif + delay(100000); + + i2c_init(); + + pwm_init(); + + pwm_set(MOTOR_BL, 0); + pwm_set(MOTOR_FL, 0); + pwm_set(MOTOR_FR, 0); + pwm_set(MOTOR_BR, 0); + + sixaxis_init(); + + if (sixaxis_check()) + { + + } + else + { + // gyro not found + failloop(4); + } + adc_init(); + // set always on channel to on + aux[CH_ON] = 1; -#ifdef USE_ANALOG_AUX + #ifdef AUX1_START_ON + aux[CH_AUX1] = 1; + #endif + + #ifdef FLASH_SAVE1 + // read pid identifier for values in file pid.c + flash_hard_coded_pid_identifier(); + + // load flash saved variables + flash_load(); + #endif + + #ifdef USE_ANALOG_AUX // saves initial pid values - after flash loading pid_init(); -#endif + #endif + rx_init(); - rx_init(); + int count = 0; - -int count = 0; - -while ( count < 5000 ) -{ - float bootadc = adc_read(0)*vreffilt; - lpf ( &vreffilt , adc_read(1) , 0.9968f); - lpf ( &vbattfilt , bootadc , 0.9968f); - count++; -} + while (count < 5000) + { + float bootadc = adc_read(0) * vreffilt; + lpf(&vreffilt, adc_read(1), 0.9968f); + lpf(&vbattfilt, bootadc, 0.9968f); + count++; + } -#ifndef LIPO_CELL_COUNT -for ( int i = 6 ; i > 0 ; i--) -{ - float cells = i; - if (vbattfilt/cells > 3.7f) - { - lipo_cell_count = cells; - break; - } -} -#else - lipo_cell_count = (float)LIPO_CELL_COUNT; -#endif - -#ifdef RX_BAYANG_BLE_APP - // for randomising MAC adddress of ble app - this will make the int = raw float value - random_seed = *(int *)&vbattfilt ; - random_seed = random_seed&0xff; -#endif - -#ifdef STOP_LOWBATTERY -// infinite loop -if ( vbattfilt/lipo_cell_count < 3.3f) failloop(2); -#endif + #ifndef LIPO_CELL_COUNT + for (int i = 6; i > 0; i--) + { + float cells = i; + if (vbattfilt / cells > 3.7f) + { + lipo_cell_count = cells; + break; + } + } + #else + lipo_cell_count = (float)LIPO_CELL_COUNT; + #endif + #ifdef RX_BAYANG_BLE_APP + // for randomising MAC adddress of ble app - this will make the int = raw + // float value + random_seed = *(int *)&vbattfilt; + random_seed = random_seed & 0xff; + #endif - gyro_cal(); + #ifdef STOP_LOWBATTERY -extern void rgb_init( void); -rgb_init(); + // infinite loop + if (vbattfilt / lipo_cell_count < 3.3f) + failloop(2); + #endif -#ifdef SERIAL_ENABLE -serial_init(); -#endif + gyro_cal(); + extern void rgb_init(void); + rgb_init(); + #ifdef SERIAL_ENABLE + serial_init(); + #endif -imu_init(); + imu_init(); -#ifdef FLASH_SAVE2 -// read accelerometer calibration values from option bytes ( 2* 8bit) -extern float accelcal[3]; - accelcal[0] = flash2_readdata( OB->DATA0 ) - 127; - accelcal[1] = flash2_readdata( OB->DATA1 ) - 127; -#endif - + #ifdef FLASH_SAVE2 + // read accelerometer calibration values from option bytes ( 2* 8bit) + extern float accelcal[3]; + accelcal[0] = flash2_readdata(OB->DATA0) - 127; + accelcal[1] = flash2_readdata(OB->DATA1) - 127; + #endif -extern int liberror; -if ( liberror ) -{ - failloop(7); -} + extern int liberror; + if (liberror) + { + failloop(7); + } + lastlooptime = gettime(); - lastlooptime = gettime(); + // + // + // MAIN LOOP + // + // + #ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE + setup_4way_external_interrupt(); + #endif -// -// -// MAIN LOOP -// -// + while (1) + { + // gettime() needs to be called at least once per second + unsigned long time = gettime(); + looptime = ((uint32_t)(time - lastlooptime)); -#ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE - setup_4way_external_interrupt(); -#endif - - while(1) - { - // gettime() needs to be called at least once per second - unsigned long time = gettime(); - looptime = ((uint32_t)( time - lastlooptime)); - if ( looptime <= 0 ) looptime = 1; - looptime = looptime * 1e-6f; - if ( looptime > 0.02f ) // max loop 20ms - { - failloop( 6); - //endless loop - } - - #ifdef DEBUG - debug.totaltime += looptime; - lpf ( &debug.timefilt , looptime, 0.998 ); - #endif - lastlooptime = time; - - if ( liberror > 20) - { - failloop(8); - // endless loop - } - - // read gyro and accelerometer data - sixaxis_read(); - - // all flight calculations and motors - control(); - - // attitude calculations for level mode - extern void imu_calc(void); - imu_calc(); - - -// battery low logic - - // read acd and scale based on processor voltage - float battadc = adc_read(0)*vreffilt; - // read and filter internal reference - lpf ( &vreffilt , adc_read(1) , 0.9968f); - - - - // average of all 4 motor thrusts - // should be proportional with battery current - extern float thrsum; // from control.c - - // filter motorpwm so it has the same delay as the filtered voltage - // ( or they can use a single filter) - lpf ( &thrfilt , thrsum , 0.9968f); // 0.5 sec at 1.6ms loop time - - float vbattfilt_corr = 4.2f * lipo_cell_count; - // li-ion battery model compensation time decay ( 18 seconds ) - lpf ( &vbattfilt_corr , vbattfilt , FILTERCALC( 1000 , 18000e3) ); - - lpf ( &vbattfilt , battadc , 0.9968f); - - -// compensation factor for li-ion internal model -// zero to bypass -#define CF1 0.25f - - float tempvolt = vbattfilt*( 1.00f + CF1 ) - vbattfilt_corr* ( CF1 ); - -#ifdef AUTO_VDROP_FACTOR - -static float lastout[12]; -static float lastin[12]; -static float vcomp[12]; -static float score[12]; -static int z = 0; -static int minindex = 0; -static int firstrun = 1; - - -if( thrfilt > 0.1f ) -{ - vcomp[z] = tempvolt + (float) z *0.1f * thrfilt; - - if ( firstrun ) + if (looptime <= 0) + looptime = 1; + looptime = looptime * 1e-6f; + + if (looptime > 0.02f) // max loop 20ms { - for (int y = 0 ; y < 12; y++) lastin[y] = vcomp[z]; - firstrun = 0; + failloop(6); + // endless loop } - float ans; - // y(n) = x(n) - x(n-1) + R * y(n-1) - // out = in - lastin + coeff*lastout - // hpf - ans = vcomp[z] - lastin[z] + FILTERCALC( 1000*12 , 6000e3) *lastout[z]; - lastin[z] = vcomp[z]; - lastout[z] = ans; - lpf ( &score[z] , ans*ans , FILTERCALC( 1000*12 , 60e6 ) ); - z++; - - if ( z >= 12 ) + + #ifdef DEBUG + debug.totaltime += looptime; + lpf(&debug.timefilt, looptime, 0.998); + #endif + lastlooptime = time; + + if (liberror > 20) { - z = 0; - float min = score[0]; - for ( int i = 0 ; i < 12; i++ ) - { - if ( (score[i]) < min ) - { - min = (score[i]); - minindex = i; - // add an offset because it seems to be usually early - minindex++; - } - } + failloop(8); + // endless loop } -} + // read gyro and accelerometer data + sixaxis_read(); -#undef VDROP_FACTOR -#define VDROP_FACTOR minindex * 0.1f -#endif + // all flight calculations and motors + control(); - float hyst; - if ( lowbatt ) hyst = HYST; - else hyst = 0.0f; + // attitude calculations for level mode + extern void imu_calc(void); + imu_calc(); - if (( tempvolt + (float) VDROP_FACTOR * thrfilt <(float) VBATTLOW + hyst ) - || ( vbattfilt < ( float ) 2.7f ) ) - lowbatt = 1; - else lowbatt = 0; + // battery low logic - vbatt_comp = tempvolt + (float) VDROP_FACTOR * thrfilt; + // read acd and scale based on processor voltage + float battadc = adc_read(0) * vreffilt; + // read and filter internal reference + lpf(&vreffilt, adc_read(1), 0.9968f); - -#ifdef DEBUG - debug.vbatt_comp = vbatt_comp ; -#endif -// check gestures - if ( onground ) - { - gestures( ); - } + // average of all 4 motor thrusts + // should be proportional with battery current + extern float thrsum; // from control.c - + // filter motorpwm so it has the same delay as the filtered voltage + // ( or they can use a single filter) + lpf(&thrfilt, thrsum, 0.9968f); // 0.5 sec at 1.6ms loop + // time + float vbattfilt_corr = 4.2f * lipo_cell_count; + // li-ion battery model compensation time decay ( 18 seconds ) + lpf(&vbattfilt_corr, vbattfilt, FILTERCALC(1000, 18000e3)); -if ( LED_NUMBER > 0) -{ -// led flash logic - if ( lowbatt ) - ledflash ( 500000 , 8); - else + lpf(&vbattfilt, battadc, 0.9968f); + + // compensation factor for li-ion internal model + // zero to bypass + #define CF1 0.25f + + float tempvolt = vbattfilt * (1.00f + CF1) - vbattfilt_corr * (CF1); + + #ifdef AUTO_VDROP_FACTOR + + static float lastout[12]; + static float lastin[12]; + static float vcomp[12]; + static float score[12]; + static int z = 0; + static int minindex = 0; + static int firstrun = 1; + + if (thrfilt > 0.1f) { - if ( rxmode == RXMODE_BIND) - {// bind mode - ledflash ( 100000, 12); - }else - {// non bind - if ( failsafe) - { - ledflash ( 500000, 15); - } - else - { - int leds_on = !aux[LEDS_ON]; - if (ledcommand) - { - if (!ledcommandtime) - ledcommandtime = gettime(); - if (gettime() - ledcommandtime > 500000) - { - ledcommand = 0; - ledcommandtime = 0; - } - ledflash(100000, 8); - } - else if (ledblink) - { - unsigned long time = gettime(); - if (!ledcommandtime) - { - ledcommandtime = time; - if ( leds_on) ledoff(255); - else ledon(255); - } - if ( time - ledcommandtime > 500000) - { - ledblink--; - ledcommandtime = 0; - } - if ( time - ledcommandtime > 300000) - { - if ( leds_on) ledon(255); - else ledoff(255); - } - } - else if ( leds_on ) - { - if ( LED_BRIGHTNESS != 15) - led_pwm(LED_BRIGHTNESS); - else ledon(255); - } - else ledoff(255); - } - } + vcomp[z] = tempvolt + (float)z * 0.1f * thrfilt; + + if (firstrun) + { + for (int y = 0; y < 12; y++) lastin[y] = vcomp[z]; + firstrun = 0; + } + float ans; + // y(n) = x(n) - x(n-1) + R * y(n-1) + // out = in - lastin + coeff*lastout + // hpf + ans = vcomp[z] - lastin[z] + FILTERCALC(1000 * 12, 6000e3) * lastout[z]; + lastin[z] = vcomp[z]; + lastout[z] = ans; + lpf(&score[z], ans * ans, FILTERCALC(1000 * 12, 60e6)); + z++; + + if (z >= 12) + { + z = 0; + float min = score[0]; + for (int i = 0; i < 12; i++) + { + if ((score[i]) < min) + { + min = (score[i]); + minindex = i; + // add an offset because it seems to be usually early + minindex++; + } + } + } + } -} + #undef VDROP_FACTOR + #define VDROP_FACTOR minindex * 0.1f + #endif + + float hyst; + if (lowbatt) + hyst = HYST; + else + hyst = 0.0f; -#if ( RGB_LED_NUMBER > 0) -// RGB led control -extern void rgb_led_lvc( void); -rgb_led_lvc( ); -#ifdef RGB_LED_DMA -extern void rgb_dma_start(); -rgb_dma_start(); -#endif -#endif + if ((tempvolt + (float)VDROP_FACTOR * thrfilt < (float)VBATTLOW + hyst) + || (vbattfilt < ( float )2.7f)) + lowbatt = 1; + else + lowbatt = 0; + vbatt_comp = tempvolt + (float)VDROP_FACTOR * thrfilt; -#ifdef BUZZER_ENABLE - buzzer(); -#endif + #ifdef DEBUG + debug.vbatt_comp = vbatt_comp; + #endif - -#ifdef FPV_ON -// fpv switch - static int fpv_init = 0; - if ( !fpv_init && rxmode == RXMODE_NORMAL ) { - fpv_init = gpio_init_fpv(); + // check gestures + if (onground) + { + gestures(); + } + + if (LED_NUMBER > 0) + { + // led flash logic + if (lowbatt) + ledflash(500000, 8); + else + { + if (rxmode == RXMODE_BIND) // bind mode + { + ledflash(100000, 12); } - if ( fpv_init ) { - if ( failsafe ) { - GPIO_WriteBit( FPV_PORT, FPV_PIN, Bit_RESET ); - } else { - GPIO_WriteBit( FPV_PORT, FPV_PIN, aux[ FPV_ON ] ? Bit_SET : Bit_RESET ); + else // non bind + { + if (failsafe) + { + ledflash(500000, 15); + } + else + { + int leds_on = !aux[LEDS_ON]; + + if (ledcommand) + { + if (!ledcommandtime) + ledcommandtime = gettime(); + + if (gettime() - ledcommandtime > 500000) + { + ledcommand = 0; + ledcommandtime = 0; + } + ledflash(100000, 8); + } + else if (ledblink) + { + unsigned long time = gettime(); + + if (!ledcommandtime) + { + ledcommandtime = time; + + if (leds_on) + ledoff(255); + else + ledon(255); + } + + if (time - ledcommandtime > 500000) + { + ledblink--; + ledcommandtime = 0; + } + + if (time - ledcommandtime > 300000) + { + if (leds_on) + ledon(255); + else + ledoff(255); + } + } + else if (leds_on) + { + if (LED_BRIGHTNESS != 15) + led_pwm(LED_BRIGHTNESS); + else + ledon(255); + } + else + ledoff(255); + } } + } } -#endif -#ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE - extern int onground; - if (onground) - { - NVIC_EnableIRQ(EXTI4_15_IRQn); - - if (switch_to_4way) - { - switch_to_4way = 0; - - NVIC_DisableIRQ(EXTI4_15_IRQn); - ledon(2); - esc4wayInit(); - esc4wayProcess(); - NVIC_EnableIRQ(EXTI4_15_IRQn); - ledoff(2); - - lastlooptime = gettime(); - } - } - else - { - NVIC_DisableIRQ(EXTI4_15_IRQn); - } -#endif -// receiver function -checkrx(); + #if (RGB_LED_NUMBER > 0) + // RGB led control + extern void rgb_led_lvc(void); + rgb_led_lvc(); + #ifdef RGB_LED_DMA + extern void rgb_dma_start(); + rgb_dma_start(); + #endif + #endif + + #ifdef BUZZER_ENABLE + buzzer(); + #endif + + #ifdef FPV_ON + // fpv switch + static int fpv_init = 0; + if (!fpv_init && rxmode == RXMODE_NORMAL) + { + fpv_init = gpio_init_fpv(); + } -#ifdef DEBUG - debug.cpu_load = (gettime() - lastlooptime )*1e-3f; -#endif + if (fpv_init) + { + if (failsafe) + { + GPIO_WriteBit(FPV_PORT, FPV_PIN, Bit_RESET); + } + else + { + GPIO_WriteBit(FPV_PORT, FPV_PIN, aux[ FPV_ON ] ? Bit_SET : Bit_RESET); + } + } + #endif + #ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE + extern int onground; + + if (onground) + { + NVIC_EnableIRQ(EXTI4_15_IRQn); + + if (switch_to_4way) + { + switch_to_4way = 0; + + NVIC_DisableIRQ(EXTI4_15_IRQn); + ledon(2); + esc4wayInit(); + esc4wayProcess(); + NVIC_EnableIRQ(EXTI4_15_IRQn); + ledoff(2); + + lastlooptime = gettime(); + } + } + else + { + NVIC_DisableIRQ(EXTI4_15_IRQn); + } + #endif + + // receiver function + checkrx(); + + #ifdef DEBUG + debug.cpu_load = (gettime() - lastlooptime) * 1e-3f; + #endif -while ( (gettime() - time) < LOOPTIME ); + while ((gettime() - time) < LOOPTIME) ; - - }// end loop - + } // end loop } @@ -578,106 +573,103 @@ while ( (gettime() - time) < LOOPTIME ); // 4 - Gyro not found // 5 - clock , intterrupts , systick // 6 - loop time issue -// 7 - i2c error +// 7 - i2c error // 8 - i2c error main loop - -void failloop( int val) +void failloop(int val) { - for ( int i = 0 ; i <= 3 ; i++) - { - pwm_set( i ,0 ); - } - - while(1) - { - for ( int i = 0 ; i < val; i++) - { - ledon( 255); - delay(200000); - ledoff( 255); - delay(200000); - } - delay(800000); - } - -} + for (int i = 0; i <= 3; i++) + { + pwm_set(i, 0); + } + + while (1) + { + for (int i = 0; i < val; i++) + { + ledon(255); + delay(200000); + ledoff(255); + delay(200000); + } + delay(800000); + } +} void HardFault_Handler(void) { - failloop(5); + failloop(5); } -void MemManage_Handler(void) +void MemManage_Handler(void) { - failloop(5); + failloop(5); } -void BusFault_Handler(void) +void BusFault_Handler(void) { - failloop(5); + failloop(5); } -void UsageFault_Handler(void) +void UsageFault_Handler(void) { - failloop(5); + failloop(5); } - #ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE -// set up external interrupt to check +// set up external interrupt to check // for 4way serial start byte static void setup_4way_external_interrupt(void) { - SYSCFG->EXTICR[3] &= ~(0x000F) ; //clear bits 3:0 in the SYSCFG_EXTICR1 reg - EXTI->FTSR |= EXTI_FTSR_TR14; - EXTI->IMR |= EXTI_IMR_MR14; - NVIC_SetPriority(EXTI4_15_IRQn,2); + SYSCFG->EXTICR[3] &= ~(0x000F); // clear bits 3:0 in the SYSCFG_EXTICR1 + // reg + EXTI->FTSR |= EXTI_FTSR_TR14; + EXTI->IMR |= EXTI_IMR_MR14; + NVIC_SetPriority(EXTI4_15_IRQn, 2); } // interrupt for detecting blheli serial 4way // start byte (0x2F) on PA14 at 38400 baud void EXTI4_15_IRQHandler(void) { - if( (EXTI->IMR & EXTI_IMR_MR14) && (EXTI->PR & EXTI_PR_PR14)) - { -#define IS_RX_HIGH (GPIOA->IDR & GPIO_Pin_14) - uint32_t micros_per_bit = 26; - uint32_t micros_per_bit_half = 13; - - uint32_t i = 0; - // looking for 2F - uint8_t start_byte = 0x2F; - uint32_t time_next = gettime(); - time_next += micros_per_bit_half; // move away from edge to center of bit - - for (; i < 8; ++i) - { - time_next += micros_per_bit; - delay_until(time_next); - if ((0 == IS_RX_HIGH) != (0 == (start_byte & (1 << i)))) - { - i = 0; - break; - } - } - - if (i == 8) - { - time_next += micros_per_bit; - delay_until(time_next); // move away from edge - - if (IS_RX_HIGH) // stop bit - { - // got the start byte - switch_to_4way = 1; - } - } - - // clear pending request - EXTI->PR |= EXTI_PR_PR14 ; - } -} -#endif - + if ((EXTI->IMR & EXTI_IMR_MR14) && (EXTI->PR & EXTI_PR_PR14)) + { + #define IS_RX_HIGH (GPIOA->IDR & GPIO_Pin_14) + uint32_t micros_per_bit = 26; + uint32_t micros_per_bit_half = 13; + + uint32_t i = 0; + // looking for 2F + uint8_t start_byte = 0x2F; + uint32_t time_next = gettime(); + time_next += micros_per_bit_half; // move away from edge to + // center of bit + + for (; i < 8; ++i) + { + time_next += micros_per_bit; + delay_until(time_next); + + if ((0 == IS_RX_HIGH) != (0 == (start_byte & (1 << i)))) + { + i = 0; + break; + } + } + if (i == 8) + { + time_next += micros_per_bit; + delay_until(time_next); // move away from edge + + if (IS_RX_HIGH) // stop bit + { + // got the start byte + switch_to_4way = 1; + } + } + // clear pending request + EXTI->PR |= EXTI_PR_PR14; + } +} +#endif diff --git a/uncrustify.bat b/uncrustify.bat new file mode 100644 index 0000000..9553ad5 --- /dev/null +++ b/uncrustify.bat @@ -0,0 +1,45 @@ +@echo off + +IF (%1)==() GOTO error +dir /b /ad %1 >nul 2>nul && GOTO indentDir +IF NOT EXIST %1 GOTO error +goto indentFile + +:indentDir +set searchdir=%1 + +IF (%2)==() GOTO assignDefaultSuffix +set filesuffix=%2 + +GOTO run + +:assignDefaultSuffix +::echo !!!!DEFAULT SUFFIX!!! +set filesuffix=* + +:run +FOR /F "tokens=*" %%G IN ('DIR /B /S %searchdir%\*.%filesuffix%') DO ( +echo Indenting file "%%G" +uncrustify.exe -f "%%G" -c "./uncrustify.cfg" -o indentoutput.tmp +move /Y indentoutput.tmp "%%G" + +) +GOTO ende + +:indentFile +echo Indenting one file %1 +uncrustify.exe -f "%1" -c "./uncrustify.cfg" -o indentoutput.tmp +move /Y indentoutput.tmp "%1" + + +GOTO ende + +:error +echo . +echo ERROR: As parameter given directory or file does not exist! +echo Syntax is: uncrustify.bat dirname filesuffix +echo Syntax is: uncrustify.bat filename +echo Example: uncrustify.bat temp cpp +echo . + +:ende diff --git a/uncrustify.cfg b/uncrustify.cfg new file mode 100644 index 0000000..128c458 --- /dev/null +++ b/uncrustify.cfg @@ -0,0 +1,147 @@ +tok_split_gte=false +utf8_byte=false +utf8_force=false +indent_cmt_with_tabs=false +indent_align_string=false +indent_braces=false +indent_braces_no_func=false +indent_braces_no_class=false +indent_braces_no_struct=false +indent_brace_parent=false +indent_namespace=false +indent_extern=false +indent_class=false +indent_class_colon=false +indent_else_if=false +indent_var_def_cont=false +indent_func_call_param=false +indent_func_def_param=false +indent_func_proto_param=false +indent_func_class_param=false +indent_func_ctor_var_param=false +indent_template_param=false +indent_func_param_double=false +indent_relative_single_line_comments=false +indent_col1_comment=true +indent_access_spec_body=false +indent_paren_nl=false +indent_comma_paren=false +indent_bool_paren=false +indent_first_bool_expr=false +indent_square_nl=false +indent_preserve_sql=false +indent_align_assign=true +sp_balance_nested_parens=false +align_keep_tabs=false +align_with_tabs=false +align_on_tabstop=false +align_number_left=false +align_func_params=false +align_same_func_call_params=false +align_var_def_colon=false +align_var_def_attribute=false +align_var_def_inline=false +align_right_cmt_mix=false +align_on_operator=false +align_mix_var_proto=false +align_single_line_func=false +align_single_line_brace=false +align_nl_cont=false +align_left_shift=true +align_oc_decl_colon=false +nl_collapse_empty_body=false +nl_assign_leave_one_liners=false +nl_class_leave_one_liners=false +nl_enum_leave_one_liners=false +nl_getset_leave_one_liners=false +nl_func_leave_one_liners=false +nl_if_leave_one_liners=false +nl_multi_line_cond=false +nl_multi_line_define=false +nl_before_case=false +nl_after_case=false +nl_after_return=false +nl_after_semicolon=false +nl_after_brace_open=false +nl_after_brace_open_cmt=false +nl_after_vbrace_open=false +nl_after_vbrace_open_empty=false +nl_after_brace_close=false +nl_after_vbrace_close=false +nl_define_macro=false +nl_squeeze_ifdef=false +nl_ds_struct_enum_cmt=false +nl_ds_struct_enum_close_brace=false +nl_create_if_one_liner=false +nl_create_for_one_liner=false +nl_create_while_one_liner=false +ls_for_split_full=false +ls_func_split_full=false +nl_after_multiline_comment=false +eat_blanks_after_open_brace=false +eat_blanks_before_close_brace=false +mod_full_brace_if_chain=false +mod_pawn_semicolon=false +mod_full_paren_if_bool=false +mod_remove_extra_semicolon=false +mod_sort_import=false +mod_sort_using=false +mod_sort_include=false +mod_move_case_break=false +mod_remove_empty_return=false +cmt_indent_multi=false +cmt_c_group=false +cmt_c_nl_start=false +cmt_c_nl_end=false +cmt_cpp_group=false +cmt_cpp_nl_start=false +cmt_cpp_nl_end=false +cmt_cpp_to_c=false +cmt_star_cont=false +cmt_multi_check_last=false +cmt_insert_before_preproc=false +pp_indent_at_level=true +pp_region_indent_code=false +pp_if_indent_code=false +pp_define_at_level=true +indent_columns=2 +indent_brace=0 +nl_start_of_file_min=0 +nl_end_of_file_min=1 +nl_max=2 +cmt_width=80 +indent_with_tabs=0 +sp_arith=force +sp_assign=force +sp_compare=force +sp_inside_paren=remove +sp_paren_paren=remove +sp_paren_brace=force +sp_before_ptr_star=force +sp_between_ptr_star=remove +sp_before_byref=force +sp_after_byref=remove +sp_before_sparen=force +sp_inside_sparen=remove +sp_inside_sparen_close=remove +sp_after_sparen=force +sp_sparen_brace=add +sp_after_comma=force +sp_before_comma=remove +sp_after_cast=remove +sp_inside_braces=remove +sp_inside_fparens=remove +sp_inside_fparen=remove +sp_func_call_paren=remove +sp_return_paren=force +sp_macro=add +sp_cond_colon=force +sp_cond_question=force +sp_cmt_cpp_start=force +sp_before_tr_emb_cmt=force +nl_start_of_file=remove +nl_end_of_file=add +nl_if_brace=force +nl_brace_else=force +nl_else_brace=force +nl_before_if=add