Skip to content

Commit 4b7e11f

Browse files
committed
Extract BBIO_err into a separate header
1 parent 2dd2ea5 commit 4b7e11f

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

setup.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
'Topic :: Home Automation',
3434
'Topic :: System :: Hardware']
3535

36+
extension_args = {
37+
'include_dirs': ['source/include/'],
38+
'extra_compile_args': CFLAGS,
39+
'define_macros': kernel41
40+
}
41+
3642
setup(name = 'Adafruit_BBIO',
3743
version = '1.0.3',
3844
author = 'Justin Cooper',
@@ -45,9 +51,9 @@
4551
classifiers = classifiers,
4652
packages = find_packages(),
4753
py_modules = ['Adafruit_I2C'],
48-
ext_modules = [Extension('Adafruit_BBIO.GPIO', ['source/py_gpio.c', 'source/event_gpio.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
49-
Extension('Adafruit_BBIO.PWM', ['source/py_pwm.c', 'source/c_pwm.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
50-
Extension('Adafruit_BBIO.ADC', ['source/py_adc.c', 'source/c_adc.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
51-
Extension('Adafruit_BBIO.SPI', ['source/spimodule.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
52-
Extension('Adafruit_BBIO.UART', ['source/py_uart.c', 'source/c_uart.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41)] )
54+
ext_modules = [Extension('Adafruit_BBIO.GPIO', ['source/py_gpio.c', 'source/event_gpio.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], **extension_args),
55+
Extension('Adafruit_BBIO.PWM', ['source/py_pwm.c', 'source/c_pwm.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], **extension_args),
56+
Extension('Adafruit_BBIO.ADC', ['source/py_adc.c', 'source/c_adc.c', 'source/constants.c', 'source/common.c'], **extension_args),
57+
Extension('Adafruit_BBIO.SPI', ['source/spimodule.c', 'source/constants.c', 'source/common.c'], **extension_args),
58+
Extension('Adafruit_BBIO.UART', ['source/py_uart.c', 'source/c_uart.c', 'source/constants.c', 'source/common.c'], **extension_args)] )
5359

source/common.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ SOFTWARE.
3333

3434
#include <stddef.h>
3535

36+
#include "adafruit/bbio/error.h"
37+
3638
#define MODE_UNKNOWN -1
3739
#define BOARD 10
3840
#define BCM 11
@@ -42,16 +44,6 @@ SOFTWARE.
4244
#define FILENAME_BUFFER_SIZE 128
4345
#define MAX_PATH 256
4446

45-
typedef enum {
46-
BBIO_OK, // No error
47-
BBIO_ACCESS, // Error accessing a file
48-
BBIO_SYSFS, // Some error with Sysfs files
49-
BBIO_CAPE, // some error with capes
50-
BBIO_INVARG, // Invalid argument
51-
BBIO_MEM,
52-
BBIO_GEN // General error
53-
} BBIO_err;
54-
5547
// Modeled after "pwm": submap in bone.js from bonescript
5648
// https://github.com/jadonk/bonescript/blob/master/src/bone.js#L680
5749
typedef struct pwm_t {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright (c) 2017 Adafruit
3+
Copyright (c) 2017 Nikolay Semenov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
*/
23+
#pragma once
24+
25+
#ifdef __cplusplus
26+
namespace adafruit {
27+
namespace bbio {
28+
#endif
29+
30+
typedef enum {
31+
BBIO_OK, // No error
32+
BBIO_ACCESS, // Error accessing a file
33+
BBIO_SYSFS, // Some error with Sysfs files
34+
BBIO_CAPE, // some error with capes
35+
BBIO_INVARG, // Invalid argument
36+
BBIO_MEM,
37+
BBIO_GEN // General error
38+
} BBIO_err;
39+
40+
#ifdef __cplusplus
41+
} // namespace bbio
42+
} // namespace adafruit
43+
#endif

0 commit comments

Comments
 (0)