-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bluetooth: Mesh: Add some actual behavior in sample
Populates the onoff server stubs in the Bluetooth Mesh sample, and implements generic LED based hardware support to include more boards. Fixes #31031. Signed-off-by: Trond Einar Snekvik <[email protected]>
- Loading branch information
1 parent
b813616
commit 1a14bc8
Showing
9 changed files
with
493 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* board.c - Generic HW interaction hooks */ | ||
|
||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <bluetooth/mesh.h> | ||
#include <drivers/gpio.h> | ||
#include "board.h" | ||
|
||
/* Locate led0 as alias or label by that name */ | ||
#if DT_NODE_EXISTS(DT_ALIAS(led0)) | ||
#define LED0 DT_ALIAS(led0) | ||
#elif DT_NODE_EXISTS(DT_NODELABEL(led0)) | ||
#define LED0 DT_NODELABEL(led0) | ||
#else | ||
#define LED0 DT_INVALID_NODE | ||
#endif | ||
|
||
/* Locate button0 as alias or label by sw0 or button0 */ | ||
#if DT_NODE_EXISTS(DT_ALIAS(sw0)) | ||
#define BUTTON0 DT_ALIAS(sw0) | ||
#elif DT_NODE_EXISTS(DT_ALIAS(button0)) | ||
#define BUTTON0 DT_ALIAS(button0) | ||
#elif DT_NODE_EXISTS(DT_NODELABEL(sw0)) | ||
#define BUTTON0 DT_NODELABEL(sw0) | ||
#elif DT_NODE_EXISTS(DT_NODELABEL(button0)) | ||
#define BUTTON0 DT_NODELABEL(button0) | ||
#else | ||
#define BUTTON0 DT_INVALID_NODE | ||
#endif | ||
|
||
#if DT_NODE_EXISTS(LED0) | ||
#define LED0_DEV DT_PHANDLE(LED0, gpios) | ||
#define LED0_PIN DT_PHA(LED0, gpios, pin) | ||
#define LED0_FLAGS DT_PHA(LED0, gpios, flags) | ||
|
||
static const struct device *led_dev = DEVICE_DT_GET(LED0_DEV); | ||
#endif /* LED0 */ | ||
|
||
#if DT_NODE_EXISTS(BUTTON0) | ||
#define BUTTON0_DEV DT_PHANDLE(BUTTON0, gpios) | ||
#define BUTTON0_PIN DT_PHA(BUTTON0, gpios, pin) | ||
#define BUTTON0_FLAGS DT_PHA(BUTTON0, gpios, flags) | ||
|
||
static const struct device *button_dev = DEVICE_DT_GET(BUTTON0_DEV); | ||
static struct k_work *button_work; | ||
|
||
static void button_cb(const struct device *port, struct gpio_callback *cb, | ||
gpio_port_pins_t pins) | ||
{ | ||
k_work_submit(button_work); | ||
} | ||
#endif /* BUTTON0 */ | ||
|
||
static int led_init(void) | ||
{ | ||
#if DT_NODE_EXISTS(LED0) | ||
int err; | ||
|
||
if (!device_is_ready(led_dev)) { | ||
return -ENODEV; | ||
} | ||
|
||
err = gpio_pin_configure(led_dev, LED0_PIN, | ||
LED0_FLAGS | GPIO_OUTPUT_INACTIVE); | ||
if (err) { | ||
return err; | ||
} | ||
#else | ||
printk("WARNING: LEDs not supported on this board.\n"); | ||
#endif | ||
|
||
return 0; | ||
} | ||
|
||
static int button_init(struct k_work *button_pressed) | ||
{ | ||
#if DT_NODE_EXISTS(BUTTON0) | ||
int err; | ||
|
||
err = gpio_pin_configure(button_dev, BUTTON0_PIN, | ||
BUTTON0_FLAGS | GPIO_INPUT); | ||
if (err) { | ||
return err; | ||
} | ||
|
||
static struct gpio_callback gpio_cb; | ||
|
||
err = gpio_pin_interrupt_configure(button_dev, BUTTON0_PIN, | ||
GPIO_INT_EDGE_TO_ACTIVE); | ||
if (err) { | ||
return err; | ||
} | ||
|
||
button_work = button_pressed; | ||
|
||
gpio_init_callback(&gpio_cb, button_cb, BIT(BUTTON0_PIN)); | ||
gpio_add_callback(button_dev, &gpio_cb); | ||
#else | ||
printk("WARNING: Buttons not supported on this board.\n"); | ||
#endif | ||
|
||
return 0; | ||
} | ||
|
||
int board_init(struct k_work *button_pressed) | ||
{ | ||
int err; | ||
|
||
err = led_init(); | ||
if (err) { | ||
return err; | ||
} | ||
|
||
return button_init(button_pressed); | ||
} | ||
|
||
void board_led_set(bool val) | ||
{ | ||
#if DT_NODE_EXISTS(LED0) | ||
gpio_pin_set(led_dev, LED0_PIN, val); | ||
#endif | ||
} | ||
|
||
void board_output_number(bt_mesh_output_action_t action, uint32_t number) | ||
{ | ||
} | ||
|
||
void board_prov_complete(void) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.