add bluetooth support
Some checks failed
Some checks failed
This commit is contained in:
@ -16,4 +16,7 @@ CONFIG_LOG=y
|
|||||||
|
|
||||||
CONFIG_CFB_LOG_LEVEL_DBG=y
|
CONFIG_CFB_LOG_LEVEL_DBG=y
|
||||||
CONFIG_CHARACTER_FRAMEBUFFER=y
|
CONFIG_CHARACTER_FRAMEBUFFER=y
|
||||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||||
|
|
||||||
|
CONFIG_BT=y
|
||||||
|
CONFIG_BT_DEVICE_NAME="Mellifera"
|
@ -12,11 +12,75 @@
|
|||||||
|
|
||||||
#include <app_version.h>
|
#include <app_version.h>
|
||||||
|
|
||||||
|
#include <zephyr/bluetooth/bluetooth.h>
|
||||||
|
#include <zephyr/bluetooth/hci.h>
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
||||||
|
|
||||||
#define BLINK_PERIOD_MS_STEP 100U
|
#define BLINK_PERIOD_MS_STEP 100U
|
||||||
#define BLINK_PERIOD_MS_MAX 1000U
|
#define BLINK_PERIOD_MS_MAX 1000U
|
||||||
|
|
||||||
|
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
|
||||||
|
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set Advertisement data. Based on the Eddystone specification:
|
||||||
|
* https://github.com/google/eddystone/blob/master/protocol-specification.md
|
||||||
|
* https://github.com/google/eddystone/tree/master/eddystone-url
|
||||||
|
*/
|
||||||
|
static const struct bt_data ad[] = {
|
||||||
|
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
|
||||||
|
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0xaa, 0xfe),
|
||||||
|
BT_DATA_BYTES(BT_DATA_SVC_DATA16,
|
||||||
|
0xaa, 0xfe, /* Eddystone UUID */
|
||||||
|
0x10, /* Eddystone-URL frame type */
|
||||||
|
0x00, /* Calibrated Tx power at 0m */
|
||||||
|
0x00, /* URL Scheme Prefix http://www. */
|
||||||
|
'z', 'e', 'p', 'h', 'y', 'r',
|
||||||
|
'p', 'r', 'o', 'j', 'e', 'c', 't',
|
||||||
|
0x08) /* .org */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Set Scan Response data */
|
||||||
|
static const struct bt_data sd[] = {
|
||||||
|
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
|
||||||
|
};
|
||||||
|
|
||||||
|
static void bt_ready(int err)
|
||||||
|
{
|
||||||
|
char addr_s[BT_ADDR_LE_STR_LEN];
|
||||||
|
bt_addr_le_t addr = {0};
|
||||||
|
size_t count = 1;
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
LOG_ERR("Bluetooth init failed (err %d)", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INF("Bluetooth initialized");
|
||||||
|
|
||||||
|
/* Start advertising */
|
||||||
|
err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
|
||||||
|
sd, ARRAY_SIZE(sd));
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
LOG_ERR("Advertising failed to start (err %d)", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* For connectable advertising you would use
|
||||||
|
* bt_le_oob_get_local(). For non-connectable non-identity
|
||||||
|
* advertising an non-resolvable private address is used;
|
||||||
|
* there is no API to retrieve that.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bt_id_get(&addr, &count);
|
||||||
|
bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s));
|
||||||
|
|
||||||
|
LOG_INF("Beacon started, advertising as %s", addr_s);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct device *dev;
|
const struct device *dev;
|
||||||
@ -27,13 +91,24 @@ int main(void)
|
|||||||
uint8_t font_width;
|
uint8_t font_width;
|
||||||
uint8_t font_height;
|
uint8_t font_height;
|
||||||
|
|
||||||
|
int err;
|
||||||
|
|
||||||
printk("Starting Mellifera version %s...\n", APP_VERSION_STRING);
|
printk("Starting Mellifera version %s...\n", APP_VERSION_STRING);
|
||||||
// printk("Board: %s\n", BOARD);
|
// printk("Board: %s\n", BOARD);
|
||||||
|
|
||||||
|
LOG_INF("Starting Beacon Demo");
|
||||||
|
|
||||||
|
/* Initialize the Bluetooth Subsystem */
|
||||||
|
err = bt_enable(bt_ready);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
LOG_ERR("Bluetooth init failed (err %d)", err);
|
||||||
|
}
|
||||||
|
|
||||||
dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
|
dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
|
||||||
if (!device_is_ready(dev))
|
if (!device_is_ready(dev))
|
||||||
{
|
{
|
||||||
LOG_ERR("Device %s not ready\n", dev->name);
|
LOG_ERR("Device %s not ready", dev->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,11 +121,11 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INF("Initialized %s\n", dev->name);
|
LOG_INF("Initialized %s", dev->name);
|
||||||
|
|
||||||
if (cfb_framebuffer_init(dev))
|
if (cfb_framebuffer_init(dev))
|
||||||
{
|
{
|
||||||
LOG_ERR("Framebuffer initialization failed!\n");
|
LOG_ERR("Framebuffer initialization failed!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,37 +164,37 @@ int main(void)
|
|||||||
ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
|
ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
|
||||||
if (!device_is_ready(ina))
|
if (!device_is_ready(ina))
|
||||||
{
|
{
|
||||||
LOG_ERR("Device %s not ready\n", ina->name);
|
LOG_ERR("Device %s not ready", ina->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bmp = DEVICE_DT_GET(DT_NODELABEL(bmp388));
|
bmp = DEVICE_DT_GET(DT_NODELABEL(bmp388));
|
||||||
if (!device_is_ready(bmp))
|
if (!device_is_ready(bmp))
|
||||||
{
|
{
|
||||||
LOG_ERR("Device %s not ready\n", bmp->name);
|
LOG_ERR("Device %s not ready", bmp->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bmx = DEVICE_DT_GET(DT_NODELABEL(bmx055));
|
bmx = DEVICE_DT_GET(DT_NODELABEL(bmx055));
|
||||||
if (!device_is_ready(bmx))
|
if (!device_is_ready(bmx))
|
||||||
{
|
{
|
||||||
LOG_ERR("Device %s not ready\n", bmx->name);
|
LOG_ERR("Device %s not ready", bmx->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LOG_INF("Initialized %s\n", bmx->name);
|
LOG_INF("Initialized %s", bmx->name);
|
||||||
|
|
||||||
lis = DEVICE_DT_GET(DT_NODELABEL(lis2dh));
|
lis = DEVICE_DT_GET(DT_NODELABEL(lis2dh));
|
||||||
if (!device_is_ready(lis))
|
if (!device_is_ready(lis))
|
||||||
{
|
{
|
||||||
LOG_ERR("Device %s not ready\n", lis->name);
|
LOG_ERR("Device %s not ready", lis->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LOG_INF("Initialized %s\n", lis->name);
|
LOG_INF("Initialized %s", lis->name);
|
||||||
|
|
||||||
hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080));
|
hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080));
|
||||||
if (!device_is_ready(hdc))
|
if (!device_is_ready(hdc))
|
||||||
{
|
{
|
||||||
printf("Device %s not ready\n", hdc->name);
|
LOG_ERR("Device %s not ready", hdc->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +321,7 @@ int main(void)
|
|||||||
sprintf(str_ay, "Y :%+7.3f", accel_y.val1 + accel_y.val2 * 1e-6);
|
sprintf(str_ay, "Y :%+7.3f", accel_y.val1 + accel_y.val2 * 1e-6);
|
||||||
sprintf(str_az, "Z :%+7.3f", accel_z.val1 + accel_z.val2 * 1e-6);
|
sprintf(str_az, "Z :%+7.3f", accel_z.val1 + accel_z.val2 * 1e-6);
|
||||||
sprintf(str_az_ref, "Zr:%+7.3f", accel_z_ref.val1 + accel_z_ref.val2 * 1e-6);
|
sprintf(str_az_ref, "Zr:%+7.3f", accel_z_ref.val1 + accel_z_ref.val2 * 1e-6);
|
||||||
sprintf(str_h, "H :%7.5f", humidity.val1 + humidity.val2 * 1e-6);
|
sprintf(str_h, "H :%7.3f", humidity.val1 + humidity.val2 * 1e-6);
|
||||||
|
|
||||||
// printf("%s\t%s\t%s\t%s\n", str_v, str_i, str_p, str_t);
|
// printf("%s\t%s\t%s\t%s\n", str_v, str_i, str_p, str_t);
|
||||||
|
|
||||||
|
@ -188,3 +188,29 @@
|
|||||||
pinctrl-1 = <&spi1_sleep>;
|
pinctrl-1 = <&spi1_sleep>;
|
||||||
pinctrl-names = "default", "sleep";
|
pinctrl-names = "default", "sleep";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
&flash0 {
|
||||||
|
|
||||||
|
partitions {
|
||||||
|
compatible = "fixed-partitions";
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <1>;
|
||||||
|
|
||||||
|
boot_partition: partition@0 {
|
||||||
|
label = "mcuboot";
|
||||||
|
reg = <0x00000000 0xc000>;
|
||||||
|
};
|
||||||
|
slot0_partition: partition@c000 {
|
||||||
|
label = "image-0";
|
||||||
|
reg = <0x0000C000 0x37000>;
|
||||||
|
};
|
||||||
|
slot1_partition: partition@43000 {
|
||||||
|
label = "image-1";
|
||||||
|
reg = <0x00043000 0x37000>;
|
||||||
|
};
|
||||||
|
storage_partition: partition@7a000 {
|
||||||
|
label = "storage";
|
||||||
|
reg = <0x0007a000 0x00006000>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user