-
Notifications
You must be signed in to change notification settings - Fork 3
Edgepi gpio dac config #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7fa02bf
gpio-dac-config being implemented
sjpark608 1fd0536
testing I2C
sjpark608 b0c5bad
1. Added gpio config #48
sjpark608 740c13a
gpio module configurations packed as enum
sjpark608 c1f4d7d
filter_dict by value (#53)
flavius-t 2214dfa
add names to test and lint workflows (#56)
flavius-t 2ae307a
added mock for testing I2C
sjpark608 f9569f9
gpio-dac-config being implemented
sjpark608 170dbc6
testing I2C
sjpark608 3a6bb9e
1. Added gpio config #48
sjpark608 199a80e
gpio module configurations packed as enum
sjpark608 13fbf5d
added mock for testing I2C
sjpark608 87bf7d5
Merge branch 'edgepi-gpio-dac-config' of https://github.com/osensa/ed…
sjpark608 38b0776
combined repetitive dataclass
sjpark608 fce5392
fixing pytest failures
flavius-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,8 @@ on: | |
| - 'dev' | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| lint: | ||
| name: Linter | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ''' | ||
| Provides a class for interacting with the GPIO pins through I2C and GPIO peripheral | ||
| ''' | ||
|
|
||
| import logging | ||
| import time | ||
|
|
||
| from edgepi.peripherals.gpio import GpioDevice | ||
| from edgepi.peripherals.i2c import I2CDevice | ||
| from edgepi.gpio.gpio_commands import * | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
| class EdgePiGPIO(I2CDevice): | ||
| ''' | ||
| A class used to represent the GPIO. This class will be imported to each module | ||
| that requires GPIO manipulation. It is not intended for user. | ||
| ''' | ||
|
|
||
| def __init__(self, config: str = None): | ||
| if config is None: | ||
| _logger.error(f'Config is not chosen, please choose a configuration') | ||
| self.config = getPeriphConfig(config) | ||
| _logger.debug(f'{self.config.name} Configuration Selected: {self.config}') | ||
| if self.config is not None and 'i2c' in self.config.dev_path: | ||
| super().__init__(self.config.dev_path) | ||
| _logger.info(f'GPIO expander up and running') | ||
| self.pinList = generate_pin_info(self.config.name) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,9 @@ | ||
| from edgepi.peripherals.gpio import GpioDevice | ||
| from edgepi.peripherals.i2c import I2CDevice | ||
| from edgepi.gpio.gpio_constants import * | ||
| from edgepi.gpio.gpio_configs import * | ||
|
|
||
| class GPIOCommands(I2CDevice): | ||
| def __init__(self, pinList: list = None): | ||
| self.gpioPinDict = {} | ||
| self.i2cPinList = {} | ||
| for pin in pinList: | ||
| if GPIOCommands._gpioSettings[pin][0] == 'gpio': | ||
| self.gpioPinList[pin] = GpioDevice(pin_num=GPIOCommands._gpioSettings[pin][1], | ||
| pin_dir=GPIOCommands._gpioSettings[pin][2], | ||
| pin_bias=GPIOCommands._gpioSettings[pin][3]) | ||
| else: | ||
| self.i2cPinList[pin] = GPIOCommands._gpioSettings[pin] | ||
| self.i2cDev = super().__init__(fd='/dev/i2c-10') if self.i2cPinList else None | ||
| self.setDefaults() | ||
|
|
||
| def _read_regs_map(self): | ||
| reg_map = {} | ||
| if 'PORTA' in self.i2cPinList | ||
|
|
||
| def setDefaults(self): | ||
| def getPeriphConfig(config: str = None): | ||
| ''' Used to get proper config dataclass to configure neccessary peripheral configuration ''' | ||
| for perpheryConfig in GpioConfigs: | ||
| if config == perpheryConfig.value.name: | ||
| return perpheryConfig.value | ||
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import pytest | ||
| from unittest import mock | ||
| from unittest.mock import patch | ||
| import sys | ||
| if sys.platform != 'linux': | ||
| sys.modules['periphery'] = mock.MagicMock() | ||
| from edgepi.gpio.gpio_configs import * | ||
| from edgepi.gpio.edgepi_gpio import EdgePiGPIO | ||
|
|
||
| @pytest.fixture(name='gpio') | ||
| def fixture_test_edgepi_tc(mocker): | ||
| mocker.patch('edgepi.peripherals.i2c.I2C') | ||
| mocker.patch('edgepi.peripherals.gpio.GPIO') | ||
|
|
||
| @pytest.mark.parametrize("mock_expect,config, result", | ||
| [(['/dev/i2c-10'],'dac',[GpioConfigs.DAC.value]), | ||
| (['/dev/i2c-10'],'adc',[GpioConfigs.ADC.value]), | ||
| (['/dev/i2c-10'],'rtd',[GpioConfigs.RTD.value]), | ||
| (['/dev/i2c-10'],'led',[GpioConfigs.LED.value]), | ||
| ]) | ||
| @patch('edgepi.peripherals.i2c.I2CDevice') | ||
| def test_edgepi_gpio_init(i2c_mock, mock_expect, config, result): | ||
| i2c_mock.fd = mock_expect[0] | ||
| gpioCtrl = EdgePiGPIO(config) | ||
| assert gpioCtrl.config == result[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import pytest | ||
| from edgepi.gpio.gpio_commands import * | ||
| from edgepi.gpio.gpio_configs import * | ||
|
|
||
| @pytest.mark.parametrize('config, result', | ||
| [('dac', GpioConfigs.DAC.value), | ||
| ('adc', GpioConfigs.ADC.value), | ||
| ('rtd', GpioConfigs.RTD.value), | ||
| ('din', None), | ||
| ('dout', None), | ||
| ('led', GpioConfigs.LED.value), | ||
| ( None, None)]) | ||
| def test_getPeriphConfig(config, result): | ||
| assert getPeriphConfig(config) == result |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.