Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6466f0e

Browse filesBrowse files
committed
NDP: introduce high level library for Nicla Voice
1 parent 2adb3c9 commit 6466f0e
Copy full SHA for 6466f0e
Expand file treeCollapse file tree

29 files changed

+3890
-0
lines changed
+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "NDP.h"
2+
3+
//const bool lowestPower = true;
4+
const bool lowestPower = false;
5+
6+
void ledBlueOn(char* label) {
7+
nicla::leds.begin();
8+
nicla::leds.setColor(blue);
9+
delay(200);
10+
nicla::leds.setColor(off);
11+
if (!lowestPower) {
12+
Serial.println(label);
13+
}
14+
nicla::leds.end();
15+
}
16+
17+
void ledGreenOn() {
18+
nicla::leds.begin();
19+
nicla::leds.setColor(green);
20+
delay(200);
21+
nicla::leds.setColor(off);
22+
nicla::leds.end();
23+
}
24+
25+
void ledRedBlink() {
26+
while (1) {
27+
nicla::leds.begin();
28+
nicla::leds.setColor(red);
29+
delay(200);
30+
nicla::leds.setColor(off);
31+
delay(200);
32+
nicla::leds.end();
33+
}
34+
}
35+
36+
void setup() {
37+
38+
Serial.begin(115200);
39+
nicla::begin();
40+
nicla::disableLDO();
41+
nicla::leds.begin();
42+
43+
NDP.onError(ledRedBlink);
44+
NDP.onMatch(ledBlueOn);
45+
NDP.onEvent(ledGreenOn);
46+
Serial.println("Loading synpackages");
47+
NDP.begin("mcu_fw_120_v90.synpkg");
48+
NDP.load("dsp_firmware_v90.synpkg");
49+
NDP.load("alexa_334_NDP120_B0_v11_v90.synpkg");
50+
Serial.println("packages loaded");
51+
NDP.getInfo();
52+
Serial.println("Configure clock");
53+
NDP.turnOnMicrophone();
54+
NDP.interrupts();
55+
56+
// For maximum low power; please note that it's impossible to print afer calling these functions
57+
nicla::leds.end();
58+
if (lowestPower) {
59+
NRF_UART0->ENABLE = 0;
60+
}
61+
//NDP.turnOffMicrophone();
62+
}
63+
64+
void loop() {
65+
uint8_t command = 0xFF;
66+
67+
while (Serial.available()) {
68+
command = Serial.read();
69+
if (command == 'f') {
70+
Serial.println("Interrupts disabled");
71+
NDP.noInterrupts();
72+
} else if (command == 'o') {
73+
Serial.println("Interrupts enabled");
74+
NDP.interrupts();
75+
}
76+
}
77+
//Serial.println("in the loop");
78+
delay(100);
79+
}
+86Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include "NDP.h"
2+
#include <ArduinoBLE.h>
3+
4+
// BLE Battery Service
5+
BLEService alertService("1802"); // Immediate alert
6+
7+
// BLE Battery Level Characteristic
8+
BLEUnsignedCharCharacteristic alertLevel("2A06", BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
9+
10+
const bool lowestPower = true;
11+
12+
void alertViaBLE(int index) {
13+
// notify that we recognized a keyword
14+
alertLevel.writeValue(2);
15+
delay(1000);
16+
alertLevel.writeValue(0);
17+
}
18+
19+
void ledGreenOn() {
20+
nicla::leds.begin();
21+
nicla::leds.setColor(green);
22+
delay(200);
23+
nicla::leds.setColor(off);
24+
nicla::leds.end();
25+
}
26+
27+
void ledRedBlink() {
28+
while (1) {
29+
nicla::leds.begin();
30+
nicla::leds.setColor(red);
31+
delay(200);
32+
nicla::leds.setColor(off);
33+
delay(200);
34+
nicla::leds.end();
35+
}
36+
}
37+
38+
void setup() {
39+
40+
Serial.begin(115200);
41+
nicla::begin();
42+
nicla::disableLDO();
43+
nicla::leds.begin();
44+
45+
if (!BLE.begin()) {
46+
Serial.println("Starting BLE failed!");
47+
while (1);
48+
}
49+
50+
BLE.setLocalName("BLExaDemo");
51+
BLE.setAdvertisedService(alertService); // add the service UUID
52+
alertService.addCharacteristic(alertLevel); // add the alert level characteristic
53+
BLE.addService(alertService); // Add the alert service
54+
alertLevel.writeValue(0); // set initial value for this characteristic
55+
56+
NDP.onError(ledRedBlink);
57+
NDP.onMatch(alertViaBLE);
58+
NDP.onEvent(ledGreenOn);
59+
NDP.begin("mcu_fw_120_v90.synpkg");
60+
NDP.load("dsp_firmware_v90.synpkg");
61+
NDP.load("alexa_334_NDP120_B0_v11_v90.synpkg");
62+
NDP.turnOnMicrophone();
63+
NDP.interrupts();
64+
65+
// start advertising
66+
BLE.advertise();
67+
68+
// For maximum low power; please note that it's impossible to print afer calling these functions
69+
nicla::leds.end();
70+
if (lowestPower) {
71+
NRF_UART0->ENABLE = 0;
72+
}
73+
}
74+
75+
void loop() {
76+
BLEDevice central = BLE.central();
77+
if (central) {
78+
// serve the updates in the interrupt
79+
while (central.connected()) {
80+
// sleep and save power
81+
delay(1000);
82+
}
83+
} else {
84+
delay(1000);
85+
}
86+
}
+68Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Stream the microphone audio to serial port
3+
The file is compressed using G722 codec
4+
Prerequisite libraries:
5+
https://github.com/pschatzmann/arduino-libg722
6+
https://github.com/pschatzmann/arduino-audio-tools/
7+
8+
Precedure to extract audio:
9+
Setup the serial port as raw, for example with
10+
stty -F /dev/ttyACM0 115200 raw
11+
Dump the data
12+
cat /dev/ttyACM0 > test.g722
13+
Open Audacity
14+
audacity test.g722
15+
*/
16+
17+
#include "Arduino.h"
18+
#include "NDP.h"
19+
20+
#include "AudioTools.h"
21+
#include "AudioCodecs/CodecG722.h"
22+
23+
G722Encoder encoder;
24+
25+
uint8_t data[2048];
26+
27+
void ledGreenOn() {
28+
nicla::leds.begin();
29+
nicla::leds.setColor(green);
30+
delay(200);
31+
nicla::leds.setColor(off);
32+
nicla::leds.end();
33+
}
34+
35+
void setup() {
36+
37+
Serial.begin(115200);
38+
nicla::begin();
39+
nicla::disableLDO();
40+
nicla::leds.begin();
41+
42+
NDP.onEvent(ledGreenOn);
43+
44+
AudioBaseInfo bi;
45+
bi.channels = 1;
46+
bi.sample_rate = 16000;
47+
48+
encoder.setOptions(0);
49+
encoder.begin(bi);
50+
51+
encoder.setOutputStream(Serial);
52+
53+
NDP.begin("mcu_fw_120_v90.synpkg");
54+
NDP.load("dsp_firmware_v90.synpkg");
55+
NDP.load("alexa_334_NDP120_B0_v11_v90.synpkg");
56+
NDP.turnOnMicrophone();
57+
int chunk_size = NDP.getAudioChunkSize();
58+
if (chunk_size >= sizeof(data)) {
59+
for(;;);
60+
}
61+
}
62+
63+
void loop() {
64+
unsigned int len = 0;
65+
66+
NDP.extractData(data, &len);
67+
encoder.write(data, len);
68+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.