@@ -38,55 +38,58 @@ SOFTWARE.
3838
3939int adc_initialized = 0 ;
4040
41- int initialize_adc (void )
41+ BBIO_err initialize_adc (void )
4242{
4343#ifdef BBBVERSION41
4444 char test_path [49 ];
4545#else
4646 char test_path [40 ];
4747#endif
4848 FILE * fh ;
49+ BBIO_err err ;
50+
4951 if (adc_initialized ) {
50- return 1 ;
52+ return BBIO_OK ;
5153 }
5254
5355#ifdef BBBVERSION41
54- if (load_device_tree ("BB-ADC" )) {
56+ err = load_device_tree ("BB-ADC" );
57+ if (err == BBIO_OK ) {
5558 strncat (adc_prefix_dir , "/sys/bus/iio/devices/iio:device0/in_voltage" , sizeof (adc_prefix_dir ));
5659 snprintf (test_path , sizeof (test_path ), "%s%d_raw" , adc_prefix_dir , 1 );
5760 fh = fopen (test_path , "r" );
5861
5962 if (!fh ) {
60- puts ("wiiii" );
61- return 0 ;
63+ return BBIO_SYSFS ;
6264 }
6365 fclose (fh );
6466
6567 adc_initialized = 1 ;
66- return 1 ;
68+ return BBIO_OK ;
6769 }
6870#else
69- if (load_device_tree ("cape-bone-iio" )) {
71+ err = load_device_tree ("cape-bone-iio" );
72+ if (err == BBIO_OK ) {
7073 build_path ("/sys/devices" , "ocp." , ocp_dir , sizeof (ocp_dir ));
7174 build_path (ocp_dir , "helper." , adc_prefix_dir , sizeof (adc_prefix_dir ));
7275 strncat (adc_prefix_dir , "/AIN" , sizeof (adc_prefix_dir ));
7376 snprintf (test_path , sizeof (test_path ), "%s%d" , adc_prefix_dir , 0 );
7477 fh = fopen (test_path , "r" );
7578
7679 if (!fh ) {
77- return 0 ;
80+ return BBIO_SYSFS ;
7881 }
7982 fclose (fh );
8083
8184 adc_initialized = 1 ;
82- return 1 ;
85+ return BBIO_OK ;
8386 }
8487#endif
8588
86- return 0 ;
89+ return BBIO_GEN ;
8790}
8891
89- int read_value (unsigned int ain , float * value )
92+ BBIO_err read_value (unsigned int ain , float * value )
9093{
9194 FILE * fh ;
9295#ifdef BBBVERSION41
@@ -109,7 +112,7 @@ int read_value(unsigned int ain, float *value)
109112
110113 // Likely a bad path to the ocp device driver
111114 if (!fh ) {
112- return -1 ;
115+ return BBIO_SYSFS ;
113116 }
114117
115118 fseek (fh , 0 , SEEK_SET );
@@ -121,22 +124,22 @@ int read_value(unsigned int ain, float *value)
121124 try_count ++ ;
122125 }
123126
124- if (read_successful ) return 1 ;
127+ if (read_successful ) return BBIO_OK ;
125128
126129 // Fall through and fail
127- return -1 ;
130+ return BBIO_GEN ;
128131}
129132
130- int adc_setup ()
133+ BBIO_err adc_setup (void )
131134{
132135 return initialize_adc ();
133136}
134137
135- void adc_cleanup (void )
138+ BBIO_err adc_cleanup (void )
136139{
137140#ifdef BBBVERSION41
138- unload_device_tree ("BB-ADC" );
141+ return unload_device_tree ("BB-ADC" );
139142#else
140- unload_device_tree ("cape-bone-iio" );
143+ return unload_device_tree ("cape-bone-iio" );
141144#endif
142145}
0 commit comments