Krolyxon
Commit 097b106

Branches

Tags

Refs →

orion-rffirmwarefirmware.ino

128 lines · 2.1 KB

1#include <Arduino.h>
2#include <USB.h>
3#include <USBHIDKeyboard.h>
4
5#include <BLEDevice.h>
6#include <BLEScan.h>
7
8#include <RF24.h>
9#include <nRF24L01.h>
10
11#include "ELECHOUSE_CC1101_SRC_DRV.h"
12
13#include <WiFi.h>
14#include <esp_wifi.h>
15
16#include <esp_chip_info.h>
17#include <esp_heap_caps.h>
18#include <esp_system.h>
19#include <SPI.h>
20
21
22#include "display.h"
23#include "buttons.h"
24#include "menu.h"
25
26#include "config.h"
27#include "cc1101.h"
28
29// ================= USB HID =================
30USBHIDKeyboard Keyboard;
31
32
33RF24 radio1(CE1_PIN, CSN1_PIN);
34RF24 radio2(CE2_PIN, CSN2_PIN);
35SPIClass *RADIO_SPI;
36
37
38
39
40// ================= BLE SCAN =================
41BLEScan *pBLEScan;
42
43
44void startBLEScan()
45{
46 BLEDevice::init("");
47
48 pBLEScan = BLEDevice::getScan();
49
50 pBLEScan->setActiveScan(true);
51
52 pBLEScan->start(5);
53
54 Serial.println("BLE scan complete");
55}
56
57// ================= SYSTEM INFO =================
58void printSystemUsage()
59{
60 esp_chip_info_t chip_info;
61
62 esp_chip_info(&chip_info);
63
64 Serial.printf("CPU cores: %d\n", chip_info.cores);
65
66 Serial.printf(
67 "Free heap: %d bytes\n",
68 heap_caps_get_free_size(MALLOC_CAP_DEFAULT)
69 );
70
71 Serial.printf(
72 "PSRAM free: %d bytes\n",
73 heap_caps_get_free_size(MALLOC_CAP_SPIRAM)
74 );
75}
76
77void showSplash()
78{
79 u8g2.clearBuffer();
80
81 u8g2.setFont(u8g2_font_logisoso20_tr); // big font
82 u8g2.drawStr(10, 40, "Orion-RF");
83
84 u8g2.setFont(u8g2_font_5x8_tr); // small subtitle
85 u8g2.drawStr(25, 58, "Initializing...");
86
87 u8g2.sendBuffer();
88
89 delay(1500); // 1.5 sec
90}
91
92
93// ================= SETUP =================
94void setup()
95{
96 Serial.begin(115200);
97
98 displayInit();
99 showSplash();
100
101 buttonsInit();
102 menuInit();
103
104 delay(1500);
105
106 USB.begin();
107 Keyboard.begin();
108
109 // NRF SPI safety
110 pinMode(CSN1_PIN, OUTPUT);
111 digitalWrite(CSN1_PIN, HIGH);
112
113 pinMode(CSN2_PIN, OUTPUT);
114 digitalWrite(CSN2_PIN, HIGH);
115
116 RADIO_SPI = new SPIClass(FSPI);
117 RADIO_SPI->begin(NRF_SCK, NRF_MISO, NRF_MOSI);
118
119 printSystemUsage();
120
121 Serial.println("SYSTEM READY");
122}
123
124// ================= LOOP =================
125void loop()
126{
127 menuLoop();
128}