Skip to content

Commit 42e088c

Browse files
committed
WIP: drivers/soft_onewire: add tests
1 parent c09eee1 commit 42e088c

File tree

5 files changed

+168
-0
lines changed

5 files changed

+168
-0
lines changed

tests/drivers/onewire/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include ../Makefile.drivers_common
2+
3+
USEMODULE += onewire
4+
USEMODULE += soft_onewire
5+
USEMODULE += soft_onewire_hwtimer
6+
USEMODULE += tiny_strerror
7+
#USEMODULE += ztimer_auto_adjust
8+
9+
include $(RIOTBASE)/Makefile.include
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dfgdfg

tests/drivers/onewire/board.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
/*#include "soft_onewire.h"*/
4+
/*#include "soft_onewire_params.h"*/
5+
6+
//TODO
7+
/*extern soft_onewire_t soft_onewire_devs[];*/
8+
/*extern soft_onewire_params_t soft_onewire_params[];*/
9+
10+
/*#define SOFT_ONEWIRE_PARAMS_PIN 0*/
11+
12+
/*#define ONEWIRE_PARAMS_DRIVER &soft_onewire_driver*/
13+
/*#define ONEWIRE_PARAMS_LLDEV &soft_onewire_devs[0]*/
14+
/*#define ONEWIRE_PARAMS_LLDEV_PARAMS &soft_onewire_params[0]*/

tests/drivers/onewire/main.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2025 Joshua DeWeese
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup tests
11+
* @{
12+
*
13+
* @file
14+
* @brief Test application for the 1-Wire (onewire) bus driver
15+
*
16+
* @author Joshua DeWeese <[email protected]>
17+
* @}
18+
*/
19+
20+
#include <stdio.h>
21+
22+
#include "onewire.h"
23+
#include "soft_onewire.h"
24+
#include "tiny_strerror.h"
25+
26+
static soft_onewire_params_t soft_onewire_params[] = {
27+
{
28+
#ifdef MODULE_ONEWIRE_MULTIDRIVER
29+
.super = { .driver = &soft_onewire_driver },
30+
#endif
31+
#if defined(BOARD_NATIVE)
32+
.pin = GPIO_UNDEF,
33+
#elif defined(BOARD_STM32F429I_DISC1)
34+
.pin = GPIO_PIN(PORT_C, 0),
35+
#endif
36+
.pin_imode = GPIO_IN,
37+
#ifdef MODULE_SOFT_ONEWIRE_HWTIMER
38+
.timer = TIMER_DEV(1),
39+
#endif
40+
},
41+
};
42+
43+
#define SOFT_ONEWIRE_NUMOF ARRAY_SIZE(soft_onewire_params)
44+
45+
soft_onewire_t soft_onewire_devs[SOFT_ONEWIRE_NUMOF];
46+
47+
static void _enumerate_bus(onewire_t *bus)
48+
{
49+
onewire_rom_t id;
50+
int res = ONEWIRE_SEARCH_FIRST;
51+
52+
onewire_aquire(bus);
53+
54+
do {
55+
res = onewire_search(bus, &id, res);
56+
if (res < 0) {
57+
printf("failure to enumerate device: %s\n", tiny_strerror(-res));
58+
break;
59+
}
60+
61+
printf("found device: ");
62+
onewire_rom_print(&id);
63+
puts("");
64+
65+
} while (res > 0);
66+
67+
onewire_release(bus);
68+
}
69+
70+
int main(void)
71+
{
72+
for (unsigned i = 0; i < SOFT_ONEWIRE_NUMOF; i++) {
73+
soft_onewire_init(&soft_onewire_devs[i], &soft_onewire_params[i]);
74+
_enumerate_bus(&soft_onewire_devs[i].super);
75+
}
76+
77+
return 0;
78+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2023 Prime Controls
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup drivers_onewire
11+
*
12+
* @{
13+
* @file
14+
* @brief Default configuration for 1-Wire driver
15+
*
16+
* @author Joshua DeWeese <[email protected]>
17+
*/
18+
19+
#ifndef ONEWIRE_PARAMS_H
20+
#define ONEWIRE_PARAMS_H
21+
22+
#include "board.h"
23+
24+
#include "container.h"
25+
#include "onewire.h"
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
#ifndef ONEWIRE_PARAMS_DRIVER
32+
#define ONEWIRE_PARAMS_DRIVER NULL
33+
#endif
34+
35+
#ifndef ONEWIRE_PARAMS_LLDEV
36+
#define ONEWIRE_PARAMS_LLDEV NULL
37+
#endif
38+
39+
#ifndef ONEWIRE_PARAMS_LLDEV_PARAMS
40+
#define ONEWIRE_PARAMS_LLDEV_PARAMS NULL
41+
#endif
42+
43+
#ifndef ONEWIRE_PARAMS
44+
#define ONEWIRE_PARAMS \
45+
{ \
46+
.driver = ONEWIRE_PARAMS_DRIVER, \
47+
.lldev = ONEWIRE_PARAMS_LLDEV, \
48+
.lldev_params = ONEWIRE_PARAMS_LLDEV_PARAMS, \
49+
}
50+
#endif
51+
52+
static const onewire_params_t onewire_params[] = {
53+
ONEWIRE_PARAMS
54+
};
55+
56+
#define ONEWIRE_NUMOF ARRAY_SIZE(onewire_params)
57+
58+
/** board's 1-Wire buses masters */
59+
extern onewire_t onewire_buses[ONEWIRE_NUMOF];
60+
61+
#ifdef __cplusplus
62+
}
63+
#endif
64+
65+
#endif /* ONEWIRE_PARAMS_H */
66+
/** @} */

0 commit comments

Comments
 (0)