Skip to content

Commit 046af37

Browse files
committed
pbio/drv/core: Drop process autostart.
This was a longstanding chore that we have done gradually over time. The ADC driver was the last to be tranformed to the manual start format. To ensure that this isn't a potentially breaking change in itself, we move the call to initialize the ADC driver to the end of pbdrv_init, which is where the process was previously auto-started.
1 parent e04f9b1 commit 046af37

File tree

13 files changed

+39
-48
lines changed

13 files changed

+39
-48
lines changed

lib/pbio/drv/adc/adc.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2024 The Pybricks Authors
3+
4+
// Internal common adc functions.
5+
6+
#ifndef _INTERNAL_PBDRV_ADC_H_
7+
#define _INTERNAL_PBDRV_ADC_H_
8+
9+
#include <pbdrv/config.h>
10+
11+
#if PBDRV_CONFIG_ADC
12+
13+
void pbdrv_adc_init(void);
14+
15+
#else // PBDRV_CONFIG_ADC
16+
17+
#define pbdrv_adc_init()
18+
19+
#endif // PBDRV_CONFIG_ADC
20+
21+
#endif // _INTERNAL_PBDRV_ADC_H_

lib/pbio/drv/adc/adc_stm32_hal.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ static void pbdrv_adc_exit(void) {
8181
HAL_DMA_DeInit(&pbdrv_adc_hdma);
8282
}
8383

84-
PROCESS_THREAD(pbdrv_adc_process, ev, data) {
85-
PROCESS_POLLHANDLER(pbdrv_adc_poll());
86-
PROCESS_EXITHANDLER(pbdrv_adc_exit());
87-
88-
PROCESS_BEGIN();
84+
void pbdrv_adc_init(void) {
8985

9086
// Timer to trigger ADC
9187

@@ -149,6 +145,15 @@ PROCESS_THREAD(pbdrv_adc_process, ev, data) {
149145
HAL_ADC_Start_DMA(&pbdrv_adc_hadc, pbdrv_adc_dma_buffer, PBIO_ARRAY_SIZE(pbdrv_adc_dma_buffer));
150146
HAL_TIM_Base_Start(&pbdrv_adc_htim);
151147

148+
process_start(&pbdrv_adc_process);
149+
}
150+
151+
PROCESS_THREAD(pbdrv_adc_process, ev, data) {
152+
PROCESS_POLLHANDLER(pbdrv_adc_poll());
153+
PROCESS_EXITHANDLER(pbdrv_adc_exit());
154+
155+
PROCESS_BEGIN();
156+
152157
while (true) {
153158
PROCESS_WAIT_EVENT();
154159
}

lib/pbio/drv/adc/adc_stm32f0.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void pbdrv_adc_calibrate(void) {
3535
}
3636
}
3737

38-
static void pbdrv_adc_init(void) {
38+
void pbdrv_adc_init(void) {
3939
// enable power domain
4040
RCC->APB2ENR |= RCC_APB2ENR_ADCEN;
4141

@@ -61,6 +61,8 @@ static void pbdrv_adc_init(void) {
6161
// TODO: LEGO firmware reads CH 3 during init 10 times and averages it.
6262
// Not sure what this is measuring or what it would be used for. Perhaps
6363
// some kind of ID resistor?
64+
65+
process_start(&pbdrv_adc_process);
6466
}
6567

6668
// does a single conversion for the specified channel
@@ -91,8 +93,6 @@ PROCESS_THREAD(pbdrv_adc_process, ev, data) {
9193

9294
PROCESS_BEGIN();
9395

94-
pbdrv_adc_init();
95-
9696
while (true) {
9797
PROCESS_WAIT_EVENT();
9898
}

lib/pbio/drv/core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <pbdrv/config.h>
77

88
#include "core.h"
9+
#include "adc/adc.h"
910
#include "battery/battery.h"
1011
#include "block_device/block_device.h"
1112
#include "bluetooth/bluetooth.h"
@@ -78,4 +79,8 @@ void pbdrv_init(void) {
7879
// devices behaves the same as if unknown devices are still syncing up after
7980
// just being plugged in.
8081
pbdrv_legodev_init();
82+
83+
// REVISIT: verify that the order does not matter and that we can start this
84+
// in the same place as the other drivers above.
85+
pbdrv_adc_init();
8186
}

lib/pbio/drv/uart/uart_stm32f0.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <pbio/error.h>
2222
#include <pbio/util.h>
2323

24-
#include "../../src/processes.h"
2524
#include "../core.h"
2625

2726
#include "stm32f0xx.h"

lib/pbio/drv/uart/uart_stm32f4_ll_irq.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "../core.h"
2525
#include "./uart_stm32f4_ll_irq.h"
26-
#include "../../src/processes.h"
2726

2827
#define RX_DATA_SIZE 64 // must be power of 2 for ring buffer!
2928

lib/pbio/drv/uart/uart_stm32l4_ll_dma.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <pbio/util.h>
2121

2222
#include "./uart_stm32l4_ll_dma.h"
23-
#include "../../src/processes.h"
2423
#include "../core.h"
2524

2625
#include "stm32l4xx_ll_dma.h"

lib/pbio/src/main.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@
2323
#include <pbio/motor_process.h>
2424

2525
#include "light/animation.h"
26-
#include "processes.h"
27-
28-
// DO NOT ADD NEW PROCESSES HERE!
29-
// We are trying to remove the use of autostart.
30-
AUTOSTART_PROCESSES(
31-
#if PBDRV_CONFIG_ADC
32-
&pbdrv_adc_process,
33-
#endif
34-
NULL);
3526

3627
/**
3728
* Initialize the Pybricks I/O Library. This function must be called once,
@@ -41,10 +32,6 @@ AUTOSTART_PROCESSES(
4132
void pbio_init(void) {
4233
pbdrv_init();
4334

44-
// TODO: remove autostart - this currently starts legacy drivers like analog
45-
// it has to be after pbdrv_init() but before anything else
46-
autostart_start(autostart_processes);
47-
4835
#if PBIO_CONFIG_MOTOR_PROCESS_AUTO_START
4936
pbio_motor_process_start();
5037
#endif

lib/pbio/src/processes.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/pbio/test/src/test_drivebase.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <pbio/servo.h>
2727
#include <test-pbio.h>
2828

29-
#include "../src/processes.h"
3029
#include "../drv/core.h"
3130
#include "../drv/clock/clock_test.h"
3231
#include "../drv/motor_driver/motor_driver_virtual_simulation.h"

0 commit comments

Comments
 (0)