image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
FlashHelper.c File Reference

Eve's connected flash helper functions. More...

#include "FlashHelper.h"
#include "Gpu_Hal.h"

Go to the source code of this file.

Functions

ft_bool_t Esd_Calibrate (EVE_HalContext *phost)
 Do calibration.
 
ft_void_t Ft_Gpu_HorizontalScanoutFilter (EVE_HalContext *phost, uint32_t physical_W, uint32_t physical_H)
 Adjust for non-sqare pixel panel.
 
void App_WrDl_Buffer (Gpu_Hal_Context_t *phost, uint32_t cmd)
 Write DL command to buffer.
 
void App_Flush_DL_Buffer (const Gpu_Hal_Context_t *phost)
 Flush DL buffer to Coprocessor.
 
void App_Set_DlBuffer_Index (uint32_t index)
 Set DL buffer index.
 
void GPU_DLSwap (Gpu_Hal_Context_t *phost, uint8_t DL_Swap_Type)
 API to check the status of previous DLSWAP and perform DLSWAP of new DL Check for the status of previous DLSWAP and if still not done wait for few ms and check again.
 
void fadeout (EVE_HalContext *phost)
 Fadeout animation.
 
void fadein (EVE_HalContext *phost)
 Fadein animation perform display fadein effect by changing the display PWM from 0 till 100 and finally 128.
 
void Fifo_Init (Fifo_t *pFifo, uint32_t StartAddress, uint32_t Length, uint32_t HWReadRegAddress, uint32_t HWWriteRegAddress)
 Init mediafifo.
 
void Fifo_Update (Gpu_Hal_Context_t *host, Fifo_t *pFifo)
 update both the read and write pointers
 
uint32_t Fifo_Write (Gpu_Hal_Context_t *host, Fifo_t *pFifo, const uint8_t *buffer, uint32_t NumbytetoWrite)
 write and update the write register
 
void Fifo_WriteWait (Gpu_Hal_Context_t *host, Fifo_t *pFifo, const uint8_t *buffer, uint32_t Numbyte)
 write and wait for the fifo to be empty. handle cases even if the Numbytes are more than freespace
 
void Fifo_Write32 (Gpu_Hal_Context_t *host, Fifo_t *pFifo, uint32_t WriteWord)
 write one word and update the write register
 
uint32_t Fifo_GetFreeSpace (Gpu_Hal_Context_t *host, Fifo_t *pFifo)
 get the free space in the fifo
 
int32_t FlashHelper_GetSizeMB (Gpu_Hal_Context_t *phost)
 

Variables

uint32_t DlBuffer_Index
 

Detailed Description

Eve's connected flash helper functions.

Author
Tuan Nguyen tuan..nosp@m.nguy.nosp@m.en@br.nosp@m.tchi.nosp@m.p.com
Date
2019

MIT License

Copyright (c) [2019] [Bridgetek Pte Ltd (BRTChip)]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file FlashHelper.c.

Function Documentation

◆ App_Flush_DL_Buffer()

void App_Flush_DL_Buffer ( const Gpu_Hal_Context_t phost)

Flush DL buffer to Coprocessor.

Parameters
phostPointer to Hal context

Definition at line 471 of file FlashHelper.c.

472{
473#ifdef BUFFER_OPTIMIZATION
474 if (DlBuffer_Index > 0)
475 EVE_Hal_wrMem(phost, RAM_DL, DlBuffer, DlBuffer_Index); /* Not legal on big endian CPU */
476#endif
477 DlBuffer_Index = 0;
478}
#define RAM_DL
Definition EVE_GpuDefs.h:95
EVE_HAL_EXPORT void EVE_Hal_wrMem(EVE_HalContext *phost, uint32_t addr, const uint8_t *buffer, uint32_t size)
Write a buffer to Coprocessor's memory.
Definition EVE_Hal.c:263
uint32_t DlBuffer_Index

◆ App_Set_DlBuffer_Index()

void App_Set_DlBuffer_Index ( uint32_t  index)

Set DL buffer index.

Parameters
index

Definition at line 485 of file FlashHelper.c.

486{
487 DlBuffer_Index = index;
488}

◆ App_WrDl_Buffer()

void App_WrDl_Buffer ( Gpu_Hal_Context_t phost,
uint32_t  cmd 
)

Write DL command to buffer.

Parameters
phostPointer to Hal context
cmdDL command

Definition at line 444 of file FlashHelper.c.

445{
446#ifdef BUFFER_OPTIMIZATION
447 /* Copy the command instruction into buffer */
448 uint32_t* pBuffcmd;
449 /* Prevent buffer overflow */
450 if (DlBuffer_Index < DL_SIZE)
451 {
452 pBuffcmd = (uint32_t*)&DlBuffer[DlBuffer_Index];
453 *pBuffcmd = cmd;
454 }
455 else
456 {
457 printf("DlBuffer overflow\n");
458 }
459#else
461#endif
462 /* Increment the command index */
464}
EVE_HAL_EXPORT void EVE_Hal_wr32(EVE_HalContext *phost, uint32_t addr, uint32_t v)
Write 4 bytes to Coprocessor's memory.
Definition EVE_Hal.c:248
unsigned int uint32_t
static ft_void_t ft_uint32_t * cmd
Definition FT_Gpu_Hal.h:184
#define CMD_SIZE
Definition Gpu_Hal.h:77

◆ Esd_Calibrate()

ft_bool_t Esd_Calibrate ( EVE_HalContext phost)

Do calibration.

Returns
ft_bool_t True on successfull or otherwise

Definition at line 42 of file FlashHelper.c.

43{
44 ft_uint32_t result;
45 ft_uint32_t transMatrix[6];
46#if defined(EVE_SUPPORT_CAPACITIVE)
48#else
50#endif
51
52 eve_printf_debug("App_CoPro_Widget_Calibrate: Start\n");
53
54 EVE_CoCmd_dlStart(phost);
55 EVE_Cmd_wr32(phost, CLEAR_COLOR_RGB(64, 64, 64));
56 EVE_Cmd_wr32(phost, CLEAR(1, 1, 1));
57 EVE_Cmd_wr32(phost, COLOR_RGB(0xff, 0xff, 0xff));
58
59 EVE_CoCmd_text(phost, (uint16_t)(phost->Width / 2), (uint16_t)(phost->Height / 2), 27, OPT_CENTER, "Please Tap on the dot");
60
61 result = EVE_CoCmd_calibrate(phost);
62 EVE_Cmd_waitFlush(phost);
63
64 eve_printf_debug("App_CoPro_Widget_Calibrate: End\n");
65
66 // Print the configured values
67 EVE_Hal_rdMem(phost, (ft_uint8_t*)transMatrix, REG_TOUCH_TRANSFORM_A, 4 * 6); //read all the 6 coefficients
68 eve_printf_debug("Touch screen transform values are A 0x%x,B 0x%x,C 0x%x,D 0x%x,E 0x%x, F 0x%x\n",
69 transMatrix[0], transMatrix[1], transMatrix[2], transMatrix[3], transMatrix[4], transMatrix[5]);
70
71 return result != 0;
72}
EVE_HAL_EXPORT bool EVE_Cmd_wr32(EVE_HalContext *phost, uint32_t value)
Write 4 bytes to Coprocessor's command fifo.
Definition EVE_Cmd.c:394
EVE_HAL_EXPORT uint32_t EVE_CoCmd_calibrate(EVE_HalContext *phost)
Send CMD_CALIBRATE.
Definition EVE_CoCmd.c:500
EVE_HAL_EXPORT void EVE_CoCmd_text(EVE_HalContext *phost, int16_t x, int16_t y, int16_t font, uint16_t options, const char *s,...)
Send CMD_TEXT.
static void EVE_CoCmd_dlStart(EVE_HalContext *phost)
Send CMD_DLSTART.
Definition EVE_CoCmd.h:159
#define CTOUCH_MODE_COMPATIBILITY
#define CLEAR(c, s, t)
#define ADC_DIFFERENTIAL
#define REG_TOUCH_ADC_MODE
#define COLOR_RGB(red, green, blue)
#define OPT_CENTER
#define REG_CTOUCH_EXTENDED
#define REG_TOUCH_TRANSFORM_A
#define CLEAR_COLOR_RGB(red, green, blue)
EVE_HAL_EXPORT void EVE_Hal_rdMem(EVE_HalContext *phost, uint8_t *result, uint32_t addr, uint32_t size)
Read a block data from Coprocessor's memory.
Definition EVE_Hal.c:206
EVE_HAL_EXPORT void EVE_Hal_wr8(EVE_HalContext *phost, uint32_t addr, uint8_t v)
Write 8 bits to Coprocessor's memory.
Definition EVE_Hal.c:220
unsigned short uint16_t
#define eve_printf_debug(fmt,...)
#define ft_uint32_t
Definition FT_Gpu_Hal.h:54
#define ft_uint8_t
Definition FT_Gpu_Hal.h:50
void EVE_Cmd_waitFlush(EVE_HalContext *host)
Definition Gpu_Hal.cpp:775
uint32_t Height

◆ fadein()

void fadein ( EVE_HalContext phost)

Fadein animation perform display fadein effect by changing the display PWM from 0 till 100 and finally 128.

Parameters
phostPointer to Hal context

Definition at line 542 of file FlashHelper.c.

543{
544 for (int8_t i = 0; i <= 100; i += 3)
545 {
546 EVE_Hal_wr8(phost, REG_PWM_DUTY, i);
547 EVE_sleep(2);//sleep for 2 ms
548 }
549 /* Finally make the PWM 100% */
550 uint8_t i = 128;
551 EVE_Hal_wr8(phost, REG_PWM_DUTY, i);
552}
#define REG_PWM_DUTY
EVE_HAL_EXPORT void EVE_sleep(uint32_t ms)
Sleep in milisecond.
unsigned char uint8_t
signed char int8_t

◆ fadeout()

void fadeout ( EVE_HalContext phost)

Fadeout animation.

Parameters
phostPointer to Hal context

Definition at line 527 of file FlashHelper.c.

528{
529 for (int8_t i = 100; i >= 0; i -= 3)
530 {
531 EVE_Hal_wr8(phost, REG_PWM_DUTY, i);
532 EVE_sleep(2);//sleep for 2 ms
533 }
534}

◆ Fifo_GetFreeSpace()

uint32_t Fifo_GetFreeSpace ( Gpu_Hal_Context_t host,
Fifo_t pFifo 
)

get the free space in the fifo

Parameters
hostPointer to Hal context
pFifoFifo pointer
Returns
uint32_t

Definition at line 701 of file FlashHelper.c.

702{
703 uint32_t FreeSpace = 0;
704
705 Fifo_Update(host, pFifo);
706
707 if (pFifo->fifo_wp >= pFifo->fifo_rp)
708 {
709 FreeSpace = pFifo->fifo_len - pFifo->fifo_wp + pFifo->fifo_rp;
710 }
711 else
712 {
713 FreeSpace = pFifo->fifo_rp - pFifo->fifo_wp;
714 }
715
716 if (FreeSpace >= 4)
717 {
718 FreeSpace -= 4;//make sure 1 word space is maintained between rd and wr pointers
719 }
720 return FreeSpace;
721}
void Fifo_Update(Gpu_Hal_Context_t *host, Fifo_t *pFifo)
update both the read and write pointers
int32_t fifo_len
Definition Gpu_Hal.h:155
int32_t fifo_wp
Definition Gpu_Hal.h:156
int32_t fifo_rp
Definition Gpu_Hal.h:157

◆ Fifo_Init()

void Fifo_Init ( Fifo_t pFifo,
uint32_t  StartAddress,
uint32_t  Length,
uint32_t  HWReadRegAddress,
uint32_t  HWWriteRegAddress 
)

Init mediafifo.

Parameters
pFifoFifo pointer
StartAddressAddress on RAM_G
LengthFifo length
HWReadRegAddressREG_MEDIAFIFO_READ
HWWriteRegAddressREG_MEDIAFIFO_WRITE

Definition at line 563 of file FlashHelper.c.

564{
565 /* update the context parameters */
566 pFifo->fifo_buff = StartAddress;
567 pFifo->fifo_len = Length;
568 pFifo->fifo_rp = pFifo->fifo_wp = 0;
569
570 /* update the hardware register addresses - specific to FT800 series chips */
571 pFifo->HW_Read_Reg = HWReadRegAddress;
572 pFifo->HW_Write_Reg = HWWriteRegAddress;
573}
uint32_t fifo_buff
Definition Gpu_Hal.h:154
uint32_t HW_Write_Reg
Definition Gpu_Hal.h:161
uint32_t HW_Read_Reg
Definition Gpu_Hal.h:160

◆ Fifo_Update()

void Fifo_Update ( Gpu_Hal_Context_t host,
Fifo_t pFifo 
)

update both the read and write pointers

Parameters
hostPointer to Hal context
pFifoFifo poiner

Definition at line 581 of file FlashHelper.c.

582{
583 pFifo->fifo_rp = EVE_Hal_rd32(host, pFifo->HW_Read_Reg);
584}
EVE_HAL_EXPORT uint32_t EVE_Hal_rd32(EVE_HalContext *phost, uint32_t addr)
Read 4 bytes from Coprocessor's memory.
Definition EVE_Hal.c:189

◆ Fifo_Write()

uint32_t Fifo_Write ( Gpu_Hal_Context_t host,
Fifo_t pFifo,
const uint8_t buffer,
uint32_t  NumbytetoWrite 
)

write and update the write register

Parameters
hostPointer to Hal context
pFifoFifo pointer
buffer
NumbytetoWrite
Returns
uint32_t

Definition at line 595 of file FlashHelper.c.

596{
597 uint32_t FreeSpace = Fifo_GetFreeSpace(host, pFifo);
598 uint32_t TotalBytes = NumbytetoWrite;
599
600 if (NumbytetoWrite > FreeSpace)
601 {
602 /* update the read pointer and get the free space */
603 Fifo_Update(host, pFifo);
604 FreeSpace = Fifo_GetFreeSpace(host, pFifo);
605
606 if (NumbytetoWrite > FreeSpace)
607 {
608 TotalBytes = FreeSpace;
609 }
610 }
611
612 /* sanity check */
613 if (TotalBytes <= 0)
614 {
615 return 0;//error condition
616 }
617 /* check for the loopback conditions */
618 if ((pFifo->fifo_wp + (int32_t)TotalBytes) >= pFifo->fifo_len)
619 {
620 uint32_t partialchunk = pFifo->fifo_len - pFifo->fifo_wp;
621 uint32_t secpartialchunk = TotalBytes - partialchunk;
622
623 EVE_Hal_wrMem(host, pFifo->fifo_buff + pFifo->fifo_wp, buffer, partialchunk);
624 if (secpartialchunk > 0)
625 {
626 EVE_Hal_wrMem(host, pFifo->fifo_buff, buffer + partialchunk, secpartialchunk);
627 }
628 pFifo->fifo_wp = secpartialchunk;
629
630 }
631 else
632 {
633 EVE_Hal_wrMem(host, pFifo->fifo_buff + pFifo->fifo_wp, buffer, TotalBytes);
634 pFifo->fifo_wp += TotalBytes;
635 }
636
637 /* update the write pointer address in write register */
638 EVE_Hal_wr32(host, pFifo->HW_Write_Reg, pFifo->fifo_wp);
639
640 return TotalBytes;
641}
int int32_t
static ft_uint32_t ft_uint8_t * buffer
Definition FT_Gpu_Hal.h:139
uint32_t Fifo_GetFreeSpace(Gpu_Hal_Context_t *host, Fifo_t *pFifo)
get the free space in the fifo

◆ Fifo_Write32()

void Fifo_Write32 ( Gpu_Hal_Context_t host,
Fifo_t pFifo,
uint32_t  WriteWord 
)

write one word and update the write register

Parameters
hostPointer to Hal context
pFifoFifo pointer
WriteWordWord to write

Definition at line 689 of file FlashHelper.c.

690{
691 Fifo_WriteWait(host, pFifo, (uint8_t*)&WriteWord, 4);
692}
void Fifo_WriteWait(Gpu_Hal_Context_t *host, Fifo_t *pFifo, const uint8_t *buffer, uint32_t Numbyte)
write and wait for the fifo to be empty. handle cases even if the Numbytes are more than freespace

◆ Fifo_WriteWait()

void Fifo_WriteWait ( Gpu_Hal_Context_t host,
Fifo_t pFifo,
const uint8_t buffer,
uint32_t  Numbyte 
)

write and wait for the fifo to be empty. handle cases even if the Numbytes are more than freespace

Parameters
hostPointer to Hal context
pFifoFifo pointer
buffer
Numbyte

Definition at line 659 of file FlashHelper.c.

660{
661 uint32_t TotalBytes = Numbyte;
662 uint32_t currchunk = 0;
663 uint32_t FreeSpace;
664 const uint8_t* pbuff = buffer;
665 /* blocking call, manage to check for the error case and break in case of error */
666 while (TotalBytes > 0)
667 {
668 currchunk = TotalBytes;
669 FreeSpace = Fifo_GetFreeSpace(host, pFifo);
670 if (currchunk > FreeSpace)
671 {
672 currchunk = FreeSpace;
673 }
674
675 Fifo_Write(host, pFifo, pbuff, currchunk);
676 pbuff += currchunk;
677 TotalBytes -= currchunk;
678
679 }
680}
uint32_t Fifo_Write(Gpu_Hal_Context_t *host, Fifo_t *pFifo, const uint8_t *buffer, uint32_t NumbytetoWrite)
write and update the write register

◆ FlashHelper_GetSizeMB()

int32_t FlashHelper_GetSizeMB ( Gpu_Hal_Context_t phost)

Definition at line 723 of file FlashHelper.c.

724{
725 uint8_t status = Gpu_Hal_Rd8(phost, REG_FLASH_STATUS);
726
727 if (status == FLASH_STATUS_DETACHED)
728 {
730 App_Flush_Co_Buffer(phost);
732 status = Gpu_Hal_Rd8(phost, REG_FLASH_STATUS);
733
734 if (FLASH_STATUS_BASIC != status)
735 {
736 printf("Error, Flash is not able to attach\n");
737 return -1;
738 }
739 }
740 int32_t size = Gpu_Hal_Rd32(phost, REG_FLASH_SIZE);
741
742 return size;
743}
#define FLASH_STATUS_BASIC
#define REG_FLASH_SIZE
#define FLASH_STATUS_DETACHED
#define REG_FLASH_STATUS
#define Gpu_CoCmd_FlashAttach
Definition Gpu_CoCmd.h:71
#define Gpu_Hal_Rd32
Definition Gpu_Hal.h:206
#define Gpu_Hal_WaitCmdfifo_empty
Definition Gpu_Hal.h:240
#define App_Flush_Co_Buffer(phost)
Definition Gpu_Hal.h:439
#define Gpu_Hal_Rd8
Definition Gpu_Hal.h:204

◆ Ft_Gpu_HorizontalScanoutFilter()

ft_void_t Ft_Gpu_HorizontalScanoutFilter ( EVE_HalContext phost,
uint32_t  physical_W,
uint32_t  physical_H 
)

Adjust for non-sqare pixel panel.

Parameters
phostPointer to Hal context
physical_WPanel width in inches
physical_HPanel height in inches
Returns
ft_void_t

Definition at line 385 of file FlashHelper.c.

385 {
386 uint32_t eve_W = phost->Width;
387 uint32_t eve_H = phost->Height;
388 uint32_t logical_W = eve_H * physical_W / physical_H;
389
390 // Configure panel
391 EVE_Hal_wr32(phost, REG_HSIZE, logical_W);
392 EVE_CoCmd_hsf(phost, eve_W);
393}
#define EVE_CoCmd_hsf(phost, hsf)
Definition EVE_CoCmd.h:351
#define REG_HSIZE

◆ GPU_DLSwap()

void GPU_DLSwap ( Gpu_Hal_Context_t phost,
uint8_t  DL_Swap_Type 
)

API to check the status of previous DLSWAP and perform DLSWAP of new DL Check for the status of previous DLSWAP and if still not done wait for few ms and check again.

Parameters
phostPointer to Hal context
DL_Swap_TypeDL list swap type

Definition at line 497 of file FlashHelper.c.

498{
499 uint8_t Swap_Type = DLSWAP_FRAME;
500 uint8_t Swap_Done = DLSWAP_FRAME;
501
502 if (DL_Swap_Type == DLSWAP_LINE)
503 {
504 Swap_Type = DLSWAP_LINE;
505 }
506
507 /* Perform a new DL swap */
508 EVE_Hal_wr8(phost, REG_DLSWAP, Swap_Type);
509
510 /* Wait till the swap is done */
511 while (Swap_Done)
512 {
513 Swap_Done = EVE_Hal_rd8(phost, REG_DLSWAP);
514
515 if (DLSWAP_DONE != Swap_Done)
516 {
517 EVE_sleep(10);//wait for 10ms
518 }
519 }
520}
#define DLSWAP_DONE
#define DLSWAP_LINE
#define REG_DLSWAP
#define DLSWAP_FRAME
EVE_HAL_EXPORT uint8_t EVE_Hal_rd8(EVE_HalContext *phost, uint32_t addr)
Read 8 bits from Coprocessor's memory.
Definition EVE_Hal.c:157

Variable Documentation

◆ DlBuffer_Index

uint32_t DlBuffer_Index

Definition at line 432 of file FlashHelper.c.