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
EVE_HalImpl.h File Reference

Eve_Hal framework APIs. More...

#include "EVE_HalDefs.h"

Go to the source code of this file.

Functions

INIT
void EVE_HalImpl_initialize ()
 Initialize HAL platform.
 
void EVE_HalImpl_release ()
 Release HAL platform.
 
bool EVE_HalImpl_defaults (EVE_HalParameters *parameters, size_t deviceIdx)
 Get the default configuration parameters.
 
bool EVE_HalImpl_open (EVE_HalContext *phost, const EVE_HalParameters *parameters)
 Opens a new HAL context using the specified parameters.
 
void EVE_HalImpl_close (EVE_HalContext *phost)
 Close a HAL context.
 
void EVE_HalImpl_idle (EVE_HalContext *phost)
 Idle. Call regularly to update frequently changing internal state.
 
TRANSFER
EVE_HAL_EXPORT void EVE_Hal_startTransfer (EVE_HalContext *phost, EVE_TRANSFER_T rw, uint32_t addr)
 Start data transfer to Coprocessor.
 
EVE_HAL_EXPORT void EVE_Hal_endTransfer (EVE_HalContext *phost)
 End data transfer.
 
EVE_HAL_EXPORT uint8_t EVE_Hal_transfer8 (EVE_HalContext *phost, uint8_t value)
 Write 8 bits to Coprocessor.
 
EVE_HAL_EXPORT uint16_t EVE_Hal_transfer16 (EVE_HalContext *phost, uint16_t value)
 Write 2 bytes to Coprocessor.
 
EVE_HAL_EXPORT uint32_t EVE_Hal_transfer32 (EVE_HalContext *phost, uint32_t value)
 Write 4 bytes to Coprocessor.
 
EVE_HAL_EXPORT void EVE_Hal_flush (EVE_HalContext *phost)
 Flush data to Coprocessor.
 
MISC
void EVE_Mcu_initialize ()
 Init FT9x host MCU.
 
void EVE_Mcu_release ()
 Release FT9x host MCU.
 
void EVE_Millis_initialize ()
 Init FT9x timer.
 
void EVE_Millis_release ()
 Release FT9x timer.
 
EVE_HAL_EXPORT uint32_t EVE_millis ()
 Get clock in miliseond.
 
EVE_HAL_EXPORT uint64_t EVE_millis64 ()
 Get clock in miliseond.
 
bool EVE_UtilImpl_bootupDisplayGpio (EVE_HalContext *phost)
 Display GPIO pins.
 

Variables

EVE_HalPlatform g_HalPlatform
 

Detailed Description

Eve_Hal framework APIs.

This file defines the generic APIs of phost access layer for the FT800 or EVE compatible silicon. Application shall access FT800 or EVE resources over these APIs,regardless of I2C or SPI protocol. In addition, there are some helper functions defined for FT800 coprocessor engine as well as phost commands.

Author
Bridgetek
Date
2018

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 EVE_HalImpl.h.

Function Documentation

◆ EVE_Hal_endTransfer()

EVE_HAL_EXPORT void EVE_Hal_endTransfer ( EVE_HalContext phost)

End data transfer.

Parameters
phostPointer to Hal context

Definition at line 291 of file EVE_HalImpl_FT9XX.c.

292{
294
295 spi_close(SPIM, phost->SpiCsPin);
296 phost->Status = EVE_STATUS_OPENED;
297}
@ EVE_STATUS_READING
Definition EVE_HalDefs.h:59
@ EVE_STATUS_OPENED
Definition EVE_HalDefs.h:58
@ EVE_STATUS_WRITING
Definition EVE_HalDefs.h:60
#define eve_assert(cond)
EVE_STATUS_T Status

◆ EVE_Hal_flush()

EVE_HAL_EXPORT void EVE_Hal_flush ( EVE_HalContext phost)

Flush data to Coprocessor.

Parameters
phostPointer to Hal context

Definition at line 304 of file EVE_HalImpl_FT9XX.c.

305{
307 /* no-op */
308}

◆ EVE_Hal_startTransfer()

EVE_HAL_EXPORT void EVE_Hal_startTransfer ( EVE_HalContext phost,
EVE_TRANSFER_T  rw,
uint32_t  addr 
)

Start data transfer to Coprocessor.

Parameters
phostPointer to Hal context
rwRead or Write
addrAddress to read/write

Definition at line 257 of file EVE_HalImpl_FT9XX.c.

258{
260
261 if (rw == EVE_TRANSFER_READ)
262 {
263 eve_assert(3 + phost->SpiDummyBytes <= 5);
264 uint8_t spidata[5]; // FIXME: phost->SpiDummyBytes // ?
265 spidata[0] = (addr >> 16);
266 spidata[1] = (addr >> 8);
267 spidata[2] = addr & 0xff;
268 spi_open(SPIM, phost->SpiCsPin);
269 spi_writen(SPIM, spidata, 3 + phost->SpiDummyBytes);
270 phost->Status = EVE_STATUS_READING;
271 }
272 else
273 {
274 uint8_t spidata[4];
275 spidata[0] = (0x80 | (addr >> 16));
276 spidata[1] = (addr >> 8);
277 spidata[2] = addr;
278
279 spi_open(SPIM, phost->SpiCsPin);
280 spi_writen(SPIM, spidata, 3);
281
282 phost->Status = EVE_STATUS_WRITING;
283 }
284}
@ EVE_TRANSFER_READ
Definition EVE_HalDefs.h:67
unsigned char uint8_t
static ft_uint32_t addr
Definition FT_Gpu_Hal.h:139
uint8_t SpiDummyBytes

◆ EVE_Hal_transfer16()

EVE_HAL_EXPORT uint16_t EVE_Hal_transfer16 ( EVE_HalContext phost,
uint16_t  value 
)

Write 2 bytes to Coprocessor.

Parameters
phostPointer to Hal context
valueValue to write
Returns
uint16_t Number of bytes transfered

Definition at line 374 of file EVE_HalImpl_FT9XX.c.

375{
376 uint8_t buffer[2];
377 if (phost->Status == EVE_STATUS_READING)
378 {
379 rdBuffer(phost, buffer, 2);
380 return (uint16_t)buffer[0]
381 | (uint16_t)buffer[1] << 8;
382 }
383 else
384 {
385 buffer[0] = value & 0xFF;
386 buffer[1] = value >> 8;
387 wrBuffer(phost, buffer, 2);
388 return 0;
389 }
390}
static void wrBuffer(EVE_HalContext *phost, const uint8_t *buffer, uint32_t size)
Write a block data to Coprocessor.
static void rdBuffer(EVE_HalContext *phost, uint8_t *buffer, uint32_t size)
Read a block data from Coprocessor.
unsigned short uint16_t
static ft_uint32_t ft_uint8_t * buffer
Definition FT_Gpu_Hal.h:139

◆ EVE_Hal_transfer32()

EVE_HAL_EXPORT uint32_t EVE_Hal_transfer32 ( EVE_HalContext phost,
uint32_t  value 
)

Write 4 bytes to Coprocessor.

Parameters
phostPointer to Hal context
valueValue to write
Returns
uint32_t Number of bytes transfered

Definition at line 399 of file EVE_HalImpl_FT9XX.c.

400{
401 uint8_t buffer[4];
402 if (phost->Status == EVE_STATUS_READING)
403 {
404 rdBuffer(phost, buffer, 4);
405 return (uint32_t)buffer[0]
406 | (uint32_t)buffer[1] << 8
407 | (uint32_t)buffer[2] << 16
408 | (uint32_t)buffer[3] << 24;
409 }
410 else
411 {
412 buffer[0] = value & 0xFF;
413 buffer[1] = (value >> 8) & 0xFF;
414 buffer[2] = (value >> 16) & 0xFF;
415 buffer[3] = value >> 24;
416 wrBuffer(phost, buffer, 4);
417 return 0;
418 }
419}
unsigned int uint32_t

◆ EVE_Hal_transfer8()

EVE_HAL_EXPORT uint8_t EVE_Hal_transfer8 ( EVE_HalContext phost,
uint8_t  value 
)

Write 8 bits to Coprocessor.

Parameters
phostPointer to Hal context
valueValue to write
Returns
uint8_t Number of bytes transfered

Definition at line 362 of file EVE_HalImpl_FT9XX.c.

363{
364 return transfer8(phost, value);
365}
static uint8_t transfer8(EVE_HalContext *phost, uint8_t value)
Write 8 bit to Coprocessor.

◆ EVE_HalImpl_close()

void EVE_HalImpl_close ( EVE_HalContext phost)

Close a HAL context.

Close a HAL context

Parameters
phostPointer to Hal context

Definition at line 223 of file EVE_HalImpl_FT9XX.c.

224{
225 phost->Status = EVE_STATUS_CLOSED;
227#ifndef PANL_APPLET
228 spi_close(SPIM, phost->SpiCsPin);
229#endif
230}
EVE_HalPlatform g_HalPlatform
Definition EVE_Hal.c:43
@ EVE_STATUS_CLOSED
Definition EVE_HalDefs.h:57
uint32_t OpenedDevices

◆ EVE_HalImpl_defaults()

bool EVE_HalImpl_defaults ( EVE_HalParameters parameters,
size_t  deviceIdx 
)

Get the default configuration parameters.

Get the default configuration parameters. Use deviceIdx to choose the connected device.

Parameters
parametersEVE_Hal framework's parameters
deviceIdx
Returns
true True if ok
false False if error

Definition at line 116 of file EVE_HalImpl_FT9XX.c.

117{
118 parameters->PowerDownPin = GPIO_FT800_PWD;
119 parameters->SpiCsPin = deviceIdx < GPIO_SS_NB ? deviceIdx : 0; // SS0-3
120 return true;
121}
#define GPIO_SS_NB

◆ EVE_HalImpl_idle()

void EVE_HalImpl_idle ( EVE_HalContext phost)

Idle. Call regularly to update frequently changing internal state.

Idle. Call regularly to update frequently changing internal state

Parameters
phostPointer to Hal context

Definition at line 237 of file EVE_HalImpl_FT9XX.c.

238{
239 /* no-op */
240}

◆ EVE_HalImpl_initialize()

void EVE_HalImpl_initialize ( )

Initialize HAL platform.

Initialize HAL platform

Definition at line 57 of file EVE_HalImpl_FT9XX.c.

58{
59}

◆ EVE_HalImpl_open()

bool EVE_HalImpl_open ( EVE_HalContext phost,
const EVE_HalParameters parameters 
)

Opens a new HAL context using the specified parameters.

Opens a new HAL context using the specified parameters

Parameters
phostPointer to Hal context
parametersEVE_Hal framework's parameters
Returns
true True if ok
false False if error

Definition at line 191 of file EVE_HalImpl_FT9XX.c.

192{
193 phost->SpiCsPin = parameters->SpiCsPin < GPIO_SS_NB ? parameters->SpiCsPin : 0;
194 phost->PowerDownPin = parameters->PowerDownPin;
195 eve_printf_debug("EVE open PWD: %d, SS: %d\n",
196 (unsigned int)phost->PowerDownPin, (unsigned int)s_SpimGpioSS[phost->SpiCsPin]);
197
198#ifdef EVE_MULTI_GRAPHICS_TARGET
199 phost->GpuDefs = &EVE_GpuDefs_FT80X;
200#endif
201
202 gpio_function(phost->PowerDownPin, pad_func_0);
203 gpio_dir(phost->PowerDownPin, pad_dir_output);
204 gpio_write(phost->PowerDownPin, 0);
205
206 /* Initialize single channel */
208
209 gpio_write(phost->PowerDownPin, 1);
210
211 /* Initialize the context variables */
212 phost->Status = EVE_STATUS_OPENED;
214
215 return true;
216}
@ EVE_SPI_SINGLE_CHANNEL
static const uint8_t s_SpimGpioSS[4]
void setSPI(EVE_HalContext *phost, EVE_SPI_CHANNELS_T numchnls, uint8_t numdummy)
Set number of SPI channel.
#define eve_printf_debug(fmt,...)
uint8_t PowerDownPin

◆ EVE_HalImpl_release()

void EVE_HalImpl_release ( )

Release HAL platform.

Release HAL platform

Definition at line 65 of file EVE_HalImpl_FT9XX.c.

66{
67#ifndef PANL_APPLET
68 spi_uninit(SPIM);
69#endif
70}

◆ EVE_Mcu_initialize()

void EVE_Mcu_initialize ( )

Init FT9x host MCU.

Definition at line 720 of file EVE_HalImpl_FT9XX.c.

721{
722#ifndef PANL_APPLET
723 sys_reset_all();
724
725 interrupt_enable_globally();
726
727 sys_enable(sys_device_uart0);
728 gpio_function(GPIO_UART0_TX, pad_uart0_txd); /* UART0 TXD */
729 gpio_function(GPIO_UART0_RX, pad_uart0_rxd); /* UART0 RXD */
730 uart_open(UART0, /* Device */
731 1, /* Prescaler = 1 */
732 UART_DIVIDER_115200_BAUD, /* Divider = 1302 */
733 uart_data_bits_8, /* No. Data Bits */
734 uart_parity_none, /* Parity */
735 uart_stop_bits_1); /* No. Stop Bits */
736#endif
737
738#if (defined(ENABLE_ILI9488_HVGA_PORTRAIT) || defined(ENABLE_KD2401_HVGA_PORTRAIT))
739 /* assign all the respective pins to GPIO and set them to default values */
740 gpio_function(GPIO_ILI9488_DCX, pad_ili9488_dcx);
741 gpio_dir(GPIO_ILI9488_DCX, pad_dir_output);
742 gpio_write(GPIO_ILI9488_DCX, 1);
743
744 gpio_function(GPIO_SPIM_CLK, pad_spim_sck);
745 gpio_dir(GPIO_SPIM_CLK, pad_dir_output);
746 gpio_write(GPIO_SPIM_CLK, 1);
747
748 gpio_function(GPIO_SPIM_MOSI, pad_spim_mosi);
749 gpio_dir(GPIO_SPIM_MOSI, pad_dir_output);
750 gpio_write(GPIO_SPIM_MOSI, 1);
751
752 gpio_function(GPIO_ILI9488_CS1, pad_ili9488_cs1);
753 gpio_dir(GPIO_ILI9488_CS1, pad_dir_output);
754 gpio_write(GPIO_ILI9488_CS1, 1);
755
756 gpio_function(GPIO_SPIM_MISO, pad_spim_miso);
757 gpio_dir(GPIO_SPIM_MISO, pad_dir_output);
758 gpio_write(GPIO_SPIM_MISO, 1);
759
760 gpio_function(GPIO_SPIM_SS0, pad_spim_ss0);
761 gpio_dir(GPIO_SPIM_SS0, pad_dir_output);
762 gpio_write(GPIO_SPIM_SS0, 1);
763
764 gpio_function(GPIO_FT800_PWD, pad_func_0); /* FIXME: This needs to be done at open, not init */
765 gpio_dir(GPIO_FT800_PWD, pad_dir_output);
766 gpio_write(GPIO_FT800_PWD, 1);
767
768 gpio_write(GPIO_ILI9488_DCX, 1);
769 gpio_write(GPIO_SPIM_SS0, 1);
770 gpio_write(GPIO_FT800_PWD, 1);
771 gpio_write(GPIO_ILI9488_CS1, 1);
772#endif
773
774 initSdHost();
775}
static void initSdHost()
Sdcard initialization.

◆ EVE_Mcu_release()

void EVE_Mcu_release ( )

Release FT9x host MCU.

Definition at line 781 of file EVE_HalImpl_FT9XX.c.

782{
783 /* no-op */
784}

◆ EVE_millis()

EVE_HAL_EXPORT uint32_t EVE_millis ( )

Get clock in miliseond.

Need to ensure that below api is called at least once in 6.5 seconds duration for FT900 platform as this module doesnt use timer for context update global counter to loopback after ~49.71 days

Returns
uint32_t Clock number

Definition at line 842 of file EVE_HalImpl_FT9XX.c.

843{
844#if defined(PANL_APPLET)
845 uint32_t ms = panl_timer_get_time();
847 s_TotalMilliseconds64 += (1 << 32);
849 s_TotalMilliseconds64 = (s_TotalMilliseconds64 & ~0xFFFFFFFFULL) | (uint64_t)ms;
850#endif
851 return s_TotalMilliseconds;
852}
static uint32_t s_TotalMilliseconds
static uint64_t s_TotalMilliseconds64
unsigned long long uint64_t

◆ EVE_millis64()

EVE_HAL_EXPORT uint64_t EVE_millis64 ( )

Get clock in miliseond.

Need to ensure that below api is called at least once in 6.5 seconds duration for FT900 platform as this module doesnt use timer for context update global counter to loopback after ~49.71 days

Returns
uint32_t Clock number

Definition at line 862 of file EVE_HalImpl_FT9XX.c.

863{
864#if defined(PANL_APPLET)
865 uint32_t ms = panl_timer_get_time();
867 s_TotalMilliseconds64 += (1 << 32);
869 s_TotalMilliseconds64 = (s_TotalMilliseconds64 & ~0xFFFFFFFFULL) | (uint64_t)ms;
870#endif
872}

◆ EVE_Millis_initialize()

void EVE_Millis_initialize ( )

Init FT9x timer.

Definition at line 802 of file EVE_HalImpl_FT9XX.c.

803{
805#if !defined(PANL_APPLET)
806 sys_enable(sys_device_timer_wdt);
807#if defined(FT900_PLATFORM)
808 timer_prescaler(FT900_TIMER_PRESCALE_VALUE);
809#else
811#endif
812 timer_init(FT900_FT_MILLIS_TIMER, FT900_TIMER_OVERFLOW_VALUE, timer_direction_up, timer_prescaler_select_on, timer_mode_continuous);
813
814 interrupt_attach(interrupt_timers, 17, ticker);
815 /* enabling the interrupts for timer */
816 timer_enable_interrupt(FT900_FT_MILLIS_TIMER);
817
818 timer_start(FT900_FT_MILLIS_TIMER);
819#endif
820}
void ticker()
Clear the interrupt and increment the counter.
#define FT900_FT_MILLIS_TIMER
#define FT900_TIMER_PRESCALE_VALUE
#define FT900_TIMER_OVERFLOW_VALUE

◆ EVE_Millis_release()

void EVE_Millis_release ( )

Release FT9x timer.

Definition at line 826 of file EVE_HalImpl_FT9XX.c.

827{
828#if !defined(PANL_APPLET)
829 timer_stop(FT900_FT_MILLIS_TIMER);
830 timer_disable_interrupt(FT900_FT_MILLIS_TIMER);
831#endif
832}

◆ EVE_UtilImpl_bootupDisplayGpio()

bool EVE_UtilImpl_bootupDisplayGpio ( EVE_HalContext phost)

Display GPIO pins.

Parameters
phostPointer to Hal context
Returns
true True if Ok
false False if error

Definition at line 915 of file EVE_HalImpl_FT9XX.c.

916{
917 return true;
918}

Variable Documentation

◆ g_HalPlatform

EVE_HalPlatform g_HalPlatform
extern

Definition at line 43 of file EVE_Hal.c.