Skip to content

Commit 761ba6a

Browse files
committed
pbio/drv/counter: Rename virtual to virtual_cpython.
This allows us to add other virtual implementations.
1 parent 1fd2011 commit 761ba6a

File tree

8 files changed

+48
-48
lines changed

8 files changed

+48
-48
lines changed

bricks/_common/sources.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
145145
drv/counter/counter_lpf2.c \
146146
drv/counter/counter_nxt.c \
147147
drv/counter/counter_stm32f0_gpio_quad_enc.c \
148-
drv/counter/counter_virtual.c \
148+
drv/counter/counter_virtual_cpython.c \
149149
drv/gpio/gpio_stm32f0.c \
150150
drv/gpio/gpio_stm32f4.c \
151151
drv/gpio/gpio_stm32l4.c \

lib/pbio/cpython/pbio_virtual/drv/counter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
class VirtualCounter:
66
rotations: int = 0
77
"""
8-
Provides the rotations returned by ``pbdrv_counter_virtual_get_angle()``.
8+
Provides the rotations returned by ``pbdrv_counter_virtual_cpython_get_angle()``.
99
1010
CPython code should write to this attribute to simulate the current value
1111
and the PBIO driver will read this attribute.
1212
"""
1313

1414
millidegrees: int = 0
1515
"""
16-
Provides the millidegrees returned by ``pbdrv_counter_virtual_get_angle()``.
16+
Provides the millidegrees returned by ``pbdrv_counter_virtual_cpython_get_angle()``.
1717
1818
CPython code should write to this attribute to simulate the current value
1919
and the PBIO driver will read this attribute.
2020
"""
2121

2222
millidegrees_abs: int = 0
2323
"""
24-
Provides the absolute angle returned by ``pbdrv_counter_virtual_get_abs_angle()``.
24+
Provides the absolute angle returned by ``pbdrv_counter_virtual_cpython_get_abs_angle()``.
2525
2626
CPython code should write to this attribute to simulate the current value
2727
and the PBIO driver will read this attribute.

lib/pbio/cpython/pbio_virtual/platform/robot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ def __init__(self, sim_motor, clock):
9696
@property
9797
def rotations(self):
9898
"""
99-
Provides rotations for ``pbdrv_counter_virtual_get_angle()``.
99+
Provides rotations for ``pbdrv_counter_virtual_cpython_get_angle()``.
100100
"""
101101
return self.get_counter_data()[0]
102102

103103
@property
104104
def millidegrees(self):
105105
"""
106-
Provides rotations for ``pbdrv_counter_virtual_get_angle()``.
106+
Provides rotations for ``pbdrv_counter_virtual_cpython_get_angle()``.
107107
"""
108108
return self.get_counter_data()[1]
109109

110110
@property
111111
def millidegrees_abs(self):
112112
"""
113-
Provides the value for ``pbdrv_counter_virtual_get_abs_angle()``.
113+
Provides the value for ``pbdrv_counter_virtual_cpython_get_abs_angle()``.
114114
"""
115115
return self.get_counter_data()[2]
116116

lib/pbio/drv/counter/counter_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "counter_nxt.h"
1616
#include "counter_stm32f0_gpio_quad_enc.h"
1717
#include "counter_test.h"
18-
#include "counter_virtual.h"
18+
#include "counter_virtual_cpython.h"
1919
#include "counter.h"
2020

2121
static pbdrv_counter_dev_t pbdrv_counter_devs[PBDRV_CONFIG_COUNTER_NUM_DEV];
@@ -26,7 +26,7 @@ void pbdrv_counter_init(void) {
2626
pbdrv_counter_nxt_init(pbdrv_counter_devs);
2727
pbdrv_counter_stm32f0_gpio_quad_enc_init(pbdrv_counter_devs);
2828
pbdrv_counter_test_init(pbdrv_counter_devs);
29-
pbdrv_counter_virtual_init(pbdrv_counter_devs);
29+
pbdrv_counter_virtual_cpython_init(pbdrv_counter_devs);
3030
}
3131

3232
pbio_error_t pbdrv_counter_get_dev(uint8_t id, pbdrv_counter_dev_t **dev) {

lib/pbio/drv/counter/counter_virtual.h

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

lib/pbio/drv/counter/counter_virtual.c renamed to lib/pbio/drv/counter/counter_virtual_cpython.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <pbdrv/config.h>
77

8-
#if PBDRV_CONFIG_COUNTER_VIRTUAL
8+
#if PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON
99

1010
#include <errno.h>
1111
#include <stdint.h>
@@ -29,9 +29,9 @@ typedef struct {
2929
uint8_t index;
3030
} private_data_t;
3131

32-
static private_data_t private_data[PBDRV_CONFIG_COUNTER_VIRTUAL_NUM_DEV];
32+
static private_data_t private_data[PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON_NUM_DEV];
3333

34-
static pbio_error_t pbdrv_counter_virtual_get_angle(pbdrv_counter_dev_t *dev, int32_t *rotations, int32_t *millidegrees) {
34+
static pbio_error_t pbdrv_counter_virtual_cpython_get_angle(pbdrv_counter_dev_t *dev, int32_t *rotations, int32_t *millidegrees) {
3535
private_data_t *priv = dev->priv;
3636

3737
pbio_error_t err = pbdrv_virtual_get_i32("counter", priv->index, "rotations", rotations);
@@ -42,18 +42,18 @@ static pbio_error_t pbdrv_counter_virtual_get_angle(pbdrv_counter_dev_t *dev, in
4242
return pbdrv_virtual_get_i32("counter", priv->index, "millidegrees", millidegrees);
4343
}
4444

45-
static pbio_error_t pbdrv_counter_virtual_get_abs_angle(pbdrv_counter_dev_t *dev, int32_t *millidegrees) {
45+
static pbio_error_t pbdrv_counter_virtual_cpython_get_abs_angle(pbdrv_counter_dev_t *dev, int32_t *millidegrees) {
4646
private_data_t *priv = dev->priv;
4747

4848
return pbdrv_virtual_get_i32("counter", priv->index, "millidegrees_abs", millidegrees);
4949
}
5050

51-
static const pbdrv_counter_funcs_t pbdrv_counter_virtual_funcs = {
52-
.get_angle = pbdrv_counter_virtual_get_angle,
53-
.get_abs_angle = pbdrv_counter_virtual_get_abs_angle,
51+
static const pbdrv_counter_funcs_t pbdrv_counter_virtual_cpython_funcs = {
52+
.get_angle = pbdrv_counter_virtual_cpython_get_angle,
53+
.get_abs_angle = pbdrv_counter_virtual_cpython_get_abs_angle,
5454
};
5555

56-
void pbdrv_counter_virtual_init(pbdrv_counter_dev_t *devs) {
56+
void pbdrv_counter_virtual_cpython_init(pbdrv_counter_dev_t *devs) {
5757
for (size_t i = 0; i < PBIO_ARRAY_SIZE(private_data); i++) {
5858
private_data_t *priv = &private_data[i];
5959

@@ -62,13 +62,13 @@ void pbdrv_counter_virtual_init(pbdrv_counter_dev_t *devs) {
6262
// FIXME: assuming that these are the only counter devices
6363
// counter_id should be passed from platform data instead
6464
// i.e. enumerate CPython `platform.counter.keys()`.
65-
_Static_assert(PBDRV_CONFIG_COUNTER_VIRTUAL_NUM_DEV == PBDRV_CONFIG_COUNTER_NUM_DEV,
66-
"need to fix counter_virtual implementation to allow other counter devices");
65+
_Static_assert(PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON_NUM_DEV == PBDRV_CONFIG_COUNTER_NUM_DEV,
66+
"need to fix counter_virtual_cpython implementation to allow other counter devices");
6767

6868
priv->dev = &devs[i];
69-
priv->dev->funcs = &pbdrv_counter_virtual_funcs;
69+
priv->dev->funcs = &pbdrv_counter_virtual_cpython_funcs;
7070
priv->dev->priv = priv;
7171
}
7272
}
7373

74-
#endif // PBDRV_CONFIG_COUNTER_VIRTUAL
74+
#endif // PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022 The Pybricks Authors
3+
4+
#ifndef _INTERNAL_PBDRV_COUNTER_VIRTUAL_CPYTHON_H_
5+
#define _INTERNAL_PBDRV_COUNTER_VIRTUAL_CPYTHON_H_
6+
7+
#include <pbdrv/config.h>
8+
9+
#if PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON
10+
11+
#if !PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON_NUM_DEV
12+
#error Platform must define PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON_NUM_DEV
13+
#endif
14+
15+
#include <pbdrv/counter.h>
16+
17+
void pbdrv_counter_virtual_cpython_init(pbdrv_counter_dev_t *devs);
18+
19+
#else // PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON
20+
21+
#define pbdrv_counter_virtual_cpython_init(devs)
22+
23+
#endif // PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON
24+
25+
#endif // _INTERNAL_PBDRV_COUNTER_VIRTUAL_CPYTHON_H_

lib/pbio/platform/virtual_hub/pbdrvconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
#define PBDRV_CONFIG_COUNTER (1)
1414
#define PBDRV_CONFIG_COUNTER_NUM_DEV (6)
15-
#define PBDRV_CONFIG_COUNTER_VIRTUAL (1)
16-
#define PBDRV_CONFIG_COUNTER_VIRTUAL_NUM_DEV (6)
15+
#define PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON (1)
16+
#define PBDRV_CONFIG_COUNTER_VIRTUAL_CPYTHON_NUM_DEV (6)
1717

1818
#define PBDRV_CONFIG_IOPORT (1)
1919
#define PBDRV_CONFIG_IOPORT_VIRTUAL (1)

0 commit comments

Comments
 (0)