forked from CU-ECEN-5823/course-project-PuneetBansal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.h
136 lines (110 loc) · 3.42 KB
/
gpio.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* @FileName : main.h
* @description : contains header files and #defines for the project.
* @author : Puneet Bansal
* @reference : Silicon Labs SDK -https://siliconlabs.github.io/Gecko_SDK_Doc/efr32bg13/html/index.html
* : Bluetooth Mesh SDK- https://www.silabs.com/documents/login/reference-manuals/bluetooth-le-and-mesh-software-api-reference-manual.pdf
* : SOC Bluetooth Mesh Light, SOC Bluetooth Mesh Switch example code.
*/
#include <stdint.h>
#include "cmu.h"
#include "letimer.h"
//#include "i2c.h"
#include <stdlib.h>
#include <stdbool.h>
#include "log.h"
//#include "si7021.h"
//#include "sleep.h"
//#include "i2c_interrupt.h"
#include "display.h"
#include "ble_device_type.h"
//#define sleepEM (sleepEM3) /*Energy mode you want to sleep in. i.e. if EM = 2 then, EM3,EM4 will be blocked.*/
#define sleepEM (1)
#define LED_PERIOD (1) /*Total LED period in seconds*/
#define LED_ONTIME (.175) /*LED on time in seconds*/
#define LFX0_FREQ (32768) /*Low frequency crystal oscillator frequency*/
#define ULFRCO_FREQ (1000) /*Ultra low frequency crystal oscillator frequency*/
#define MAX_TICKS (65535) /*Maximum ticks possible for a 16bit timer*/
#define MEAS_TEMP (1<<0)
#define SET_STATE (1<<1);
#define SENSOR_ENABLE_PIN 15
#define SENSOR_ENABLE_PORT gpioPortD
#define connection_min_interval (60) //time=value*1.25 so this is for 75ms
#define connection_max_interval (60)
#define connection_latency (3) //(300/75)
#define connection_timeout (600) //value should be greater than (1+latency)*max_interval*2
#define bt_Comp0Underflow 1<<0
#define bt_Comp1Interrupt 1<<1
#define bt_transferComplete 1<<2
#define bt_transferError 1<<3
#define bt_risingEdgeInt 1<<4
#define bt_fallingEdgeInt 1<<5
#define LCD_PORT gpioPortD
#define LCD_PIN 13
#define LCD_ENABLE_PIN 15
#define LCD_ENABLE_PORT gpioPortD
#define SCHEDULER_SUPPORTS_DISPLAY_UPDATE_EVENT 1
#define TIMER_SUPPORTS_1HZ_TIMER_EVENT 1
volatile uint16_t scheduler; /*Global variable to keep a track of events*/
typedef enum
{
idle,
initState,
writeState,
readState,
}states;
typedef enum
{
None=0,
Comp0Underflow,
Comp1Interrupt,
transferComplete,
transferError
}events;
typedef enum
{
discoverPrimaryServices,
discoverCharacteristics,
readCharacteristicsValue,
indication,
tempIndication,
running
}client;
client clientState;
volatile states presentState,prevState;
volatile events event;
int flag;
void state_machine();
void send_temp_via_bluetooth(float);
void disable_fxn();
int connection_open;
uint8_t bt_connection;
uint32_t bt_event;
int32_t transmitPower;
int32_t rssiValue;
/*************Client related defines***************/
volatile uint8_t client_connection;
volatile uint32_t client_tempService;
volatile uint32_t client_buttonService;
volatile uint16_t client_buttonCharacteristics;
volatile uint16_t client_tempCharacteristics;
volatile uint32_t client_temp;
uint8_t chNotifCounterTemp;
uint8_t chNotifCounterButton;
uint8_t indicationCounter;
uint8_t* charTemp;
uint8_t* receivedButtonState;
#define UINT32_TO_FLT(data) (((float)((int32_t)(data) & 0x00FFFFFFU)) * (float)pow(10, ((int32_t)(data) >> 24)))
uint8_t client_state;
#define GETTEMP 0x01
/*************************************************/
///*Bonding related declarations*/
//uint8 bondingConnection;
//int8 bondingHandle;
//uint16_t boundingVar;
//
///*Bonding +Client*/
//uint8_t bondingCon;
uint32_t buttonPress;
#define timerHandle 12
#define frienshipFailedHandle 10
uint32_t buttonDefine;