mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Change Font size (more readable)
Rework display spi driver: use DMA for read, write add blitBitmap functions Use DMA for color fill More correct SPI bus control Move color definitions to nanovna.h Some code optimization for speed and size (save about 3k bytes) Change grid Y resolution to 10 Fix convert from float to int (fix some rounding errors on plot) Disable unused HAL serial Change battery icon
This commit is contained in:
parent
18a1ca4e6e
commit
6f666cf31b
|
|
@ -132,7 +132,7 @@
|
||||||
* @brief Enables the SERIAL subsystem.
|
* @brief Enables the SERIAL subsystem.
|
||||||
*/
|
*/
|
||||||
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
|
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
|
||||||
#define HAL_USE_SERIAL TRUE
|
#define HAL_USE_SERIAL FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
804
ili9341.c
804
ili9341.c
|
|
@ -21,6 +21,119 @@
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "nanovna.h"
|
#include "nanovna.h"
|
||||||
|
|
||||||
|
uint16_t spi_buffer[1024];
|
||||||
|
// Default foreground & background colors
|
||||||
|
uint16_t foreground_color=DEFAULT_FG_COLOR;
|
||||||
|
uint16_t background_color=DEFAULT_BG_COLOR;
|
||||||
|
|
||||||
|
// Display width and height definition
|
||||||
|
#define ILI9341_WIDTH 320
|
||||||
|
#define ILI9341_HEIGHT 240
|
||||||
|
|
||||||
|
// Display commands list
|
||||||
|
#define ILI9341_NOP 0x00
|
||||||
|
#define ILI9341_SOFTWARE_RESET 0x01
|
||||||
|
#define ILI9341_READ_IDENTIFICATION 0x04
|
||||||
|
#define ILI9341_READ_STATUS 0x09
|
||||||
|
#define ILI9341_READ_POWER_MODE 0x0A
|
||||||
|
#define ILI9341_READ_MADCTL 0x0B
|
||||||
|
#define ILI9341_READ_PIXEL_FORMAT 0x0C
|
||||||
|
#define ILI9341_READ_IMAGE_FORMAT 0x0D
|
||||||
|
#define ILI9341_READ_SIGNAL_MODE 0x0E
|
||||||
|
#define ILI9341_READ_SELF_DIAGNOSTIC 0x0F
|
||||||
|
#define ILI9341_SLEEP_IN 0x10
|
||||||
|
#define ILI9341_SLEEP_OUT 0x11
|
||||||
|
#define ILI9341_PARTIAL_MODE_ON 0x12
|
||||||
|
#define ILI9341_NORMAL_DISPLAY_MODE_ON 0x13
|
||||||
|
#define ILI9341_INVERSION_OFF 0x20
|
||||||
|
#define ILI9341_INVERSION_ON 0x21
|
||||||
|
#define ILI9341_GAMMA_SET 0x26
|
||||||
|
#define ILI9341_DISPLAY_OFF 0x28
|
||||||
|
#define ILI9341_DISPLAY_ON 0x29
|
||||||
|
#define ILI9341_COLUMN_ADDRESS_SET 0x2A
|
||||||
|
#define ILI9341_PAGE_ADDRESS_SET 0x2B
|
||||||
|
#define ILI9341_MEMORY_WRITE 0x2C
|
||||||
|
#define ILI9341_COLOR_SET 0x2D
|
||||||
|
#define ILI9341_MEMORY_READ 0x2E
|
||||||
|
#define ILI9341_PARTIAL_AREA 0x30
|
||||||
|
#define ILI9341_VERTICAL_SCROLLING_DEF 0x33
|
||||||
|
#define ILI9341_TEARING_LINE_OFF 0x34
|
||||||
|
#define ILI9341_TEARING_LINE_ON 0x35
|
||||||
|
#define ILI9341_MEMORY_ACCESS_CONTROL 0x36
|
||||||
|
#define ILI9341_VERTICAL_SCROLLING 0x37
|
||||||
|
#define ILI9341_IDLE_MODE_OFF 0x38
|
||||||
|
#define ILI9341_IDLE_MODE_ON 0x39
|
||||||
|
#define ILI9341_PIXEL_FORMAT_SET 0x3A
|
||||||
|
#define ILI9341_WRITE_MEMORY_CONTINUE 0x3C
|
||||||
|
#define ILI9341_READ_MEMORY_CONTINUE 0x3E
|
||||||
|
#define ILI9341_SET_TEAR_SCANLINE 0x44
|
||||||
|
#define ILI9341_GET_SCANLINE 0x45
|
||||||
|
#define ILI9341_WRITE_BRIGHTNESS 0x51
|
||||||
|
#define ILI9341_READ_BRIGHTNESS 0x52
|
||||||
|
#define ILI9341_WRITE_CTRL_DISPLAY 0x53
|
||||||
|
#define ILI9341_READ_CTRL_DISPLAY 0x54
|
||||||
|
#define ILI9341_WRITE_CA_BRIGHTNESS 0x55
|
||||||
|
#define ILI9341_READ_CA_BRIGHTNESS 0x56
|
||||||
|
#define ILI9341_WRITE_CA_MIN_BRIGHTNESS 0x5E
|
||||||
|
#define ILI9341_READ_CA_MIN_BRIGHTNESS 0x5F
|
||||||
|
#define ILI9341_READ_ID1 0xDA
|
||||||
|
#define ILI9341_READ_ID2 0xDB
|
||||||
|
#define ILI9341_READ_ID3 0xDC
|
||||||
|
#define ILI9341_RGB_INTERFACE_CONTROL 0xB0
|
||||||
|
#define ILI9341_FRAME_RATE_CONTROL_1 0xB1
|
||||||
|
#define ILI9341_FRAME_RATE_CONTROL_2 0xB2
|
||||||
|
#define ILI9341_FRAME_RATE_CONTROL_3 0xB3
|
||||||
|
#define ILI9341_DISPLAY_INVERSION_CONTROL 0xB4
|
||||||
|
#define ILI9341_BLANKING_PORCH_CONTROL 0xB5
|
||||||
|
#define ILI9341_DISPLAY_FUNCTION_CONTROL 0xB6
|
||||||
|
#define ILI9341_ENTRY_MODE_SET 0xB7
|
||||||
|
#define ILI9341_BACKLIGHT_CONTROL_1 0xB8
|
||||||
|
#define ILI9341_BACKLIGHT_CONTROL_2 0xB9
|
||||||
|
#define ILI9341_BACKLIGHT_CONTROL_3 0xBA
|
||||||
|
#define ILI9341_BACKLIGHT_CONTROL_4 0xBB
|
||||||
|
#define ILI9341_BACKLIGHT_CONTROL_5 0xBC
|
||||||
|
#define ILI9341_BACKLIGHT_CONTROL_7 0xBE
|
||||||
|
#define ILI9341_BACKLIGHT_CONTROL_8 0xBF
|
||||||
|
#define ILI9341_POWER_CONTROL_1 0xC0
|
||||||
|
#define ILI9341_POWER_CONTROL_2 0xC1
|
||||||
|
#define ILI9341_VCOM_CONTROL_1 0xC5
|
||||||
|
#define ILI9341_VCOM_CONTROL_2 0xC7
|
||||||
|
#define ILI9341_POWERA 0xCB
|
||||||
|
#define ILI9341_POWERB 0xCF
|
||||||
|
#define ILI9341_NV_MEMORY_WRITE 0xD0
|
||||||
|
#define ILI9341_NV_PROTECTION_KEY 0xD1
|
||||||
|
#define ILI9341_NV_STATUS_READ 0xD2
|
||||||
|
#define ILI9341_READ_ID4 0xD3
|
||||||
|
#define ILI9341_POSITIVE_GAMMA_CORRECTION 0xE0
|
||||||
|
#define ILI9341_NEGATIVE_GAMMA_CORRECTION 0xE1
|
||||||
|
#define ILI9341_DIGITAL_GAMMA_CONTROL_1 0xE2
|
||||||
|
#define ILI9341_DIGITAL_GAMMA_CONTROL_2 0xE3
|
||||||
|
#define ILI9341_DTCA 0xE8
|
||||||
|
#define ILI9341_DTCB 0xEA
|
||||||
|
#define ILI9341_POWER_SEQ 0xED
|
||||||
|
#define ILI9341_3GAMMA_EN 0xF2
|
||||||
|
#define ILI9341_INTERFACE_CONTROL 0xF6
|
||||||
|
#define ILI9341_PUMP_RATIO_CONTROL 0xF7
|
||||||
|
|
||||||
|
//
|
||||||
|
// ILI9341_MEMORY_ACCESS_CONTROL registers
|
||||||
|
//
|
||||||
|
#define ILI9341_MADCTL_MY 0x80
|
||||||
|
#define ILI9341_MADCTL_MX 0x40
|
||||||
|
#define ILI9341_MADCTL_MV 0x20
|
||||||
|
#define ILI9341_MADCTL_ML 0x10
|
||||||
|
#define ILI9341_MADCTL_BGR 0x08
|
||||||
|
#define ILI9341_MADCTL_MH 0x04
|
||||||
|
#define ILI9341_MADCTL_RGB 0x00
|
||||||
|
|
||||||
|
#define DISPLAY_ROTATION_270 (ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR)
|
||||||
|
#define DISPLAY_ROTATION_90 (ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR)
|
||||||
|
#define DISPLAY_ROTATION_0 (ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR)
|
||||||
|
#define DISPLAY_ROTATION_180 (ILI9341_MADCTL_MX | ILI9341_MADCTL_MY | ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Pin macros
|
||||||
|
//
|
||||||
#define RESET_ASSERT palClearPad(GPIOA, 15)
|
#define RESET_ASSERT palClearPad(GPIOA, 15)
|
||||||
#define RESET_NEGATE palSetPad(GPIOA, 15)
|
#define RESET_NEGATE palSetPad(GPIOA, 15)
|
||||||
#define CS_LOW palClearPad(GPIOB, 6)
|
#define CS_LOW palClearPad(GPIOB, 6)
|
||||||
|
|
@ -28,380 +141,487 @@
|
||||||
#define DC_CMD palClearPad(GPIOB, 7)
|
#define DC_CMD palClearPad(GPIOB, 7)
|
||||||
#define DC_DATA palSetPad(GPIOB, 7)
|
#define DC_DATA palSetPad(GPIOB, 7)
|
||||||
|
|
||||||
uint16_t spi_buffer[1024];
|
//*****************************************************************************
|
||||||
|
//********************************** SPI bus **********************************
|
||||||
|
//*****************************************************************************
|
||||||
|
// STM32 SPI transfer mode:
|
||||||
|
// in 8 bit mode:
|
||||||
|
// if you write *(uint8_t*)(&SPI1->DR) = (uint8_t) data, then data send as << data
|
||||||
|
// if you write *(uint16_t*)(&SPI1->DR) =(uint16_t) data, then data send as << dataLoByte, after send dataHiByte
|
||||||
|
// in 16 bit mode
|
||||||
|
// if you write *(uint16_t*)(&SPI1->DR) =(uint16_t) data, then data send as << data
|
||||||
|
|
||||||
void
|
// SPI init in 8 bit mode
|
||||||
ssp_wait(void)
|
#define SPI_CR2_8BIT 0x0700
|
||||||
{
|
#define SPI_CR2_16BIT 0x0F00
|
||||||
while (SPI1->SR & SPI_SR_BSY)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
// SPI bus activity macros
|
||||||
ssp_wait_slot(void)
|
|
||||||
{
|
|
||||||
while ((SPI1->SR & 0x1800) == 0x1800)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
// The RXNE flag is set depending on the FRXTH bit value in the SPIx_CR2 register:
|
||||||
ssp_senddata(uint8_t x)
|
// • If FRXTH is set, RXNE goes high and stays high until the RXFIFO level is greater or equal to 1/4 (8-bit).
|
||||||
{
|
#define SPI_RX_IS_NOT_EMPTY (SPI1->SR&SPI_SR_RXNE)
|
||||||
*(uint8_t*)(&SPI1->DR) = x;
|
#define SPI_RX_IS_EMPTY (((SPI1->SR&SPI_SR_RXNE) == 0))
|
||||||
while (SPI1->SR & SPI_SR_BSY)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t
|
// The TXE flag is set when transmission TXFIFO has enough space to store data to send.
|
||||||
ssp_sendrecvdata(uint8_t x)
|
// 0: Tx buffer not empty, bit is cleared automatically when the TXFIFO level becomes greater than 1/2
|
||||||
{
|
// 1: Tx buffer empty, flag goes high and stays high until the TXFIFO level is lower or equal to 1/2 of the FIFO depth
|
||||||
while (!(SPI1->SR & SPI_SR_TXE));
|
#define SPI_TX_IS_NOT_EMPTY (((SPI1->SR&(SPI_SR_TXE)) == 0))
|
||||||
// clear OVR
|
#define SPI_TX_IS_EMPTY (SPI1->SR&SPI_SR_TXE)
|
||||||
while (SPI1->SR & SPI_SR_RXNE) (void)SPI1->DR;
|
|
||||||
|
|
||||||
*(uint8_t*)(&SPI1->DR) = x;
|
// When BSY is set, it indicates that a data transfer is in progress on the SPI (the SPI bus is busy).
|
||||||
while (!(SPI1->SR & SPI_SR_RXNE));
|
#define SPI_IS_BUSY (SPI1->SR & SPI_SR_BSY)
|
||||||
return SPI1->DR;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
// SPI send data macros
|
||||||
ssp_senddata16(uint16_t x)
|
#define SPI_WRITE_8BIT(data) *(__IO uint8_t*)(&SPI1->DR) = (uint8_t) data
|
||||||
{
|
#define SPI_WRITE_16BIT(data) SPI1->DR = data
|
||||||
ssp_wait_slot();
|
|
||||||
SPI1->DR = x;
|
|
||||||
//while (SPI1->SR & SPI_SR_BSY)
|
|
||||||
// ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
// SPI read data macros
|
||||||
ssp_databit8(void)
|
#define SPI_READ_DATA SPI1->DR
|
||||||
{
|
|
||||||
SPI1->CR2 = (SPI1->CR2 & 0xf0ff) | 0x0700;
|
|
||||||
//LPC_SSP1->CR0 = (LPC_SSP1->CR0 & 0xf0) | SSP_DATABIT_8;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
#ifdef __USE_DISPLAY_DMA__
|
||||||
ssp_databit16(void)
|
static const stm32_dma_stream_t *dmatx = STM32_DMA_STREAM(STM32_SPI_SPI1_TX_DMA_STREAM);
|
||||||
{
|
static uint32_t txdmamode = STM32_DMA_CR_CHSEL(SPI1_TX_DMA_CHANNEL) // Select SPI1 Tx DMA
|
||||||
SPI1->CR2 = (SPI1->CR2 & 0xf0ff) | 0x0f00;
|
| STM32_DMA_CR_PL(STM32_SPI_SPI1_DMA_PRIORITY) // Set priority
|
||||||
//LPC_SSP1->CR0 = (LPC_SSP1->CR0 & 0xf0) | SSP_DATABIT_16;
|
| STM32_DMA_CR_DIR_M2P // Memory to Spi
|
||||||
}
|
| STM32_DMA_CR_DMEIE //
|
||||||
|
| STM32_DMA_CR_TEIE;
|
||||||
|
|
||||||
const stm32_dma_stream_t *dmatx;
|
|
||||||
uint32_t txdmamode;
|
|
||||||
|
|
||||||
static void spi_lld_serve_tx_interrupt(SPIDriver *spip, uint32_t flags) {
|
static void spi_lld_serve_tx_interrupt(SPIDriver *spip, uint32_t flags) {
|
||||||
(void)spip;
|
(void)spip;
|
||||||
(void)flags;
|
(void)flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static const stm32_dma_stream_t *dmarx = STM32_DMA_STREAM(STM32_SPI_SPI1_RX_DMA_STREAM);
|
||||||
spi_init(void)
|
static uint32_t rxdmamode = STM32_DMA_CR_CHSEL(SPI1_RX_DMA_CHANNEL)
|
||||||
{
|
| STM32_DMA_CR_PL(STM32_SPI_SPI1_DMA_PRIORITY)
|
||||||
rccEnableSPI1(FALSE);
|
| STM32_DMA_CR_DIR_P2M
|
||||||
|
| STM32_DMA_CR_TCIE
|
||||||
|
| STM32_DMA_CR_DMEIE
|
||||||
|
| STM32_DMA_CR_TEIE;
|
||||||
|
|
||||||
dmatx = STM32_DMA_STREAM(STM32_SPI_SPI1_TX_DMA_STREAM);
|
static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags) {
|
||||||
txdmamode = STM32_DMA_CR_CHSEL(SPI1_TX_DMA_CHANNEL) |
|
(void)spip;
|
||||||
STM32_DMA_CR_PL(STM32_SPI_SPI1_DMA_PRIORITY) |
|
(void)flags;
|
||||||
STM32_DMA_CR_DIR_M2P |
|
|
||||||
STM32_DMA_CR_DMEIE |
|
|
||||||
STM32_DMA_CR_TEIE |
|
|
||||||
STM32_DMA_CR_PSIZE_HWORD |
|
|
||||||
STM32_DMA_CR_MSIZE_HWORD;
|
|
||||||
dmaStreamAllocate(dmatx,
|
|
||||||
STM32_SPI_SPI1_IRQ_PRIORITY,
|
|
||||||
(stm32_dmaisr_t)spi_lld_serve_tx_interrupt,
|
|
||||||
NULL);
|
|
||||||
dmaStreamSetPeripheral(dmatx, &SPI1->DR);
|
|
||||||
|
|
||||||
SPI1->CR1 = 0;
|
|
||||||
SPI1->CR1 = SPI_CR1_MSTR | SPI_CR1_SSM | SPI_CR1_SSI;// | SPI_CR1_BR_1;
|
|
||||||
SPI1->CR2 = 0x0700 | SPI_CR2_TXDMAEN | SPI_CR2_FRXTH;
|
|
||||||
SPI1->CR1 |= SPI_CR1_SPE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void dmaStreamFlush(uint32_t len){
|
||||||
send_command(uint8_t cmd, int len, const uint8_t *data)
|
while (len){
|
||||||
|
// DMA data transfer limited by 65535
|
||||||
|
uint16_t tx_size = len > 65535 ? 65535 : len;
|
||||||
|
dmaStreamSetTransactionSize(dmatx, tx_size);
|
||||||
|
dmaStreamEnable(dmatx);
|
||||||
|
len -= tx_size;
|
||||||
|
dmaWaitCompletion(dmatx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void spi_init(void)
|
||||||
|
{
|
||||||
|
rccEnableSPI1(FALSE);
|
||||||
|
SPI1->CR1 = 0;
|
||||||
|
SPI1->CR1 = SPI_CR1_MSTR // SPI is MASTER
|
||||||
|
| SPI_CR1_SSM // Software slave management (The external NSS pin is free for other application uses)
|
||||||
|
| SPI_CR1_SSI; // Internal slave select (This bit has an effect only when the SSM bit is set. Allow use NSS pin as I/O)
|
||||||
|
// | SPI_CR1_BR_1; // Baud rate control
|
||||||
|
|
||||||
|
SPI1->CR2 = SPI_CR2_8BIT // SPI data size, set to 8 bit
|
||||||
|
| SPI_CR2_FRXTH; // SPI_SR_RXNE generated every 8 bit data
|
||||||
|
// | SPI_CR2_SSOE; //
|
||||||
|
|
||||||
|
#ifdef __USE_DISPLAY_DMA__
|
||||||
|
// Tx DMA init
|
||||||
|
dmaStreamAllocate(dmatx, STM32_SPI_SPI1_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_tx_interrupt, NULL);
|
||||||
|
dmaStreamSetPeripheral(dmatx, &SPI1->DR);
|
||||||
|
// Rx DMA init
|
||||||
|
dmaStreamAllocate(dmarx, STM32_SPI_SPI1_IRQ_PRIORITY, (stm32_dmaisr_t)spi_lld_serve_rx_interrupt, NULL);
|
||||||
|
dmaStreamSetPeripheral(dmarx, &SPI1->DR);
|
||||||
|
// Enable DMA on SPI
|
||||||
|
SPI1->CR2|= SPI_CR2_TXDMAEN // Tx DMA enable
|
||||||
|
| SPI_CR2_RXDMAEN; // Rx DMA enable
|
||||||
|
#endif
|
||||||
|
SPI1->CR1|= SPI_CR1_SPE; //SPI enable
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable inline for this function
|
||||||
|
static void __attribute__ ((noinline)) send_command(uint8_t cmd, uint8_t len, const uint8_t *data)
|
||||||
{
|
{
|
||||||
CS_LOW;
|
CS_LOW;
|
||||||
|
// while (SPI_TX_IS_NOT_EMPTY);
|
||||||
DC_CMD;
|
DC_CMD;
|
||||||
ssp_databit8();
|
SPI_WRITE_8BIT(cmd);
|
||||||
ssp_senddata(cmd);
|
// Need wait transfer complete and set data bit
|
||||||
|
while (SPI_IS_BUSY);
|
||||||
|
// Send command data (if need)
|
||||||
DC_DATA;
|
DC_DATA;
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
ssp_senddata(*data++);
|
while (SPI_TX_IS_NOT_EMPTY);
|
||||||
|
SPI_WRITE_8BIT(*data++);
|
||||||
}
|
}
|
||||||
//CS_HIGH;
|
//CS_HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static const uint8_t ili9341_init_seq[] = {
|
||||||
send_command16(uint8_t cmd, int data)
|
|
||||||
{
|
|
||||||
CS_LOW;
|
|
||||||
DC_CMD;
|
|
||||||
ssp_databit8();
|
|
||||||
ssp_senddata(cmd);
|
|
||||||
DC_DATA;
|
|
||||||
ssp_databit16();
|
|
||||||
ssp_senddata16(data);
|
|
||||||
CS_HIGH;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint8_t ili9341_init_seq[] = {
|
|
||||||
// cmd, len, data...,
|
// cmd, len, data...,
|
||||||
|
// SW reset
|
||||||
|
ILI9341_SOFTWARE_RESET, 0,
|
||||||
|
// display off
|
||||||
|
ILI9341_DISPLAY_OFF, 0,
|
||||||
// Power control B
|
// Power control B
|
||||||
0xCF, 3, 0x00, 0x83, 0x30,
|
ILI9341_POWERB, 3, 0x00, 0x83, 0x30,
|
||||||
// Power on sequence control
|
// Power on sequence control
|
||||||
0xED, 4, 0x64, 0x03, 0x12, 0x81,
|
ILI9341_POWER_SEQ, 4, 0x64, 0x03, 0x12, 0x81,
|
||||||
//0xED, 4, 0x55, 0x01, 0x23, 0x01,
|
//ILI9341_POWER_SEQ, 4, 0x55, 0x01, 0x23, 0x01,
|
||||||
// Driver timing control A
|
// Driver timing control A
|
||||||
0xE8, 3, 0x85, 0x01, 0x79,
|
ILI9341_DTCA, 3, 0x85, 0x01, 0x79,
|
||||||
//0xE8, 3, 0x84, 0x11, 0x7a,
|
//ILI9341_DTCA, 3, 0x84, 0x11, 0x7a,
|
||||||
// Power control A
|
// Power control A
|
||||||
0xCB, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
|
ILI9341_POWERA, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
|
||||||
// Pump ratio control
|
// Pump ratio control
|
||||||
0xF7, 1, 0x20,
|
ILI9341_PUMP_RATIO_CONTROL, 1, 0x20,
|
||||||
// Driver timing control B
|
// Driver timing control B
|
||||||
0xEA, 2, 0x00, 0x00,
|
ILI9341_DTCB, 2, 0x00, 0x00,
|
||||||
// POWER_CONTROL_1
|
// POWER_CONTROL_1
|
||||||
0xC0, 1, 0x26,
|
ILI9341_POWER_CONTROL_1, 1, 0x26,
|
||||||
// POWER_CONTROL_2
|
// POWER_CONTROL_2
|
||||||
0xC1, 1, 0x11,
|
ILI9341_POWER_CONTROL_2, 1, 0x11,
|
||||||
// VCOM_CONTROL_1
|
// VCOM_CONTROL_1
|
||||||
0xC5, 2, 0x35, 0x3E,
|
ILI9341_VCOM_CONTROL_1, 2, 0x35, 0x3E,
|
||||||
// VCOM_CONTROL_2
|
// VCOM_CONTROL_2
|
||||||
0xC7, 1, 0xBE,
|
ILI9341_VCOM_CONTROL_2, 1, 0xBE,
|
||||||
// MEMORY_ACCESS_CONTROL
|
// MEMORY_ACCESS_CONTROL
|
||||||
//0x36, 1, 0x48, // portlait
|
//ILI9341_MEMORY_ACCESS_CONTROL, 1, 0x48, // portlait
|
||||||
0x36, 1, 0x28, // landscape
|
ILI9341_MEMORY_ACCESS_CONTROL, 1, DISPLAY_ROTATION_0, // landscape
|
||||||
// COLMOD_PIXEL_FORMAT_SET : 16 bit pixel
|
// COLMOD_PIXEL_FORMAT_SET : 16 bit pixel
|
||||||
0x3A, 1, 0x55,
|
ILI9341_PIXEL_FORMAT_SET, 1, 0x55,
|
||||||
// Frame Rate
|
// Frame Rate
|
||||||
0xB1, 2, 0x00, 0x1B,
|
ILI9341_FRAME_RATE_CONTROL_1, 2, 0x00, 0x1B,
|
||||||
// Gamma Function Disable
|
// Gamma Function Disable
|
||||||
0xF2, 1, 0x08,
|
ILI9341_3GAMMA_EN, 1, 0x08,
|
||||||
// gamma set for curve 01/2/04/08
|
// gamma set for curve 01/2/04/08
|
||||||
0x26, 1, 0x01,
|
ILI9341_GAMMA_SET, 1, 0x01,
|
||||||
// positive gamma correction
|
// positive gamma correction
|
||||||
0xE0, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00,
|
// ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00,
|
||||||
// negativ gamma correction
|
// negativ gamma correction
|
||||||
0xE1, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F,
|
// ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F,
|
||||||
|
|
||||||
// Column Address Set
|
// Column Address Set
|
||||||
0x2A, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
|
// ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
|
||||||
// Page Address Set
|
// Page Address Set
|
||||||
0x2B, 4, 0x00, 0x00, 0x00, 0xef, // height 240
|
// ILI9341_PAGE_ADDRESS_SET, 4, 0x00, 0x00, 0x00, 0xef, // height 240
|
||||||
|
|
||||||
// entry mode
|
// entry mode
|
||||||
0xB7, 1, 0x06,
|
ILI9341_ENTRY_MODE_SET, 1, 0x06,
|
||||||
// display function control
|
// display function control
|
||||||
0xB6, 4, 0x0A, 0x82, 0x27, 0x00,
|
ILI9341_DISPLAY_FUNCTION_CONTROL, 4, 0x0A, 0x82, 0x27, 0x00,
|
||||||
|
// Interface Control (set WEMODE=0)
|
||||||
|
ILI9341_INTERFACE_CONTROL, 3, 0x00, 0x00, 0x00,
|
||||||
// control display
|
// control display
|
||||||
//0x53, 1, 0x0c,
|
//ILI9341_WRITE_CTRL_DISPLAY, 1, 0x0c,
|
||||||
// diaplay brightness
|
// diaplay brightness
|
||||||
//0x51, 1, 0xff,
|
//ILI9341_WRITE_BRIGHTNESS, 1, 0xff,
|
||||||
|
|
||||||
// sleep out
|
// sleep out
|
||||||
0x11, 0,
|
ILI9341_SLEEP_OUT, 0,
|
||||||
|
// display on
|
||||||
|
ILI9341_DISPLAY_ON, 0,
|
||||||
0 // sentinel
|
0 // sentinel
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void ili9341_init(void)
|
||||||
ili9341_init(void)
|
|
||||||
{
|
{
|
||||||
spi_init();
|
spi_init();
|
||||||
|
|
||||||
DC_DATA;
|
DC_DATA;
|
||||||
RESET_ASSERT;
|
RESET_ASSERT;
|
||||||
chThdSleepMilliseconds(10);
|
chThdSleepMilliseconds(10);
|
||||||
RESET_NEGATE;
|
RESET_NEGATE;
|
||||||
|
|
||||||
send_command(0x01, 0, NULL); // SW reset
|
|
||||||
chThdSleepMilliseconds(5);
|
|
||||||
send_command(0x28, 0, NULL); // display off
|
|
||||||
|
|
||||||
const uint8_t *p;
|
const uint8_t *p;
|
||||||
for (p = ili9341_init_seq; *p; ) {
|
for (p = ili9341_init_seq; *p; ) {
|
||||||
send_command(p[0], p[1], &p[2]);
|
send_command(p[0], p[1], &p[2]);
|
||||||
p += 2 + p[1];
|
p += 2 + p[1];
|
||||||
chThdSleepMilliseconds(5);
|
chThdSleepMilliseconds(5);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
int x1, y1, x2, y2;
|
||||||
|
x1 = y1 = 0;
|
||||||
|
y2 = 240 - 1;
|
||||||
|
for(x2=0; x2<320; x2+=6) ili9341_line(x1, y1, x2, y2);
|
||||||
|
x2 = 320 - 1;
|
||||||
|
for(y2=0; y2<240; y2+=6) ili9341_line(x1, y1, x2, y2);
|
||||||
|
chThdSleepMilliseconds(2000);*/
|
||||||
|
/*
|
||||||
|
char buf[64];
|
||||||
|
ili9341_fill(0,0, 320, 240, 255);
|
||||||
|
|
||||||
chThdSleepMilliseconds(100);
|
|
||||||
send_command(0x29, 0, NULL); // display on
|
systime_t time = chVTGetSystemTimeX();
|
||||||
|
for (int c=0;c<255;c+=5)
|
||||||
|
ili9341_fill(0,0, 320, 240, RGB565(0,0,c));
|
||||||
|
chThdSleepMilliseconds(1000);
|
||||||
|
for (int c=0;c<255;c+=5)
|
||||||
|
ili9341_fill(0,0, 320, 240, RGB565(0,c,0));
|
||||||
|
chThdSleepMilliseconds(1000);
|
||||||
|
for (int c=0;c<255;c+=5)
|
||||||
|
ili9341_fill(0,0, 320, 240, RGB565(c,0,0));
|
||||||
|
chThdSleepMilliseconds(1000);
|
||||||
|
time = chVTGetSystemTimeX() - time;
|
||||||
|
chsnprintf(buf, sizeof buf, "Fill Time %d", time);
|
||||||
|
ili9341_drawstring(buf, 10,10);
|
||||||
|
chThdSleepMilliseconds(2000);
|
||||||
|
|
||||||
|
// time = chVTGetSystemTimeX();
|
||||||
|
// for (int c=0;c<50;c++)
|
||||||
|
// show_version();
|
||||||
|
// time = chVTGetSystemTimeX() - time;
|
||||||
|
// chsnprintf(buf, sizeof buf, "Fill Time %d", time);
|
||||||
|
|
||||||
|
chsnprintf(buf, sizeof buf, "0123456789123456789");
|
||||||
|
|
||||||
|
setForegroundColor(RGB565(255,0,0));
|
||||||
|
ili9341_drawstring(buf, 0, 0);
|
||||||
|
setForegroundColor(RGB565(0,255,0));
|
||||||
|
ili9341_drawstring(buf, 0, 8);
|
||||||
|
setForegroundColor(RGB565(0,0,255));
|
||||||
|
ili9341_drawstring(buf, 0, 16);
|
||||||
|
ili9341_drawstring(buf, 0, 24);
|
||||||
|
ili9341_drawstring(buf, 0, 32);
|
||||||
|
ili9341_fill(0, 64, 320, 64, 0);
|
||||||
|
chThdSleepMilliseconds(2000);
|
||||||
|
ili9341_read_memory(0, 0, 32, 16, 512, spi_buffer);
|
||||||
|
ili9341_bulk(32, 64, 32, 16);
|
||||||
|
ili9341_read_memory(0, 16, 32, 16, 512, spi_buffer);
|
||||||
|
ili9341_bulk(32, 64+16, 32, 16);
|
||||||
|
chThdSleepMilliseconds(5000);/**/
|
||||||
|
/**/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_pixel(int x, int y, int color)
|
#ifndef __USE_DISPLAY_DMA__
|
||||||
{
|
|
||||||
uint8_t xx[4] = { x >> 8, x, (x+1) >> 8, (x+1) };
|
|
||||||
uint8_t yy[4] = { y >> 8, y, (y+1) >> 8, (y+1) };
|
|
||||||
uint8_t cc[2] = { color >> 8, color };
|
|
||||||
send_command(0x2A, 4, xx);
|
|
||||||
send_command(0x2B, 4, yy);
|
|
||||||
send_command(0x2C, 2, cc);
|
|
||||||
//send_command16(0x2C, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ili9341_fill(int x, int y, int w, int h, int color)
|
void ili9341_fill(int x, int y, int w, int h, int color)
|
||||||
{
|
{
|
||||||
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
int len = w * h;
|
|
||||||
send_command(0x2A, 4, xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
||||||
send_command(0x2B, 4, yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
||||||
send_command(0x2C, 0, NULL);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
while (len-- > 0)
|
int32_t len = w * h;
|
||||||
ssp_senddata16(color);
|
while (len-- > 0){
|
||||||
|
while (SPI_TX_IS_NOT_EMPTY);
|
||||||
|
SPI_WRITE_16BIT(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
void ili9341_bulk(int x, int y, int w, int h)
|
void ili9341_bulk(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
uint16_t *buf = spi_buffer;
|
uint16_t *buf = spi_buffer;
|
||||||
int len = w * h;
|
|
||||||
send_command(0x2A, 4, xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
||||||
send_command(0x2B, 4, yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
||||||
send_command(0x2C, 0, NULL);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
while (len-- > 0)
|
int32_t len = w * h;
|
||||||
ssp_senddata16(*buf++);
|
while (len-- > 0){
|
||||||
|
while (SPI_TX_IS_NOT_EMPTY);
|
||||||
|
SPI_WRITE_16BIT(*buf++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t ssp_sendrecvdata()
|
||||||
|
{
|
||||||
|
// Start RX clock (by sending data)
|
||||||
|
SPI_WRITE_8BIT(0);
|
||||||
|
while(SPI_RX_IS_EMPTY && SPI_IS_BUSY)
|
||||||
|
;
|
||||||
|
return SPI_READ_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
||||||
|
{
|
||||||
|
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
|
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
||||||
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
||||||
|
send_command(ILI9341_MEMORY_READ, 0, NULL);
|
||||||
|
|
||||||
|
// Skip data from rx buffer
|
||||||
|
while (SPI_RX_IS_NOT_EMPTY)
|
||||||
|
(void) SPI_READ_DATA;
|
||||||
|
// require 8bit dummy clock
|
||||||
|
ssp_sendrecvdata();
|
||||||
|
while (len-- > 0) {
|
||||||
|
// read data is always 18bit
|
||||||
|
uint8_t r = ssp_sendrecvdata();
|
||||||
|
uint8_t g = ssp_sendrecvdata();
|
||||||
|
uint8_t b = ssp_sendrecvdata();
|
||||||
|
*out++ = RGB565(r,g,b);
|
||||||
|
}
|
||||||
|
CS_HIGH;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
//
|
||||||
|
// Use DMA for send data
|
||||||
|
//
|
||||||
|
|
||||||
|
// Fill region by some color
|
||||||
|
void ili9341_fill(int x, int y, int w, int h, int color)
|
||||||
|
{
|
||||||
|
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
|
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
||||||
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
||||||
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
|
|
||||||
|
dmaStreamSetMemory0(dmatx, &color);
|
||||||
|
dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD);
|
||||||
|
dmaStreamFlush(w * h);
|
||||||
|
}
|
||||||
|
// Copy spi_buffer to region
|
||||||
void ili9341_bulk(int x, int y, int w, int h)
|
void ili9341_bulk(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
int len = w * h;
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
||||||
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
||||||
send_command(0x2A, 4, xx);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
send_command(0x2B, 4, yy);
|
|
||||||
send_command(0x2C, 0, NULL);
|
|
||||||
|
|
||||||
|
// Init Tx DMA mem->spi, set size, mode (spi and mem data size is 16 bit)
|
||||||
dmaStreamSetMemory0(dmatx, spi_buffer);
|
dmaStreamSetMemory0(dmatx, spi_buffer);
|
||||||
dmaStreamSetTransactionSize(dmatx, len);
|
dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC);
|
||||||
dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_MINC);
|
dmaStreamFlush(w * h);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy screen data to buffer
|
||||||
|
// Warning!!! buffer size must be greater then 3*len + 1 bytes
|
||||||
|
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
||||||
|
{
|
||||||
|
uint8_t dummy_tx = 0;
|
||||||
|
uint8_t *rgbbuf=(uint8_t *)out;
|
||||||
|
uint16_t data_size = len * 3 + 1;
|
||||||
|
|
||||||
|
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
|
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
||||||
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
||||||
|
send_command(ILI9341_MEMORY_READ, 0, NULL);
|
||||||
|
// Skip SPI rx buffer
|
||||||
|
while (SPI_RX_IS_NOT_EMPTY)
|
||||||
|
(void) SPI_READ_DATA;
|
||||||
|
// Init Rx DMA buffer, size, mode (spi and mem data size is 8 bit)
|
||||||
|
dmaStreamSetMemory0(dmarx, rgbbuf);
|
||||||
|
dmaStreamSetTransactionSize(dmarx, data_size);
|
||||||
|
dmaStreamSetMode(dmarx, rxdmamode | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE | STM32_DMA_CR_MINC);
|
||||||
|
// Init dummy Tx DMA (for rx clock), size, mode (spi and mem data size is 8 bit)
|
||||||
|
dmaStreamSetMemory0(dmatx, &dummy_tx);
|
||||||
|
dmaStreamSetTransactionSize(dmatx, data_size);
|
||||||
|
dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE);
|
||||||
|
|
||||||
|
// Start DMA exchange
|
||||||
dmaStreamEnable(dmatx);
|
dmaStreamEnable(dmatx);
|
||||||
|
dmaStreamEnable(dmarx);
|
||||||
|
// Wait DMA completion
|
||||||
dmaWaitCompletion(dmatx);
|
dmaWaitCompletion(dmatx);
|
||||||
|
dmaWaitCompletion(dmarx);
|
||||||
|
CS_HIGH;
|
||||||
|
|
||||||
|
// Parce recived data
|
||||||
|
// Skip dummy 8-bit read
|
||||||
|
rgbbuf++;
|
||||||
|
while (len-- > 0) {
|
||||||
|
uint8_t r, g, b;
|
||||||
|
// read data is always 18bit
|
||||||
|
r = rgbbuf[0];
|
||||||
|
g = rgbbuf[1];
|
||||||
|
b = rgbbuf[2];
|
||||||
|
*out++ = RGB565(r,g,b);
|
||||||
|
rgbbuf+=3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void setForegroundColor(uint16_t fg) {foreground_color = fg;}
|
||||||
ili9341_read_memory_raw(uint8_t cmd, int len, uint16_t* out)
|
void setBackgroundColor(uint16_t bg) {background_color = bg;}
|
||||||
{
|
|
||||||
uint8_t r, g, b;
|
|
||||||
send_command(cmd, 0, NULL);
|
|
||||||
ssp_databit8();
|
|
||||||
|
|
||||||
// consume old data
|
void ili9341_setRotation(uint8_t r) {
|
||||||
while (!(SPI1->SR & SPI_SR_TXE));
|
// static const uint8_t rotation_const[]={DISPLAY_ROTATION_0, DISPLAY_ROTATION_90, DISPLAY_ROTATION_180, DISPLAY_ROTATION_270};
|
||||||
// clear OVR
|
send_command(ILI9341_MEMORY_ACCESS_CONTROL, 1, &r);
|
||||||
while (SPI1->SR & SPI_SR_RXNE) r = SPI1->DR;
|
|
||||||
|
|
||||||
// require 8bit dummy clock
|
|
||||||
r = ssp_sendrecvdata(0);
|
|
||||||
|
|
||||||
while (len-- > 0) {
|
|
||||||
// read data is always 18bit
|
|
||||||
r = ssp_sendrecvdata(0);
|
|
||||||
g = ssp_sendrecvdata(0);
|
|
||||||
b = ssp_sendrecvdata(0);
|
|
||||||
*out++ = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
CS_HIGH;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap){
|
||||||
ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
|
||||||
{
|
|
||||||
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
|
||||||
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
|
||||||
|
|
||||||
send_command(0x2A, 4, xx);
|
|
||||||
send_command(0x2B, 4, yy);
|
|
||||||
|
|
||||||
ili9341_read_memory_raw(0x2E, len, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ili9341_read_memory_continue(int len, uint16_t* out)
|
|
||||||
{
|
|
||||||
ili9341_read_memory_raw(0x3E, len, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg)
|
|
||||||
{
|
|
||||||
uint16_t *buf = spi_buffer;
|
uint16_t *buf = spi_buffer;
|
||||||
uint8_t bits;
|
for(uint16_t c = 0; c < height; c++) {
|
||||||
int c, r;
|
uint8_t bits = *bitmap++;
|
||||||
for(c = 0; c < 7; c++) {
|
for (uint16_t r = 0; r < width; r++) {
|
||||||
bits = x5x7_bits[(ch * 7) + c];
|
*buf++ = (0x80 & bits) ? foreground_color : background_color;
|
||||||
for (r = 0; r < 5; r++) {
|
|
||||||
*buf++ = (0x80 & bits) ? fg : bg;
|
|
||||||
bits <<= 1;
|
bits <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ili9341_bulk(x, y, 5, 7);
|
ili9341_bulk(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap){
|
||||||
ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg)
|
|
||||||
{
|
|
||||||
while (*str) {
|
|
||||||
ili9341_drawchar_5x7(*str, x, y, fg, bg);
|
|
||||||
x += 5;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ili9341_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool invert)
|
|
||||||
{
|
|
||||||
if (invert)
|
|
||||||
ili9341_drawstring_5x7(str, x, y, bg, fg);
|
|
||||||
else
|
|
||||||
ili9341_drawstring_5x7(str, x, y, fg, bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size)
|
|
||||||
{
|
|
||||||
uint16_t *buf = spi_buffer;
|
uint16_t *buf = spi_buffer;
|
||||||
uint8_t bits;
|
for(uint16_t c = 0; c < height; c++) {
|
||||||
int c, r;
|
uint16_t bits = *bitmap++;
|
||||||
for(c = 0; c < 7*size; c++) {
|
for (uint16_t r = 0; r < width; r++) {
|
||||||
bits = x5x7_bits[(ch * 7) + (c / size)];
|
*buf++ = (0x8000 & bits) ? foreground_color : background_color;
|
||||||
for (r = 0; r < 5*size; r++) {
|
|
||||||
*buf++ = (0x80 & bits) ? fg : bg;
|
|
||||||
if (r % size == (size-1)) {
|
|
||||||
bits <<= 1;
|
bits <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
ili9341_bulk(x, y, width, height);
|
||||||
ili9341_bulk(x, y, 5*size, 7*size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void ili9341_drawchar(uint8_t ch, int x, int y)
|
||||||
ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size)
|
{
|
||||||
|
blit8BitWidthBitmap(x, y, FONT_GET_WIDTH(ch), FONT_GET_HEIGHT, FONT_GET_DATA(ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ili9341_drawstring(const char *str, int x, int y)
|
||||||
{
|
{
|
||||||
while (*str) {
|
while (*str) {
|
||||||
ili9341_drawchar_size(*str, x, y, fg, bg, size);
|
uint8_t ch = *str++;
|
||||||
x += 5 * size;
|
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
||||||
str++;
|
uint16_t w = FONT_GET_WIDTH(ch);
|
||||||
|
blit8BitWidthBitmap(x, y, w, FONT_GET_HEIGHT, char_buf);
|
||||||
|
x+=w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SWAP(x,y) do { int z=x; x = y; y = z; } while(0)
|
void ili9341_drawstringV(const char *str, int x, int y){
|
||||||
|
ili9341_setRotation(DISPLAY_ROTATION_270);
|
||||||
|
ili9341_drawstring(str, ILI9341_HEIGHT-y, x);
|
||||||
|
ili9341_setRotation(DISPLAY_ROTATION_0);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size)
|
||||||
ili9341_line(int x0, int y0, int x1, int y1, uint16_t fg)
|
|
||||||
{
|
{
|
||||||
|
uint16_t *buf = spi_buffer;
|
||||||
|
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
||||||
|
uint16_t w=FONT_GET_WIDTH(ch);
|
||||||
|
for(int c = 0; c < FONT_GET_HEIGHT; c++, char_buf++){
|
||||||
|
for (int i=0;i<size;i++){
|
||||||
|
uint8_t bits = *char_buf;
|
||||||
|
for (int r = 0; r < w; r++, bits<<=1)
|
||||||
|
for (int j=0; j<size; j++)
|
||||||
|
*buf++ = (0x80 & bits) ? foreground_color : background_color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ili9341_bulk(x, y, w*size, FONT_GET_HEIGHT*size);
|
||||||
|
return w*size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ili9341_drawfont(uint8_t ch, int x, int y)
|
||||||
|
{
|
||||||
|
blit16BitWidthBitmap(x, y, NUM_FONT_GET_WIDTH, NUM_FONT_GET_HEIGHT, NUM_FONT_GET_DATA(ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size)
|
||||||
|
{
|
||||||
|
while (*str)
|
||||||
|
x += ili9341_drawchar_size(*str++, x, y, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SWAP(x,y) { int z=x; x = y; y = z; }
|
||||||
|
void ili9341_line(int x0, int y0, int x1, int y1)
|
||||||
|
{
|
||||||
|
|
||||||
if (x0 > x1) {
|
if (x0 > x1) {
|
||||||
SWAP(x0, x1);
|
SWAP(x0, x1);
|
||||||
SWAP(y0, y1);
|
SWAP(y0, y1);
|
||||||
|
|
@ -422,53 +642,38 @@ ili9341_line(int x0, int y0, int x1, int y1, uint16_t fg)
|
||||||
if (-dy > dx) {
|
if (-dy > dx) {
|
||||||
dy /= dx; dx = 1;
|
dy /= dx; dx = 1;
|
||||||
} else {
|
} else {
|
||||||
dx /= -dy; dy = -1;
|
dx /= -dy;dy = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dy > 0)
|
if (dy > 0)
|
||||||
ili9341_fill(x0, y0, dx, dy, fg);
|
ili9341_fill(x0, y0, dx, dy, foreground_color);
|
||||||
else
|
else
|
||||||
ili9341_fill(x0, y0+dy, dx, -dy, fg);
|
ili9341_fill(x0, y0+dy, dx, -dy, foreground_color);
|
||||||
x0 += dx;
|
x0 += dx;
|
||||||
y0 += dy;
|
y0 += dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const font_t NF20x22 = { 20, 22, 1, 3*22, (const uint8_t *)numfont20x22 };
|
|
||||||
|
|
||||||
void
|
|
||||||
ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg)
|
|
||||||
{
|
|
||||||
uint16_t *buf = spi_buffer;
|
|
||||||
const uint8_t *bitmap = &font->bitmap[font->slide * ch];
|
|
||||||
int c, r;
|
|
||||||
|
|
||||||
for (c = 0; c < font->height; c++) {
|
|
||||||
uint8_t bits = *bitmap++;
|
|
||||||
uint8_t m = 0x80;
|
|
||||||
for (r = 0; r < font->width; r++) {
|
|
||||||
*buf++ = (bits & m) ? fg : bg;
|
|
||||||
m >>= 1;
|
|
||||||
|
|
||||||
if (m == 0) {
|
|
||||||
bits = *bitmap++;
|
|
||||||
m = 0x80;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ili9341_bulk(x, y, font->width, font->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
const uint16_t colormap[] = {
|
static const uint16_t colormap[] = {
|
||||||
RGB565(255,0,0), RGB565(0,255,0), RGB565(0,0,255),
|
RGBHEX(0x00ff00), RGBHEX(0x0000ff), RGBHEX(0xff0000),
|
||||||
RGB565(255,255,0), RGB565(0,255,255), RGB565(255,0,255)
|
RGBHEX(0x00ffff), RGBHEX(0xff00ff), RGBHEX(0xffff00)
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
static void ili9341_pixel(int x, int y, int color)
|
||||||
ili9341_test(int mode)
|
|
||||||
{
|
{
|
||||||
|
uint8_t xx[4] = { x >> 8, x, (x+1) >> 8, (x+1) };
|
||||||
|
uint8_t yy[4] = { y >> 8, y, (y+1) >> 8, (y+1) };
|
||||||
|
uint8_t cc[2] = { color >> 8, color };
|
||||||
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
||||||
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
||||||
|
send_command(ILI9341_MEMORY_WRITE, 2, cc);
|
||||||
|
//send_command16(ILI9341_MEMORY_WRITE, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ili9341_test(int mode)
|
||||||
|
{
|
||||||
|
chMtxLock(&mutex_ili9341);
|
||||||
int x, y;
|
int x, y;
|
||||||
int i;
|
int i;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
@ -476,7 +681,7 @@ ili9341_test(int mode)
|
||||||
#if 1
|
#if 1
|
||||||
ili9341_fill(0, 0, 320, 240, 0);
|
ili9341_fill(0, 0, 320, 240, 0);
|
||||||
for (y = 0; y < 240; y++) {
|
for (y = 0; y < 240; y++) {
|
||||||
ili9341_fill(0, y, 320, 1, RGB565(y, (y + 120) % 256, 240-y));
|
ili9341_fill(0, y, 320, 1, RGB(240-y, y, (y + 120) % 256));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
|
@ -495,7 +700,7 @@ ili9341_test(int mode)
|
||||||
#if 1
|
#if 1
|
||||||
case 3:
|
case 3:
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 10; i++)
|
||||||
ili9341_drawfont(i, &NF20x22, i*20, 120, colormap[i%6], 0x0000);
|
ili9341_drawfont(i, i*20, 120);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -504,11 +709,12 @@ ili9341_test(int mode)
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 4:
|
case 4:
|
||||||
ili9341_line(0, 0, 15, 100, 0xffff);
|
ili9341_line(0, 0, 15, 100);
|
||||||
ili9341_line(0, 0, 100, 100, 0xffff);
|
ili9341_line(0, 0, 100, 100);
|
||||||
ili9341_line(0, 15, 100, 0, 0xffff);
|
ili9341_line(0, 15, 100, 0);
|
||||||
ili9341_line(0, 100, 100, 0, 0xffff);
|
ili9341_line(0, 100, 100, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
chMtxUnlock(&mutex_ili9341);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
51
main.c
51
main.c
|
|
@ -533,32 +533,21 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// read pixel count at one time (PART*2 bytes required for read buffer)
|
// read pixel count at one time (PART*2 bytes required for read buffer)
|
||||||
#define PART 320
|
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
chMtxLock(&mutex);
|
chMtxLock(&mutex);
|
||||||
|
|
||||||
|
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
|
||||||
|
for (int y=0; y < 240; y+=2)
|
||||||
|
{
|
||||||
// use uint16_t spi_buffer[1024] (defined in ili9341) for read buffer
|
// use uint16_t spi_buffer[1024] (defined in ili9341) for read buffer
|
||||||
uint16_t *buf = &spi_buffer[0];
|
uint8_t *buf = (uint8_t *)spi_buffer;
|
||||||
int len = 320 * 240;
|
ili9341_read_memory(0, y, 320, 2, 2*320, spi_buffer);
|
||||||
int i;
|
for (int i = 0; i < 4*320; i++) {
|
||||||
ili9341_read_memory(0, 0, 320, 240, PART, buf);
|
streamPut(chp, *buf++);
|
||||||
for (i = 0; i < PART; i++) {
|
|
||||||
streamPut(chp, buf[i] >> 8);
|
|
||||||
streamPut(chp, buf[i] & 0xff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
len -= PART;
|
|
||||||
while (len > 0) {
|
|
||||||
ili9341_read_memory_continue(PART, buf);
|
|
||||||
for (i = 0; i < PART; i++) {
|
|
||||||
streamPut(chp, buf[i] >> 8);
|
|
||||||
streamPut(chp, buf[i] & 0xff);
|
|
||||||
}
|
}
|
||||||
len -= PART;
|
|
||||||
}
|
|
||||||
//*/
|
|
||||||
|
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
}
|
}
|
||||||
|
|
@ -602,10 +591,10 @@ static void cmd_sample(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
config_t config = {
|
config_t config = {
|
||||||
.magic = CONFIG_MAGIC,
|
.magic = CONFIG_MAGIC,
|
||||||
.dac_value = 1922,
|
.dac_value = 1922,
|
||||||
.grid_color = 0x1084,
|
.grid_color = DEFAULT_GRID_COLOR,
|
||||||
.menu_normal_color = 0xffff,
|
.menu_normal_color = DEFAULT_MENU_COLOR,
|
||||||
.menu_active_color = 0x7777,
|
.menu_active_color = DEFAULT_MENU_ACTIVE_COLOR,
|
||||||
.trace_color = { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
|
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR, DEFAULT_TRACE_4_COLOR },
|
||||||
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
||||||
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
||||||
.default_loadcal = 0,
|
.default_loadcal = 0,
|
||||||
|
|
@ -618,10 +607,10 @@ properties_t current_props = {
|
||||||
._frequency1 = 900000000, // end = 900MHz
|
._frequency1 = 900000000, // end = 900MHz
|
||||||
._sweep_points = 101,
|
._sweep_points = 101,
|
||||||
._trace = {/*enable, type, channel, polar, scale, refpos*/
|
._trace = {/*enable, type, channel, polar, scale, refpos*/
|
||||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
{ 1, TRC_LOGMAG, 0, 0, 1.0, 9.0 },
|
||||||
{ 1, TRC_LOGMAG, 1, 0, 1.0, 7.0 },
|
{ 1, TRC_LOGMAG, 1, 0, 1.0, 9.0 },
|
||||||
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
|
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
|
||||||
{ 1, TRC_PHASE, 1, 0, 1.0, 4.0 }
|
{ 1, TRC_PHASE, 1, 0, 1.0, 5.0 }
|
||||||
},
|
},
|
||||||
._markers = {
|
._markers = {
|
||||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||||
|
|
@ -1431,17 +1420,17 @@ const struct {
|
||||||
uint16_t refpos;
|
uint16_t refpos;
|
||||||
float scale_unit;
|
float scale_unit;
|
||||||
} trace_info[] = {
|
} trace_info[] = {
|
||||||
{ "LOGMAG", 7, 10 },
|
{ "LOGMAG", 9, 10 },
|
||||||
{ "PHASE", 4, 90 },
|
{ "PHASE", 5, 90 },
|
||||||
{ "DELAY", 4, 1e-9 },
|
{ "DELAY", 5, 1e-9 },
|
||||||
{ "SMITH", 0, 1 },
|
{ "SMITH", 0, 1 },
|
||||||
{ "POLAR", 0, 1 },
|
{ "POLAR", 0, 1 },
|
||||||
{ "LINEAR", 0, 0.125 },
|
{ "LINEAR", 0, 0.125 },
|
||||||
{ "SWR", 0, 1 },
|
{ "SWR", 0, 1 },
|
||||||
{ "REAL", 4, 0.25 },
|
{ "REAL", 5, 0.25 },
|
||||||
{ "IMAG", 4, 0.25 },
|
{ "IMAG", 5, 0.25 },
|
||||||
{ "R", 0, 100 },
|
{ "R", 0, 100 },
|
||||||
{ "X", 4, 100 }
|
{ "X", 5, 100 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * const trc_channel_name[] = {
|
const char * const trc_channel_name[] = {
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,9 @@
|
||||||
#define STM32_I2C_BUSY_TIMEOUT 50
|
#define STM32_I2C_BUSY_TIMEOUT 50
|
||||||
#define STM32_I2C_I2C1_IRQ_PRIORITY 3
|
#define STM32_I2C_I2C1_IRQ_PRIORITY 3
|
||||||
#define STM32_I2C_I2C2_IRQ_PRIORITY 3
|
#define STM32_I2C_I2C2_IRQ_PRIORITY 3
|
||||||
#define STM32_I2C_USE_DMA TRUE
|
|
||||||
|
// I2C1 rx operation use DMA3, some as SPI1 DMA Tx used by LCD
|
||||||
|
#define STM32_I2C_USE_DMA FALSE
|
||||||
#define STM32_I2C_I2C1_DMA_PRIORITY 1
|
#define STM32_I2C_I2C1_DMA_PRIORITY 1
|
||||||
#define STM32_I2C_I2C2_DMA_PRIORITY 1
|
#define STM32_I2C_I2C2_DMA_PRIORITY 1
|
||||||
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
|
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
|
||||||
|
|
|
||||||
93
nanovna.h
93
nanovna.h
|
|
@ -19,6 +19,9 @@
|
||||||
*/
|
*/
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
|
|
||||||
|
// Need enable HAL_USE_SPI in halconf.h
|
||||||
|
#define __USE_DISPLAY_DMA__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* main.c
|
* main.c
|
||||||
*/
|
*/
|
||||||
|
|
@ -129,7 +132,12 @@ extern void tlv320aic3204_select(int channel);
|
||||||
#define OFFSETX 15
|
#define OFFSETX 15
|
||||||
#define OFFSETY 0
|
#define OFFSETY 0
|
||||||
#define WIDTH 291
|
#define WIDTH 291
|
||||||
#define HEIGHT 233
|
#define HEIGHT 230
|
||||||
|
|
||||||
|
// Smith/polar chart
|
||||||
|
#define P_CENTER_X 145
|
||||||
|
#define P_CENTER_Y 115
|
||||||
|
#define P_RADIUS 115
|
||||||
|
|
||||||
#define CELLOFFSETX 5
|
#define CELLOFFSETX 5
|
||||||
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
|
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
|
||||||
|
|
@ -137,21 +145,29 @@ extern void tlv320aic3204_select(int channel);
|
||||||
extern int area_width;
|
extern int area_width;
|
||||||
extern int area_height;
|
extern int area_height;
|
||||||
|
|
||||||
#define GRIDY 29
|
#define GRIDY 23
|
||||||
|
|
||||||
// font
|
// font
|
||||||
|
|
||||||
extern const uint8_t x5x7_bits [];
|
extern const uint8_t x5x7_bits [];
|
||||||
extern const uint8_t numfont20x22[][22 * 3];
|
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
||||||
|
#define FONT_GET_WIDTH(ch) (7-(x5x7_bits[ch*7]&3))
|
||||||
|
#define FONT_GET_HEIGHT 7
|
||||||
|
|
||||||
|
extern const uint16_t numfont16x22[];
|
||||||
|
#define NUM_FONT_GET_DATA(ch) (&numfont16x22[ch*22])
|
||||||
|
#define NUM_FONT_GET_WIDTH 16
|
||||||
|
#define NUM_FONT_GET_HEIGHT 22
|
||||||
|
|
||||||
#define S_DELTA "\004"
|
#define S_DELTA "\004"
|
||||||
|
#define S_DEGREE "\037"
|
||||||
|
#define S_SARROW "\030"
|
||||||
|
#define S_INFINITY "\031"
|
||||||
|
#define S_LARROW "\032"
|
||||||
|
#define S_RARROW "\033"
|
||||||
#define S_PI "\034"
|
#define S_PI "\034"
|
||||||
#define S_MICRO "\035"
|
#define S_MICRO "\035"
|
||||||
#define S_OHM "\036"
|
#define S_OHM "\036"
|
||||||
#define S_DEGREE "\037"
|
|
||||||
#define S_LARROW "\032"
|
|
||||||
#define S_RARROW "\033"
|
|
||||||
|
|
||||||
// trace
|
// trace
|
||||||
|
|
||||||
#define TRACES_MAX 4
|
#define TRACES_MAX 4
|
||||||
|
|
@ -261,8 +277,34 @@ extern int16_t vbat;
|
||||||
/*
|
/*
|
||||||
* ili9341.c
|
* ili9341.c
|
||||||
*/
|
*/
|
||||||
#define RGB565(b,r,g) ( (((b)<<8)&0xfc00) | (((r)<<2)&0x03e0) | (((g)>>3)&0x001f) )
|
// SPI bus revert byte order
|
||||||
|
//gggBBBbb RRRrrGGG
|
||||||
|
#define RGB565(r,g,b) ( (((g)&0x1c)<<11) | (((b)&0xf8)<<5) | ((r)&0xf8) | (((g)&0xe0)>>5) )
|
||||||
|
#define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) )
|
||||||
|
|
||||||
|
#define DEFAULT_FG_COLOR RGB565(255,255,255)
|
||||||
|
#define DEFAULT_BG_COLOR RGB565( 0, 0, 0)
|
||||||
|
#define DEFAULT_GRID_COLOR RGB565(128,128,128)
|
||||||
|
#define DEFAULT_MENU_COLOR RGB565(255,255,255)
|
||||||
|
#define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0)
|
||||||
|
#define DEFAULT_MENU_ACTIVE_COLOR RGB565(180,255,180)
|
||||||
|
#define DEFAULT_TRACE_1_COLOR RGB565( 0,255,255)
|
||||||
|
#define DEFAULT_TRACE_2_COLOR RGB565(255, 0, 40)
|
||||||
|
#define DEFAULT_TRACE_3_COLOR RGB565( 0, 0,255)
|
||||||
|
#define DEFAULT_TRACE_4_COLOR RGB565( 50,255, 0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define DEFAULT_FG_COLOR RGB565( 0, 0, 0)
|
||||||
|
#define DEFAULT_BG_COLOR RGB565(255,255,255)
|
||||||
|
#define DEFAULT_GRID_COLOR RGB565(150,150,150)
|
||||||
|
#define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0)
|
||||||
|
#define DEFAULT_MENU_COLOR RGB565(180,180,180)
|
||||||
|
#define DEFAULT_MENU_ACTIVE_COLOR RGB565(180,255,180)
|
||||||
|
#define DEFAULT_TRACE_1_COLOR RGB565( 0,255,255)
|
||||||
|
#define DEFAULT_TRACE_2_COLOR RGB565(255, 0, 40)
|
||||||
|
#define DEFAULT_TRACE_3_COLOR RGB565( 0, 0,255)
|
||||||
|
#define DEFAULT_TRACE_4_COLOR RGB565( 50,255, 0)
|
||||||
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
|
|
@ -271,23 +313,30 @@ typedef struct {
|
||||||
const uint8_t *bitmap;
|
const uint8_t *bitmap;
|
||||||
} font_t;
|
} font_t;
|
||||||
|
|
||||||
extern const font_t NF20x22;
|
extern uint16_t foreground_color;
|
||||||
|
extern uint16_t background_color;
|
||||||
|
|
||||||
extern uint16_t spi_buffer[1024];
|
extern uint16_t spi_buffer[1024];
|
||||||
|
|
||||||
void ili9341_init(void);
|
void ili9341_init(void);
|
||||||
|
//void ili9341_setRotation(uint8_t r);
|
||||||
void ili9341_test(int mode);
|
void ili9341_test(int mode);
|
||||||
void ili9341_bulk(int x, int y, int w, int h);
|
void ili9341_bulk(int x, int y, int w, int h);
|
||||||
void ili9341_fill(int x, int y, int w, int h, int color);
|
void ili9341_fill(int x, int y, int w, int h, int color);
|
||||||
void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg);
|
void setForegroundColor(uint16_t fg);
|
||||||
void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg);
|
void setBackgroundColor(uint16_t fg);
|
||||||
void ili9341_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool inv);
|
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap);
|
||||||
void ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
|
void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap);
|
||||||
void ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
|
void ili9341_drawchar(uint8_t ch, int x, int y);
|
||||||
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
|
void ili9341_drawstring(const char *str, int x, int y);
|
||||||
|
void ili9341_drawstringV(const char *str, int x, int y);
|
||||||
|
int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size);
|
||||||
|
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size);
|
||||||
|
void ili9341_drawfont(uint8_t ch, int x, int y);
|
||||||
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t* out);
|
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t* out);
|
||||||
void ili9341_read_memory_continue(int len, uint16_t* out);
|
void ili9341_line(int x0, int y0, int x1, int y1);
|
||||||
|
void show_version(void);
|
||||||
|
void show_logo(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* flash.c
|
* flash.c
|
||||||
|
|
@ -404,14 +453,4 @@ int16_t adc_vbat_read(ADC_TypeDef *adc);
|
||||||
*/
|
*/
|
||||||
#define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0)
|
#define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0)
|
||||||
|
|
||||||
// convert vbat [mV] to battery indicator
|
|
||||||
static inline uint8_t vbat2bati(int16_t vbat)
|
|
||||||
{
|
|
||||||
if (vbat < 3200) return 0;
|
|
||||||
if (vbat < 3450) return 25;
|
|
||||||
if (vbat < 3700) return 50;
|
|
||||||
if (vbat < 4100) return 75;
|
|
||||||
return 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*EOF*/
|
/*EOF*/
|
||||||
|
|
|
||||||
1086
numfont20x22.c
1086
numfont20x22.c
File diff suppressed because it is too large
Load diff
177
ui.c
177
ui.c
|
|
@ -305,7 +305,7 @@ void touch_wait_release(void)
|
||||||
} while(status != EVT_TOUCH_RELEASED);
|
} while(status != EVT_TOUCH_RELEASED);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void ili9341_line(int, int, int, int, int);
|
extern void ili9341_line(int, int, int, int);
|
||||||
|
|
||||||
void
|
void
|
||||||
touch_cal_exec(void)
|
touch_cal_exec(void)
|
||||||
|
|
@ -314,11 +314,12 @@ touch_cal_exec(void)
|
||||||
int x1, x2, y1, y2;
|
int x1, x2, y1, y2;
|
||||||
|
|
||||||
adc_stop(ADC1);
|
adc_stop(ADC1);
|
||||||
|
setForegroundColor(DEFAULT_FG_COLOR);
|
||||||
ili9341_fill(0, 0, 320, 240, 0);
|
setBackgroundColor(DEFAULT_BG_COLOR);
|
||||||
ili9341_line(0, 0, 0, 32, 0xffff);
|
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR);
|
||||||
ili9341_line(0, 0, 32, 0, 0xffff);
|
ili9341_line(0, 0, 0, 32);
|
||||||
ili9341_drawstring_5x7("TOUCH UPPER LEFT", 10, 10, 0xffff, 0x0000);
|
ili9341_line(0, 0, 32, 0);
|
||||||
|
ili9341_drawstring("TOUCH UPPER LEFT", 10, 10);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = touch_check();
|
status = touch_check();
|
||||||
|
|
@ -326,10 +327,10 @@ touch_cal_exec(void)
|
||||||
x1 = last_touch_x;
|
x1 = last_touch_x;
|
||||||
y1 = last_touch_y;
|
y1 = last_touch_y;
|
||||||
|
|
||||||
ili9341_fill(0, 0, 320, 240, 0);
|
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR);
|
||||||
ili9341_line(320-1, 240-1, 320-1, 240-32, 0xffff);
|
ili9341_line(320-1, 240-1, 320-1, 240-32);
|
||||||
ili9341_line(320-1, 240-1, 320-32, 240-1, 0xffff);
|
ili9341_line(320-1, 240-1, 320-32, 240-1);
|
||||||
ili9341_drawstring_5x7("TOUCH LOWER RIGHT", 230, 220, 0xffff, 0x0000);
|
ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = touch_check();
|
status = touch_check();
|
||||||
|
|
@ -355,8 +356,10 @@ touch_draw_test(void)
|
||||||
|
|
||||||
adc_stop(ADC1);
|
adc_stop(ADC1);
|
||||||
|
|
||||||
ili9341_fill(0, 0, 320, 240, 0);
|
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR);
|
||||||
ili9341_drawstring_5x7("TOUCH TEST: DRAG PANEL", OFFSETX, 233, 0xffff, 0x0000);
|
setForegroundColor(DEFAULT_FG_COLOR);
|
||||||
|
setBackgroundColor(DEFAULT_BG_COLOR);
|
||||||
|
ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, 233);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = touch_check();
|
status = touch_check();
|
||||||
|
|
@ -366,7 +369,7 @@ touch_draw_test(void)
|
||||||
do {
|
do {
|
||||||
status = touch_check();
|
status = touch_check();
|
||||||
touch_position(&x1, &y1);
|
touch_position(&x1, &y1);
|
||||||
ili9341_line(x0, y0, x1, y1, 0xffff);
|
ili9341_line(x0, y0, x1, y1);
|
||||||
x0 = x1;
|
x0 = x1;
|
||||||
y0 = y1;
|
y0 = y1;
|
||||||
chThdSleepMilliseconds(50);
|
chThdSleepMilliseconds(50);
|
||||||
|
|
@ -390,21 +393,23 @@ show_version(void)
|
||||||
int x = 5, y = 5;
|
int x = 5, y = 5;
|
||||||
|
|
||||||
adc_stop(ADC1);
|
adc_stop(ADC1);
|
||||||
ili9341_fill(0, 0, 320, 240, 0);
|
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR);
|
||||||
|
|
||||||
ili9341_drawstring_size(BOARD_NAME, x, y, 0xffff, 0x0000, 4);
|
setForegroundColor(DEFAULT_FG_COLOR);
|
||||||
|
setBackgroundColor(DEFAULT_BG_COLOR);
|
||||||
|
ili9341_drawstring_size(BOARD_NAME, x, y, 4);
|
||||||
y += 25;
|
y += 25;
|
||||||
|
|
||||||
ili9341_drawstring_5x7("2016-2019 Copyright @edy555", x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("2016-2019 Copyright @edy555", x, y += 10);
|
||||||
ili9341_drawstring_5x7("Licensed under GPL. See: https://github.com/ttrftech/NanoVNA", x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Licensed under GPL. See: https://github.com/ttrftech/NanoVNA", x, y += 10);
|
||||||
ili9341_drawstring_5x7("Version: " VERSION, x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Version: " VERSION, x, y += 10);
|
||||||
ili9341_drawstring_5x7("Build Time: " __DATE__ " - " __TIME__, x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Build Time: " __DATE__ " - " __TIME__, x, y += 10);
|
||||||
y += 5;
|
y += 5;
|
||||||
ili9341_drawstring_5x7("Kernel: " CH_KERNEL_VERSION, x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Kernel: " CH_KERNEL_VERSION, x, y += 10);
|
||||||
ili9341_drawstring_5x7("Compiler: " PORT_COMPILER_NAME, x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Compiler: " PORT_COMPILER_NAME, x, y += 10);
|
||||||
ili9341_drawstring_5x7("Architecture: " PORT_ARCHITECTURE_NAME " Core Variant: " PORT_CORE_VARIANT_NAME, x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Architecture: " PORT_ARCHITECTURE_NAME " Core Variant: " PORT_CORE_VARIANT_NAME, x, y += 10);
|
||||||
ili9341_drawstring_5x7("Port Info: " PORT_INFO, x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Port Info: " PORT_INFO, x, y += 10);
|
||||||
ili9341_drawstring_5x7("Platform: " PLATFORM_NAME, x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("Platform: " PLATFORM_NAME, x, y += 10);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (touch_check() == EVT_TOUCH_PRESSED)
|
if (touch_check() == EVT_TOUCH_PRESSED)
|
||||||
|
|
@ -422,11 +427,12 @@ enter_dfu(void)
|
||||||
adc_stop(ADC1);
|
adc_stop(ADC1);
|
||||||
|
|
||||||
int x = 5, y = 5;
|
int x = 5, y = 5;
|
||||||
|
setForegroundColor(DEFAULT_FG_COLOR);
|
||||||
|
setBackgroundColor(DEFAULT_BG_COLOR);
|
||||||
// leave a last message
|
// leave a last message
|
||||||
ili9341_fill(0, 0, 320, 240, 0);
|
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR);
|
||||||
ili9341_drawstring_5x7("DFU: Device Firmware Update Mode", x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("DFU: Device Firmware Update Mode", x, y += 10);
|
||||||
ili9341_drawstring_5x7("To exit DFU mode, please reset device yourself.", x, y += 10, 0xffff, 0x0000);
|
ili9341_drawstring("To exit DFU mode, please reset device yourself.", x, y += 10);
|
||||||
|
|
||||||
// see __early_init in ./NANOVNA_STM32_F072/board.c
|
// see __early_init in ./NANOVNA_STM32_F072/board.c
|
||||||
*((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = BOOT_FROM_SYTEM_MEMORY_MAGIC;
|
*((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = BOOT_FROM_SYTEM_MEMORY_MAGIC;
|
||||||
|
|
@ -453,6 +459,11 @@ static void menu_move_back(void);
|
||||||
static void
|
static void
|
||||||
menu_calop_cb(int item)
|
menu_calop_cb(int item)
|
||||||
{
|
{
|
||||||
|
static const uint8_t cal_type[]={CAL_OPEN, CAL_SHORT, CAL_LOAD, CAL_ISOLN, CAL_THRU};
|
||||||
|
if (item < 0 && item >= sizeof(cal_type))
|
||||||
|
return;
|
||||||
|
cal_collect(cal_type[item]);
|
||||||
|
/*
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case 0: // OPEN
|
case 0: // OPEN
|
||||||
cal_collect(CAL_OPEN);
|
cal_collect(CAL_OPEN);
|
||||||
|
|
@ -469,7 +480,7 @@ menu_calop_cb(int item)
|
||||||
case 4: // THRU
|
case 4: // THRU
|
||||||
cal_collect(CAL_THRU);
|
cal_collect(CAL_THRU);
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
selection = item+1;
|
selection = item+1;
|
||||||
draw_cal_status();
|
draw_cal_status();
|
||||||
draw_menu();
|
draw_menu();
|
||||||
|
|
@ -607,6 +618,11 @@ menu_trace_cb(int item)
|
||||||
static void
|
static void
|
||||||
menu_format_cb(int item)
|
menu_format_cb(int item)
|
||||||
{
|
{
|
||||||
|
static const uint8_t types[]={TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_SWR};
|
||||||
|
if (item < 0 && item >= sizeof(types))
|
||||||
|
return;
|
||||||
|
set_trace_type(uistat.current_trace, types[item]);
|
||||||
|
/*
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case 0:
|
case 0:
|
||||||
set_trace_type(uistat.current_trace, TRC_LOGMAG);
|
set_trace_type(uistat.current_trace, TRC_LOGMAG);
|
||||||
|
|
@ -623,7 +639,7 @@ menu_format_cb(int item)
|
||||||
case 4:
|
case 4:
|
||||||
set_trace_type(uistat.current_trace, TRC_SWR);
|
set_trace_type(uistat.current_trace, TRC_SWR);
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
request_to_redraw_grid();
|
request_to_redraw_grid();
|
||||||
ui_mode_normal();
|
ui_mode_normal();
|
||||||
|
|
@ -633,6 +649,11 @@ menu_format_cb(int item)
|
||||||
static void
|
static void
|
||||||
menu_format2_cb(int item)
|
menu_format2_cb(int item)
|
||||||
{
|
{
|
||||||
|
static const uint8_t types[]={TRC_POLAR, TRC_LINEAR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X};
|
||||||
|
if (item < 0 && item >= sizeof(types))
|
||||||
|
return;
|
||||||
|
set_trace_type(uistat.current_trace, types[item]);
|
||||||
|
/*
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case 0:
|
case 0:
|
||||||
set_trace_type(uistat.current_trace, TRC_POLAR);
|
set_trace_type(uistat.current_trace, TRC_POLAR);
|
||||||
|
|
@ -652,7 +673,7 @@ menu_format2_cb(int item)
|
||||||
case 5:
|
case 5:
|
||||||
set_trace_type(uistat.current_trace, TRC_X);
|
set_trace_type(uistat.current_trace, TRC_X);
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
request_to_redraw_grid();
|
request_to_redraw_grid();
|
||||||
ui_mode_normal();
|
ui_mode_normal();
|
||||||
|
|
@ -1335,8 +1356,10 @@ draw_keypad(void)
|
||||||
uint16_t bg = config.menu_normal_color;
|
uint16_t bg = config.menu_normal_color;
|
||||||
if (i == selection)
|
if (i == selection)
|
||||||
bg = config.menu_active_color;
|
bg = config.menu_active_color;
|
||||||
|
setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
|
||||||
|
setBackgroundColor(bg);
|
||||||
ili9341_fill(keypads[i].x, keypads[i].y, 44, 44, bg);
|
ili9341_fill(keypads[i].x, keypads[i].y, 44, 44, bg);
|
||||||
ili9341_drawfont(keypads[i].c, &NF20x22, keypads[i].x+12, keypads[i].y+10, 0x0000, bg);
|
ili9341_drawfont(keypads[i].c, keypads[i].x+14, keypads[i].y+10);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1344,9 +1367,11 @@ draw_keypad(void)
|
||||||
void
|
void
|
||||||
draw_numeric_area_frame(void)
|
draw_numeric_area_frame(void)
|
||||||
{
|
{
|
||||||
ili9341_fill(0, 208, 320, 32, 0xffff);
|
ili9341_fill(0, 208, 320, 32, DEFAULT_MENU_COLOR);
|
||||||
ili9341_drawstring_5x7(keypad_mode_label[keypad_mode], 10, 220, 0x0000, 0xffff);
|
setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
|
||||||
//ili9341_drawfont(KP_KEYPAD, &NF20x22, 300, 216, 0x0000, 0xffff);
|
setBackgroundColor(DEFAULT_MENU_COLOR);
|
||||||
|
ili9341_drawstring(keypad_mode_label[keypad_mode], 10, 220);
|
||||||
|
//ili9341_drawfont(KP_KEYPAD, 300, 216);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -1355,10 +1380,11 @@ draw_numeric_input(const char *buf)
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int x = 64;
|
int x = 64;
|
||||||
int focused = FALSE;
|
int focused = FALSE;
|
||||||
const uint16_t xsim[] = { 0, 0, 8, 0, 0, 8, 0, 0, 0, 0 };
|
uint16_t xsim = 0b0010010000000000;
|
||||||
for (i = 0; i < 10 && buf[i]; i++) {
|
|
||||||
uint16_t fg = 0x0000;
|
for (i = 0; i < 10 && buf[i]; i++, xsim<<=1) {
|
||||||
uint16_t bg = 0xffff;
|
uint16_t fg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
|
uint16_t bg = DEFAULT_MENU_COLOR;
|
||||||
int c = buf[i];
|
int c = buf[i];
|
||||||
if (c == '.')
|
if (c == '.')
|
||||||
c = KP_PERIOD;
|
c = KP_PERIOD;
|
||||||
|
|
@ -1373,24 +1399,21 @@ draw_numeric_input(const char *buf)
|
||||||
fg = RGB565(128,255,128);
|
fg = RGB565(128,255,128);
|
||||||
focused = TRUE;
|
focused = TRUE;
|
||||||
if (uistat.digit_mode)
|
if (uistat.digit_mode)
|
||||||
bg = 0x0000;
|
bg = DEFAULT_MENU_COLOR;
|
||||||
}
|
}
|
||||||
|
setForegroundColor(fg);
|
||||||
|
setBackgroundColor(bg);
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
ili9341_drawfont(c, &NF20x22, x, 208+4, fg, bg);
|
ili9341_drawfont(c, x, 208+4);
|
||||||
else if (focused)
|
else if (focused)
|
||||||
ili9341_drawfont(0, &NF20x22, x, 208+4, fg, bg);
|
ili9341_drawfont(0, x, 208+4);
|
||||||
else
|
else
|
||||||
ili9341_fill(x, 208+4, 20, 24, bg);
|
ili9341_fill(x, 208+4, 20, 24, bg);
|
||||||
|
|
||||||
x += 20;
|
x += xsim&0x8000 ? 18+8 : 18;
|
||||||
if (xsim[i] > 0) {
|
|
||||||
//ili9341_fill(x, 208+4, xsim[i], 20, bg);
|
|
||||||
x += xsim[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (i < 10) {
|
if (i < 10) {
|
||||||
ili9341_fill(x, 208+4, 20*(10-i), 24, 0xffff);
|
ili9341_fill(x, 208+4, 20*(10-i), 24, DEFAULT_MENU_COLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1415,24 +1438,25 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
|
||||||
} else if (menu == menu_marker_sel) {
|
} else if (menu == menu_marker_sel) {
|
||||||
if (item < 4) {
|
if (item < 4) {
|
||||||
if (markers[item].enabled) {
|
if (markers[item].enabled) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
} else if (item == 5) {
|
} else if (item == 5) {
|
||||||
if (uistat.marker_delta) {
|
if (uistat.marker_delta) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (menu == menu_marker_search) {
|
} else if (menu == menu_marker_search) {
|
||||||
if (item == 4 && marker_tracking) {
|
if (item == 4 && marker_tracking) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
} else if (menu == menu_marker_smith) {
|
} else if (menu == menu_marker_smith) {
|
||||||
|
|
||||||
if (marker_smith_format == item) {
|
if (marker_smith_format == item) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
} else if (menu == menu_calop) {
|
} else if (menu == menu_calop) {
|
||||||
if ((item == 0 && (cal_status & CALSTAT_OPEN))
|
if ((item == 0 && (cal_status & CALSTAT_OPEN))
|
||||||
|
|
@ -1441,18 +1465,18 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
|
||||||
|| (item == 3 && (cal_status & CALSTAT_ISOLN))
|
|| (item == 3 && (cal_status & CALSTAT_ISOLN))
|
||||||
|| (item == 4 && (cal_status & CALSTAT_THRU))) {
|
|| (item == 4 && (cal_status & CALSTAT_THRU))) {
|
||||||
domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ;
|
domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ;
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
} else if (menu == menu_stimulus) {
|
} else if (menu == menu_stimulus) {
|
||||||
if (item == 5 /* PAUSE */ && !sweep_enabled) {
|
if (item == 5 /* PAUSE */ && !sweep_enabled) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
} else if (menu == menu_cal) {
|
} else if (menu == menu_cal) {
|
||||||
if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY)) {
|
if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY)) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
} else if (menu == menu_transform) {
|
} else if (menu == menu_transform) {
|
||||||
if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME)
|
if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME)
|
||||||
|
|
@ -1460,16 +1484,16 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
|
||||||
|| (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP)
|
|| (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP)
|
||||||
|| (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS)
|
|| (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS)
|
||||||
) {
|
) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
} else if (menu == menu_transform_window) {
|
} else if (menu == menu_transform_window) {
|
||||||
if ((item == 0 && (domain_mode & TD_WINDOW) == TD_WINDOW_MINIMUM)
|
if ((item == 0 && (domain_mode & TD_WINDOW) == TD_WINDOW_MINIMUM)
|
||||||
|| (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL)
|
|| (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL)
|
||||||
|| (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM)
|
|| (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM)
|
||||||
) {
|
) {
|
||||||
*bg = 0x0000;
|
*bg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
*fg = 0xffff;
|
*fg = config.menu_normal_color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1486,18 +1510,22 @@ draw_menu_buttons(const menuitem_t *menu)
|
||||||
continue;
|
continue;
|
||||||
int y = 32*i;
|
int y = 32*i;
|
||||||
uint16_t bg = config.menu_normal_color;
|
uint16_t bg = config.menu_normal_color;
|
||||||
uint16_t fg = 0x0000;
|
uint16_t fg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
// focus only in MENU mode but not in KEYPAD mode
|
// focus only in MENU mode but not in KEYPAD mode
|
||||||
if (ui_mode == UI_MENU && i == selection)
|
if (ui_mode == UI_MENU && i == selection)
|
||||||
bg = config.menu_active_color;
|
bg = config.menu_active_color;
|
||||||
ili9341_fill(320-60, y, 60, 30, bg);
|
ili9341_fill(320-60, y, 60, 30, bg);
|
||||||
|
|
||||||
menu_item_modify_attribute(menu, i, &fg, &bg);
|
menu_item_modify_attribute(menu, i, &fg, &bg);
|
||||||
|
setForegroundColor(fg);
|
||||||
|
setBackgroundColor(bg);
|
||||||
if (menu_is_multiline(menu[i].label, &l1, &l2)) {
|
if (menu_is_multiline(menu[i].label, &l1, &l2)) {
|
||||||
ili9341_drawstring_5x7(l1, 320-54, y+8, fg, bg);
|
ili9341_fill(320-57, y+6, 54, 19, bg);
|
||||||
ili9341_drawstring_5x7(l2, 320-54, y+15, fg, bg);
|
ili9341_drawstring(l1, 320-55, y+8);
|
||||||
|
ili9341_drawstring(l2, 320-55, y+16);
|
||||||
} else {
|
} else {
|
||||||
ili9341_drawstring_5x7(menu[i].label, 320-54, y+12, fg, bg);
|
ili9341_fill(320-57, y+10, 54, 11, bg);
|
||||||
|
ili9341_drawstring(menu[i].label, 320-55, y+12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1546,8 +1574,7 @@ draw_menu(void)
|
||||||
void
|
void
|
||||||
erase_menu_buttons(void)
|
erase_menu_buttons(void)
|
||||||
{
|
{
|
||||||
uint16_t bg = 0;
|
ili9341_fill(320-60, 0, 60, 32*7, DEFAULT_BG_COLOR);
|
||||||
ili9341_fill(320-60, 0, 60, 32*7, bg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -1667,7 +1694,7 @@ ui_mode_menu(void)
|
||||||
ui_mode = UI_MENU;
|
ui_mode = UI_MENU;
|
||||||
/* narrowen plotting area */
|
/* narrowen plotting area */
|
||||||
area_width = AREA_WIDTH_NORMAL - (64-8);
|
area_width = AREA_WIDTH_NORMAL - (64-8);
|
||||||
area_height = HEIGHT;
|
area_height = HEIGHT+1;
|
||||||
ensure_selection();
|
ensure_selection();
|
||||||
draw_menu();
|
draw_menu();
|
||||||
}
|
}
|
||||||
|
|
@ -1721,7 +1748,7 @@ ui_mode_normal(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
area_width = AREA_WIDTH_NORMAL;
|
area_width = AREA_WIDTH_NORMAL;
|
||||||
area_height = HEIGHT;
|
area_height = HEIGHT+1;
|
||||||
leave_ui_mode();
|
leave_ui_mode();
|
||||||
ui_mode = UI_NORMAL;
|
ui_mode = UI_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue