/* Blink Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "freertos/FreeRTOS.h"
#include <stdio.h>
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include "freertos/task.h"
#include "EPD_Test.h"
#include "EPD_4in2.h"
/* Can use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
or you can edit the following line and set a number here.
*/
#define BLINK_GPIO 16//0 is turn on,1 is turn off
//the list pins are controled by spi
//#define PIN_NUM_MISO 37
#define PIN_NUM_MOSI 13
#define PIN_NUM_CLK 14
#define PIN_NUM_CS 15
#define PIN_NUM_RST 2
#define PIN_NUM_BUSY 4
#define PIN_NUM_DC 12
esp_err_t ret;
spi_device_handle_t spi;
spi_transaction_t t;
void gpio_init(void){
/* Configure the IOMUX register for pad BLINK_GPIO (some pads are
muxed to GPIO on reset already, but some default to other
functions and need to be switched to GPIO. Consult the
Technical Reference for a list of pads and their default
functions.)
*/
gpio_pad_select_gpio(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
/*e-paper rest pin ,mode is output*/
gpio_pad_select_gpio(PIN_NUM_RST);
gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT);
/*e-paper data or command pin ,mode is output*/
gpio_pad_select_gpio(PIN_NUM_DC);
gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT);
/*e-paper busy pin ,mode is input*/
gpio_pad_select_gpio(PIN_NUM_BUSY);
gpio_set_direction(PIN_NUM_BUSY, GPIO_MODE_INPUT);
}
void spi_init(void){
spi_bus_config_t my_config={
.miso_io_num=-1,
.mosi_io_num=PIN_NUM_MOSI,
.sclk_io_num=PIN_NUM_CLK,
.quadwp_io_num=-1,
.quadhd_io_num=-1,
.max_transfer_sz=1000,
};
spi_device_interface_config_t my_device={
.flags=SPI_DEVICE_NO_DUMMY,
.input_delay_ns=10,
.command_bits=0,
.address_bits=0,
.clock_speed_hz=10*1000*1000,
.mode=0,
.spics_io_num=-1,
.queue_size=7,
};
ret=spi_bus_initialize(HSPI_HOST, &my_config, 0);
ESP_ERROR_CHECK(ret);
ret=spi_bus_add_device(HSPI_HOST, &my_device, &spi);
ESP_ERROR_CHECK(ret);
}
void app_main(void)
{
gpio_init();
spi_init();
printf("SPI gpio Init success!");
//DEV_Module_Init();
//EPD_4IN2_Init();
printf("EPD Init success!");
//EPD_4IN2_Clear();
EPD_4in2_test();
while(1) {
/* Blink off (output low) */
printf("Turning off the LED\n");
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
/* Blink on (output high) */
printf("Turning on the LED\n");
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(9000 / portTICK_PERIOD_MS);
}
}