Last active
May 6, 2020 07:50
-
-
Save jeremyherbert/62cbed007f2f0c1b5b1a550fd14726ec to your computer and use it in GitHub Desktop.
Zephyr BLE test
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
#include <zephyr.h> | |
#include <device.h> | |
#include <drivers/gpio.h> | |
#include <bluetooth/bluetooth.h> | |
#define LED_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER | |
#define LED DT_ALIAS_LED0_GPIOS_PIN | |
/* 1000 msec = 1 sec */ | |
#define SLEEP_TIME 1000 | |
static u8_t mfg_data[] = { 0xff, 0xff, 0xAB }; | |
static const struct bt_data ad[] = { | |
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3), | |
}; | |
void main(void) | |
{ | |
u32_t cnt = 0; | |
struct device *dev; | |
dev = device_get_binding(LED_PORT); | |
/* Set LED pin as output */ | |
gpio_pin_configure(dev, LED, GPIO_DIR_OUT); | |
int err = bt_enable(NULL); | |
if (err) { | |
printk("Bluetooth init failed (err %d)\n", err); | |
return; | |
} | |
err = bt_le_adv_start(BT_LE_ADV_NCONN_NAME, ad, ARRAY_SIZE(ad), | |
NULL, 0); | |
if (err) { | |
printk("Advertising failed to start (err %d)\n", err); | |
return; | |
} | |
while (1) { | |
/* Set pin to HIGH/LOW every 1 second */ | |
gpio_pin_write(dev, LED, cnt % 2); | |
cnt++; | |
k_sleep(SLEEP_TIME); | |
} | |
} |
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
CONFIG_GPIO=y | |
CONFIG_OPENOCD_SUPPORT=y | |
CONFIG_BT=y | |
CONFIG_BT_BROADCASTER=y | |
CONFIG_BT_DEBUG_LOG=y | |
CONFIG_BT_DEVICE_NAME="Zephyr Test" | |
CONFIG_BT_DEVICE_NAME_MAX=15 | |
CONFIG_DEBUG=y | |
CONFIG_NO_OPTIMIZATIONS=y | |
CONFIG_ASSERT=y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment