Skip to content

Instantly share code, notes, and snippets.

@jeremyherbert
Last active May 6, 2020 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyherbert/62cbed007f2f0c1b5b1a550fd14726ec to your computer and use it in GitHub Desktop.
Save jeremyherbert/62cbed007f2f0c1b5b1a550fd14726ec to your computer and use it in GitHub Desktop.
Zephyr BLE test
#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);
}
}
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