Skip to content

Commit 48bf296

Browse files
committed
Merge branch 'master' into feature/pr
2 parents 9c08a7a + 8f043cb commit 48bf296

File tree

9 files changed

+86
-66
lines changed

9 files changed

+86
-66
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Recent changes to the [Chirp Arduino SDK](https://developers.chirp.io/docs).
44

5-
## v3.3.0 (beta)
5+
## v3.3.0 (09/08/2019)
66

7-
- Added send-only support for cortex-m0plus (MKRZero, MKR Vidor 4000)
87
- Added support for cortex-m4 (Nano 33 Sense)
8+
- Added send-only support for cortex-m0plus (MKRZero, MKR Vidor 4000)
99
- Build v3.3.0-rc1
1010

1111
## v3.2.0 (14/03/2019)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ and you can include the headers to use Chirp in your own code by adding:
5959
To set up the Chirp SDK, initialise and configure with your app key,
6060
secret and config from the [Developer Hub](https://developers.chirp.io).
6161

62-
*Note* You must select the `arduino` protocol from the dropdown menu, when
62+
*Note* You must select the `16khz-mono-embedded` protocol from the dropdown menu, when
6363
selecting your chirp configuration.
6464

6565
chirp = new_chirp_connect(APP_KEY, APP_SECRET);

examples/ESP32Receive/ESP32Receive.ino

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
@file ESP32Receive.ino
77
88
@brief Create a developer account at https://developers.chirp.io,
9-
and copy and paste your key, secret and config string for the "16khz-mono"
10-
protocol into the credentials.h file.
9+
and copy and paste your key, secret and config string for the
10+
"16khz-mono-embedded" protocol into the credentials.h file.
1111
1212
This example will start listening for chirps and print to the terminal
1313
when anything is received.
@@ -45,11 +45,13 @@
4545
#define CONVERT_INPUT(sample) (((int32_t)(sample) >> 14) + MIC_CALIBRATION)
4646

4747
// Global variables ------------------------------------------------------------
48+
4849
static chirp_connect_t *chirp = NULL;
4950
static chirp_connect_state_t currentState = CHIRP_CONNECT_STATE_NOT_CREATED;
5051
static bool startTasks = false;
5152

5253
// Function definitions --------------------------------------------------------
54+
5355
void setupChirp();
5456
void chirpErrorHandler(chirp_connect_error_code_t code);
5557
void setupAudioInput(int sample_rate);
@@ -145,10 +147,11 @@ onReceivedCallback(void *chirp, uint8_t *payload, size_t length, uint8_t channel
145147
{
146148
if (payload)
147149
{
148-
char *data = chirp_connect_as_string((chirp_connect_t *)chirp, payload, length);
149-
Serial.printf("data = %s\n", data);
150-
digitalWrite(LED_PIN, LOW);
151-
chirp_connect_free(data);
150+
char *data = (char *)calloc(length + 1, sizeof(uint8_t));
151+
memcpy(data, payload, length * sizeof(uint8_t));
152+
Serial.print("Received data: ");
153+
Serial.println(data);
154+
free(data);
152155
}
153156
else
154157
{

examples/ESP32Send/ESP32Send.ino

+14-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
@file ESP32Send.ino
77
88
@brief Create a developer account at https://developers.chirp.io,
9-
and copy and paste your key, secret and config string for the "arduino"
10-
protocol into the credentials.h file.
9+
and copy and paste your key, secret and config string for the
10+
"16khz-mono-embedded" protocol into the credentials.h file.
1111
1212
When the EN switch is pressed on the board, a random chirp will be sent to
1313
the audio output.
@@ -31,16 +31,19 @@
3131
#define LED_PIN 2 // Pin number for on-board LED
3232
#define SWITCH_PIN 0 // Pin number for on-board switch
3333

34-
#define BUFFER_SIZE 512 // Audio buffer size
35-
#define SAMPLE_RATE 16000 // Audio sample rate
34+
#define VOLUME 0.5 // Between 0 and 1
35+
#define BUFFER_SIZE 512
36+
#define SAMPLE_RATE 16000
3637

3738
// Global variables ------------------------------------------------------------
39+
3840
static chirp_connect_t *chirp = NULL;
3941
static chirp_connect_state_t currentState = CHIRP_CONNECT_STATE_NOT_CREATED;
4042
static volatile bool buttonPressed = false;
4143
static bool startTasks = false;
4244

4345
// Function definitions --------------------------------------------------------
46+
4447
void IRAM_ATTR handleInterrupt();
4548
void setupChirp();
4649
void chirpErrorHandler(chirp_connect_error_code_t code);
@@ -76,12 +79,12 @@ loop()
7679

7780
if (buttonPressed)
7881
{
79-
size_t payloadLength = 0;
80-
uint8_t *payload = chirp_connect_random_payload(chirp, &payloadLength);
81-
chirp_connect_send(chirp, payload, payloadLength);
82-
Serial.println("Sending data...");
82+
char *payload = "hello";
83+
chirpError = chirp_connect_send(chirp, (uint8_t *)payload, strlen(payload));
84+
chirpErrorHandler(chirpError);
85+
Serial.print("Sending data: ");
86+
Serial.println(payload);
8387
buttonPressed = false;
84-
chirp_connect_free(payload);
8588
}
8689
}
8790

@@ -182,8 +185,8 @@ setupChirp()
182185
err = chirp_connect_start(chirp);
183186
chirpErrorHandler(err);
184187

185-
// Set volume to 0.5 to not distort output
186-
chirp_connect_set_volume(chirp, 0.5);
188+
err = chirp_connect_set_volume(chirp, VOLUME);
189+
chirpErrorHandler(err);
187190

188191
Serial.println("Chirp SDK initialised.");
189192
}

examples/MKRZeroSend/MKRZeroSend.ino

+35-26
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
@file MKRZeroSend.ino
77
88
@brief Create a developer account at https://developers.chirp.io,
9-
and copy and paste your key, secret and config string for chosen
10-
protocol into the credentials.h file.
9+
and copy and paste your key, secret and config string for the
10+
"16khz-mono-embedded" protocol into the credentials.h file.
1111
1212
This example will start sending a random chirp payload on start up.
1313
@@ -19,6 +19,9 @@
1919
*Note*: This board is send-only as it does not have a floating-point unit
2020
which is required to receive data.
2121
22+
*Important*: The example will not start until this Serial Monitor is opened.
23+
To disable this behaviour, comment out the while(!Serial) line.
24+
2225
Circuit:
2326
- Arduino MKRZero
2427
- Adafruit UDA1334
@@ -39,18 +42,17 @@
3942
#include "chirp_connect.h"
4043
#include "credentials.h"
4144

42-
#define VOLUME 0.1
45+
#define VOLUME 0.1 // Between 0 and 1
4346

4447
#define NUM_BUFFERS 2
45-
#define BUFFER_SIZE 512
48+
#define BUFFER_SIZE 1024
4649
#define SAMPLE_RATE 44100
4750

48-
// Global variables -------------------------------------------
51+
// Global variables ------------------------------------------------------------
4952

5053
int buffer[NUM_BUFFERS][BUFFER_SIZE];
5154
short tmpBuffer[BUFFER_SIZE / 2];
5255
uint8_t nextBufferIndex, currentBufferIndex;
53-
uint16_t volumeInt;
5456

5557
Adafruit_ZeroI2S i2s;
5658
Adafruit_ZeroDMA dma;
@@ -59,19 +61,19 @@ DmacDescriptor *desc;
5961
static chirp_connect_t *chirp = NULL;
6062
static volatile bool dma_complete = true;
6163

62-
// Function definitions ---------------------------------------
64+
// Function definitions --------------------------------------------------------
6365

6466
void dmaCallback(Adafruit_ZeroDMA *dma);
6567
void dmaErrorCallback(Adafruit_ZeroDMA *dma);
6668
void setupDMA(void);
6769
void setupChirp(void);
70+
void sendChirp(void);
6871

69-
// Function declarations --------------------------------------
72+
// Function declarations -------------------------------------------------------
7073

7174
void setup()
7275
{
7376
currentBufferIndex = 0;
74-
volumeInt = VOLUME * INT16_MAX;
7577

7678
Serial.begin(115200);
7779
while(!Serial); // Wait for Serial monitor before continuing
@@ -83,16 +85,7 @@ void setup()
8385
i2s.enableMCLK();
8486
i2s.enableTx();
8587

86-
size_t payload_len = 5;
87-
uint8_t *payload = chirp_connect_random_payload(chirp, &payload_len);
88-
89-
char *hex = chirp_connect_as_string(chirp, payload, payload_len);
90-
Serial.print("Generated payload: ");
91-
Serial.println(hex);
92-
chirp_connect_free(hex);
93-
94-
chirp_connect_error_code_t err = chirp_connect_send(chirp, payload, payload_len);
95-
chirpErrorHandler(err);
88+
sendChirp();
9689

9790
ZeroDMAstatus stat = dma.startJob();
9891
if (stat != DMA_STATUS_OK)
@@ -113,17 +106,18 @@ void loop()
113106
chirpErrorHandler(err);
114107

115108
// Copy the data into a stereo buffer for audio output
116-
for (int i = 0; i < BUFFER_SIZE / 2; i++) {
117-
int value = tmpBuffer[i] * volumeInt;
118-
buffer[nextBufferIndex][i * 2] = value;
119-
buffer[nextBufferIndex][i * 2 + 1] = value;
109+
for (int i = 0; i < BUFFER_SIZE / 2; i++)
110+
{
111+
int value = tmpBuffer[i] * INT16_MAX;
112+
buffer[next][i * 2] = value;
113+
buffer[next][i * 2 + 1] = value;
120114
}
121115

122116
dma_complete = false;
123117
}
124118
}
125119

126-
// Chirp -----------------------------------------------------
120+
// Chirp -----------------------------------------------------------------------
127121

128122
void chirpErrorHandler(chirp_connect_error_code_t code)
129123
{
@@ -145,7 +139,19 @@ void onSentCallback(void *chirp, uint8_t *payload, size_t length, uint8_t channe
145139
Serial.println("Sent data...");
146140
}
147141

148-
void setupChirp(void)
142+
void sendChirp()
143+
{
144+
chirp_connect_error_code_t err;
145+
146+
char *payload = "hello";
147+
err = chirp_connect_send(chirp, (uint8_t *)payload, strlen(payload));
148+
chirpErrorHandler(err);
149+
150+
Serial.print("Sending data: ");
151+
Serial.println(payload);
152+
}
153+
154+
void setupChirp()
149155
{
150156
chirp = new_chirp_connect(CHIRP_APP_KEY, CHIRP_APP_SECRET);
151157
if (chirp == NULL)
@@ -171,14 +177,17 @@ void setupChirp(void)
171177
err = chirp_connect_set_output_sample_rate(chirp, SAMPLE_RATE);
172178
chirpErrorHandler(err);
173179

180+
err = chirp_connect_set_volume(chirp, VOLUME);
181+
chirpErrorHandler(err);
182+
174183
err = chirp_connect_start(chirp);
175184
chirpErrorHandler(err);
176185

177186
Serial.println("Chirp SDK initialised.");
178187
Serial.flush();
179188
}
180189

181-
// I2S DMA ---------------------------------------------------
190+
// I2S DMA ---------------------------------------------------------------------
182191

183192
void dmaCallback(Adafruit_ZeroDMA *dma)
184193
{

examples/MXChipSendReceive/MXChipSendReceive.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file MXChipSendReceive.ino
66
*
77
* @brief After creating a developer account on https://developers.chirp.io, get
8-
* your key, secret and config string from your account using the "16kHz-mono"
8+
* your key, secret and config string from your account using the "16kHz-mono-embedded"
99
* protocol, and set them in this file (in CHIRP_APP_KEY, CHIRP_APP_SECRET, CHIRP_APP_CONFIG).
1010
*
1111
* This example will start in listening mode. The listening and playing modes

examples/Nano33SenseReceive/Nano33SenseReceive.ino

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
@file Nano33SenseReceive.ino
77
88
@brief Create a developer account at https://developers.chirp.io,
9-
and copy and paste your key, secret and config string for the "arduino"
10-
protocol into the credentials.h file.
9+
and copy and paste your key, secret and config string for the
10+
"16khz-mono-embedded" protocol into the credentials.h file.
1111
1212
This example will start listening for chirps and print to the terminal
1313
when anything is received.
1414
15-
Note: this example can be used in conjunction with the send example,
15+
*Note*: this example can be used in conjunction with the send example,
1616
to send and receive data in the same application.
1717
18+
*Important*: The example will not start until this Serial Monitor is opened.
19+
To disable this behaviour, comment out the while(!Serial) line.
20+
1821
Circuit:
1922
- Arduino Nano 33 BLE board
2023

examples/Nano33SenseSend/Nano33SenseSend.ino

+17-15
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
@file Nano33SenseSend.ino
77
88
@brief Create a developer account at https://developers.chirp.io,
9-
and copy and paste your key, secret and config string for the "arduino"
10-
protocol into the credentials.h file.
9+
and copy and paste your key, secret and config string for the
10+
"16khz-mono-embedded" protocol into the credentials.h file.
1111
1212
This example will send a single Chirp signal on startup, containing random
1313
data.
1414
15+
*Important*: The example will not start until this Serial Monitor is opened.
16+
To disable this behaviour, comment out the while(!Serial) line.
17+
1518
Circuit:
1619
- Arduino Nano 33 BLE board
1720
- Adafruit MAX98357A amplifier
@@ -24,11 +27,12 @@
2427
#include "chirp_connect.h"
2528
#include "credentials.h"
2629

30+
#define VOLUME 0.3 // Between 0 and 1
2731
#define BUFFER_SIZE 256
2832
#define OUTPUT_SAMPLE_RATE 16667
2933

30-
#define I2S_SCK_PIN 23 // D7
31-
#define I2S_DATA_PIN 21 // D8
34+
#define I2S_DATA_PIN 23 // D7
35+
#define I2S_SCK_PIN 21 // D8
3236
#define I2S_LRCK_PIN 27 // D9
3337

3438
// Global variables ------------------------------------------------------------
@@ -42,6 +46,7 @@ short buffer2[BUFFER_SIZE];
4246

4347
void chirpErrorHandler(chirp_connect_error_code_t code);
4448
void setupChirp(void);
49+
void sendChirp(void);
4550
void i2s_init(void);
4651
void i2s_start(void);
4752

@@ -53,7 +58,7 @@ void setup()
5358
while(!Serial); // Wait for Serial monitor before continuing
5459

5560
setupChirp();
56-
sendRandomChirp();
61+
sendChirp();
5762

5863
i2s_init();
5964
i2s_start();
@@ -123,7 +128,7 @@ void setupChirp(void)
123128
err = chirp_connect_set_output_sample_rate(chirp, OUTPUT_SAMPLE_RATE);
124129
chirpErrorHandler(err);
125130

126-
err = chirp_connect_set_volume(chirp, 0.5);
131+
err = chirp_connect_set_volume(chirp, VOLUME);
127132
chirpErrorHandler(err);
128133

129134
err = chirp_connect_start(chirp);
@@ -133,19 +138,16 @@ void setupChirp(void)
133138
Serial.flush();
134139
}
135140

136-
void sendRandomChirp()
141+
void sendChirp()
137142
{
138-
size_t payload_len = 5;
139-
uint8_t *payload = chirp_connect_random_payload(chirp, &payload_len);
140-
141-
char *hex = chirp_connect_as_string(chirp, payload, payload_len);
142-
Serial.print("Generated payload: ");
143-
Serial.println(hex);
143+
chirp_connect_error_code_t err;
144144

145-
chirp_connect_error_code_t err = chirp_connect_send(chirp, payload, payload_len);
145+
char *payload = "hello";
146+
err = chirp_connect_send(chirp, (uint8_t *)payload, strlen(payload));
146147
chirpErrorHandler(err);
147148

148-
chirp_connect_free(payload);
149+
Serial.print("Sending data: ");
150+
Serial.println(payload);
149151
}
150152

151153
// I2S Audio -------------------------------------------------------------------

keywords.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ chirp_connect_get_output_sample_rate KEYWORD2
3838
chirp_connect_set_input_sample_rate KEYWORD2
3939
chirp_connect_set_output_sample_rate KEYWORD2
4040
chirp_connect_get_auto_mute KEYWORD2
41-
chirp_connect_set_auto_mute KEYWORD2
41+
chirp_connect_set_listen_to_self KEYWORD2
4242
chirp_connect_set_callback_ptr KEYWORD2
4343
chirp_connect_set_frequency_correction KEYWORD2
4444
chirp_connect_get_version KEYWORD2

0 commit comments

Comments
 (0)