1212#define SERIAL_BAUD_RATE 115200 // USB serial baud rate
1313
1414// 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
1718
1819// lora module
1920
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
2728
2829// 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
3738
3839// 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
4142
4243#define LORA_RADIO_TASK_RX_BIT 0x01 // lora task rx bit command
4344#define LORA_RADIO_TASK_TX_BIT 0x02 // lora task tx bit command
4445
45- // lora task packet queues
46+ // lora task packet and packet index/size queues
4647CircularBuffer<uint8_t , LORA_RADIO_QUEUE_LEN> lora_radio_rx_queue_;
4748CircularBuffer<uint8_t , LORA_RADIO_QUEUE_LEN> lora_radio_rx_queue_index_;
4849CircularBuffer<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_;
5253byte lora_radio_rx_buf_[LORA_RADIO_BUF_LEN]; // tx packet buffer
5354byte lora_radio_tx_buf_[LORA_RADIO_BUF_LEN]; // rx packet buffer
5455
55- TaskHandle_t lora_task_; // lora rx/tx task
56+ TaskHandle_t lora_task_; // lora rx/tx task
5657volatile bool lora_enable_isr_ = true ; // true to enable rx isr, disabled on tx
5758SX1268 lora_radio_ = new Module(LORA_RADIO_PIN_SS, LORA_RADIO_PIN_A, LORA_RADIO_PIN_RST, LORA_RADIO_PIN_B);
5859
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)
6364
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
6869
6970// audio support
70- #define AUDIO_CODEC2_MODE CODEC2_MODE_450 // codec2 mode
71+ #define AUDIO_CODEC2_MODE CODEC2_MODE_450 // codec2 mode
7172#define AUDIO_SAMPLE_RATE 8000 // audio sample rate
7273#define AUDIO_MAX_PACKET_SIZE 48 // maximum packet size, multiple audio frames are inside
7374#define AUDIO_TASK_PLAY_BIT 0x01 // task bit flag to start playback
7475#define AUDIO_TASK_RECORD_BIT 0x02 // task bit flag to start recording
7576
7677// audio task
77- TaskHandle_t audio_task_; // / audio playback/record task
78+ TaskHandle_t audio_task_; // audio playback/record task
7879
7980// codec2
8081struct CODEC2 * c2_; // codec2 instance
@@ -83,12 +84,12 @@ int c2_bytes_per_frame_; // how many bytes in encoded frame
8384int16_t *c2_samples_; // buffer for raw samples
8485uint8_t *c2_bits_; // buffer for encoded frame
8586
86- // deep sleep
87+ // light sleep
8788#define LIGHT_SLEEP_DELAY_MS 5000 // how long to wait before engering light sleep
8889#define LIGHT_SLEEP_BITMASK (uint64_t )(1 << LORA_RADIO_PIN_A) | (1 << LORA_RADIO_PIN_B) // bit mask for ext1 high pin wake up
8990
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
9293
9394void setup () {
9495 // setup logging
@@ -108,7 +109,13 @@ void setup() {
108109 lora_radio_.setCRC (LORA_RADIO_CRC);
109110 lora_radio_.setRfSwitchPins (LORA_RADIO_PIN_RXEN, LORA_RADIO_PIN_TXEN);
110111 lora_radio_.clearDio1Action ();
112+ #ifdef LORA_RADIO_EXPL
113+ LOG_INFO (" Using explicit header" );
111114 lora_radio_.explicitHeader ();
115+ #else
116+ LOG_INFO (" Using implicit header" );
117+ lora_radio_.implicitHeader ();
118+ #endif
112119 lora_radio_.setDio1Action (onLoraDataAvailableIsr);
113120 } else {
114121 LOG_ERROR (" Lora radio start failed:" , lora_radio_state);
@@ -210,6 +217,7 @@ void light_sleep_reset() {
210217bool light_sleep (void *param) {
211218#ifdef ENABLE_LIGHT_SLEEP
212219 LOG_INFO (" Entering light sleep" );
220+ // wake up on ptt button or lora radio incoming data
213221 esp_sleep_enable_ext0_wakeup (GPIO_NUM_39, 0 );
214222 esp_sleep_enable_ext1_wakeup (LIGHT_SLEEP_BITMASK, ESP_EXT1_WAKEUP_ANY_HIGH);
215223 delay (100 );
@@ -370,7 +378,7 @@ void audio_task(void *param) {
370378}
371379
372380void loop () {
373- // button
381+ // handle PTT button
374382 if (digitalRead (PTTBTN_PIN) == LOW && !btn_pressed_) {
375383 LOG_DEBUG (" PTT pushed, start TX" );
376384 btn_pressed_ = true ;
0 commit comments