zephyr/tests/bluetooth/mesh/src/microbit.c

97 lines
2.2 KiB
C

/* microbit.c - BBC micro:bit specific hooks */
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <drivers/gpio.h>
#include <display/mb_display.h>
#include <bluetooth/mesh.h>
#include "board.h"
static u32_t oob_number;
static struct device *gpio;
static void button_pressed(struct device *dev, struct gpio_callback *cb,
u32_t pins)
{
struct mb_display *disp = mb_display_get();
mb_display_print(disp, MB_DISPLAY_MODE_DEFAULT, K_MSEC(500),
"OOB Number: %u", oob_number);
}
static void configure_button(void)
{
static struct gpio_callback button_cb;
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));
gpio_init_callback(&button_cb, button_pressed, BIT(DT_ALIAS_SW0_GPIOS_PIN));
gpio_add_callback(gpio, &button_cb);
}
void board_output_number(bt_mesh_output_action_t action, u32_t number)
{
struct mb_display *disp = mb_display_get();
struct mb_image arrow = MB_IMAGE({ 0, 0, 1, 0, 0 },
{ 0, 1, 0, 0, 0 },
{ 1, 1, 1, 1, 1 },
{ 0, 1, 0, 0, 0 },
{ 0, 0, 1, 0, 0 });
oob_number = number;
gpio_pin_enable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN);
mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT, K_FOREVER, &arrow, 1);
}
void board_prov_complete(void)
{
struct mb_display *disp = mb_display_get();
struct mb_image arrow = MB_IMAGE({ 0, 1, 0, 1, 0 },
{ 0, 1, 0, 1, 0 },
{ 0, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 1 },
{ 0, 1, 1, 1, 0 });
gpio_pin_disable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN);
mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT, K_SECONDS(10),
&arrow, 1);
}
void board_init(void)
{
struct mb_display *disp = mb_display_get();
static struct mb_image blink[] = {
MB_IMAGE({ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 }),
MB_IMAGE({ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 })
};
mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT | MB_DISPLAY_FLAG_LOOP,
K_SECONDS(1), blink, ARRAY_SIZE(blink));
configure_button();
}