-
Notifications
You must be signed in to change notification settings - Fork 2k
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
periph/dac: support for DAC extension API #10512
Draft
gschorcht
wants to merge
10
commits into
RIOT-OS:master
Choose a base branch
from
gschorcht:dac_ext_api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
87f391f
periph/dac: initial DAC extension API
gschorcht 8ea1bcf
cpu/*: support for DAC extension API
gschorcht 5907f85
drivers/extend: support for DAC extension API
gschorcht a7c15d6
drivers: Makefile support for DAC extension API
gschorcht 9f901f0
makefiles: support for DAC extension API
gschorcht de3d2b3
test: DAC extension API test application
gschorcht c8bbb27
fixup! periph/dac: initial DAC extension API
gschorcht 6481ad9
fixup! cpu/*: support for DAC extension API
gschorcht a4b6fff
fixup! test: DAC extension API test application
gschorcht 21c6308
fixup! periph/dac: initial DAC extension API
gschorcht 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 contains 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,11 @@ | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += extend_dac | ||
|
||
TEST_ON_CI_WHITELIST += all | ||
|
||
include ./Makefile.include | ||
include $(RIOTBASE)/Makefile.include | ||
|
||
test: | ||
./tests/01-run.py |
This file contains 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,2 @@ | ||
# include test specific includes | ||
export INCLUDES += -I$(CURDIR)/include |
This file contains 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,64 @@ | ||
/* | ||
* Copyright (C) 2018 Gunar Schorcht | ||
* Copyright (C) 2018 Acutam Automation, LLC | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* | ||
* @{ | ||
* | ||
* @file | ||
* @brief DAC extension test list | ||
* | ||
* @author Gunar Schorcht <gunar@schorcht.net> | ||
* @author Matthew Blue <matthew.blue.neuro@gmail.com> | ||
* | ||
* @} | ||
*/ | ||
|
||
#ifndef DAC_EXT_CONF_H | ||
#define DAC_EXT_CONF_H | ||
|
||
#include <stddef.h> | ||
|
||
#include "extend/dac.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Reference the driver structs | ||
* | ||
* @{ | ||
*/ | ||
extern dac_ext_driver_t tests_extend_dac_driver; | ||
extern dac_ext_driver_t dac_ext_notsup_driver; | ||
/** @} */ | ||
|
||
/** | ||
* @brief DAC extension test list | ||
*/ | ||
static const dac_ext_t dac_ext_list[] = | ||
{ | ||
{ | ||
.driver = &tests_extend_dac_driver, | ||
.dev = (void *)0xbeef, | ||
}, | ||
{ | ||
.driver = &dac_ext_notsup_driver, | ||
.dev = NULL, | ||
}, | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* DAC_EXT_CONF_H */ | ||
/** @} */ |
This file contains 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,141 @@ | ||
/* | ||
* Copyright (C) 2018 Gunar Schorcht | ||
* Copyright (C) 2018 Acutam Automation, LLC | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief DAC extension test routine | ||
* | ||
* @author Gunar Schorcht <gunar@schorcht.net> | ||
* @author Matthew Blue <matthew.blue.neuro@gmail.com> | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include "extend/dac.h" | ||
#include "periph/dac.h" | ||
|
||
/* DAC extension test functions */ | ||
int8_t test_dac_init(void *dev, dac_t chn); | ||
void test_dac_set(void *dev, dac_t chn, uint16_t val); | ||
void test_dac_poweron(void *dev, dac_t chn); | ||
void test_dac_poweroff(void *dev, dac_t chn); | ||
unsigned int test_dac_channels(void *dev); | ||
|
||
/* DAC extension test driver */ | ||
const dac_ext_driver_t tests_extend_dac_driver = { | ||
.init = test_dac_init, | ||
.set = test_dac_set, | ||
.poweron = test_dac_poweron, | ||
.poweroff = test_dac_poweroff, | ||
.channels = test_dac_channels, | ||
}; | ||
|
||
int8_t test_dac_init(void *dev, dac_t chn) | ||
{ | ||
printf("\t%s dev 0x%04x, chn %u\n", __func__, (uint16_t)(uintptr_t)dev, chn); | ||
return 0; | ||
} | ||
|
||
void test_dac_set(void *dev, dac_t chn, uint16_t val) | ||
{ | ||
printf("\t%s dev 0x%04x, chn %u, val %u\n", __func__, (uint16_t)(uintptr_t)dev, chn, val); | ||
} | ||
|
||
void test_dac_poweron(void *dev, dac_t chn) | ||
{ | ||
printf("\t%s dev 0x%04x, chn %u\n", __func__, (uint16_t)(uintptr_t)dev, chn); | ||
} | ||
|
||
void test_dac_poweroff(void *dev, dac_t chn) | ||
{ | ||
printf("\t%s dev 0x%04x, chn %u\n", __func__, (uint16_t)(uintptr_t)dev, chn); | ||
} | ||
|
||
unsigned int test_dac_channels(void *dev) | ||
{ | ||
printf("\t%s dev 0x%04x\n", __func__, (uint16_t)(uintptr_t)dev); | ||
return 4; | ||
} | ||
|
||
int main(void) | ||
{ | ||
puts("DAC extension test routine"); | ||
puts("\nRunning DAC functions for internal device"); | ||
|
||
uint16_t value = 1024; | ||
|
||
unsigned int num = dac_channels(DAC_LINE(0)); | ||
printf("- Number of DAC channels: %u\n", num); | ||
|
||
for (unsigned int chn = 0; chn < num; chn++) { | ||
printf("- Init DAC channel %u\n", chn); | ||
if (dac_init(DAC_LINE(chn))) { | ||
puts("[FAILED]"); | ||
return 1; | ||
} | ||
printf("- Set DAC channel %u: %u\n", chn, chn * value); | ||
dac_set(DAC_LINE(chn), chn * value); | ||
printf("- Poweroff DAC channel %u\n", chn); | ||
dac_poweroff(DAC_LINE(chn)); | ||
printf("- Poweron DAC channel %u\n", chn); | ||
dac_poweron(DAC_LINE(chn)); | ||
} | ||
|
||
puts("\nRunning DAC functions for extension test device"); | ||
|
||
num = dac_channels(DAC_EXT_LINE(0, 0)); | ||
printf("- Number of DAC channels: %u\n", num); | ||
|
||
for (unsigned int chn = 0; chn < num; chn++) { | ||
printf("- Init DAC channel %u\n", chn); | ||
if (dac_init(DAC_EXT_LINE(0, chn))) { | ||
puts("[FAILED]"); | ||
return 1; | ||
} | ||
printf("- Set DAC channel %u: %u\n", chn, chn * value); | ||
dac_set(DAC_EXT_LINE(0, chn), chn * value); | ||
printf("- Poweroff DAC channel %u\n", chn); | ||
dac_poweroff(DAC_EXT_LINE(0, chn)); | ||
printf("- Poweron DAC channel %u\n", chn); | ||
dac_poweron(DAC_EXT_LINE(0, chn)); | ||
} | ||
|
||
puts("\nRunning DAC functions for extension notsup device"); | ||
puts("(they should not print output)"); | ||
|
||
for (unsigned int chn = 0; chn < num; chn++) { | ||
printf("- notsup dac.h functions on channel %u\n", chn); | ||
if (!dac_init(DAC_EXT_LINE(1, chn))) { | ||
puts("[FAILED]"); | ||
return 1; | ||
} | ||
dac_set(DAC_EXT_LINE(1, chn), chn * value); | ||
dac_poweroff(DAC_EXT_LINE(1, chn)); | ||
dac_poweron(DAC_EXT_LINE(1, chn)); | ||
} | ||
|
||
puts("\nChecking that all channels in range have init error using notsup"); | ||
puts("(lack of init error implies improper redirection)"); | ||
|
||
for (unsigned int chn = 0; chn <= DAC_EXT_LINE_MASK; chn +=16) { | ||
if (dac_init(DAC_EXT_LINE(1, chn)) >= 0) { | ||
printf("init succeeded on channel %u\n", chn); | ||
puts("[FAILED]"); | ||
return 1; | ||
} | ||
} | ||
|
||
puts("[SUCCESS]"); | ||
|
||
return 0; | ||
} |
This file contains 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,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2018 Acutam Automation, LLC | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
import os | ||
import sys | ||
|
||
|
||
def testfunc(child): | ||
child.expect_exact("DAC extension test routine") | ||
child.expect_exact('Running DAC functions for internal device') | ||
child.expect('- Number of DAC channels: ') | ||
i = child.readline() | ||
for _ in range(int(i)): | ||
child.expect('- Init DAC channel \d+') | ||
child.expect('- Set DAC channel \d+: \d+') | ||
child.expect('- Poweroff DAC channel \d+') | ||
child.expect('- Poweron DAC channel \d+') | ||
child.expect_exact('Running DAC functions for extension test device') | ||
child.expect('test_dac_channels dev 0xbeef') | ||
child.expect('- Number of DAC channels: ') | ||
i = child.readline() | ||
for _ in range(int(4)): | ||
child.expect('- Init DAC channel \d+') | ||
child.expect('test_dac_init dev 0xbeef, chn \d+') | ||
child.expect('- Set DAC channel \d+: \d+') | ||
child.expect('test_dac_set dev 0xbeef, chn \d+, val \d+') | ||
child.expect('- Poweroff DAC channel \d+') | ||
child.expect('test_dac_poweroff dev 0xbeef, chn \d+') | ||
child.expect('- Poweron DAC channel \d+') | ||
child.expect('test_dac_poweron dev 0xbeef, chn \d+') | ||
child.expect_exact("Running DAC functions for extension notsup device") | ||
child.expect_exact("(they should not print output)") | ||
for _ in range(int(i)): | ||
child.expect('- notsup dac.h functions on channel \d+') | ||
child.expect_exact("Checking that all channels in range have init error using notsup") | ||
child.expect_exact("(lack of init error implies improper redirection)") | ||
child.expect_exact("[SUCCESS]") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) | ||
from testrunner import run | ||
sys.exit(run(testfunc)) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicitly referencing the test is no longer necessary. If
./tests/01-run.py
exists, then it will be used.