1
1
#include " PDM.h"
2
+ #include " USBSerial.h"
3
+ #include " USBAudio.h"
2
4
3
- // mbed::DigitalOut led((PinName)40);
5
+ // After defining USE_USB_AUDIO the board will behave as an USB sound card
6
+ // You will, however, lose the chance to retrigger the bootloader via CDC Serial.
7
+ // To program a new sketch, double click the RESET button and wait for the serial port to be enumerated again.
8
+ // If USE_USB_AUDIO is not defined the stream will be sent via CDC Serial
4
9
5
- // Temporary patch to get unbuffered writes
6
- mbed::UARTSerial serial (SERIAL1_TX, SERIAL1_RX, 1000000 );
10
+ #ifdef USE_USB_AUDIO
11
+ USBAudio audio (true , 16000 , 1 , 16000 , 1 );
12
+ #endif
7
13
8
- const int led = 40 ;
14
+ const int led = 41 ;
9
15
int led_status = HIGH;
10
16
11
- #if 0
12
- /*
13
- This snippet allows to redirect stdout/stderr on a Stream at your choice
14
- Attention: it must be in mbed namespace to override the weak core definition
15
- */
16
- namespace mbed {
17
- FileHandle *mbed_override_console(int fd) {
18
- return &serial;
19
- }
20
-
21
- FileHandle *mbed_target_override_console(int fd) {
22
- return &serial;
23
- }
24
- }
25
- #endif
26
-
27
17
uint8_t buffer[1024 ];
28
18
volatile int idx = 0 ;
29
19
@@ -43,7 +33,7 @@ void send(void* buf, size_t size) {
43
33
44
34
void setup () {
45
35
// Start the PDM as MONO @ 16KHz : gain @20
46
- // At this frequency you have 15ms in the callcack to use the returned buffer
36
+ // At this frequency you have 15ms in the callback to use the returned buffer
47
37
PDM.begin (1 , 16000 , 20 );
48
38
// The IRQ can call a naked function or one with buffer and size
49
39
PDM.onReceive (send);
@@ -54,7 +44,11 @@ void setup() {
54
44
55
45
void loop () {
56
46
if (idx == 1 ) {
57
- serial.write (buffer, DEFAULT_PDM_BUFFER_SIZE);
47
+ #ifdef USE_USB_AUDIO
48
+ audio.write (buffer, DEFAULT_PDM_BUFFER_SIZE);
49
+ #else
50
+ SerialUSB.send (buffer, DEFAULT_PDM_BUFFER_SIZE);
51
+ #endif
58
52
idx = 0 ;
59
53
}
60
54
}
0 commit comments