Skip to content

Commit

Permalink
sys/io_ports: add new sys component to handle I/O ports
Browse files Browse the repository at this point in the history
For now, this just powers down the ports when the hub is shut down.

Issue: https://github.com/pybricks/pybricks-micropython/issues/36
  • Loading branch information
dlech committed Jun 29, 2021
1 parent 434d599 commit 1473c4b
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions bricks/stm32/stm32.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 4 additions & 0 deletions lib/pbio/drv/ioport/ioport_lpf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions lib/pbio/drv/ioport/ioport_lpf2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 2 additions & 0 deletions lib/pbio/platform/city_hub/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <pbsys/status.h>

#include "../sys/hmi.h"
#include "../sys/io_ports.h"
#include "../sys/supervisor.h"
#include "../sys/user_program.h"

Expand All @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/pbio/platform/move_hub/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <pbsys/status.h>

#include "../sys/hmi.h"
#include "../sys/io_ports.h"
#include "../sys/supervisor.h"
#include "../sys/user_program.h"

Expand All @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/pbio/platform/prime_hub/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <pbsys/status.h>

#include "../sys/hmi.h"
#include "../sys/io_ports.h"
#include "../sys/supervisor.h"
#include "../sys/user_program.h"

Expand All @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/pbio/platform/technic_hub/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <pbsys/status.h>

#include "../sys/hmi.h"
#include "../sys/io_ports.h"
#include "../sys/supervisor.h"
#include "../sys/user_program.h"

Expand All @@ -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();
}
Expand Down
15 changes: 15 additions & 0 deletions lib/pbio/sys/io_ports.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 The Pybricks Authors

// Manages I/O ports

#include <pbsys/status.h>

// 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();
}
}
9 changes: 9 additions & 0 deletions lib/pbio/sys/io_ports.h
Original file line number Diff line number Diff line change
@@ -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_

0 comments on commit 1473c4b

Please sign in to comment.