Index: analog.c
===================================================================
--- analog.c	(revision 1460)
+++ analog.c	(revision 1461)
@@ -49,6 +49,8 @@
  * @{
  **/
 
+unsigned char analog_initd=0;
+
 volatile int adc_loop_status = ADC_LOOP_STOPPED;
 volatile int adc_sig_stop_loop = 0;
 volatile int adc_current_port = 0;
@@ -58,6 +60,8 @@
  * Initializes the ADC.
  * Call analog_init before reading from the analog ports.
  *
+ * @return returns 0 on success, nonzero on error
+ *
  * @see analog8, analog10, analog_get8, analog_get10
  *
  * @bug First conversion takes a performance penalty of
@@ -73,43 +77,49 @@
  * determine highest clock speed for accurate 8-bit ADC.
  *
  **/
-void analog_init(int start_conversion) {
-	for (int i = 0; i < 11; i++) {
-		an_val[i].adc10 = 0;
-		an_val[i].adc8 = 0;
-	}
+int analog_init(int start_conversion) {
+  if(analog_initd)
+    return ERROR_INIT_ALREADY_INITD;
 
-	// ADMUX register
-	// Bit 7,6 - Set voltage reference to AVcc (0b01)
-	// Bit 5 - ADLAR set to simplify moving from register
-	// Bit 4 - X
-	// Bit 3:0 - Sets the current channel
-	// Initializes to read from AN1 first (AN0 is reservered for the BOM)
-	ADMUX = 0;
-	ADMUX |= ADMUX_OPT | _BV(MUX0);
+  for (int i = 0; i < 11; i++) {
+    an_val[i].adc10 = 0;
+    an_val[i].adc8 = 0;
+  }
 
-	// ADC Status Register A
-	// Bit 7 - ADEN is set (enables analog)
-	// Bit 6 - Start conversion bit is set (must be done once for free-running mode)
-	// Bit 5 - Enable Auto Trigger (for free running mode) NOT DOING THIS RIGHT NOW
-	// Bit 4 - ADC interrupt flag, 0
-	// Bit 3 - Enable ADC Interrupt (required to run free-running mode)
-	// Bits 2-0 - Set to create a clock divisor of 128, to make ADC clock = 8,000,000/64 = 125kHz
-	ADCSRA = 0;
-	ADCSRA |= _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
+  // ADMUX register
+  // Bit 7,6 - Set voltage reference to AVcc (0b01)
+  // Bit 5 - ADLAR set to simplify moving from register
+  // Bit 4 - X
+  // Bit 3:0 - Sets the current channel
+  // Initializes to read from AN1 first (AN0 is reservered for the BOM)
+  ADMUX = 0;
+  ADMUX |= ADMUX_OPT | _BV(MUX0);
+
+  // ADC Status Register A
+  // Bit 7 - ADEN is set (enables analog)
+  // Bit 6 - Start conversion bit is set (must be done once for free-running mode)
+  // Bit 5 - Enable Auto Trigger (for free running mode) NOT DOING THIS RIGHT NOW
+  // Bit 4 - ADC interrupt flag, 0
+  // Bit 3 - Enable ADC Interrupt (required to run free-running mode)
+  // Bits 2-0 - Set to create a clock divisor of 128, to make ADC clock = 8,000,000/64 = 125kHz
+  ADCSRA = 0;
+  ADCSRA |= _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
 	
-	// Set external mux lines to outputs
-	DDRG |= 0x1C;
+  // Set external mux lines to outputs
+  DDRG |= 0x1C;
 	
-	// Set up first port for conversions
-	set_adc_mux(0x00);
-	adc_current_port = AN1;
+  // Set up first port for conversions
+  set_adc_mux(0x00);
+  adc_current_port = AN1;
 
-	//Start the conversion loop if requested
-	if (start_conversion)
-		analog_start_loop();
+  //Start the conversion loop if requested
+  if (start_conversion)
+    analog_start_loop();
 		
-	//Conversion loop disabled by default
+  //Conversion loop disabled by default
+
+  analog_initd=1;
+  return 0;
 }	
 
 /**
@@ -170,15 +180,22 @@
  * Starts the analog update loop. Will continue to run
  * until analog_stop_loop is called.
  *
+ * @return returns 0 on success, nonzero on error
+ *
  * @see analog_stop_loop, analog_loop_status
  **/
-void analog_start_loop(void) {
-	if(adc_loop_status != ADC_LOOP_RUNNING){
-		//Start the conversion, enable ADC interrupt
-		ADCSRA |= _BV(ADIE);
-		ADCSRA |= _BV(ADSC);
-		adc_loop_status = ADC_LOOP_RUNNING;
-	}
+int analog_start_loop(void) {
+  if(!analog_initd)
+    return ERROR_LIBRARY_NOT_INITD;
+
+  if(adc_loop_status != ADC_LOOP_RUNNING){
+    //Start the conversion, enable ADC interrupt
+    ADCSRA |= _BV(ADIE);
+    ADCSRA |= _BV(ADSC);
+    adc_loop_status = ADC_LOOP_RUNNING;
+  }
+
+  return 0;
 }
 
 /**
@@ -187,11 +204,18 @@
  * is interrupted. No further updates will be made until
  * the loop is started again.
  *
+ * @return returns 0 on success, nonzero on error
+ *
  * @see analog_start_loop, analog_loop_status
  **/
-void analog_stop_loop() {
-	//Signal to stop after the next conversion
-	adc_sig_stop_loop = 1;
+int analog_stop_loop() {
+  if(!analog_initd)
+    return ERROR_LIBRARY_NOT_INITD;
+
+  //Signal to stop after the next conversion
+  adc_sig_stop_loop = 1;
+
+  return 0;
 }
 
 /**
