WIP sketch out init sequence
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS
|
SRCS
|
||||||
"gay-ipod-fw.cpp" "dac.cpp" "gpio-expander.cpp" "battery.cpp"
|
"gay-ipod-fw.cpp" "dac.cpp" "gpio-expander.cpp" "battery.cpp"
|
||||||
"storage.cpp" "i2c.cpp" "playback.cpp"
|
"storage.cpp" "i2c.cpp" "playback.cpp" "display.cpp"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES
|
REQUIRES
|
||||||
"esp_adc_cal" "fatfs" "audio_pipeline" "audio_stream" "result" "lvgl")
|
"esp_adc_cal" "fatfs" "audio_pipeline" "audio_stream" "result" "lvgl")
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#include "display.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
#include "hal/gpio_types.h"
|
||||||
|
#include "hal/spi_types.h"
|
||||||
|
|
||||||
|
namespace gay_ipod {
|
||||||
|
|
||||||
|
static const gpio_num_t kCommandOrDataPin = GPIO_NUM_21;
|
||||||
|
static const gpio_num_t kLedPin = GPIO_NUM_22;
|
||||||
|
|
||||||
|
static const uint8_t kDisplayWidth = 128;
|
||||||
|
static const uint8_t kDisplayHeight = 160;
|
||||||
|
|
||||||
|
auto Display::create(GpioExpander* expander)
|
||||||
|
-> cpp::result<std::unique_ptr<Display>, Error> {
|
||||||
|
// First, set up our GPIOs
|
||||||
|
#define SPI_QUADWP_IO (GPIO_NUM_22)
|
||||||
|
#define SPI_QUADHD_IO (GPIO_NUM_21)
|
||||||
|
gpio_config_t gpio_cfg = {
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pin_bit_mask = (1 << GPIO_OUTPUT_22) | (1 << GPIO_OUTPUT_21),
|
||||||
|
.pull_down_en = 0,
|
||||||
|
.pull_up_en = 0,
|
||||||
|
}
|
||||||
|
gpio_config(&gpio_cfg);
|
||||||
|
|
||||||
|
gpio_set_level(kLedPin, 1);
|
||||||
|
gpio_set_level(kCommandOrDataPin, 1);
|
||||||
|
|
||||||
|
// Next, init the SPI device
|
||||||
|
auto lock = expander->AcquireSpiBus(GpioExpander::DISPLAY);
|
||||||
|
spi_device_interface_config_t spi_cfg = {
|
||||||
|
.command_bits = 0, // Unused
|
||||||
|
.address_bits = 0, // Unused
|
||||||
|
.dummy_bits = 0,
|
||||||
|
.mode = 0,
|
||||||
|
.duty_cycle_pos = 0, // Unused
|
||||||
|
.cs_ena_pretrans = 0,
|
||||||
|
.cs_ena_posttrans = 0,
|
||||||
|
.clock_speed_hz = 32000000,
|
||||||
|
.input_delay_ns = 0,
|
||||||
|
.spics_io_num = -1,
|
||||||
|
.flags = 0,
|
||||||
|
.queue_size = 0,
|
||||||
|
.pre_cb = NULL,
|
||||||
|
.post_cb = NULL,
|
||||||
|
};
|
||||||
|
spi_device_handle_t handle;
|
||||||
|
spi_bus_add_device(VSPI_HOST, &spi_cfg, &handle);
|
||||||
|
|
||||||
|
// Now we reset the display into a known state, then configure it
|
||||||
|
// https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST77xx.cpp
|
||||||
|
// https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST7735.cpp
|
||||||
|
// commonInit with Rcmd1
|
||||||
|
// displayInit with Rcmd2green
|
||||||
|
// displayInit with Rcmd3
|
||||||
|
// setRotation
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace gay_ipod
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "gpio-expander.hpp"
|
||||||
|
|
||||||
|
namespace gay_ipod {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display driver for LVGL.
|
||||||
|
*/
|
||||||
|
class Display {
|
||||||
|
public:
|
||||||
|
enum Error {};
|
||||||
|
static auto create(GpioExpander* expander)
|
||||||
|
-> cpp::result<std::unique_ptr<Display>, Error>;
|
||||||
|
|
||||||
|
Display(GpioExpander *gpio);
|
||||||
|
~Display();
|
||||||
|
|
||||||
|
void WriteData();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GpioExpander *gpio_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gay_ipod
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "hal/gpio_types.h"
|
#include "hal/gpio_types.h"
|
||||||
#include "hal/spi_types.h"
|
#include "hal/spi_types.h"
|
||||||
|
#include "lvgl/lvgl.h"
|
||||||
|
|
||||||
#define I2C_SDA_IO (GPIO_NUM_2)
|
#define I2C_SDA_IO (GPIO_NUM_2)
|
||||||
#define I2C_SCL_IO (GPIO_NUM_4)
|
#define I2C_SCL_IO (GPIO_NUM_4)
|
||||||
@@ -63,8 +64,8 @@ esp_err_t init_spi(void) {
|
|||||||
.mosi_io_num = SPI_SDO_IO,
|
.mosi_io_num = SPI_SDO_IO,
|
||||||
.miso_io_num = SPI_SDI_IO,
|
.miso_io_num = SPI_SDI_IO,
|
||||||
.sclk_io_num = SPI_SCLK_IO,
|
.sclk_io_num = SPI_SCLK_IO,
|
||||||
.quadwp_io_num = SPI_QUADWP_IO,
|
.quadwp_io_num = -1, //SPI_QUADWP_IO,
|
||||||
.quadhd_io_num = SPI_QUADHD_IO,
|
.quadhd_io_num = -1, //SPI_QUADHD_IO,
|
||||||
|
|
||||||
// Unused
|
// Unused
|
||||||
.data4_io_num = -1,
|
.data4_io_num = -1,
|
||||||
@@ -125,11 +126,6 @@ extern "C" void app_main(void) {
|
|||||||
ESP_LOGI(TAG, "Everything looks good! Waiting a mo for debugger.");
|
ESP_LOGI(TAG, "Everything looks good! Waiting a mo for debugger.");
|
||||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
vTaskDelay(pdMS_TO_TICKS(1500));
|
||||||
|
|
||||||
playback->Play("/sdcard/test.mp3");
|
|
||||||
playback->set_volume(100);
|
|
||||||
|
|
||||||
playback->ProcessEvents();
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Time to deinit.");
|
ESP_LOGI(TAG, "Time to deinit.");
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Hooray!");
|
ESP_LOGI(TAG, "Hooray!");
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ bool GpioExpander::get_input(Pin pin) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GpioExpander::SpiLock GpioExpander::AcquireSpiBus(ChipSelect cs) {
|
GpioExpander::SpiLock GpioExpander::AcquireSpiBus(ChipSelect cs) {
|
||||||
|
// TODO: also spi_device_acquire_bus?
|
||||||
return SpiLock(*this, cs);
|
return SpiLock(*this, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user