|
| 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 | +} |
0 commit comments