Skip to content

Commit db29fc1

Browse files
committed
drv/button: move init function to private header
This move the pbdrv_button_init() function declaration to a private header file. This follows the pattern used by all of the other drivers.
1 parent c16740b commit db29fc1

File tree

10 files changed

+32
-22
lines changed

10 files changed

+32
-22
lines changed

lib/pbio/drv/button/button.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2022 The Pybricks Authors
3+
4+
// Internal common button functions.
5+
6+
#ifndef _INTERNAL_PBDRV_BUTTON_H_
7+
#define _INTERNAL_PBDRV_BUTTON_H_
8+
9+
#include <pbdrv/config.h>
10+
11+
#if PBDRV_CONFIG_BUTTON
12+
13+
/**
14+
* Initializes the low level button driver.
15+
*/
16+
void pbdrv_button_init(void);
17+
18+
#else
19+
20+
#define pbdrv_button_init()
21+
22+
#endif
23+
24+
#endif // _INTERNAL_PBDRV_BUTTON_H_

lib/pbio/drv/button/button_gpio.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
#include "button_gpio.h"
1414

15-
// PC13 is the green button (active low)
16-
17-
void _pbdrv_button_init(void) {
15+
void pbdrv_button_init(void) {
1816
for (int i = 0; i < PBDRV_CONFIG_BUTTON_GPIO_NUM_BUTTON; i++) {
1917
const pbdrv_button_gpio_platform_t *platform = &pbdrv_button_gpio_platform[i];
2018
pbdrv_gpio_set_pull(&platform->gpio, platform->pull);

lib/pbio/drv/button/button_linux_ev3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
static int f_btn = -1; // Button file descriptor
1919

20-
void _pbdrv_button_init(void) {
20+
void pbdrv_button_init(void) {
2121
f_btn = open("/dev/input/by-path/platform-gpio_keys-event", O_RDONLY);
2222
if (f_btn == -1) {
2323
perror("Failed to init buttons");

lib/pbio/drv/button/button_nxt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <base/drivers/avr.h>
1313

14-
void _pbdrv_button_init(void) {
14+
void pbdrv_button_init(void) {
1515
}
1616

1717
pbio_error_t pbdrv_button_is_pressed(pbio_button_flags_t *pressed) {

lib/pbio/drv/button/button_resistor_ladder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <pbio/button.h>
1212
#include <pbio/error.h>
1313

14-
void _pbdrv_button_init(void) {
14+
void pbdrv_button_init(void) {
1515
}
1616

1717
pbio_error_t pbdrv_button_is_pressed(pbio_button_flags_t *pressed) {

lib/pbio/drv/button/button_virtual.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "../virtual.h"
1212

13-
void _pbdrv_button_init(void) {
13+
void pbdrv_button_init(void) {
1414
}
1515

1616
pbio_error_t pbdrv_button_is_pressed(pbio_button_flags_t *pressed) {

lib/pbio/drv/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "battery/battery.h"
88
#include "block_device/block_device.h"
99
#include "bluetooth/bluetooth.h"
10+
#include "button/button.h"
1011
#include "charger/charger.h"
1112
#include "clock/clock.h"
1213
#include "counter/counter.h"
@@ -34,6 +35,7 @@ void pbdrv_init(void) {
3435
pbdrv_battery_init();
3536
pbdrv_block_device_init();
3637
pbdrv_bluetooth_init();
38+
pbdrv_button_init();
3739
pbdrv_charger_init();
3840
pbdrv_counter_init();
3941
pbdrv_imu_init();

lib/pbio/include/pbdrv/button.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@
2020

2121
#if PBDRV_CONFIG_BUTTON
2222

23-
/** @cond INTERNAL */
24-
25-
/**
26-
* Initializes the low level button driver. This should be called only
27-
* once and must be called before using any other button functions.
28-
*/
29-
void _pbdrv_button_init(void);
30-
31-
/** @endcond */
32-
3323
/**
3424
* Get bitmask indicating currently pressed buttons.
3525
* @param [out] pressed Bitmask indicating which buttons are pressed
@@ -41,9 +31,6 @@ pbio_error_t pbdrv_button_is_pressed(pbio_button_flags_t *pressed);
4131

4232
#else
4333

44-
static inline void _pbdrv_button_init(void) {
45-
}
46-
4734
static inline pbio_error_t pbdrv_button_is_pressed(pbio_button_flags_t *pressed) {
4835
*pressed = 0;
4936
return PBIO_ERROR_NOT_SUPPORTED;

lib/pbio/src/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ AUTOSTART_PROCESSES(
4949
*/
5050
void pbio_init(void) {
5151
pbdrv_init();
52-
_pbdrv_button_init();
5352
autostart_start(autostart_processes);
5453
}
5554

lib/pbio/test/drv/button.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void pbio_test_button_set_pressed(pbio_button_flags_t flags) {
1212
pbio_test_button_flags = flags;
1313
}
1414

15-
void _pbdrv_button_init(void) {
15+
void pbdrv_button_init(void) {
1616
}
1717

1818
pbio_error_t pbdrv_button_is_pressed(pbio_button_flags_t *pressed) {

0 commit comments

Comments
 (0)