└── Ra8876_Lite ├── HDMI_Shield_DTE20190610.pdf ├── README.md ├── assets ├── All_Pic_65K.xls ├── All_Pic_65K.zip ├── Arial72.bin ├── Brad34.bin ├── Brad44.bin ├── Brad60.bin ├── EPS32_SPI.writePixels_uint16_t.png ├── EPS32_SPI.writePixels_uint8_t.png ├── GN_Kin.bin ├── Menu sample.jpg ├── SimHei.bin ├── YEONSUNG.bin ├── bride.jpg ├── bruce1.bin ├── bruce1.gif ├── bruce1.jpg ├── bruce2.bin ├── bruce2.gif ├── bruce2.jpg ├── bruce3.bin ├── bruce3.gif ├── bruce3.jpg ├── burger.jpg ├── dance.jpg ├── fb_ico.jpg ├── finger.jpg ├── fish.bin ├── in_ico.jpg ├── inst_ico.jpg ├── kiss.jpg ├── lee_voc.wav ├── leopard.jpg ├── leopard_o.jpg ├── logo.bin ├── logo.jpg ├── martial.bin ├── martial.jpg ├── menuL.bin ├── menuL.jpg ├── menuP.bin ├── menuP.jpg ├── pharmacy.jpg ├── pharmacy_rccw90.jpg ├── puppy.jpg ├── rains.jpg ├── sound.bin ├── tiger.jpg ├── twi_ico.jpg ├── wifi.jpg ├── wind.jpg └── wp23.bin ├── examples ├── Ra8876_allegro_bruce_xflash │ └── Ra8876_allegro_bruce_xflash.ino ├── Ra8876_allegro_sprite │ └── Ra8876_allegro_sprite.ino ├── Ra8876_primitive_test │ ├── ESP8266_prog_reset_keys.jpg │ ├── ESP8266_use_P12_jumpers.jpg │ ├── New_ESP8266_comm_port.jpg │ ├── Ra8876_primitive_test.ino │ ├── SPI_dipSw_setting.jpg │ └── Tools_ESP8266_Config.jpg ├── Ra8876_slideshow │ └── Ra8876_slideshow.ino ├── Ra8876_ticketdisplay_part1 │ ├── Ra8876_ticketdisplay_part1.ino │ ├── Ticket Display System with Arduino-PartI.pdf │ └── assets │ │ ├── All_76_Pic_65K.bin │ │ ├── All_76_Pic_65K.h │ │ ├── All_76_Pic_65K.xls │ │ ├── background_1.bmp │ │ ├── background_2.bmp │ │ ├── char0020.bmp │ │ ├── char0020_mask.bmp │ │ ├── char0030.bmp │ │ ├── char0030_mask.bmp │ │ ├── char0031.bmp │ │ ├── char0031_mask.bmp │ │ ├── char0032.bmp │ │ ├── char0032_mask.bmp │ │ ├── char0033.bmp │ │ ├── char0033_mask.bmp │ │ ├── char0034.bmp │ │ ├── char0034_mask.bmp │ │ ├── char0035.bmp │ │ ├── char0035_mask.bmp │ │ ├── char0036.bmp │ │ ├── char0036_mask.bmp │ │ ├── char0037.bmp │ │ ├── char0037_mask.bmp │ │ ├── char0038.bmp │ │ ├── char0038_mask.bmp │ │ ├── char0039.bmp │ │ └── char0039_mask.bmp └── RestaurantMenu │ ├── RestaurantMenu.ino │ ├── hello_world.aia │ ├── hello_world.apk │ └── readme.txt ├── library.properties └── src ├── Allegro ├── Bitmap.cpp ├── Bitmap.h ├── Blit.cpp ├── Blit.h ├── Sprite.cpp ├── Sprite.h ├── allegro.cpp └── allegro.h ├── Color ├── Color.cpp ├── Color.h └── Config.h ├── HDMI ├── Ch703x.cpp ├── Ch703x.h ├── LcdParam.h └── videoInOutMap.h ├── Ra8876_Lite.cpp ├── Ra8876_Lite.h ├── Ra8876_Registers.h ├── UserConfig.h ├── __Previews ├── Ra8876_Lite.cppPreview └── Ra8876_Registers.hPreview ├── bfc ├── Arial_Rounded_MT_Bold111hAA4.c ├── French_Script_MT55hAA4.c ├── Lucida_Sans_Unicode16h_rowrowBig.c ├── __Previews │ └── bfcFontMgr.cPreview ├── bfcFontMgr.c ├── bfcFontMgr.h └── bfcfont.h ├── edid ├── edid.c └── edid.h ├── hw_font └── hw_font.h ├── memory ├── memory.cpp └── memory.h └── util └── printf.h /Ra8876_Lite/HDMI_Shield_DTE20190610.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/HDMI_Shield_DTE20190610.pdf -------------------------------------------------------------------------------- /Ra8876_Lite/README.md: -------------------------------------------------------------------------------- 1 | # **HDMI Shield** # 2 | ![](http://www.techtoys.com.hk/BoardsKits/HDMIshield/images/HDMIShield_v2_pin_diagram.png) 3 | is an Arduino compatible development board to bridge the gap between small MCUs and High Definition Television (HDTV). 4 | HDTVs or Full HD monitors with HDMI/DVI interface require a pixel clock of 148MHz for 1080p resolution. 5 | Without an Application Specific IC (ASIC) this pixel clock is out of reach from small MCUs. 6 | 7 | HDMI shield solves this problem in two steps: 8 | 9 | *(1)* A TFT controller RA8876 is used to generate RGB video in 8:8:8 format. 10 | This controller supports various AP interfaces including 4-wire SPI, 8080 16/8-bit, and I2C. Multiple display buffers in SDRAM together with 2D BitBlit engine are used to avoid direct pixel rendering. For example instead of writing individual pixels for the whole screen of 1280*720 in 16 bit-per-pixel, we only need to write simple commands (through SPI, say) to define the foreground color, window size, then finally enable a certain bit for the solid-fill register. The job of pixel rendering will be handled by hardware in a flicker-free manner. If we need to display full color pictures, there is a free image conversion tool to export binary files from jpeg/bmp/png images. The binary files can be copied to a microSD card or preloaded to Serial Flash onboard. With 256Mbit SDRAM, we can allocate 1280x720x2bytes (say) as the main window (visible region) and make the rest as frame buffer. This is equivalent to more than 16 pages for graphic assets storage. Binary data stored in microSD will be copied to frame buffer in booting phase and the data can be moved from frame buffer to the main window by 2D BitBlit, again in a flicker-free operation.There are more features like DMA transfer from Serial Flash to SDRAM, font rendering from embedded characters and Genitop font chip, picture-in-picture, and hardware accelerated shape-draw are all available for small MCUs now. 11 | 12 | *(2)* HDMI encoder CH7035B is used to convert RGB video to differential signals (TMDS) required by HDMI specification. This encoder has an internal frame buffer to boost 8:8:8 RGB to Full HD 1080p (1920*1080) at 60Hz max. In this repository there are several common video formats (e.g. 640x480, 800x480, 720x576, 1280x720 etc) generated by RA8876; that RGB video will be converted to VESA/CEA-861 compatible HDTV standard. Header file `videoInOutMap.h` is found under `/src/HDMI` folder. Parameters specified in this header are used to initialize CH7035B via I2C interface for different HDMI/DVI output resolutions if you are not interested to use the Boot ROM CH9904 for 1080p output. 13 | 14 | *Remarks: Although it is possible to boost a 480x272 RGB video to 1920x1080 HDMI in theory, actual experiments showed blurry screens.
Those "in-n-out" parameters in `videoInOutMap.h` generate good looking result by an one-step boost.* 15 | 16 | # How is the performance? # 17 | Take a look at this YouTube video
18 | [![](http://www.techtoys.com.hk/BoardsKits/HDMIshield/images/YouTube_link_beta.png)](https://youtu.be/MUeIY_gLn3c) 19 | 20 | 21 | # Source code includes : # 22 | 23 | RA8876 & CH7035B drivers in C++. Arduino compatible library and examples are available. 24 | 25 | Complete schematic is now available in pdf. 26 | 27 | Up to time of writing the following platforms have been tested: 28 | 29 | # New example : Ticket Display System # 30 | With full source code (Ra8876_ticketdisplay_part1.ino) and pdf doc in example folder. 31 | ![](http://www.techtoys.com.hk/BoardsKits/HDMIshield/images/broccoli_589.jpg) 32 | 33 | ---------- 34 | 1. ESP8266 on an Arduino form factor PCB (Due Zipper Board DTE20171024). With HDMI Shield stacking on this board you will be able to run all examples in this repository.
![](http://www.techtoys.com.hk/BoardsKits/HDMIshield/images/DueZipperBoard_DTE20171024_400x300.png) 35 | 2. ESP32-PICO-KIT wired up by jumper cables. It is messy, I know! But there are two SPI ports with ESP32, HSPI and VSPI.
Successfully using HSPI for microSD, and VSPI for RA8876 for a significant performance boost in reading data from SD.
Don't forget ESP32 is a WiFi and Bluetooth SoC. It is possible to develop applications for IoT with real-time data displayed on a HDTV.
![](http://www.techtoys.com.hk/BoardsKits/HDMIshield/images/ESP32-PICO-KIT-wiredUP.png) 36 | 3. Arduino DUE with the same Due Zipper Board DTE20171024 by shorting 2.00mm jumpers on P13. 37 | 4. Teensy 3.2 and 3.5 with a simple stacker PCB (Teensy Stacker DTE20171030). 38 | Teensy is providing the best Audio library for Arduino platform in my opinion. 39 | WAV file playback is used in the example `Ra8876_allegro_bruce_xflash.ino` for a very famous Bruce Lee movie 40 | sound track as the background music while three gif animations are played. You will need a HDTV or 41 | FHD monitor with HDMI interface to hear this.
![](http://www.techtoys.com.hk/BoardsKits/HDMIshield/images/TeensyStacker_400x300.png) 42 | 5. Arduino M0. This is the only M0 board with me! Single USB port for program upload and Serial Monitor onboard. 43 | As a result, some changes are required to use this board if you want to debug from Serial Monitor. 44 | Need to replace `Serial` with `SerialUSB` in `*.ino` file and `printf.h` in `/src/util` folder. 45 | If you have a M0 PRO board with dual USB ports no change is required. No extra hardware is required for Arduino M0. Direct stack HDMI Shield to Arduino M0/M0 PRO is OK. 46 | 6. Arduino Genuino 101. Direct stack HDMI Shield to 101 board is OK.
47 | Partially work for this platform. Allegro library is not working for some unknown reason. 48 | Known bug with `printf` for this platform too. Leading to problems with examples 49 | `Ra8876_allegro_bruce_xflash.ino`, `Ra8876_allegro_sprite.ino`, and some debug features for 50 | `Ra8876_primitive_test.ino` via Serial Monitor. 51 | 7. RA8876/77 AP Board with AP firmware preloaded with MCU STM32F103VET6 onboard.
Firmware compatible with RAiO's official AP software has been preloaded. You can find out the display quality with direct control on RA8876 and get images from your PC displayed on HDTV of HDMI-1080p.
52 | ![](http://www.techtoys.com.hk/BoardsKits/HDMIshield/images/HDMIShield_STM32F103VET6_400x300.png)
53 | **Important:** HDMI Shield is a 3.3V system. Don't use a 5V Arduino otherwise it will be damaged. 54 | 55 | 56 | # Folder structure : # 57 |
58 | \Ra8876_Lite
59 | 	\assets
60 | 	\examples
61 | 		\Ra8876_allegro_bruce_xflash
62 | 		\Ra8876_allegro_sprite
63 | 		\Ra8876_primitive_test
64 | 		\Ra8876_slideshow
65 | 		\RestaurantMenu
66 | 		\Ra8876_ticketdisplay_part1
67 | 	\src
68 | 	library.properties
69 | 	README.md (this file)
70 | 
71 | 72 | 73 | Start with `Ra8876_primitive_test.ino` Arduino example. I am using version 1.8.1 for development in my lab.
Comprehensive comments have been added in each example.
74 | Copy this library to your library folder at C:\Users\YOUR NAME\Documents\Arduino\libraries. 75 | 76 | Updated 11-08-2019 for new example for Ticket Display System 77 | 78 | Written by John Leung @ TechToys Co. Hong Kong
79 | www.TechToys.com.hk
80 | email: john@techtoys.com.hk
81 | 82 | -------------------------------------------------------------------------------- /Ra8876_Lite/assets/All_Pic_65K.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/All_Pic_65K.xls -------------------------------------------------------------------------------- /Ra8876_Lite/assets/All_Pic_65K.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/All_Pic_65K.zip -------------------------------------------------------------------------------- /Ra8876_Lite/assets/Arial72.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/Arial72.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/Brad34.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/Brad34.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/Brad44.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/Brad44.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/Brad60.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/Brad60.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/EPS32_SPI.writePixels_uint16_t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/EPS32_SPI.writePixels_uint16_t.png -------------------------------------------------------------------------------- /Ra8876_Lite/assets/EPS32_SPI.writePixels_uint8_t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/EPS32_SPI.writePixels_uint8_t.png -------------------------------------------------------------------------------- /Ra8876_Lite/assets/GN_Kin.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/GN_Kin.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/Menu sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/Menu sample.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/SimHei.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/SimHei.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/YEONSUNG.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/YEONSUNG.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bride.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bride.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce1.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce1.gif -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce1.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce2.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce2.gif -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce2.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce3.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce3.gif -------------------------------------------------------------------------------- /Ra8876_Lite/assets/bruce3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/bruce3.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/burger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/burger.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/dance.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/dance.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/fb_ico.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/fb_ico.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/finger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/finger.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/fish.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/fish.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/in_ico.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/in_ico.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/inst_ico.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/inst_ico.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/kiss.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/kiss.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/lee_voc.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/lee_voc.wav -------------------------------------------------------------------------------- /Ra8876_Lite/assets/leopard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/leopard.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/leopard_o.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/leopard_o.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/logo.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/logo.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/logo.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/martial.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/martial.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/martial.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/martial.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/menuL.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/menuL.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/menuL.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/menuL.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/menuP.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/menuP.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/menuP.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/menuP.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/pharmacy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/pharmacy.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/pharmacy_rccw90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/pharmacy_rccw90.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/puppy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/puppy.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/rains.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/rains.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/sound.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/sound.bin -------------------------------------------------------------------------------- /Ra8876_Lite/assets/tiger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/tiger.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/twi_ico.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/twi_ico.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/wifi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/wifi.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/wind.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/wind.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/assets/wp23.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/assets/wp23.bin -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_allegro_bruce_xflash/Ra8876_allegro_bruce_xflash.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief This example plays three GIF animations on a leopard background. Some preparation is required with GIF animations converted to sprite sheets in bmp/jpg format. 3 | * The bmp/jpg files are converted to binary files with a free conversion tool provided by RAiO. 4 | * Afterwards the binary files can be preloaded to W25Q256xxx Winbond Serial Flash for DMA transfer. 5 | * Binary files being played are bruce1.bin, bruce2.bin, bruce3.bin, and leopard.bin. 6 | * It also possible to use microSD card to store the binary files and playback from there. 7 | * The switch to control program flow is LOAD_BITMAP_XFLASH. Comment this line to use microSD or uncomment to use Serial Flash. 8 | * 9 | * If Teensy is used we can leverage the resourceful Teensy Audio Library for background music. 10 | * A WAV file (lee_voc.WAV) is played from SDCard for Teensy. Digital video and music are carried by a HDMI cable to your HDTV. 11 | * 12 | * Various Arduino boards have beed tested at time of writing including ESP3266, ESP32, Teensy 3.2/3.5, and Arduino DUE. 13 | * 14 | * Programmer: John Leung @ TechToys www.TechToys.com.hk 15 | * 16 | * @file Ra8876_allegro_bruce_xflash.ino 17 | * @History 9th Dec 2017 first release 18 | */ 19 | 20 | //comment this line to play from a microSD card. Don't forget to copy bruce1.bin, bruce2.bin, bruce3.bin, leopard.bin and lee_voc.WAV to the SDcard. 21 | #define LOAD_BITMAP_XFLASH 22 | 23 | #include "Ra8876_Lite.h" 24 | #include "HDMI/Ch703x.h" 25 | #include "Allegro/allegro.h" 26 | #include 27 | 28 | #if defined (TEENSYDUINO) 29 | #include "Audio.h" 30 | AudioPlaySdWav playSdWav1; 31 | AudioOutputI2S i2s1; 32 | AudioConnection patchCord1(playSdWav1, 0, i2s1, 0); 33 | AudioConnection patchCord2(playSdWav1, 1, i2s1, 1); 34 | #endif 35 | 36 | /** 37 | RA8876 GFX controller class constructor 38 | */ 39 | Ra8876_Lite ra8876lite(RA8876_XNSCS, RA8876_XNRESET, RA8876_MOSI, RA8876_MISO, RA8876_SCK); 40 | Color color; 41 | 42 | ///@note A structure to describe images converted by RAiO Image Tool. 43 | typedef struct xImages{ 44 | const String imgName; 45 | uint16_t imgWidth; 46 | uint16_t imgHeight; 47 | uint32_t imgSize; 48 | uint32_t imgAddress; //starting address with data from RAiO Image Tool 49 | }xImages; 50 | 51 | ///@note Source of images and their assocated binary file located in ..\images. 52 | ///All images restricted dimension to 8192 for w/h, and the width should be a multiple of 4 53 | const xImages gfx_assets[]= 54 | { 55 | {"bruce1", 1464, 1096, 3209088, 0}, 56 | {"bruce2", 4800, 820, 7872000, 3209088}, 57 | {"bruce3", 3968, 426, 3380736, 11081088}, 58 | {"leopard", 1280, 720, 1843200, 14461824}, 59 | {"martial", 1280, 720, 1843200, 16305024}, 60 | {"bride", 850, 1280, 2170880, 18148224}, 61 | {"burger", 640, 472, 604160, 20319104}, 62 | {"dance", 1280, 709, 1815040, 20923264}, 63 | {"wind", 1280, 960, 2457600, 22738304}, 64 | {"tiger", 1280, 720, 1843200, 25195904}, 65 | {"fb_ico", 256, 256, 131072, 27039104}, 66 | {"in_ico", 256, 256, 131072, 27170176}, 67 | {"inst_ico",256, 256, 131072, 27301248}, 68 | {"pharmacy",640, 426, 545280, 27432320}, 69 | {"pharmacy_rccw90", 424, 640, 542720, 27977600}, 70 | {"wifi", 256, 223, 114176, 28520320}, 71 | {"finger", 848, 480, 814080, 28634496}, 72 | {"rains", 1280, 853, 2183680, 29448576} 73 | }; 74 | 75 | /** 76 | @brief isr for Vsync 77 | */ 78 | void isr(void) 79 | { 80 | ra8876lite.irqEventHandler(); //not used here, just for reference 81 | } 82 | 83 | //Background BITMAP 84 | BITMAP *bg; 85 | //short animated gif converted to sprite sheets 86 | BITMAP *bruce1,*bruce2,*bruce3; 87 | SPRITE *sprite_bruce1, *sprite_bruce2, *sprite_bruce3; 88 | uint16_t frame=0; 89 | const char quote[] = {"There are only plateaus, and you must not stay there, you must go beyond them : by Bruce Lee."}; 90 | long time_s=0, time_e=0; 91 | bool play_bruce2 = false, play_bruce3 = false; 92 | 93 | void setup() { 94 | // put your setup code here, to run once: 95 | Serial.begin(115200); 96 | pinMode(RA8876_XNINTR, INPUT_PULLUP); 97 | attachInterrupt(digitalPinToInterrupt(RA8876_XNINTR), isr, FALLING); //Vsync pin, not used here (for reference only) 98 | 99 | set_color_depth(16); //color set to 16bit-per-pixel 100 | set_gfx_mode(GFX_HD720p_HD1080p_HDMI, 1280, 720); //set gfx mode with ra8876 generates 720p, scale up to 1080p HDMI 101 | //canvas area set to 1280*720 102 | allegro_init(); 103 | 104 | #if defined (TEENSYDUINO) 105 | HDMI_Tx.setI2SAudio(0, 0, 1); //enable audio for Teensy 3.2/3.5 106 | AudioMemory(8); 107 | #else 108 | HDMI_Tx.setI2SAudio(0, 0, 0); //disable audio for other platforms 109 | #endif 110 | 111 | printf("Init SD card."); 112 | uint8_t iteration = 0; 113 | #ifdef ESP32 114 | SPIClass _HSPI; 115 | _HSPI.begin(SDCARD_SCK_PIN, SDCARD_MISO_PIN, SDCARD_MOSI_PIN, SDCARD_CS_PIN); //pins defined in UserConfig.h 116 | while (!SD.begin(15, _HSPI, 50000000UL, "/sd")) //Can be 50MHz for ESP32 HSPI interface! Good! 117 | #else 118 | while (!(SD.begin(SDCARD_CS_PIN))) 119 | #endif 120 | { 121 | delay(500); 122 | if(iteration++ == 3) 123 | break; 124 | else 125 | printf("."); 126 | } 127 | printf("\n"); 128 | if (iteration > 3) 129 | { 130 | printf("SD card init failed. Have you forgot to insert a sdcard?\n"); 131 | } 132 | else 133 | { 134 | printf("SD card OK!\n"); 135 | } 136 | 137 | //create background, can be some image as the background too 138 | #ifdef LOAD_BITMAP_XFLASH 139 | bg = load_binary_xflash(gfx_assets[3].imgWidth, gfx_assets[3].imgHeight, gfx_assets[3].imgAddress); 140 | #else 141 | bg = load_binary_sd(1280,720, "leopard.bin"); 142 | #endif 143 | blit(bg, screen, 0,0,0,0,1280,720); 144 | 145 | //print text on background from RA8876's embedded character set 146 | ra8876lite.setHwTextCursor(100, 640); 147 | ra8876lite.setHwTextColor(color.Green); 148 | ra8876lite.setHwTextParam(color.Black, 1, 1); 149 | 150 | const char *ch = quote; 151 | while(*ch!='\0') 152 | { 153 | ra8876lite.putHwChar(&ICGROM_16, *ch++); //use internal font to print this quote 154 | delay(50); 155 | } 156 | #ifdef LOAD_BITMAP_XFLASH 157 | bruce1 = load_binary_xflash(gfx_assets[0].imgWidth, gfx_assets[0].imgHeight, gfx_assets[0].imgAddress); 158 | #else 159 | bruce1 = load_binary_sd(1464,1096, "bruce1.bin"); //12 frames 160 | #endif 161 | ra8876lite.putHwString(&ICGROM_16,"."); 162 | 163 | #ifdef LOAD_BITMAP_XFLASH 164 | bruce2 = load_binary_xflash(gfx_assets[1].imgWidth, gfx_assets[1].imgHeight, gfx_assets[1].imgAddress); 165 | #else 166 | bruce2 = load_binary_sd(4800,820,"bruce2.bin"); //40 frames 167 | #endif 168 | ra8876lite.putHwString(&ICGROM_16,"."); 169 | 170 | #ifdef LOAD_BITMAP_XFLASH 171 | bruce3 = load_binary_xflash(gfx_assets[2].imgWidth, gfx_assets[2].imgHeight, gfx_assets[2].imgAddress); 172 | #else 173 | bruce3 = load_binary_sd(3968,426,"bruce3.bin"); //16 frames 174 | #endif 175 | 176 | ra8876lite.putHwString(&ICGROM_16,"."); 177 | 178 | sprite_bruce1 = create_sprite(bruce1, 488, 274); 179 | sprite_bruce2 = create_sprite(bruce2, 480, 205); 180 | sprite_bruce3 = create_sprite(bruce3, 496, 213); 181 | 182 | time_s=time_e=millis(); 183 | } 184 | 185 | void loop() { 186 | if((time_e-time_s) > 3000) 187 | { 188 | play_bruce2 = true; 189 | if((time_e-time_s) > 6000) 190 | play_bruce3 = true; 191 | } 192 | //time it takes to update three sprites + background is around 100msec, i.e. the max frame rate is 10fps 193 | set_sprite_frame(sprite_bruce1, frame%12); 194 | draw_sprite(bg, sprite_bruce1,700,250); 195 | if(play_bruce2) 196 | { 197 | set_sprite_frame(sprite_bruce2, frame%40); 198 | draw_sprite(bg, sprite_bruce2,80,420); 199 | } 200 | if(play_bruce3) 201 | { 202 | set_sprite_frame(sprite_bruce3, frame%16); 203 | draw_sprite(bg, sprite_bruce3,100,80); 204 | } 205 | blit(bg, screen, 0,0,0,0,1280,720); 206 | 207 | if(play_bruce3) 208 | erase_sprite(bg, sprite_bruce3); 209 | 210 | frame++; 211 | time_e=millis(); 212 | //background music available for Teensy 3.2/3.5 213 | #if defined (TEENSYDUINO) 214 | if (playSdWav1.isPlaying() == false) { 215 | Serial.println("Start playing"); 216 | playSdWav1.play("lee_voc.WAV"); 217 | //delay(10); // wait for library to parse WAV & i2s enable to work 218 | } 219 | #endif 220 | } -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_allegro_sprite/Ra8876_allegro_sprite.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief This program demonnstrates how Allegro library is used to display an animation with three layers. Transparency is shown too. 3 | * Various Arduino boards have beed tested at time of writing including ESP3266, ESP32, Teensy 3.2/3.5, and Arduino DUE. 4 | * Initialization of RA8876 and CH7035 encapsulated in two functions: 5 | * //color set to 16 bit-per-pixel 6 | * set_color_depth(16); 7 | * //set gfx mode with ra8876 generates 720p, scale up to 1080p DVI canvas area set to 1280*720. 8 | * set_gfx_mode(GFX_HD720p_HD1080p_DVI, 1280, 720); 9 | * Global BITMAP* screen required by Allegro created in the function allegro_init(). 10 | * Screen cleared in red color by clear_to_color(screen, 255<<24). 11 | * Next SD Card is initialized. The same SPI bus with different CS lines is used for all systems except ESP32. 12 | * There are HSPI and VSPI available from ESP32. It is more efficient to use dual SPI ports to move data from SD card 13 | * to frame buffer. Directive #ifdef ESP32...#else...#endif is available to customerize ESP32 for this. 14 | * 15 | * User need to copy three files fish.bin, sound.bin, and wp23.bin from the \asset folder to a microSD card for this program to work. 16 | * After SDcard initialization the binary files will be copied from SD to SDRAM allocated in off-screen area. 17 | * Then you will see a loud speaker icon, fished moving across a graphical background with transparency supported, 3 layers. 18 | * 19 | * Programmer: John Leung @ TechToys www.TechToys.com.hk 20 | * 21 | * @file Ra8876_allegro_sprite.ino 22 | * @History 13-03-2018 first release 23 | */ 24 | 25 | #include "Ra8876_Lite.h" 26 | #include "HDMI/Ch703x.h" 27 | #include "Allegro/allegro.h" 28 | #include 29 | 30 | /** 31 | RA8876 GFX controller class constructor 32 | */ 33 | Ra8876_Lite ra8876lite(RA8876_XNSCS, RA8876_XNRESET, RA8876_MOSI, RA8876_MISO, RA8876_SCK); 34 | Color color; 35 | BITMAP *fish; 36 | BITMAP *sound; 37 | BITMAP *flower_bg; 38 | 39 | /** 40 | @brief isr for Vsync, no need here 41 | */ 42 | /* 43 | void isr(void) 44 | { 45 | ra8876lite.irqEventHandler(); 46 | } 47 | */ 48 | 49 | void setup() { 50 | // put your setup code here, to run once: 51 | Serial.begin(115200); 52 | //pinMode(RA8876_XNINTR, INPUT_PULLUP); //no need here 53 | //attachInterrupt(digitalPinToInterrupt(RA8876_XNINTR), isr, FALLING); //no need here 54 | set_color_depth(16); //color set to 16bit-per-pixel 55 | set_gfx_mode(GFX_HD720p_HD1080p_DVI, 1280, 720); //set gfx mode with ra8876 generates 720p, scale up to 1080p DVI 56 | //canvas area set to 1280*720 57 | allegro_init(); 58 | clear_to_color(screen, 255<<24); //clear screen to red color on startup 59 | 60 | printf("Init SD card."); 61 | uint8_t iteration = 0; 62 | #ifdef ESP32 63 | SPIClass _HSPI; 64 | _HSPI.begin(SDCARD_SCK_PIN, SDCARD_MISO_PIN, SDCARD_MOSI_PIN, SDCARD_CS_PIN); //pins defined in UserConfig.h 65 | while (!SD.begin(15, _HSPI, 50000000UL, "/sd")) //Can be 50MHz for ESP32 HSPI interface! Good! 66 | #else 67 | while (!(SD.begin(SDCARD_CS_PIN))) 68 | #endif 69 | { 70 | delay(500); 71 | if(iteration++ == 3) 72 | break; 73 | else 74 | printf("."); 75 | } 76 | printf("\n"); 77 | if (iteration > 3) 78 | { printf("SD card init failed. Have you forgot to insert a sdcard? Program not working with .bin file not present.\n"); 79 | while(1);//infinite loop here 80 | } 81 | else 82 | { 83 | printf("SD card OK! Now we load binary file from SD Card to SDRAM for buffering.\n"); 84 | #ifdef ESP32 85 | fish = load_binary_sd(480,300, "/fish.bin"); 86 | sound = load_binary_sd(128,128, "/sound.bin"); 87 | flower_bg = load_binary_sd(800,480, "/wp23.bin"); 88 | //also possible to load from Serial Flash like this if the binary file preloaded 89 | //BITMAP *flower_bg = load_binary_xflash(1280,720,30780208); 90 | #else 91 | fish = load_binary_sd(480,300, "fish.bin"); 92 | sound = load_binary_sd(128,128, "sound.bin"); 93 | flower_bg = load_binary_sd(800,480, "wp23.bin"); 94 | #endif 95 | } 96 | } 97 | 98 | void loop() { 99 | blit(flower_bg, screen,0,0,0,0,848,480); 100 | SPRITE *sprite_fish = create_sprite(fish, 240, 300); 101 | SPRITE *sprite_sound = create_sprite(sound, 128, 128); 102 | 103 | for(;;){ 104 | uint16_t x; 105 | // put your main code here, to run repeatedly: 106 | for(x=0; x<500; x++){ 107 | draw_trans_sprite(flower_bg, sprite_sound, 0, x, 20); 108 | draw_trans_sprite(flower_bg, sprite_fish, x, 100, 25); 109 | blit(flower_bg, screen,0,0,0,0,848,480); 110 | #ifdef ESP8266 111 | yield(); //this is to avoid wdt reset in ESP8266 112 | #endif 113 | erase_sprite(flower_bg, sprite_fish); //draw in the order 1,2,3, erase in 3,2,1 and so on. 114 | erase_sprite(flower_bg, sprite_sound); 115 | } 116 | for(x=500; x>0; x--){ 117 | draw_trans_sprite(flower_bg, sprite_sound, 0, x, 8); 118 | draw_trans_sprite(flower_bg, sprite_fish, x, 100, 20); 119 | blit(flower_bg, screen,0,0,0,0,848,480); 120 | #ifdef ESP8266 121 | yield(); //this is to avoid wdt reset in ESP8266 122 | #endif 123 | erase_sprite(flower_bg, sprite_fish); 124 | erase_sprite(flower_bg, sprite_sound); 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_primitive_test/ESP8266_prog_reset_keys.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_primitive_test/ESP8266_prog_reset_keys.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_primitive_test/ESP8266_use_P12_jumpers.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_primitive_test/ESP8266_use_P12_jumpers.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_primitive_test/New_ESP8266_comm_port.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_primitive_test/New_ESP8266_comm_port.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_primitive_test/SPI_dipSw_setting.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_primitive_test/SPI_dipSw_setting.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_primitive_test/Tools_ESP8266_Config.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_primitive_test/Tools_ESP8266_Config.jpg -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_slideshow/Ra8876_slideshow.ino: -------------------------------------------------------------------------------- 1 | /** 2 | @brief A slide show demo with screen transition in and out, plus font display in multi-languages with bitmap fonts created
3 | by a commercial font package (BitFontCreator). 4 | 5 | @file Ra8876_slideshow.ino 6 | @author John Leung @ TechToys (www.TechToys.com.hk) 7 | @section HISTORY 8 | Date 11th Dec 2017 first release 9 | */ 10 | 11 | #include "Ra8876_Lite.h" 12 | #include "HDMI/Ch703x.h" 13 | #include 14 | 15 | #if defined (TEENSYDUINO) 16 | #include "Audio.h" 17 | AudioPlaySdWav playSdWav1; 18 | AudioOutputI2S i2s1; 19 | AudioConnection patchCord1(playSdWav1, 0, i2s1, 0); 20 | AudioConnection patchCord2(playSdWav1, 1, i2s1, 1); 21 | #endif 22 | 23 | /** 24 | * RA8876 GFX controller class constructor 25 | */ 26 | Ra8876_Lite ra8876lite(RA8876_XNSCS, RA8876_XNRESET, RA8876_MOSI, RA8876_MISO, RA8876_SCK); 27 | Color color; 28 | 29 | /** 30 | * @note Local functions 31 | */ 32 | String messageParser(void) ; 33 | void dmaPutImages(void); 34 | //frame buffer related functions prefix with FB_ 35 | void FB_refresh(void); //update visible area with frame buffer 36 | void FB_fadeIn(uint16_t msec); //fade in what ever in frame buffer 37 | void FB_fadeOut(uint16_t msec); //fade out main window for black screen 38 | void FB_clear(Color color); //clear frame buffer with a pure color 39 | void FB_fill(const String image); //fill frame buffer with an image of type xImages below 40 | const uint16_t FB_StartX = 0; //Canvas size initialized to 1280*720 in setup() below 41 | const uint16_t FB_StartY = 720; //All drawing performed in frame buffer starting from y=720 (off-screen area) 42 | 43 | ///@note A structure to describe images converted by RAiO Image Tool. 44 | typedef struct xImages{ 45 | const String imgName; 46 | uint16_t imgWidth; 47 | uint16_t imgHeight; 48 | uint32_t imgSize; 49 | uint32_t imgAddress; //starting address with data from RAiO Image Tool 50 | }xImages; 51 | 52 | ///@note Source of images and their assocated binary file located in ..\images. 53 | const xImages gfx_assets[]= 54 | { 55 | {"bruce1", 1464, 1096, 3209088, 0}, 56 | {"bruce2", 4800, 820, 7872000, 3209088}, 57 | {"bruce3", 3968, 426, 3380736, 11081088}, 58 | {"leopard", 1280, 720, 1843200, 14461824}, 59 | {"martial", 1280, 720, 1843200, 16305024}, 60 | {"bride", 850, 1280, 2170880, 18148224}, 61 | {"burger", 640, 472, 604160, 20319104}, 62 | {"dance", 1280, 709, 1815040, 20923264}, 63 | {"wind", 1280, 960, 2457600, 22738304}, 64 | {"tiger", 1280, 720, 1843200, 25195904}, 65 | {"fb_ico", 256, 256, 131072, 27039104}, 66 | {"in_ico", 256, 256, 131072, 27170176}, 67 | {"inst_ico",256, 256, 131072, 27301248}, 68 | {"pharmacy",640, 426, 545280, 27432320}, 69 | {"pharmacy_rccw90", 424, 640, 542720, 27977600}, 70 | {"wifi", 256, 223, 114176, 28520320}, 71 | {"finger", 848, 480, 814080, 28634496}, 72 | {"rains", 1280, 853, 2183680, 29448576} 73 | }; 74 | 75 | ///@note unicode 16 for extended character sets in Japanese, Korean, and Chinese. 76 | /// Further details in folder .\fonts\BFC_projects 77 | ///@note Font: GN_Kin_iro_SansSerif48hAA4 こんにちは in unicode 16 78 | const uint16_t hello_japanese[]={0x3053, 0x3093, 0x306B, 0x3061, 0x306F, '\0'}; 79 | ///@note Font: BM_YEONSUNG77hAA4 여보세요 in unicode 16 80 | const uint16_t hello_korean[] ={0xC5EC, 0xBCF4, 0xC138, 0xC694, '\0'}; 81 | ///@note Font: SimHei 你好 in unicode 16 82 | const uint16_t hello_chinese[] ={0x4F60, 0x597D, '\0'}; 83 | 84 | /** 85 | @brief isr for Vsync 86 | */ 87 | void isr(void) 88 | { 89 | ra8876lite.irqEventHandler(); 90 | } 91 | 92 | void setup() { 93 | Serial.begin(115200); 94 | pinMode(RA8876_XNINTR, INPUT_PULLUP); 95 | attachInterrupt(digitalPinToInterrupt(RA8876_XNINTR), isr, FALLING); //pending for Vsync hardware is not ready yet 96 | 97 | ///@note Initialize RA8876 starts from here 98 | if (!ra8876lite.begin(&CEA_1280x720p_60Hz)) //init RA8876 with a video resolution of 1280*720 @ 60Hz with map defined in .\HDMI\LcdParam.h 99 | { 100 | #ifdef DEBUG_LLD_RA8876 101 | printf("RA8876 or RA8877 Fail\n"); 102 | #endif 103 | } 104 | else 105 | { 106 | ra8876lite.canvasImageBuffer(1280,720); //Canvas set to the same size of 1280*720 in default 16 bit-per-pixel color depth 107 | ra8876lite.displayMainWindow(); //align display window to the same canvas starting point 108 | ra8876lite.canvasClear(color.Black); //set whole screen to simple white on startup 109 | ra8876lite.graphicMode(true); 110 | ra8876lite.displayOn(true); 111 | 112 | HDMI_Tx.begin(); //Init I2C 113 | HDMI_Tx.init(VIDEO_in_1280x720_out_HDMI_1080p_60Hz); //map defined in .\HDMI\videoInOutMap.h 114 | HDMI_Tx.setI2SAudio(0, 0, 0); //disable audio 115 | delay(1000); 116 | } 117 | 118 | printf("Init SD card."); 119 | uint8_t iteration = 0; 120 | #ifdef ESP32 121 | SPIClass _HSPI; 122 | _HSPI.begin(SDCARD_SCK_PIN, SDCARD_MISO_PIN, SDCARD_MOSI_PIN, SDCARD_CS_PIN); //pins defined in UserConfig.h 123 | while (!SD.begin(15, _HSPI, 50000000UL, "/sd")) //Can be 50MHz for ESP32 HSPI interface! Good! 124 | #else 125 | while (!(SD.begin(SDCARD_CS_PIN))) 126 | #endif 127 | { 128 | delay(500); 129 | if(iteration++ == 3) 130 | break; 131 | else 132 | printf("."); 133 | } 134 | printf("\n"); 135 | if (iteration > 3) 136 | { 137 | printf("SD card init failed. Have you forgot to insert a sdcard?\n"); 138 | } 139 | else 140 | { 141 | printf("SD card OK!\n"); 142 | } 143 | 144 | ra8876lite.dmaDataBlockTransfer( 145 | 0,720l*5, 146 | gfx_assets[2].imgWidth,gfx_assets[2].imgHeight, 147 | gfx_assets[2].imgWidth, 148 | gfx_assets[2].imgAddress); 149 | 150 | } 151 | 152 | void loop() { 153 | FB_fill("tiger"); 154 | FB_fadeIn(1000); 155 | FB_fadeOut(500); 156 | FB_fill("burger"); 157 | FB_fadeIn(1000); 158 | FB_fadeOut(500); 159 | FB_fill("finger"); 160 | FB_fadeIn(1000); 161 | //print some text in unicode and numbers 162 | #ifdef ESP32 163 | ra8876lite.blitBfcString(100, 600, "/SimHei.bin", hello_chinese, color.Yellow, color.Black,0); 164 | ra8876lite.blitBfcString(600, 620, "/GN_Kin.bin", hello_japanese, color.Red, color.Black,0); 165 | ra8876lite.blitBfcString(1000, 600, "/YEONSUNG.bin", hello_korean, color.Cyan, color.Black,0); 166 | #else 167 | ra8876lite.blitBfcString(100, 600, "SimHei.bin", hello_chinese, color.Yellow, color.Black,0); 168 | ra8876lite.blitBfcString(600, 620, "GN_Kin.bin", hello_japanese, color.Red, color.Black,0); 169 | ra8876lite.blitBfcString(1000, 600, "YEONSUNG.bin", hello_korean, color.Cyan, color.Black,0); 170 | #endif 171 | int ticket=0; 172 | while(ticket++<10){ 173 | #ifdef ESP32 174 | //Known bug for ESP32 with blitBfcString(... "/Arial72.bin", ...); //seems file too big? Some problem with heap allocation... 175 | /** 176 | * assertion "heap != NULL && "free() target pointer is outside heap areas"" 177 | * failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/./heap_caps.c", line 274, function: heap_caps_free 178 | abort() was called at PC 0x400dd123 on core 1 179 | */ 180 | //ra8876lite.blitBfcString(1050, 480, "/Arial72.bin", String(ticket), color.Yellow, color.Black, 0); 181 | #else 182 | ra8876lite.blitBfcString(1050, 480, "Arial72.bin", String(ticket), color.Yellow, color.Black, 0); 183 | #endif 184 | #ifdef ESP8266 185 | yield(); //this is to avoid wdt reset in ESP8266 186 | #endif 187 | } 188 | delay(1000); 189 | FB_fadeOut(500); 190 | } 191 | /** 192 | * *********************************************************************************************************************************************** 193 | * End of loop() 194 | * *********************************************************************************************************************************************** 195 | */ 196 | 197 | /** 198 | * @brief Interpret incoming message in ASCII string from Serial Monitor. This is a blocking function with an infinite loop. Use with care. 199 | * @return String received with \r or \n removed. 200 | */ 201 | String messageParser(void) 202 | { 203 | String inString=""; 204 | if(Serial.available()) 205 | { 206 | inString = Serial.readStringUntil('\n'); 207 | } 208 | return inString; 209 | } 210 | 211 | /** 212 | * @brief update visible area with frame buffer 213 | */ 214 | void FB_refresh(void) 215 | { 216 | //ra8876lite.vsyncWait(); 217 | ra8876lite.bteMemoryCopyWithROP( 218 | 0, 219 | ra8876lite.getCanvasWidth(), 220 | FB_StartX, FB_StartY, //s0_x, s0_y 221 | 0,0,0,0, 222 | 0, 223 | ra8876lite.getCanvasWidth(), 224 | 0,0, //des_x, des_y 225 | ra8876lite.getCanvasWidth(),ra8876lite.getCanvasHeight(), //copy_width,copy_height 226 | RA8876_BTE_ROP_CODE_12); 227 | } 228 | 229 | /** 230 | * @brief Fade in whatever in frame buffer to the Main Window. 231 | */ 232 | void FB_fadeIn(uint16_t msec) 233 | { 234 | uint16_t transition_time = msec/32; 235 | 236 | for(uint8_t alpha=0; alpha<33; alpha++){ 237 | ra8876lite.vsyncWait(); 238 | ra8876lite.bteMemoryCopyWithOpacity( 239 | 0, 240 | ra8876lite.getCanvasWidth(), 241 | FB_StartX, FB_StartY, //s0_x, s0_y 242 | 0,0,0,0, 243 | 0, 244 | ra8876lite.getCanvasWidth(), 245 | 0,0, //des_x, des_y 246 | ra8876lite.getCanvasWidth(),ra8876lite.getCanvasHeight(), //copy_width,copy_height 247 | 32-alpha); 248 | delay (transition_time); 249 | #ifdef ESP8266 250 | yield(); //this is to avoid wdt reset in ESP8266 251 | #endif 252 | } 253 | } 254 | 255 | void FB_fadeOut(uint16_t msec) 256 | { 257 | uint16_t transition_time = msec/32; 258 | 259 | for(uint8_t alpha=0; alpha<33; alpha++){ 260 | ra8876lite.vsyncWait(); 261 | ra8876lite.bteMemoryCopyWithOpacity( 262 | 0, 263 | ra8876lite.getCanvasWidth(), 264 | FB_StartX, FB_StartY, //s0_x, s0_y 265 | 0,0,0,0, 266 | 0, 267 | ra8876lite.getCanvasWidth(), 268 | 0,0, //des_x, des_y 269 | ra8876lite.getCanvasWidth(),ra8876lite.getCanvasHeight(), //copy_width,copy_height 270 | alpha); 271 | delay (transition_time); 272 | #ifdef ESP8266 273 | yield(); //this is to avoid wdt reset in ESP8266 274 | #endif 275 | } 276 | } 277 | 278 | /** 279 | * @brief clear frame buffer with a pure color 280 | */ 281 | void FB_clear(Color color) 282 | { 283 | ra8876lite.canvasClear(color,FB_StartX,FB_StartY); 284 | } 285 | 286 | /** 287 | * @brief fill frame buffer with an image of type xImages below 288 | */ 289 | void FB_fill(const String image) 290 | { 291 | uint16_t arraySize = sizeof(gfx_assets) / sizeof(xImages); 292 | uint16_t x=0, y=0;; 293 | uint16_t copy_width=0, copy_height=0; 294 | 295 | FB_clear(color.Black); 296 | for(uint8_t i=0; i, 23, etc. 5 | Open Serial Monitor, set baud rate to 115200 with New Line or Carriage return as end char. 6 | From input box type in any 3 digit number e.g. 123. The monitor/TV will show the number you have entered. 7 | If you want to change the background image, please change from setup() a function: 8 | putSerialFlashImage(0, 0, "background_1") -> putSerialFlashImage(0, 0, "background_2"), or vice versa. 9 | 10 | Important: If you are using HDMI Shield version 1 (with 256Mbit Serial Flash), please open UserConfig.h 11 | from library folder, and comment #define BOARD_VERSION_2 for this demo to work. 12 | 13 | @file Ra8876_ticketdisplay_part1.ino 14 | @author John Leung @ TechToys (www.TechToys.com.hk) 15 | @section HISTORY 16 | Date 10th Aug 2019 first release 17 | */ 18 | 19 | #include "Ra8876_Lite.h" 20 | #include "HDMI/Ch703x.h" 21 | 22 | ///@note A structure to describe images converted by RAiO Image Tool. 23 | typedef struct xImages{ 24 | const String imgName; 25 | uint16_t imgWidth; 26 | uint16_t imgHeight; 27 | uint32_t imgAddress; //starting address with data from RAiO Image Tool 28 | }xImages; 29 | 30 | ///@note Source of images and their assocated binary file located in ..\assets. containing digits from '0' to '9' with two background images 31 | const xImages gfx_assets[]= 32 | { 33 | //digits with color background 34 | {"char0020", 108, 216, 0}, 35 | {"char0030", 108, 216, 46656}, 36 | {"char0031", 108, 216, 93312}, 37 | {"char0032", 108, 216, 139968}, 38 | {"char0033", 108, 216, 186624}, 39 | {"char0034", 108, 216, 233280}, 40 | {"char0035", 108, 216, 279936}, 41 | {"char0036", 108, 216, 326592}, 42 | {"char0037", 108, 216, 373248}, 43 | {"char0038", 108, 216, 419904}, 44 | {"char0039", 108, 216, 466560}, 45 | //digits with color mask 46 | {"char0020_mask", 108, 216, 513216}, 47 | {"char0030_mask", 108, 216, 559872}, 48 | {"char0031_mask", 108, 216, 606528}, 49 | {"char0032_mask", 108, 216, 653184}, 50 | {"char0033_mask", 108, 216, 699840}, 51 | {"char0034_mask", 108, 216, 746496}, 52 | {"char0035_mask", 108, 216, 793152}, 53 | {"char0036_mask", 108, 216, 839808}, 54 | {"char0037_mask", 108, 216, 886464}, 55 | {"char0038_mask", 108, 216, 933120}, 56 | {"char0039_mask", 108, 216, 979776}, 57 | //background images 58 | {"background_1", 1280, 720, 1026432}, //pharmacy bg 59 | {"background_2", 1280, 720, 2869632} //broccoli bg 60 | }; 61 | 62 | /** 63 | * RA8876 GFX controller class constructor 64 | */ 65 | Ra8876_Lite ra8876lite(RA8876_XNSCS, RA8876_XNRESET, RA8876_MOSI, RA8876_MISO, RA8876_SCK); 66 | Color color; 67 | int16_t bgIndex; 68 | 69 | /** 70 | * @brief Interpret incoming message in ASCII string from Serial Monitor. This is a blocking function until carriage return is received from Serial Monitor. 71 | * @return The original message with \n included. 72 | */ 73 | String messageParser(void) 74 | { 75 | String inString=""; 76 | 77 | while(!Serial.available()); 78 | inString = Serial.readStringUntil('\n'); 79 | return inString; 80 | } 81 | 82 | /** 83 | * @brief Return the array index of a certain image in Serial Flash 84 | * @return -1 if no such image 85 | * id>=0 if an image exists in Serial Flash 86 | */ 87 | int16_t getSerialFlashImageId(const String& name) 88 | { 89 | int16_t i; 90 | 91 | uint16_t arraySize = sizeof(gfx_assets) / sizeof(xImages); 92 | for(i=0; i=0) of the image in Serial Flash 109 | * -1 if there is no such image in Flash 110 | */ 111 | int16_t putSerialFlashImage(uint16_t x0, uint16_t y0, const String& name) 112 | { 113 | int16_t id = getSerialFlashImageId(name); 114 | if (id > -1) 115 | { 116 | ra8876lite.dmaDataBlockTransfer( 117 | x0,y0, 118 | gfx_assets[id].imgWidth,gfx_assets[id].imgHeight, 119 | gfx_assets[id].imgWidth, 120 | gfx_assets[id].imgAddress); 121 | } 122 | 123 | return id; 124 | } 125 | 126 | /** 127 | * @brief Print digits from a constant character array (null terminated) to HDTV 128 | */ 129 | void putJumboScore(uint16_t x0, uint16_t y0, const char *pStr) 130 | { 131 | uint16_t cursor_x = x0; 132 | int16_t id; 133 | 134 | while(*pStr!='\0') 135 | { 136 | switch(*pStr) 137 | { 138 | case ' ': 139 | id = putSerialFlashImage(cursor_x, y0, "char0020"); 140 | break; 141 | case '0': id = putSerialFlashImage(cursor_x, y0, "char0030"); 142 | break; 143 | case '1': id = putSerialFlashImage(cursor_x, y0, "char0031"); 144 | break; 145 | case '2': id = putSerialFlashImage(cursor_x, y0, "char0032"); 146 | break; 147 | case '3': id = putSerialFlashImage(cursor_x, y0, "char0033"); 148 | break; 149 | case '4': id = putSerialFlashImage(cursor_x, y0, "char0034"); 150 | break; 151 | case '5': id = putSerialFlashImage(cursor_x, y0, "char0035"); 152 | break; 153 | case '6': id = putSerialFlashImage(cursor_x, y0, "char0036"); 154 | break; 155 | case '7': id = putSerialFlashImage(cursor_x, y0, "char0037"); 156 | break; 157 | case '8': id = putSerialFlashImage(cursor_x, y0, "char0038"); 158 | break; 159 | case '9': id = putSerialFlashImage(cursor_x, y0, "char0039"); 160 | break; 161 | } 162 | cursor_x += gfx_assets[id].imgWidth; 163 | pStr++; 164 | } 165 | } 166 | 167 | /** 168 | @brief isr for Vsync, not used in this example 169 | */ 170 | void isr(void) 171 | { 172 | ra8876lite.irqEventHandler(); 173 | } 174 | 175 | void setup() { 176 | Serial.begin(115200); 177 | pinMode(RA8876_XNINTR, INPUT_PULLUP); 178 | attachInterrupt(digitalPinToInterrupt(RA8876_XNINTR), isr, FALLING); //pending for Vsync hardware is not ready yet 179 | 180 | ///@note Initialize RA8876 starts from here 181 | if (!ra8876lite.begin(&CEA_1280x720p_60Hz)) //init RA8876 with a video resolution of 1280*720@60Hz (720p) 182 | { 183 | #ifdef DEBUG_LLD_RA8876 184 | printf("RA8876 or RA8877 Fail\n"); 185 | #endif 186 | } 187 | else 188 | { 189 | ra8876lite.canvasImageBuffer(1280,720); //Canvas set to the same size of 1280*720 in 16 bit-per-pixel color depth 190 | ra8876lite.displayMainWindow(); //align display window to the same canvas starting point 191 | ra8876lite.canvasClear(color.White); //set whole screen to white on startup 192 | ra8876lite.graphicMode(true); 193 | ra8876lite.displayOn(true); 194 | 195 | HDMI_Tx.begin(); //Init I2C 196 | HDMI_Tx.init(VIDEO_in_1280x720_out_DVI_1080p_60Hz); //map defined in .\HDMI\videoInOutMap.h 197 | HDMI_Tx.setI2SAudio(0, 0, 0); //disable audio 198 | delay(1000); 199 | } 200 | 201 | bgIndex = putSerialFlashImage(0, 0, "background_2"); 202 | } 203 | 204 | void loop() { 205 | char char_buffer[4]; 206 | #ifdef ESP8266 207 | yield(); //this is to avoid wdt reset in ESP8266 208 | #endif 209 | String inString = messageParser(); //blocking function here until \n received 210 | sprintf(char_buffer, "%3d", inString.toInt()); //format to 3 digits 211 | char_buffer[3]='\0'; //null terminate 212 | putJumboScore(930,128, char_buffer); //print digits on screen 213 | } 214 | -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/Ticket Display System with Arduino-PartI.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/Ticket Display System with Arduino-PartI.pdf -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/All_76_Pic_65K.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/All_76_Pic_65K.bin -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/All_76_Pic_65K.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | // 3 | // brief: This file provides an easy way to obtain image data information. 4 | // 5 | // 6 | // BINARY_INFO[PICTURE_NAME].number => To obtain sequence number information of the "PICTURE_NAME"(.bmp or .jpg) which is generated in the excel file 7 | // BINARY_INFO[PICTURE_NAME].img_width => To obtain image width information of the "PICTURE_NAME" (.bmp or .jpg) 8 | // BINARY_INFO[PICTURE_NAME].img_height => To obtain image height information of the "PICTURE_NAME" (.bmp or .jpg) 9 | // BINARY_INFO[PICTURE_NAME].img_size => To obtain an image size which is converted and stored in the binary file, please notice, the binary file is combined and converted from the several files (.bmp or .jpg) 10 | // BINARY_INFO[PICTURE_NAME].start_addr => To obtain start address of binary file which is converted from the file "PICTURE_NAME" (.bmp or .jpg) 11 | // 12 | // For example, the struct and enum type as: 13 | // 14 | // const INFO (code) BINARY_INFO[3]= 15 | // { 16 | // /* No. , Width , Height , Size (bytes) , Start Address */ 17 | // {1,1280,800,2048000,0}, /* pic_01_1280x800 , element 0 */ 18 | // {2,320,240,153600,2048000}, /* RAiO , element 1 */ 19 | // {3,128,128,32768,2201600}, /* S1_16 , element 2 */ 20 | // } 21 | // 22 | // 23 | // typedef enum 24 | // { 25 | // pic_01_1280x800=0, /* 0 */ 26 | // RAiO, /* 1 */ 27 | // S1_16, /* 2 */ 28 | // }PICTURE_NAME; 29 | // 30 | // (1). To obtain size informations of the file "pic_01_1280x800" (.bmp or jpg), 31 | // the C code is: 32 | // 33 | // long param1 = 0; 34 | // 35 | // param1 = BINARY_INFO[pic_01_1280x800].img_size; 36 | // /* or */ 37 | // param1 = BINARY_INFO[0].img_size; 38 | // 39 | // /* the param1 is 2048000 (bytes) */ 40 | // 41 | // 42 | // (2). To obtain start address informations of the file "S1_16" (.bmp or jpg), 43 | // the C code is: 44 | // 45 | // long param2 = 0; 46 | // 47 | // param2 = BINARY_INFO[S1_16].start_addr; 48 | // /* or */ 49 | // param2 = BINARY_INFO[2].start_addr; 50 | // 51 | // /* the param2 is 2201600 (bytes) */ 52 | // 53 | /*********************************************************************/ 54 | typedef struct _info 55 | { 56 | unsigned short number; 57 | unsigned short img_width; 58 | unsigned short img_height; 59 | unsigned long img_size; 60 | unsigned long start_addr; 61 | }INFO; 62 | 63 | /* The 'code' is KEIL C 8051 instruction, please refer to http://www.keil.com/support/man/docs/c51/c51_le_code.htm */ 64 | /* If you do not use the 8051 microcontroller system, please remove the 'code' instruction. */ 65 | 66 | const INFO code BINARY_INFO[24]= 67 | { 68 | /* No. , Width , Height , Size , Start Address */ 69 | {1,108,216,46656,0}, /* char0020 , element 0 */ 70 | {2,108,216,46656,46656}, /* char0030 , element 1 */ 71 | {3,108,216,46656,93312}, /* char0031 , element 2 */ 72 | {4,108,216,46656,139968}, /* char0032 , element 3 */ 73 | {5,108,216,46656,186624}, /* char0033 , element 4 */ 74 | {6,108,216,46656,233280}, /* char0034 , element 5 */ 75 | {7,108,216,46656,279936}, /* char0035 , element 6 */ 76 | {8,108,216,46656,326592}, /* char0036 , element 7 */ 77 | {9,108,216,46656,373248}, /* char0037 , element 8 */ 78 | {10,108,216,46656,419904}, /* char0038 , element 9 */ 79 | {11,108,216,46656,466560}, /* char0039 , element 10 */ 80 | {12,108,216,46656,513216}, /* char0020_mask , element 11 */ 81 | {13,108,216,46656,559872}, /* char0030_mask , element 12 */ 82 | {14,108,216,46656,606528}, /* char0031_mask , element 13 */ 83 | {15,108,216,46656,653184}, /* char0032_mask , element 14 */ 84 | {16,108,216,46656,699840}, /* char0033_mask , element 15 */ 85 | {17,108,216,46656,746496}, /* char0034_mask , element 16 */ 86 | {18,108,216,46656,793152}, /* char0035_mask , element 17 */ 87 | {19,108,216,46656,839808}, /* char0036_mask , element 18 */ 88 | {20,108,216,46656,886464}, /* char0037_mask , element 19 */ 89 | {21,108,216,46656,933120}, /* char0038_mask , element 20 */ 90 | {22,108,216,46656,979776}, /* char0039_mask , element 21 */ 91 | {23,1280,720,1843200,1026432}, /* background_1 , element 22 */ 92 | {24,1280,720,1843200,2869632}, /* background_2 , element 23 */ 93 | }; 94 | 95 | typedef enum 96 | { 97 | char0020=0, /* 0 */ 98 | char0030, /* 1 */ 99 | char0031, /* 2 */ 100 | char0032, /* 3 */ 101 | char0033, /* 4 */ 102 | char0034, /* 5 */ 103 | char0035, /* 6 */ 104 | char0036, /* 7 */ 105 | char0037, /* 8 */ 106 | char0038, /* 9 */ 107 | char0039, /* 10 */ 108 | char0020_mask, /* 11 */ 109 | char0030_mask, /* 12 */ 110 | char0031_mask, /* 13 */ 111 | char0032_mask, /* 14 */ 112 | char0033_mask, /* 15 */ 113 | char0034_mask, /* 16 */ 114 | char0035_mask, /* 17 */ 115 | char0036_mask, /* 18 */ 116 | char0037_mask, /* 19 */ 117 | char0038_mask, /* 20 */ 118 | char0039_mask, /* 21 */ 119 | background_1, /* 22 */ 120 | background_2, /* 23 */ 121 | }PICTURE_NAME; 122 | 123 | -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/All_76_Pic_65K.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/All_76_Pic_65K.xls -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/background_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/background_1.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/background_2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/background_2.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0020.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0020.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0020_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0020_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0030.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0030.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0030_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0030_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0031.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0031.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0031_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0031_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0032.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0032.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0032_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0032_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0033.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0033.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0033_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0033_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0034.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0034.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0034_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0034_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0035.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0035.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0035_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0035_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0036.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0036.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0036_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0036_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0037.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0037.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0037_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0037_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0038.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0038.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0038_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0038_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0039.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0039.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0039_mask.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/Ra8876_ticketdisplay_part1/assets/char0039_mask.bmp -------------------------------------------------------------------------------- /Ra8876_Lite/examples/RestaurantMenu/hello_world.aia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/RestaurantMenu/hello_world.aia -------------------------------------------------------------------------------- /Ra8876_Lite/examples/RestaurantMenu/hello_world.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techtoys/HDMI-Shield/80a9d29204d02b473f450c61dbd9f5cb92faf200/Ra8876_Lite/examples/RestaurantMenu/hello_world.apk -------------------------------------------------------------------------------- /Ra8876_Lite/examples/RestaurantMenu/readme.txt: -------------------------------------------------------------------------------- 1 | Android app developed with MIT App Inventor 2. -------------------------------------------------------------------------------- /Ra8876_Lite/library.properties: -------------------------------------------------------------------------------- 1 | name=Ra8876_Lite 2 | version=1.0 3 | author=John Leung 4 | maintainer=John Leung 5 | sentence=RA8876 with CH7035B for HDMI output 6 | paragraph=RA8876 with CH7035B for HDMI output 7 | category=Display 8 | url=http://www.TechToys.com.hk 9 | architectures=* 10 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/Bitmap.cpp: -------------------------------------------------------------------------------- 1 | #include "Bitmap.h" 2 | 3 | static void drawSquare(BITMAP *bmp, int x1, int y1, int x2, int y2, int color, bool fill); 4 | 5 | /** 6 | * @brief Constructor for BITMAP class 7 | * @param width & height represent the dimensions of this BITMAP 8 | * @note Memory is allocated in SDRAM connected to Ra8876 for this BITMAP. 9 | * The memory allocated is not cleared on creation, so it will probably contain garbage: 10 | * you should clear the BITMAP before using it. This routine always use the 11 | * global color depth specified by calling allegro_init() in initialization. 12 | */ 13 | BITMAP:: BITMAP (uint16_t width, uint16_t height) 14 | { 15 | w = width; 16 | h = height; 17 | uint8_t bpp = ra8876lite.getColorDepth(); 18 | //allocate memory from Ra8876's SDRAM 19 | int32_t offset = mmu->mem_malloc((uint32_t)width*height*bpp); 20 | if(offset<0){ 21 | //exception.ex_throw("BITMAP::create_bitmap err -2!"); 22 | printf("BITMAP::create_bitmap err -2!\n"); 23 | } 24 | else 25 | { 26 | thisBitmapAddress = offset; 27 | //printf("#BITMAP physical address %d\n", thisBitmapAddress); 28 | } 29 | 30 | clipping = false; 31 | cl = 0; 32 | cr = width-1;//cr = VIRTUAL_W-1; 33 | ct = 0; 34 | cb = height-1;//cb = VIRTUAL_H-1; 35 | } 36 | 37 | /** 38 | * @brief Destructor for BITMAP class 39 | * @note Memory freed from heap and SDRAM of RA8876 40 | */ 41 | BITMAP::~BITMAP() 42 | { 43 | mmu->mem_free(this->thisBitmapAddress); //free memory from SDRAM 44 | //printf("This BITMAP deleted.\n"); 45 | } 46 | 47 | void BITMAP::setClipState(bool state) 48 | { 49 | if(state==true) 50 | { 51 | clipping = true; 52 | } 53 | else 54 | { 55 | clipping = false; 56 | //reset clipping rectangle to full bitmap area 57 | cl = 0; 58 | cr = w-1;//cr = VIRTUAL_W-1; 59 | ct = 0; 60 | cb = h-1;//cb = VIRTUAL_H-1; 61 | } 62 | } 63 | 64 | /** 65 | * @brief This function sets the clipping rectangle for this bitmap. 66 | * @param x1, y1 indicate the top left corner (values inclusive). 67 | * @param x2, y2 indicate the bottom right corner (values inclusive). 68 | * @note Each bitmap has an associated clipping rectangle, which is the area of the 69 | * image that it is ok to draw onto. Nothing will be drawn to positions outside 70 | * this space. Drawing operations will be performed on the bitmap 71 | * as long as the first coordinates of its clipping rectangle 72 | * are not greater than the second coordinates and its intersection with 73 | * the actual image is non-empty. If either condition is not fulfilled, 74 | * drawing will be turned off for the bitmap, 75 | * e.g. set_clip_rect(bmp, 0, 0, -1, -1); //disable drawing on bmp 76 | */ 77 | void BITMAP::setClipRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) 78 | { 79 | if((x1 >= x2) || (y1 >= y2)) return; 80 | 81 | if((x1 >= w-1) || (y1 >= h-1)) return; 82 | 83 | cl = x1; 84 | if(x2>w-1) x2=w-1; 85 | cr = x2; 86 | ct = y1; 87 | if(y2>h-1) y2=h-1; 88 | cb = y2; 89 | } 90 | 91 | /** 92 | * @brief Return clipping rectangle boundary. 93 | * @param *x1, *y1 are pointers to values holding clipping left and clipping top boundary. 94 | * @param *x2, *y2 are pointers to values holding clipping right and clipping bottom boundary. 95 | * 96 | */ 97 | void BITMAP::getClipRect(uint16_t *x1, uint16_t *y1, uint16_t *x2, uint16_t *y2) 98 | { 99 | *x1 = cl; 100 | *x2 = cr; 101 | *y1 = ct; 102 | *y2 = cb; 103 | } 104 | 105 | /** 106 | * @brief Creates a BITMAP of size width x height. 107 | * @param width, height represent the dimension of this BITMAP 108 | * @return Returns a pointer to the created BITMAP, or NULL if the BITMAP could not be created. 109 | * Remember to free this BITMAP later to avoid memory leaks. 110 | * @note Comply with legacy Allegro 4.4.x 111 | */ 112 | BITMAP* create_bitmap(int width, int height) 113 | { 114 | BITMAP* pBitmap = new BITMAP((uint16_t)width, (uint16_t)height); 115 | 116 | if(pBitmap) 117 | return pBitmap; 118 | else 119 | return NULL; 120 | } 121 | 122 | /** 123 | * @brief Create a BITMAP and then fill it up with a picture from MCU's Flash. 124 | * @param width, height indicate the dimension of the picture embedded in MCU's Flash. 125 | * @param *flash is a void pointer to a static array of 8-bit or 16-bit data in MCU's Flash. 126 | * @return Returns a pointer to the created BITMAP, or NULL if the BITMAP could not be created. 127 | * Remember to free this BITMAP later to avoid memory leaks. 128 | */ 129 | BITMAP* load_flash(int width, int height, const void *flash) 130 | { 131 | BITMAP* pBitmap = new BITMAP((uint16_t)width, (uint16_t)height); 132 | 133 | if(!pBitmap) return NULL; //failed to allocate memory from heap or SDRAM 134 | 135 | uint8_t bpp = ra8876lite.getColorDepth(); 136 | uint32_t lnOffset = pBitmap->getAddress() / (VIRTUAL_W*bpp); 137 | //printf("lnOffset calling load_bitmap_flash() = %d.\n", lnOffset); 138 | size_t byte_count = (size_t) pBitmap->getWidth() * pBitmap->getHeight() * bpp; 139 | //printf("byte_count calling load_bitmap_flash() = %d.\n", byte_count); 140 | ra8876lite.canvasWrite(flash, lnOffset, byte_count); 141 | 142 | return pBitmap; 143 | 144 | } 145 | 146 | /** 147 | * @brief Load a picture in binary format from SD card to SDRAM.
148 | * The binary file is generated by RAiO tool. A BITMAP pointer is returned as the handler.
149 | * @param width, height indicate the dimension of the picture. 150 | * @param *pFilename is a pointer to the filename. 151 | * @return Returns a pointer to the created BITMAP, or NULL if the BITMAP could not be created.
152 | * Remember to free this BITMAP if it is no longer required to avoid memory leaks. 153 | * @note Because there is no width and height information available from the binary file generated 154 | * by RAiO tool so we need to specify them as arguments. 155 | */ 156 | #if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY) 157 | BITMAP* load_binary_sd(int width, int height, const char *pFilename) 158 | { 159 | BITMAP* pBitmap = new BITMAP((uint16_t)width, (uint16_t)height); 160 | 161 | if(!pBitmap) return NULL; //failed to allocate memory from heap or SDRAM 162 | 163 | uint8_t bpp = ra8876lite.getColorDepth(); 164 | uint32_t lnOffset = pBitmap->getAddress() / (VIRTUAL_W*bpp); 165 | 166 | ra8876lite.canvasWrite(width, height, pFilename, lnOffset); 167 | 168 | return pBitmap; 169 | } 170 | #endif 171 | 172 | /** 173 | * @brief Load a picture in binary format from external serial flash to SDRAM.
174 | * The binary file is generated by RAiO tool and preloaded to the external serial flash onboard of ArduoHDMI.
175 | * A BITMAP pointer is returned as the handler.
176 | * @param picture_width is the pixel width of the image. 177 | * @param picture_height is the image height in line. 178 | * @param src_addr is the Serial flash DMA source address. This is obtained from RAiO Image_AP tool. 179 | * @return Returns a pointer to the created BITMAP, or NULL if the BITMAP could not be created.
180 | * Remember to free this BITMAP if it is no longer required to avoid memory leaks. 181 | */ 182 | BITMAP* load_binary_xflash(int picture_width, int picture_height, long src_addr) 183 | { 184 | BITMAP* pBitmap = new BITMAP((uint16_t)picture_width, (uint16_t)picture_height); 185 | if(!pBitmap) return NULL; //failed to allocate memory from heap or SDRAM 186 | 187 | //change to linear mode 188 | ra8876lite.canvasLinearModeSet(); 189 | 190 | ra8876lite.dmaDataLinearTransfer(pBitmap->getAddress(), picture_width, picture_height, src_addr); 191 | //printf("desAddr = %d, w = %d, h = %d, src_addr = %d\n", pBitmap->getAddress(), picture_width, picture_height, src_addr); 192 | //restore to block mode 193 | ra8876lite.canvasBlockModeSet(); 194 | 195 | return pBitmap; 196 | } 197 | 198 | /** 199 | * @brief Destroy a BITMAP from heap and RA8876's SDRAM. 200 | * @param *bitmap is a pointer to the BITMAP to be destroyed. 201 | * @note Comply with legacy Allegro 4.4.x 202 | */ 203 | void destroy_bitmap(BITMAP *bitmap) 204 | { 205 | if(!bitmap) return; 206 | delete bitmap; 207 | } 208 | 209 | /** 210 | * @brief Turns on (if state is non-zero) or off (if state is zero) clipping for the specified bitmap. 211 | * @param *bitmap is a pointer to the BITMAP to set 212 | * @param state = 1 to turn on 213 | * state = 0 to turn off 214 | */ 215 | void set_clip_state(BITMAP *bitmap, int state) 216 | { 217 | bitmap->setClipState((bool)state); 218 | } 219 | 220 | /** 221 | * @brief Returns non-zero if clipping is turned on for the specified bitmap and zero otherwise. 222 | * @return '1' if clipping has been turned on.
223 | * '0' is clipping is off. 224 | */ 225 | int get_clip_state(BITMAP *bitmap) 226 | { 227 | return ((int)bitmap->getClipState()); 228 | } 229 | 230 | /** 231 | * @brief This function is the same as
232 | * BITMAP::setClipRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2). 233 | */ 234 | void set_clip_rect(BITMAP *bitmap, int x1, int y1, int x2, int y2) 235 | { 236 | bitmap->setClipRect((uint16_t)x1,(uint16_t)y1,(uint16_t)x2,(uint16_t)y2); 237 | } 238 | 239 | /* 240 | * @brief This function is the same as
241 | * BITMAP::getClipRect(uint16_t *x1, uint16_t *y1, uint16_t *x2, uint16_t *y2). 242 | * @note Example :
243 | * uint16_t left,right,top,bottom; 244 | * get_clip_rect(screen, &left, &top, &right, &bottom); 245 | */ 246 | void get_clip_rect(BITMAP *bitmap, uint16_t *x1, uint16_t *y1, uint16_t *x2, uint16_t *y2) 247 | { 248 | bitmap->getClipRect(x1,y1,x2,y2); 249 | } 250 | 251 | /** 252 | * @brief Local function to draw and fill a rectangle with solid color or drawing the frame only. 253 | * Use as the calling function for rectfill() & rect() 254 | */ 255 | static void drawSquare(BITMAP *bmp, int x1, int y1, int x2, int y2, int color, bool fill) 256 | { 257 | if(bmp==NULL) return; 258 | if(x1==x2 || y1==y2) return; //a rectangle cannot be of zero width/height 259 | 260 | uint16_t left,right,top,bottom; 261 | uint16_t cl,cr,ct,cb; 262 | bmp->getClipRect(&cl, &ct, &cr, &cb); //get clipping rectangle first 263 | //printf("Clipping rectangle = left %d, right %d, top %d, bottom %d\n", cl, cr, ct, cb); 264 | 265 | if(x2>x1) 266 | { 267 | right = x2; 268 | left = x1; 269 | }else 270 | { 271 | right = x1; 272 | left = x2; 273 | } 274 | 275 | if(y2>y1) 276 | { 277 | top = y1; 278 | bottom = y2; 279 | }else 280 | { 281 | top = y2; 282 | bottom = y1; 283 | } 284 | 285 | left = constrain(left, cl, cr); //values cl, cr are inclusive. 286 | right = constrain(right, cl, cr); 287 | top = constrain(top, ct, cb); 288 | bottom = constrain(bottom, ct, cb); 289 | 290 | //printf("Clipping rectangle is now: left %d, right %d, top %d, bottom %d\n", left, right, top, bottom); 291 | 292 | Color _color(color); 293 | 294 | if(fill) 295 | { 296 | //ra8876lite.bteSolidFill(bmp->getAddress(),left,top,right-left+1,bottom-top+1,_color); 297 | ra8876lite.canvasImageStartAddress(bmp->getAddress()); 298 | ra8876lite.drawSquareFill(left, top, right, bottom, _color); 299 | ra8876lite.canvasImageStartAddress(CANVAS_OFFSET); 300 | } 301 | else 302 | { 303 | ra8876lite.canvasImageStartAddress(bmp->getAddress()); 304 | ra8876lite.drawSquare(left, top, right, bottom, _color); 305 | ra8876lite.canvasImageStartAddress(CANVAS_OFFSET); 306 | } 307 | } 308 | 309 | /** 310 | * @brief Draws a solid, filled rectangle with two points as its opposite corners. 311 | * @param *bmp is a pointer to the BITMAP to draw this rectangle. 312 | * @param x1,y1 are the starting coordinates 313 | * @param x2,y2 are the ending coordinates 314 | * @param color in integer (not sf::Color object) 315 | * @note Example:
316 | * rectfill(screen, 100, 200, 150, 230, 255<<24); 317 | * //draw a rectangle of size 50*30 of red color starting from (100,200) 318 | */ 319 | void rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color) 320 | { 321 | if(bmp==screen) 322 | { 323 | drawSquare(screen, x1, y1, x2, y2, color, true); 324 | } 325 | else 326 | {//pixel-by-pixel draw routine 327 | 328 | } 329 | } 330 | 331 | void rect(BITMAP *bmp, int x1, int y1, int x2, int y2, int color) 332 | { 333 | if(bmp==screen) 334 | { 335 | drawSquare(screen, x1, y1, x2, y2, color, false); 336 | } 337 | else 338 | {//pixel-by-pixel draw routine 339 | 340 | } 341 | } 342 | 343 | /** 344 | * @brief Clears the bitmap to color black. 345 | * @param *bitmap points to the BITMAP to clear. 346 | */ 347 | void clear_bitmap(BITMAP *bitmap) 348 | { 349 | clear_to_color(bitmap, 0); 350 | } 351 | 352 | /** 353 | * @brief Clears the bitmap to the specified color. 354 | * @param *bitmap points to the BITMAP to clear. 355 | * @param color represents the color to fill in integer. 356 | */ 357 | void clear_to_color(BITMAP *bitmap, int color) 358 | { 359 | sf::Color color_to_clear(color); 360 | //data in BITMAP rectangle re-arranged to fit the full virtual width (VIRTUAL_W). 361 | //e.g. BITMAP of size 300x500*bpp converted to 800*188*bpp; 800=VIRTUAL_W, 188 is calculated from the formula (300*500 + 800)/800 362 | uint16_t bte_height = ra8876lite.getColorDepth()*(bitmap->getWidth() * bitmap->getHeight() + VIRTUAL_W)/VIRTUAL_W; 363 | 364 | ra8876lite.bteSolidFill(bitmap->getAddress(),0,0,VIRTUAL_W,bte_height,color_to_clear); 365 | } 366 | 367 | 368 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/Bitmap.h: -------------------------------------------------------------------------------- 1 | #ifndef _BITMAP_H 2 | #define _BITMAP_H 3 | 4 | #include "Ra8876_Lite.h" 5 | #include "memory/memory.h" 6 | #include "Allegro/allegro.h" 7 | 8 | /** 9 | * @brief BITMAP Class declaration 10 | */ 11 | class BITMAP { 12 | public: 13 | BITMAP(uint16_t width, uint16_t height); 14 | ~BITMAP(); 15 | 16 | uint16_t getWidth(){return w;} 17 | uint16_t getHeight(){return h;} 18 | uint32_t getAddress() {return thisBitmapAddress;} 19 | bool getClipState(){return clipping;} 20 | void setClipState(bool state); 21 | void setClipRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); 22 | void getClipRect(uint16_t *x1, uint16_t *y1, uint16_t *x2, uint16_t *y2); 23 | private: 24 | uint16_t w; //width of this BITMAP 25 | uint16_t h; //height of this BITMAP 26 | uint32_t thisBitmapAddress; //address offset allocated in SDRAM of Ra8876 27 | bool clipping; //clipping to be turned on when true 28 | //clip rectangle left, right, top, and bottom (inclusive), 29 | //nothing will be drawn on this BITMAP outside the clip rectangle 30 | uint16_t cl,cr,ct,cb; 31 | }; 32 | extern BITMAP *screen; //global BITMAP of dimension CANVAS_WIDTH & CANVAS_HEIGHT for the visible screen 33 | 34 | 35 | /* Starts C function definitions when using C++ */ 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | BITMAP* create_bitmap(int width, int height); 41 | BITMAP* load_flash(int width, int height, const void *flash); 42 | #if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY) 43 | BITMAP* load_binary_sd(int width, int height, const char *pFilename); 44 | #endif 45 | BITMAP* load_binary_xflash(int picture_width, int picture_height, long src_addr); 46 | 47 | void destroy_bitmap(BITMAP *bitmap); 48 | void set_clip_state(BITMAP *bitmap, int state); 49 | int get_clip_state(BITMAP *bitmap); 50 | void set_clip_rect(BITMAP *bitmap, int x1, int y1, int x2, int y2); 51 | void get_clip_rect(BITMAP *bitmap, int *x1, int *y1, int *x2, int *y2); 52 | 53 | void rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color); 54 | void rect(BITMAP *bmp, int x1, int y1, int x2, int y2, int color); 55 | void clear_bitmap(BITMAP *bitmap); 56 | void clear_to_color(BITMAP *bitmap, int color); 57 | 58 | void textout_ex(BITMAP *bmp, const BFC_FONT *f, const char *s, int x, int y, int color, int bg); 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | /* Ends C function definitions when using C++ */ 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/Blit.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief 3 | * @note Reference : https://www.allegro.cc/manual/4/api/blitting-and-sprites/ 4 | * 5 | */ 6 | 7 | #include "Blit.h" 8 | 9 | /** 10 | * @brief Copies a rectangular area of the source BITMAP to the destination BITMAP. 11 | * @param *source points to the source BITMAP. 12 | * @param *dest points to the destination BITMAP to be copied to. 13 | * @param source_x & source_y are the top left corner of the area to copy from the source BITMAP. 14 | * @param dest_x and dest_y are the corresponding position in the destination BITMAP. 15 | * @param width & height indicate the dimension of the source BITMAP to be copied. 16 | * @note This fuction makes use of the hardware feature (BTE engine) of RA8876 to copy graphical content 17 | * from one area of the SDRAM to another. 18 | * Comply with legacy Allegro 4.4.x 19 | */ 20 | void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height) 21 | { 22 | if(source_x > source->getWidth() || source_y > source->getHeight()) return; 23 | if(dest_x > dest->getWidth() || dest_y > dest->getHeight()) return; 24 | 25 | if((dest_x+width) > dest->getWidth()) 26 | width = dest->getWidth()-dest_x; 27 | 28 | if((dest_y+height) > dest->getHeight()) 29 | height = dest->getHeight()-dest_y; 30 | 31 | ra8876lite.bteMemoryCopyWithROP( 32 | source->getAddress(), //src image physical address 33 | source->getWidth(), 34 | source_x,source_y, 35 | 0,0,0,0, //set s1_addr, s1_image_width, s1_x, s1_y all '0' 36 | dest->getAddress(), 37 | dest->getWidth(), 38 | dest_x, dest_y, 39 | width, height, 40 | RA8876_BTE_ROP_CODE_12 41 | ); 42 | } 43 | 44 | /** 45 | * @brief This function works like blit() but skipping transparent pixels defined by MASK_COLOR in blit.h 46 | * @param *source points to the source BITMAP. 47 | * @param *dest points to the destination BITMAP to be copied to. 48 | * @param source_x & source_y are the top left corner of the area to copy from the source BITMAP. 49 | * @param dest_x and dest_y are the corresponding position in the destination BITMAP. 50 | * @param width & height indicate the dimension of the source BITMAP to be copied. 51 | * @note This fuction makes use of the hardware feature (BTE engine) of RA8876 to copy graphical content 52 | * from one area of the SDRAM to another with chroma key. 53 | * Comply with legacy Allegro 4.4.x 54 | */ 55 | void masked_blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height) 56 | { 57 | if(source_x > source->getWidth() || source_y > source->getHeight()) return; 58 | if(dest_x > dest->getWidth() || dest_y > dest->getHeight()) return; 59 | 60 | if((dest_x+width) > dest->getWidth()) 61 | width = dest->getWidth()-dest_x; 62 | 63 | if((dest_y+height) > dest->getHeight()) 64 | height = dest->getHeight()-dest_y; 65 | 66 | ra8876lite.bteMemoryCopyWithChromaKey( 67 | source->getAddress(), //src image physical address 68 | source->getWidth(), 69 | source_x,source_y, //src image width & height 70 | dest->getAddress(), 71 | dest->getWidth(), 72 | dest_x, dest_y, 73 | width, height, 74 | MASK_COLOR 75 | ); 76 | } 77 | 78 | /** 79 | * @brief This function works like blit() but now with opacity level. 80 | * @param *source points to the source BITMAP. 81 | * @param *dest points to the destination BITMAP to be copied to. 82 | * @param source_x & source_y are the top left corner of the area to copy from the source BITMAP. 83 | * @param dest_x and dest_y are the corresponding position in the destination BITMAP. 84 | * @param width & height indicate the dimension of the source BITMAP to be copied. 85 | * @param alpha is the opacity level in 33 steps from 0 - 32 with opaque color level = 0 86 | */ 87 | void alpha_blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height, char alpha) 88 | { 89 | if(source_x > source->getWidth() || source_y > source->getHeight()) return; 90 | if(dest_x > dest->getWidth() || dest_y > dest->getHeight()) return; 91 | 92 | if((dest_x+width) > dest->getWidth()) 93 | width = dest->getWidth()-dest_x; 94 | 95 | if((dest_y+height) > dest->getHeight()) 96 | height = dest->getHeight()-dest_y; 97 | 98 | //Output Effect = (S0 image x (1 - alpha setting value)) + (S1 image x alpha setting value) 99 | //Don't ignore the background because transparency always refer to opacity against a background 100 | ra8876lite.bteMemoryCopyWithOpacity( 101 | dest->getAddress(), 102 | dest->getWidth(), 103 | dest_x, dest_y, 104 | source->getAddress(), 105 | source->getWidth(), 106 | source_x,source_y, 107 | dest->getAddress(), 108 | dest->getWidth(), 109 | dest_x, dest_y, 110 | width, height, 111 | alpha 112 | ); 113 | } 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/Blit.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief 3 | * @note Reference : https://www.allegro.cc/manual/4/api/blitting-and-sprites/ 4 | * 5 | */ 6 | 7 | #ifndef _BLIT_H 8 | #define _BLIT_H 9 | 10 | #include "Bitmap.h" 11 | 12 | class BITMAP; 13 | 14 | extern Color mask; 15 | ///@note MASK_COLOR (sf::Color object) is used to mask transparent sprite pixels 16 | #define MASK_COLOR mask.Magenta 17 | 18 | /* Starts C function definitions when using C++ */ 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); 24 | void masked_blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); 25 | void alpha_blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height, char alpha); 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | /* Ends C function definitions when using C++ */ 30 | 31 | #endif //#define _BLIT_H -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/Sprite.cpp: -------------------------------------------------------------------------------- 1 | #include "Sprite.h" 2 | 3 | /** 4 | * @note Default constructor with BITMAP bgsave created to store backgroung this sprite is going to cover. 5 | */ 6 | SPRITE::SPRITE(BITMAP *graphics, uint16_t width, uint16_t height) 7 | { 8 | if(graphics!=NULL) { 9 | frames = graphics; 10 | bgsave = new BITMAP(width, height); 11 | w = width; 12 | h = height; 13 | } 14 | } 15 | 16 | SPRITE::~SPRITE() 17 | { 18 | if(frames!=NULL) delete frames; 19 | if(bgsave!=NULL) delete bgsave; 20 | //printf("Sprite deleted!\n"); 21 | } 22 | 23 | static BITMAP *grabframe(BITMAP *source,int width,int height,int startx,int starty,int columns,int frame) 24 | { 25 | if(source==NULL) return NULL; 26 | 27 | BITMAP *temp = create_bitmap(width,height); 28 | 29 | if(temp==NULL) return NULL; 30 | 31 | int x = startx + (frame % columns) * width; 32 | int y = starty + (frame / columns) * height; 33 | blit(source,temp,x,y,0,0,width,height); 34 | return temp; 35 | } 36 | 37 | SPRITE *create_sprite(BITMAP *graphics, int width, int height) 38 | { 39 | SPRITE *pSprite = new SPRITE(graphics, width, height); 40 | 41 | if(pSprite==NULL) return NULL; 42 | //pSprite->bgsave = create_bitmap(width, height); 43 | //if(pSprite->bgsave==NULL) return NULL; 44 | 45 | return pSprite; 46 | } 47 | 48 | void set_sprite_position(SPRITE *sprite, int16_t x, int16_t y) 49 | { 50 | sprite->updatePosition(x,y); 51 | } 52 | 53 | void set_sprite_frame(SPRITE *sprite, uint16_t frame) 54 | { 55 | sprite->setCurFrame(frame); 56 | } 57 | 58 | /** 59 | * @brief Draws a copy of the sprite (*sprite) onto the destination bitmap (*bg) at a specified position (x,y). 60 | * @param *bg is a pointer to the background BITMAP this sprite covers. 61 | * @param *sprite is a pointer to the sprite to be drawn. 62 | * @param x,y indicate the position. 63 | * @note This is a modified version of masked_blit(sprite, bg, 0, 0, x, y, sprite->getWidth(), sprite->getHeight()) such that 64 | * the area of the background BITMAP this sprite covering is saved to a member BITMAP *bgsave of the sprite. 65 | * Function masked_blit() is used here to skip transparent pixels MASK_COLOR defined in Blit.h. 66 | */ 67 | void draw_sprite(BITMAP *bg, SPRITE *sprite, int x, int y) 68 | { 69 | if(bg==NULL || sprite==NULL) return; 70 | 71 | //save the background first 72 | blit(bg, sprite->bgsave, x, y, 0, 0, sprite->getWidth(), sprite->getHeight()); 73 | 74 | int column = (sprite->frames -> getWidth())/sprite->getWidth(); 75 | BITMAP *frame = grabframe(sprite->frames, sprite->getWidth(),sprite->getHeight(),0,0,column,sprite->getCurFrame()); 76 | 77 | if(frame!=NULL) 78 | { 79 | masked_blit(frame, bg,0,0,x,y,sprite->getWidth(),sprite->getHeight()); 80 | destroy_bitmap(frame); 81 | sprite->updatePosition(x,y); 82 | } 83 | } 84 | 85 | /** 86 | * @brief This function works like draw_sprite() except an extra argument alpha is used to 87 | * indicate the opacity level of the sprite, and the function alpha_blit() is used to 88 | * copy the sprite to a background instead of masked_blit(). MASK_COLOR is also supported. 89 | * @note If vsync() is not used it is advised to create a background BIMTAP with all graphics copied 90 | * to it. After rendering is finished, a single instruction to move the whole background to 91 | * screen to avoid flickering. 92 | */ 93 | void draw_trans_sprite(BITMAP *bg, SPRITE *sprite, int x, int y, char alpha) 94 | { 95 | if(bg==NULL || sprite==NULL) return; 96 | 97 | //save the background first 98 | blit(bg, sprite->bgsave, x, y, 0, 0, sprite->getWidth(), sprite->getHeight()); 99 | 100 | int column = (sprite->frames -> getWidth())/sprite->getWidth(); 101 | BITMAP *frame = grabframe(sprite->frames, sprite->getWidth(),sprite->getHeight(),0,0,column,sprite->getCurFrame()); 102 | 103 | if(frame!=NULL) 104 | { 105 | masked_blit(frame, bg,0,0,x,y,sprite->getWidth(),sprite->getHeight()); 106 | blit(bg, frame, x,y,0,0,sprite->getWidth(),sprite->getHeight()); //copy a masked version of the frame 107 | blit(sprite->bgsave, bg, 0,0,x,y,sprite->getWidth(),sprite->getHeight()); //restore the background 108 | alpha_blit(frame, bg,0,0,x,y,sprite->getWidth(),sprite->getHeight(), alpha); 109 | destroy_bitmap(frame); 110 | sprite->updatePosition(x,y); 111 | } 112 | } 113 | 114 | /** 115 | * @brief This function erases the sprite with the background redrawn. 116 | * @param *bg is a pointer to the background BITMAP where this sprite is covering. 117 | * @param *sprite is a pointer to the sprite to be erased. 118 | */ 119 | void erase_sprite(BITMAP *bg, SPRITE *sprite) 120 | { 121 | if((bg==NULL)||(sprite==NULL)) return; 122 | 123 | blit(sprite->bgsave, bg, 0,0, 124 | sprite->getX(), sprite->getY(), 125 | sprite->getWidth(), sprite->getHeight()); 126 | } 127 | 128 | 129 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/Sprite.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief 3 | * @note Reference : https://www.allegro.cc/manual/4/api/blitting-and-sprites/ 4 | * 5 | */ 6 | 7 | #ifndef _SPRITE_H 8 | #define _SPRITE_H 9 | 10 | #include "Bitmap.h" 11 | class BITMAP; 12 | 13 | /** 14 | * @brief SPRITE Class declaration 15 | * @note Reference: Game Programming All in One by
16 | * J. Harbour. Chapter 9: Advanced Sprite Programming 17 | * Class modified by John Leung @ TechToys 18 | */ 19 | class SPRITE { 20 | public: 21 | SPRITE(BITMAP *graphics, uint16_t width, uint16_t height); 22 | ~SPRITE(); 23 | BITMAP *bgsave=NULL; //pointer to background the sprite covering 24 | BITMAP *frames=NULL; //pointer to BITMAP of matrix n*m frames 25 | uint16_t getWidth(){return w;} 26 | uint16_t getHeight(){return h;} 27 | uint16_t getCurFrame(){return curframe;} 28 | void setCurFrame(uint16_t frame) {curframe = frame;} 29 | void updatePosition(int16_t x, int16_t y){pos_x = x; pos_y = y;} 30 | uint16_t getX(void){return pos_x;} 31 | uint16_t getY(void){return pos_y;} 32 | private: 33 | uint16_t w,h; 34 | int16_t pos_x=0,pos_y=0; //sprite position 35 | int16_t xspeed=0, yspeed=0;//velocity elements in pixel 36 | uint16_t curframe=0; 37 | }; 38 | 39 | /* Starts C function definitions when using C++ */ 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | static BITMAP *grabframe(BITMAP *source,int width,int height,int startx,int starty,int columns,int frame); 45 | 46 | SPRITE *create_sprite(BITMAP *graphics, int width, int height); 47 | void destroy_sprite(SPRITE *sprite); 48 | void set_sprite_speed(SPRITE *sprite, int16_t xspeed, int16_t yspeed); 49 | void set_sprite_position(SPRITE *sprite, int16_t x, int16_t y); 50 | void set_sprite_frame(SPRITE *sprite, uint16_t frame); 51 | //void set_sprite_animation(SPRITE *sprite, uint16_t framedelay, int16_t dir); 52 | void draw_sprite(BITMAP *bg, SPRITE *sprite, int x, int y); 53 | void draw_trans_sprite(BITMAP *bg, SPRITE *sprite, int x, int y, char alpha); 54 | void erase_sprite(BITMAP *bg, SPRITE *sprite); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | /* Ends C function definitions when using C++ */ 60 | 61 | #endif //#define _SPRITE_H 62 | 63 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/allegro.cpp: -------------------------------------------------------------------------------- 1 | #include "allegro.h" 2 | 3 | /** 4 | * @note Allegro creates a global screen pointer *screen allegro_init is called. 5 | * For RA8876, this pointer is equivalent to the Canvas with starting address 6 | * defined by CANVAS_OFFSET and its width/height defined by CANVAS_WIDTH/CANVAS_HEIGHT 7 | * in Ra8876_Lite.h. 8 | */ 9 | BITMAP *screen = NULL; 10 | Memory *mmu = new Memory(); 11 | static int color_depth = 16; 12 | 13 | /****************************************************************************/ 14 | /* C functions (inspired by Allegro 4.4.2 API) */ 15 | /****************************************************************************/ 16 | 17 | /** 18 | * @brief Function to initialize the Allegro library and create a global BITMAP *screen. 19 | * @return '0' on success 20 | * '-1' on failure 21 | */ 22 | int allegro_init(void) 23 | { 24 | screen = create_bitmap(VIRTUAL_W, VIRTUAL_H); 25 | //screen = create_bitmap(VIRTUAL_W, 240); 26 | //printf("Virtual w & h = %d, %d\n", VIRTUAL_W, VIRTUAL_H); 27 | 28 | if(screen==NULL) 29 | return -1; 30 | else 31 | return 0; 32 | } 33 | 34 | /** 35 | * @brief Function to closes down the Allegro system and free all memory 36 | * @note It is your job to delete all created BITMAPs in your program. 37 | * This function only delete and free memory for the global *screen 38 | * and dynamic array memory_tbl[] 39 | */ 40 | void allegro_exit(void) 41 | { 42 | delete screen; 43 | delete mmu; 44 | } 45 | 46 | /** 47 | * @brief Sets the pixel format to be used by subsequent calls to set_gfx_mode() and create_bitmap(). 48 | * @param depth is the color depth in bit-per-pixel. Valid depths are 8, 16, & 24 for RA8876. 49 | * @note Default color depth is 16bpp. 50 | */ 51 | void set_color_depth(int depth) 52 | { 53 | if(depth==8 || depth==16 || depth==24) 54 | color_depth = depth; 55 | } 56 | 57 | /** 58 | * @brief This function initializes RA8876 and CH7035B and set RA8876 in graphics mode. 59 | * @param card is a parameter selected from the enum GFX_VIDEO_MODE defined in allegro.h. 60 | * @param v_w is the virtual screen width equivalent to Canvas width of RA8876. 61 | * @param v_h is the virtual screen height equivalent to Canvas height of RA8876. 62 | * @return '0' on success 63 | * '-1' on failure 64 | * @note The color depth of the graphic mode has to be specified before calling this function 65 | * with set_color_depth(); otherwise, the default 16 bit-per-pixel color will be applied. 66 | * The input resolution of the RGB signal generated by RA8876 is specified by the prefix 67 | * GFX_ZZZ with _ZZZ as the video format e.g. VGA(640x480), WVGA(800x480), etc. 68 | * Video frames will be multiplied by a scaling engine of CH7035B HDMI encoder for higher 69 | * resolution that fits a HDTV/LCD monitor. Output HDMI resolution is specified by the suffixes 70 | * _YYY in GFX_ZZZ_YYY.
71 | * 72 | * Example to use:
73 | * set_color_depth(8); //set a color depth 8bpp 74 | * set_gfx_mode(GFX_FWVGA_HD720p_HDMI, 848, 480); //RA8876 generates 848x480 FWVGA @60Hz 75 | * //CH7035B upscale it to 1280x720p @60Hz HDMI interface 76 | * //set canvas size 848x480 for the input (not output) 77 | 78 | * set_color_depth(16); //set a color depth 16bpp 79 | * set_gfx_mode(GFX_HD720p_HD1080i_HDMI, 1280*2, 720*2); //RA8876 generates 1280x720 @60Hz (720p) HDMI interface 80 | * //CH7035B upscale it to 1080i interlaced HDMI 81 | * //v_w & v_h set to 1280*2 & 720*2 for screen scrolling & panning 82 | * 83 | */ 84 | int set_gfx_mode(int card, int v_w, int v_h) 85 | { 86 | LCDParam video_in; 87 | COLOR_MODE _mode; 88 | sf::Color color; 89 | 90 | switch (card) 91 | { 92 | case GFX_AUTO_DETECT: //use 9904 bootROM for 1280x720 @60Hz input 93 | break; 94 | case GFX_VGA_SVGA_DVI: 95 | video_in = CEA_640x480p_60Hz; 96 | break; 97 | case GFX_WVGA_WXGA_DVI: 98 | video_in = WVGA_800x480_60Hz; 99 | break; 100 | case GFX_SVGA_XGA_DVI: 101 | case GFX_SVGA_SXGA_DVI: 102 | case GFX_SVGA_UXGA_DVI: 103 | video_in = SVGA_800x600_60Hz; 104 | break; 105 | case GFX_FWVGA_HD720p_HDMI: 106 | video_in = FWVGA_848x480_60Hz; 107 | break; 108 | case GFX_HD480p_HD720p_HDMI: 109 | case GFX_HD480p_HD720p_DVI: 110 | video_in = CEA_720x480p_60Hz; 111 | break; 112 | case GFX_HD576p_SXGA_HDMI: 113 | video_in = CEA_720x576p_50Hz; 114 | break; 115 | case GFX_HD720p_HD1080i_HDMI: 116 | case GFX_HD720p_HD1080p_HDMI: 117 | case GFX_HD720p_HD1080p_DVI: 118 | video_in = CEA_1280x720p_60Hz; 119 | break; 120 | case GFX_WQVGA_HD480p_HDMI: 121 | case GFX_WQVGA_HD720p_HDMI: 122 | case GFX_WQVGA_HD1080p_HDMI: 123 | video_in = WQVGA_480x272_60Hz; 124 | break; 125 | default: 126 | printf("Incorrect 'card' argument in set_gfx_mode() call.\n"); 127 | return -1; 128 | } 129 | 130 | bool _success = 0; 131 | 132 | if(card!=GFX_AUTO_DETECT) 133 | _success = ra8876lite.begin(&video_in); 134 | else 135 | _success = ra8876lite.begin(); //use 9904 bootROM for 1280x720 @60Hz input, output 1080p 60Hz 136 | 137 | if(!_success) return -1; 138 | 139 | if(color_depth==24) 140 | _mode = COLOR_24BPP_RGB888; 141 | else if(color_depth==8) 142 | _mode = COLOR_8BPP_RGB332; 143 | else 144 | _mode = COLOR_16BPP_RGB565; 145 | 146 | ra8876lite.canvasImageBuffer(v_w, v_h, ACTIVE_WINDOW_STARTX, ACTIVE_WINDOW_STARTY, _mode, CANVAS_OFFSET); 147 | ra8876lite.displayMainWindow(); 148 | ra8876lite.canvasClear(color.Black); 149 | ra8876lite.graphicMode(true); 150 | ra8876lite.displayOn(true); 151 | 152 | HDMI_Tx.begin(); 153 | switch(card) 154 | { 155 | case GFX_VGA_SVGA_DVI: 156 | HDMI_Tx.init(VIDEO_in_640x480_out_DVI_800x600_60Hz); 157 | break; 158 | case GFX_WVGA_WXGA_DVI: 159 | HDMI_Tx.init(VIDEO_in_800x480_out_DVI_1280x768_60Hz); 160 | break; 161 | case GFX_SVGA_XGA_DVI: 162 | HDMI_Tx.init(VIDEO_in_800x600_out_DVI_1024x768_60Hz); 163 | break; 164 | case GFX_SVGA_SXGA_DVI: 165 | HDMI_Tx.init(VIDEO_in_800x600_out_DVI_1280x960_60Hz); 166 | break; 167 | case GFX_SVGA_UXGA_DVI: 168 | HDMI_Tx.init(VIDEO_in_800x600_out_DVI_1600x1200_60Hz); 169 | break; 170 | case GFX_HD480p_HD720p_DVI: 171 | HDMI_Tx.init(VIDEO_in_720x480_out_DVI_720p_60Hz); 172 | break; 173 | case GFX_HD720p_HD1080p_DVI: 174 | HDMI_Tx.init(VIDEO_in_1280x720_out_DVI_1080p_60Hz); 175 | break; 176 | 177 | case GFX_FWVGA_HD720p_HDMI: 178 | HDMI_Tx.init(VIDEO_in_848x480_out_HDMI_720p_60Hz); 179 | break; 180 | case GFX_HD480p_HD720p_HDMI: 181 | HDMI_Tx.init(VIDEO_in_720x480_out_HDMI_720p_60Hz); 182 | break; 183 | case GFX_HD576p_SXGA_HDMI: 184 | HDMI_Tx.init(VIDEO_in_720x576_out_DVI_1280x1024_60Hz); 185 | break; 186 | case GFX_HD720p_HD1080i_HDMI: 187 | HDMI_Tx.init(VIDEO_in_1280x720_out_HDMI_1080i_60Hz); 188 | break; 189 | case GFX_HD720p_HD1080p_HDMI: 190 | HDMI_Tx.init(VIDEO_in_1280x720_out_HDMI_1080p_60Hz); 191 | break; 192 | case GFX_WQVGA_HD480p_HDMI: 193 | HDMI_Tx.init(VIDEO_in_480x272_out_HDMI_480p_60Hz); 194 | break; 195 | case GFX_WQVGA_HD720p_HDMI: 196 | HDMI_Tx.init(VIDEO_in_480x272_out_HDMI_720p_60Hz); 197 | break; 198 | case GFX_WQVGA_HD1080p_HDMI: 199 | HDMI_Tx.init(VIDEO_in_480x272_out_HDMI_1080p_60Hz); 200 | break; 201 | } 202 | return 0; 203 | } 204 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Allegro/allegro.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief Allegro.h 3 | * @note Project inspired by Allegro Game Library (4.4.2) created by Shawn Hargreaves. 4 | * http://liballeg.org/stabledocs/en/allegro.html 5 | * API : https://www.allegro.cc/manual/4/api/ 6 | * 7 | */ 8 | 9 | #ifndef _ALLEGRO_H 10 | #define _ALLEGRO_H 11 | 12 | #include "HDMI/Ch703x.h" 13 | #include "Bitmap.h" 14 | #include "Blit.h" 15 | #include "Sprite.h" 16 | 17 | /** 18 | * @brief Video generated by RA8876. Monitors with DVI input accept only constant GFX_xxx_DVI as parameter.
19 | * Monitor/HDTV with HDMI interface accepts both GFX_xxx_DVI & GFX_xxx_HDMI as parameter.
20 | */ 21 | enum GFX_VIDEO_MODE{ //RA8876 -> CH7035B 22 | GFX_AUTO_DETECT = 0, //CEA 1280x720p -> CEA 1280x720p HDMI using 9904 bootROM 23 | GFX_VGA_SVGA_DVI, //640x480 -> 800x600 DVI 24 | GFX_WVGA_WXGA_DVI, //800x480 -> 1280x768 DVI 25 | GFX_SVGA_XGA_DVI, //800x600 -> 1024x768 DVI 26 | GFX_SVGA_SXGA_DVI, //800x600 -> 1280x960 DVI 27 | GFX_SVGA_UXGA_DVI, //800x600 -> 1600x1200 DVI 28 | GFX_HD480p_HD720p_DVI, //CEA 720x480p -> CEA 1280x720p DVI 29 | GFX_HD720p_HD1080p_DVI, //CEA 1280x720p -> 1920x1080p DVI 30 | 31 | GFX_FWVGA_HD720p_HDMI, //848x480 -> CEA 1280x720p HDMI 32 | GFX_HD480p_HD720p_HDMI, //CEA 720x480p -> CEA 1280x720p HDMI 33 | GFX_HD576p_SXGA_HDMI, //CEA 720x576p -> 1280x1024 DVI 34 | GFX_HD720p_HD1080i_HDMI,//CEA 1280x720p -> 1920x1080i HDMI 35 | GFX_HD720p_HD1080p_HDMI,//CEA 1280x720p -> 1920x1080p HDMI 36 | 37 | GFX_WQVGA_HD480p_HDMI, //480x272 -> CEA 720x480p HDMI 38 | GFX_WQVGA_HD720p_HDMI, //480x272 -> CEA 1280x720p HDMI 39 | GFX_WQVGA_HD1080p_HDMI //480x272 -> CEA 1920x1080p HDMI 40 | }; 41 | 42 | /** 43 | * @note VIRTUAL_W & VIRTUAL_H are parameters that return Canvas Width and Height after set_gfx_mode() is called.
44 | * Canvas Width and Height parameterize the image buffer allocated in SDRAM of RA8876. 45 | */ 46 | #define VIRTUAL_W ra8876lite.getCanvasWidth() 47 | #define VIRTUAL_H ra8876lite.getCanvasHeight() 48 | 49 | /** 50 | * @note SCREEN_W & SCREEN_H are width and height of the RGB video generated by RA8876.
51 | * These parameters may not the same as the final video output on LCD monitor.
52 | * Because there is a HDMI encoder (CH7035B) with scaling engine onboard of ArduoHDMI,
53 | * the actual video resolution output from CH7035B is scaled by a certain factor parameterized by
54 | * the argument in calling HDMI_Tx.init(). For example, calling the function
55 | * HDMI_Tx.init(VIDEO_in_848x480_out_HDMI_720p_60Hz)
56 | * will scale a 848x480 video source to an HDMI output of 1280x720 @ 60Hz.
57 | * CH7035B allows us to design graphics on a smaller video canvas (say 848x480) and get it boosted
58 | * to a higher resolution of 1280x720 and get it displayed on a modern HD or Full HDTV.
59 | */ 60 | #define SCREEN_W ra8876lite.getLCDWidth() 61 | #define SCREEN_H ra8876lite.getLCDHeight() 62 | 63 | 64 | /* Starts C function definitions when using C++ */ 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | int allegro_init(void); 70 | void allegro_exit(void); 71 | void set_color_depth(int depth); 72 | int set_gfx_mode(int card, int v_w, int v_h); 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | /* Ends C function definitions when using C++ */ 77 | 78 | #endif //_ALLEGRO_H -------------------------------------------------------------------------------- /Ra8876_Lite/src/Color/Color.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | 26 | /// Remove #include & #include 27 | /// By John Leung @TechToys Co. 28 | 29 | 30 | //////////////////////////////////////////////////////////// 31 | // Headers 32 | //////////////////////////////////////////////////////////// 33 | //#include 34 | //#include 35 | #include "Color.h" 36 | 37 | 38 | namespace sf 39 | { 40 | //////////////////////////////////////////////////////////// 41 | // Static member data 42 | //////////////////////////////////////////////////////////// 43 | const Color Color::Black(0, 0, 0); 44 | const Color Color::White(255, 255, 255); 45 | const Color Color::Red(255, 0, 0); 46 | const Color Color::Green(0, 255, 0); 47 | const Color Color::Blue(0, 0, 255); 48 | const Color Color::Yellow(255, 255, 0); 49 | const Color Color::Magenta(255, 0, 255); 50 | const Color Color::Cyan(0, 255, 255); 51 | const Color Color::Transparent(0, 0, 0, 0); 52 | 53 | 54 | //////////////////////////////////////////////////////////// 55 | Color::Color() : 56 | r(0), 57 | g(0), 58 | b(0), 59 | a(255) 60 | { 61 | 62 | } 63 | 64 | 65 | //////////////////////////////////////////////////////////// 66 | Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) : 67 | r(red), 68 | g(green), 69 | b(blue), 70 | a(alpha) 71 | { 72 | 73 | } 74 | 75 | //////////////////////////////////////////////////////////// 76 | Color::Color(Uint32 color) : 77 | r((color & 0xff000000) >> 24), 78 | g((color & 0x00ff0000) >> 16), 79 | b((color & 0x0000ff00) >> 8 ), 80 | a((color & 0x000000ff) >> 0 ) 81 | { 82 | 83 | } 84 | 85 | //////////////////////////////////////////////////////////// 86 | Uint32 Color::toInteger() const 87 | { 88 | return (r << 24) | (g << 16) | (b << 8) | a; 89 | } 90 | 91 | //////////////////////////////////////////////////////////// 92 | bool operator ==(const Color& left, const Color& right) 93 | { 94 | return (left.r == right.r) && 95 | (left.g == right.g) && 96 | (left.b == right.b) && 97 | (left.a == right.a); 98 | } 99 | 100 | 101 | //////////////////////////////////////////////////////////// 102 | bool operator !=(const Color& left, const Color& right) 103 | { 104 | return !(left == right); 105 | } 106 | 107 | 108 | //////////////////////////////////////////////////////////// 109 | Color operator +(const Color& left, const Color& right) 110 | { 111 | return Color(Uint8(min(int(left.r) + right.r, 255)), 112 | Uint8(min(int(left.g) + right.g, 255)), 113 | Uint8(min(int(left.b) + right.b, 255)), 114 | Uint8(min(int(left.a) + right.a, 255))); 115 | } 116 | 117 | 118 | //////////////////////////////////////////////////////////// 119 | Color operator -(const Color& left, const Color& right) 120 | { 121 | return Color(Uint8(max(int(left.r) - right.r, 0)), 122 | Uint8(max(int(left.g) - right.g, 0)), 123 | Uint8(max(int(left.b) - right.b, 0)), 124 | Uint8(max(int(left.a) - right.a, 0))); 125 | } 126 | 127 | 128 | //////////////////////////////////////////////////////////// 129 | Color operator *(const Color& left, const Color& right) 130 | { 131 | return Color(Uint8(int(left.r) * right.r / 255), 132 | Uint8(int(left.g) * right.g / 255), 133 | Uint8(int(left.b) * right.b / 255), 134 | Uint8(int(left.a) * right.a / 255)); 135 | } 136 | 137 | 138 | //////////////////////////////////////////////////////////// 139 | Color& operator +=(Color& left, const Color& right) 140 | { 141 | return left = left + right; 142 | } 143 | 144 | 145 | //////////////////////////////////////////////////////////// 146 | Color& operator -=(Color& left, const Color& right) 147 | { 148 | return left = left - right; 149 | } 150 | 151 | 152 | //////////////////////////////////////////////////////////// 153 | Color& operator *=(Color& left, const Color& right) 154 | { 155 | return left = left * right; 156 | } 157 | 158 | } // namespace sf 159 | 160 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Color/Color.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | /// Add to ensure compatibility with sketches that uses only Color object 26 | /// Remove #include 27 | /// Add #include "Config.h" 28 | /// By John Leung @TechToys Co. 29 | #ifndef SFML_COLOR_HPP 30 | #define SFML_COLOR_HPP 31 | 32 | //////////////////////////////////////////////////////////// 33 | // Headers 34 | //////////////////////////////////////////////////////////// 35 | //#include 36 | #include "Config.h" 37 | 38 | namespace sf 39 | { 40 | //////////////////////////////////////////////////////////// 41 | /// \brief Utility class for manipulating RGBA colors 42 | /// 43 | //////////////////////////////////////////////////////////// 44 | class SFML_GRAPHICS_API Color 45 | { 46 | public: 47 | 48 | //////////////////////////////////////////////////////////// 49 | /// \brief Default constructor 50 | /// 51 | /// Constructs an opaque black color. It is equivalent to 52 | /// sf::Color(0, 0, 0, 255). 53 | /// 54 | //////////////////////////////////////////////////////////// 55 | Color(); 56 | 57 | //////////////////////////////////////////////////////////// 58 | /// \brief Construct the color from its 4 RGBA components 59 | /// 60 | /// \param red Red component (in the range [0, 255]) 61 | /// \param green Green component (in the range [0, 255]) 62 | /// \param blue Blue component (in the range [0, 255]) 63 | /// \param alpha Alpha (opacity) component (in the range [0, 255]) 64 | /// 65 | //////////////////////////////////////////////////////////// 66 | Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255); 67 | 68 | //////////////////////////////////////////////////////////// 69 | /// \brief Construct the color from 32-bit unsigned integer 70 | /// 71 | /// \param color Number containing the RGBA components (in that order) 72 | /// 73 | //////////////////////////////////////////////////////////// 74 | explicit Color(Uint32 color); 75 | 76 | //////////////////////////////////////////////////////////// 77 | /// \brief Retrieve the color as a 32-bit unsigned integer 78 | /// 79 | /// \return Color represented as a 32-bit unsigned integer 80 | /// 81 | //////////////////////////////////////////////////////////// 82 | Uint32 toInteger() const; 83 | 84 | //////////////////////////////////////////////////////////// 85 | // Static member data 86 | //////////////////////////////////////////////////////////// 87 | static const Color Black; ///< Black predefined color 88 | static const Color White; ///< White predefined color 89 | static const Color Red; ///< Red predefined color 90 | static const Color Green; ///< Green predefined color 91 | static const Color Blue; ///< Blue predefined color 92 | static const Color Yellow; ///< Yellow predefined color 93 | static const Color Magenta; ///< Magenta predefined color 94 | static const Color Cyan; ///< Cyan predefined color 95 | static const Color Transparent; ///< Transparent (black) predefined color 96 | 97 | //////////////////////////////////////////////////////////// 98 | // Member data 99 | //////////////////////////////////////////////////////////// 100 | Uint8 r; ///< Red component 101 | Uint8 g; ///< Green component 102 | Uint8 b; ///< Blue component 103 | Uint8 a; ///< Alpha (opacity) component 104 | }; 105 | 106 | //////////////////////////////////////////////////////////// 107 | /// \relates Color 108 | /// \brief Overload of the == operator 109 | /// 110 | /// This operator compares two colors and check if they are equal. 111 | /// 112 | /// \param left Left operand 113 | /// \param right Right operand 114 | /// 115 | /// \return True if colors are equal, false if they are different 116 | /// 117 | //////////////////////////////////////////////////////////// 118 | SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right); 119 | 120 | //////////////////////////////////////////////////////////// 121 | /// \relates Color 122 | /// \brief Overload of the != operator 123 | /// 124 | /// This operator compares two colors and check if they are different. 125 | /// 126 | /// \param left Left operand 127 | /// \param right Right operand 128 | /// 129 | /// \return True if colors are different, false if they are equal 130 | /// 131 | //////////////////////////////////////////////////////////// 132 | SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right); 133 | 134 | //////////////////////////////////////////////////////////// 135 | /// \relates Color 136 | /// \brief Overload of the binary + operator 137 | /// 138 | /// This operator returns the component-wise sum of two colors. 139 | /// Components that exceed 255 are clamped to 255. 140 | /// 141 | /// \param left Left operand 142 | /// \param right Right operand 143 | /// 144 | /// \return Result of \a left + \a right 145 | /// 146 | //////////////////////////////////////////////////////////// 147 | SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right); 148 | 149 | //////////////////////////////////////////////////////////// 150 | /// \relates Color 151 | /// \brief Overload of the binary - operator 152 | /// 153 | /// This operator returns the component-wise subtraction of two colors. 154 | /// Components below 0 are clamped to 0. 155 | /// 156 | /// \param left Left operand 157 | /// \param right Right operand 158 | /// 159 | /// \return Result of \a left - \a right 160 | /// 161 | //////////////////////////////////////////////////////////// 162 | SFML_GRAPHICS_API Color operator -(const Color& left, const Color& right); 163 | 164 | //////////////////////////////////////////////////////////// 165 | /// \relates Color 166 | /// \brief Overload of the binary * operator 167 | /// 168 | /// This operator returns the component-wise multiplication 169 | /// (also called "modulation") of two colors. 170 | /// Components are then divided by 255 so that the result is 171 | /// still in the range [0, 255]. 172 | /// 173 | /// \param left Left operand 174 | /// \param right Right operand 175 | /// 176 | /// \return Result of \a left * \a right 177 | /// 178 | //////////////////////////////////////////////////////////// 179 | SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right); 180 | 181 | //////////////////////////////////////////////////////////// 182 | /// \relates Color 183 | /// \brief Overload of the binary += operator 184 | /// 185 | /// This operator computes the component-wise sum of two colors, 186 | /// and assigns the result to the left operand. 187 | /// Components that exceed 255 are clamped to 255. 188 | /// 189 | /// \param left Left operand 190 | /// \param right Right operand 191 | /// 192 | /// \return Reference to \a left 193 | /// 194 | //////////////////////////////////////////////////////////// 195 | SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right); 196 | 197 | //////////////////////////////////////////////////////////// 198 | /// \relates Color 199 | /// \brief Overload of the binary -= operator 200 | /// 201 | /// This operator computes the component-wise subtraction of two colors, 202 | /// and assigns the result to the left operand. 203 | /// Components below 0 are clamped to 0. 204 | /// 205 | /// \param left Left operand 206 | /// \param right Right operand 207 | /// 208 | /// \return Reference to \a left 209 | /// 210 | //////////////////////////////////////////////////////////// 211 | SFML_GRAPHICS_API Color& operator -=(Color& left, const Color& right); 212 | 213 | //////////////////////////////////////////////////////////// 214 | /// \relates Color 215 | /// \brief Overload of the binary *= operator 216 | /// 217 | /// This operator returns the component-wise multiplication 218 | /// (also called "modulation") of two colors, and assigns 219 | /// the result to the left operand. 220 | /// Components are then divided by 255 so that the result is 221 | /// still in the range [0, 255]. 222 | /// 223 | /// \param left Left operand 224 | /// \param right Right operand 225 | /// 226 | /// \return Reference to \a left 227 | /// 228 | //////////////////////////////////////////////////////////// 229 | SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right); 230 | 231 | }; // namespace sf 232 | 233 | // Add to ensure compatibility with sketches that uses only Color object 234 | using namespace sf; 235 | typedef sf::Color Color; 236 | 237 | #endif // SFML_COLOR_HPP 238 | 239 | 240 | //////////////////////////////////////////////////////////// 241 | /// \class sf::Color 242 | /// \ingroup graphics 243 | /// 244 | /// sf::Color is a simple color class composed of 4 components: 245 | /// \li Red 246 | /// \li Green 247 | /// \li Blue 248 | /// \li Alpha (opacity) 249 | /// 250 | /// Each component is a public member, an unsigned integer in 251 | /// the range [0, 255]. Thus, colors can be constructed and 252 | /// manipulated very easily: 253 | /// 254 | /// \code 255 | /// sf::Color color(255, 0, 0); // red 256 | /// color.r = 0; // make it black 257 | /// color.b = 128; // make it dark blue 258 | /// \endcode 259 | /// 260 | /// The fourth component of colors, named "alpha", represents 261 | /// the opacity of the color. A color with an alpha value of 262 | /// 255 will be fully opaque, while an alpha value of 0 will 263 | /// make a color fully transparent, whatever the value of the 264 | /// other components is. 265 | /// 266 | /// The most common colors are already defined as static variables: 267 | /// \code 268 | /// sf::Color black = sf::Color::Black; 269 | /// sf::Color white = sf::Color::White; 270 | /// sf::Color red = sf::Color::Red; 271 | /// sf::Color green = sf::Color::Green; 272 | /// sf::Color blue = sf::Color::Blue; 273 | /// sf::Color yellow = sf::Color::Yellow; 274 | /// sf::Color magenta = sf::Color::Magenta; 275 | /// sf::Color cyan = sf::Color::Cyan; 276 | /// sf::Color transparent = sf::Color::Transparent; 277 | /// \endcode 278 | /// 279 | /// Colors can also be added and modulated (multiplied) using the 280 | /// overloaded operators + and *. 281 | /// 282 | //////////////////////////////////////////////////////////// 283 | 284 | 285 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/Color/Config.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | // 3 | // SFML - Simple and Fast Multimedia Library 4 | // Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) 5 | // 6 | // This software is provided 'as-is', without any express or implied warranty. 7 | // In no event will the authors be held liable for any damages arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it freely, 11 | // subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; 14 | // you must not claim that you wrote the original software. 15 | // If you use this software in a product, an acknowledgment 16 | // in the product documentation would be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, 19 | // and must not be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source distribution. 22 | // 23 | //////////////////////////////////////////////////////////// 24 | 25 | #ifndef SFML_CONFIG_HPP 26 | #define SFML_CONFIG_HPP 27 | 28 | 29 | //////////////////////////////////////////////////////////// 30 | // Define the SFML version 31 | //////////////////////////////////////////////////////////// 32 | #define SFML_VERSION_MAJOR 2 33 | #define SFML_VERSION_MINOR 4 34 | #define SFML_VERSION_PATCH 2 35 | 36 | 37 | //////////////////////////////////////////////////////////// 38 | // Identify the operating system 39 | // see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system 40 | //////////////////////////////////////////////////////////// 41 | #if defined(_WIN32) 42 | 43 | // Windows 44 | #define SFML_SYSTEM_WINDOWS 45 | #ifndef NOMINMAX 46 | #define NOMINMAX 47 | #endif 48 | 49 | #elif defined(__APPLE__) && defined(__MACH__) 50 | 51 | // Apple platform, see which one it is 52 | #include "TargetConditionals.h" 53 | 54 | #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 55 | 56 | // iOS 57 | #define SFML_SYSTEM_IOS 58 | 59 | #elif TARGET_OS_MAC 60 | 61 | // MacOS 62 | #define SFML_SYSTEM_MACOS 63 | 64 | #else 65 | 66 | // Unsupported Apple system 67 | #error This Apple operating system is not supported by SFML library 68 | 69 | #endif 70 | 71 | #elif defined(__unix__) 72 | 73 | // UNIX system, see which one it is 74 | #if defined(__ANDROID__) 75 | 76 | // Android 77 | #define SFML_SYSTEM_ANDROID 78 | 79 | #elif defined(__linux__) 80 | 81 | // Linux 82 | #define SFML_SYSTEM_LINUX 83 | 84 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 85 | 86 | // FreeBSD 87 | #define SFML_SYSTEM_FREEBSD 88 | 89 | #else 90 | 91 | // Unsupported UNIX system 92 | #error This UNIX operating system is not supported by SFML library 93 | 94 | #endif 95 | 96 | #elif defined (ARDUINO) & ARDUINO >= 100 97 | #define SFML_SYSTEM_ARDUINO 98 | #define SFML_GRAPHICS_API 99 | #include 100 | #else 101 | 102 | // Unsupported system 103 | #error This operating system is not supported by SFML library 104 | 105 | #endif 106 | 107 | 108 | //////////////////////////////////////////////////////////// 109 | // Define a portable debug macro 110 | //////////////////////////////////////////////////////////// 111 | #if !defined(NDEBUG) 112 | 113 | #define SFML_DEBUG 114 | 115 | #endif 116 | 117 | 118 | //////////////////////////////////////////////////////////// 119 | // Define helpers to create portable import / export macros for each module 120 | //////////////////////////////////////////////////////////// 121 | #if !defined(SFML_STATIC) 122 | 123 | #if defined(SFML_SYSTEM_WINDOWS) 124 | 125 | // Windows compilers need specific (and different) keywords for export and import 126 | #define SFML_API_EXPORT __declspec(dllexport) 127 | #define SFML_API_IMPORT __declspec(dllimport) 128 | 129 | // For Visual C++ compilers, we also need to turn off this annoying C4251 warning 130 | #ifdef _MSC_VER 131 | 132 | #pragma warning(disable: 4251) 133 | 134 | #endif 135 | 136 | #else // Linux, FreeBSD, Mac OS X 137 | 138 | #if __GNUC__ >= 4 139 | 140 | // GCC 4 has special keywords for showing/hidding symbols, 141 | // the same keyword is used for both importing and exporting 142 | #define SFML_API_EXPORT __attribute__ ((__visibility__ ("default"))) 143 | #define SFML_API_IMPORT __attribute__ ((__visibility__ ("default"))) 144 | 145 | #else 146 | 147 | // GCC < 4 has no mechanism to explicitely hide symbols, everything's exported 148 | #define SFML_API_EXPORT 149 | #define SFML_API_IMPORT 150 | 151 | #endif 152 | 153 | #endif 154 | 155 | #else 156 | 157 | // Static build doesn't need import/export macros 158 | #define SFML_API_EXPORT 159 | #define SFML_API_IMPORT 160 | 161 | #endif 162 | 163 | 164 | //////////////////////////////////////////////////////////// 165 | // Cross-platform warning for deprecated functions and classes 166 | // 167 | // Usage: 168 | // class SFML_DEPRECATED MyClass 169 | // { 170 | // SFML_DEPRECATED void memberFunc(); 171 | // }; 172 | // 173 | // SFML_DEPRECATED void globalFunc(); 174 | //////////////////////////////////////////////////////////// 175 | #if defined(SFML_NO_DEPRECATED_WARNINGS) 176 | 177 | // User explicitly requests to disable deprecation warnings 178 | #define SFML_DEPRECATED 179 | 180 | #elif defined(_MSC_VER) 181 | 182 | // Microsoft C++ compiler 183 | // Note: On newer MSVC versions, using deprecated functions causes a compiler error. In order to 184 | // trigger a warning instead of an error, the compiler flag /sdl- (instead of /sdl) must be specified. 185 | #define SFML_DEPRECATED __declspec(deprecated) 186 | 187 | #elif defined(__GNUC__) 188 | 189 | // g++ and Clang 190 | #define SFML_DEPRECATED __attribute__ ((deprecated)) 191 | 192 | #else 193 | 194 | // Other compilers are not supported, leave class or function as-is. 195 | // With a bit of luck, the #pragma directive works, otherwise users get a warning (no error!) for unrecognized #pragma. 196 | #pragma message("SFML_DEPRECATED is not supported for your compiler, please contact the SFML team") 197 | #define SFML_DEPRECATED 198 | 199 | #endif 200 | 201 | 202 | //////////////////////////////////////////////////////////// 203 | // Define portable fixed-size types 204 | //////////////////////////////////////////////////////////// 205 | namespace sf 206 | { 207 | // All "common" platforms use the same size for char, short and int 208 | // (basically there are 3 types for 3 sizes, so no other match is possible), 209 | // we can use them without doing any kind of check 210 | 211 | // 8 bits integer types 212 | typedef signed char Int8; 213 | typedef unsigned char Uint8; 214 | 215 | // 16 bits integer types 216 | typedef signed short Int16; 217 | typedef unsigned short Uint16; 218 | 219 | // 32 bits integer types 220 | typedef signed int Int32; 221 | typedef unsigned int Uint32; 222 | 223 | // 64 bits integer types 224 | #if defined(_MSC_VER) 225 | typedef signed __int64 Int64; 226 | typedef unsigned __int64 Uint64; 227 | #else 228 | typedef signed long long Int64; 229 | typedef unsigned long long Uint64; 230 | #endif 231 | 232 | } // namespace sf 233 | 234 | 235 | #endif // SFML_CONFIG_HPP 236 | 237 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/HDMI/Ch703x.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Ch703x.h 3 | * @author John Leung @ TechToys (www.TechToys.com.hk) 4 | * 5 | * @section HISTORY 6 | * Date 22nd May 2017 First release
7 | * 8 | * @note Pinout summary::
9 | * 10 | * Board(interface) Arduino Due (via adapter Due Zipper DTE20171024)
11 | * ============== ===========
12 | * CH7035B-SCL SCL1(D71)
13 | * CH7035B-SDA SDA1(D70)
14 | * CH7035B-IRQ D5 (not used)
15 | * 16 | * Board(interface) M0/M0 PRO & Curie (direct stack)
17 | * ============== ===========
18 | * CH7035B-SCL SCL0
19 | * CH7035B-SDA SDA0
20 | * CH7035B-IRQ D5 (not used)
21 | * CH7035B-I2S/SD D9
22 | * CH7035B-I2S/SCK D6
23 | * CH7035B-I2S/FS D7
24 | * 25 | * Board(interface) Teensy3.2/3.5 (via adapter Teensy Stacker DTE20171030)
26 | * ============== ===============================
27 | * CH7035B-SCL SCL0(D19)
28 | * CH7035B-SDA SDA0(D18)
29 | * CH7035B-IRQ D6 (not used)
30 | * CH7035B-I2S/SD D22
31 | * CH7035B-I2S/SCK D9
32 | * CH7035B-I2S/FS D23
33 | * 34 | * Board(interface) ESP8266 (via adapter Due Zipper DTE20171024)
35 | * ============== =====================
36 | * CH7035B-SCL SCL0(D5)
37 | * CH7035B-SDA SDA0(D4)
38 | */ 39 | 40 | #ifndef __CH703X_H 41 | #define __CH703X_H 42 | 43 | #include "Arduino.h" 44 | #include "Wire.h" 45 | #include "edid/edid.h" 46 | #include "LcdParam.h" 47 | #include "videoInOutMap.h" 48 | #include "util/printf.h" ///by Michael McElligott 49 | 50 | 51 | ///@note Hardware pinout 52 | /* 53 | #ifdef TEENSYDUINO 54 | const int CH703X_IRQ =6; //Pin D15 for Teensy 3.2/3.5 55 | #else 56 | const int CH703X_IRQ =5; //Pin D5 for Due, M0/M0 PRO, Curie 57 | #endif 58 | */ 59 | const int CH703X_SLAVE_ADDR = 0x76; //7'bit slave address of CH7035B 60 | 61 | class CH703X { 62 | private: 63 | void hal_hwSetup(); 64 | void hal_delayMs(uint32_t ms); 65 | void hal_writeRegister(uint8_t index, uint8_t val); 66 | uint8_t hal_readRegister(uint8_t index); 67 | void writeRegister(uint8_t page, uint8_t index, uint8_t val); 68 | void readRegister(uint8_t page, uint8_t index, uint8_t *val, uint8_t count); 69 | void setRegisterPage(uint8_t page); 70 | const char *yesno (int v); 71 | 72 | bool _initialised = false; 73 | TwoWire *_i2c; 74 | 75 | uint8_t edidBuf[128]; ///EDID buffer 76 | 77 | public: 78 | CH703X(){}; 79 | ~CH703X(){}; 80 | 81 | /** 82 | *@brief This function resets all control registers to the default values. 83 | *@note Control registers are also reset at power on by an internally 84 | * generated power on reset signal. 85 | */ 86 | void resetIB(void); 87 | 88 | /** 89 | *@brief This function resets the data path. 90 | *@note reset the data path is like reseting the MCU of ch703x. 91 | */ 92 | void resetDB(void); 93 | 94 | /** 95 | * @brief Initialize CH703x and power it up with video in & out parameters 96 | * @param lcdParamInOut[][2] is a 2-D array generated by an offline tool from Chrontel 97 | */ 98 | bool init(const uint8_t lcdParamInOut[][2]); 99 | 100 | //bool init(const LCDParam *videoIn, const LCDParam *videoOut, uint8_t monitorType); 101 | 102 | /** 103 | * @brief This function allows remote procedure call to writeRegister() 104 | * & readRegister() from a serial terminal. 105 | * @precondition Serial.begin(115200) in setup() 106 | * @note Example to use: 107 | * In Arduino, open Serial Monitor, type in following 108 | * command into the text box and click 109 | * 110 | * //i2c write to page 1 at register address 0x10, a value of 55 111 | * i2c,w,1,0x10,55 -or- i2c,w,0x01,0x10,0x37 112 | * //i2c read from page 1 at register address 0x10 a single byte 113 | * i2c,r,1,0x10 114 | * 115 | * @param *msg is a pointer to message. 116 | * 117 | */ 118 | void parser(char *msg); 119 | 120 | /** 121 | * @brief GPIO and I2C setup. Should call this before using in Serial Monitor to read EDID 122 | */ 123 | void begin(void); 124 | 125 | /** 126 | * @brief Read device ID from page 4 register 0x50. 127 | * @return 0x52 if i2c read is doing correctly (returning 0x5E actually) 128 | */ 129 | uint8_t getChipID(void); 130 | 131 | /** 132 | * @brief Read revision ID from page 4 register 0x51. 133 | * @return 0x02 if i2c read is doing correctly (returning 0xC3 actually) 134 | */ 135 | uint8_t getRevID(void); 136 | 137 | /** 138 | * @brief Read EDID from a HDMI sink device. 139 | * @return true if EDID read OK 140 | * false if no EDID can be read 141 | */ 142 | bool readEdid(void); 143 | 144 | /** 145 | * @brief Print EDID information via Serial Monitor 146 | * @note Copyright 2007 Red Hat, Inc. 147 | * src: https://people.gnome.org/~ssp/randr/edid.h 148 | */ 149 | void dump_monitor_info(void); 150 | 151 | /** 152 | * @brief Freeze image on DVI/VGA/HDTV 153 | * @param Set 1 to freeze 154 | * Set 0 to release 155 | */ 156 | void freezeImage(bool freeze); 157 | 158 | /** 159 | * @brief Bypass frame scaler enable / disable 160 | * @param Set 1 to bypass 161 | * Set 0 to enable frame scaler 162 | * 163 | */ 164 | void frameScaler(bool bypass); 165 | 166 | /** 167 | * @brief Display a test pattern directly from CH703X HDMI encoder 168 | * @param sw is the switch for ON(1), OFF(0) 169 | * @param pattern valid values are 0(External data), 1(White), 2(Vertical ramp), 170 | * 3(Horizontal ramp), 4(Color bar), 7(production test pattern), 171 | * 11(sine wave output for DAC test), 13(ramp output for DAC test) 172 | */ 173 | void testPattern(bool sw, uint8_t pattern); 174 | 175 | /** 176 | * @brief Set horizontal total pixels for input signal 177 | * @param hti is the horizontal total pixels 178 | */ 179 | void setInputHorizontalTotal(uint16_t hti); 180 | 181 | /** 182 | * @brief Set horizontal front porch for input signal 183 | * @param hoi is the horizontal sync offset, also known as front porch 184 | */ 185 | void setInputHsyncFrontPorch(uint16_t hoi); 186 | 187 | /** 188 | * @brief Set horizontal active pixel for input signal 189 | * @param hai is the horizontal active width in pixel clock 190 | */ 191 | void setInputHsyncActiveWidth(uint16_t hai); 192 | 193 | /** 194 | * @brief Set horzonital pulse width for input signal 195 | * @param hwi is the horizontal pulse width in pixel clock 196 | */ 197 | void setInputHsyncPulseWidth(uint16_t hwi); 198 | 199 | /** 200 | * @brief Set vertical total line number for input signal 201 | * @param vti is the vertical total line number 202 | */ 203 | void setInputVerticalTotal(uint16_t vti); 204 | 205 | /** 206 | * @brief Set vertical front porch for input signal 207 | * @param voi is the vertical sync offset, also known as front porch 208 | */ 209 | void setInputVsyncFrontPorch(uint16_t voi); 210 | 211 | /** 212 | * @brief Set vertical active height for input signal 213 | * @param vai is the vertical active height in line number 214 | */ 215 | void setInputVsyncActiveHeight(uint16_t vai); 216 | 217 | /** 218 | * @brief Set vertical pulse width for input signal 219 | * @param hwi is the vertical pulse width in line number 220 | */ 221 | void setInputVsyncPulseWidth(uint16_t vwi); 222 | 223 | /** 224 | * @brief Set input sync polarity for hsync, vsync, and de 225 | * @param hsync polarity, 1 for high active, 0 for low active 226 | * @param vsync polarity, 1 for high active, 0 for low active 227 | * @param de polarity, 1 for high active, 0 for low active 228 | */ 229 | void setInputSyncPolarity(bool hsync, bool vsync, bool de); 230 | 231 | /** 232 | * @brief Set input signal pixel clock frequency 233 | * @param pclk in kHz (eg 50MHz, GCLKFREQ[17:0]=50000 234 | */ 235 | void setInputPclkFrequency(uint32_t pclk); 236 | 237 | /** 238 | * @brief Set horizontal total pixels for output signal 239 | * @param hto is the horizontal total pixels 240 | */ 241 | void setOutputHorizontalTotal(uint16_t hto); 242 | 243 | /** 244 | * @brief Set horizontal front porch for output signal 245 | * @param hoo is the horizontal sync offset, also known as front porch 246 | */ 247 | void setOutputHsyncFrontPorch(uint16_t hoo); 248 | 249 | /** 250 | * @brief Set horizontal active pixel for output signal 251 | * @param hao is the horizontal active width in pixel clock 252 | */ 253 | void setOutputHsyncActiveWidth(uint16_t hao); 254 | 255 | /** 256 | * @brief Set horizontal pulse width for output signal 257 | * @param hwo is the horizontal pulse width in pixel clock 258 | */ 259 | void setOutputHsyncPulseWidth(uint16_t hwo); 260 | 261 | 262 | /** 263 | * @brief Set I2S audio format and set it enable or disable 264 | * @param len is the length of I2S data bit, 0=16bits, 1=20bits, or 2=24bits. 265 | * @param fmt is the format, 00:standard, 01:right-justified, 10:left-justified 266 | * @param en is the enable flag, '1' to enable, '0' to disable 267 | * @note: Example to set an I2S standard format in 16-bit data length to enable audio 268 | * setI2SAudio(0, 0, 1); 269 | * Example to disable I2S audio 270 | * setI2SAudio(xx, xx, 0); //xx's are don't care values when en=0, they can be zero 271 | * @note: Relevant registers 272 | * Page 1, R1_07h[6], I2S_PD, 1:power down, 0:power on 273 | Page 1, register 0x1E: 274 | I2SPOL, I2S_SPDIFB, INTLC, I2S_LENGTH, I2SFMT, 275 | Page 2, register 0x4F: 276 | R2_4Fh[7:6] with values dependent on I2S length 277 | */ 278 | void setI2SAudio(uint8_t len, uint8_t fmt, bool en); 279 | 280 | }; 281 | 282 | extern CH703X HDMI_Tx; 283 | #endif //__CH703X_H 284 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/HDMI/LcdParam.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file LcdParam.h 3 | * @author John Leung @ TechToys Co. (www.TechToys.com.hk) 4 | * @license BSD license, all text above and below must be included in any redistribution 5 | * 6 | * This header file describes timing information of a LCD panel in RGB mode. 7 | * 8 | * @section HISTORY 9 | * 10 | * v1.0 - First release on 14-07-2017 11 | */ 12 | 13 | #ifndef _LCDPARAM_H 14 | #define _LCDPARAM_H 15 | 16 | #include "stdint.h" 17 | #include "stdbool.h" 18 | 19 | /** 20 | * @note Timing parameters of a LCD panel.
21 | * A structure with CEA_ prefix below implies a timing in compliance with CEA Standard (CEA-861-D).
22 | * CEA-861-D establishes protocols for consumer electronics devices such as digital TVs, set-top boxes, 23 | * DVD players, and other related source or sink devices (a HDTV in our case).
24 | * Some information specific for RA8876 is that, although there are over 40 standards defined in CEA-861-D 25 | * there are not all of them can be used in RA8876. 26 | * Generation of a pixel clock is limited by the SPLL clock (SCAN_FREQ) and core clock (CORE_FREQ) speed 27 | * of RA8876. RA8876's CORE_FREQ without internal font is 133MHz. SCAN_FREQ generated should be smaller 28 | * than CORE_FREQ / 1.5, as a result, the max. pixel clock = 88.67MHz. 29 | * Therefore, generation of a 1080p HDTV resolution with 60Hz frme rate is not possible because pixel clock 30 | * of 1080p@60Hz requires 148MHz.
31 | * Another restriction is that max horizontal display width of 2049 or higher is not allowed with RA8876.
32 | * Max horizontal blanking period in RA8876 = h back porch + h front porch + h pulse width
33 | * = (REG[16]+1)*8+REG[17]+(REG[18]+1)*8+(REG[19]+1)*8
34 | * = (31+1)*8 + 16 + (31+1)*8 + (31+1)*8
35 | * = 784
36 | * As a result, VIC code 32 of 1920x1080p @ 24Hz is not supported either. 37 | * Because max horizontal front porch that can be set in RA8876 is 256 pclk, 38 | * VIC code 31 for 1920x1080p @50Hz is not supported again as its front porch value required 39 | * to be 440 pclk.
40 | * With such restrictions, it would make sense to use a HDMI encoder with frame scaler embedded such as CH703x 41 | * to boost a lower resolution (720p@60Hz in our standard demo) to 1080p@60Hz. 42 | */ 43 | typedef struct LCDParam { 44 | /// Name of panel 45 | const char* name; 46 | /// Panel width in pixels 47 | uint16_t width; 48 | /// Panel height in pixels 49 | uint16_t height; 50 | /// Horizontal blanking period in pixel clock (pclk) = pulse width + back porch + front porch 51 | uint16_t hblank; 52 | /// Horizontal front porch in pclk 53 | uint16_t hfporch; 54 | /// Horizontal pulse width in pclk 55 | uint16_t hpulse; 56 | /// Vertical blanking period in lines = pulse width + back porch + front porch. 57 | /// Blanking period for MCU to write data takes vpulse+vbackporch=vblank-vfporch 58 | uint16_t vblank; 59 | /// Vertical front porch in lines 60 | uint16_t vfporch; 61 | /// Vertical pulse with in lines 62 | uint16_t vpulse; 63 | /// Pixel clock uint in MHz. This will be changed to kHz in future version. 64 | uint32_t pclk; 65 | /// Vsync polarity : 1=positive vsync, 0=negative vsync 66 | bool vsyncPolarity; 67 | /// Hsync polarity : 1=positive hsync, 0=negative hsync 68 | bool hsyncPolarity; 69 | /// Pixel clock polarity : 1=falling edge, 0=rising edge 70 | bool pclkPolarity; 71 | /// DE pulse polarity : 1=negative DE, 0=positive DE 72 | bool dePolarity; 73 | } LCDParam; 74 | 75 | /** 76 | * @note This timing is based on the timing in VESA Monitor Timings Spec. available only in a 4:3 aspect ratio.
77 | * Resolution 640x480 @ 60Hz. This resolution can be generated directly by RA8876 alone. 78 | */ 79 | const LCDParam CEA_640x480p_60Hz = 80 | { 81 | "CEA 640x480p@60Hz 4:3 VIC#1", 82 | 640, 480, 83 | 160, //h blanking total 84 | 16, //h front porch 85 | 96, //h pulse width 86 | 45, //v blanking total 87 | 10, //v front porch 88 | 2, //v pulse width 89 | 25, //pclk in MHz (chg to 25200kHz in new version) 90 | 0, //-ve vsync 91 | 0, //-ve vsync 92 | 0, 93 | 0 94 | }; 95 | 96 | /** 97 | * @note This timing is based on CEA-770.2-C [19], with one difference. CEA-770.2-C has a composite sync while 98 | CEA-861-D uses separate sync signals, thus eliminating the need for serrations during vertical sync. This 99 | format timing can use either 4:3 or 16:9 aspect ratio.
100 | Resolution 720x480 @ 60Hz. This resolution can be generated directly by RA8876 alone. 101 | */ 102 | const LCDParam CEA_720x480p_60Hz = 103 | { 104 | "CEA 720x480p@60Hz 4:3 VIC#2", 105 | 720, 480, 106 | 138, //h blanking total 107 | 16, //h front porch 108 | 62, //h pulse width 109 | 45, //v blanking total 110 | 9, //v front porch 111 | 6, //v pulse width 112 | 27, //pclk 113 | 0, 114 | 0, 115 | 0, 116 | 0 117 | }; 118 | 119 | /** 120 | * @note This format is available only in a 16:9 aspect ratio. This timing is based on CEA-770.3-D [20], but there 121 | are two differences. First, CEA-770.3-C uses tri-level sync, while CEA-861-D uses bi-level. Bi-level sync 122 | timing is accomplished using the second half of the CEA-770.3-C tri-level sync, defining the actual sync 123 | time to be the rising edge of that pulse.
124 | Resolution 1280x720 @ 60Hz. This resolution can be generated directly by RA8876 alone. 125 | */ 126 | const LCDParam CEA_1280x720p_60Hz = 127 | { 128 | "CEA 1280x720p@60Hz 16:9 VIC#4", 129 | 1280, 720, //width, height 130 | (220+110+40), //horizontal blanking total 131 | 110, //horizontal front porch 132 | 40, //horizontal pulse width 133 | (20+5+5), //vertical blanking total 134 | 5, //vertical front porch 135 | 5, //vertical pulse width 136 | 74, //pixel clock 74MHz 137 | 1, //+ve vsync 138 | 1, //+ve hsync 139 | 0, //rising edge pclk 140 | 0 //+ve de 141 | }; 142 | 143 | /** 144 | * @note This format is available only in a 16:9 aspect ratio. It is likely that non-HDMI source devices may not 145 | recognize this format in a Detailed Timing Descriptor.
146 | Resolution 1920x1080 @ 60Hz. This resolution can NOT be generated directly by RA8876 alone. 147 | */ 148 | const LCDParam CEA_1920x1080p_60Hz = 149 | { 150 | "CEA 1920x1080P@60Hz 16:9 VIC#16", //CEA861D format 16 151 | 1920, 1080, 152 | 280, 153 | 88, 154 | 44, 155 | 45, 156 | 4, 157 | 5, 158 | 148, 159 | 1, 160 | 1, 161 | 0, 162 | 0 163 | }; 164 | 165 | /** 166 | * @note This timing is based on ITU-R BT.1358 [41]. This format timing can use either 4:3 or 16:9 aspect ratio.
167 | * Resolution 720x576 @ 50Hz. This resolution can be generated directly by RA8876 alone. 168 | */ 169 | const LCDParam CEA_720x576p_50Hz = 170 | { 171 | "CEA 720x576p@50Hz 4:3 VIC#17", 172 | 720, 576, 173 | 144, //h blanking total 174 | 12, //h front porch 175 | 64, //h pulse width 176 | 49, //v blanking total 177 | 5, //v front porch 178 | 5, //v pulse width 179 | 27, //pclk 180 | 0, 181 | 0, 182 | 0, 183 | 0 184 | }; 185 | 186 | /** 187 | * @note Example of a non-CEA TFT panel (7" TFT).
188 | * Resolution 800x600 @ 60Hz. This resolution can be generated directly by RA8876 alone. 189 | */ 190 | const LCDParam AT080TN52 = 191 | { "Innolux AT080TN52", 192 | 800, 600, 193 | 256, //h blanking total 194 | 210, //h front porch 195 | 8, //h pulse width 196 | 35, //v blanking total 197 | 12, //v front porch 198 | 8, //v pulse width 199 | 40, //pclk 200 | 0, //-ve vsync 201 | 0, //-ve hsync 202 | 1, //falling edge pclk 203 | 0 204 | }; 205 | 206 | /** 207 | * @note Example of a non-CEA TFT panel (Common 4.3" WQVGA TFT of 480*272 RGB).
208 | * Resolution 480x272 @ 60Hz. This resolution can be generated directly by RA8876 alone. 209 | */ 210 | const LCDParam WQVGA_480x272_60Hz = 211 | { 212 | "WQVGA 480x272 TFT", 213 | 480, 272, 214 | 45, //h blanking 215 | 2, //h front porch 216 | 41, //h pulse width 217 | 14, //v blanking 218 | 2, //v front porch 219 | 10, //v pulse width 220 | 9, //9MHz pixel clock 221 | 0, //-ve vsync 222 | 0, //-ve hsync 223 | 0, //rising edge pclk 224 | 0, //+ve de 225 | }; 226 | 227 | /** 228 | * @note Example of a non-CEA TFT panel (7" TFT).
229 | * Resolution 800x480 @ 60Hz. This resolution can be generated directly by RA8876 alone. 230 | * Reference: NewHaven 5" 800xRGBx480 TFT (NHD-5.0-800480TF-ATXI#) 231 | */ 232 | const LCDParam WVGA_800x480_60Hz = 233 | { 234 | "WVGA 800x480 TFT", 235 | 800, 480, 236 | 128, //h blanking total 237 | 40, //h front porch 238 | 48, //h pulse width 239 | 45, //v blanking 240 | 13, //v front porch 241 | 3, //v pulse width 242 | 30, //30Mhz pclk 243 | 0, //-ve vsync 244 | 0, //-ve hsync 245 | 0, //rising edge pclk 246 | 0, //+ve de 247 | }; 248 | 249 | /** 250 | * @note VESA compliance 1024x768 @60Hz frame rate.
251 | * Resolution 1024x768 @ 60Hz. This resolution can be generated directly by RA8876 alone. 252 | */ 253 | const LCDParam VESA_1024x768_60Hz = 254 | { 255 | "VESA 1024x768 @ 60Hz", 256 | 1024, 768, 257 | 320, //h blanking 258 | 24, //h front porch 259 | 136, //h pulse width 260 | 38, //v blanking 261 | 3, //v front porch 262 | 6, //v pulse width 263 | 65, //65MHz pixel clk 264 | 0, //-ve vsync 265 | 0, //-ve hsync 266 | 0, //rising edge pclk 267 | 0 //+ve de 268 | }; 269 | 270 | /** 271 | * @note VESA compliance 1366x768 @60Hz frame rate.
272 | * This resolution can be generated directly by RA8876 alone. 273 | */ 274 | const LCDParam VESA_1366x768_60Hz = 275 | { 276 | "VESA 1366x768 @ 60Hz", 277 | 1366, 768, 278 | 194, //h blanking 279 | 32, //h front porch 280 | 64, //h pulse width 281 | 38, //v blanking 282 | 6, //v front porch 283 | 12, //v pulse width 284 | 75, //75MHz pixel clk 285 | 0, //-ve vsync 286 | 0, //-ve hsync 287 | 0, //rising edge pclk 288 | 0 //+ve de 289 | }; 290 | 291 | /** 292 | * @note VESA SVGA 800x600 @ 60Hz
293 | */ 294 | const LCDParam SVGA_800x600_60Hz = 295 | { "VESA 800x600 @ 60Hz", 296 | 800, 600, 297 | 256, //h blanking total 298 | 40, //h front porch 299 | 128, //h pulse width 300 | 28, //v blanking total 301 | 1, //v front porch 302 | 4, //v pulse width 303 | 40, //pclk 304 | 1, //+ve vsync 305 | 1, //+ve hsync 306 | 0, //rising edge pclk 307 | 0 308 | }; 309 | 310 | /** 311 | * @note VESA FWVGA 848x480 @ 60Hz 312 | */ 313 | const LCDParam FWVGA_848x480_60Hz = 314 | { 315 | "VESA FWVGA 848x480 @ 60Hz", 316 | 848, 480, 317 | 240, //h blanking 318 | 16, //h front porch 319 | 112, //h pulse width 320 | 37, //v blanking 321 | 6, //v front porch 322 | 8, //v pulse width 323 | 34, //34Mhz pclk 324 | 1, //+ve vsync 325 | 1, //+ve hsync 326 | 0, //rising edge pclk 327 | 0, //+ve de 328 | }; 329 | 330 | #endif 331 | 332 | 333 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/UserConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Add support for board version 2, for Serial Flash 128Mbit. Directive is : #define BOARD_VERSION_2 3 | * Date: 2019-08-10 4 | */ 5 | 6 | /** 7 | * Add support for RA8876M with 64Mbit RAM 8 | * Date: 2021-06-11 9 | * Add #ifdef RA8876M...#endif in UserConfig.h 10 | */ 11 | 12 | ////#define RA8876M 13 | 14 | #ifndef _USER_CONFIG_H 15 | #define _USER_CONFIG_H 16 | 17 | /** 18 | * @note This option allows debug information for RA8876 print-out via Serial Monitor (Arduino)
19 | * Pre-requisite : printf(args) should be available to use it. 20 | */ 21 | #define DEBUG_LLD_RA8876 22 | 23 | /** 24 | * @note Use font rendering functions with *.c or *.bin files created by BitFontCreator 25 | */ 26 | #define LOAD_BFC_FONT 27 | 28 | /** 29 | * @note Legacy Arduino SD library. This required for BitFontCreator fonts. 30 | * Use either the legacy Arduino library 31 | */ 32 | #define LOAD_SD_LIBRARY 33 | //#define LOAD_SDFAT_LIBRARY //SdFat not supported yet 34 | 35 | 36 | ///@note This option allows debug information for memory module (SDRAM) from Serial Monitor(Arduino) when Allegro is used. 37 | //#define DEBUG_LLD_MEMORY 38 | 39 | #define BOARD_VERSION_2 40 | 41 | #if defined (TEENSYDUINO) 42 | const int RA8876_XNSCS = 20; 43 | const int RA8876_XNRESET = 8; 44 | const int RA8876_MOSI = 7; 45 | const int RA8876_MISO = 12; 46 | const int RA8876_SCK = 14; 47 | const int SDCARD_CS_PIN = 10; 48 | const int SDCARD_MOSI_PIN = RA8876_MOSI; 49 | const int SDCARD_SCK_PIN = RA8876_SCK; 50 | const int RA8876_XNINTR = 2; 51 | #elif defined (ESP8266) 52 | const int RA8876_XNSCS = 15; 53 | const int RA8876_XNRESET = 16; 54 | const int RA8876_MOSI = 13; 55 | const int RA8876_MISO = 12; 56 | const int RA8876_SCK = 14; 57 | const int SDCARD_CS_PIN = 2; 58 | const int SDCARD_MOSI_PIN = RA8876_MOSI; 59 | const int SDCARD_SCK_PIN = RA8876_SCK; 60 | const int RA8876_XNINTR = 0; 61 | #elif defined (ESP32) 62 | const int RA8876_XNSCS = 5; 63 | const int RA8876_XNRESET = 10; 64 | const int RA8876_MOSI = 23; 65 | const int RA8876_MISO = 19; 66 | const int RA8876_SCK = 18; 67 | const int RA8876_XNINTR = 35; //GPIO35 is an input pin, good for interrupt pin here 68 | 69 | const int SDCARD_CS_PIN = 15; //SD_CS on HSPI CS=15 70 | const int SDCARD_MOSI_PIN = 13; //HSPI MOSI 71 | const int SDCARD_MISO_PIN = 4; //Don't use HSPI's native MISO (12) otherwise boot problem. 72 | const int SDCARD_SCK_PIN = 14; //HSPI SCK 73 | 74 | const int CH7035_SDA = 32; 75 | const int CH7035_SCL = 33; 76 | #else 77 | //Arduino Due, M0, or Arduino 101 78 | const int RA8876_XNSCS = 10; 79 | const int RA8876_XNRESET = 8; 80 | const int RA8876_MOSI = 11; 81 | const int RA8876_MISO = 12; 82 | const int RA8876_SCK = 13; 83 | const int SDCARD_CS_PIN = 4; 84 | const int SDCARD_MOSI_PIN = RA8876_MOSI; 85 | const int SDCARD_SCK_PIN = RA8876_SCK; 86 | const int RA8876_XNINTR = 3; 87 | #endif 88 | 89 | 90 | #endif //_USER_CONFIG_H 91 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/bfc/bfcFontMgr.c: -------------------------------------------------------------------------------- 1 | #include "bfcFontMgr.h" 2 | 3 | /** 4 | * @brief Return font's bits-per-pixel 5 | * @param FontType is defined in bfcfont.h 6 | * @return bits-per-pixel in values 1,2,4, or 8. If FontType is not valid, -1 is returned 7 | */ 8 | int GetFontBpp(unsigned long FontType) 9 | { 10 | // bits per pixel 11 | int bpp = -1; 12 | 13 | switch(FontType & 0xFF) 14 | { 15 | case FONTTYPE_MONO: 16 | case FONTTYPE_PROP: 17 | bpp = 1; 18 | break; 19 | case FONTTYPE_MONO_AA2: 20 | case FONTTYPE_PROP_AA2: 21 | bpp = 2; 22 | break; 23 | case FONTTYPE_MONO_AA4: 24 | case FONTTYPE_PROP_AA4: 25 | bpp = 4; 26 | break; 27 | case FONTTYPE_MONO_AA8: 28 | case FONTTYPE_PROP_AA8: 29 | bpp = 8; 30 | break; 31 | } 32 | 33 | return bpp; 34 | } 35 | 36 | /** 37 | * @brief Return font's endianness 38 | * @param FontType is defined in bfcfont.h 39 | * @return 0: Big Endian (default), 1: Little Endian 40 | */ 41 | int GetFontEndian(unsigned long FontType) 42 | { 43 | // 0: Big Endian (default) 44 | // 1: Little Endian 45 | int endian = (FontType & BFC_LITTLE_ENDIAN) > 0 ? 1 : 0; 46 | 47 | return endian; 48 | } 49 | 50 | /** 51 | * @brief Return font's byte arrangement either in Row or Column 52 | * @param FontType is defined in bfcfont.h 53 | * @return 0: Row (default), 1: Column 54 | * @note This function is not used yet.
55 | * Please fix font generation data format to Big Endian, Row based, Row preferred, Unpacked in BitFontCreator 56 | */ 57 | int GetFontScanBase(unsigned long FontType) 58 | { 59 | // 0: Row (default) 60 | // 1: Column 61 | int scanBase = (FontType & COLUMN_BASED) > 0 ? 1 : 0; 62 | 63 | return scanBase; 64 | } 65 | 66 | 67 | int GetFontScanPrefer(unsigned long FontType) 68 | { 69 | // 0: Row (default) 70 | // 1: Column 71 | int scanPrefer = (FontType & COLUMN_PREFERRED) > 0 ? 1 : 0; 72 | 73 | return scanPrefer; 74 | } 75 | 76 | int GetFontDataPack(unsigned long FontType) 77 | { 78 | // 0: No (default) 79 | // 1: Yes 80 | int dataPack = (FontType & DATA_PACKED) > 0 ? 1 : 0; 81 | 82 | return dataPack; 83 | } 84 | 85 | int GetFontHeight(const BFC_FONT *pFont) 86 | { 87 | int height = -1; 88 | 89 | if(pFont != 0) 90 | height = pFont->FontHeight; 91 | 92 | return height; 93 | } 94 | 95 | const BFC_CHARINFO* GetCharInfo(const BFC_FONT *pFont, unsigned short ch) 96 | { 97 | const BFC_CHARINFO *pCharInfo = 0; 98 | const BFC_FONT_PROP *pProp = pFont->p.pProp; 99 | unsigned short first_char, last_char; 100 | 101 | if(pFont == 0 || pFont->p.pProp == 0) 102 | return 0; 103 | 104 | while(pProp != 0) 105 | { 106 | first_char = pProp->FirstChar; 107 | last_char = pProp->LastChar; 108 | pCharInfo = pProp->pFirstCharInfo; 109 | 110 | if( ch >= first_char && ch <= last_char ) 111 | { 112 | // the character "ch" is inside this range, 113 | // return this char info, and not search anymore. 114 | pCharInfo = pCharInfo + (ch - first_char); 115 | return pCharInfo; 116 | } 117 | else 118 | { 119 | // the character "ch" is not in this range 120 | // so search it in the next range 121 | pProp = pProp->pNextProp; 122 | } 123 | } 124 | 125 | // if the character "ch" is not rendered in this font, 126 | // we use the first character in this font as the default one. 127 | if( pCharInfo == 0 ) 128 | { 129 | pProp = pFont->p.pProp; 130 | pCharInfo = pProp->pFirstCharInfo; 131 | } 132 | 133 | return pCharInfo; 134 | } 135 | 136 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/bfc/bfcFontMgr.h: -------------------------------------------------------------------------------- 1 | #ifndef _BFC_FONT_MGR_H 2 | #define _BFC_FONT_MGR_H 3 | 4 | #include "bfcfont.h" 5 | 6 | #if defined(__cplusplus) 7 | extern "C" { /* Make sure we have C-declarations in C++ programs */ 8 | #endif 9 | 10 | // bpp: 1, 2, 4 or 8 (bits per pixel) 11 | int GetFontBpp(unsigned long FontType); 12 | // bit order: 0 (Big Endian), or 1 (Little Endian) 13 | int GetFontEndian(unsigned long FontType); 14 | // scan based: 0 (row), or 1 (column) 15 | int GetFontScanBase(unsigned long FontType); 16 | // scan prfered: 0 (row), or 1 (column) 17 | int GetFontScanPrefer(unsigned long FontType); 18 | // data packed: 0 (No), or 1 (Yes) 19 | int GetFontDataPack(unsigned long FontType); 20 | // return font height in pixels 21 | int GetFontHeight(const BFC_FONT *pFont); 22 | // get structure BFC_CHARINFO pointer 23 | const BFC_CHARINFO* GetCharInfo(const BFC_FONT *pFont, unsigned short ch); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | #endif //_BFC_FONT_MGR_H 29 | 30 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/bfc/bfcfont.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * * 3 | * bfcfont.h -- Basic Type Definitions * 4 | * * 5 | * Copyright (c) 2012, Iseatech Software. All rights reserved. * 6 | * website: http://www.iseasoft.com/bfc.htm * 7 | * email: support@iseatech.com * 8 | * * 9 | ***************************************************************************** 10 | * * 11 | * @file bfcfont.h * 12 | * @version 0.3.1.0 * 13 | * @date Mar-28-2016 * 14 | * @brief BitFontCreator (Pro & Grayscale) font header include file * 15 | * * 16 | *****************************************************************************/ 17 | 18 | /** 19 | * LITTLE_ENDIAN -> BFC_LITTLE_ENDIAN for Arduino 20 | * Please fix font generation data format to Big Endian, Row based, Row preferred, Unpacked in BitFontCreator 21 | * Useful tool online: 22 | * //(1) is an online language translator 23 | * (1) https://www.google.com.hk/search?q=online+chinese+to+english+dictionary&oq=online+chinese+to+english+dictionary&gs_l=psy-ab.12...0.0.0.625904.0.0.0.0.0.0.0.0..0.0....0...1..64.psy-ab..0.0.0....0.TZ9ummyxy0g 24 | * //(2) is a unicode generator tool 25 | * (2) http://mylanguages.org/converter.php 26 | */ 27 | 28 | #ifndef _BFC_FONT_H_ 29 | #define _BFC_FONT_H_ 30 | 31 | #define UCHAR unsigned char 32 | #define USHORT unsigned short 33 | #define ULONG unsigned long 34 | 35 | #define FONTTYPE_MONO (1<<0) /* Is monospaced font */ 36 | #define FONTTYPE_PROP (1<<1) /* Is proportional font */ 37 | #define FONTTYPE_MONO_AA2 (1<<2) /* Is an antialiased mono font, 2bpp */ 38 | #define FONTTYPE_MONO_AA4 (1<<3) /* Is an antialiased mono font, 4bpp */ 39 | #define FONTTYPE_MONO_AA8 (1<<4) /* Is an antialiased mono font, 8bpp */ 40 | #define FONTTYPE_PROP_AA2 (1<<5) /* Is an antialiased prop font, 2bpp */ 41 | #define FONTTYPE_PROP_AA4 (1<<6) /* Is an antialiased prop font, 4bpp */ 42 | #define FONTTYPE_PROP_AA8 (1<<7) /* Is an antialiased prop font, 8bpp */ 43 | 44 | /************************************************************************************ 45 | * the following 4 flags is added since Pro v3.7 & Grayscale v4.5 on 2016-03-28 * 46 | *************************************************************************************/ 47 | #define BFC_LITTLE_ENDIAN (1<<8) /* Is Little Endian if set, or is Big Endian (default) */ 48 | #define COLUMN_BASED (1<<9) /* Is Column if set, or is Row (default) */ 49 | #define COLUMN_PREFERRED (1<<10) /* Is Column if set, or is Row (default) */ 50 | #define DATA_PACKED (1<<11) /* Is Packed if set, or is Unpacked (default) */ 51 | 52 | #define ENCODING_ASCII (1<<16) /* Character encoding: Ascii + ISO8859 */ 53 | #define ENCODING_UNICODE (1<<17) /* Character encoding: Unicode */ 54 | #define ENCODING_SHIFTJIS (1<<18) /* Character encoding: Shift_JIS */ 55 | #define ENCODING_BIG5 (1<<19) /* Character encoding: Big5 */ 56 | #define ENCODING_GBK (1<<20) /* Character encoding: GBK */ 57 | #define ENCODING_JOHAB (1<<21) /* Character encoding: Johab */ 58 | 59 | #define DATALENGTH_8 (1<<24) /* Data length: 8 bits per unit (1 byte) */ 60 | #define DATALENGTH_16 (1<<25) /* Data length: 16 bits per unit (2 bytes) */ 61 | #define DATALENGTH_32 (1<<26) /* Data length: 32 bits per unit (4 bytes) */ 62 | 63 | #if defined(__cplusplus) 64 | extern "C" { /* Make sure we have C-declarations in C++ programs */ 65 | #endif 66 | 67 | /********************************************************************* 68 | * C font structures 69 | **********************************************************************/ 70 | typedef struct BFC_CHARINFO 71 | { 72 | USHORT Width; /* character width in pixels */ 73 | USHORT DataSize; /* # bytes/words/dwords of pixel data */ 74 | union 75 | { 76 | const void *pData; 77 | const UCHAR *pData8; /* pixel data in bytes */ 78 | const USHORT *pData16; /* pixel data in words */ 79 | const ULONG *pData32; /* pixel data in dwords */ 80 | } p; 81 | } BFC_CHARINFO; 82 | 83 | typedef struct BFC_FONT_PROP 84 | { 85 | USHORT FirstChar; /* index of first character */ 86 | USHORT LastChar; /* index of last character */ 87 | const BFC_CHARINFO *pFirstCharInfo; /* address of first character */ 88 | const struct BFC_FONT_PROP *pNextProp; /* pointer to next BFC_FONT_PROP */ 89 | } BFC_FONT_PROP; 90 | 91 | typedef struct BFC_FONT_MONO 92 | { 93 | USHORT FirstChar; /* index of first character */ 94 | USHORT LastChar; /* index of last character */ 95 | USHORT FontWidth; /* font width in pixels */ 96 | USHORT DataSize; /* # bytes/words/dwords data of single character */ 97 | union 98 | { 99 | const void *pData; 100 | const UCHAR *pData8; /* pixel data in bytes */ 101 | const USHORT *pData16; /* pixel data in words */ 102 | const ULONG *pData32; /* pixel data in dwords */ 103 | } p; 104 | } BFC_FONT_MONO; 105 | 106 | typedef struct 107 | { 108 | ULONG FontType; /* font type */ 109 | USHORT FontHeight; /* font height in pixels */ 110 | USHORT Baseline; /* font ascent (baseline) in pixels */ 111 | ULONG Reversed; /* reversed, =0 */ 112 | union 113 | { 114 | const void * pData; 115 | const BFC_FONT_MONO * pMono; /* point to Monospaced font */ 116 | const BFC_FONT_PROP * pProp; /* point to proportional font */ 117 | } p; 118 | } BFC_FONT; 119 | 120 | 121 | /********************************************************************* 122 | * Binary font structures (BIN) 123 | **********************************************************************/ 124 | typedef struct 125 | { 126 | ULONG FontType; /* font type */ 127 | USHORT FontHeight; /* font height in pixels */ 128 | USHORT Baseline; /* font ascent (baseline) in pixels */ 129 | USHORT Reversed; /* reversed, =0 */ 130 | USHORT NumRanges; /* number of character ranges */ 131 | } BFC_BIN_FONT; 132 | 133 | typedef struct 134 | { 135 | USHORT FirstChar; /* index of first character */ 136 | USHORT LastChar; /* index of last charcter */ 137 | } BFC_BIN_CHARRANGE; 138 | 139 | typedef struct 140 | { 141 | USHORT Width; /* character width in pixels */ 142 | USHORT DataSize; /* # bytes/words/dwords of pixel data */ 143 | ULONG OffData; /* Offset of pixel data */ 144 | } BFC_BIN_CHARINFO; 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif //#ifndef _BFC_FONT_H_ -------------------------------------------------------------------------------- /Ra8876_Lite/src/edid/edid.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file edid.c 3 | * @author Soren Sandmann 4 | * @note source: https://people.gnome.org/~ssp/randr/edid.h 5 | * @license 6 | * 7 | * Copyright 2007 Red Hat, Inc. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a 10 | * copy of this software and associated documentation files (the "Software"), 11 | * to deal in the Software without restriction, including without limitation 12 | * on the rights to use, copy, modify, merge, publish, distribute, sub 13 | * license, and/or sell copies of the Software, and to permit persons to whom 14 | * the Software is furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice (including the next 17 | * paragraph) shall be included in all copies or substantial portions of the 18 | * Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 23 | * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #include "edid.h" 29 | #include 30 | #include 31 | #include 32 | 33 | #define TRUE 1 34 | #define FALSE 0 35 | 36 | /** 37 | * @note When no edid information can be fetched from a monitor, 38 | * this is the generic edid array. 39 | */ 40 | const uchar generic_edid[]= 41 | { 42 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 43 | 0x10, 0xac, 0x09, 0xe0, 0x4c, 0x50, 0x55, 0x31, 44 | 0x08, 0x0f, 0x01, 0x03, 0xee, 0x2b, 0x1b, 0x78, 45 | 0xea, 0x01, 0x95, 0xa3, 0x57, 0x4c, 0x9c, 0x25, 46 | 0x12, 0x50, 0x54, 0xa5, 0x4b, 0x00, 0x81, 0x80, 47 | 0x71, 0x4f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 48 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7c, 0x2e, 49 | 0x90, 0xa0, 0x60, 0x1a, 0x1e, 0x40, 0x30, 0x20, 50 | 0x36, 0x00, 0xb2, 0x0e, 0x11, 0x00, 0x00, 0x1a, 51 | 0x00, 0x00, 0x00, 0xff, 0x00, 0x54, 0x36, 0x31, 52 | 0x33, 0x30, 0x35, 0x32, 0x4e, 0x31, 0x55, 0x50, 53 | 0x4c, 0x0a, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x38, 54 | 0x4b, 0x1e, 0x53, 0x0e, 0x00, 0x0a, 0x20, 0x20, 55 | 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 56 | 0x00, 0x44, 0x45, 0x4c, 0x4c, 0x20, 0x32, 0x30, 57 | 0x30, 0x35, 0x46, 0x50, 0x57, 0x0a, 0x00, 0x99, 58 | }; 59 | 60 | static int 61 | get_bit (int in, int bit) 62 | { 63 | return (in & (1 << bit)) >> bit; 64 | } 65 | 66 | static int 67 | get_bits (int in, int begin, int end) 68 | { 69 | int mask = (1 << (end - begin + 1)) - 1; 70 | 71 | return (in >> begin) & mask; 72 | } 73 | 74 | static int 75 | decode_header (const uchar *edid) 76 | { 77 | if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0) 78 | return TRUE; 79 | return FALSE; 80 | } 81 | 82 | static int 83 | decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info) 84 | { 85 | int is_model_year; 86 | 87 | /* Manufacturer Code */ 88 | info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6); 89 | info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3; 90 | info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7); 91 | info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4); 92 | info->manufacturer_code[3] = '\0'; 93 | 94 | info->manufacturer_code[0] += 'A' - 1; 95 | info->manufacturer_code[1] += 'A' - 1; 96 | info->manufacturer_code[2] += 'A' - 1; 97 | 98 | /* Product Code */ 99 | info->product_code = edid[0x0b] << 8 | edid[0x0a]; 100 | 101 | /* Serial Number */ 102 | info->serial_number = 103 | edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24; 104 | 105 | /* Week and Year */ 106 | is_model_year = FALSE; 107 | switch (edid[0x10]) 108 | { 109 | case 0x00: 110 | info->production_week = -1; 111 | break; 112 | 113 | case 0xff: 114 | info->production_week = -1; 115 | is_model_year = TRUE; 116 | break; 117 | 118 | default: 119 | info->production_week = edid[0x10]; 120 | break; 121 | } 122 | 123 | if (is_model_year) 124 | { 125 | info->production_year = -1; 126 | info->model_year = 1990 + edid[0x11]; 127 | } 128 | else 129 | { 130 | info->production_year = 1990 + edid[0x11]; 131 | info->model_year = -1; 132 | } 133 | 134 | return TRUE; 135 | } 136 | 137 | static int 138 | decode_edid_version (const uchar *edid, MonitorInfo *info) 139 | { 140 | info->major_version = edid[0x12]; 141 | info->minor_version = edid[0x13]; 142 | 143 | return TRUE; 144 | } 145 | 146 | static int 147 | decode_display_parameters (const uchar *edid, MonitorInfo *info) 148 | { 149 | /* Digital vs Analog */ 150 | info->is_digital = get_bit (edid[0x14], 7); 151 | 152 | if (info->is_digital) 153 | { 154 | int bits; 155 | 156 | static const int bit_depth[8] = 157 | { 158 | -1, 6, 8, 10, 12, 14, 16, -1 159 | }; 160 | 161 | static const Interface interfaces[6] = 162 | { 163 | UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT 164 | }; 165 | 166 | bits = get_bits (edid[0x14], 4, 6); 167 | info->digital.bits_per_primary = bit_depth[bits]; 168 | 169 | bits = get_bits (edid[0x14], 0, 3); 170 | 171 | if (bits <= 5) 172 | info->digital.interface = interfaces[bits]; 173 | else 174 | info->digital.interface = UNDEFINED; 175 | } 176 | else 177 | { 178 | int bits = get_bits (edid[0x14], 5, 6); 179 | 180 | static const double levels[][3] = 181 | { 182 | { 0.7, 0.3, 1.0 }, 183 | { 0.714, 0.286, 1.0 }, 184 | { 1.0, 0.4, 1.4 }, 185 | { 0.7, 0.0, 0.7 }, 186 | }; 187 | 188 | info->analog.video_signal_level = levels[bits][0]; 189 | info->analog.sync_signal_level = levels[bits][1]; 190 | info->analog.total_signal_level = levels[bits][2]; 191 | 192 | info->analog.blank_to_black = get_bit (edid[0x14], 4); 193 | 194 | info->analog.separate_hv_sync = get_bit (edid[0x14], 3); 195 | info->analog.composite_sync_on_h = get_bit (edid[0x14], 2); 196 | info->analog.composite_sync_on_green = get_bit (edid[0x14], 1); 197 | 198 | info->analog.serration_on_vsync = get_bit (edid[0x14], 0); 199 | } 200 | 201 | /* Screen Size / Aspect Ratio */ 202 | if (edid[0x15] == 0 && edid[0x16] == 0) 203 | { 204 | info->width_mm = -1; 205 | info->height_mm = -1; 206 | info->aspect_ratio = -1.0; 207 | } 208 | else if (edid[0x16] == 0) 209 | { 210 | info->width_mm = -1; 211 | info->height_mm = -1; 212 | info->aspect_ratio = 100.0 / (edid[0x15] + 99); 213 | } 214 | else if (edid[0x15] == 0) 215 | { 216 | info->width_mm = -1; 217 | info->height_mm = -1; 218 | info->aspect_ratio = 100.0 / (edid[0x16] + 99); 219 | info->aspect_ratio = 1/info->aspect_ratio; /* portrait */ 220 | } 221 | else 222 | { 223 | info->width_mm = 10 * edid[0x15]; 224 | info->height_mm = 10 * edid[0x16]; 225 | } 226 | 227 | /* Gamma */ 228 | if (edid[0x17] == 0xFF) 229 | info->gamma = -1.0; 230 | else 231 | info->gamma = (edid[0x17] + 100.0) / 100.0; 232 | 233 | /* Features */ 234 | info->standby = get_bit (edid[0x18], 7); 235 | info->suspend = get_bit (edid[0x18], 6); 236 | info->active_off = get_bit (edid[0x18], 5); 237 | 238 | if (info->is_digital) 239 | { 240 | info->digital.rgb444 = TRUE; 241 | if (get_bit (edid[0x18], 3)) 242 | info->digital.ycrcb444 = 1; 243 | if (get_bit (edid[0x18], 4)) 244 | info->digital.ycrcb422 = 1; 245 | } 246 | else 247 | { 248 | int bits = get_bits (edid[0x18], 3, 4); 249 | ColorType color_type[4] = 250 | { 251 | MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR 252 | }; 253 | 254 | info->analog.color_type = color_type[bits]; 255 | } 256 | 257 | info->srgb_is_standard = get_bit (edid[0x18], 2); 258 | 259 | /* In 1.3 this is called "has preferred timing" */ 260 | info->preferred_timing_includes_native = get_bit (edid[0x18], 1); 261 | 262 | /* FIXME: In 1.3 this indicates whether the monitor accepts GTF */ 263 | info->continuous_frequency = get_bit (edid[0x18], 0); 264 | return TRUE; 265 | } 266 | 267 | static double 268 | decode_fraction (int high, int low) 269 | { 270 | double result = 0.0; 271 | int i; 272 | 273 | high = (high << 2) | low; 274 | 275 | for (i = 0; i < 10; ++i) 276 | result += get_bit (high, i) * pow (2, i - 10); 277 | 278 | return result; 279 | } 280 | 281 | static int 282 | decode_color_characteristics (const uchar *edid, MonitorInfo *info) 283 | { 284 | info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7)); 285 | info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4)); 286 | info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3)); 287 | info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1)); 288 | info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7)); 289 | info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5)); 290 | info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3)); 291 | info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1)); 292 | 293 | return TRUE; 294 | } 295 | 296 | static int 297 | decode_established_timings (const uchar *edid, MonitorInfo *info) 298 | { 299 | static const Timing established[][8] = 300 | { 301 | { 302 | { 800, 600, 60 }, 303 | { 800, 600, 56 }, 304 | { 640, 480, 75 }, 305 | { 640, 480, 72 }, 306 | { 640, 480, 67 }, 307 | { 640, 480, 60 }, 308 | { 720, 400, 88 }, 309 | { 720, 400, 70 } 310 | }, 311 | { 312 | { 1280, 1024, 75 }, 313 | { 1024, 768, 75 }, 314 | { 1024, 768, 70 }, 315 | { 1024, 768, 60 }, 316 | { 1024, 768, 87 }, 317 | { 832, 624, 75 }, 318 | { 800, 600, 75 }, 319 | { 800, 600, 72 } 320 | }, 321 | { 322 | { 0, 0, 0 }, 323 | { 0, 0, 0 }, 324 | { 0, 0, 0 }, 325 | { 0, 0, 0 }, 326 | { 0, 0, 0 }, 327 | { 0, 0, 0 }, 328 | { 0, 0, 0 }, 329 | { 1152, 870, 75 } 330 | }, 331 | }; 332 | 333 | int i, j, idx; 334 | 335 | idx = 0; 336 | for (i = 0; i < 3; ++i) 337 | { 338 | for (j = 0; j < 8; ++j) 339 | { 340 | int byte = edid[0x23 + i]; 341 | 342 | if (get_bit (byte, j) && established[i][j].frequency != 0) 343 | info->established[idx++] = established[i][j]; 344 | } 345 | } 346 | return TRUE; 347 | } 348 | 349 | static int 350 | decode_standard_timings (const uchar *edid, MonitorInfo *info) 351 | { 352 | int i; 353 | 354 | for (i = 0; i < 8; i++) 355 | { 356 | int first = edid[0x26 + 2 * i]; 357 | int second = edid[0x27 + 2 * i]; 358 | 359 | if (first != 0x01 && second != 0x01) 360 | { 361 | int w = 8 * (first + 31); 362 | int h; 363 | 364 | switch (get_bits (second, 6, 7)) 365 | { 366 | case 0x00: h = (w / 16) * 10; break; 367 | case 0x01: h = (w / 4) * 3; break; 368 | case 0x02: h = (w / 5) * 4; break; 369 | case 0x03: h = (w / 16) * 9; break; 370 | } 371 | 372 | info->standard[i].width = w; 373 | info->standard[i].height = h; 374 | info->standard[i].frequency = get_bits (second, 0, 5) + 60; 375 | } 376 | } 377 | 378 | return TRUE; 379 | } 380 | 381 | static void 382 | decode_lf_string (const uchar *s, int n_chars, char *result) 383 | { 384 | int i; 385 | for (i = 0; i < n_chars; ++i) 386 | { 387 | if (s[i] == 0x0a) 388 | { 389 | *result++ = '\0'; 390 | break; 391 | } 392 | else if (s[i] == 0x00) 393 | { 394 | /* Convert embedded 0's to spaces */ 395 | *result++ = ' '; 396 | } 397 | else 398 | { 399 | *result++ = s[i]; 400 | } 401 | } 402 | } 403 | 404 | static void 405 | decode_display_descriptor (const uchar *desc, 406 | MonitorInfo *info) 407 | { 408 | switch (desc[0x03]) 409 | { 410 | case 0xFC: 411 | decode_lf_string (desc + 5, 13, info->dsc_product_name); 412 | break; 413 | case 0xFF: 414 | decode_lf_string (desc + 5, 13, info->dsc_serial_number); 415 | break; 416 | case 0xFE: 417 | decode_lf_string (desc + 5, 13, info->dsc_string); 418 | break; 419 | case 0xFD: 420 | /* Range Limits */ 421 | break; 422 | case 0xFB: 423 | /* Color Point */ 424 | break; 425 | case 0xFA: 426 | /* Timing Identifications */ 427 | break; 428 | case 0xF9: 429 | /* Color Management */ 430 | break; 431 | case 0xF8: 432 | /* Timing Codes */ 433 | break; 434 | case 0xF7: 435 | /* Established Timings */ 436 | break; 437 | case 0x10: 438 | break; 439 | } 440 | } 441 | 442 | static void 443 | decode_detailed_timing (const uchar *timing, 444 | DetailedTiming *detailed) 445 | { 446 | int bits; 447 | StereoType stereo[] = 448 | { 449 | NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT, 450 | TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN, 451 | FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE 452 | }; 453 | 454 | detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000; 455 | detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4); 456 | detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8); 457 | detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4); 458 | detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8); 459 | detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8; 460 | detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8; 461 | detailed->v_front_porch = 462 | get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4; 463 | detailed->v_sync = 464 | get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4; 465 | detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8; 466 | detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8; 467 | detailed->right_border = timing[0x0f]; 468 | detailed->top_border = timing[0x10]; 469 | 470 | detailed->interlaced = get_bit (timing[0x11], 7); 471 | 472 | /* Stereo */ 473 | bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0); 474 | detailed->stereo = stereo[bits]; 475 | 476 | /* Sync */ 477 | bits = timing[0x11]; 478 | 479 | detailed->digital_sync = get_bit (bits, 4); 480 | if (detailed->digital_sync) 481 | { 482 | detailed->digital.composite = !get_bit (bits, 3); 483 | 484 | if (detailed->digital.composite) 485 | { 486 | detailed->digital.serrations = get_bit (bits, 2); 487 | detailed->digital.negative_vsync = FALSE; 488 | } 489 | else 490 | { 491 | detailed->digital.serrations = FALSE; 492 | detailed->digital.negative_vsync = !get_bit (bits, 2); 493 | } 494 | 495 | detailed->digital.negative_hsync = !get_bit (bits, 0); 496 | } 497 | else 498 | { 499 | detailed->analog.bipolar = get_bit (bits, 3); 500 | detailed->analog.serrations = get_bit (bits, 2); 501 | detailed->analog.sync_on_green = !get_bit (bits, 1); 502 | } 503 | } 504 | 505 | static int 506 | decode_descriptors (const uchar *edid, MonitorInfo *info) 507 | { 508 | int i; 509 | int timing_idx; 510 | 511 | timing_idx = 0; 512 | 513 | for (i = 0; i < 4; ++i) 514 | { 515 | int index = 0x36 + i * 18; 516 | 517 | if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00) 518 | { 519 | decode_display_descriptor (edid + index, info); 520 | } 521 | else 522 | { 523 | decode_detailed_timing ( 524 | edid + index, &(info->detailed_timings[timing_idx++])); 525 | } 526 | } 527 | 528 | info->n_detailed_timings = timing_idx; 529 | 530 | return TRUE; 531 | } 532 | 533 | static void 534 | decode_check_sum (const uchar *edid, 535 | MonitorInfo *info) 536 | { 537 | int i; 538 | uchar check = 0; 539 | 540 | for (i = 0; i < 128; ++i) 541 | check += edid[i]; 542 | 543 | info->checksum = check; 544 | } 545 | 546 | MonitorInfo * 547 | decode_edid (const uchar *edid) 548 | { 549 | MonitorInfo *info = calloc (1, sizeof (MonitorInfo)); 550 | 551 | decode_check_sum (edid, info); 552 | 553 | if (!decode_header (edid)) 554 | return NULL; 555 | 556 | if (!decode_vendor_and_product_identification (edid, info)) 557 | return NULL; 558 | 559 | if (!decode_edid_version (edid, info)) 560 | return NULL; 561 | 562 | if (!decode_display_parameters (edid, info)) 563 | return NULL; 564 | 565 | if (!decode_color_characteristics (edid, info)) 566 | return NULL; 567 | 568 | if (!decode_established_timings (edid, info)) 569 | return NULL; 570 | 571 | if (!decode_standard_timings (edid, info)) 572 | return NULL; 573 | 574 | if (!decode_descriptors (edid, info)) 575 | return NULL; 576 | 577 | return info; 578 | } 579 | 580 | 581 | 582 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/edid/edid.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file edid.h 3 | * @author Soren Sandmann 4 | * @note source: https://people.gnome.org/~ssp/randr/edid.h 5 | * @license 6 | * 7 | * Copyright 2007 Red Hat, Inc. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a 10 | * copy of this software and associated documentation files (the "Software"), 11 | * to deal in the Software without restriction, including without limitation 12 | * on the rights to use, copy, modify, merge, publish, distribute, sub 13 | * license, and/or sell copies of the Software, and to permit persons to whom 14 | * the Software is furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice (including the next 17 | * paragraph) shall be included in all copies or substantial portions of the 18 | * Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 23 | * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef __EDID_H 29 | #define __EDID_H 30 | 31 | #ifdef __cplusplus 32 | extern "C"{ 33 | #endif 34 | 35 | typedef unsigned char uchar; 36 | typedef struct MonitorInfo MonitorInfo; 37 | typedef struct Timing Timing; 38 | typedef struct DetailedTiming DetailedTiming; 39 | 40 | /** 41 | * @note When no edid information can be fetched from a monitor, 42 | * this is the generic edid array. 43 | */ 44 | extern const uchar generic_edid[]; 45 | 46 | typedef enum 47 | { 48 | UNDEFINED, 49 | DVI, 50 | HDMI_A, 51 | HDMI_B, 52 | MDDI, 53 | DISPLAY_PORT 54 | } Interface; 55 | 56 | typedef enum 57 | { 58 | UNDEFINED_COLOR, 59 | MONOCHROME, 60 | RGB, 61 | OTHER_COLOR 62 | } ColorType; 63 | 64 | typedef enum 65 | { 66 | NO_STEREO, 67 | FIELD_RIGHT, 68 | FIELD_LEFT, 69 | TWO_WAY_RIGHT_ON_EVEN, 70 | TWO_WAY_LEFT_ON_EVEN, 71 | FOUR_WAY_INTERLEAVED, 72 | SIDE_BY_SIDE 73 | } StereoType; 74 | 75 | struct Timing 76 | { 77 | int width; 78 | int height; 79 | int frequency; 80 | }; 81 | 82 | struct DisplayDescriptor 83 | { 84 | }; 85 | 86 | struct DetailedTiming 87 | { 88 | int pixel_clock; 89 | int h_addr; 90 | int h_blank; 91 | int h_sync; 92 | int h_front_porch; 93 | int v_addr; 94 | int v_blank; 95 | int v_sync; 96 | int v_front_porch; 97 | int width_mm; 98 | int height_mm; 99 | int right_border; 100 | int top_border; 101 | int interlaced; 102 | StereoType stereo; 103 | 104 | int digital_sync; 105 | union 106 | { 107 | struct 108 | { 109 | int bipolar; 110 | int serrations; 111 | int sync_on_green; 112 | } analog; 113 | 114 | struct 115 | { 116 | int composite; 117 | int serrations; 118 | int negative_vsync; 119 | int negative_hsync; 120 | } digital; 121 | }; 122 | }; 123 | 124 | struct MonitorInfo 125 | { 126 | int checksum; 127 | char manufacturer_code[4]; 128 | int product_code; 129 | unsigned int serial_number; 130 | 131 | int production_week; /* -1 if not specified */ 132 | int production_year; /* -1 if not specified */ 133 | int model_year; /* -1 if not specified */ 134 | 135 | int major_version; 136 | int minor_version; 137 | 138 | int is_digital; 139 | 140 | union 141 | { 142 | struct 143 | { 144 | int bits_per_primary; 145 | Interface interface; 146 | int rgb444; 147 | int ycrcb444; 148 | int ycrcb422; 149 | } digital; 150 | 151 | struct 152 | { 153 | double video_signal_level; 154 | double sync_signal_level; 155 | double total_signal_level; 156 | 157 | int blank_to_black; 158 | 159 | int separate_hv_sync; 160 | int composite_sync_on_h; 161 | int composite_sync_on_green; 162 | int serration_on_vsync; 163 | ColorType color_type; 164 | } analog; 165 | }; 166 | 167 | int width_mm; /* -1 if not specified */ 168 | int height_mm; /* -1 if not specified */ 169 | double aspect_ratio; /* -1.0 if not specififed */ 170 | 171 | double gamma; /* -1.0 if not specified */ 172 | 173 | int standby; 174 | int suspend; 175 | int active_off; 176 | 177 | int srgb_is_standard; 178 | int preferred_timing_includes_native; 179 | int continuous_frequency; 180 | 181 | double red_x; 182 | double red_y; 183 | double green_x; 184 | double green_y; 185 | double blue_x; 186 | double blue_y; 187 | double white_x; 188 | double white_y; 189 | 190 | Timing established[24]; /* Terminated by 0x0x0 */ 191 | Timing standard[8]; 192 | 193 | int n_detailed_timings; 194 | DetailedTiming detailed_timings[4]; /* If monitor has a preferred 195 | * mode, it is the first one 196 | * (whether it has, is 197 | * determined by the 198 | * preferred_timing_includes 199 | * bit. 200 | */ 201 | 202 | /* Optional product description */ 203 | char dsc_serial_number[14]; 204 | char dsc_product_name[14]; 205 | char dsc_string[14]; /* Unspecified ASCII data */ 206 | }; 207 | 208 | MonitorInfo *decode_edid (const uchar *data); 209 | char * make_display_name (const char *output_name, const MonitorInfo *info); 210 | 211 | #ifdef __cplusplus 212 | } 213 | #endif 214 | 215 | #endif //__EDID_H 216 | 217 | 218 | -------------------------------------------------------------------------------- /Ra8876_Lite/src/hw_font/hw_font.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief RA8876 have three text sources; they are Embedded Characters built-in RA8876, 3 | * External Character ROM, and User-defined Characters. 4 | * (1) Embedded Characters: ROM-based 8x16, 12x24, 16x32 ASCII characters that users 5 | * need only input characters by ASCII code. Coding standards ISO/IEC 8859-1/2/4/5 6 | * are all supported. Because this character set is a ROM-based data, no Flash space is required 7 | * from the host or MCU which is rather expensive to store static data like ASCII code. 8 | * Details can be found from Section 14.1 of RA8876 datasheet. 9 | * This option is enumerated by FONT_SRC as INTERNAL_CGROM below. 10 | * (2) External Character ROM: RA8876 is compatible with External serial ROMs from Genitop Inc. 11 | * Supporting product numbers are GT21L16T1W, GT30L16U2W, GT30L24T3Y, GT30L24M1Z, GT30L32S4W, GT20L24F6Y, and GT21L24S1W. 12 | * According to different products, there are different character’s size including 16x16, 24x24, 32x32, 13 | * and variable width character size in them. Detail functionality description please refers section: 14 | * “External Serial Flash/ROM Interface” in RA8876 datasheet. 15 | * Important : Only footprints for Genitop Font ROM is available. No ROM chip has been soldered. 16 | * Users may choose the appropriate product from Genitop Inc and solder it by himself at designator U33/U34. 17 | * This option is enumerated by FONT_SRC as GENITOP_FONT below. 18 | * (3) User-defined Characters: User can create characters or symbols and then get them stored in SDRAM. 19 | * This mode is not supported by current version. Details can be found under section 14.3 on RA8876 datasheet. 20 | * This option is enumerated by FONT_SRC as CUSTOM_CGRAM below. 21 | */ 22 | 23 | #ifndef _HW_FONT_H 24 | #define _HW_FONT_H 25 | 26 | /** 27 | *@note Enum for three hardware font sources; they are Embedded Characters builtin RA8876, 28 | * External Character ROM, and User-defined Characters. 29 | */ 30 | enum FONT_SRC { 31 | INTERNAL_CGROM =0, //RA8876 embedded Char set 32 | GENITOP_FONT =1, //External CGROM 33 | CUSTOM_CGRAM =2 //User-defined CGRAM 34 | }; 35 | 36 | /** 37 | *@note Enum for character height for hardware fonts, variation subject to source of characters also. 38 | * Details refer RA8876's REG[CCh] 39 | */ 40 | enum FONT_HEIGHT { 41 | CHAR_HEIGHT_16=16, 42 | CHAR_HEIGHT_24=24, 43 | CHAR_HEIGHT_32=32 44 | }; 45 | 46 | 47 | ///@note External character ROM, parameter to be set in REG[CEh] bit7:5 48 | enum GT_FONT_ROM { 49 | FONT_ROM_GT21L16T1W=0, 50 | FONT_ROM_GT30L16U2W=1, 51 | FONT_ROM_GT30L24T3Y=2, 52 | FONT_ROM_GT30L24M1Z=3, 53 | FONT_ROM_GT30L32S4W=4, 54 | FONT_ROM_GT20L24F6Y=5, 55 | FONT_ROM_GT21L24S1W=6 56 | }; 57 | 58 | ///@note Character encoding, parameter to be set in REG[CC] / REG[CF] for Internal Char ROM or External CGROM (Genitop) 59 | enum FONT_CODE { 60 | ICGROM_ISO_8859_1 = 0, //Internal CGROM ISO char code 61 | XCGROM_GB2312 = 0, //Genitop ROM double byte character code 62 | ICGROM_ISO_8859_2 = 1, 63 | XCGROM_GB12345 = 1, 64 | ICGROM_ISO_8859_4 = 2, 65 | XCGROM_BIG5 = 2, 66 | ICGROM_ISO_8859_5 = 3, 67 | XCGROM_UNICODE = 3, 68 | XCGROM_ASCII = 4, //ASCII only from 00h-1Fh, 80-FFh will send "blank space" 69 | XCGROM_UNI_JAPANESE = 5, 70 | XCGROM_JIS0208 = 6, //2-byte character set specified as a Japanese Industrial Standard 71 | XCGROM_LATIN = 7, //Latin, Greek, Cyrillic, Arabic, Thai, Hebrew 72 | XCGROM_ISO_8859_1 = 17, 73 | XCGROM_ISO_8859_2 = 18, 74 | XCGROM_ISO_8859_3 = 19, 75 | XCGROM_ISO_8859_4 = 20, 76 | XCGROM_ISO_8859_5 = 21, 77 | XCGROM_ISO_8859_7 = 22, 78 | XCGROM_ISO_8859_8 = 23, 79 | XCGROM_ISO_8859_9 = 24, 80 | XCGROM_ISO_8859_10= 25, 81 | XCGROM_ISO_8859_11= 26, 82 | XCGROM_ISO_8859_13= 27, 83 | XCGROM_ISO_8859_14= 28, 84 | XCGROM_ISO_8859_15= 29, 85 | XCGROM_ISO_8859_16= 30 86 | }; 87 | 88 | /** 89 | *@note Font background with either SOLID (character's background filled with the background color) or 90 | * TRANSPARENT(the character's background filled with the canvas background) 91 | */ 92 | const bool SOLID = 0; 93 | const bool TRANSPARENT = 1; 94 | 95 | /** 96 | * @note Structure to describe hardware fonts (Embedded Characters and Genitop) 97 | */ 98 | typedef struct HW_FONT{ 99 | const char *name; /* name of font */ 100 | wchar_t FirstChar; /* first character available in ROM (Embedded/Genitop) */ 101 | wchar_t LastChar; /* last character available in ROM (Embedded/Genitop) */ 102 | FONT_SRC FontSource; /* Enum FONT_SRC */ 103 | uint16_t FontWidth; /* Fixed width or zero if it is a variable width */ 104 | uint16_t FontHeight; /* Font height */ 105 | FONT_CODE FontCode; /* Encoding method with enum listing in FONT_CODE above */ 106 | }HW_FONT; 107 | 108 | /************************************************************************************/ 109 | /************************************************************************************/ 110 | /** 111 | * @brief Internal CG ROM character set of 8x16 pixels 112 | */ 113 | const HW_FONT ICGROM_16 = 114 | { 115 | "Internal CG ROM", 116 | 0x00, 117 | 0xff, 118 | FONT_SRC::INTERNAL_CGROM, 119 | 8, 120 | 16, 121 | FONT_CODE::ICGROM_ISO_8859_1 122 | }; 123 | 124 | /** 125 | * @note BIG5 character set in Genitop GT21L16T1W ROM.
126 | * BIG5 code reference : http://ash.jp/code/cn/big5tbl.htm
127 | * Characters of 15x16 dots in the range 0xA140 - 0xC67E.
128 | * Example to display 100 characters from '一' to '世'.
129 | * 130 | * wchar_t wch; 131 | //set printing position starts from (100,100); auto line feed when cursor meets Active Window boundary 132 | ra8876lite.setHwTextCursor(100,100); 133 | ra8876lite.setHwTextColor(color.Black); //set font color black 134 | ra8876lite.setHwTextParam(color.White, 1,1); //set background white, magnification factor 1:1 135 | 136 | for(wch=0xA440; wch<(0xA440+101); wch++) 137 | { 138 | ra8876lite.putHwChar(&XCGROM_BIG5_16, wch); 139 | } 140 | */ 141 | const HW_FONT XCGROM_BIG5_16 = 142 | { 143 | "Genitop BIG5 16", 144 | 0xA140, 145 | 0xC67E, 146 | FONT_SRC::GENITOP_FONT, 147 | 15, 148 | 16, 149 | FONT_CODE::XCGROM_BIG5 150 | }; 151 | 152 | /** 153 | * @note Janpanese JIS0208 character set in Genitop GT21L16T1W ROM.
154 | * JIS0208 Reference: http://charset.7jp.net/jis0208.html.
155 | * JIS code of ぁ is 2421. Its UTF-16 representation is 0x3041.
156 | * Somehow we need to use 0x0401 for 'ぁ'.
157 | * Hex value 0x0401 means to start from 04区 01点 displaying ぁあぃい...for 300 characters.
158 | * 159 | * Example to use to display 300 characters starting from ぁ.
160 | 161 | * wchar_t wch; 162 | //0x0401 means to start from 04区 01点 displaying ぁあぃい...for 300 characters 163 | //print wide characters starting from x=100,y=150 with auto line feed when cursor meets x=canvas width=1280 in this demo 164 | ra8876lite.setHwTextCursor(100,150); 165 | ra8876lite.setHwTextColor(color.White); 166 | ra8876lite.setHwTextParam(color.Black, 1,1); 167 | for(wch=0x0401; wch<(0x0401+301); wch++) 168 | { 169 | ra8876lite.putHwChar(&XCGROM_JIS_16, wch); 170 | } 171 | */ 172 | const HW_FONT XCGROM_JIS_16 = 173 | { 174 | "Genitop JIS0208 16", 175 | 0x0101, 176 | 0x8794, 177 | FONT_SRC::GENITOP_FONT, 178 | 15, 179 | 16, 180 | FONT_CODE::XCGROM_JIS0208 181 | }; 182 | 183 | /** 184 | * @note Cyrillic character set in Genitop GT21L16T1W ROM.
185 | * Reference: http://www.unicode.org/charts/PDF/U0400.pdf
186 | * Example to display 'Ё' to 'ӹ'
187 | * 188 | wchar_t wch; 189 | ra8876lite.setHwTextCursor(100,250); 190 | ra8876lite.setHwTextColor(color.Black); 191 | ra8876lite.setHwTextParam(color.Cyan, 2,2); 192 | for(wch=XCGROM_CYRIL_16.FirstChar; wch 210 | * Reference: https://zh.wikipedia.org/wiki/GB_12345
211 | * GB12345 is compatible with GB2312
212 | * Reference: http://www.khngai.com/chinese/charmap/tblgb.php?page=1
213 | * 214 | * Example to display '啊' to '剥'
215 | 216 | * wchar_t wch; 217 | ra8876lite.setHwTextCursor(100,500); 218 | ra8876lite.setHwTextParam(color.Magenta, 2,2); 219 | for(wch=0xB0A1; wch<0xB0FF; wch++) 220 | { 221 | ra8876lite.putHwChar(&XCGROM_GB12345_16, wch); 222 | } 223 | */ 224 | const HW_FONT XCGROM_GB12345_16 = 225 | { 226 | "Genitop GB12345 16", 227 | 0xA1A1, 228 | 0xF9A9, 229 | FONT_SRC::GENITOP_FONT, 230 | 15, 231 | 16, 232 | FONT_CODE::XCGROM_GB12345 233 | }; 234 | 235 | /** 236 | * @note Arabian 16-dots font(250 characters)
237 | * Reference: http://jrgraphix.net/r/Unicode/0600-06FF
238 | * Example to display '؟' to '۹'
239 | * 240 | wchar_t wch; 241 | 242 | ra8876lite.setHwTextCursor(100,400); 243 | ra8876lite.setHwTextParam(color.Yellow, 1,1); 244 | for(wch=0x061F; wch=0: return "allocated" physical address in offset*mem_block_size 57 | int32_t Memory::mem_malloc(uint32_t size) 58 | { 59 | int offset = 0; 60 | int startEntry = MEM_START_ENTRY; // (CANVAS_WIDTH*CANVAS_HEIGHT*ra8876lite.getColorDepth())/mem_block_size; 61 | int nmemb; //number of memory block required 62 | int i; 63 | 64 | if(!isMemoryManagementReady) 65 | { 66 | mem_init(); 67 | } 68 | 69 | #ifdef DEBUG_LLD_MEMORY 70 | printf("***********************************************\n\r"); 71 | printf("Size = 0x%x.\n\r", size); 72 | #endif 73 | 74 | if(size==0) 75 | { 76 | #ifdef DEBUG_LLD_MEMORY 77 | printf(" Error mem_malloc(%d): size==0\n",size); 78 | #endif 79 | return -1; 80 | } 81 | 82 | nmemb=size/mem_block_size; //calculate the number of memory blocks required 83 | 84 | if(size%mem_block_size) 85 | { 86 | nmemb++; 87 | } 88 | 89 | #ifdef DEBUG_LLD_MEMORY 90 | printf("Number of memory blocks required is %d\n", nmemb); 91 | #endif 92 | //allocate small memory piece in higher memory region 93 | if(size > MEM_LARGE_BLOCK_THRESHOLD) 94 | { 95 | for(offset=startEntry;offset=0;offset--) 124 | for(offset=mem_alloc_tbl_size-1;offset>=startEntry;offset--) 125 | { //scan the whole array memory_tbl[] for continguous memory region 126 | //that is able to allocate nmemb's memory blocks for this bitmap 127 | if(!memory_tbl[offset] && ((offset+nmemb)<=mem_alloc_tbl_size)) 128 | { 129 | //printf("offset = %d\n",offset); 130 | //printf("(offset+nmemb) = %d\n",(offset+nmemb)); 131 | //check if the size is enough 132 | int vacantSize=0; 133 | for(vacantSize=0;vacantSize