Compare commits

...

5 Commits

2 changed files with 75 additions and 15 deletions

View File

@ -1,9 +1,48 @@
this is a template firmware for [ESP32-S2](https://www.espressif.com/en/products/socs/esp32-s2)-based micro-controller projects.
this project is about interfacing the GM-1352 sound level meter using an ESP32-S2-based board, so to read the sound level measurements digitally.
GM-1352
=======
the GM-1352 is the successor of the GM-1351, and very similar to it.
the main difference is that the power is not delivered by a 9V battery, but by 3x1.5V AA batteries.
[CuVoodoo #030](https://www.cuvoodoo.info/cuvoodoo-030-audio-is-killing-the-music/) already explained how to interface it.
basically just tap on the lines between the MCU (a EFM8BB10F8G-QFN20) and LCD controller (a Chip-on-Board under a blob of epoxy).
there are test points available for that:
- CS: chip select, to start data communication
- DATA: the actual data bits
- WR: the data clock (not periodic)
there are additional test points to read (or assert) button presses:
- 1: HOLD button (press low)
- 2: MIN/MAX button (press low)
- 3: POWER button (press low)
there is another test point marked S, but I don't know what this is for.
also note that the LCD has segments for Bluetooth and USB.
there might be variants of the GM-1352 with these options.
board
=====
the board used is a [WEMOS](https://www.wemos.cc/en/latest/index.html) [S2 mini](https://www.wemos.cc/en/latest/s2/s2_mini.html).
this repository is the firmware for [ESP32-S2](https://www.espressif.com/en/products/socs/esp32-s2)-based [WEMOS](https://www.wemos.cc/en/latest/index.html) [S2 mini](https://www.wemos.cc/en/latest/s2/s2_mini.html) board.
connect the GM-1352 to the S2 mini as follows:
- B+ to 5V: to power or get power from the device
- B- to GND: ground reference
- POWER to 16: to wake up the S2 when the device is powered (the S2 will shut down shortly after the GM-1352)
- DATA to 18: this will be the SPI MOSI line to read the measurments
- CS to 33: this will be the SPI CS line to identify transactions
- WR to 35: this will be the SPI SCK line to clock the data bits (not periodic)
I soldered wires to the pads, and broke them out on a 8-pin female header, located above the battery compartment.
this also to easily connect on row of the S2 mini to it on the back of the GM-1352.
now you can power the sound level meter through the S2 mini USB port, and read the measurements over its serial CDC ACM interface.
compile and flash
=================

View File

@ -3,9 +3,11 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/reent.h>
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_sleep.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -28,19 +30,14 @@
// GPIO for on-board LED (WEMOS S2 mini, source on)
#define LED_BOARD 15
/* GM1352 test pads:
* - CS: LCD chip select, to start data communication
* - DATA: LCD data bits
* - WR: LCD data clock (not periodic)
* - S: ??? (low)
* - 1: HOLD button (press low)
* - 2: MIN/MAX button (press low)
* - 3: POWER button (press low)
*/
#define GPIO_POWER (35U)
#define GPIO_MOSI (16U)
#define GPIO_SCLK (33U)
#define GPIO_CS (18U)
// connect GPIO to test pad 3
#define GPIO_POWER (16U)
// connect GPIO to test pad DATA
#define GPIO_MOSI (18U)
// connect GPIO to test pad WR
#define GPIO_SCLK (35U)
// connect GPIO to test pad CS
#define GPIO_CS (33U)
static const char *TAG = "main";
@ -283,6 +280,16 @@ void app_main(void)
ESP_ERROR_CHECK( tusb_dfu_rf_init() ); // configure DFU runtime (ensures we can use it)
ESP_LOGI(TAG, "USB initialized");
// configure shutdown
io_conf.pin_bit_mask = (1ULL << GPIO_POWER); // GPIO to configure
io_conf.intr_type = GPIO_INTR_DISABLE; // disable interrupt
io_conf.mode = GPIO_MODE_INPUT; // set as input
io_conf.pull_down_en = 0; // don't use pull-down
io_conf.pull_up_en = 0; // there is already an external pull-up
ESP_ERROR_CHECK( gpio_config(&io_conf) ); // configure GPIO
ESP_ERROR_CHECK( esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL) ); // make sure all sources are disabled
ESP_ERROR_CHECK( esp_sleep_enable_ext0_wakeup(GPIO_POWER, 0) ); // use power button to wake up (low when pressed)
// task to decode and show the measurements
meas_queue = xQueueCreate(MEAS_QUEUE_SIZE, sizeof(spi_slave_transaction_t));
ESP_ERROR_CHECK( NULL == meas_queue );
@ -323,5 +330,19 @@ void app_main(void)
} else {
gpio_set_level(LED_BOARD, 1);
}
if (timeout > 0) {
printf(".");
fflush(stdout);
fsync(fileno(stdout));
}
timeout++;
if (timeout > 10) {
printf("\nshutting down due to inactivity\n");
fflush(stdout);
fsync(fileno(stdout));
gpio_set_level(LED_BOARD, 1); // ensure run LED is off
esp_deep_sleep_start(); // go to deep sleep
}
}
}