Skip to content

Commit 9f9c874

Browse files
authored
Gpio merge for house keeping (#42)
* gpio periphery being added * gpio periphery being added * rebase gpio branch * created gpio folder and files and tests * Feature branch git action added, gpio command and constants are added * github action yml changed * testing GPIO * gpio bias keyword takenout * path typeError troubleshooting * gpio in progress #20 * disable push test until fixing the bug * Update gpio.py add all keyword args * Update gpio.py passing arguments without keyword * Update gpio.py * gpio test issue resolved #20 * working on constants
1 parent 454c8a5 commit 9f9c874

File tree

10 files changed

+333
-0
lines changed

10 files changed

+333
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will install Python dependencies, run tests using PyTest.
2+
3+
name: PyTest-gpio
4+
5+
on:
6+
push:
7+
branches:
8+
- 'dev'
9+
pull_request:
10+
branches:
11+
- 'dev'
12+
13+
jobs:
14+
build:
15+
16+
runs-on: self-hosted
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: ["3.9"]
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
- name: Install Dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
python -m venv venv_test
29+
source venv_test/bin/activate
30+
python -m pip install pytest
31+
if [ -f requirements_test.txt ]; then pip install -r requirements_test.txt; fi
32+
- name: Test with pytest
33+
run: |
34+
source venv_test/bin/activate
35+
pytest ./src/test_edgepi

src/edgepi/gpio/__init__.py

Whitespace-only changes.

src/edgepi/gpio/gpio_commands.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from edgepi.peripherals.gpio import GpioDevice
2+
from edgepi.peripherals.i2c import I2CDevice
3+
from edgepi.gpio.gpio_constants import *
4+
5+
class GPIOCommands(I2CDevice):
6+
_gpioSettings = {'DIN1': ['gpio',26, 'in', 'pull_down'],
7+
'DIN2': ['gpio',6, 'in', 'pull_down'],
8+
'DIN3': ['gpio',11, 'in', 'pull_down'],
9+
'DIN4': ['gpio',9, 'in', 'pull_down'],
10+
'DIN5': ['gpio',22, 'in', 'pull_down'],
11+
'DIN6': ['gpio',27, 'in', 'pull_down'],
12+
'DIN7': ['gpio',3, 'in', 'pull_down'],
13+
'DIN8': ['gpio',2, 'in', 'pull_down'],
14+
'DOUT1': ['gpio',13, 'out', 'pull_down'],
15+
'DOUT2': ['gpio',12, 'out', 'pull_down'],
16+
'LED_OVR1' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN1_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_1.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'], # TODO: double check the default conditions
17+
'LED_OVR2' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN2_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_2.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'],
18+
'LED_OVR3' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN3_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_3.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'],
19+
'LED_OVR4' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN4_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_4.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'],
20+
'LED_OVR5' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN5_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_5.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'],
21+
'LED_OVR6' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN6_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_6.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'],
22+
'LED_OVR7' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN7_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_7.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'],
23+
'LED_OVR8' : ['i2c', 'out', 'pull_down',GpioBPinDir.PIN8_DIR_OUT.value, GpioBOutputClear.CLEAR_OUTPUT_8.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTB'],
24+
'AO_EN1' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN8_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_8.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'], #TODO: double check the pin numbering
25+
'AO_EN2' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN5_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_5.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'],
26+
'AO_EN3' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN6_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_6.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'],
27+
'AO_EN4' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN7_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_7.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'],
28+
'AO_EN5' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN4_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_4.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'],
29+
'AO_EN6' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN3_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_3.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'],
30+
'AO_EN7' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN2_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_2.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'],
31+
'AO_EN8' : ['i2c', 'out', 'pull_down',GpioAPinDir.PIN1_DIR_OUT.value, GpioAOutputClear.CLEAR_OUTPUT_1.value, GpioExpanderAdreess.EXP_ONE.value, 'PORTA'],
32+
'DOUT3' : ['i2c', 'out', 'pull_down', 33, 'PORTA'], #TODO: double check the pin numbering
33+
'DOUT4' : ['i2c', 'out', 'pull_down', 33, 'PORTA'],
34+
'DOUT5' : ['i2c', 'out', 'pull_down', 33, 'PORTA'],
35+
'DOUT6' : ['i2c', 'out', 'pull_down', 33, 'PORTA'],
36+
'DOUT7' : ['i2c', 'out', 'pull_down', 33, 'PORTA'],
37+
'DOUT8' : ['i2c', 'out', 'pull_down', 33, 'PORTA'],
38+
'RTD_EN' : ['i2c', 'out', 'pull_down', 33, 'PORTB'],
39+
'GND_SW1' : ['i2c', 'out', 'pull_down', 33, 'PORTB'],
40+
'GND_SW2' : ['i2c', 'out', 'pull_down', 33, 'PORTB']
41+
}
42+
def __init__(self, pinList: list = None):
43+
self.gpioPinDict = {}
44+
self.i2cPinList = {}
45+
for pin in pinList:
46+
if GPIOCommands._gpioSettings[pin][0] == 'gpio':
47+
self.gpioPinList[pin] = GpioDevice(pin_num=GPIOCommands._gpioSettings[pin][1],
48+
pin_dir=GPIOCommands._gpioSettings[pin][2],
49+
pin_bias=GPIOCommands._gpioSettings[pin][3])
50+
else:
51+
self.i2cPinList[pin] = GPIOCommands._gpioSettings[pin]
52+
self.i2cDev = super().__init__(fd='/dev/i2c-10') if self.i2cPinList else None
53+
self.setDefaults()
54+
55+
def _read_regs_map(self):
56+
reg_map = {}
57+
if 'PORTA' in self.i2cPinList
58+
59+
def setDefaults(self):

src/edgepi/gpio/gpio_constants.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
from enum import Enum, unique
2+
from edgepi.reg_helper.reg_helper import OpCode
3+
4+
@unique
5+
class GpioExpanderAdreess(Enum):
6+
EXP_ONE = 32
7+
EXP_TWO = 33
8+
9+
@unique
10+
class GPIOAddresses(Enum):
11+
# Read addresses
12+
INPUT_PORT_0 = 0x00
13+
INPUT_PORT_1 = 0x01
14+
OUTPUT_PORT_0 = 0x02
15+
OUTPUT_PORT_1 = 0x03
16+
POLARITY_INVERSION_PORT_0 = 0x04
17+
POLARITY_INVERSION_PORT_1 = 0x05
18+
CONFIGURATION_PORT_0 = 0x06
19+
CONFIGURATION_PORT_1 = 0x07
20+
21+
class BitMask(Enum):
22+
BIT0 = 0xFE
23+
BIT1 = 0xFD
24+
BIT2 = 0xFB
25+
BIT3 = 0xF7
26+
BIT4 = 0xEF
27+
BIT5 = 0xDF
28+
BIT6 = 0xBF
29+
BIT7 = 0x7F
30+
BYTE = 0x00
31+
32+
33+
34+
@unique
35+
class GpioAOutputSet(Enum):
36+
SET_OUTPUT_1 = OpCode(0x01, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT0.value)
37+
SET_OUTPUT_2 = OpCode(0x02, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT1.value)
38+
SET_OUTPUT_3 = OpCode(0x04, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT2.value)
39+
SET_OUTPUT_4 = OpCode(0x08, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT3.value)
40+
SET_OUTPUT_5 = OpCode(0x10, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT4.value)
41+
SET_OUTPUT_6 = OpCode(0x20, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT5.value)
42+
SET_OUTPUT_7 = OpCode(0x40, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT6.value)
43+
SET_OUTPUT_8 = OpCode(0x80, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT7.value)
44+
SET_OUTPUT_ALL = OpCode(0xFF, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value)
45+
46+
47+
@unique
48+
class GpioAOutputClear(Enum):
49+
CLEAR_OUTPUT_1 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT0.value)
50+
CLEAR_OUTPUT_2 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT1.value)
51+
CLEAR_OUTPUT_3 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT2.value)
52+
CLEAR_OUTPUT_4 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT3.value)
53+
CLEAR_OUTPUT_5 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT4.value)
54+
CLEAR_OUTPUT_6 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT5.value)
55+
CLEAR_OUTPUT_7 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT6.value)
56+
CLEAR_OUTPUT_8 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BIT7.value)
57+
CLEAR_OUTPUT_ALL = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value)
58+
59+
60+
@unique
61+
class GpioBOutputSet(Enum):
62+
SET_OUTPUT_1 = OpCode(0x01, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT0.value)
63+
SET_OUTPUT_2 = OpCode(0x02, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT1.value)
64+
SET_OUTPUT_3 = OpCode(0x04, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT2.value)
65+
SET_OUTPUT_4 = OpCode(0x08, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT3.value)
66+
SET_OUTPUT_5 = OpCode(0x10, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT4.value)
67+
SET_OUTPUT_6 = OpCode(0x20, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT5.value)
68+
SET_OUTPUT_7 = OpCode(0x40, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT6.value)
69+
SET_OUTPUT_8 = OpCode(0x80, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT7.value)
70+
SET_OUTPUT_ALL = OpCode(0xFF, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value)
71+
72+
@unique
73+
class GpioBOutputClear(Enum):
74+
CLEAR_OUTPUT_1 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT0.value)
75+
CLEAR_OUTPUT_2 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT1.value)
76+
CLEAR_OUTPUT_3 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT2.value)
77+
CLEAR_OUTPUT_4 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT3.value)
78+
CLEAR_OUTPUT_5 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT4.value)
79+
CLEAR_OUTPUT_6 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT5.value)
80+
CLEAR_OUTPUT_7 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT6.value)
81+
CLEAR_OUTPUT_8 = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_1.value, BitMask.BIT7.value)
82+
CLEAR_OUTPUT_ALL = OpCode(0x00, GPIOAddresses.OUTPUT_PORT_0.value, BitMask.BYTE.value)
83+
84+
@unique
85+
class GpioAPinDir(Enum):
86+
PIN1_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT0.value)
87+
PIN2_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT1.value)
88+
PIN3_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT2.value)
89+
PIN4_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT3.value)
90+
PIN5_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT4.value)
91+
PIN6_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT5.value)
92+
PIN7_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT6.value)
93+
PIN8_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT7.value)
94+
ALL_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value)
95+
96+
PIN1_DIR_IN = OpCode(0x01, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT0.value)
97+
PIN2_DIR_IN = OpCode(0x02, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT1.value)
98+
PIN3_DIR_IN = OpCode(0x04, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT2.value)
99+
PIN4_DIR_IN = OpCode(0x08, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT3.value)
100+
PIN5_DIR_IN = OpCode(0x10, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT4.value)
101+
PIN6_DIR_IN = OpCode(0x20, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT5.value)
102+
PIN7_DIR_IN = OpCode(0x40, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT6.value)
103+
PIN8_DIR_IN = OpCode(0x80, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BIT7.value)
104+
ALL_DIR_IN = OpCode(0xFF, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value)
105+
106+
@unique
107+
class GpioBPinDir(Enum):
108+
PIN1_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT0.value)
109+
PIN2_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT1.value)
110+
PIN3_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT2.value)
111+
PIN4_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT3.value)
112+
PIN5_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT4.value)
113+
PIN6_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT5.value)
114+
PIN7_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT6.value)
115+
PIN8_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT7.value)
116+
ALL_DIR_OUT = OpCode(0x00, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value)
117+
118+
119+
PIN1_DIR_IN = OpCode(0x01, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT0.value)
120+
PIN2_DIR_IN = OpCode(0x02, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT1.value)
121+
PIN3_DIR_IN = OpCode(0x04, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT2.value)
122+
PIN4_DIR_IN = OpCode(0x08, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT3.value)
123+
PIN5_DIR_IN = OpCode(0x10, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT4.value)
124+
PIN6_DIR_IN = OpCode(0x20, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT5.value)
125+
PIN7_DIR_IN = OpCode(0x40, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT6.value)
126+
PIN8_DIR_IN = OpCode(0x80, GPIOAddresses.CONFIGURATION_PORT_1.value, BitMask.BIT7.value)
127+
ALL_DIR_IN = OpCode(0xFF, GPIOAddresses.CONFIGURATION_PORT_0.value, BitMask.BYTE.value)

src/edgepi/peripherals/gpio.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from periphery import GPIO
2+
3+
class GpioDevice():
4+
_dev_path = "/dev/gpiochip0"
5+
6+
def __init__(self, pin_num: int = None, pin_dir: str = None, pin_bias: str = None):
7+
self.fd = GpioDevice._dev_path
8+
self.pin_num = pin_num
9+
self.pin_dir = pin_dir
10+
self.pin_bias = pin_bias
11+
self.gpio = GPIO(self.fd, self.pin_num, self.pin_dir, bias=self.pin_bias)
12+
13+
def close(self):
14+
self.gpio.close()

src/edgepi/peripherals/i2c.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from periphery import I2C
2+
3+
class I2CDevice():
4+
5+
def __init__(self, fd: str = None):
6+
self.fd = fd
7+
self.i2cdev = I2C(fd)
8+
9+
def close(self):
10+
self.i2cdev.close()

src/test_edgepi/test_gpio/__init__.py

Whitespace-only changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import pytest
2+
from edgepi.reg_helper.reg_helper import _apply_opcode
3+
from edgepi.gpio.gpio_constants import *
4+
5+
@pytest.mark.parametrize('reg_value, opcode, updated_reg_value', [
6+
(0b00000000, GpioAOutputSet.SET_OUTPUT_1.value, 0b00000001), # Set Bit1
7+
(0b00000001, GpioAOutputSet.SET_OUTPUT_2.value, 0b00000011), # Set Bit2
8+
(0b00000011, GpioAOutputSet.SET_OUTPUT_3.value, 0b00000111), # Set Bit3
9+
(0b00000111, GpioAOutputSet.SET_OUTPUT_4.value, 0b00001111), # Set Bit4
10+
(0b00001111, GpioAOutputSet.SET_OUTPUT_5.value, 0b00011111), # Set Bit5
11+
(0b00011111, GpioAOutputSet.SET_OUTPUT_6.value, 0b00111111), # Set Bit6
12+
(0b00111111, GpioAOutputSet.SET_OUTPUT_7.value, 0b01111111), # Set Bit7
13+
(0b01111111, GpioAOutputSet.SET_OUTPUT_8.value, 0b11111111), # Set Bit8
14+
(0b00000000, GpioAOutputSet.SET_OUTPUT_ALL.value, 0b11111111) # Set ALL
15+
])
16+
def test_output_set(reg_value, opcode, updated_reg_value):
17+
assert _apply_opcode(reg_value, opcode) == updated_reg_value
18+
19+
20+
@pytest.mark.parametrize('reg_value, opcode, updated_reg_value', [
21+
(0b11111111, GpioAOutputClear.CLEAR_OUTPUT_8.value, 0b01111111), # Claer Bit8
22+
(0b01111111, GpioAOutputClear.CLEAR_OUTPUT_7.value, 0b00111111), # Claer Bit7
23+
(0b00111111, GpioAOutputClear.CLEAR_OUTPUT_6.value, 0b00011111), # Claer Bit6
24+
(0b00011111, GpioAOutputClear.CLEAR_OUTPUT_5.value, 0b00001111), # Claer Bit5
25+
(0b00001111, GpioAOutputClear.CLEAR_OUTPUT_4.value, 0b00000111), # Claer Bit4
26+
(0b00000111, GpioAOutputClear.CLEAR_OUTPUT_3.value, 0b00000011), # Claer Bit3
27+
(0b00000011, GpioAOutputClear.CLEAR_OUTPUT_2.value, 0b00000001), # Claer Bit2
28+
(0b00000001, GpioAOutputClear.CLEAR_OUTPUT_1.value, 0b00000000), # Claer Bit1
29+
(0b11111111, GpioAOutputClear.CLEAR_OUTPUT_ALL.value, 0b00000000) # Claer ALL
30+
])
31+
def test_output_clear(reg_value, opcode, updated_reg_value):
32+
assert _apply_opcode(reg_value, opcode) == updated_reg_value
33+
34+
@pytest.mark.parametrize('reg_value, opcode, updated_reg_value', [
35+
(0b11111111, GpioAPinDir.PIN8_DIR_OUT.value, 0b01111111), # Output Dir Bit8
36+
(0b01111111, GpioAPinDir.PIN7_DIR_OUT.value, 0b00111111), # Output Dir Bit7
37+
(0b00111111, GpioAPinDir.PIN6_DIR_OUT.value, 0b00011111), # Output Dir Bit6
38+
(0b00011111, GpioAPinDir.PIN5_DIR_OUT.value, 0b00001111), # Output Dir Bit5
39+
(0b00001111, GpioAPinDir.PIN4_DIR_OUT.value, 0b00000111), # Output Dir Bit4
40+
(0b00000111, GpioAPinDir.PIN3_DIR_OUT.value, 0b00000011), # Output Dir Bit3
41+
(0b00000011, GpioAPinDir.PIN2_DIR_OUT.value, 0b00000001), # Output Dir Bit2
42+
(0b00000001, GpioAPinDir.PIN1_DIR_OUT.value, 0b00000000), # Output Dir Bit1
43+
(0b11111111, GpioAPinDir.ALL_DIR_OUT.value, 0b00000000) # Output Dir ALL
44+
])
45+
def test_pin_dir_out(reg_value, opcode, updated_reg_value):
46+
assert _apply_opcode(reg_value, opcode) == updated_reg_value
47+
48+
@pytest.mark.parametrize('reg_value, opcode, updated_reg_value', [
49+
(0b00000000, GpioAPinDir.PIN1_DIR_IN.value, 0b00000001), # Input Dir Bit8
50+
(0b00000001, GpioAPinDir.PIN2_DIR_IN.value, 0b00000011), # Input Dir Bit7
51+
(0b00000011, GpioAPinDir.PIN3_DIR_IN.value, 0b00000111), # Input Dir Bit6
52+
(0b00000111, GpioAPinDir.PIN4_DIR_IN.value, 0b00001111), # Input Dir Bit5
53+
(0b00001111, GpioAPinDir.PIN5_DIR_IN.value, 0b00011111), # Input Dir Bit4
54+
(0b00011111, GpioAPinDir.PIN6_DIR_IN.value, 0b00111111), # Input Dir Bit3
55+
(0b00111111, GpioAPinDir.PIN7_DIR_IN.value, 0b01111111), # Input Dir Bit2
56+
(0b01111111, GpioAPinDir.PIN8_DIR_IN.value, 0b11111111), # Input Dir Bit1
57+
(0b00000000, GpioAPinDir.ALL_DIR_IN.value, 0b11111111) # Input Dir ALL
58+
])
59+
def test_pin_dir_in(reg_value, opcode, updated_reg_value):
60+
assert _apply_opcode(reg_value, opcode) == updated_reg_value
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from edgepi.peripherals.gpio import GpioDevice
3+
4+
@pytest.mark.parametrize("fd, pin_num, pin_dir, pin_bias",
5+
[( "/dev/gpiochip0", 27, "in", "pull_down"),
6+
( "/dev/gpiochip0", 6, "in", "pull_down"),
7+
( "/dev/gpiochip0", 6, "in", "pull_down"),
8+
( "/dev/gpiochip0", 13, "out", "pull_down")
9+
])
10+
def test_gpio_init_param(fd, pin_num, pin_dir, pin_bias):
11+
gpio = GpioDevice(pin_num, pin_dir, pin_bias)
12+
assert gpio.fd == fd
13+
assert gpio.pin_num == pin_num
14+
assert gpio.pin_dir == pin_dir
15+
assert gpio.pin_bias == pin_bias
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
from edgepi.peripherals.i2c import I2CDevice
3+
4+
@pytest.mark.parametrize("fd",
5+
[( '/dev/i2c-10'),
6+
( '/dev/i2c-11'),
7+
( '/dev/i2c-12'),
8+
( '/dev/i2c-13')
9+
])
10+
def test_i2c_init_param(fd):
11+
i2cDevice = I2CDevice(fd)
12+
assert i2cDevice.fd == fd
13+
assert i2cDevice.i2cdev.devpath == fd

0 commit comments

Comments
 (0)