Merged nuttx/nuttx into master

This commit is contained in:
Aleksandr Vyhovanec 2017-01-07 21:15:13 +03:00
commit 02c877f649
33 changed files with 3660 additions and 496 deletions

21
TODO
View File

@ -1,4 +1,4 @@
NuttX TODO List (Last updated December 11, 2016)
NuttX TODO List (Last updated January 6, 2017)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This file summarizes known NuttX bugs, limitations, inconsistencies with
@ -24,7 +24,7 @@ nuttx/:
(0) Other drivers (drivers/)
(12) Libraries (libc/, libm/)
(11) File system/Generic drivers (fs/, drivers/)
(9) Graphics Subsystem (graphics/)
(8) Graphics Subsystem (graphics/)
(2) Build system / Toolchains
(3) Linux/Cywgin simulation (arch/sim)
(4) ARM (arch/arm/)
@ -1710,18 +1710,6 @@ o Graphics Subsystem (graphics/)
Status: Open
Priority: Medium low
Title: IMPROVED NxTERM FONT CACHING
Description: Now each NxTerm instance has its own private font cache
whose size is determined by CONFIG_NXTERM_MXCHARS. If there
are multiple NxTerm instances using the same font, each will
have a separate font cache. This is inefficient and wasteful
of memory: Each NxTerm instance should share a common font
cache.
Status: Open
Priority: Medium. Not important for day-to-day testing but would be
a critical improvement if NxTerm were to be used in a
product.
Title: NxTERM VT100 SUPPORT
Description: If the NxTerm will be used with the Emacs-like command line
editor (CLE), then it will need to support VT100 cursor control
@ -2080,7 +2068,12 @@ o Other Applications & Tests (apps/examples/)
it stops rendering. This is not a problem for the examples/nx
code because it uses so few fonts, but if the logic were
leveraged for more general purposes, it would be a problem.
Update: see examples/nxtext for some improved font cache handling.
Update: The NXTERM font cache has been generalized and is now
offered as the standard, common font cache for all applications.
both the nx and nxtext examples should be modified to use this
common font cache. See interfaces defined in nxfonts.h.
Status: Open
Priority: Low. This is not really a problem because examples/nx works
fine with its bogus font caching.

View File

@ -2256,13 +2256,13 @@ static void sam_txerr_interrupt(FAR struct sam_emac_s *priv, int qid)
* Function: sam_interrupt_work
*
* Description:
* Perform interrupt related work from the worker thread
* Perform interrupt related work from the worker thread.
*
* Parameters:
* arg - The argument passed when work_queue() was called.
*
* Returned Value:
* OK on success
* None
*
* Assumptions:
* Ethernet interrupts are disabled
@ -2279,6 +2279,7 @@ static void sam_interrupt_work(FAR void *arg)
uint32_t regval;
uint32_t pending;
uint32_t clrbits;
int qid = EMAC_QUEUE_0; /* REVISIT: Currently services on EMAC_QUEUE_0 */
/* Process pending Ethernet interrupts */
@ -2454,10 +2455,10 @@ static void sam_interrupt_work(FAR void *arg)
* Function: sam_emac_interrupt
*
* Description:
* Common hardware interrupt handler
* Common hardware interrupt handler.
*
* Parameters:
* priv - Reference to the EMAC private state structure
* priv - Reference to the EMAC private state structure
*
* Returned Value:
* OK on success

View File

@ -12,8 +12,10 @@
# CONFIG_HOST_OSX is not set
CONFIG_HOST_WINDOWS=y
# CONFIG_HOST_OTHER is not set
CONFIG_TOOLCHAIN_WINDOWS=y
# CONFIG_WINDOWS_NATIVE is not set
CONFIG_WINDOWS_CYGWIN=y
# CONFIG_WINDOWS_UBUNTU is not set
# CONFIG_WINDOWS_MSYS is not set
# CONFIG_WINDOWS_OTHER is not set
@ -612,6 +614,7 @@ CONFIG_PREALLOC_TIMERS=4
#
# Tasks and Scheduling
#
# CONFIG_SPINLOCK is not set
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
@ -628,6 +631,8 @@ CONFIG_MAX_TASKS=16
#
# CONFIG_MUTEX_TYPES is not set
CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set
#
# Performance Monitoring
@ -1061,6 +1066,8 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
CONFIG_ARCH_HAVE_TLS=y
# CONFIG_TLS is not set
# CONFIG_LIBC_IPv4_ADDRCONV is not set
# CONFIG_LIBC_IPv6_ADDRCONV is not set
# CONFIG_LIBC_NETDB is not set
# CONFIG_NETDB_HOSTFILE is not set

View File

@ -12,8 +12,10 @@
# CONFIG_HOST_OSX is not set
CONFIG_HOST_WINDOWS=y
# CONFIG_HOST_OTHER is not set
CONFIG_TOOLCHAIN_WINDOWS=y
# CONFIG_WINDOWS_NATIVE is not set
CONFIG_WINDOWS_CYGWIN=y
# CONFIG_WINDOWS_UBUNTU is not set
# CONFIG_WINDOWS_MSYS is not set
# CONFIG_WINDOWS_OTHER is not set
@ -613,6 +615,7 @@ CONFIG_PREALLOC_TIMERS=4
#
# Tasks and Scheduling
#
# CONFIG_SPINLOCK is not set
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
@ -629,6 +632,8 @@ CONFIG_MAX_TASKS=16
#
# CONFIG_MUTEX_TYPES is not set
CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set
#
# Performance Monitoring
@ -1018,6 +1023,8 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
CONFIG_ARCH_HAVE_TLS=y
# CONFIG_TLS is not set
# CONFIG_LIBC_IPv4_ADDRCONV is not set
# CONFIG_LIBC_IPv6_ADDRCONV is not set
# CONFIG_LIBC_NETDB is not set
# CONFIG_NETDB_HOSTFILE is not set
@ -1215,6 +1222,7 @@ CONFIG_NSH_MMCSDSLOTNO=0
# Configure Command Options
#
CONFIG_NSH_CMDOPT_DF_H=y
# CONFIG_NSH_CMDOPT_DD_STATS is not set
CONFIG_NSH_CODECS_BUFSIZE=128
CONFIG_NSH_CMDOPT_HEXDUMP=y
CONFIG_NSH_FILEIOSIZE=512

View File

@ -12,8 +12,10 @@
# CONFIG_HOST_OSX is not set
CONFIG_HOST_WINDOWS=y
# CONFIG_HOST_OTHER is not set
CONFIG_TOOLCHAIN_WINDOWS=y
# CONFIG_WINDOWS_NATIVE is not set
CONFIG_WINDOWS_CYGWIN=y
# CONFIG_WINDOWS_UBUNTU is not set
# CONFIG_WINDOWS_MSYS is not set
# CONFIG_WINDOWS_OTHER is not set
@ -629,6 +631,7 @@ CONFIG_PREALLOC_TIMERS=4
#
# Tasks and Scheduling
#
# CONFIG_SPINLOCK is not set
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
@ -645,6 +648,8 @@ CONFIG_SCHED_WAITPID=y
#
# CONFIG_MUTEX_TYPES is not set
CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set
#
# Performance Monitoring
@ -1104,6 +1109,7 @@ CONFIG_NXFONT_SANS28X37B=y
# CONFIG_NXFONT_X11_MISC_FIXED_9X18 is not set
# CONFIG_NXFONT_X11_MISC_FIXED_9X18B is not set
# CONFIG_NXFONT_X11_MISC_FIXED_10X20 is not set
# CONFIG_NXFONT_TOM_THUMB_4X6 is not set
# CONFIG_NXTERM is not set
#
@ -1177,6 +1183,8 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
CONFIG_ARCH_HAVE_TLS=y
# CONFIG_TLS is not set
# CONFIG_LIBC_IPv4_ADDRCONV is not set
# CONFIG_LIBC_IPv6_ADDRCONV is not set
# CONFIG_LIBC_NETDB is not set
# CONFIG_NETDB_HOSTFILE is not set
@ -1413,6 +1421,7 @@ CONFIG_NSH_MMCSDSLOTNO=0
# Configure Command Options
#
CONFIG_NSH_CMDOPT_DF_H=y
# CONFIG_NSH_CMDOPT_DD_STATS is not set
CONFIG_NSH_CODECS_BUFSIZE=128
CONFIG_NSH_CMDOPT_HEXDUMP=y
CONFIG_NSH_FILEIOSIZE=512

View File

@ -12,8 +12,10 @@
# CONFIG_HOST_OSX is not set
CONFIG_HOST_WINDOWS=y
# CONFIG_HOST_OTHER is not set
CONFIG_TOOLCHAIN_WINDOWS=y
# CONFIG_WINDOWS_NATIVE is not set
CONFIG_WINDOWS_CYGWIN=y
# CONFIG_WINDOWS_UBUNTU is not set
# CONFIG_WINDOWS_MSYS is not set
# CONFIG_WINDOWS_OTHER is not set
@ -616,6 +618,7 @@ CONFIG_PREALLOC_TIMERS=4
#
# Tasks and Scheduling
#
# CONFIG_SPINLOCK is not set
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
@ -632,6 +635,8 @@ CONFIG_MAX_TASKS=16
#
# CONFIG_MUTEX_TYPES is not set
CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set
#
# Performance Monitoring
@ -1012,6 +1017,7 @@ CONFIG_NXFONT_SANS23X27=y
# CONFIG_NXFONT_X11_MISC_FIXED_9X18 is not set
# CONFIG_NXFONT_X11_MISC_FIXED_9X18B is not set
# CONFIG_NXFONT_X11_MISC_FIXED_10X20 is not set
# CONFIG_NXFONT_TOM_THUMB_4X6 is not set
# CONFIG_NXTERM is not set
#
@ -1080,6 +1086,8 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
CONFIG_ARCH_HAVE_TLS=y
# CONFIG_TLS is not set
# CONFIG_LIBC_IPv4_ADDRCONV is not set
# CONFIG_LIBC_IPv6_ADDRCONV is not set
# CONFIG_LIBC_NETDB is not set
#

View File

@ -666,7 +666,7 @@ CONFIG_SIG_SIGWORK=17
# POSIX Message Queue Options
#
CONFIG_PREALLOC_MQ_MSGS=8
CONFIG_MQ_MAXMSGSIZE=32
CONFIG_MQ_MAXMSGSIZE=64
# CONFIG_MODULE is not set
#
@ -999,7 +999,7 @@ CONFIG_NXTERM=y
# NxTerm Output Text/Graphics Options
#
CONFIG_NXTERM_BPP=16
CONFIG_NXTERM_CURSORCHAR=137
CONFIG_NXTERM_CURSORCHAR=95
CONFIG_NXTERM_MXCHARS=256
CONFIG_NXTERM_CACHESIZE=32
CONFIG_NXTERM_LINESEPARATION=0

View File

@ -12,8 +12,10 @@
# CONFIG_HOST_OSX is not set
CONFIG_HOST_WINDOWS=y
# CONFIG_HOST_OTHER is not set
CONFIG_TOOLCHAIN_WINDOWS=y
# CONFIG_WINDOWS_NATIVE is not set
CONFIG_WINDOWS_CYGWIN=y
# CONFIG_WINDOWS_UBUNTU is not set
# CONFIG_WINDOWS_MSYS is not set
# CONFIG_WINDOWS_OTHER is not set
@ -626,6 +628,7 @@ CONFIG_PREALLOC_TIMERS=4
#
# Tasks and Scheduling
#
# CONFIG_SPINLOCK is not set
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
@ -642,6 +645,8 @@ CONFIG_SCHED_WAITPID=y
#
# CONFIG_MUTEX_TYPES is not set
CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set
#
# Performance Monitoring
@ -1035,6 +1040,7 @@ CONFIG_NXFONT_SANS28X37B=y
# CONFIG_NXFONT_X11_MISC_FIXED_9X18 is not set
# CONFIG_NXFONT_X11_MISC_FIXED_9X18B is not set
# CONFIG_NXFONT_X11_MISC_FIXED_10X20 is not set
# CONFIG_NXFONT_TOM_THUMB_4X6 is not set
# CONFIG_NXTERM is not set
#
@ -1106,6 +1112,8 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
CONFIG_ARCH_HAVE_TLS=y
# CONFIG_TLS is not set
# CONFIG_LIBC_IPv4_ADDRCONV is not set
# CONFIG_LIBC_IPv6_ADDRCONV is not set
# CONFIG_LIBC_NETDB is not set
#
@ -1335,6 +1343,7 @@ CONFIG_NSH_MMCSDMINOR=0
# Configure Command Options
#
CONFIG_NSH_CMDOPT_DF_H=y
# CONFIG_NSH_CMDOPT_DD_STATS is not set
CONFIG_NSH_CODECS_BUFSIZE=128
CONFIG_NSH_CMDOPT_HEXDUMP=y
CONFIG_NSH_FILEIOSIZE=512

View File

@ -605,6 +605,7 @@ CONFIG_PREALLOC_TIMERS=4
#
# Tasks and Scheduling
#
# CONFIG_SPINLOCK is not set
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
@ -621,6 +622,8 @@ CONFIG_MAX_TASKS=16
#
# CONFIG_MUTEX_TYPES is not set
CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set
#
# Performance Monitoring
@ -988,6 +991,8 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
CONFIG_ARCH_HAVE_TLS=y
# CONFIG_TLS is not set
# CONFIG_LIBC_IPv4_ADDRCONV is not set
# CONFIG_LIBC_IPv6_ADDRCONV is not set
# CONFIG_LIBC_NETDB is not set
# CONFIG_NETDB_HOSTFILE is not set

View File

@ -597,6 +597,7 @@ CONFIG_PREALLOC_TIMERS=4
#
# Tasks and Scheduling
#
# CONFIG_SPINLOCK is not set
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
@ -613,6 +614,8 @@ CONFIG_MAX_TASKS=16
#
# CONFIG_MUTEX_TYPES is not set
CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set
#
# Performance Monitoring
@ -954,6 +957,8 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
CONFIG_ARCH_HAVE_TLS=y
# CONFIG_TLS is not set
# CONFIG_LIBC_IPv4_ADDRCONV is not set
# CONFIG_LIBC_IPv6_ADDRCONV is not set
# CONFIG_LIBC_NETDB is not set
#

View File

@ -713,7 +713,7 @@ CONFIG_SIG_SIGWORK=17
# POSIX Message Queue Options
#
CONFIG_PREALLOC_MQ_MSGS=8
CONFIG_MQ_MAXMSGSIZE=32
CONFIG_MQ_MAXMSGSIZE=64
# CONFIG_MODULE is not set
#
@ -1189,7 +1189,7 @@ CONFIG_NXTERM=y
# NxTerm Output Text/Graphics Options
#
CONFIG_NXTERM_BPP=16
CONFIG_NXTERM_CURSORCHAR=137
CONFIG_NXTERM_CURSORCHAR=95
CONFIG_NXTERM_MXCHARS=256
CONFIG_NXTERM_CACHESIZE=32
CONFIG_NXTERM_LINESEPARATION=0

View File

@ -35,8 +35,10 @@ Contents
- Development Environment
- GNU Toolchain Options
- Setup and Programming Flash
- LEDs
- UARTs
- Ser
- Timer Inputs/Outputs
- FPU
- FSMC SRAM
@ -46,10 +48,28 @@ Contents
Development Environment
=======================
The Development environments for the STM32F429I-DISCO board are identical
to the environments for other STM32F boards. For full details on the
environment options and setup, see the README.txt file in the
config/stm32f4discovery directory.
The Development environments for the STM32F429I-DISCO board are identical
to the environments for other STM32F boards. For full details on the
environment options and setup, see the README.txt file in the
config/stm32f4discovery directory.
Setup and Programming Flash
===========================
I use a USB cable to power and program it. And I use a USB/Serial
connected to pins PA9 and PA10 for the serial console (See the section
"UARTs" below).
FLASH may be programmed:
- Via USB using STM32 ST-Link Utility
- Via USB using OpenOCD. This command may be used to flash the
firmware using OpenOCD:
$ sudo openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"
- Via JTAG/SWD connected to the SWD connector CN2.
LEDs
====
@ -82,8 +102,8 @@ UARTs
=====
On the STM32F429I-DISCO board, because of pin mappings to support the
onboard SDRAM and LCD, the only UARTs that has both RX and TX pins
avilalbe are USART1 and UART5. Other USARTS could be used for RX or TX
onboard SDRAM and LCD, the only UARTs that have both RX and TX pins
available are USART1 and UART5. Other USARTS could be used for RX or TX
only, or they could be used for full-duplex if the other pin functions
aren't being used (i.e. LCD or SDRAM).
@ -91,38 +111,38 @@ UART/USART PINS
---------------
USART1
CK PA8
CK PA8*
CTS PA11*
RTS PA12*
RX PA10*, PB7*
TX PA9*, PB6*
RX PA10, PB7
TX PA9, PB6*
USART2
CK PA4*, PD7
CTS PA0*, PD3
RTS PA1, PD4*
RX PA3, PD6
TX PA2, PD5*
CTS PA0*, PD3*
RTS PA1*, PD4
RX PA3*, PD6*
TX PA2*, PD5
USART3
CK PB12, PC12*, PD10
CTS PB13, PD11
RTS PB14, PD12*
RX PB11, PC11, PD9
TX PB10*, PC10*, PD8
CK PB12*, PC12, PD10*
CTS PB13*, PD11*
RTS PB14*, PD12*
RX PB11*, PC11, PD9*
TX PB10*, PC10*, PD8*
UART4
RX PA1, PC11
RX PA1*, PC11
TX PA0*, PC10*
UART5
RX PD2
TX PC12*
TX PC12
USART6
CK PC8, PG7*
CTS PG13*, PG15*
RTS PG12*, PG8*
RX PC7*, PG9*
TX PC6, PG14*
RX PC7*, PG9
TX PC6*, PG14*
UART7
RX PE7*,PF6*
TX PE8*,PF7*
RX PE7*, PF6
TX PE8*, PF7*
* Indicates pins that have other on-board functions and should be used only
with care (See table 6 in the STM32F429I-DISCO User Guide for a list of free
@ -132,60 +152,60 @@ Default USART/UART Configuration
--------------------------------
USART1 is enabled in all configurations (see */defconfig). RX and TX are
configured on pins PA3 and PA2, respectively (see include/board.h).
configured on pins PA10 and PA9, respectively (see include/board.h).
Timer Inputs/Outputs
====================
TIM1
CH1 PA8, PE9
CH2 PA9*, PE11
CH3 PA10*, PE13
CH4 PA11*, PE14
CH1 PA8*, PE9*
CH2 PA9, PE11*
CH3 PA10, PE13*
CH4 PA11*, PE14*
TIM2
CH1 PA0*, PA15, PA5*
CH2 PA1, PB3*
CH3 PA2, PB10*
CH4 PA3, PB11
CH1 PA0*, PA15*, PA5
CH2 PA1*, PB3*
CH3 PA2*, PB10*
CH4 PA3*, PB11*
TIM3
CH1 PA6*, PB4, PC6
CH2 PA7*, PB5, PC7*
CH3 PB0, PC8
CH4 PB1, PC9
CH1 PA6*, PB4, PC6*
CH2 PA7*, PB5*, PC7*
CH3 PB0*, PC8
CH4 PB1*, PC9*
TIM4
CH1 PB6*, PD12*
CH2 PB7, PD13*
CH3 PB8, PD14*
CH3 PB8*, PD14*
CH4 PB9*, PD15*
TIM5
CH1 PA0*, PH10**
CH2 PA1, PH11**
CH3 PA2, PH12**
CH4 PA3, PI0
CH1 PA0*, PH10*
CH2 PA1*, PH11*
CH3 PA2*, PH12*
CH4 PA3*, PI0**
TIM8
CH1 PC6, PI5
CH2 PC7*, PI6
CH3 PC8, PI7
CH4 PC9, PI2
CH1 PC6*, PI5**
CH2 PC7*, PI6**
CH3 PC8, PI7**
CH4 PC9*, PI2**
TIM9
CH1 PA2, PE5
CH2 PA3, PE6
CH1 PA2*, PE5
CH2 PA3*, PE6
TIM10
CH1 PB8, PF6
CH1 PB8*, PF6
TIM11
CH1 PB9*, PF7
CH1 PB9*, PF7*
TIM12
CH1 PH6**, PB14
CH2 PC15, PH9**
CH1 PH6*, PB14*
CH2 PC15*, PH9*
TIM13
CH1 PA6*, PF8
CH1 PA6*, PF8*
TIM14
CH1 PA7*, PF9
CH1 PA7*, PF9*
* Indicates pins that have other on-board functions and should be used only
with care (See table 5 in the STM32F429I-DISCO User Guide). The rest are
free I/O pins.
** Port H pins are not supported by the MCU
free I/O pins (This need to be updated. They are incorrect!)
** Port I pins are not supported by the MCU
FPU
===
@ -240,7 +260,7 @@ the following lines in each Make.defs file:
Configuration Changes
---------------------
Below are all of the configuration changes that I had to make to configs/stm3240g-eval/nsh2
Below are all of the configuration changes that I had to make to configs/stm32f429i-disco/nsh2
in order to successfully build NuttX using the Atollic toolchain WITH FPU support:
-CONFIG_ARCH_FPU=n : Enable FPU support
@ -598,6 +618,30 @@ instead of configure.sh:
Where <subdir> is one of the following:
extflash:
---------
This is another NSH example. If differs from other 'nsh' configurations
in that this configuration defines an external 8 MByte SPI FLASH (the
SST25VF064C part from Silicon Storage Technology, Inc.) which must be
be connected to the Discovery board's SPI4 pins on the expansion pins.
Additionally, this demo uses UART1 for the console
NOTES:
1. This configuration assumes an SST25VF064C 8Mbyte SPI FLASH is
connected to SPI4 on the following Discovery board Pins:
SCK: Port PE2 Board Connector P1, Pin 15
MOSI: Port PE6 Board Connector P1, Pin 11
MISO: Port PE5 Board Connector P1, Pin 14
CS: Port PE4 Board Connector P1, Pin 13
2. This configuration does have UART1 output enabled and set up as
the system logging device. To use this UART, you must add an
external RS-232 line driver to the UART1 pins of the DISCO board
on PA9 and PA10 of connector P1.
ltdc:
----
STM32F429I-DISCO LTDC Framebuffer demo example. See
@ -843,29 +887,60 @@ Where <subdir> is one of the following:
2015-04-30
Appears to be fully functional.
extflash:
---------
nxwm
----
This is a special configuration setup for the NxWM window manager
UnitTest. The NxWM window manager can be found here:
This is another NSH example. If differs from other 'nsh' configurations
in that this configuration defines an external 8 MByte SPI FLASH (the
SST25VF064C part from Silicon Storage Technology, Inc.) which must be
be connected to the Discovery board's SPI4 pins on the expansion pins.
Additionally, this demo uses UART1 for the console
nuttx-code/NxWidgets/nxwm
NOTES:
The NxWM unit test can be found at:
1. This configuration assumes an SST25VF064C 8Mbyte SPI FLASH is
connected to SPI4 on the following Discovery board Pins:
nuttx-code/NxWidgets/UnitTests/nxwm
SCK: Port PE2 Board Connector P1, Pin 15
MOSI: Port PE6 Board Connector P1, Pin 11
MISO: Port PE5 Board Connector P1, Pin 14
CS: Port PE4 Board Connector P1, Pin 13
Documentation for installing the NxWM unit test can be found here:
2. This configuration does have UART1 output enabled and set up as
the system logging device. To use this UART, you must add an
external RS-232 line driver to the UART1 pins of the DISCO board
on PA9 and PA10 of connector P1.
nuttx-code/NxWidgets/UnitTests/README.txt
Here is the quick summary of the build steps (Assuming that all of
the required packages are available in a directory ~/nuttx-code):
1. Install the nxwm configuration
$ cd ~/nuttx-code/nuttx/tools
$ ./configure.sh stm32f429i-disco/nxwm
2. Make the build context (only)
$ cd ..
$ . ./setenv.sh
$ make context
...
3. Install the nxwm unit test
$ cd ~/nuttx-code/NxWidgets
$ tools/install.sh ~/nuttx-code/apps nxwm
Creating symbolic link
- To ~/nuttx-code/NxWidgets/UnitTests/nxwm
- At ~/nuttx-code/apps/external
4. Build the NxWidgets library
$ cd ~/nuttx-code/NxWidgets/libnxwidgets
$ make TOPDIR=~/nuttx-code/nuttx
...
5. Build the NxWM library
$ cd ~/nuttx-code/NxWidgets/nxwm
$ make TOPDIR=~/nuttx-code/nuttx
...
6. Built NuttX with the installed unit test as the application
$ cd ~/nuttx-code/nuttx
$ make
usbnsh:
------

View File

@ -224,6 +224,11 @@
#define GPIO_TIM4_CH2OUT GPIO_TIM4_CH2OUT_2
/* I2C - There is a STMPE811 TouchPanel on I2C3 using these pins: */
#define GPIO_I2C3_SCL GPIO_I2C3_SCL_1
#define GPIO_I2C3_SDA GPIO_I2C3_SDA_1
/* SPI - There is a MEMS device on SPI5 using these pins: */
#define GPIO_SPI5_MISO GPIO_SPI5_MISO_1

View File

@ -0,0 +1,112 @@
############################################################################
# configs/stm32f429i-disco/nxwm/Make.defs
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
include ${TOPDIR}/.config
include ${TOPDIR}/tools/Config.mk
include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs
LDSCRIPT = ld.script
ifeq ($(WINTOOL),y)
# Windows-native toolchains
DIRLINK = $(TOPDIR)/tools/copydir.sh
DIRUNLINK = $(TOPDIR)/tools/unlink.sh
MKDEP = $(TOPDIR)/tools/mkwindeps.sh
ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}"
ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}"
ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)}"
else
# Linux/Cygwin-native toolchain
MKDEP = $(TOPDIR)/tools/mkdeps$(HOSTEXEEXT)
ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx
ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)
endif
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
CPP = $(CROSSDEV)gcc -E
LD = $(CROSSDEV)ld
AR = $(ARCROSSDEV)ar rcs
NM = $(ARCROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump
ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'}
ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1}
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
ARCHWARNINGSXX = -Wall -Wshadow -Wundef
ARCHDEFINES =
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES)
AFLAGS = $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
ASMEXT = .S
OBJEXT = .o
LIBEXT = .a
EXEEXT =
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif
HOSTCC = gcc
HOSTINCLUDES = -I.
HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
HOSTLDFLAGS =

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,80 @@
#!/bin/bash
# configs/stm32f429i-disco/nxwm/setenv.sh
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
if [ "$_" = "$0" ] ; then
echo "You must source this script, not run it!" 1>&2
exit 1
fi
WD=`pwd`
if [ ! -x "setenv.sh" ]; then
echo "This script must be executed from the top-level NuttX build directory"
exit 1
fi
if [ -z "${PATH_ORIG}" ]; then
export PATH_ORIG="${PATH}"
fi
# This is the Cygwin path to the location where I installed the CodeSourcery
# toolchain under windows. You will also have to edit this if you install
# the CodeSourcery toolchain in any other location
#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
# export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
# These are the Cygwin paths to the locations where I installed the Atollic
# toolchain under windows. You will also have to edit this if you install
# the Atollic toolchain in any other location. /usr/bin is added before
# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
# at those locations as well.
#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
# This is the path to the location where I installed the devkitARM toolchain
# You can get this free toolchain from http://devkitpro.org/ or http://sourceforge.net/projects/devkitpro/
#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/devkitARM/bin"
# This is the Cygwin path to the location where I build the buildroot
# toolchain.
#export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
# Add the path to the toolchain to the PATH varialble
export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
echo "PATH : ${PATH}"

View File

@ -64,6 +64,10 @@ ifeq ($(CONFIG_STM32_OTGHS),y)
CSRCS += stm32_usb.c
endif
ifeq ($(CONFIG_INPUT_STMPE811),y)
CSRCS += stm32_stmpe811.c
endif
ifeq ($(CONFIG_STM32F429I_DISCO_ILI9341),y)
CSRCS += stm32_ili93414ws.c
endif

View File

@ -52,9 +52,76 @@
* Pre-processor Definitions
************************************************************************************/
/************************************************************************************
* Private Functions
************************************************************************************/
/* Configuration ********************************************************************/
/* Should we initialize the NX server using nx_start? This is done for NxWidgets
* (CONFIG_NXWIDGETS=y) and if the NxWidget::CNxServer class expects the RTOS do the
* the NX initialization (CONFIG_NXWIDGET_SERVERINIT=n). This combination of
* settings is normally only used in the kernel build mode* (CONFIG_BUILD_PROTECTED)
* when NxWidgets is unable to initialize NX from user-space.
*/
#undef HAVE_NXSTART
#if !defined(CONFIG_NX_MULTIUSER)
# undef CONFIG_NX_START
#endif
#if defined(CONFIG_NXWIDGETS) && !defined(CONFIG_NXWIDGET_SERVERINIT)
# define HAVE_NXSTART
# include <nuttx/nx/nx.h>
#endif
/* Should we initialize the touchscreen for the NxWM (CONFIG_NXWM=y)? This
* is done if we have a touchscreen (CONFIG_INPUT_STMPE811=y), NxWM uses the
* touchscreen (CONFIG_NXWM_TOUCHSCREEN=y), and if we were asked to
* initialize the touchscreen for NxWM (NXWM_TOUCHSCREEN_DEVINIT=n). This
* combination of settings is normally only used in the kernel build mode
* (CONFIG_BUILD_PROTECTED) when NxWidgets is unable to initialize NX from
* user-space.
*/
#undef HAVE_TCINIT
#if defined(CONFIG_NXWM_TOUCHSCREEN)
# if !defined(CONFIG_NXWM_TOUCHSCREEN_DEVNO)
# error CONFIG_NXWM_TOUCHSCREEN_DEVNO is not defined
# elif defined(CONFIG_INPUT_STMPE811)
# if !defined(CONFIG_NXWM_TOUCHSCREEN_DEVINIT)
# define HAVE_TCINIT
# include <nuttx/input/touchscreen.h>
# endif
# else
# if !defined(CONFIG_NXWM_TOUCHSCREEN_DEVINIT) && defined(CONFIG_BUILD_PROTECTED)
# error CONFIG_INPUT_STMPE811=y is needed
# endif
# endif
#endif
/* Check if we will need to support the initialization kernel thread */
#undef HAVE_INITTHREAD
#ifdef CONFIG_BOARD_INITIALIZE
# if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_LIB_BOARDCTL)
# define HAVE_INITTHREAD 1
# elif defined(HAVE_NXSTART)
# define HAVE_INITTHREAD 1
# elif defined(HAVE_TCINIT)
# define HAVE_INITTHREAD 1
# endif
#endif
#ifdef HAVE_INITTHREAD
# include <stdlib.h>
# include <assert.h>
# include <nuttx/kthread.h>
# ifndef CONFIG_STM32F429I_DISCO_BOARDINIT_PRIO
# define CONFIG_STM32F429I_DISCO_BOARDINIT_PRIO 196
# endif
# ifndef CONFIG_STM32F429I_DISCO_BOARDINIT_STACK
# define CONFIG_STM32F429I_DISCO_BOARDINIT_STACK 2048
# endif
#endif
/************************************************************************************
* Public Functions
@ -131,6 +198,17 @@ void stm32_boardinitialize(void)
#ifdef CONFIG_BOARD_INITIALIZE
void board_initialize(void)
{
#ifdef HAVE_INITTHREAD
pid_t server;
/* Start the board initialization kernel thread */
server = kernel_thread("Board Init", CONFIG_STM32F429I_DISCO_BOARDINIT_PRIO,
CONFIG_STM32F429I_DISCO_BOARDINIT_STACK, board_initthread,
NULL);
ASSERT(server > 0);
#endif
#ifdef CONFIG_STM32F429I_DISCO_ILI9341_FBIFACE
/* Initialize the framebuffer driver */

View File

@ -0,0 +1,357 @@
/************************************************************************************
* configs/stm32f429i-disco/src/stm32_stmpe811.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/board.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/input/touchscreen.h>
#include <nuttx/input/stmpe811.h>
#include <nuttx/irq.h>
#include "stm32.h"
#include "stm32f429i-disco.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifdef CONFIG_INPUT_STMPE811
#ifndef CONFIG_INPUT
# error "STMPE811 support requires CONFIG_INPUT"
#endif
#ifndef CONFIG_STM32_I2C3
# error "STMPE811 support requires CONFIG_STM32_I2C3"
#endif
#ifndef CONFIG_STMPE811_I2C
# error "Only the STMPE811 I2C interface is supported"
#endif
#ifdef CONFIG_STMPE811_SPI
# error "Only the STMPE811 SPI interface is supported"
#endif
#ifndef CONFIG_STMPE811_FREQUENCY
# define CONFIG_STMPE811_FREQUENCY 100000
#endif
#ifndef CONFIG_STMPE811_I2CDEV
# define CONFIG_STMPE811_I2CDEV 3
#endif
#if CONFIG_STMPE811_I2CDEV != 3
# error "CONFIG_STMPE811_I2CDEV must be three"
#endif
#ifndef CONFIG_STMPE811_DEVMINOR
# define CONFIG_STMPE811_DEVMINOR 0
#endif
/* Board definitions ********************************************************/
/* The STM3240G-EVAL has two STMPE811QTR I/O expanders on board both connected
* to the STM32 via I2C1. They share a common interrupt line: PI2.
*
* STMPE811 U24, I2C address 0x41 (7-bit)
* ------ ---- ---------------- --------------------------------------------
* STPE11 PIN BOARD SIGNAL BOARD CONNECTION
* ------ ---- ---------------- --------------------------------------------
* Y- TouchScreen_Y- LCD Connector XL
* X- TouchScreen_X- LCD Connector XR
* Y+ TouchScreen_Y+ LCD Connector XD
* X+ TouchScreen_X+ LCD Connector XU
* IN3 EXP_IO9
* IN2 EXP_IO10
* IN1 EXP_IO11
* IN0 EXP_IO12
*
* STMPE811 U29, I2C address 0x44 (7-bit)
* ------ ---- ---------------- --------------------------------------------
* STPE11 PIN BOARD SIGNAL BOARD CONNECTION
* ------ ---- ---------------- --------------------------------------------
* Y- EXP_IO1
* X- EXP_IO2
* Y+ EXP_IO3
* X+ EXP_IO4
* IN3 EXP_IO5
* IN2 EXP_IO6
* IN1 EXP_IO7
* IN0 EXP_IO8
*/
/****************************************************************************
* Private Types
****************************************************************************/
struct stm32_stmpe811config_s
{
/* Configuration structure as seen by the STMPE811 driver */
struct stmpe811_config_s config;
/* Additional private definitions only known to this driver */
STMPE811_HANDLE handle; /* The STMPE811 driver handle */
xcpt_t handler; /* The STMPE811 interrupt handler */
};
/****************************************************************************
* Static Function Prototypes
****************************************************************************/
/* IRQ/GPIO access callbacks. These operations all hidden behind callbacks
* to isolate the STMPE811 driver from differences in GPIO
* interrupt handling by varying boards and MCUs.* so that contact and loss-
* of-contact events can be detected.
*
* attach - Attach the STMPE811 interrupt handler to the GPIO interrupt
* enable - Enable or disable the GPIO interrupt
* clear - Acknowledge/clear any pending GPIO interrupt
*/
static int stmpe811_attach(FAR struct stmpe811_config_s *state, xcpt_t isr);
static void stmpe811_enable(FAR struct stmpe811_config_s *state, bool enable);
static void stmpe811_clear(FAR struct stmpe811_config_s *state);
/****************************************************************************
* Private Data
****************************************************************************/
/* A reference to a structure of this type must be passed to the STMPE811
* driver. This structure provides information about the configuration
* of the STMPE811 and provides some board-specific hooks.
*
* Memory for this structure is provided by the caller. It is not copied
* by the driver and is presumed to persist while the driver is active. The
* memory must be writable because, under certain circumstances, the driver
* may modify frequency or X plate resistance values.
*/
#ifndef CONFIG_STMPE811_TSC_DISABLE
static struct stm32_stmpe811config_s g_stmpe811config =
{
.config =
{
#ifdef CONFIG_STMPE811_I2C
.address = STMPE811_ADDR1,
#endif
.frequency = CONFIG_STMPE811_FREQUENCY,
#ifdef CONFIG_STMPE811_MULTIPLE
.irq = STM32_IRQ_EXTI2,
#endif
.ctrl1 = (ADC_CTRL1_SAMPLE_TIME_80 | ADC_CTRL1_MOD_12B),
.ctrl2 = ADC_CTRL2_ADC_FREQ_3p25,
.attach = stmpe811_attach,
.enable = stmpe811_enable,
.clear = stmpe811_clear,
},
.handler = NULL,
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/* IRQ/GPIO access callbacks. These operations all hidden behind
* callbacks to isolate the STMPE811 driver from differences in GPIO
* interrupt handling by varying boards and MCUs.
*
* attach - Attach the STMPE811 interrupt handler to the GPIO interrupt
* enable - Enable or disable the GPIO interrupt
* clear - Acknowledge/clear any pending GPIO interrupt
*/
static int stmpe811_attach(FAR struct stmpe811_config_s *state, xcpt_t isr)
{
FAR struct stm32_stmpe811config_s *priv =
(FAR struct stm32_stmpe811config_s *)state;
iinfo("Saving handler %p\n", isr);
DEBUGASSERT(priv);
/* Just save the handler. We will use it when EXTI interruptsare enabled */
priv->handler = isr;
return OK;
}
static void stmpe811_enable(FAR struct stmpe811_config_s *state, bool enable)
{
FAR struct stm32_stmpe811config_s *priv =
(FAR struct stm32_stmpe811config_s *)state;
irqstate_t flags;
/* Attach and enable, or detach and disable. Enabling and disabling GPIO
* interrupts is a multi-step process so the safest thing is to keep
* interrupts disabled during the reconfiguration.
*/
flags = enter_critical_section();
if (enable)
{
/* Configure the EXTI interrupt using the SAVED handler */
(void)stm32_gpiosetevent(GPIO_IO_EXPANDER, true, true, true,
priv->handler);
}
else
{
/* Configure the EXTI interrupt with a NULL handler to disable it */
(void)stm32_gpiosetevent(GPIO_IO_EXPANDER, false, false, false, NULL);
}
leave_critical_section(flags);
}
static void stmpe811_clear(FAR struct stmpe811_config_s *state)
{
/* Does nothing */
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_tsc_setup
*
* Description:
* Each board that supports a touchscreen device must provide this function.
* This function is called by application-specific, setup logic to
* configure the touchscreen device. This function will register the driver
* as /dev/inputN where N is the minor device number.
*
* Input Parameters:
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int board_tsc_setup(int minor)
{
#ifndef CONFIG_STMPE811_TSC_DISABLE
FAR struct i2c_master_s *dev;
int ret;
iinfo("minor %d\n", minor);
DEBUGASSERT(minor == 0);
/* Check if we are already initialized */
if (!g_stmpe811config.handle)
{
iinfo("Initializing\n");
/* Configure the STMPE811 interrupt pin as an input */
(void)stm32_configgpio(GPIO_IO_EXPANDER);
/* Get an instance of the I2C interface */
dev = stm32_i2cbus_initialize(CONFIG_STMPE811_I2CDEV);
if (!dev)
{
ierr("ERROR: Failed to initialize I2C bus %d\n", CONFIG_STMPE811_I2CDEV);
return -ENODEV;
}
/* Instantiate the STMPE811 driver */
g_stmpe811config.handle =
stmpe811_instantiate(dev, (FAR struct stmpe811_config_s *)&g_stmpe811config);
if (!g_stmpe811config.handle)
{
ierr("ERROR: Failed to instantiate the STMPE811 driver\n");
return -ENODEV;
}
/* Initialize and register the I2C touchscreen device */
ret = stmpe811_register(g_stmpe811config.handle, CONFIG_STMPE811_DEVMINOR);
if (ret < 0)
{
ierr("ERROR: Failed to register STMPE driver: %d\n", ret);
/* stm32_i2cbus_uninitialize(dev); */
return -ENODEV;
}
}
return OK;
#else
return -ENOSYS;
#endif
}
/****************************************************************************
* Name: board_tsc_teardown
*
* Description:
* Each board that supports a touchscreen device must provide this function.
* This function is called by application-specific, setup logic to
* uninitialize the touchscreen device.
*
* Input Parameters:
* None
*
* Returned Value:
* None.
*
****************************************************************************/
void board_tsc_teardown(void)
{
/* No support for un-initializing the touchscreen STMPE811 device yet */
}
#endif /* CONFIG_INPUT_STMPE811 */

View File

@ -66,6 +66,16 @@
# undef CONFIG_STM32_SPI3
#endif
/* STMPE811 on I2C3 */
//#define GPIO_I2C3_SCL GPIO_I2C3_SCL_1
//#define GPIO_I2C3_SDA GPIO_I2C3_SDA_1
#define STMPE811_ADDR1 0x41
#define STMPE811_ADDR2 0x44
#define GPIO_IO_EXPANDER (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTA|GPIO_PIN15)
/* STM32F429 Discovery GPIOs **************************************************************************/
/* LEDs */

View File

@ -960,7 +960,7 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
#endif
#if CONFIG_NSOCKET_DESCRIPTORS > 0
linesize = snprintf(procfile->line, STATUS_LINELEN, "\n%3-s %-2s %-3s %s\n",
linesize = snprintf(procfile->line, STATUS_LINELEN, "\n%-3s %-2s %-3s %s\n",
"SD", "RF", "TYP", "FLAGS");
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset);
@ -983,7 +983,7 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
{
linesize = snprintf(procfile->line, STATUS_LINELEN, "%3d %2d %3d %02x",
i + CONFIG_NFILE_DESCRIPTORS,
(long)socket->s_crefs, socket->s_type, socket->s_flags);
socket->s_crefs, socket->s_type, socket->s_flags);
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset);
totalsize += copysize;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* nuttx/graphics/nxterm/nxterm.h
*
* Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2014, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -33,8 +33,8 @@
*
****************************************************************************/
#ifndef __GRAPHICS_NXTERM_NXTERM_INTERNAL_H
#define __GRAPHICS_NXTERM_NXTERM_INTERNAL_H
#ifndef __GRAPHICS_NXTERM_NXTERM_H
#define __GRAPHICS_NXTERM_NXTERM_H
/****************************************************************************
* Included Files
@ -61,10 +61,6 @@
#define BMFLAGS_NOGLYPH (1 << 0) /* No glyph available, use space */
#define BM_ISSPACE(bm) (((bm)->flags & BMFLAGS_NOGLYPH) != 0)
/* Sizes and maximums */
#define MAX_USECNT 255 /* Limit to range of a uint8_t */
/* Device path formats */
#define NX_DEVNAME_FORMAT "/dev/nxterm%d"
@ -81,6 +77,7 @@
/****************************************************************************
* Public Types
****************************************************************************/
/* Identifies the state of the VT100 escape sequence processing */
enum nxterm_vt100state_e
@ -111,18 +108,6 @@ struct nxterm_operations_s
unsigned int stride);
};
/* Describes one cached glyph bitmap */
struct nxterm_glyph_s
{
uint8_t code; /* Character code */
uint8_t height; /* Height of this glyph (in rows) */
uint8_t width; /* Width of this glyph (in pixels) */
uint8_t stride; /* Width of the glyph row (in bytes) */
uint8_t usecnt; /* Use count */
FAR uint8_t *bitmap; /* Allocated bitmap memory */
};
/* Describes on character on the display */
struct nxterm_bitmap_s
@ -138,8 +123,7 @@ struct nxterm_state_s
{
FAR const struct nxterm_operations_s *ops; /* Window operations */
FAR void *handle; /* The window handle */
FAR struct nxterm_window_s wndo; /* Describes the window and font */
NXHANDLE font; /* The current font handle */
FAR struct nxterm_window_s wndo; /* Describes the window and font */
sem_t exclsem; /* Forces mutually exclusive access */
#ifdef CONFIG_DEBUG_FEATURES
pid_t holder; /* Deadlock avoidance */
@ -151,7 +135,6 @@ struct nxterm_state_s
uint8_t fheight; /* Max height of a font in pixels */
uint8_t fwidth; /* Max width of a font in pixels */
uint8_t spwidth; /* The width of a space */
uint8_t maxglyphs; /* Size of the glyph[] array */
uint16_t maxchars; /* Size of the bm[] array */
uint16_t nchars; /* Number of chars in the bm[] array */
@ -165,13 +148,10 @@ struct nxterm_state_s
/* Font cache data storage */
FCACHE fcache; /* Font cache handle */
struct nxterm_bitmap_s cursor;
struct nxterm_bitmap_s bm[CONFIG_NXTERM_MXCHARS];
/* Glyph cache data storage */
struct nxterm_glyph_s glyph[CONFIG_NXTERM_CACHESIZE];
/* Keyboard input support */
#ifdef CONFIG_NXTERM_NXKBDIN
@ -235,8 +215,8 @@ enum nxterm_vt100state_e nxterm_vt100(FAR struct nxterm_state_s *priv, char ch);
void nxterm_home(FAR struct nxterm_state_s *priv);
void nxterm_newline(FAR struct nxterm_state_s *priv);
FAR const struct nxterm_bitmap_s *nxterm_addchar(NXHANDLE hfont,
FAR struct nxterm_state_s *priv, uint8_t ch);
FAR const struct nxterm_bitmap_s *nxterm_addchar(FAR struct nxterm_state_s *priv,
uint8_t ch);
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
FAR const struct nxterm_bitmap_s *bm);
int nxterm_backspace(FAR struct nxterm_state_s *priv);
@ -251,4 +231,4 @@ void nxterm_hidecursor(FAR struct nxterm_state_s *priv);
void nxterm_scroll(FAR struct nxterm_state_s *priv, int scrollheight);
#endif /* __GRAPHICS_NXTERM_NXTERM_INTERNAL_H */
#endif /* __GRAPHICS_NXTERM_NXTERM_H */

View File

@ -48,294 +48,26 @@
#include "nxterm.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Select renderer -- Some additional logic would be required to support
* pixel depths that are not directly addressable (1,2,4, and 24).
*/
#if CONFIG_NXTERM_BPP == 1
# define RENDERER nxf_convert_1bpp
#elif CONFIG_NXTERM_BPP == 2
# define RENDERER nxf_convert_2bpp
#elif CONFIG_NXTERM_BPP == 4
# define RENDERER nxf_convert_4bpp
#elif CONFIG_NXTERM_BPP == 8
# define RENDERER nxf_convert_8bpp
#elif CONFIG_NXTERM_BPP == 16
# define RENDERER nxf_convert_16bpp
#elif CONFIG_NXTERM_BPP == 24
# define RENDERER nxf_convert_24bpp
#elif CONFIG_NXTERM_BPP == 32
# define RENDERER nxf_convert_32bpp
#else
# error "Unsupported CONFIG_NXTERM_BPP"
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxterm_freeglyph
****************************************************************************/
static void nxterm_freeglyph(FAR struct nxterm_glyph_s *glyph)
{
if (glyph->bitmap)
{
kmm_free(glyph->bitmap);
}
memset(glyph, 0, sizeof(struct nxterm_glyph_s));
}
/****************************************************************************
* Name: nxterm_allocglyph
****************************************************************************/
static inline FAR struct nxterm_glyph_s *
nxterm_allocglyph(FAR struct nxterm_state_s *priv)
{
FAR struct nxterm_glyph_s *glyph = NULL;
FAR struct nxterm_glyph_s *luglyph = NULL;
uint8_t luusecnt;
int i;
/* Search through the glyph cache looking for an unused glyph. Also, keep
* track of the least used glyph as well. We need that if we have to replace
* a glyph in the cache.
*/
for (i = 0; i < priv->maxglyphs; i++)
{
/* Is this glyph in use? */
glyph = &priv->glyph[i];
if (!glyph->usecnt)
{
/* No.. return this glyph with a use count of one */
glyph->usecnt = 1;
return glyph;
}
/* Yes.. check for the least recently used */
if (!luglyph || glyph->usecnt < luglyph->usecnt)
{
luglyph = glyph;
}
}
/* If we get here, the glyph cache is full. We replace the least used
* glyph with the one we need now. (luglyph can't be NULL).
*/
luusecnt = luglyph->usecnt;
nxterm_freeglyph(luglyph);
/* But lets decrement all of the usecnts so that the new one one be so
* far behind in the counts as the older ones.
*/
if (luusecnt > 1)
{
uint8_t decr = luusecnt - 1;
for (i = 0; i < priv->maxglyphs; i++)
{
/* Is this glyph in use? */
glyph = &priv->glyph[i];
if (glyph->usecnt > decr)
{
glyph->usecnt -= decr;
}
}
}
/* Then return the least used glyph */
luglyph->usecnt = 1;
return luglyph;
}
/****************************************************************************
* Name: nxterm_findglyph
****************************************************************************/
static FAR struct nxterm_glyph_s *
nxterm_findglyph(FAR struct nxterm_state_s *priv, uint8_t ch)
{
int i;
/* First, try to find the glyph in the cache of pre-rendered glyphs */
for (i = 0; i < priv->maxglyphs; i++)
{
FAR struct nxterm_glyph_s *glyph = &priv->glyph[i];
if (glyph->usecnt > 0 && glyph->code == ch)
{
/* Increment the use count (unless it is already at the max) */
if (glyph->usecnt < MAX_USECNT)
{
glyph->usecnt++;
}
/* And return the glyph that we found */
return glyph;
}
}
return NULL;
}
/****************************************************************************
* Name: nxterm_renderglyph
****************************************************************************/
static inline FAR struct nxterm_glyph_s *
nxterm_renderglyph(FAR struct nxterm_state_s *priv,
FAR const struct nx_fontbitmap_s *fbm, uint8_t ch)
{
FAR struct nxterm_glyph_s *glyph = NULL;
FAR nxgl_mxpixel_t *ptr;
#if CONFIG_NXTERM_BPP < 8
nxgl_mxpixel_t pixel;
#endif
int bmsize;
int row;
int col;
int ret;
/* Allocate the glyph (always succeeds) */
glyph = nxterm_allocglyph(priv);
glyph->code = ch;
/* Get the dimensions of the glyph */
glyph->width = fbm->metric.width + fbm->metric.xoffset;
glyph->height = fbm->metric.height + fbm->metric.yoffset;
/* Get the physical width of the glyph in bytes */
glyph->stride = (glyph->width * CONFIG_NXTERM_BPP + 7) / 8;
/* Allocate memory to hold the glyph with its offsets */
bmsize = glyph->stride * glyph->height;
glyph->bitmap = (FAR uint8_t *)kmm_malloc(bmsize);
if (glyph->bitmap)
{
/* Initialize the glyph memory to the background color using the
* hard-coded bits-per-pixel (BPP).
*
* TODO: The rest of NX is configured to support multiple devices
* with differing BPP. They logic should be extended to support
* differing BPP's as well.
*/
#if CONFIG_NXTERM_BPP < 8
pixel = priv->wndo.wcolor[0];
# if CONFIG_NXTERM_BPP == 1
/* Pack 1-bit pixels into a 2-bits */
pixel &= 0x01;
pixel = (pixel) << 1 | pixel;
# endif
# if CONFIG_NXTERM_BPP < 4
/* Pack 2-bit pixels into a nibble */
pixel &= 0x03;
pixel = (pixel) << 2 | pixel;
# endif
/* Pack 4-bit nibbles into a byte */
pixel &= 0x0f;
pixel = (pixel) << 4 | pixel;
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
for (row = 0; row < glyph->height; row++)
{
for (col = 0; col < glyph->stride; col++)
{
/* Transfer the packed bytes into the buffer */
*ptr++ = pixel;
}
}
#elif CONFIG_NXTERM_BPP == 24
# error "Additional logic is needed here for 24bpp support"
#else /* CONFIG_NXTERM_BPP = {8,16,32} */
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
for (row = 0; row < glyph->height; row++)
{
/* Just copy the color value into the glyph memory */
for (col = 0; col < glyph->width; col++)
{
*ptr++ = priv->wndo.wcolor[0];
}
}
#endif
/* Then render the glyph into the allocated memory */
ret = RENDERER((FAR nxgl_mxpixel_t *)glyph->bitmap,
glyph->height, glyph->width, glyph->stride,
fbm, priv->wndo.fcolor[0]);
if (ret < 0)
{
/* Actually, the RENDERER never returns a failure */
gerr("ERROR: nxterm_renderglyph: RENDERER failed\n");
nxterm_freeglyph(glyph);
glyph = NULL;
}
}
return glyph;
}
/****************************************************************************
* Name: nxterm_fontsize
****************************************************************************/
static int nxterm_fontsize(NXHANDLE hfont, uint8_t ch, FAR struct nxgl_size_s *size)
static int nxterm_fontsize(FAR struct nxterm_state_s *priv, uint8_t ch,
FAR struct nxgl_size_s *size)
{
FAR const struct nx_fontbitmap_s *fbm;
NXHANDLE hfont;
/* No, it is not cached... Does the code map to a font? */
/* Get the handle of the font managed by the font cache */
hfont = nxf_cache_getfonthandle(priv->fcache);
DEBUGASSERT(hfont != NULL);
/* Does the character code map to a font? */
fbm = nxf_getbitmap(hfont, ch);
if (fbm)
@ -347,40 +79,7 @@ static int nxterm_fontsize(NXHANDLE hfont, uint8_t ch, FAR struct nxgl_size_s *s
return OK;
}
return ERROR;
}
/****************************************************************************
* Name: nxterm_getglyph
****************************************************************************/
static FAR struct nxterm_glyph_s *
nxterm_getglyph(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
{
FAR struct nxterm_glyph_s *glyph;
FAR const struct nx_fontbitmap_s *fbm;
/* First, try to find the glyph in the cache of pre-rendered glyphs */
glyph = nxterm_findglyph(priv, ch);
if (glyph)
{
/* We found it in the cache .. return the cached glyph */
return glyph;
}
/* No, it is not cached... Does the code map to a font? */
fbm = nxf_getbitmap(hfont, ch);
if (fbm)
{
/* Yes.. render the glyph */
glyph = nxterm_renderglyph(priv, fbm, ch);
}
return glyph;
return -ENOENT;
}
/****************************************************************************
@ -397,10 +96,10 @@ nxterm_getglyph(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
****************************************************************************/
FAR const struct nxterm_bitmap_s *
nxterm_addchar(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
nxterm_addchar(FAR struct nxterm_state_s *priv, uint8_t ch)
{
FAR struct nxterm_bitmap_s *bm = NULL;
FAR struct nxterm_glyph_s *glyph;
FAR const struct nxfonts_glyph_s *glyph;
/* Is there space for another character on the display? */
@ -416,7 +115,7 @@ nxterm_addchar(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
/* Find (or create) the matching glyph */
glyph = nxterm_getglyph(hfont, priv, ch);
glyph = nxf_cache_getglyph(priv->fcache, ch);
if (!glyph)
{
/* No, there is no font for this code. Just mark this as a space. */
@ -449,6 +148,7 @@ nxterm_addchar(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
* Erase a character from the window.
*
****************************************************************************/
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
FAR const struct nxterm_bitmap_s *bm)
{
@ -461,7 +161,7 @@ int nxterm_hidechar(FAR struct nxterm_state_s *priv,
* modification is required (not an error).
*/
ret = nxterm_fontsize(priv->font, bm->code, &fsize);
ret = nxterm_fontsize(priv, bm->code, &fsize);
if (ret < 0)
{
/* It was rendered as a space. */
@ -572,10 +272,10 @@ void nxterm_newline(FAR struct nxterm_state_s *priv)
****************************************************************************/
void nxterm_fillchar(FAR struct nxterm_state_s *priv,
FAR const struct nxgl_rect_s *rect,
FAR const struct nxterm_bitmap_s *bm)
FAR const struct nxgl_rect_s *rect,
FAR const struct nxterm_bitmap_s *bm)
{
FAR struct nxterm_glyph_s *glyph;
FAR const struct nxfonts_glyph_s *glyph;
struct nxgl_rect_s bounds;
struct nxgl_rect_s intersection;
struct nxgl_size_s fsize;
@ -590,7 +290,7 @@ void nxterm_fillchar(FAR struct nxterm_state_s *priv,
/* Get the size of the font glyph (which may not have been created yet) */
ret = nxterm_fontsize(priv->font, bm->code, &fsize);
ret = nxterm_fontsize(priv, bm->code, &fsize);
if (ret < 0)
{
/* This would mean that there is no bitmap for the character code and
@ -632,7 +332,7 @@ void nxterm_fillchar(FAR struct nxterm_state_s *priv,
/* Find (or create) the glyph that goes with this font */
glyph = nxterm_getglyph(priv->font, priv, bm->code);
glyph = nxf_cache_getglyph(priv->fcache, bm->code);
if (!glyph)
{
/* Shouldn't happen */
@ -648,4 +348,3 @@ void nxterm_fillchar(FAR struct nxterm_state_s *priv,
DEBUGASSERT(ret >= 0);
}
}

View File

@ -142,7 +142,7 @@ void nxterm_putc(FAR struct nxterm_state_s *priv, uint8_t ch)
* display.
*/
bm = nxterm_addchar(priv->font, priv, ch);
bm = nxterm_addchar(priv, ch);
if (bm)
{
nxterm_fillchar(priv, NULL, bm);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* nuttx/graphics/nxterm/nxterm_register.c
*
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -66,7 +66,9 @@ FAR struct nxterm_state_s *
FAR const struct nxterm_operations_s *ops, int minor)
{
FAR struct nxterm_state_s *priv;
FAR const struct nx_font_s *fontset;
char devname[NX_DEVNAME_SIZE];
NXHANDLE hfont;
int ret;
DEBUGASSERT(handle && wndo && ops && (unsigned)minor < 256);
@ -101,22 +103,33 @@ FAR struct nxterm_state_s *
sem_setprotocol(&priv->waitsem, SEM_PRIO_NONE);
#endif
/* Select the font */
/* Connect to the font cache for the configured font characteristics */
priv->font = nxf_getfonthandle(wndo->fontid);
if (!priv->font)
priv->fcache = nxf_cache_connect(wndo->fontid, wndo->fcolor[0],
wndo->wcolor[0], CONFIG_NXTERM_BPP,
CONFIG_NXTERM_CACHESIZE);
if (priv->fcache == NULL)
{
gerr("ERROR: Failed to get font ID %d: %d\n", wndo->fontid, errno);
gerr("ERROR: Failed to connect to font cache for font ID %d: %d\n",
wndo->fontid, errno);
goto errout;
}
FAR const struct nx_font_s *fontset;
/* Get the handle of the font managed by the font cache */
hfont = nxf_cache_getfonthandle(priv->fcache);
if (hfont == NULL)
{
gerr("ERROR: Failed to get handlr for font ID %d: %d\n",
wndo->fontid, errno);
goto errout;
}
/* Get information about the font set being used and save this in the
* state structure
*/
fontset = nxf_getfontset(priv->font);
fontset = nxf_getfontset(hfont);
priv->fheight = fontset->mxheight;
priv->fwidth = fontset->mxwidth;
priv->spwidth = fontset->spwidth;
@ -125,10 +138,6 @@ FAR struct nxterm_state_s *
priv->maxchars = CONFIG_NXTERM_MXCHARS;
/* Set up the font glyph bitmap cache */
priv->maxglyphs = CONFIG_NXTERM_CACHESIZE;
/* Set the initial display position */
nxterm_home(priv);
@ -146,6 +155,7 @@ FAR struct nxterm_state_s *
{
gerr("ERROR: Failed to register %s\n", devname);
}
return (NXTERM)priv;
errout:

View File

@ -50,22 +50,6 @@
#include "nxterm.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
@ -89,7 +73,6 @@ void nxterm_unregister(NXTERM handle)
{
FAR struct nxterm_state_s *priv;
char devname[NX_DEVNAME_SIZE];
int i;
DEBUGASSERT(handle);
@ -101,16 +84,9 @@ void nxterm_unregister(NXTERM handle)
sem_destroy(&priv->waitsem);
#endif
/* Free all allocated glyph bitmap */
/* Free the font cache */
for (i = 0; i < CONFIG_NXTERM_CACHESIZE; i++)
{
FAR struct nxterm_glyph_s *glyph = &priv->glyph[i];
if (glyph->bitmap)
{
kmm_free(glyph->bitmap);
}
}
nxf_cache_disconnect(priv->fcache);
/* Unregister the driver */

View File

@ -51,6 +51,7 @@
* Pre-processor definitions
****************************************************************************/
/* Font Definitions *********************************************************/
/* Select the default font. If no fonts are selected, then a compilation
* error is likely down the road.
*/
@ -206,6 +207,7 @@
* Public Types
****************************************************************************/
/* Font Types ***************************************************************/
/* Font IDs */
enum nx_fontid_e
@ -453,6 +455,25 @@ struct nx_fontpackage_s
#endif
};
/* Font Cache ***************************************************************/
/* Opaque handle used to reference a font cache */
typedef FAR void *FCACHE;
/* Describes one cached font glyph */
struct nxfonts_glyph_s
{
FAR struct nxfonts_glyph_s *flink; /* Implements a singly linked list */
uint8_t code; /* Character code */
uint8_t height; /* Height of this glyph (in rows) */
uint8_t width; /* Width of this glyph (in pixels) */
uint8_t stride; /* Width of the glyph row (in bytes) */
FAR uint8_t bitmap[1]; /* Bitmap memory, actual size varies */
};
#define SIZEOF_NXFONTS_GLYPH_S(b) (sizeof(struct nxfonts_glyph_s) + (b) - 1)
/****************************************************************************
* Public Data
****************************************************************************/
@ -480,6 +501,9 @@ extern "C"
* Input Parameters:
* fontid: Identifies the font set to get
*
* Returned Value:
* One success, a non-NULL font handle is returned.
*
****************************************************************************/
NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid);
@ -564,6 +588,87 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
FAR const struct nx_fontbitmap_s *bm,
nxgl_mxpixel_t color);
/****************************************************************************
* Name: nxf_cache_connect
*
* Description:
* Create a new font cache for the provided 'fontid'. If the cache
* already, then just increment a reference count return the handle for
* the existing font cache.
*
* Input Parameters:
* fontid - Identifies the font supported by this cache
* fgcolor - Foreground color
* bgcolor - Background color
* bpp - Bits per pixel
* maxglyphs - Maximum number of glyphs permitted in the cache
*
* Returned value:
* On success a non-NULL handle is returned that then may sequently be
* used with nxf_getglyph() to extract fonts from the font cache. NULL
* returned on any failure with the errno value set to indicate the nature
* of the error.
*
****************************************************************************/
FCACHE nxf_cache_connect(enum nx_fontid_e fontid,
nxgl_mxpixel_t fgcolor, nxgl_mxpixel_t bgcolor,
int bpp, int maxglyph);
/****************************************************************************
* Name: nxf_cache_disconnect
*
* Description:
* Decrement the reference count on the font cache and, if the reference
* count goes to zero, free all resources used by the font cache. The
* font handler is invalid upon return in either case.
*
* Input Parameters:
* fhandle - A font cache handler previously returned by nxf_cache_connect();
*
* Returned value:
* None
*
****************************************************************************/
void nxf_cache_disconnect(FCACHE fhandle);
/****************************************************************************
* Name: nxf_cache_getfonthandle
*
* Description:
* Return the handle to the font set used by this instance of the font
* cache.
*
* Input Parameters:
* fhandle - A font cache handle previously returned by nxf_cache_connect();
*
* Returned value:
* Zero (OK) is returned if the metrics were
*
* Returned Value:
* One success, a non-NULL font handle is returned.
*
****************************************************************************/
NXHANDLE nxf_cache_getfonthandle(FCACHE fhandle);
/****************************************************************************
* Name: nxf_cache_getglyph
*
* Description:
* Get the font glyph for the character code 'ch' from the font cache. If
* the glyph for that character code does not exist in the font cache, it
* be rendered.
*
* Returned Value:
* On success, a non-NULL pointer to the rendered glyph in the font cache
* is returned. NULL is returned on any failure.
*
****************************************************************************/
FAR const struct nxfonts_glyph_s *nxf_cache_getglyph(FCACHE fhandle, uint8_t ch);
#undef EXTERN
#if defined(__cplusplus)
}

View File

@ -58,5 +58,6 @@ void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue)
{
queue->tail = node;
}
queue->head = node;
}

View File

@ -44,10 +44,10 @@
****************************************************************************/
/****************************************************************************
* Name:
* Name: sq_remafter
*
* Description:
* sq_remafter removes the entry following 'node; from the'queue' Returns
* sq_remafter removes the entry following 'node' from the'queue' Returns
* a reference to the removed entry.
*
****************************************************************************/
@ -55,6 +55,7 @@
FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue)
{
FAR sq_entry_t *ret = node->flink;
if (queue->head && ret)
{
if (queue->tail == ret)

View File

@ -591,6 +591,7 @@ static int cmp(Bigint * a, Bigint * b)
break;
}
}
return 0;
}
@ -784,6 +785,7 @@ static Bigint *d2b(double d, int *e, int *bits)
}
while (!x[i])
--i;
b->wds = i + 1;
#endif
if (de)
@ -855,6 +857,7 @@ static int quorem(Bigint * b, Bigint * S)
lerr("ERROR: oversize b in quorem\n");
}
#endif
`
if (b->wds < n)
{
return 0;
@ -867,15 +870,16 @@ static int quorem(Bigint * b, Bigint * S)
q = *bxe / (*sxe + 1); /* ensure q <= true quotient */
#ifdef CONFIG_DEBUG_LIB
if (q > 9)
{
lerr("ERROR: oversized quotient in quorem\n");
}
{
lerr("ERROR: oversized quotient in quorem\n");
}
#endif
if (q)
{
borrow = 0;
carry = 0;
do
{
#ifdef Pack_32
@ -912,6 +916,7 @@ static int quorem(Bigint * b, Bigint * S)
b->wds = n;
}
}
if (cmp(b, S) >= 0)
{
q++;
@ -919,6 +924,7 @@ static int quorem(Bigint * b, Bigint * S)
carry = 0;
bx = b->x;
sx = S->x;
do
{
#ifdef Pack_32
@ -943,6 +949,7 @@ static int quorem(Bigint * b, Bigint * S)
#endif
}
while (sx <= sxe);
bx = b->x;
bxe = bx + n;
if (!*bxe)

View File

@ -44,7 +44,12 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <math.h>
#include <assert.h>
#include <nuttx/arch.h>
#include "libc.h"
@ -157,6 +162,15 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec,
int dsgn; /* Unused sign indicator */
int i;
/* This function may *NOT* be called within interrupt level logic. That is
* because the logic in __dtoa may attempt to allocate memory. That will
* lead to cryptic failures down the road within the memory manager.
* Better to explicitly assert upstream here. Rule: Don't use floating
* point formats on any output from interrupt handling logic.
*/
DEBUGASSERT(up_interrupt_context() == false);
/* Special handling for NaN and Infinity */
if (isnan(value))

View File

@ -37,7 +37,7 @@
ifeq ($(CONFIG_NX),y)
CSRCS += nxfonts_getfont.c
CSRCS += nxfonts_getfont.c nxfonts_cache.c
CSRCS += nxfonts_convert_1bpp.c nxfonts_convert_2bpp.c
CSRCS += nxfonts_convert_4bpp.c nxfonts_convert_8bpp.c
CSRCS += nxfonts_convert_16bpp.c nxfonts_convert_24bpp.c

View File

@ -0,0 +1,935 @@
/****************************************************************************
* libnx/nxfonts/nxfonts_cache.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <semaphore.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx/nxfonts.h>
#include "nxcontext.h"
/****************************************************************************
* Private Types
****************************************************************************/
/* This describes a rendering function */
typedef CODE int (*nxf_renderer_t)(FAR nxgl_mxpixel_t *dest, uint16_t height,
uint16_t width, uint16_t stride,
FAR const struct nx_fontbitmap_s *bm,
nxgl_mxpixel_t color);
/* This structure defines one font cache */
struct nxfonts_fcache_s
{
FAR struct nxfonts_fcache_s *flink; /* Supports a singly linked list */
NXHANDLE font; /* Font handle associated with fontid */
sem_t fsem; /* Serializes access to the font cache */
uint16_t fontid; /* ID of font in this cache */
int16_t fclients; /* Number of connected clients */
uint8_t maxglyphs; /* Maximum size of glyph[] array */
uint8_t nglyphs; /* Current size of glyph[] array */
uint8_t bpp; /* Bits per pixel */
nxgl_mxpixel_t fgcolor; /* Foreground color */
nxgl_mxpixel_t bgcolor; /* Background color */
nxf_renderer_t renderer; /* Font renderer */
/* Glyph cache data storage */
FAR struct nxfonts_glyph_s *head; /* Head of the list of glyphs */
FAR struct nxfonts_glyph_s *tail; /* Tail of the list of glyphs */
};
/****************************************************************************
* Private Data
****************************************************************************/
/* Head of a list of font caches */
static FAR struct nxfonts_fcache_s *g_fcaches;
static sem_t g_cachesem = SEM_INITIALIZER(1);
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxf_list_lock and nxf_list_unlock
*
* Description:
* Get/relinquish exclusive access to the font cache list
*
****************************************************************************/
static void nxf_list_lock(void)
{
int ret;
/* Get exclusive access to the font cache */
while ((ret = sem_wait(&g_cachesem)) < 0)
{
int errorcode = errno;
DEBUGASSERT(errorcode == EINTR || errorcode == ECANCELED);
UNUSED(errorcode);
}
}
#define nxf_list_unlock() (sem_post(&g_cachesem))
/****************************************************************************
* Name: nxf_removecache
*
* Description:
* Removes the entry 'glyph' from the font cache.
*
* Assumptions:
* The caller holds the font cache list semaphore.
*
****************************************************************************/
static inline void nxf_removecache(FAR struct nxfonts_fcache_s *fcache,
FAR struct nxfonts_fcache_s *prev)
{
/* Remove the cache for the list. First check for removal from the head */
if (prev == NULL)
{
/* Replace the head with the node following glyph */
g_fcaches = fcache->flink;
}
/* No.. Remove from the head or from mid-list */
else
{
prev->flink = fcache->flink;
}
fcache->flink = NULL;
}
/****************************************************************************
* Name: nxf_cache_lock and nxf_cache_unlock
*
* Description:
* Get/relinquish exclusive access to the font cache
*
****************************************************************************/
static void nxf_cache_lock(FAR struct nxfonts_fcache_s *priv)
{
int ret;
/* Get exclusive access to the font cache */
while ((ret = sem_wait(&priv->fsem)) < 0)
{
int errorcode = errno;
DEBUGASSERT(errorcode == EINTR || errorcode == ECANCELED);
UNUSED(errorcode);
}
}
#define nxf_cache_unlock(p) (sem_post(&priv->fsem))
/****************************************************************************
* Name: nxf_removeglyph
*
* Description:
* Removes the entry 'glyph' from the font cache.
*
****************************************************************************/
static inline void nxf_removeglyph(FAR struct nxfonts_fcache_s *priv,
FAR struct nxfonts_glyph_s *glyph,
FAR struct nxfonts_glyph_s *prev)
{
ginfo("fcache=%p glyph=%p\n", priv, glyph);
/* Remove the glyph for the list. First check for removal from the head
* (which, I think, never actually happens).
*/
if (prev == NULL)
{
/* Replace the head with the node following glyph */
priv->head = glyph->flink;
/* If there is no node following glyph, then the list is empty */
if (priv->head == NULL)
{
priv->tail = NULL;
}
}
/* Check for removal from the tail (we know that the list cannot become
* empty in either of the next two cases).
*/
else if (glyph->flink == NULL)
{
priv->tail = prev;
prev->flink = NULL;
}
/* No.. Remove from mid-list */
else
{
prev->flink = glyph->flink;
}
glyph->flink = NULL;
/* Decrement the count of glyphs in the font cache */
DEBUGASSERT(priv->nglyphs > 0);
priv->nglyphs--;
}
/****************************************************************************
* Name: nxf_addglyph
*
* Description:
* Add the entry 'glyph' to the head font cache list.
*
****************************************************************************/
static inline void nxf_addglyph(FAR struct nxfonts_fcache_s *priv,
FAR struct nxfonts_glyph_s *glyph)
{
ginfo("fcache=%p glyph=%p\n", priv, glyph);
/* Add the glyph to the head of the list */
glyph->flink = priv->head;
if (priv->head == NULL)
{
priv->tail = glyph;
}
priv->head = glyph;
/* Increment the count of glyphs in the font cache. */
DEBUGASSERT(priv->nglyphs < priv->maxglyphs);
priv->nglyphs++;
}
/****************************************************************************
* Name: nxf_findglyph
*
* Description:
* Find the glyph for the specific character 'ch' in the list of pre-
* rendered fonts in the font cache.
*
* This is logically a part of nxf_cache_getglyph(). nxf_cache_getglyph()
* will attempt to find the cached glyph before rendering a new one. So
* this function has two unexpected side-effects: (1) If the font cache
* is full and the font is not found, then the least-recently-used glyph
* is deleted to make space for the new glyph that will be allocated.
*
* (2) If the glyph is found, then it is moved to the head of the list of
* glyphs since it is now the most recently used (leaving the least
* recently used glyph at the tail of the list).
*
* Assumptions:
* The caller has exclusive access to the font cache.
*
****************************************************************************/
static FAR struct nxfonts_glyph_s *
nxf_findglyph(FAR struct nxfonts_fcache_s *priv, uint8_t ch)
{
FAR struct nxfonts_glyph_s *glyph;
FAR struct nxfonts_glyph_s *prev;
ginfo("fcache=%p ch=%c (%02x)\n",
priv, (ch >= 32 && ch < 128) ? ch : '.', ch);
/* Try to find the glyph in the list of pre-rendered glyphs */
for (prev = NULL, glyph = priv->head;
glyph != NULL;
prev = glyph, glyph = glyph->flink)
{
/* Check if we found the the glyph for this character */
if (glyph->code == ch)
{
/* This is now the most recently used glyph. Move it to the head
* of the list (if it is not already at the head of the list).
*/
if (prev != NULL)
{
nxf_removeglyph(priv, glyph, prev);
nxf_addglyph(priv, glyph);
}
/* And return the glyph that we found */
return glyph;
}
/* Is this the last glyph in the list? Has the cache reached its
* limit for the number of cached fonts?
*/
if (glyph->flink == NULL && priv->nglyphs >= priv->maxglyphs)
{
/* Yes.. then remove it from the list and free the glyph memory.
* We do this because we have all of the information in hand now
* and we will surely need to have this space later.
*/
nxf_removeglyph(priv, glyph, prev);
return NULL;
}
}
return NULL;
}
/****************************************************************************
* Name: nxf_fillglyph
*
* Description:
* Fill the glyph memory with the background color
*
****************************************************************************/
static inline void nxf_fillglyph(FAR struct nxfonts_fcache_s *priv,
FAR struct nxfonts_glyph_s *glyph)
{
int row;
int col;
/* Initialize the glyph memory to the background color. */
#if !defined(CONFIG_NX_DISABLE_1BPP) || !defined(CONFIG_NX_DISABLE_2BPP) || \
!defined(CONFIG_NX_DISABLE_4BPP) || !defined(CONFIG_NX_DISABLE_8BPP)
/* For pixel depths of 1, 2, 4, and 8, build up an 8-bit value containing
* multiple background colored pixels.
*/
if (priv->bpp <= 8)
{
uint8_t pixel = (uint8_t)priv->bgcolor;
FAR uint8_t *ptr;
#ifndef CONFIG_NX_DISABLE_1BPP
/* Pack a 1-bit pixel to 2 pixels */
if (priv->bpp < 2)
{
/* Pack 1-bit pixels into a 2-bits */
pixel &= 0x01;
pixel = (pixel) << 1 | pixel;
}
#endif
#if !defined(CONFIG_NX_DISABLE_1BPP) || !defined(CONFIG_NX_DISABLE_2BPP)
/* Pack a 2-bit pixel to a 4-bit nibble */
if (priv->bpp < 4)
{
/* Pack 2-bit pixels into a nibble */
pixel &= 0x03;
pixel = (pixel) << 2 | pixel;
}
#endif
#if !defined(CONFIG_NX_DISABLE_1BPP) || !defined(CONFIG_NX_DISABLE_2BPP) || \
!defined(CONFIG_NX_DISABLE_4BPP)
/* Pack the 4-bit nibble into a byte */
if (priv->bpp < 8)
{
pixel &= 0x0f;
pixel = (pixel) << 4 | pixel;
}
#endif
/* Then fill the glyph with the packed background color */
ptr = (FAR uint8_t *)glyph->bitmap;
for (row = 0; row < glyph->height; row++)
{
for (col = 0; col < glyph->stride; col++)
{
/* Transfer the packed bytes into the buffer */
*ptr++ = pixel;
}
}
}
else
#endif
#if !defined(CONFIG_NX_DISABLE_16BPP)
if (priv->bpp == 16)
{
FAR uint16_t *ptr = (FAR uint16_t *)glyph->bitmap;
for (row = 0; row < glyph->height; row++)
{
/* Just copy the color value into the glyph memory */
for (col = 0; col < glyph->width; col++)
{
*ptr++ = priv->bgcolor;
}
}
}
else
#endif
#ifndef CONFIG_NX_DISABLE_24BPP
if (priv->bpp == 24)
{
FAR uint32_t *ptr = (FAR uint32_t *)glyph->bitmap;
FAR uint32_t pixel[3];
/* Get two 32-bit values for alternating 32 representations */
pixel[0] = (uint32_t)priv->bgcolor << 8 | (uint32_t)priv->bgcolor >> 16;
pixel[1] = (uint32_t)priv->bgcolor << 16 | (uint32_t)priv->bgcolor >> 8;
pixel[1] = (uint32_t)priv->bgcolor << 24 | (uint32_t)priv->bgcolor;
for (row = 0; row < glyph->height; row++)
{
/* Copy the color value into the glyph memory */
col = 0;
for (; ; )
{
*ptr++ = pixel[0];
if (++col >= glyph->width)
{
break;
}
*ptr++ = pixel[1];
if (++col >= glyph->width)
{
break;
}
*ptr++ = pixel[2];
if (++col >= glyph->width)
{
break;
}
}
}
}
else
#endif
#if !defined(CONFIG_NX_DISABLE_32BPP)
if (priv->bpp == 32)
{
FAR uint32_t *ptr = (FAR uint32_t *)glyph->bitmap;
for (row = 0; row < glyph->height; row++)
{
/* Just copy the color value into the glyph memory */
for (col = 0; col < glyph->width; col++)
{
*ptr++ = priv->bgcolor;
}
}
}
else
#endif
{
PANIC();
}
}
/****************************************************************************
* Name: nxf_renderglyph
*
* Description:
* Allocate memory for a new glyph and render the bitmap font into the
* allocated glyph memory.
*
* Assumptions:
* The caller holds the font cache semaphore.
*
****************************************************************************/
static inline FAR struct nxfonts_glyph_s *
nxf_renderglyph(FAR struct nxfonts_fcache_s *priv,
FAR const struct nx_fontbitmap_s *fbm, uint8_t ch)
{
FAR struct nxfonts_glyph_s *glyph = NULL;
size_t bmsize;
unsigned int height;
unsigned int width;
unsigned int stride;
int ret;
ginfo("fcache=%p fbm=%p ch=%c (%02x)\n",
priv, fbm, (ch >= 32 && ch < 128) ? ch : '.', ch);
/* Get the size of the glyph */
width = fbm->metric.width + fbm->metric.xoffset;
height = fbm->metric.height + fbm->metric.yoffset;
/* Get the physical width of the glyph in bytes */
stride = (width * priv->bpp + 7) >> 3;
/* Allocate the glyph (always succeeds) */
bmsize = stride * height;
glyph = (FAR struct nxfonts_glyph_s *)lib_malloc(SIZEOF_NXFONTS_GLYPH_S(bmsize));
if (glyph != NULL)
{
/* Save the character code, dimensions, and physcial width of the glyph */
glyph->code = ch;
glyph->width = width;
glyph->height = height;
glyph->stride = stride;
/* Initialize the glyph memory to the background color. */
nxf_fillglyph(priv, glyph);
/* Then render the glyph into the allocated, initialized memory */
ret = priv->renderer((FAR nxgl_mxpixel_t *)glyph->bitmap,
glyph->height, glyph->width, glyph->stride,
fbm, priv->fgcolor);
if (ret < 0)
{
/* Actually, the renderer never returns a failure */
gerr("ERROR: nxf_renderglyph: Renderer failed\n");
lib_free(glyph);
return NULL;
}
/* Add the new glyph to the font cache */
nxf_addglyph(priv, glyph);
}
return glyph;
}
/****************************************************************************
* Name: nxf_findcache
*
* Description:
* Find a font cache tht matches the font charcteristics.
*
* Assumptions:
* The caller holds the font cache list semaphore.
*
****************************************************************************/
static FAR struct nxfonts_fcache_s *
nxf_findcache(enum nx_fontid_e fontid, nxgl_mxpixel_t fgcolor,
nxgl_mxpixel_t bgcolor, int bpp)
{
FAR struct nxfonts_fcache_s *fcache;
ginfo("fontid=%p fgcolor=%u bgcolor=%u bpp=%d\n",
fontid, fgcolor, bgcolor, bpp);
/* Search for a cache for this font characteristics */
for (fcache = g_fcaches; fcache != NULL; fcache = fcache->flink)
{
/* Does this font have the same characteristics? */
if (fcache->fontid == fontid &&
fcache->fgcolor == fgcolor &&
fcache->bgcolor == bgcolor &&
fcache->bpp == bpp)
{
/* Yes... return it */
ginfo("Returning fcache=%p\n", fcache);
return fcache;
}
}
ginfo("Not found\n");
return NULL;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxf_cache_connect
*
* Description:
* Create a new font cache for the provided 'fontid'. If the cache
* already, then just increment a reference count return the handle for
* the existing font cache.
*
* Input Parameters:
* fontid - Identifies the font supported by this cache
* fgcolor - Foreground color
* bgcolor - Background color
* bpp - Bits per pixel
* maxglyphs - Maximum number of glyphs permitted in the cache
*
* Returned value:
* On success a non-NULL handle is returned that then may sequently be
* used with nxf_getglyph() to extract fonts from the font cache. NULL
* returned on any failure with the errno value set to indicate the nature
* of the error.
*
****************************************************************************/
FCACHE nxf_cache_connect(enum nx_fontid_e fontid,
nxgl_mxpixel_t fgcolor, nxgl_mxpixel_t bgcolor,
int bpp, int maxglyphs)
{
FAR struct nxfonts_fcache_s *priv;
int errcode;
ginfo("fontid=%p fgcolor=%u bgcolor=%u bpp=%d maxglyphs=%d\n",
fontid, fgcolor, bgcolor, bpp, maxglyphs);
/* Get exclusive access to the font cache list */
nxf_list_lock();
/* Find a font cache with the matching font characteristics */
priv = nxf_findcache(fontid, fgcolor, bgcolor, bpp);
if (priv == NULL)
{
/* There isn't one... we will have to create a new font cache for this
* client.
*/
/* Allocate memory for the (empty) font cache */
priv = (FAR struct nxfonts_fcache_s *)
lib_zalloc(sizeof( struct nxfonts_fcache_s));
if (priv == NULL)
{
errcode = ENOMEM;
goto errout_with_lock;
}
/* Initialize the font cache */
priv->fontid = fontid;
priv->fclients = 1;
priv->maxglyphs = maxglyphs;
priv->bpp = bpp;
priv->fgcolor = fgcolor;
priv->bgcolor = bgcolor;
/* Select the rendering function */
/* Select renderer -- Some additional logic would be required to
* support pixel depths that are not directly addressable (1,2,4, and
* 24).
*/
switch (bpp)
{
#ifndef CONFIG_NX_DISABLE_1BPP
case 1:
priv->renderer = (nxf_renderer_t)nxf_convert_1bpp;
break;
#endif
#ifndef CONFIG_NX_DISABLE_2BPP
case 2:
priv->renderer = (nxf_renderer_t)nxf_convert_2bpp;
break;
#endif
#ifndef CONFIG_NX_DISABLE_4BPP
case 4:
priv->renderer = (nxf_renderer_t)nxf_convert_4bpp;
break;
#endif
#ifndef CONFIG_NX_DISABLE_8BPP
case 8:
priv->renderer = (nxf_renderer_t)nxf_convert_8bpp;
break;
#endif
#ifndef CONFIG_NX_DISABLE_16BPP
case 16:
priv->renderer = (nxf_renderer_t)nxf_convert_16bpp;
break;
#endif
#ifndef CONFIG_NX_DISABLE_24BPP
case 24:
priv->renderer = (nxf_renderer_t)nxf_convert_24bpp;
break;
#endif
#ifndef CONFIG_NX_DISABLE_32BPP
case 32:
priv->renderer = (nxf_renderer_t)nxf_convert_32bpp;
break;
#endif
default:
gerr("ERROR: Unsupported pixel depth: %d\n", bpp);
errcode = ENOSYS;
goto errout_with_fcache;
}
/* Select the font */
priv->font = nxf_getfonthandle(fontid);
if (priv->font == NULL)
{
errcode = get_errno();
gerr("ERROR: Failed to get font ID %d: %d\n", fontid, errcode);
goto errout_with_fcache;
}
/* Initialize the mutual exclusion semaphore */
sem_init(&priv->fsem, 0, 1);
/* Add the new font cache to the list of font caches */
priv->flink = g_fcaches;
g_fcaches = priv;
}
else
{
/* A font cache with these characteristics already exists. Just make
* sure that it is as least a big as the size requested.
*/
if (priv->maxglyphs < maxglyphs)
{
priv->maxglyphs = maxglyphs;
}
/* Increment the number of clients of the font cache */
priv->fclients++;
}
nxf_list_unlock();
ginfo("fhandle=%p\n", priv);
return (FCACHE)priv;
errout_with_fcache:
lib_free(priv);
errout_with_lock:
nxf_list_unlock();
set_errno(errcode);
return NULL;
}
/****************************************************************************
* Name: nxf_cache_disconnect
*
* Description:
* Decrement the reference count on the font cache and, if the reference
* count goes to zero, free all resources used by the font cache. The
* font handle is invalid upon return in either case.
*
* Input Parameters:
* fhandle - A font cache handle previously returned by nxf_cache_connect();
*
* Returned value:
* None
*
****************************************************************************/
void nxf_cache_disconnect(FCACHE fhandle)
{
FAR struct nxfonts_fcache_s *priv = (FAR struct nxfonts_fcache_s *)fhandle;
FAR struct nxfonts_fcache_s *fcache;
FAR struct nxfonts_fcache_s *prev;
FAR struct nxfonts_glyph_s *glyph;
FAR struct nxfonts_glyph_s *next;
ginfo("fhandle=%p\n", fhandle);
DEBUGASSERT(priv != NULL && priv->fclients > 0);
/* Get exclusive access to the font cache */
nxf_cache_lock(priv);
/* Is this the last client of the font cache? */
if (priv->fclients <= 1)
{
/* Get exclusive access to the font cache list */
nxf_list_lock();
/* Remove the font cache from the list of caches. This is a singly
* linked list, so we must do this the hard way.
*/
for (prev = NULL, fcache = g_fcaches;
fcache != priv && fcache != NULL;
fcache = fcache->flink);
ASSERT(fcache == priv);
nxf_removecache(fcache, prev);
nxf_list_unlock();
/* Free all allocated glyph memory */
for (glyph = priv->head; glyph != NULL; glyph = next)
{
next = glyph->flink;
lib_free(glyph);
}
/* Destroy the serializing semaphore... while we are holding it? */
sem_destroy(&priv->fsem);
/* Finally, free the font cache stucture itself */
lib_free(priv);
}
else
{
/* No.. just decrement the number of clients connected to the font
* cache.
*/
priv->fclients--;
nxf_cache_unlock(priv);
}
}
/****************************************************************************
* Name: nxf_cache_getfonthandle
*
* Description:
* Return the handle to the font set used by this instance of the font
* cache.
*
* Input Parameters:
* fhandle - A font cache handle previously returned by nxf_cache_connect();
*
* Returned value:
* Zero (OK) is returned if the metrics were
*
* Returned Value:
* One success, a non-NULL font handle is returned.
*
****************************************************************************/
NXHANDLE nxf_cache_getfonthandle(FCACHE fhandle)
{
FAR struct nxfonts_fcache_s *priv = (FAR struct nxfonts_fcache_s *)fhandle;
DEBUGASSERT(priv != NULL && priv->font != NULL);
return priv->font;
}
/****************************************************************************
* Name: nxf_cache_getglyph
*
* Description:
* Get the font glyph for the character code 'ch' from the font cache. If
* the glyph for that character code does not exist in the font cache, it
* be rendered.
*
* Returned Value:
* On success, a non-NULL pointer to the rendered glyph in the font cache
* is returned. NULL is returned on any failure.
*
****************************************************************************/
FAR const struct nxfonts_glyph_s *nxf_cache_getglyph(FCACHE fhandle, uint8_t ch)
{
FAR struct nxfonts_fcache_s *priv = (FAR struct nxfonts_fcache_s *)fhandle;
FAR struct nxfonts_glyph_s *glyph;
FAR const struct nx_fontbitmap_s *fbm;
ginfo("ch=%c (%02x)\n", (ch >= 32 && ch < 128) ? ch : '.', ch);
/* Get exclusive access to the font cache */
nxf_cache_lock(priv);
/* First, try to find the glyph in the cache of pre-rendered glyphs */
glyph = nxf_findglyph(priv, ch);
if (glyph == NULL)
{
/* No, it is not cached... Does the code map to a font? */
fbm = nxf_getbitmap(priv->font, ch);
if (fbm)
{
/* Yes.. render the glyph for the font */
glyph = nxf_renderglyph(priv, fbm, ch);
}
}
nxf_cache_unlock(priv);
return glyph;
}