diff --git a/bricks/stm32/stm32.mk b/bricks/stm32/stm32.mk index 8f7d93b87..f4f672ce1 100644 --- a/bricks/stm32/stm32.mk +++ b/bricks/stm32/stm32.mk @@ -452,6 +452,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\ sys/bluetooth.c \ sys/command.c \ sys/hmi.c \ + sys/io_ports.c \ sys/light_matrix.c \ sys/light.c \ sys/main.c \ diff --git a/lib/pbio/drv/ioport/ioport_lpf2.c b/lib/pbio/drv/ioport/ioport_lpf2.c index b2030b280..e77a668aa 100644 --- a/lib/pbio/drv/ioport/ioport_lpf2.c +++ b/lib/pbio/drv/ioport/ioport_lpf2.c @@ -139,6 +139,10 @@ void pbdrv_ioport_lpf2_init(void) { process_start(&pbdrv_ioport_lpf2_process, NULL); } +void pbdrv_ioport_lpf2_shutdown(void) { + process_exit(&pbdrv_ioport_lpf2_process); +} + static void ioport_enable_uart(ioport_dev_t *ioport) { const pbdrv_ioport_lpf2_port_platform_data_t *pdata = ioport->pdata; diff --git a/lib/pbio/drv/ioport/ioport_lpf2.h b/lib/pbio/drv/ioport/ioport_lpf2.h index a95f16d27..00a02b27c 100644 --- a/lib/pbio/drv/ioport/ioport_lpf2.h +++ b/lib/pbio/drv/ioport/ioport_lpf2.h @@ -43,8 +43,11 @@ typedef struct { extern const pbdrv_ioport_lpf2_platform_data_t pbdrv_ioport_lpf2_platform_data; void pbdrv_ioport_lpf2_init(void); +void pbdrv_ioport_lpf2_shutdown(void); + #else // PBDRV_CONFIG_IOPORT_LPF2 #define pbdrv_ioport_lpf2_init() +#define pbdrv_ioport_lpf2_shutdown() #endif // PBDRV_CONFIG_IOPORT_LPF2 #endif // _INTERNAL_PBDRV_IOPORT_LPF2_H_ diff --git a/lib/pbio/platform/city_hub/sys.c b/lib/pbio/platform/city_hub/sys.c index 36f23f143..fb9e631c9 100644 --- a/lib/pbio/platform/city_hub/sys.c +++ b/lib/pbio/platform/city_hub/sys.c @@ -11,6 +11,7 @@ #include #include "../sys/hmi.h" +#include "../sys/io_ports.h" #include "../sys/supervisor.h" #include "../sys/user_program.h" @@ -33,6 +34,7 @@ PROCESS_THREAD(pbsys_process, ev, data) { etimer_reset(&timer); pbsys_battery_poll(); pbsys_hmi_poll(); + pbsys_io_ports_poll(); pbsys_supervisor_poll(); pbsys_user_program_poll(); } diff --git a/lib/pbio/platform/move_hub/sys.c b/lib/pbio/platform/move_hub/sys.c index 36f23f143..fb9e631c9 100644 --- a/lib/pbio/platform/move_hub/sys.c +++ b/lib/pbio/platform/move_hub/sys.c @@ -11,6 +11,7 @@ #include #include "../sys/hmi.h" +#include "../sys/io_ports.h" #include "../sys/supervisor.h" #include "../sys/user_program.h" @@ -33,6 +34,7 @@ PROCESS_THREAD(pbsys_process, ev, data) { etimer_reset(&timer); pbsys_battery_poll(); pbsys_hmi_poll(); + pbsys_io_ports_poll(); pbsys_supervisor_poll(); pbsys_user_program_poll(); } diff --git a/lib/pbio/platform/prime_hub/sys.c b/lib/pbio/platform/prime_hub/sys.c index 36f23f143..fb9e631c9 100644 --- a/lib/pbio/platform/prime_hub/sys.c +++ b/lib/pbio/platform/prime_hub/sys.c @@ -11,6 +11,7 @@ #include #include "../sys/hmi.h" +#include "../sys/io_ports.h" #include "../sys/supervisor.h" #include "../sys/user_program.h" @@ -33,6 +34,7 @@ PROCESS_THREAD(pbsys_process, ev, data) { etimer_reset(&timer); pbsys_battery_poll(); pbsys_hmi_poll(); + pbsys_io_ports_poll(); pbsys_supervisor_poll(); pbsys_user_program_poll(); } diff --git a/lib/pbio/platform/technic_hub/sys.c b/lib/pbio/platform/technic_hub/sys.c index 8c0cba3e0..db7b926b5 100644 --- a/lib/pbio/platform/technic_hub/sys.c +++ b/lib/pbio/platform/technic_hub/sys.c @@ -11,6 +11,7 @@ #include #include "../sys/hmi.h" +#include "../sys/io_ports.h" #include "../sys/supervisor.h" #include "../sys/user_program.h" @@ -34,6 +35,7 @@ PROCESS_THREAD(pbsys_process, ev, data) { etimer_reset(&timer); pbsys_battery_poll(); pbsys_hmi_poll(); + pbsys_io_ports_poll(); pbsys_supervisor_poll(); pbsys_user_program_poll(); } diff --git a/lib/pbio/sys/io_ports.c b/lib/pbio/sys/io_ports.c new file mode 100644 index 000000000..b837713b8 --- /dev/null +++ b/lib/pbio/sys/io_ports.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2021 The Pybricks Authors + +// Manages I/O ports + +#include + +// TODO need to make this more generic - for now assuming LPF2 everywhere +#include "../../drv/ioport/ioport_lpf2.h" + +void pbsys_io_ports_poll(void) { + if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)) { + pbdrv_ioport_lpf2_shutdown(); + } +} diff --git a/lib/pbio/sys/io_ports.h b/lib/pbio/sys/io_ports.h new file mode 100644 index 000000000..9b2bcca25 --- /dev/null +++ b/lib/pbio/sys/io_ports.h @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2021 The Pybricks Authors + +#ifndef _PBSYS_SYS_IO_PORTS_H_ +#define _PBSYS_SYS_IO_PORTS_H_ + +void pbsys_io_ports_poll(void); + +#endif // _PBSYS_SYS_IO_PORTS_H_