Initial pico w port
This commit is contained in:
1 parent
50e59ce2a2
commit
ead5d48ce0
17 files changed
+184
-7818
No files matched your search
+47
-92
@@ -29,37 +29,30 @@
|
||||
******************************************************************************/
|
||||
#include "config.h"
|
||||
#include "DEV_Config.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include <string.h>
|
||||
|
||||
#define SPI_PORT SPI2_HOST
|
||||
#define SPI_PORT spi1
|
||||
|
||||
// /**
|
||||
// * GPIO
|
||||
// **/
|
||||
// int EPD_RST_PIN;
|
||||
// int EPD_DC_PIN;
|
||||
// int EPD_CS_PIN;
|
||||
// int EPD_BUSY_PIN;
|
||||
// int EPD_CLK_PIN;
|
||||
// int EPD_MOSI_PIN;
|
||||
|
||||
spi_device_handle_t spi_device;
|
||||
/**
|
||||
* GPIO
|
||||
**/
|
||||
int EPD_RST_PIN;
|
||||
int EPD_DC_PIN;
|
||||
int EPD_CS_PIN;
|
||||
int EPD_BUSY_PIN;
|
||||
int EPD_CLK_PIN;
|
||||
int EPD_MOSI_PIN;
|
||||
|
||||
/**
|
||||
* GPIO read and write
|
||||
**/
|
||||
void DEV_Digital_Write(UWORD Pin, UBYTE Value)
|
||||
{
|
||||
gpio_set_level(Pin, Value);
|
||||
gpio_put(Pin, Value);
|
||||
}
|
||||
|
||||
UBYTE DEV_Digital_Read(UWORD Pin)
|
||||
{
|
||||
return gpio_get_level(Pin);
|
||||
return gpio_get(Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,23 +60,12 @@ UBYTE DEV_Digital_Read(UWORD Pin)
|
||||
**/
|
||||
void DEV_SPI_WriteByte(uint8_t Value)
|
||||
{
|
||||
spi_transaction_t trans;
|
||||
memset(&trans, 0, sizeof(spi_transaction_t));
|
||||
trans.flags = SPI_TRANS_USE_TXDATA;
|
||||
trans.length = 8;
|
||||
trans.tx_data[0] = Value;
|
||||
spi_device_transmit(spi_device, &trans);
|
||||
spi_write_blocking(SPI_PORT, &Value, 1);
|
||||
}
|
||||
|
||||
void DEV_SPI_Write_nByte(uint8_t *pData, uint32_t Len)
|
||||
{
|
||||
if (Len == 0) return;
|
||||
|
||||
spi_transaction_t trans;
|
||||
memset(&trans, 0, sizeof(spi_transaction_t));
|
||||
trans.length = 8*Len;
|
||||
trans.tx_buffer = pData;
|
||||
spi_device_transmit(spi_device, &trans);
|
||||
spi_write_blocking(SPI_PORT, pData, Len);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,20 +73,12 @@ void DEV_SPI_Write_nByte(uint8_t *pData, uint32_t Len)
|
||||
**/
|
||||
void DEV_GPIO_Mode(UWORD Pin, UWORD Mode)
|
||||
{
|
||||
gpio_config_t io_conf = {
|
||||
.pin_bit_mask = (1ULL << Pin),
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE
|
||||
};
|
||||
|
||||
if(Mode == 0 || Mode == GPIO_MODE_INPUT) {
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
gpio_init(Pin);
|
||||
if(Mode == 0 || Mode == GPIO_IN) {
|
||||
gpio_set_dir(Pin, GPIO_IN);
|
||||
} else {
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_set_dir(Pin, GPIO_OUT);
|
||||
}
|
||||
gpio_config(&io_conf);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,19 +86,17 @@ void DEV_GPIO_Mode(UWORD Pin, UWORD Mode)
|
||||
**/
|
||||
void DEV_Delay_ms(UDOUBLE xms)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(xms));
|
||||
sleep_ms(xms);
|
||||
}
|
||||
|
||||
void DEV_GPIO_Init(void)
|
||||
{
|
||||
|
||||
// EPD_RST_PIN = 12;
|
||||
// EPD_DC_PIN = 8;
|
||||
// EPD_BUSY_PIN = 13;
|
||||
|
||||
// EPD_CS_PIN = 9;
|
||||
// EPD_CLK_PIN = 10;
|
||||
// EPD_MOSI_PIN = 11;
|
||||
EPD_RST_PIN = EPD_RST_GPIO;
|
||||
EPD_DC_PIN = EPD_DC_GPIO;
|
||||
EPD_BUSY_PIN = EPD_BUSY_GPIO;
|
||||
EPD_CS_PIN = EPD_CS_GPIO;
|
||||
EPD_CLK_PIN = EPD_CLK_GPIO;
|
||||
EPD_MOSI_PIN = EPD_MOSI_GPIO;
|
||||
|
||||
DEV_GPIO_Mode(EPD_RST_PIN, 1);
|
||||
DEV_GPIO_Mode(EPD_DC_PIN, 1);
|
||||
@@ -143,26 +115,9 @@ UBYTE DEV_Module_Init(void)
|
||||
// GPIO Config
|
||||
DEV_GPIO_Init();
|
||||
|
||||
spi_bus_config_t buscfg = {
|
||||
.mosi_io_num = SPI_MOSI,
|
||||
.miso_io_num = -1,
|
||||
.sclk_io_num = SPI_CLK,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
.max_transfer_sz = 4096
|
||||
};
|
||||
esp_err_t ret = spi_bus_initialize(SPI_PORT, &buscfg, 1);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
spi_device_interface_config_t devcfg = {
|
||||
.clock_speed_hz = 4000 * 1000,
|
||||
.mode = 0,
|
||||
.queue_size = 7,
|
||||
.spics_io_num = -1
|
||||
};
|
||||
// Attach the device configuration to the initialized bus
|
||||
ret = spi_bus_add_device(SPI_PORT, &devcfg, &spi_device);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
spi_init(SPI_PORT, 4000 * 1000);
|
||||
gpio_set_function(EPD_CLK_PIN, GPIO_FUNC_SPI);
|
||||
gpio_set_function(EPD_MOSI_PIN, GPIO_FUNC_SPI);
|
||||
|
||||
printf("DEV_Module_Init OK \r\n");
|
||||
return 0;
|
||||
@@ -170,55 +125,55 @@ UBYTE DEV_Module_Init(void)
|
||||
|
||||
void DEV_GPIO_Init_1(void)
|
||||
{
|
||||
//spi_deinit(SPI_PORT);
|
||||
//gpio_set_function(EPD_CLK_PIN, GPIO_FUNC_SPI);
|
||||
//gpio_set_function(EPD_MOSI_PIN, GPIO_FUNC_SPI);
|
||||
spi_deinit(SPI_PORT);
|
||||
gpio_set_function(EPD_CLK_PIN, GPIO_FUNC_SPI);
|
||||
gpio_set_function(EPD_MOSI_PIN, GPIO_FUNC_SPI);
|
||||
}
|
||||
|
||||
void DEV_SPI_Init(void)
|
||||
{
|
||||
//spi_init(SPI_PORT, 4000 * 1000);
|
||||
//gpio_set_function(EPD_CLK_PIN, GPIO_FUNC_SPI);
|
||||
//gpio_set_function(EPD_MOSI_PIN, GPIO_FUNC_SPI);
|
||||
spi_init(SPI_PORT, 4000 * 1000);
|
||||
gpio_set_function(EPD_CLK_PIN, GPIO_FUNC_SPI);
|
||||
gpio_set_function(EPD_MOSI_PIN, GPIO_FUNC_SPI);
|
||||
}
|
||||
|
||||
|
||||
void DEV_SPI_SendData(UBYTE Reg)
|
||||
{
|
||||
UBYTE i,j=Reg;
|
||||
DEV_GPIO_Mode(SPI_MOSI, 1);
|
||||
DEV_GPIO_Mode(SPI_CLK, 1);
|
||||
DEV_GPIO_Mode(EPD_MOSI_PIN, 1);
|
||||
DEV_GPIO_Mode(EPD_CLK_PIN, 1);
|
||||
DEV_Digital_Write(EPD_CS_PIN, 0);
|
||||
for(i = 0; i<8; i++)
|
||||
{
|
||||
DEV_Digital_Write(SPI_CLK, 0);
|
||||
DEV_Digital_Write(EPD_CLK_PIN, 0);
|
||||
if (j & 0x80)
|
||||
{
|
||||
DEV_Digital_Write(SPI_MOSI, 1);
|
||||
DEV_Digital_Write(EPD_MOSI_PIN, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEV_Digital_Write(SPI_MOSI, 0);
|
||||
DEV_Digital_Write(EPD_MOSI_PIN, 0);
|
||||
}
|
||||
|
||||
DEV_Digital_Write(SPI_CLK, 1);
|
||||
DEV_Digital_Write(EPD_CLK_PIN, 1);
|
||||
j = j << 1;
|
||||
}
|
||||
DEV_Digital_Write(SPI_CLK, 0);
|
||||
DEV_Digital_Write(EPD_CLK_PIN, 0);
|
||||
DEV_Digital_Write(EPD_CS_PIN, 1);
|
||||
}
|
||||
|
||||
UBYTE DEV_SPI_ReadData(void)
|
||||
{
|
||||
UBYTE i,j=0xff;
|
||||
DEV_GPIO_Mode(SPI_MOSI, 0);
|
||||
DEV_GPIO_Mode(SPI_CLK, 1);
|
||||
DEV_GPIO_Mode(EPD_MOSI_PIN, 0);
|
||||
DEV_GPIO_Mode(EPD_CLK_PIN, 1);
|
||||
DEV_Digital_Write(EPD_CS_PIN, 0);
|
||||
for(i = 0; i<8; i++)
|
||||
{
|
||||
DEV_Digital_Write(SPI_CLK, 0);
|
||||
DEV_Digital_Write(EPD_CLK_PIN, 0);
|
||||
j = j << 1;
|
||||
if (DEV_Digital_Read(SPI_MOSI))
|
||||
if (DEV_Digital_Read(EPD_MOSI_PIN))
|
||||
{
|
||||
j = j | 0x01;
|
||||
}
|
||||
@@ -226,9 +181,9 @@ UBYTE DEV_SPI_ReadData(void)
|
||||
{
|
||||
j= j & 0xfe;
|
||||
}
|
||||
DEV_Digital_Write(SPI_CLK, 1);
|
||||
DEV_Digital_Write(EPD_CLK_PIN, 1);
|
||||
}
|
||||
DEV_Digital_Write(SPI_CLK, 0);
|
||||
DEV_Digital_Write(EPD_CLK_PIN, 0);
|
||||
DEV_Digital_Write(EPD_CS_PIN, 1);
|
||||
return j;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@
|
||||
#ifndef _DEV_CONFIG_H_
|
||||
#define _DEV_CONFIG_H_
|
||||
|
||||
//#include "pico/stdlib.h"
|
||||
//#include "hardware/spi.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/spi.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/**
|
||||
@@ -62,12 +62,12 @@
|
||||
/**
|
||||
* GPIOI config
|
||||
**/
|
||||
// extern int EPD_RST_PIN;
|
||||
// extern int EPD_DC_PIN;
|
||||
// extern int EPD_CS_PIN;
|
||||
// extern int EPD_BUSY_PIN;
|
||||
// extern int EPD_CLK_PIN;
|
||||
// extern int EPD_MOSI_PIN;
|
||||
extern int EPD_RST_PIN;
|
||||
extern int EPD_DC_PIN;
|
||||
extern int EPD_CS_PIN;
|
||||
extern int EPD_BUSY_PIN;
|
||||
extern int EPD_CLK_PIN;
|
||||
extern int EPD_MOSI_PIN;
|
||||
|
||||
/*------------------------------------------------------------------------------------------------------*/
|
||||
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
|
||||
|
||||
+20
-22
@@ -29,10 +29,7 @@
|
||||
#
|
||||
******************************************************************************/
|
||||
#include "EPD_4in2_V2.h"
|
||||
#include "DEV_Config.h"
|
||||
#include "Debug.h"
|
||||
#include "config.h"
|
||||
#include <string.h>
|
||||
|
||||
const unsigned char LUT_ALL[233]={
|
||||
0x01, 0x0A, 0x1B, 0x0F, 0x03, 0x01, 0x01,
|
||||
@@ -111,26 +108,17 @@ static void EPD_4IN2_V2_SendData(UBYTE Data)
|
||||
DEV_Digital_Write(EPD_CS_PIN, 1);
|
||||
}
|
||||
|
||||
static void EPD_4IN2_V2_SendDataBuffer(UBYTE *Data, UWORD Length)
|
||||
{
|
||||
DEV_Digital_Write(EPD_DC_PIN, 1);
|
||||
DEV_Digital_Write(EPD_CS_PIN, 0);
|
||||
DEV_SPI_Write_nByte(Data, Length);
|
||||
DEV_Digital_Write(EPD_CS_PIN, 1);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
function : Wait until the busy_pin goes LOW
|
||||
parameter:
|
||||
******************************************************************************/
|
||||
void EPD_4IN2_V2_ReadBusy(void)
|
||||
{
|
||||
printf("Waiting for e-Paper BUSY (GPIO%d=%d)...\r\n",
|
||||
EPD_BUSY_PIN, DEV_Digital_Read(EPD_BUSY_PIN));
|
||||
Debug("e-Paper busy\r\n");
|
||||
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
|
||||
DEV_Delay_ms(10);
|
||||
}
|
||||
printf("e-Paper BUSY released.\r\n");
|
||||
Debug("e-Paper busy release\r\n");
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -342,19 +330,21 @@ parameter:
|
||||
void EPD_4IN2_V2_Clear(void)
|
||||
{
|
||||
UWORD Width, Height;
|
||||
UBYTE white_row[EPD_4IN2_V2_WIDTH / 8];
|
||||
Width = (EPD_4IN2_V2_WIDTH % 8 == 0)? (EPD_4IN2_V2_WIDTH / 8 ): (EPD_4IN2_V2_WIDTH / 8 + 1);
|
||||
Height = EPD_4IN2_V2_HEIGHT;
|
||||
memset(white_row, 0xFF, sizeof(white_row));
|
||||
|
||||
EPD_4IN2_V2_SendCommand(0x24);
|
||||
for (UWORD j = 0; j < Height; j++) {
|
||||
EPD_4IN2_V2_SendDataBuffer(white_row, Width);
|
||||
for (UWORD i = 0; i < Width; i++) {
|
||||
EPD_4IN2_V2_SendData(0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
EPD_4IN2_V2_SendCommand(0x26);
|
||||
for (UWORD j = 0; j < Height; j++) {
|
||||
EPD_4IN2_V2_SendDataBuffer(white_row, Width);
|
||||
for (UWORD i = 0; i < Width; i++) {
|
||||
EPD_4IN2_V2_SendData(0xFF);
|
||||
}
|
||||
}
|
||||
EPD_4IN2_V2_TurnOnDisplay();
|
||||
}
|
||||
@@ -371,12 +361,16 @@ void EPD_4IN2_V2_Display(UBYTE *Image)
|
||||
|
||||
EPD_4IN2_V2_SendCommand(0x24);
|
||||
for (UWORD j = 0; j < Height; j++) {
|
||||
EPD_4IN2_V2_SendDataBuffer(&Image[j * Width], Width);
|
||||
for (UWORD i = 0; i < Width; i++) {
|
||||
EPD_4IN2_V2_SendData(Image[i + j * Width]);
|
||||
}
|
||||
}
|
||||
|
||||
EPD_4IN2_V2_SendCommand(0x26);
|
||||
for (UWORD j = 0; j < Height; j++) {
|
||||
EPD_4IN2_V2_SendDataBuffer(&Image[j * Width], Width);
|
||||
for (UWORD i = 0; i < Width; i++) {
|
||||
EPD_4IN2_V2_SendData(Image[i + j * Width]);
|
||||
}
|
||||
}
|
||||
EPD_4IN2_V2_TurnOnDisplay();
|
||||
}
|
||||
@@ -393,12 +387,16 @@ void EPD_4IN2_V2_Display_Fast(UBYTE *Image)
|
||||
|
||||
EPD_4IN2_V2_SendCommand(0x24);
|
||||
for (UWORD j = 0; j < Height; j++) {
|
||||
EPD_4IN2_V2_SendDataBuffer(&Image[j * Width], Width);
|
||||
for (UWORD i = 0; i < Width; i++) {
|
||||
EPD_4IN2_V2_SendData(Image[i + j * Width]);
|
||||
}
|
||||
}
|
||||
|
||||
EPD_4IN2_V2_SendCommand(0x26);
|
||||
for (UWORD j = 0; j < Height; j++) {
|
||||
EPD_4IN2_V2_SendDataBuffer(&Image[j * Width], Width);
|
||||
for (UWORD i = 0; i < Width; i++) {
|
||||
EPD_4IN2_V2_SendData(Image[i + j * Width]);
|
||||
}
|
||||
}
|
||||
EPD_4IN2_V2_TurnOnDisplay_Fast();
|
||||
}
|
||||
|
||||
@@ -31,11 +31,7 @@
|
||||
#ifndef _EPD_4IN2_V2_H_
|
||||
#define _EPD_4IN2_V2_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define UBYTE uint8_t
|
||||
#define UWORD uint16_t
|
||||
#define UDOUBLE uint32_t
|
||||
#include "DEV_Config.h"
|
||||
|
||||
// Display resolution
|
||||
#define EPD_4IN2_V2_WIDTH 400
|
||||
|
||||
Reference in new issue
Block a user