-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.c
71 lines (61 loc) · 1.38 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (c) 2018 AnyLedger
*
* SPDX-License-Identifier: Apache-2.0
*/
/* system includes */
#include <zephyr.h>
#include <board.h>
#include <device.h>
#include <gpio.h>
#include <string.h>
/* local includes */
#include "wallet.h"
#include "lwm2m_client.h"
/* 1000 msec = 1 sec */
#define SLEEP_TIME 1000
/* Change this if you have an LED connected to a custom port */
#ifndef LED0_GPIO_CONTROLLER
#ifdef LED0_GPIO_PORT
#define LED0_GPIO_CONTROLLER LED0_GPIO_PORT
#else
#define LED0_GPIO_CONTROLLER "(fail)"
#define LED0_GPIO_PIN 0
#endif
#endif
/* Change this if you have an LED connected to a custom pin */
#define LED LED0_GPIO_PIN
#define LED_PORT LED0_GPIO_CONTROLLER
extern uint8_t g_zephyr_private_key[32];
static struct device *init_led()
{
int ret;
struct device *led_dev;
led_dev = device_get_binding(LED_PORT);
if(led_dev == NULL) {
return NULL;
}
/* Set LED pin as output */
ret = gpio_pin_configure(led_dev, LED, GPIO_DIR_OUT);
if (ret) {
return NULL;
}
return led_dev;
}
void main(void)
{
int cnt = 0;
struct device *dev = init_led();
lwm2m_init();
privkey_t pk;
memcpy(&pk.k, g_zephyr_private_key, 32);
wallet_set_global_privkey(&pk);
while (1) {
/* Set pin to HIGH/LOW every 1 second */
if(dev != NULL) {
gpio_pin_write(dev, LED, cnt % 2);
cnt++;
}
k_sleep(SLEEP_TIME);
}
}