12
12
#define SERIAL_BAUD_RATE 115200 // USB serial baud rate
13
13
14
14
// ptt button
15
- #define PTTBTN_PIN 39
16
- volatile bool btn_pressed_ = false ;
15
+ #define PTTBTN_PIN 39 // PTT button pin number
16
+ #define PTTBTN_GPIO_PIN GPIO_NUM_39 // PTT button light wake up GPIO pin
17
+ volatile bool btn_pressed_ = false ; // true when button is held
17
18
18
19
// lora module
19
20
20
- // lora module pinouts
21
- #define LORA_RADIO_PIN_SS SS
22
- #define LORA_RADIO_PIN_RST 27
23
- #define LORA_RADIO_PIN_A 12
24
- #define LORA_RADIO_PIN_B 14
25
- #define LORA_RADIO_PIN_RXEN 32
26
- #define LORA_RADIO_PIN_TXEN 33
21
+ // lora module pinouts (SX1268)
22
+ #define LORA_RADIO_PIN_SS SS // NSS pin
23
+ #define LORA_RADIO_PIN_RST 27 // NRST pin
24
+ #define LORA_RADIO_PIN_A 12 // BUSY pin
25
+ #define LORA_RADIO_PIN_B 14 // DIO1 pin
26
+ #define LORA_RADIO_PIN_RXEN 32 // RX enable pin
27
+ #define LORA_RADIO_PIN_TXEN 33 // TX enable pin
27
28
28
29
// lora modulation parameters
29
- #define LORA_RADIO_FREQ 433.775
30
- #define LORA_RADIO_BW 125.0
31
- #define LORA_RADIO_SF 9
32
- #define LORA_RADIO_CR 7
33
- #define LORA_RADIO_PWR 2
34
- #define LORA_RADIO_CRC 1
35
- #define LORA_RADIO_EXPL true
36
- #define LORA_RADIO_SYNC 0x34
30
+ #define LORA_RADIO_FREQ 433.775 // frequency (MHz)
31
+ #define LORA_RADIO_BW 125.0 // bandwidth (kHz)
32
+ #define LORA_RADIO_SF 9 // spreading factor
33
+ #define LORA_RADIO_CR 7 // coding rate
34
+ #define LORA_RADIO_PWR 2 // power in dbm (real is +10db if module has amplifier)
35
+ #define LORA_RADIO_CRC 1 // CRC bytes count
36
+ #define LORA_RADIO_EXPL true // comment out to use implicit mode (for spreading factor 6)
37
+ #define LORA_RADIO_SYNC 0x34 // sync word
37
38
38
39
// lora support config
39
- #define LORA_RADIO_BUF_LEN 256 // packet buffer size
40
- #define LORA_RADIO_QUEUE_LEN 512 // queue length
40
+ #define LORA_RADIO_BUF_LEN 256 // packets buffer size
41
+ #define LORA_RADIO_QUEUE_LEN 512 // queues length
41
42
42
43
#define LORA_RADIO_TASK_RX_BIT 0x01 // lora task rx bit command
43
44
#define LORA_RADIO_TASK_TX_BIT 0x02 // lora task tx bit command
44
45
45
- // lora task packet queues
46
+ // lora task packet and packet index/size queues
46
47
CircularBuffer<uint8_t , LORA_RADIO_QUEUE_LEN> lora_radio_rx_queue_;
47
48
CircularBuffer<uint8_t , LORA_RADIO_QUEUE_LEN> lora_radio_rx_queue_index_;
48
49
CircularBuffer<uint8_t , LORA_RADIO_QUEUE_LEN> lora_radio_tx_queue_;
@@ -52,29 +53,29 @@ CircularBuffer<uint8_t, LORA_RADIO_QUEUE_LEN> lora_radio_tx_queue_index_;
52
53
byte lora_radio_rx_buf_[LORA_RADIO_BUF_LEN]; // tx packet buffer
53
54
byte lora_radio_tx_buf_[LORA_RADIO_BUF_LEN]; // rx packet buffer
54
55
55
- TaskHandle_t lora_task_; // lora rx/tx task
56
+ TaskHandle_t lora_task_; // lora rx/tx task
56
57
volatile bool lora_enable_isr_ = true ; // true to enable rx isr, disabled on tx
57
58
SX1268 lora_radio_ = new Module(LORA_RADIO_PIN_SS, LORA_RADIO_PIN_A, LORA_RADIO_PIN_RST, LORA_RADIO_PIN_B);
58
59
59
- // audio speaker pinouts
60
- #define AUDIO_SPEAKER_BCLK 26
61
- #define AUDIO_SPEAKER_LRC 13
62
- #define AUDIO_SPEAKER_DIN 25
60
+ // audio speaker pinouts (MAX98357A)
61
+ #define AUDIO_SPEAKER_BCLK 26 // i2s clock (SLK)
62
+ #define AUDIO_SPEAKER_LRC 13 // i2s word select (WS)
63
+ #define AUDIO_SPEAKER_DIN 25 // i2s data (SD)
63
64
64
- // audio mic pinouts
65
- #define AUDIO_MIC_SD 2
66
- #define AUDIO_MIC_WS 15
67
- #define AUDIO_MIC_SCK 4
65
+ // audio mic pinouts (INMP441)
66
+ #define AUDIO_MIC_SD 2 // i2s data
67
+ #define AUDIO_MIC_WS 15 // i2s word select
68
+ #define AUDIO_MIC_SCK 4 // i2s clock
68
69
69
70
// audio support
70
- #define AUDIO_CODEC2_MODE CODEC2_MODE_450 // codec2 mode
71
+ #define AUDIO_CODEC2_MODE CODEC2_MODE_450 // codec2 mode
71
72
#define AUDIO_SAMPLE_RATE 8000 // audio sample rate
72
73
#define AUDIO_MAX_PACKET_SIZE 48 // maximum packet size, multiple audio frames are inside
73
74
#define AUDIO_TASK_PLAY_BIT 0x01 // task bit flag to start playback
74
75
#define AUDIO_TASK_RECORD_BIT 0x02 // task bit flag to start recording
75
76
76
77
// audio task
77
- TaskHandle_t audio_task_; // / audio playback/record task
78
+ TaskHandle_t audio_task_; // audio playback/record task
78
79
79
80
// codec2
80
81
struct CODEC2 * c2_; // codec2 instance
@@ -83,12 +84,12 @@ int c2_bytes_per_frame_; // how many bytes in encoded frame
83
84
int16_t *c2_samples_; // buffer for raw samples
84
85
uint8_t *c2_bits_; // buffer for encoded frame
85
86
86
- // deep sleep
87
+ // light sleep
87
88
#define LIGHT_SLEEP_DELAY_MS 5000 // how long to wait before engering light sleep
88
89
#define LIGHT_SLEEP_BITMASK (uint64_t )(1 << LORA_RADIO_PIN_A) | (1 << LORA_RADIO_PIN_B) // bit mask for ext1 high pin wake up
89
90
90
- Timer<1 > light_sleep_timer_; // light sleep timer
91
- uintptr_t light_sleep_timer_task_; // light sleep timer task
91
+ Timer<1 > light_sleep_timer_; // light sleep timer
92
+ Timer< 1 >::Task light_sleep_timer_task_; // light sleep timer task
92
93
93
94
void setup () {
94
95
// setup logging
@@ -108,7 +109,13 @@ void setup() {
108
109
lora_radio_.setCRC (LORA_RADIO_CRC);
109
110
lora_radio_.setRfSwitchPins (LORA_RADIO_PIN_RXEN, LORA_RADIO_PIN_TXEN);
110
111
lora_radio_.clearDio1Action ();
112
+ #ifdef LORA_RADIO_EXPL
113
+ LOG_INFO (" Using explicit header" );
111
114
lora_radio_.explicitHeader ();
115
+ #else
116
+ LOG_INFO (" Using implicit header" );
117
+ lora_radio_.implicitHeader ();
118
+ #endif
112
119
lora_radio_.setDio1Action (onLoraDataAvailableIsr);
113
120
} else {
114
121
LOG_ERROR (" Lora radio start failed:" , lora_radio_state);
@@ -210,6 +217,7 @@ void light_sleep_reset() {
210
217
bool light_sleep (void *param) {
211
218
#ifdef ENABLE_LIGHT_SLEEP
212
219
LOG_INFO (" Entering light sleep" );
220
+ // wake up on ptt button or lora radio incoming data
213
221
esp_sleep_enable_ext0_wakeup (GPIO_NUM_39, 0 );
214
222
esp_sleep_enable_ext1_wakeup (LIGHT_SLEEP_BITMASK, ESP_EXT1_WAKEUP_ANY_HIGH);
215
223
delay (100 );
@@ -370,7 +378,7 @@ void audio_task(void *param) {
370
378
}
371
379
372
380
void loop () {
373
- // button
381
+ // handle PTT button
374
382
if (digitalRead (PTTBTN_PIN) == LOW && !btn_pressed_) {
375
383
LOG_DEBUG (" PTT pushed, start TX" );
376
384
btn_pressed_ = true ;
0 commit comments