Skip to content

Commit

Permalink
CMakeLists.txt
Browse files Browse the repository at this point in the history
display.h
spi.cpp
spi.h
  • Loading branch information
meesokim committed Jan 30, 2023
1 parent 74a9f22 commit d6dd968
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.8)

project(fbcp-ili9341)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
Expand Down Expand Up @@ -227,6 +228,9 @@ elseif(KEDEI_V63_MPI3501)
if (USE_DMA_TRANSFERS)
message(FATAL_ERROR "DMA is unfortunately not possible with KeDei MPI3501. Please disable with -DUSE_DMA_TRANSFERS=OFF.")
endif()
elseif(KEDEI_TRASH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DKEDEI_TRASH")
message(STATUS "Targeting KeDei 3.5 inch SPI TFTLCD 480*320 16bit/18bit version 3.0 2015/4/9 display")
elseif(ILI9341)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DILI9341")
message(STATUS "Targeting ILI9341")
Expand Down Expand Up @@ -278,4 +282,4 @@ endif()

add_executable(fbcp-ili9341 ${sourceFiles})

target_link_libraries(fbcp-ili9341 pthread bcm_host atomic)
target_link_libraries(fbcp-ili9341 pthread bcm_host atomic bcm2835)
2 changes: 2 additions & 0 deletions display.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#if defined(ILI9341) || defined(ILI9340)
#include "ili9341.h"
#elif defined(KEDEI_TRASH)
#include "kedei_trash.h"
#elif defined(ILI9486L)
#include "ili9486l.h"
#elif defined(ILI9488)
Expand Down
26 changes: 22 additions & 4 deletions spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static uint32_t writeCounter = 0;
TOGGLE_CHIP_SELECT_LINE(); \
DEBUG_PRINT_WRITTEN_BYTE(w); \
} while(0)

int mem_fd = -1;
volatile void *bcm2835 = 0;
volatile GPIORegisterFile *gpio = 0;
Expand Down Expand Up @@ -322,7 +322,6 @@ void RunSPITask(SPITask *task)

SET_GPIO(GPIO_TFT_DATA_CONTROL);
#endif

// Send the data payload:
while(tStart < tPrefillEnd) WRITE_FIFO(*tStart++);
while(tStart < tEnd)
Expand All @@ -338,6 +337,11 @@ void RunSPITask(SPITask *task)
}
#else

#ifdef KEDEI_TRASH
extern void lcd_data8(uint8_t *data);
extern void lcd_cmd(uint8_t data);
#endif

void RunSPITask(SPITask *task)
{
WaitForPolledSPITransferToFinish();
Expand All @@ -355,6 +359,15 @@ void RunSPITask(SPITask *task)
const uint32_t payloadSize = tEnd - tStart;
uint8_t *tPrefillEnd = tStart + MIN(15, payloadSize);

#ifdef KEDEI_TRASH
lcd_cmd(task->cmd);
while(tStart < tEnd)
{
lcd_data8(tStart);
tStart += 2;
}
#else // not KEDEI_TRASH

// Send the command word if display is 4-wire (3-wire displays can omit this, commands are interleaved in the data payload stream above)
#ifndef SPI_3WIRE_PROTOCOL
// An SPI transfer to the display always starts with one control (command) byte, followed by N data bytes.
Expand All @@ -365,7 +378,6 @@ void RunSPITask(SPITask *task)
WRITE_FIFO(0x00);
#endif
WRITE_FIFO(task->cmd);

#ifdef DISPLAY_SPI_BUS_IS_16BITS_WIDE
while(!(spi->cs & (BCM2835_SPI0_CS_DONE))) /*nop*/;
spi->fifo;
Expand Down Expand Up @@ -393,7 +405,11 @@ void RunSPITask(SPITask *task)
else
#endif
{
while(tStart < tPrefillEnd) WRITE_FIFO(*tStart++);
while(tStart < tPrefillEnd)
{
WRITE_FIFO(*tStart++);

}
while(tStart < tEnd)
{
uint32_t cs = spi->cs;
Expand All @@ -402,10 +418,12 @@ void RunSPITask(SPITask *task)
if ((cs & (BCM2835_SPI0_CS_RXR|BCM2835_SPI0_CS_RXF))) spi->cs = BCM2835_SPI0_CS_CLEAR_RX | BCM2835_SPI0_CS_TA | DISPLAY_SPI_DRIVE_SETTINGS;
}
}
#endif // not KEDEI_TRASH

#ifdef DISPLAY_NEEDS_CHIP_SELECT_SIGNAL
END_SPI_COMMUNICATION();
#endif

}
#endif

Expand Down
3 changes: 2 additions & 1 deletion spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ typedef struct __attribute__((packed)) SPITask
#else
uint8_t cmd;
#endif
uint32_t dmaSpiHeader;
#ifdef OFFLOAD_PIXEL_COPY_TO_DMA_CPP
uint8_t *fb;
uint8_t *prevFb;
uint16_t width;
#endif
uint32_t dmaSpiHeader;
uint8_t data[]; // Contains both 8-bit and 9-bit tasks back to back, 8-bit first, then 9-bit.

#ifdef SPI_3WIRE_PROTOCOL
Expand All @@ -130,6 +130,7 @@ typedef struct __attribute__((packed)) SPITask
inline uint8_t *PayloadEnd() { return data + size; }
inline uint32_t PayloadSize() const { return size; }
inline uint32_t *DmaSpiHeaderAddress() { return &dmaSpiHeader; }
// inline uint32_t *DmaSpiHeaderAddress() { return 0; }
#endif

} SPITask;
Expand Down

0 comments on commit d6dd968

Please sign in to comment.