Skip to content

Commit 6b2aa7a

Browse files
author
Matthew West
committed
Change return value convention for errors
Replace 1 for success and 0/-1 for failure with an enum type.
1 parent 8a2e4d1 commit 6b2aa7a

File tree

12 files changed

+279
-169
lines changed

12 files changed

+279
-169
lines changed

source/c_adc.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ SOFTWARE.
3838

3939
int adc_initialized = 0;
4040

41-
int initialize_adc(void)
41+
BBIO_err initialize_adc(void)
4242
{
4343
#ifdef BBBVERSION41
4444
char test_path[49];
@@ -47,7 +47,7 @@ int initialize_adc(void)
4747
#endif
4848
FILE *fh;
4949
if (adc_initialized) {
50-
return 1;
50+
return BBIO_OK;
5151
}
5252

5353
#ifdef BBBVERSION41
@@ -57,13 +57,12 @@ int initialize_adc(void)
5757
fh = fopen(test_path, "r");
5858

5959
if (!fh) {
60-
puts("wiiii");
61-
return 0;
60+
return BBIO_SYSFS;
6261
}
6362
fclose(fh);
6463

6564
adc_initialized = 1;
66-
return 1;
65+
return BBIO_OK;
6766
}
6867
#else
6968
if (load_device_tree("cape-bone-iio")) {
@@ -74,19 +73,19 @@ int initialize_adc(void)
7473
fh = fopen(test_path, "r");
7574

7675
if (!fh) {
77-
return 0;
76+
return BBIO_SYSFS;
7877
}
7978
fclose(fh);
8079

8180
adc_initialized = 1;
82-
return 1;
81+
return BBIO_OK;
8382
}
8483
#endif
8584

86-
return 0;
85+
return BBIO_GEN;
8786
}
8887

89-
int read_value(unsigned int ain, float *value)
88+
BBIO_err read_value(unsigned int ain, float *value)
9089
{
9190
FILE * fh;
9291
#ifdef BBBVERSION41
@@ -109,7 +108,7 @@ int read_value(unsigned int ain, float *value)
109108

110109
// Likely a bad path to the ocp device driver
111110
if (!fh) {
112-
return -1;
111+
return BBIO_SYSFS;
113112
}
114113

115114
fseek(fh, 0, SEEK_SET);
@@ -121,22 +120,22 @@ int read_value(unsigned int ain, float *value)
121120
try_count++;
122121
}
123122

124-
if (read_successful) return 1;
123+
if (read_successful) return BBIO_OK;
125124

126125
// Fall through and fail
127-
return -1;
126+
return BBIO_GEN;
128127
}
129128

130-
int adc_setup()
129+
BBIO_err adc_setup()
131130
{
132131
return initialize_adc();
133132
}
134133

135-
void adc_cleanup(void)
134+
BBIO_err adc_cleanup(void)
136135
{
137136
#ifdef BBBVERSION41
138-
unload_device_tree("BB-ADC");
137+
return unload_device_tree("BB-ADC");
139138
#else
140-
unload_device_tree("cape-bone-iio");
139+
return unload_device_tree("cape-bone-iio");
141140
#endif
142141
}

source/c_adc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SOFTWARE.
2626

2727
extern int adc_initialized;
2828

29-
int adc_setup(void);
30-
int read_value(unsigned int ain, float *value);
31-
void adc_cleanup(void);
29+
BBIO_err adc_setup(void);
30+
BBIO_err read_value(unsigned int ain, float *value);
31+
BBIO_err adc_cleanup(void);
3232
#endif

source/c_pinmux.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include "common.h"
66

77

8-
// 0 = success
9-
// non-zero = error
10-
int set_pin_mode(const char *key, const char *mode)
8+
BBIO_err set_pin_mode(const char *key, const char *mode)
119
{
1210
// char ocp_dir[30] "/sys/devices/platform/ocp"
1311
char path[60]; // "/sys/devices/platform/ocp/ocp:P#_##_pinmux/state"
@@ -21,11 +19,11 @@ int set_pin_mode(const char *key, const char *mode)
2119

2220
f = fopen(path, "w");
2321
if (NULL == f) {
24-
return -1;
22+
return BBIO_ACCESS;
2523
}
2624

2725
fprintf(f, "%s", mode);
2826
fclose(f);
2927

30-
return 0;
28+
return BBIO_OK;
3129
}

source/c_pinmux.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ SOFTWARE.
2424
#ifndef C_PINMUX_H
2525
#define C_PINMUX_H
2626

27-
int set_pin_mode(const char *key, const char *mode);
27+
#include "common.h"
2828

29-
#endif
29+
BBIO_err set_pin_mode(const char *key, const char *mode);
30+
31+
#endif

0 commit comments

Comments
 (0)