]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
ADCuC: whitespace fixes / 2spaces instead of tabs
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 13 Jul 2017 11:53:37 +0000 (13:53 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 13 Jul 2017 11:53:55 +0000 (13:53 +0200)
atmega32u4/adcuc/main.c
atmega32u4/adcuc/usb_serial.c
atmega32u4/adcuc/usb_serial.h

index 0fb80c9d9f55addfa39664180218ee9888a5b4f6..9f00fd5f1b2241960af0322b61475ef62eacc652 100644 (file)
@@ -18,7 +18,7 @@
 //Select:           PD5
 
 //all commands end in \n
-// cc          -- channel address in hex 
+// cc          -- channel address in hex
 //Scc(0|1|/)   -- switch channel off/on/toggle
 //Scc?         -- read channel status - 2nd char: 'e' in case of overcurrent, 3rd char: enable 1/0
 //Ccc?         -- read current
@@ -92,13 +92,13 @@ void send_answer_hex(uint8_t chan, uint16_t v) {
   usb_serial_write(txbuf,8);
   usb_serial_flush_output();
   }
-    
-    
+
+
 
 ISR(TIMER0_OVF_vect) {
   time++;
   asm volatile("wdr");
-  }  
+  }
 
 void getdata(uint8_t buf) {
   if (rxcnt != 0 || (buf == 'S' || buf == 'A' || buf == 'L' || buf == 'C' || buf == 'I'
@@ -110,68 +110,66 @@ void getdata(uint8_t buf) {
       if (rxbuf[0] == 'A') {
         // do something
         }
-
-      }      
+      }
     }
-  if (rxcnt >= 7 || buf == '\n' || buf == '\r') { rxcnt = 0; }  
-  } 
+  if (rxcnt >= 7 || buf == '\n' || buf == '\r') { rxcnt = 0; }
+  }
 
 void original_value(uint8_t channel, uint8_t get_value_1, uint8_t get_value_2) {
   uint16_t result = (get_value_1 << 8) | get_value_2;
-  send_answer_hex(channel,result);  
-}
-  
+  send_answer_hex(channel,result);
+  }
+
 void update_eeprom(void) {
   //etc...
   // eeprom_update_byte((uint8_t*)0x28,adc_enable);
   }
 
 void do_channel(uint8_t channel) {
-    uint8_t get_value_1;
-    uint8_t get_value_2;
-    if(channel<4) 
-      ADC1_select(); 
-    else 
-      ADC2_select();
-       SPDR  = 0b11000011 + ((channel & 0b00000011) << 4); // MSB=Byte1
-       while ((SPSR & (1<<SPIF)) == 0);
-               get_value_1 = SPDR;
-       SPDR  = 0b11101011; // LSB=Byte2
-       while ((SPSR & (1<<SPIF)) == 0);
-               get_value_2 = SPDR;
-    if(channel<4) 
-      ADC1_unselect(); 
-    else 
-      ADC2_unselect();
-       }  
+  uint8_t get_value_1;
+  uint8_t get_value_2;
+  if(channel<4)
+    ADC1_select();
+  else
+    ADC2_select();
+  SPDR  = 0b11000011 + ((channel & 0b00000011) << 4); // MSB=Byte1
+  while ((SPSR & (1<<SPIF)) == 0) {};
+  get_value_1 = SPDR;
+  SPDR  = 0b11101011; // LSB=Byte2
+  while ((SPSR & (1<<SPIF)) == 0) {};
+  get_value_2 = SPDR;
+  if(channel<4)
+    ADC1_unselect();
+  else
+    ADC2_unselect();
+  }
 
 void read_channel(uint8_t channel) {
-    uint8_t get_value_1;
-    uint8_t get_value_2;
-    if(channel<4)
-      ADC1_select();
-    else
-      ADC2_select();
-               SPDR  = 0b00000000; // MSB=Byte1
-       while ((SPSR & (1<<SPIF)) == 0);
-               get_value_1 = SPDR;
-       SPDR  = 0b00000000; // LSB=Byte2
-       while ((SPSR & (1<<SPIF)) == 0);
-               get_value_2 = SPDR;
-    if(channel<4)
-      ADC1_unselect();
-    else
-      ADC2_unselect();
-
-    original_value(channel, get_value_1, get_value_2);
-}      
+  uint8_t get_value_1;
+  uint8_t get_value_2;
+  if(channel<4)
+    ADC1_select();
+  else
+    ADC2_select();
+  SPDR  = 0b00000000; // MSB=Byte1
+  while ((SPSR & (1<<SPIF)) == 0) {};
+  get_value_1 = SPDR;
+  SPDR  = 0b00000000; // LSB=Byte2
+  while ((SPSR & (1<<SPIF)) == 0) {};
+  get_value_2 = SPDR;
+  if(channel<4)
+    ADC1_unselect();
+  else
+    ADC2_unselect();
+  original_value(channel, get_value_1, get_value_2);
+  }
 
 
 __attribute__((naked)) int main(void) {
-  
+
   CLKPR = (1 << CLKPCE); // prescaler 2 = 8 MHz
   CLKPR = (1 << CLKPS0); // prescaler 2
-  usb_init(); 
+  usb_init();
 
 
  // Configure ports
@@ -181,10 +179,10 @@ __attribute__((naked)) int main(void) {
  //UART: RX PD2, TX PD3
  //SPI: out: PB2, PB1 ; in: PB3
  //CS: PB7, PB0
-  
+
   MCUCR |= (1<<JTD);
   MCUCR |= (1<<JTD);  //yes, twice
-  
+
   PORTB = 0b11011001;
   DDRB  = 0b10000111;
 
@@ -194,27 +192,27 @@ __attribute__((naked)) int main(void) {
   PORTF = 0b11010011;
   DDRF  = 0b01100000;
 
-  PORTC = 0b11000000; 
+  PORTC = 0b11000000;
   DDRC  = 0b00000000;
 
   PORTE = 0b01000000;
   DDRE  = 0b00000000;
-  
-  //limit[3]  |= eeprom_read_byte((uint8_t*)0x26);  
-  
+
+  //limit[3]  |= eeprom_read_byte((uint8_t*)0x26);
+
   //Timer0 at ~488 Hz overflow for ADC control and buttons
   TCCR0B = 4 << CS00; //(1 << CS01) | (1 << CS00);
   TIMSK0 = (1 << TOIE0); //Overflow interrupt`
 
-  
+
   //SPI  2 MHz, Master, mode 1, no interrupts
   SPCR = (1 << SPE) | (1 << MSTR) | (0 << CPOL) | (1 << CPHA) | ( 0 << SPR0);
 
   //Watchdog at .5 seconds
   WDTCSR = (1<<WDCE);
-  WDTCSR = (1<<WDE) | (5<<WDP0); 
-  sei();  
-  
+  WDTCSR = (1<<WDE) | (5<<WDP0);
+  sei();
+
   uint16_t lasttime = 0;
   uint16_t step = 0;
 
@@ -224,8 +222,15 @@ __attribute__((naked)) int main(void) {
       getdata(n);
       n = usb_serial_getchar();
       }
-      
+
     if(time != lasttime) {
+      /*
+      LED2_ON();
+      _delay_us(500);
+      LED2_OFF();
+      _delay_us(500);
+      */
+
       switch(step++) {
         case 10: do_channel(0); break;
         case 20: read_channel(0); break;
@@ -249,7 +254,7 @@ __attribute__((naked)) int main(void) {
         step = 0;
         }
       }
-      
+
 //  update_eeprom();
     lasttime = time;
     }
index 1a4bc2d3a21c5f31923632897cc576dd9c539644..331783e7ec090a1892652ed46d1cb9c56e621be2 100644 (file)
@@ -357,7 +357,7 @@ int16_t usb_serial_getchar(void)
                 if (c & (1<<RXOUTI)) {
                         UEINTX = 0x6B;
                         goto retry;
-                }        
+                }
                 SREG = intr_state;
                 return -1;
         }
@@ -398,7 +398,7 @@ void usb_serial_flush_input(void)
                 cli();
                 UENUM = CDC_RX_ENDPOINT;
                 while ((UEINTX & (1<<RWAL))) {
-                        UEINTX = 0x6B; 
+                        UEINTX = 0x6B;
                 }
                 SREG = intr_state;
         }
@@ -455,7 +455,7 @@ int8_t usb_serial_putchar(uint8_t c)
 
 
 // transmit a character, but do not wait if the buffer is full,
-//   0 returned on success, -1 on buffer full or error 
+//   0 returned on success, -1 on buffer full or error
 int8_t usb_serial_putchar_nowait(uint8_t c)
 {
         uint8_t intr_state;
index 14c5b1a7557f8805960a05b81ec72a41502acae1..a8db3415fcd54a4002813b2e262f14b142e77521 100644 (file)
@@ -79,7 +79,7 @@ int8_t usb_serial_set_control(uint8_t signals); // set DSR, DCD, RI, etc
 #define MSB(n) ((n >> 8) & 255)
 
 #if defined(__AVR_AT90USB162__)
-#define HW_CONFIG() 
+#define HW_CONFIG()
 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
 #define USB_CONFIG() (USBCON = (1<<USBE))
 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))