From 32c00cc609c2d18414ed7385eaefc709332e0172 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 29 Jun 2021 12:27:24 -0500 Subject: [PATCH] drv/ioport_ev3dev_stretch: remove driver The ioport_ev3dev_stretch driver is not being used, so we can remove it. --- bricks/ev3dev/Makefile | 1 - lib/pbio/drv/ioport/ioport_ev3dev_stretch.c | 214 ------------------ lib/pbio/drv/ioport/ioport_ev3dev_stretch.h | 14 -- .../platform/ev3dev_stretch/pbdrvconfig.h | 3 - lib/pbio/src/main.c | 3 - lib/pbio/src/processes.h | 4 - 6 files changed, 239 deletions(-) delete mode 100644 lib/pbio/drv/ioport/ioport_ev3dev_stretch.c delete mode 100644 lib/pbio/drv/ioport/ioport_ev3dev_stretch.h diff --git a/bricks/ev3dev/Makefile b/bricks/ev3dev/Makefile index e2abe84df..030358fe9 100644 --- a/bricks/ev3dev/Makefile +++ b/bricks/ev3dev/Makefile @@ -315,7 +315,6 @@ PYBRICKS_LIB_SRC_C = $(addprefix lib/,\ pbio/drv/counter/counter_core.c \ pbio/drv/counter/counter_ev3dev_stretch_iio.c \ pbio/drv/ev3dev_stretch/motor.c \ - pbio/drv/ioport/ioport_ev3dev_stretch.c \ pbio/platform/motors/settings.c \ pbio/platform/ev3dev_stretch/status_light.c \ pbio/src/color/conversion.c \ diff --git a/lib/pbio/drv/ioport/ioport_ev3dev_stretch.c b/lib/pbio/drv/ioport/ioport_ev3dev_stretch.c deleted file mode 100644 index 04c336419..000000000 --- a/lib/pbio/drv/ioport/ioport_ev3dev_stretch.c +++ /dev/null @@ -1,214 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2019-2020 The Pybricks Authors - -// ev3dev-stretch I/O port - -#include - -#if PBDRV_CONFIG_IOPORT_EV3DEV_STRETCH - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -typedef struct { - const char *name; - struct udev_device *device; - UT_hash_handle hh; -} ev3dev_port_t; - -static ev3dev_port_t *ev3dev_ports; - -PROCESS(pbdrv_ioport_ev3dev_stretch_process, "ev3dev-stretch I/O port"); - -static void add_port(struct udev_device *device) { - ev3dev_port_t *new_port; - - new_port = malloc(sizeof(*new_port)); - new_port->name = udev_device_get_property_value(device, "LEGO_ADDRESS"); - new_port->device = udev_device_ref(device); - HASH_ADD_STR(ev3dev_ports, name, new_port); -} - -static ev3dev_port_t *find_port(const char *name) { - ev3dev_port_t *found_port; - - HASH_FIND_STR(ev3dev_ports, name, found_port); - return found_port; -} - -static void remove_port(struct udev_device *device) { - ev3dev_port_t *remove_port; - const char *name; - - name = udev_device_get_property_value(device, "LEGO_ADDRESS"); - if (!name) { - return; - } - - remove_port = find_port(name); - if (!remove_port) { - return; - } - - HASH_DEL(ev3dev_ports, remove_port); - udev_device_unref(remove_port->device); - free(remove_port); -} - -pbio_error_t pbdrv_ioport_ev3dev_get_syspath(pbio_port_t port, const char **syspath) { - const char *name; - ev3dev_port_t *p; - - switch (port) { - case PBIO_PORT_1: - name = "ev3-ports:in1"; - break; - case PBIO_PORT_2: - name = "ev3-ports:in2"; - break; - case PBIO_PORT_3: - name = "ev3-ports:in3"; - break; - case PBIO_PORT_4: - name = "ev3-ports:in4"; - break; - case PBIO_PORT_A: - name = "ev3-ports:outA"; - break; - case PBIO_PORT_B: - name = "ev3-ports:outB"; - break; - case PBIO_PORT_C: - name = "ev3-ports:outC"; - break; - case PBIO_PORT_D: - name = "ev3-ports:outD"; - break; - default: - return PBIO_ERROR_INVALID_PORT; - } - - p = find_port(name); - if (!p) { - return PBIO_ERROR_NO_DEV; - } - - *syspath = udev_device_get_syspath(p->device); - - return PBIO_SUCCESS; -} - -PROCESS_THREAD(pbdrv_ioport_ev3dev_stretch_process, ev, data) { - static struct udev *udev; - static struct udev_monitor *monitor; - static struct etimer timer; - struct udev_enumerate *enumerate; - struct udev_list_entry *list, *entry; - int ret; - - PROCESS_BEGIN(); - - udev = udev_new(); - if (!udev) { - perror("Failed to get udev"); - PROCESS_EXIT(); - } - - monitor = udev_monitor_new_from_netlink(udev, "udev"); - if (!monitor) { - perror("Failed to get udev monitor"); - udev = udev_unref(udev); - PROCESS_EXIT(); - } - - enumerate = udev_enumerate_new(udev); - if (!enumerate) { - perror("Failed to get udev enumerate"); - monitor = udev_monitor_unref(monitor); - udev = udev_unref(udev); - PROCESS_EXIT(); - } - - ret = udev_enumerate_add_match_subsystem(enumerate, "lego-port"); - if (ret < 0) { - errno = -ret; - perror("udev_enumerate_add_match_subsystem failed"); - enumerate = udev_enumerate_unref(enumerate); - monitor = udev_monitor_unref(monitor); - udev = udev_unref(udev); - PROCESS_EXIT(); - } - - udev_monitor_filter_add_match_subsystem_devtype(monitor, "lego-port", NULL); - udev_monitor_enable_receiving(monitor); - - ret = udev_enumerate_scan_devices(enumerate); - if (ret < 0) { - errno = -ret; - perror("udev_enumerate_scan_devices failed"); - enumerate = udev_enumerate_unref(enumerate); - monitor = udev_monitor_unref(monitor); - udev = udev_unref(udev); - PROCESS_EXIT(); - } - - list = udev_enumerate_get_list_entry(enumerate); - udev_list_entry_foreach(entry, list) { - const char *syspath; - struct udev_device *device; - - syspath = udev_list_entry_get_name(entry); - device = udev_device_new_from_syspath(udev, syspath); - if (!device) { - continue; - } - - add_port(device); - udev_device_unref(device); - } - - enumerate = udev_enumerate_unref(enumerate); - - // poll for added/removed devices every 100 milliseconds - etimer_set(&timer, clock_from_msec(100)); - - while (true) { - struct udev_device *device; - const char *action; - - PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)); - etimer_reset(&timer); - - device = udev_monitor_receive_device(monitor); - if (!device) { - continue; - } - - action = udev_device_get_action(device); - if (!action) { - continue; - } - - if (strcmp(action, "add") == 0) { - add_port(device); - } - if (strcmp(action, "remove") == 0) { - remove_port(device); - } - udev_device_unref(device); - } - - PROCESS_END(); -} - -#endif // PBDRV_CONFIG_IOPORT_EV3DEV_STRETCH diff --git a/lib/pbio/drv/ioport/ioport_ev3dev_stretch.h b/lib/pbio/drv/ioport/ioport_ev3dev_stretch.h deleted file mode 100644 index f37cda8bd..000000000 --- a/lib/pbio/drv/ioport/ioport_ev3dev_stretch.h +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2019-2020 The Pybricks Authors - -// ev3dev-stretch I/O port - -#ifndef _INTERNAL_PBDRV_IOPORT_EV3DEV_STRETCH_H_ -#define _INTERNAL_PBDRV_IOPORT_EV3DEV_STRETCH_H_ - -#include -#include - -pbio_error_t pbdrv_ioport_ev3dev_get_syspath(pbio_port_t port, const char **syspath); - -#endif // _INTERNAL_PBDRV_IOPORT_EV3DEV_STRETCH_H_ diff --git a/lib/pbio/platform/ev3dev_stretch/pbdrvconfig.h b/lib/pbio/platform/ev3dev_stretch/pbdrvconfig.h index a9970c9b0..eac6cf5db 100644 --- a/lib/pbio/platform/ev3dev_stretch/pbdrvconfig.h +++ b/lib/pbio/platform/ev3dev_stretch/pbdrvconfig.h @@ -22,9 +22,6 @@ #define PBDRV_CONFIG_COUNTER_COUNTS_PER_DEGREE (2) -#define PBDRV_CONFIG_IOPORT (1) -#define PBDRV_CONFIG_IOPORT_EV3DEV_STRETCH (1) - #define PBDRV_CONFIG_HAS_PORT_A (1) #define PBDRV_CONFIG_HAS_PORT_B (1) #define PBDRV_CONFIG_HAS_PORT_C (1) diff --git a/lib/pbio/src/main.c b/lib/pbio/src/main.c index 07f75baaf..19de8f9ad 100644 --- a/lib/pbio/src/main.c +++ b/lib/pbio/src/main.c @@ -30,9 +30,6 @@ AUTOSTART_PROCESSES( #if PBDRV_CONFIG_ADC &pbdrv_adc_process, #endif -#if PBDRV_CONFIG_IOPORT_EV3DEV_STRETCH - &pbdrv_ioport_ev3dev_stretch_process, -#endif #if PBDRV_CONFIG_IOPORT_LPF2 &pbdrv_ioport_lpf2_process, #endif diff --git a/lib/pbio/src/processes.h b/lib/pbio/src/processes.h index c9095122b..5d55e2723 100644 --- a/lib/pbio/src/processes.h +++ b/lib/pbio/src/processes.h @@ -16,10 +16,6 @@ PROCESS_NAME(pbdrv_adc_process); #endif -#if PBDRV_CONFIG_IOPORT_EV3DEV_STRETCH -PROCESS_NAME(pbdrv_ioport_ev3dev_stretch_process); -#endif - #if PBDRV_CONFIG_IOPORT_LPF2 PROCESS_NAME(pbdrv_ioport_lpf2_process); #endif