├── ATtiny84 ├── README.md └── RetroLiteMonitorScript.cpp ├── BOM ├── RetroLite-Rev-1.3-Main-PCB.csv ├── Retrolite-CM4-Left-PCB.csv └── Retrolite-CM4-Right-PCB.csv ├── CAD Files ├── Buttons │ └── Retro Lite CM4 Buttons.zip ├── Dock │ ├── Dock Body.stl │ └── Dock Lid.stl ├── Housing │ ├── Heatsink-V2.step │ ├── MirrorSpeaker Assembly.step │ ├── Printed-Speaker-Duct-Lid-Mirrored.stl │ ├── Printed-Speaker-Duct-Lid.stl │ ├── Retro Lite CM4 Drawing - Front.pdf │ ├── Retro Lite CM4 Drawing - Rear.pdf │ ├── Retro Lite CM4 Front v1.step │ ├── Retro Lite CM4 Heatsink -Technical Document.pdf │ ├── Retro Lite CM4 Rear v1.step │ ├── Screen Bezel Dimensions (Glass - Tempered).PNG │ ├── Screen Protector.step │ ├── Screen_Bezel_Surround.eps │ ├── Speaker Assembly.step │ ├── Trigger Mounts Left.step │ └── Trigger Mounts Right.step └── PCB │ ├── Power_Volume_PCB.brd │ ├── Power_Volume_PCB.sch │ ├── Power_Volume_PCB_2022-11-11.zip │ ├── RetroLite Rev 1.3 - Main Board (Gerbers).zip │ ├── RetroLite Rev 1.3 - Main Board.brd │ ├── RetroLite Rev 1.3 - Main Board.sch │ ├── Retrolite_CM4_-_Left_PCB.brd │ ├── Retrolite_CM4_-_Left_PCB.sch │ ├── Retrolite_CM4_-_Left_PCB_Gerbers.zip │ ├── Retrolite_CM4_-_Right_PCB.brd │ ├── Retrolite_CM4_-_Right_PCB.sch │ └── Retrolite_CM4_-_Right_PCB_Gerbers.zip ├── HID-Controller └── ATMEGA32u4.cpp ├── LICENSE ├── README.md ├── batteryIcons ├── battery_0_white_18dp.png ├── battery_10_white_18dp.png ├── battery_20_white_18dp.png ├── battery_30_white_18dp.png ├── battery_40_white_18dp.png ├── battery_50_white_18dp.png ├── battery_60_white_18dp.png ├── battery_70_white_18dp.png ├── battery_80_white_18dp.png ├── battery_90_white_18dp.png ├── battery_charge_0_18dp.png ├── battery_charge_1_18dp.png ├── battery_charge_2_18dp.png ├── battery_charge_3_18dp.png ├── battery_charge_4_18dp.png ├── battery_error_18d.png └── battery_full_white_18dp.png ├── boot ├── cmdline.txt ├── config.txt └── rc.local ├── brightnessIcons ├── brightness_0.png ├── brightness_10.png ├── brightness_100.png ├── brightness_20.png ├── brightness_30.png ├── brightness_40.png ├── brightness_50.png ├── brightness_60.png ├── brightness_70.png ├── brightness_80.png └── brightness_90.png ├── keyboard ├── 00.png ├── 01.png ├── 02.png ├── 03.png ├── 04.png ├── 05.png ├── 06.png ├── 10.png ├── 11.png ├── 12.png ├── 13.png ├── 14.png ├── 15.png ├── 16.png ├── 17.png ├── 18.png ├── 19.png ├── 20.png ├── 21.png ├── 22.png ├── 23.png ├── 24.png ├── 25.png ├── 26.png ├── 27.png ├── 28.png ├── 29.png ├── 30.png ├── 31.png ├── 32.png ├── 33.png ├── 34.png ├── 35.png ├── 36.png ├── 37.png ├── 38.png ├── 39.png ├── 40.png ├── 41.png ├── 42.png ├── 43.png ├── 44.png ├── 45.png ├── 46.png ├── 47.png ├── 48.png ├── 49.png ├── lowerCase.png └── upperCase.png ├── lib ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── common │ ├── README.md │ ├── backgroundLayer.c │ ├── backgroundLayer.h │ ├── bits.h │ ├── element_change.h │ ├── font.c │ ├── font.h │ ├── hsv2rgb.c │ ├── hsv2rgb.h │ ├── image.c │ ├── image.h │ ├── imageGraphics.c │ ├── imageGraphics.h │ ├── imageKey.c │ ├── imageKey.h │ ├── imageLayer.c │ ├── imageLayer.h │ ├── imagePalette.c │ ├── imagePalette.h │ ├── key.c │ ├── key.h │ ├── loadpng.c │ ├── loadpng.h │ ├── placeholder.txt │ ├── savepng.c │ ├── savepng.h │ ├── scrollingLayer.c │ ├── scrollingLayer.h │ ├── spriteLayer.c │ └── spriteLayer.h ├── debian │ ├── changelog │ ├── compat │ ├── control │ ├── placeholder.txt │ ├── raspidmx-dev.install │ ├── raspidmx.install │ └── rules ├── game │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── placeholder.txt │ ├── spotlight.png │ ├── sprite.png │ └── texture.png ├── lib │ ├── Makefile │ └── placeholder.txt ├── life │ ├── Makefile │ ├── README.md │ ├── info.c │ ├── info.h │ ├── life.c │ ├── life.h │ ├── main.c │ └── placeholder.txt ├── mandelbrot │ ├── Makefile │ ├── README.md │ ├── info.c │ ├── info.h │ ├── main.c │ ├── mandelbrot.c │ ├── mandelbrot.h │ └── placeholder.txt ├── offscreen │ ├── Makefile │ ├── README.md │ ├── placeholder.txt │ ├── pngresize.c │ ├── resizeDispmanX.c │ └── resizeDispmanX.h ├── pngview │ ├── Makefile │ ├── README.md │ ├── placeholder.txt │ └── pngview.c ├── radar_sweep │ ├── Makefile │ ├── README.md │ ├── placeholder.txt │ └── radar_sweep.c ├── radar_sweep_alpha │ ├── Makefile │ ├── README.md │ ├── placeholder.txt │ └── radar_sweep_alpha.c ├── rgb_triangle │ ├── Makefile │ ├── README.md │ ├── placeholder.txt │ └── rgb_triangle.c ├── spriteview │ ├── Makefile │ ├── README.md │ ├── placeholder.txt │ └── spriteview.c ├── test_pattern │ ├── Makefile │ ├── README.md │ ├── placeholder.txt │ └── test_pattern.c └── worms │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── placeholder.txt │ ├── worms.c │ └── worms.h ├── overlays ├── batteryInfo.png ├── calibration1.png ├── calibration2.png ├── calibration3.png ├── lowbatterywarning.png ├── mainMenu.png ├── menuDot.png └── settingsMenu.png ├── src ├── Makefile ├── config ├── display.h ├── hdmi_switch.sh ├── keycodes.h ├── max17055.h ├── retrolite.c └── retrolite.h └── volumeIcons ├── volume_bar_0.png ├── volume_bar_10.png ├── volume_bar_100.png ├── volume_bar_20.png ├── volume_bar_30.png ├── volume_bar_40.png ├── volume_bar_50.png ├── volume_bar_60.png ├── volume_bar_70.png ├── volume_bar_80.png └── volume_bar_90.png /ATtiny84/README.md: -------------------------------------------------------------------------------- 1 | # ATtiny84 C++ Script 2 | 3 | ## Description 4 | The purpose of the ATtiny84 onboard micrcontroller is to perform 5 simple functions: 5 | 6 | 1) Drive the EN pin of the boost/buck regulators high, to turn on system power 7 | 2) Safely shutdown the operating system via a push button, and shut off regulator output after a reasonable delay (in this case, 10 seconds) 8 | 3) Safely shutdown the operating system when battery voltage depletes less than 3.1v to prevent undervoltage/prolong the battery lifespan. This can be set as low as 2.8v but I would not recommend setting it lower than 3.0v to maintain good battery health 9 | 4) Monitor the BQ24292i charging chip over i2c, including setting the correct parameters/registers for the Retro Lite CM4, like max charge current and voltage cutoffs 10 | 5) Allow for specific time delays before performing actions (i.e hold button 3 seconds for power off, 1 second power on. 10 second delay before regulators switched off, 30 second low voltage shutdown delay) - adjustable via the powerOn, powerOff, and shutDown variables 11 | 6) Set the CM4 to the lowest possible power down state by driving GLOBAL_EN low after software shutdown 12 | 13 | ### Install Instructions 14 | 15 | The easiest way to flash the ATtiny84 is with an Arduino UNO set up as an ICSP (in-circuit serial programmer) directly from within the Arduino IDE. 16 | https://www.arduino.cc/en/software 17 | 18 | Please install the below ATtiny cores for Arduino IDE support and choose the internal 8Mhz clock at 5v when programming your ATtiny84. 19 | https://github.com/damellis/attiny 20 | 21 | For further understanding of the BQ24292i, please check the official datasheet below. Magic number code (i.e directly writing hexadecimal values to the write registers) will be eliminated soon, with proper bitshifting logic to be implemented at a later date. 22 | https://www.ti.com/lit/ds/symlink/bq24292i.pdf 23 | 24 | 25 | -------------------------------------------------------------------------------- /ATtiny84/RetroLiteMonitorScript.cpp: -------------------------------------------------------------------------------- 1 | #define SDA_PIN 6 2 | #define SDA_PORT PORTA 3 | #define SCL_PIN 4 4 | #define SCL_PORT PORTA 5 | #include 6 | 7 | byte BQ24292i_ADDRESS = 0xD6; //BQ24292i slave address (8-bit) 8 | byte power_btn = 8; //Power button connected to this pin. Low Active 9 | byte sys_on = 1; //Regulator power. Active High 10 | byte sht_dwn = 2; //Connected to GPIO25. Signal to start Pi Shutdown. Active High 11 | byte low_volt_shutdown = 0; //Connected to GPIO16 on pi. Used for low voltage shut down 12 | 13 | byte powerBtnState; 14 | byte lowVoltInState = LOW; 15 | byte lastLowVoltInState = LOW; 16 | byte systemState = 0; //Low Power Off 17 | bool shutdownInit = false; 18 | 19 | unsigned long powerBtnTimer; 20 | unsigned long shutDown; 21 | long powerOnDelay = 1000; 22 | long powerOffDelay = 3000; 23 | long shutDownDelay = 10000; 24 | bool btnTimerStarted = false; 25 | bool shutDownTimerStarted = false; 26 | 27 | unsigned long lastLowVoltDebounce = 0; 28 | unsigned long debounceDelay = 50; 29 | 30 | void setup() { 31 | //Serial.begin(9600); 32 | i2c_init(); 33 | BQ_INIT(); 34 | pinMode(power_btn, INPUT_PULLUP); 35 | pinMode(sys_on, OUTPUT); 36 | pinMode(sht_dwn, OUTPUT); 37 | pinMode(low_volt_shutdown, INPUT); 38 | } 39 | 40 | void loop() { 41 | powerButtonDebounce(); 42 | lowVoltShutdownDebounce(); 43 | 44 | if(!shutdownInit){ 45 | if(powerBtnState){ 46 | powerTimerCheck(); 47 | } else { 48 | btnTimerStarted = false; 49 | } 50 | } else { 51 | shutdownTimer(); 52 | } 53 | if(lowVoltInState){ 54 | shutdownTimer(); 55 | } 56 | } 57 | 58 | void powerTimerCheck(){ 59 | if(!btnTimerStarted){ 60 | btnTimerStarted = true; 61 | powerBtnTimer = millis(); 62 | } else { 63 | if(systemState == 0){ 64 | if(powerBtnTimer + powerOnDelay < millis()){ 65 | systemState = 1; 66 | digitalWrite(sys_on, HIGH); 67 | btnTimerStarted = false; 68 | } 69 | } else { 70 | if(powerBtnTimer + powerOffDelay < millis()){ 71 | systemState = 0; 72 | digitalWrite(sht_dwn, HIGH); 73 | btnTimerStarted = false; 74 | shutdownInit = true; 75 | } 76 | } 77 | } 78 | } 79 | 80 | void shutdownTimer(){ 81 | if(!shutDownTimerStarted){ 82 | shutDown = millis(); 83 | shutDownTimerStarted = true; 84 | digitalWrite(sht_dwn, HIGH);//Tell Pi to Shut down 85 | shutdownInit = true; 86 | } else { 87 | if(shutDown + shutDownDelay < millis()){ 88 | digitalWrite(sys_on, LOW); 89 | digitalWrite(sht_dwn, LOW); 90 | systemState = 0; 91 | shutDownTimerStarted = false; 92 | shutdownInit = false; 93 | } 94 | } 95 | } 96 | 97 | void powerButtonDebounce(){ 98 | int input = !digitalRead(power_btn); 99 | if (input != powerBtnState){ 100 | powerBtnState = input; 101 | } 102 | } 103 | 104 | void lowVoltShutdownDebounce(){ 105 | int input = digitalRead(low_volt_shutdown); 106 | if(input != lastLowVoltInState){ 107 | lastLowVoltDebounce = millis(); 108 | } 109 | if((millis() - lastLowVoltDebounce) > debounceDelay){ 110 | if(input != lowVoltInState){ 111 | lowVoltInState = input; 112 | } 113 | } 114 | lastLowVoltInState = input; 115 | } 116 | 117 | void BQ_Write(uint8_t address, uint8_t reg, const uint8_t message) { 118 | i2c_start_wait(address | I2C_WRITE); 119 | i2c_write(reg); 120 | i2c_write(message); 121 | i2c_stop(); 122 | } 123 | 124 | uint8_t BQ_Read(uint8_t address, uint8_t reg){ 125 | i2c_start_wait(address | I2C_WRITE); 126 | i2c_write(reg); 127 | i2c_rep_start(address | I2C_READ); 128 | uint8_t data = i2c_read(true); 129 | i2c_stop(); 130 | return(data); 131 | } 132 | 133 | // BQ24292i Register Configuration Settings 134 | // 135 | //// REG00 136 | //const uint8_t EN_HIZ = 0; 137 | //const uint8_t EN_ILIM = 1; 138 | //const uint8_t INILIM = 0b111; 139 | //const uint8_t INILIM = 0b111; // 3A 140 | // 141 | //// REG01 142 | //const uint8_t REG_RST = 0; 143 | //const uint8_t WD_RST = 0; 144 | //const uint8_t CHG_CONFIG = 0b01; 145 | //const uint8_t SYS_MIN = 0b011; // 3.3V 146 | //const uint8_t BOOST_LIM = 1; 147 | // 148 | //// REG02 149 | //const uint8_t ICHG = 0b011000; // 1.5A 150 | //const uint8_t FORCE_20PCT = 0; 151 | // 152 | //// REG03 default values are OK 153 | // 154 | //// REG04 155 | //const uint8_t VREG = 0b101100; // 4.208V 156 | //const uint8_t BATLOWV = 0; 157 | //const uint8_t VRECHG = 0; 158 | // 159 | //// REG05 160 | //const uint8_t EN_TERM = 1; 161 | //const uint8_t TERM_STAT = 0; 162 | //const uint8_t WATCHDOG = 0b00; // Disable I2C WD 163 | //const uint8_t EN_TIMER = 1; 164 | //const uint8_t CHG_TIMER = 0b01; 165 | // 166 | ////REG06 167 | //const uint8_t BAT_COMP = 0; 168 | //const uint8_t VCLAMP = 0; 169 | //const uint8_t TREG = 0b01; // 80C 170 | 171 | uint8_t REG00_config = 0b01111111; 172 | uint8_t REG01_config = 0b00010001; 173 | uint8_t REG02_config = 0b01000000; //2A Charge Current. Do not alter for Retro Lite CM4 cell 174 | uint8_t REG04_config = 0b10110000; 175 | uint8_t REG05_config = 0b10001010; 176 | uint8_t REG06_config = 0b00000001; 177 | uint8_t REG07_config = 0b01001011; 178 | 179 | void BQ_INIT() { 180 | BQ_Write(BQ24292i_ADDRESS, 0x00, REG00_config); 181 | BQ_Write(BQ24292i_ADDRESS, 0x01, REG01_config); 182 | BQ_Write(BQ24292i_ADDRESS, 0x02, REG02_config); 183 | BQ_Write(BQ24292i_ADDRESS, 0x04, REG04_config); 184 | BQ_Write(BQ24292i_ADDRESS, 0x05, REG05_config); 185 | BQ_Write(BQ24292i_ADDRESS, 0x06, REG06_config); 186 | BQ_Write(BQ24292i_ADDRESS, 0x07, REG07_config); 187 | } 188 | -------------------------------------------------------------------------------- /BOM/Retrolite-CM4-Left-PCB.csv: -------------------------------------------------------------------------------- 1 | Qty,Value,Device,Package,Parts,Description,Unit Price,Total Price,SMT,THT,Original,Remark,,,,,,,,,,VALUE 2 | 2,0.1uF,0.1UF-0603-25V-5%,603,"C1, C2",0.1µF ceramic capacitors,0.000 ,0.000 ,4 ,,N,,,,,,,,,,,0.1uF 3 | 1,545500571,545500571,545500571,JOYSTICK,Joystick FFC conector,1.354 ,1.354 ,7 ,,Y,,,,,,,,,,, 4 | 1,1-1734839-4,1-1734839-4,TE_1-1734839-4,J1,Conn FPC Connector SKT 14 POS 0.5mm Solder RA SMD T/R,1.081 ,1.081 ,14 ,,Y,,,,,,,,,,, 5 | 6,EVQ-Q2B03W,EVQ-Q2B03W,EVQQ2_3,"DPAD_DN, DPAD_L, DPAD_R, DPAD_UP, L2, SELECT",Trigger Button,0.330 ,1.980 ,24 ,,N,,,,,,,,,,, 6 | 1,SKRTLAE010,SKRTLAE010,SW3_SKRTLAE010_ALPS,L1,,0.500 ,0.500 ,5 ,,N,,,,,,,,,,, 7 | ,,,,,,Total,4.915 ,54 ,0 ,,,,,,,,,,,, 8 | -------------------------------------------------------------------------------- /BOM/Retrolite-CM4-Right-PCB.csv: -------------------------------------------------------------------------------- 1 | Qty,Value,Device,Package,Parts,Description,Unit Price,Total Price,SMT,THT,Original,Remark 2 | 4,0.1uF,WCAP-CSGP_0805_885012006018_WAVE,WCAP-CSGP_0805_WAVE,"C3, C5, C9, C10",WCAP-CSGP Ceramic Capacitors,0.000 ,0.000 ,8 ,,N, 3 | 2,22,22OHM-0805-1/4W-1%,805,"R4, R5",22Ω resistor,0.000 ,0.000 ,4 ,,N, 4 | 1,545500571,545500571,545500571,JOYSTICK,Joystick FFC Connector,1.354 ,1.354 ,7 ,,Y, 5 | 1,1-1734839-4,1-1734839-4,TE_1-1734839-4,J2,Conn FPC Connector SKT 14 POS 0.5mm Solder RA SMD T/R,1.081 ,1.081 ,14 ,,Y, 6 | 3,1.0uF,WCAP-CSGP_0805_885012006018_WAVE,WCAP-CSGP_0805_WAVE,"C6, C7, C8",WCAP-CSGP Ceramic Capacitors,0.020 ,0.060 ,6 ,,N, 7 | 3,10k,10KOHM-0603-1/10W-1%,603,"R1, R6, R7",10kΩ resistor,0.000 ,0.000 ,6 ,,N, 8 | 1,10uF,WCAP-CSGP_0805_885012006018_WAVE,WCAP-CSGP_0805_WAVE,C4,WCAP-CSGP Ceramic Capacitors,0.020 ,0.020 ,2 ,,N, 9 | 1,16MHz,CRYSTAL-16MHZSMD-5X3.2,CRYSTAL-SMD-5X3.2-4PAD,Y1,16MHz Crystal,0.500 ,0.500 ,4 ,,N,5TJ416000NYGBC 10 | 2,22pF,22PF-0603-50V-5%,603,"C1, C2",22pF ceramic capacitors,0.000 ,0.000 ,4 ,,N, 11 | 2,330,300OHM-0603-1/10W-1%,603,"R2, R3",1.6kΩ resistor,0.000 ,0.000 ,4 ,,N, 12 | 1,A,EVQ-Q2B03W,EVQQ2_3,A,Tact Switch,0.330 ,0.330 ,4 ,,N, 13 | 1,ATMEGA32U4-AU,ATMEGA32U4-AU,QFP80P1200X1200X120-44N,ATMEGA32U4-AU,8-bit Microcontroller with ISP Flash and USB Controller Check prices,25.904 ,25.904 ,44 ,,Y, 14 | 1,B,EVQ-Q2B03W,EVQQ2_3,B,Tact Switch,0.330 ,0.330 ,4 ,,N, 15 | 1,GREEN,LED-GREEN0603,LED-0603,D1,Green SMD LED,0.030 ,0.030 ,2 ,,N, 16 | 1,SKRTLAE010,SKRTLAE010,SW3_SKRTLAE010_ALPS,RT1,Shoulder Button,0.500 ,0.500 ,5 ,,N, 17 | 1,START,EVQ-Q2B03W,EVQQ2_3,START,Tact Switch,0.330 ,0.330 ,4 ,,N, 18 | 1,T2,EVQ-Q2B03W,EVQQ2_3,RT2,Tact Switch,0.330 ,0.330 ,4 ,,N, 19 | 1,X,EVQ-Q2B03W,EVQQ2_3,X,Tact Switch,0.330 ,0.330 ,4 ,,N, 20 | 1,Y,EVQ-Q2B03W,EVQQ2_3,Y,Tact Switch,0.330 ,0.330 ,4 ,,N, 21 | 1,Yellow,LED-YELLOW0603,LED-0603,D2,Yellow SMD LED 0603,0.030 ,0.030 ,2 ,,N, 22 | ,,,,,,Total,31.459 ,136 ,0 ,, 23 | ,,,,,,,,,,, 24 | ,,,,,,,,,,, 25 | ,,,,,,,,,,, 26 | ,,,,,,,,,,, 27 | ,,,,,,,,,,, 28 | ,,,,,,,,,,, 29 | ,,,,,,,,,,, 30 | ,,,,,,,,,,, 31 | ,,,,,,,,,,, 32 | ,,,,,,s,,,,, 33 | -------------------------------------------------------------------------------- /CAD Files/Buttons/Retro Lite CM4 Buttons.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Buttons/Retro Lite CM4 Buttons.zip -------------------------------------------------------------------------------- /CAD Files/Dock/Dock Body.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Dock/Dock Body.stl -------------------------------------------------------------------------------- /CAD Files/Dock/Dock Lid.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Dock/Dock Lid.stl -------------------------------------------------------------------------------- /CAD Files/Housing/Printed-Speaker-Duct-Lid-Mirrored.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Housing/Printed-Speaker-Duct-Lid-Mirrored.stl -------------------------------------------------------------------------------- /CAD Files/Housing/Printed-Speaker-Duct-Lid.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Housing/Printed-Speaker-Duct-Lid.stl -------------------------------------------------------------------------------- /CAD Files/Housing/Retro Lite CM4 Drawing - Front.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Housing/Retro Lite CM4 Drawing - Front.pdf -------------------------------------------------------------------------------- /CAD Files/Housing/Retro Lite CM4 Drawing - Rear.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Housing/Retro Lite CM4 Drawing - Rear.pdf -------------------------------------------------------------------------------- /CAD Files/Housing/Retro Lite CM4 Heatsink -Technical Document.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Housing/Retro Lite CM4 Heatsink -Technical Document.pdf -------------------------------------------------------------------------------- /CAD Files/Housing/Screen Bezel Dimensions (Glass - Tempered).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Housing/Screen Bezel Dimensions (Glass - Tempered).PNG -------------------------------------------------------------------------------- /CAD Files/Housing/Screen_Bezel_Surround.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/Housing/Screen_Bezel_Surround.eps -------------------------------------------------------------------------------- /CAD Files/PCB/Power_Volume_PCB_2022-11-11.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/PCB/Power_Volume_PCB_2022-11-11.zip -------------------------------------------------------------------------------- /CAD Files/PCB/RetroLite Rev 1.3 - Main Board (Gerbers).zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/PCB/RetroLite Rev 1.3 - Main Board (Gerbers).zip -------------------------------------------------------------------------------- /CAD Files/PCB/Retrolite_CM4_-_Left_PCB_Gerbers.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/PCB/Retrolite_CM4_-_Left_PCB_Gerbers.zip -------------------------------------------------------------------------------- /CAD Files/PCB/Retrolite_CM4_-_Right_PCB_Gerbers.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/CAD Files/PCB/Retrolite_CM4_-_Right_PCB_Gerbers.zip -------------------------------------------------------------------------------- /batteryIcons/battery_0_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_0_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_10_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_10_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_20_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_20_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_30_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_30_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_40_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_40_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_50_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_50_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_60_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_60_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_70_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_70_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_80_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_80_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_90_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_90_white_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_charge_0_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_charge_0_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_charge_1_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_charge_1_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_charge_2_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_charge_2_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_charge_3_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_charge_3_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_charge_4_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_charge_4_18dp.png -------------------------------------------------------------------------------- /batteryIcons/battery_error_18d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_error_18d.png -------------------------------------------------------------------------------- /batteryIcons/battery_full_white_18dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/batteryIcons/battery_full_white_18dp.png -------------------------------------------------------------------------------- /boot/cmdline.txt: -------------------------------------------------------------------------------- 1 | console=tty3 root=PARTUUID=cb1c38bb-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait loglevel=3 consoleblank=0 plymouth.enable=0 quiet vt.global_cursor_default=0 plymouth.enable=0 dwc_otg.fiq_fsm_mask=0x3 usbcore.autosuspend=-1 2 | -------------------------------------------------------------------------------- /boot/config.txt: -------------------------------------------------------------------------------- 1 | # For more options and information see 2 | # http://rpf.io/configtxt 3 | # Some settings may impact device functionality. See link above for details 4 | 5 | # uncomment to force a specific HDMI mode (here we are forcing 800x480!) on the internal screen 6 | #hdmi_group:1=2 7 | #hdmi_mode:1=82 8 | hdmi_group:0=2 9 | hdmi_mode:0=87 10 | hdmi_cvt:0=800 480 60 6 0 0 0 11 | hdmi_force_hotplug:0=1 12 | hdmi_drive:0=1 13 | dtoverlay=i2s-mmap 14 | #dtparam=audio=on 15 | dtparam=i2c_arm=on 16 | dtparam=i2s=on 17 | dtparam=spi=on 18 | gpio=12=pd,dl,op 19 | dtoverlay=seeed-2mic-voicecard 20 | 21 | [pi4] 22 | # Enable DRM VC4 V3D driver on top of the dispmanx display stack 23 | dtoverlay=vc4-fkms-v3d 24 | max_framebuffers=2 25 | 26 | [all] 27 | #dtoverlay=vc4-fkms-v3d 28 | overscan_scale=1 29 | dtoverlay=dwc2,dr_mode=host 30 | -------------------------------------------------------------------------------- /boot/rc.local: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # 3 | # rc.local 4 | # 5 | # This script is executed at the end of each multiuser runlevel. 6 | # Make sure that the script will "exit 0" on success or any other 7 | # value on error. 8 | # 9 | # In order to enable or disable this script just change the execution 10 | # bits. 11 | # 12 | # By default this script does nothing. 13 | 14 | # Print the IP address 15 | _IP=$(hostname -I) || true 16 | if [ "$_IP" ]; then 17 | printf "My IP address is %s\n" "$_IP" 18 | fi 19 | 20 | sudo python3 /home/pi/splash_statistics.py & 21 | 22 | # Reseet USB subsystem for proper hub enumeration 23 | sudo sh -c 'echo 0 > /sys/bus/usb/devices/usb1/authorized' 24 | sudo sh -c 'echo 1 > /sys/bus/usb/devices/usb1/authorized' 25 | 26 | cd /home/pi/RetroliteOSD 27 | sudo ./retrolite & 28 | sudo ./hdmi_switch.sh & 29 | 30 | exit 0 31 | -------------------------------------------------------------------------------- /brightnessIcons/brightness_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_0.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_10.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_100.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_20.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_30.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_40.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_50.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_60.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_70.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_80.png -------------------------------------------------------------------------------- /brightnessIcons/brightness_90.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/brightnessIcons/brightness_90.png -------------------------------------------------------------------------------- /keyboard/00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/00.png -------------------------------------------------------------------------------- /keyboard/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/01.png -------------------------------------------------------------------------------- /keyboard/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/02.png -------------------------------------------------------------------------------- /keyboard/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/03.png -------------------------------------------------------------------------------- /keyboard/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/04.png -------------------------------------------------------------------------------- /keyboard/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/05.png -------------------------------------------------------------------------------- /keyboard/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/06.png -------------------------------------------------------------------------------- /keyboard/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/10.png -------------------------------------------------------------------------------- /keyboard/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/11.png -------------------------------------------------------------------------------- /keyboard/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/12.png -------------------------------------------------------------------------------- /keyboard/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/13.png -------------------------------------------------------------------------------- /keyboard/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/14.png -------------------------------------------------------------------------------- /keyboard/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/15.png -------------------------------------------------------------------------------- /keyboard/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/16.png -------------------------------------------------------------------------------- /keyboard/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/17.png -------------------------------------------------------------------------------- /keyboard/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/18.png -------------------------------------------------------------------------------- /keyboard/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/19.png -------------------------------------------------------------------------------- /keyboard/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/20.png -------------------------------------------------------------------------------- /keyboard/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/21.png -------------------------------------------------------------------------------- /keyboard/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/22.png -------------------------------------------------------------------------------- /keyboard/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/23.png -------------------------------------------------------------------------------- /keyboard/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/24.png -------------------------------------------------------------------------------- /keyboard/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/25.png -------------------------------------------------------------------------------- /keyboard/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/26.png -------------------------------------------------------------------------------- /keyboard/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/27.png -------------------------------------------------------------------------------- /keyboard/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/28.png -------------------------------------------------------------------------------- /keyboard/29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/29.png -------------------------------------------------------------------------------- /keyboard/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/30.png -------------------------------------------------------------------------------- /keyboard/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/31.png -------------------------------------------------------------------------------- /keyboard/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/32.png -------------------------------------------------------------------------------- /keyboard/33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/33.png -------------------------------------------------------------------------------- /keyboard/34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/34.png -------------------------------------------------------------------------------- /keyboard/35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/35.png -------------------------------------------------------------------------------- /keyboard/36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/36.png -------------------------------------------------------------------------------- /keyboard/37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/37.png -------------------------------------------------------------------------------- /keyboard/38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/38.png -------------------------------------------------------------------------------- /keyboard/39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/39.png -------------------------------------------------------------------------------- /keyboard/40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/40.png -------------------------------------------------------------------------------- /keyboard/41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/41.png -------------------------------------------------------------------------------- /keyboard/42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/42.png -------------------------------------------------------------------------------- /keyboard/43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/43.png -------------------------------------------------------------------------------- /keyboard/44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/44.png -------------------------------------------------------------------------------- /keyboard/45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/45.png -------------------------------------------------------------------------------- /keyboard/46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/46.png -------------------------------------------------------------------------------- /keyboard/47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/47.png -------------------------------------------------------------------------------- /keyboard/48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/48.png -------------------------------------------------------------------------------- /keyboard/49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/49.png -------------------------------------------------------------------------------- /keyboard/lowerCase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/lowerCase.png -------------------------------------------------------------------------------- /keyboard/upperCase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/keyboard/upperCase.png -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | # object files 2 | 3 | *.o 4 | 5 | # code 6 | 7 | core 8 | 9 | # programs 10 | 11 | game/game 12 | life/life 13 | mandelbrot/mandelbrot 14 | offscreen/pngresize 15 | pngview/pngview 16 | radar_sweep/radar_sweep 17 | radar_sweep_alpha/radar_sweep_alpha 18 | rgb_triangle/rgb_triangle 19 | spriteview/spriteview 20 | test_pattern/test_pattern 21 | worms/worms 22 | 23 | # other directories 24 | 25 | *_/ 26 | -------------------------------------------------------------------------------- /lib/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Andrew Duncan 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | TARGETS=lib \ 2 | life \ 3 | mandelbrot \ 4 | offscreen \ 5 | pngview \ 6 | radar_sweep \ 7 | radar_sweep_alpha \ 8 | rgb_triangle \ 9 | game \ 10 | spriteview \ 11 | test_pattern \ 12 | worms 13 | 14 | default :all 15 | 16 | all: 17 | for target in $(TARGETS); do ($(MAKE) -C $$target); done 18 | 19 | clean: 20 | for target in $(TARGETS); do ($(MAKE) -C $$target clean); done 21 | 22 | -------------------------------------------------------------------------------- /lib/README.md: -------------------------------------------------------------------------------- 1 | # Dispmanx 2 | 3 | There are a number of APIs available for the Raspberry Pi that can make use 4 | of the computers GPU. These include OpenMAX, Open GL ES(1 and 2) and OpenVG. 5 | The raspberrypi/firmware repository has short examples for these and other 6 | APIs. They can be found in /opt/vc/src/hello_pi/ on the Raspbian 'wheezy' 7 | image. Among these examples is a program called hello_dispmanx. It is a 8 | very small example of the Dispmanx windowing system. Apart from this example, 9 | there is very little documentation available for this API. There 10 | are snippets of information on the Raspberry Pi forum, but I have not found 11 | a single place with detailed information on DispmanX. Hopefully these 12 | programs can be used as a starting point for anyone wanting to make use of 13 | DispmanX. 14 | 15 | https://github.com/raspberrypi/firmware/tree/master/opt/vc/src/hello_pi/hello_dispmanx 16 | 17 | The programs demonstrate layers with the following types: 4BPP (4 bit 18 | indexed), 8BPP (8 bit indexed), RGB565 (16 bit), RGB888 (24 bit), RGBA16 19 | (16 bit with transparency) and RGBA32 (32 bit with transparency) 20 | 21 | ## test_pattern 22 | 23 | This test pattern should be familiar to anyone who has used the Raspberry 24 | Pi. It is the same four colour square displayed when the Raspberry Pi boots. 25 | 26 | ## rgb_triangle 27 | 28 | Displays a triangle in a layer with red, green and blue gradients starting 29 | at each corner respectively. Blends to grey in the center. Demonstrates 30 | changing size of source and destination rectangles. 31 | 32 | ## life 33 | 34 | Conway's game of life. Demonstrates double buffering. 35 | 36 | ## worms 37 | 38 | The program raspiworms uses a single 16 or 32 bit RGBA layer to display a 39 | number of coloured worms on the screen of the Raspberry Pi. 40 | 41 | ## pngview 42 | 43 | Load a png image file and display it as a Dispmanx layer. 44 | 45 | ## spriteview 46 | 47 | Loads a sprite (png) image file and displays it as an animation. 48 | 49 | ## game 50 | 51 | Demonstrates a seamless background image that can be scolled in any 52 | direction. As well as animated sprites. 53 | 54 | ## mandelbrot 55 | 56 | The famous (in the 1990s) Mandelbrot set. 57 | 58 | ## radar_sweep 59 | 60 | An animation of a 'radar sweep' using 16 bit (rgb) palette animation. 61 | 62 | ## radar_sweep_alpha 63 | 64 | An animation of a 'radar sweep' using 32 bit (rgba) palette animation. 65 | 66 | ## offscreen 67 | 68 | An example of using an offscreen display to resize an image. 69 | 70 | ## common 71 | 72 | Code that may be common to some of the demonstration programs is in this 73 | folder. 74 | 75 | ## building 76 | 77 | If you type make in the top level directory, the make file will build all 78 | the different programs in this repository. Each program has its own make 79 | file, so you can build them individually if you wish. 80 | 81 | You will need to install libpng before you build the program. On Raspbian 82 | 83 | sudo apt-get install libpng12-dev 84 | 85 | -------------------------------------------------------------------------------- /lib/common/README.md: -------------------------------------------------------------------------------- 1 | # common 2 | 3 | I have put all the generic code in this common directory. 4 | 5 | -------------------------------------------------------------------------------- /lib/common/backgroundLayer.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | #include 30 | 31 | #include "backgroundLayer.h" 32 | 33 | //------------------------------------------------------------------------- 34 | 35 | void 36 | initBackgroundLayer( 37 | BACKGROUND_LAYER_T *bg, 38 | uint16_t colour, 39 | int32_t layer) 40 | { 41 | int result = 0; 42 | VC_IMAGE_TYPE_T type = VC_IMAGE_RGBA16; 43 | uint32_t vc_image_ptr; 44 | 45 | bg->resource = vc_dispmanx_resource_create(type, 1, 1, &vc_image_ptr); 46 | assert(bg->resource != 0); 47 | 48 | //--------------------------------------------------------------------- 49 | 50 | VC_RECT_T dst_rect; 51 | vc_dispmanx_rect_set(&dst_rect, 0, 0, 1, 1); 52 | 53 | bg->layer = layer; 54 | 55 | result = vc_dispmanx_resource_write_data(bg->resource, 56 | type, 57 | sizeof(colour), 58 | &colour, 59 | &dst_rect); 60 | assert(result == 0); 61 | } 62 | 63 | //------------------------------------------------------------------------- 64 | 65 | void 66 | addElementBackgroundLayer( 67 | BACKGROUND_LAYER_T *bg, 68 | DISPMANX_DISPLAY_HANDLE_T display, 69 | DISPMANX_UPDATE_HANDLE_T update) 70 | { 71 | VC_DISPMANX_ALPHA_T alpha = 72 | { 73 | DISPMANX_FLAGS_ALPHA_FROM_SOURCE, 74 | 255, 75 | 0 76 | }; 77 | 78 | //--------------------------------------------------------------------- 79 | 80 | VC_RECT_T src_rect; 81 | vc_dispmanx_rect_set(&src_rect, 0, 0, 1, 1); 82 | 83 | VC_RECT_T dst_rect; 84 | vc_dispmanx_rect_set(&dst_rect, 0, 0, 0, 0); 85 | 86 | bg->element = 87 | vc_dispmanx_element_add(update, 88 | display, 89 | bg->layer, 90 | &dst_rect, 91 | bg->resource, 92 | &src_rect, 93 | DISPMANX_PROTECTION_NONE, 94 | &alpha, 95 | NULL, 96 | DISPMANX_NO_ROTATE); 97 | assert(bg->element != 0); 98 | } 99 | 100 | //------------------------------------------------------------------------- 101 | 102 | void 103 | destroyBackgroundLayer( 104 | BACKGROUND_LAYER_T *bg) 105 | { 106 | int result = 0; 107 | 108 | DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0); 109 | assert(update != 0); 110 | 111 | result = vc_dispmanx_element_remove(update, bg->element); 112 | assert(result == 0); 113 | 114 | result = vc_dispmanx_update_submit_sync(update); 115 | assert(result == 0); 116 | 117 | result = vc_dispmanx_resource_delete(bg->resource); 118 | assert(result == 0); 119 | } 120 | 121 | -------------------------------------------------------------------------------- /lib/common/backgroundLayer.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef BACKGROUND_LAYER_H 29 | #define BACKGROUND_LAYER_H 30 | 31 | //------------------------------------------------------------------------- 32 | 33 | #include "bcm_host.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | typedef struct 38 | { 39 | int32_t layer; 40 | DISPMANX_RESOURCE_HANDLE_T resource; 41 | DISPMANX_ELEMENT_HANDLE_T element; 42 | } BACKGROUND_LAYER_T; 43 | 44 | //------------------------------------------------------------------------- 45 | 46 | void 47 | initBackgroundLayer( 48 | BACKGROUND_LAYER_T *bg, 49 | uint16_t colour, 50 | int32_t layer); 51 | 52 | void 53 | addElementBackgroundLayer( 54 | BACKGROUND_LAYER_T *bg, 55 | DISPMANX_DISPLAY_HANDLE_T display, 56 | DISPMANX_UPDATE_HANDLE_T update); 57 | 58 | void destroyBackgroundLayer(BACKGROUND_LAYER_T *bg); 59 | 60 | 61 | //------------------------------------------------------------------------- 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /lib/common/element_change.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // flags for vc_dispmanx_element_change_attributes 3 | // 4 | // can be found in interface/vmcs_host/vc_vchi_dispmanx.h 5 | // but you can't include that file as 6 | // interface/peer/vc_vchi_dispmanx_common.h is missing. 7 | // 8 | //------------------------------------------------------------------------- 9 | 10 | #ifndef ELEMENT_CHANGE_H 11 | #define ELEMENT_CHANGE_H 12 | 13 | #ifndef ELEMENT_CHANGE_LAYER 14 | #define ELEMENT_CHANGE_LAYER (1<<0) 15 | #endif 16 | 17 | #ifndef ELEMENT_CHANGE_OPACITY 18 | #define ELEMENT_CHANGE_OPACITY (1<<1) 19 | #endif 20 | 21 | #ifndef ELEMENT_CHANGE_DEST_RECT 22 | #define ELEMENT_CHANGE_DEST_RECT (1<<2) 23 | #endif 24 | 25 | #ifndef ELEMENT_CHANGE_SRC_RECT 26 | #define ELEMENT_CHANGE_SRC_RECT (1<<3) 27 | #endif 28 | 29 | #ifndef ELEMENT_CHANGE_MASK_RESOURCE 30 | #define ELEMENT_CHANGE_MASK_RESOURCE (1<<4) 31 | #endif 32 | 33 | #ifndef ELEMENT_CHANGE_TRANSFORM 34 | #define ELEMENT_CHANGE_TRANSFORM (1<<5) 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/common/font.h: -------------------------------------------------------------------------------- 1 | 2 | //------------------------------------------------------------------------- 3 | // 4 | // The MIT License (MIT) 5 | // 6 | // Copyright (c) 2013 Andrew Duncan 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a 9 | // copy of this software and associated documentation files (the 10 | // "Software"), to deal in the Software without restriction, including 11 | // without limitation the rights to use, copy, modify, merge, publish, 12 | // distribute, sublicense, and/or sell copies of the Software, and to 13 | // permit persons to whom the Software is furnished to do so, subject to 14 | // the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included 17 | // in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | //------------------------------------------------------------------------- 28 | 29 | #ifndef FONT_H 30 | #define FONT_H 31 | 32 | //------------------------------------------------------------------------- 33 | 34 | #include "image.h" 35 | 36 | //------------------------------------------------------------------------- 37 | 38 | #define FONT_WIDTH 8 39 | #define FONT_HEIGHT 16 40 | 41 | //------------------------------------------------------------------------- 42 | 43 | void 44 | drawCharIndexed( 45 | int x, 46 | int y, 47 | uint8_t c, 48 | int8_t index, 49 | IMAGE_T *image); 50 | 51 | void 52 | drawCharRGB( 53 | int x, 54 | int y, 55 | uint8_t c, 56 | const RGBA8_T *rgb, 57 | IMAGE_T *image); 58 | 59 | void 60 | drawStringIndexed( 61 | int x, 62 | int y, 63 | const char *string, 64 | int8_t index, 65 | IMAGE_T *image); 66 | 67 | void 68 | drawStringRGB( 69 | int x, 70 | int y, 71 | const char *string, 72 | const RGBA8_T *rgb, 73 | IMAGE_T *image); 74 | 75 | //------------------------------------------------------------------------- 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /lib/common/hsv2rgb.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "hsv2rgb.h" 33 | #include "image.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | void 38 | hsv2rgb( 39 | int16_t hue, 40 | int16_t saturation, 41 | int16_t value, 42 | RGBA8_T *rgb) 43 | { 44 | //--------------------------------------------------------------------- 45 | // convert hue, saturation and value (HSV) to red, green and blue. 46 | // 47 | // hue = 0 to 3600 (i.e. 1/10 of a degree). 48 | // saturation = 0 to 1000 49 | // value = 0 to 1000 50 | //--------------------------------------------------------------------- 51 | 52 | rgb->red = 0; 53 | rgb->green = 0; 54 | rgb->blue = 0; 55 | 56 | if (saturation == 0) 57 | { 58 | rgb->red = (uint8_t)((255 * value) / 1000); 59 | rgb->green = rgb->red; 60 | rgb->blue = rgb->red; 61 | } 62 | else 63 | { 64 | int16_t h = hue/600; 65 | int16_t f = ((hue%600)*1000)/600; 66 | int16_t p = (value*(1000-saturation))/1000; 67 | int16_t q = (value*(1000-((saturation*f)/1000)))/1000; 68 | int16_t t = (value*(1000-((saturation*(1000-f))/1000)))/1000; 69 | 70 | switch (h) 71 | { 72 | case 0: 73 | 74 | rgb->red = (uint8_t)((255 * value) / 1000); 75 | rgb->green = (uint8_t)((255 * t) / 1000); 76 | rgb->blue = (uint8_t)((255 * p) / 1000); 77 | break; 78 | 79 | case 1: 80 | 81 | rgb->red = (uint8_t)((255 * q) / 1000); 82 | rgb->green = (uint8_t)((255 * value) / 1000); 83 | rgb->blue = (uint8_t)((255 * p) / 1000); 84 | break; 85 | 86 | case 2: 87 | 88 | rgb->red = (uint8_t)((255 * p) / 1000); 89 | rgb->green = (uint8_t)((255 * value) / 1000); 90 | rgb->blue = (uint8_t)((255 * t) / 1000); 91 | break; 92 | 93 | case 3: 94 | 95 | rgb->red = (uint8_t)((255 * p) / 1000); 96 | rgb->green = (uint8_t)((255 * q) / 1000); 97 | rgb->blue = (uint8_t)((255 * value) / 1000); 98 | break; 99 | 100 | case 4: 101 | 102 | rgb->red = (uint8_t)((255 * t) / 1000); 103 | rgb->green = (uint8_t)((255 * p) / 1000); 104 | rgb->blue = (uint8_t)((255 * value) / 1000); 105 | break; 106 | 107 | case 5: 108 | 109 | rgb->red = (uint8_t)((255 * value) / 1000); 110 | rgb->green = (uint8_t)((255 * p) / 1000); 111 | rgb->blue = (uint8_t)((255 * q) / 1000); 112 | break; 113 | 114 | } 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /lib/common/hsv2rgb.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef HSV2RGB_H 29 | #define HSV2RGB_H 30 | 31 | //------------------------------------------------------------------------- 32 | 33 | #include "image.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | void hsv2rgb(int16_t hue, int16_t saturation, int16_t value, RGBA8_T *rgb); 38 | 39 | //------------------------------------------------------------------------- 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/common/image.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef IMAGE_H 29 | #define IMAGE_H 30 | 31 | //------------------------------------------------------------------------- 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "bcm_host.h" 38 | 39 | //------------------------------------------------------------------------- 40 | 41 | typedef struct 42 | { 43 | uint8_t red; 44 | uint8_t green; 45 | uint8_t blue; 46 | uint8_t alpha; 47 | } RGBA8_T; 48 | 49 | //------------------------------------------------------------------------- 50 | 51 | typedef struct IMAGE_T_ IMAGE_T; 52 | 53 | struct IMAGE_T_ 54 | { 55 | VC_IMAGE_TYPE_T type; 56 | int32_t width; 57 | int32_t height; 58 | int32_t pitch; 59 | int32_t alignedHeight; 60 | uint16_t bitsPerPixel; 61 | uint32_t size; 62 | void *buffer; 63 | void (*setPixelDirect)(IMAGE_T*, int32_t, int32_t, const RGBA8_T*); 64 | void (*getPixelDirect)(IMAGE_T*, int32_t, int32_t, RGBA8_T*); 65 | void (*setPixelIndexed)(IMAGE_T*, int32_t, int32_t, int8_t); 66 | void (*getPixelIndexed)(IMAGE_T*, int32_t, int32_t, int8_t*); 67 | }; 68 | 69 | //------------------------------------------------------------------------- 70 | 71 | typedef struct 72 | { 73 | const char *name; 74 | VC_IMAGE_TYPE_T type; 75 | bool hasAlpha; 76 | bool isIndexed; 77 | } IMAGE_TYPE_INFO_T; 78 | 79 | typedef enum 80 | { 81 | IMAGE_TYPES_WITH_ALPHA = 1, 82 | IMAGE_TYPES_WITHOUT_ALPHA = 1 << 1, 83 | IMAGE_TYPES_ALPHA_DONT_CARE = IMAGE_TYPES_WITH_ALPHA 84 | | IMAGE_TYPES_WITHOUT_ALPHA, 85 | IMAGE_TYPES_DIRECT_COLOUR = 1 << 2, 86 | IMAGE_TYPES_ALL_DIRECT_COLOUR = IMAGE_TYPES_ALPHA_DONT_CARE 87 | | IMAGE_TYPES_DIRECT_COLOUR, 88 | IMAGE_TYPES_INDEXED_COLOUR = 1 << 3, 89 | IMAGE_TYPES_ALL_INDEXED_COLOUR = IMAGE_TYPES_ALPHA_DONT_CARE 90 | | IMAGE_TYPES_INDEXED_COLOUR, 91 | IMAGE_TYPES_COLOUR_DONT_CARE = IMAGE_TYPES_DIRECT_COLOUR 92 | | IMAGE_TYPES_INDEXED_COLOUR, 93 | IMAGE_TYPES_ALL = IMAGE_TYPES_ALPHA_DONT_CARE 94 | | IMAGE_TYPES_COLOUR_DONT_CARE 95 | } IMAGE_TYPE_SELECTOR_T; 96 | 97 | //------------------------------------------------------------------------- 98 | 99 | bool 100 | initImage( 101 | IMAGE_T *image, 102 | VC_IMAGE_TYPE_T type, 103 | int32_t width, 104 | int32_t height, 105 | bool dither); 106 | 107 | void 108 | clearImageIndexed( 109 | IMAGE_T *image, 110 | int8_t index); 111 | 112 | void 113 | clearImageRGB( 114 | IMAGE_T *image, 115 | const RGBA8_T *rgb); 116 | 117 | bool 118 | setPixelIndexed( 119 | IMAGE_T *image, 120 | int32_t x, 121 | int32_t y, 122 | int8_t index); 123 | 124 | bool 125 | setPixelRGB( 126 | IMAGE_T *image, 127 | int32_t x, 128 | int32_t y, 129 | const RGBA8_T *rgb); 130 | 131 | bool 132 | getPixelIndexed( 133 | IMAGE_T *image, 134 | int32_t x, 135 | int32_t y, 136 | int8_t *index); 137 | 138 | bool 139 | getPixelRGB( 140 | IMAGE_T *image, 141 | int32_t x, 142 | int32_t y, 143 | RGBA8_T *rgb); 144 | 145 | void 146 | destroyImage( 147 | IMAGE_T *image); 148 | 149 | //------------------------------------------------------------------------- 150 | 151 | bool 152 | findImageType( 153 | IMAGE_TYPE_INFO_T *typeInfo, 154 | const char *name, 155 | IMAGE_TYPE_SELECTOR_T selector); 156 | 157 | void 158 | printImageTypes( 159 | FILE *fp, 160 | const char *before, 161 | const char *after, 162 | IMAGE_TYPE_SELECTOR_T selector); 163 | 164 | //------------------------------------------------------------------------- 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /lib/common/imageGraphics.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef IMAGE_GRAPHICS_H 29 | #define IMAGE_GRAPHICS_H 30 | 31 | #include "image.h" 32 | 33 | //------------------------------------------------------------------------- 34 | 35 | void 36 | imageBoxIndexed( 37 | IMAGE_T *image, 38 | int32_t x1, 39 | int32_t y1, 40 | int32_t x2, 41 | int32_t y2, 42 | int8_t index); 43 | 44 | void 45 | imageBoxRGB( 46 | IMAGE_T *image, 47 | int32_t x1, 48 | int32_t y1, 49 | int32_t x2, 50 | int32_t y2, 51 | const RGBA8_T *rgb); 52 | 53 | void 54 | imageBoxFilledIndexed( 55 | IMAGE_T *image, 56 | int32_t x1, 57 | int32_t y1, 58 | int32_t x2, 59 | int32_t y2, 60 | int8_t index); 61 | 62 | void 63 | imageBoxFilledRGB( 64 | IMAGE_T *image, 65 | int32_t x1, 66 | int32_t y1, 67 | int32_t x2, 68 | int32_t y2, 69 | const RGBA8_T *rgb); 70 | 71 | void 72 | imageLineIndexed( 73 | IMAGE_T *image, 74 | int32_t x1, 75 | int32_t y1, 76 | int32_t x2, 77 | int32_t y2, 78 | int8_t index); 79 | 80 | void 81 | imageLineRGB( 82 | IMAGE_T *image, 83 | int32_t x1, 84 | int32_t y1, 85 | int32_t x2, 86 | int32_t y2, 87 | const RGBA8_T *rgb); 88 | 89 | void 90 | imageHorizontalLineIndexed( 91 | IMAGE_T *image, 92 | int32_t x1, 93 | int32_t x2, 94 | int32_t y, 95 | int8_t index); 96 | 97 | void 98 | imageHorizontalLineRGB( 99 | IMAGE_T *image, 100 | int32_t x1, 101 | int32_t x2, 102 | int32_t y, 103 | const RGBA8_T *rgb); 104 | 105 | void 106 | imageVerticalLineIndexed( 107 | IMAGE_T *image, 108 | int32_t x, 109 | int32_t y1, 110 | int32_t y2, 111 | int8_t index); 112 | 113 | void 114 | imageVerticalLineRGB( 115 | IMAGE_T *image, 116 | int32_t x, 117 | int32_t y1, 118 | int32_t y2, 119 | const RGBA8_T *rgb); 120 | 121 | //------------------------------------------------------------------------- 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /lib/common/imageKey.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | 30 | #include "font.h" 31 | #include "imageGraphics.h" 32 | #include "imageKey.h" 33 | #include "imageLayer.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | #define KEY_BORDER_WIDTH 1 38 | #define KEY_LEFT_PADDING 5 39 | #define KEY_RIGHT_PADDING 5 40 | #define KEY_TOP_PADDING 1 41 | #define KEY_BOTTOM_PADDING 1 42 | 43 | //------------------------------------------------------------------------- 44 | 45 | KEY_DIMENSIONS_T 46 | drawKey( 47 | IMAGE_LAYER_T *imageLayer, 48 | int32_t x, 49 | int32_t y, 50 | const char *text, 51 | const char *description) 52 | { 53 | static RGBA8_T textColour = { 0, 0, 0, 255 }; 54 | static RGBA8_T borderColour = { 191, 191, 191, 255 }; 55 | static RGBA8_T backgroundColour = { 255, 255, 255, 255 }; 56 | 57 | size_t textLength = strlen(text); 58 | 59 | int32_t width = (FONT_WIDTH * textLength) 60 | + (2 * KEY_BORDER_WIDTH) 61 | + KEY_LEFT_PADDING 62 | + KEY_RIGHT_PADDING; 63 | 64 | int32_t height = FONT_HEIGHT 65 | + (2 * KEY_BORDER_WIDTH) 66 | + KEY_TOP_PADDING 67 | + KEY_BOTTOM_PADDING; 68 | 69 | IMAGE_T *image = &(imageLayer->image); 70 | 71 | imageBoxFilledRGB(image, 72 | x, 73 | y, 74 | x + width, 75 | y + height, 76 | &backgroundColour); 77 | 78 | imageBoxRGB(image, x, y, x + width, y + height, &borderColour); 79 | 80 | drawStringRGB(x + KEY_BORDER_WIDTH + KEY_LEFT_PADDING, 81 | y + KEY_BORDER_WIDTH + KEY_TOP_PADDING, 82 | text, 83 | &textColour, 84 | image); 85 | 86 | drawStringRGB(x + width + KEY_RIGHT_PADDING, 87 | y + KEY_BORDER_WIDTH + KEY_TOP_PADDING, 88 | description, 89 | &textColour, 90 | image); 91 | 92 | KEY_DIMENSIONS_T dimensions = { width, height }; 93 | 94 | return dimensions; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /lib/common/imageKey.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef IMAGE_KEY_H 29 | #define IMAGE_KEY_H 30 | 31 | #include 32 | 33 | #include "imageLayer.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | typedef struct 38 | { 39 | int32_t width; 40 | int32_t height; 41 | } KEY_DIMENSIONS_T; 42 | 43 | //------------------------------------------------------------------------- 44 | 45 | KEY_DIMENSIONS_T 46 | drawKey( 47 | IMAGE_LAYER_T *imageLayer, 48 | int32_t x, 49 | int32_t y, 50 | const char *text, 51 | const char *description); 52 | 53 | //------------------------------------------------------------------------- 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/common/imageLayer.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef IMAGE_LAYER_H 29 | #define IMAGE_LAYER_H 30 | 31 | #include "image.h" 32 | 33 | #include "bcm_host.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | typedef struct 38 | { 39 | IMAGE_T image; 40 | VC_RECT_T bmpRect; 41 | VC_RECT_T srcRect; 42 | VC_RECT_T dstRect; 43 | int32_t layer; 44 | DISPMANX_RESOURCE_HANDLE_T resource; 45 | DISPMANX_ELEMENT_HANDLE_T element; 46 | } IMAGE_LAYER_T; 47 | 48 | //------------------------------------------------------------------------- 49 | 50 | void 51 | initImageLayer( 52 | IMAGE_LAYER_T *il, 53 | int32_t width, 54 | int32_t height, 55 | VC_IMAGE_TYPE_T type); 56 | 57 | void 58 | createResourceImageLayer( 59 | IMAGE_LAYER_T *il, 60 | int32_t layer); 61 | 62 | void 63 | addElementImageLayerOffset( 64 | IMAGE_LAYER_T *il, 65 | int32_t xOffset, 66 | int32_t yOffset, 67 | DISPMANX_DISPLAY_HANDLE_T display, 68 | DISPMANX_UPDATE_HANDLE_T update); 69 | 70 | void 71 | addElementImageLayerCentered( 72 | IMAGE_LAYER_T *il, 73 | DISPMANX_MODEINFO_T *info, 74 | DISPMANX_DISPLAY_HANDLE_T display, 75 | DISPMANX_UPDATE_HANDLE_T update); 76 | 77 | void 78 | addElementImageLayer( 79 | IMAGE_LAYER_T *il, 80 | DISPMANX_DISPLAY_HANDLE_T display, 81 | DISPMANX_UPDATE_HANDLE_T update); 82 | 83 | void 84 | changeSourceImageLayer( 85 | IMAGE_LAYER_T *il, 86 | DISPMANX_UPDATE_HANDLE_T update); 87 | 88 | void 89 | changeSourceAndUpdateImageLayer( 90 | IMAGE_LAYER_T *il); 91 | 92 | void 93 | moveImageLayer( 94 | IMAGE_LAYER_T *il, 95 | int32_t xOffset, 96 | int32_t yOffset, 97 | DISPMANX_UPDATE_HANDLE_T update); 98 | 99 | 100 | void destroyImageLayer(IMAGE_LAYER_T *il); 101 | 102 | //------------------------------------------------------------------------- 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /lib/common/imagePalette.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef IMAGE_PALETTE_H 29 | #define IMAGE_PALETTE_H 30 | 31 | //------------------------------------------------------------------------- 32 | 33 | #include 34 | #include 35 | 36 | #include "bcm_host.h" 37 | 38 | #include "image.h" 39 | 40 | //------------------------------------------------------------------------- 41 | 42 | typedef struct 43 | { 44 | uint16_t *palette; 45 | int16_t length; 46 | } IMAGE_PALETTE16_T; 47 | 48 | typedef struct 49 | { 50 | uint32_t *palette; 51 | int16_t length; 52 | } IMAGE_PALETTE32_T; 53 | 54 | //------------------------------------------------------------------------- 55 | 56 | bool 57 | initImagePalette16( 58 | IMAGE_PALETTE16_T *palette, 59 | int16_t length); 60 | 61 | bool 62 | setPalette16EntryRgb( 63 | IMAGE_PALETTE16_T *palette, 64 | int16_t index, 65 | const RGBA8_T *rgb); 66 | 67 | bool 68 | getPalette16EntryRgb( 69 | IMAGE_PALETTE16_T *palette, 70 | int16_t index, 71 | RGBA8_T *rgb); 72 | 73 | void 74 | palette16EntryToRgb( 75 | uint16_t entry, 76 | RGBA8_T *rgb); 77 | 78 | uint16_t 79 | rgbToPalette16Entry( 80 | const RGBA8_T *rgb); 81 | 82 | bool 83 | setResourcePalette16( 84 | const IMAGE_PALETTE16_T *palette, 85 | int16_t offset, 86 | DISPMANX_RESOURCE_HANDLE_T resource, 87 | int16_t first, 88 | int16_t last); 89 | 90 | void 91 | destroyImagePalette16( 92 | IMAGE_PALETTE16_T *palette); 93 | 94 | //------------------------------------------------------------------------- 95 | 96 | bool 97 | initImagePalette32( 98 | IMAGE_PALETTE32_T *palette, 99 | int16_t length); 100 | 101 | bool 102 | setPalette32EntryRgba( 103 | IMAGE_PALETTE32_T *palette, 104 | int16_t index, 105 | const RGBA8_T *rgba); 106 | 107 | bool 108 | getPalette32EntryRgba( 109 | IMAGE_PALETTE32_T *palette, 110 | int16_t index, 111 | RGBA8_T *rgba); 112 | 113 | void 114 | palette32EntryToRgba( 115 | uint32_t entry, 116 | RGBA8_T *rgba); 117 | 118 | uint32_t 119 | rgbaToPalette32Entry( 120 | const RGBA8_T *rgba); 121 | 122 | bool 123 | setResourcePalette32( 124 | const IMAGE_PALETTE32_T *palette, 125 | int16_t offset, 126 | DISPMANX_RESOURCE_HANDLE_T resource, 127 | int16_t first, 128 | int16_t last); 129 | 130 | void 131 | destroyImagePalette32( 132 | IMAGE_PALETTE32_T *palette); 133 | 134 | //------------------------------------------------------------------------- 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /lib/common/key.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "key.h" 35 | 36 | //------------------------------------------------------------------------- 37 | 38 | static int stdin_fd = -1; 39 | static struct termios original; 40 | 41 | //------------------------------------------------------------------------- 42 | 43 | bool keyPressed(int *character) 44 | { 45 | // If this is the first time the function is called, change the stdin 46 | // stream so that we get each character when the keys are pressed and 47 | // and so that character aren't echoed to the screen when the keys are 48 | // pressed. 49 | if (stdin_fd == -1) 50 | { 51 | // Get the file descriptor associated with stdin stream. 52 | stdin_fd = fileno(stdin); 53 | 54 | // Get the terminal (termios) attritubets for stdin so we can 55 | // modify them and reset them before exiting the program. 56 | tcgetattr(stdin_fd, &original); 57 | 58 | // Copy the termios attributes so we can modify them. 59 | struct termios term; 60 | memcpy(&term, &original, sizeof(term)); 61 | 62 | // Unset ICANON and ECHO for stdin. When ICANON is not set the 63 | // input is in noncanonical mode. In noncanonical mode input is 64 | // available as each key is pressed. In canonical mode input is 65 | // only available after the enter key is pressed. Unset ECHO so that 66 | // the characters aren't echoed to the screen when keys are pressed. 67 | // See the termios(3) man page for more information. 68 | term.c_lflag &= ~(ICANON|ECHO); 69 | tcsetattr(stdin_fd, TCSANOW, &term); 70 | 71 | // Turn off buffering for stdin. We want to get the characters 72 | // immediately. We don't want the characters to be buffered. 73 | setbuf(stdin, NULL); 74 | } 75 | 76 | // Get the number of characters that are waiting to be read. 77 | int characters_buffered = 0; 78 | ioctl(stdin_fd, FIONREAD, &characters_buffered); 79 | 80 | // Set the return value to true if there are any characters to be read. 81 | bool pressed = (characters_buffered != 0); 82 | 83 | if (characters_buffered == 1) 84 | { 85 | // There is only one character to be read. Read it in. 86 | int c = fgetc(stdin); 87 | 88 | // Check if the caller wants the value of character read. 89 | if (character != NULL) 90 | { 91 | *character = c; 92 | } 93 | } 94 | else if (characters_buffered > 1) 95 | { 96 | // There is more than one character to be read. This can be key such 97 | // as the arrow keys or function keys. This code just reads them in 98 | // and ignores them. The caller will be informed that a key was 99 | // pressed, but won't get a value for the key. 100 | while (characters_buffered) 101 | { 102 | fgetc(stdin); 103 | --characters_buffered; 104 | } 105 | } 106 | 107 | return pressed; 108 | } 109 | 110 | //------------------------------------------------------------------------- 111 | 112 | void keyboardReset(void) 113 | { 114 | if (stdin_fd != -1) 115 | { 116 | // If keyPressed() has been called the terminal input has been 117 | // changed for the stdin stream. Put the attributes back the way 118 | // we found them. 119 | tcsetattr(stdin_fd, TCSANOW, &original); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /lib/common/key.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef KEY_H 29 | #define KEY_H 30 | 31 | //------------------------------------------------------------------------- 32 | 33 | #include 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | // The keyPressed function is a non-blocking function that returns true if 38 | // a character has been read from stdin. If the character argument is not 39 | // NULL, the character read is returned. NOTE when function keys, arrow keys 40 | // etc are pressed the function will return true, but the character argument 41 | // will not be set. 42 | bool keyPressed(int *character); 43 | 44 | // The keyboardReset function puts the stdin stream back to the way it was 45 | // found when the program started. 46 | void keyboardReset(void); 47 | 48 | //------------------------------------------------------------------------- 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /lib/common/loadpng.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | #include 30 | 31 | #include "bcm_host.h" 32 | 33 | #include "loadpng.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | #ifndef ALIGN_TO_16 38 | #define ALIGN_TO_16(x) ((x + 15) & ~15) 39 | #endif 40 | 41 | //------------------------------------------------------------------------- 42 | 43 | bool 44 | loadPng( 45 | IMAGE_T* image, 46 | const char *file) 47 | { 48 | FILE* fpin = fopen(file, "rb"); 49 | 50 | if (fpin == NULL) 51 | { 52 | fprintf(stderr, "loadpng: can't open file for reading\n"); 53 | return false; 54 | } 55 | 56 | //--------------------------------------------------------------------- 57 | 58 | png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 59 | NULL, 60 | NULL, 61 | NULL); 62 | 63 | if (png_ptr == NULL) 64 | { 65 | fclose(fpin); 66 | return false; 67 | } 68 | 69 | png_infop info_ptr = png_create_info_struct(png_ptr); 70 | 71 | if (info_ptr == NULL) 72 | { 73 | png_destroy_read_struct(&png_ptr, 0, 0); 74 | fclose(fpin); 75 | return false; 76 | } 77 | 78 | if (setjmp(png_jmpbuf(png_ptr))) 79 | { 80 | png_destroy_read_struct(&png_ptr, &info_ptr, 0); 81 | fclose(fpin); 82 | return false; 83 | } 84 | 85 | //--------------------------------------------------------------------- 86 | 87 | png_init_io(png_ptr, fpin); 88 | 89 | png_read_info(png_ptr, info_ptr); 90 | 91 | //--------------------------------------------------------------------- 92 | 93 | png_byte colour_type = png_get_color_type(png_ptr, info_ptr); 94 | png_byte bit_depth = png_get_bit_depth(png_ptr, info_ptr); 95 | 96 | VC_IMAGE_TYPE_T type = VC_IMAGE_RGB888; 97 | 98 | if (colour_type & PNG_COLOR_MASK_ALPHA) 99 | { 100 | type = VC_IMAGE_RGBA32; 101 | } 102 | 103 | initImage(image, 104 | type, 105 | png_get_image_width(png_ptr, info_ptr), 106 | png_get_image_height(png_ptr, info_ptr), 107 | false); 108 | 109 | //--------------------------------------------------------------------- 110 | 111 | double gamma = 0.0; 112 | 113 | if (png_get_gAMA(png_ptr, info_ptr, &gamma)) 114 | { 115 | png_set_gamma(png_ptr, 2.2, gamma); 116 | } 117 | 118 | //--------------------------------------------------------------------- 119 | 120 | if (colour_type == PNG_COLOR_TYPE_PALETTE) 121 | { 122 | png_set_palette_to_rgb(png_ptr); 123 | } 124 | 125 | if ((colour_type == PNG_COLOR_TYPE_GRAY) && (bit_depth < 8)) 126 | { 127 | png_set_expand_gray_1_2_4_to_8(png_ptr); 128 | } 129 | 130 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) 131 | { 132 | png_set_tRNS_to_alpha(png_ptr); 133 | } 134 | 135 | if (bit_depth == 16) 136 | { 137 | #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED 138 | png_set_scale_16(png_ptr); 139 | #else 140 | png_set_strip_16(png_ptr); 141 | #endif 142 | } 143 | 144 | if (colour_type == PNG_COLOR_TYPE_GRAY || 145 | colour_type == PNG_COLOR_TYPE_GRAY_ALPHA) 146 | { 147 | png_set_gray_to_rgb(png_ptr); 148 | } 149 | 150 | //--------------------------------------------------------------------- 151 | 152 | png_read_update_info(png_ptr, info_ptr); 153 | 154 | //--------------------------------------------------------------------- 155 | 156 | png_bytepp row_pointers = malloc(image->height * sizeof(png_bytep)); 157 | 158 | png_uint_32 j = 0; 159 | for (j = 0 ; j < image->height ; ++j) 160 | { 161 | row_pointers[j] = image->buffer + (j * image->pitch); 162 | } 163 | 164 | //--------------------------------------------------------------------- 165 | 166 | png_read_image(png_ptr, row_pointers); 167 | 168 | //--------------------------------------------------------------------- 169 | 170 | fclose(fpin); 171 | 172 | free(row_pointers); 173 | 174 | png_destroy_read_struct(&png_ptr, &info_ptr, 0); 175 | 176 | return true; 177 | } 178 | 179 | -------------------------------------------------------------------------------- /lib/common/loadpng.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef LOADPNG_H 29 | #define LOADPNG_H 30 | 31 | #include 32 | 33 | #include "image.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | bool loadPng(IMAGE_T *image, const char *file); 38 | 39 | //------------------------------------------------------------------------- 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/common/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/common/savepng.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #define _GNU_SOURCE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "image.h" 38 | 39 | //----------------------------------------------------------------------- 40 | 41 | bool 42 | pngWriteImageRGB565( 43 | const IMAGE_T *image, 44 | png_structp pngPtr, 45 | png_infop infoPtr) 46 | { 47 | int32_t rowLength = 3 * image->width; 48 | uint8_t *imageRow = malloc(rowLength); 49 | 50 | if (imageRow == NULL) 51 | { 52 | fprintf(stderr, "savepng: unable to allocated row buffer\n"); 53 | return false; 54 | } 55 | 56 | int32_t y = 0; 57 | for (y = 0; y < image->height; y++) 58 | { 59 | int32_t x = 0; 60 | for (x = 0; x < image->width; x++) 61 | { 62 | uint16_t pixels = *(uint16_t*)(image->buffer + 63 | (y * image->pitch) + 64 | ((x * image->bitsPerPixel) / 8)); 65 | int32_t index = x * 3; 66 | 67 | uint8_t r5 = (pixels >> 11) & 0x1F; 68 | uint8_t g6 = (pixels >> 5) & 0x3F; 69 | uint8_t b5 = (pixels) & 0x1F; 70 | 71 | imageRow[index] = (r5 << 3) | (r5 >> 2); 72 | imageRow[index + 1] = (g6 << 2) | (g6 >> 4); 73 | imageRow[index + 2] = (b5 << 3) | (b5 >> 2); 74 | } 75 | png_write_row(pngPtr, imageRow); 76 | 77 | } 78 | 79 | free(imageRow); 80 | 81 | return true; 82 | } 83 | 84 | //----------------------------------------------------------------------- 85 | 86 | bool 87 | pngWriteImageRGB888( 88 | const IMAGE_T *image, 89 | png_structp pngPtr, 90 | png_infop infoPtr) 91 | { 92 | int32_t y = 0; 93 | for (y = 0; y < image->height; y++) 94 | { 95 | png_write_row(pngPtr, image->buffer + (image->pitch * y)); 96 | } 97 | 98 | return true; 99 | } 100 | 101 | //----------------------------------------------------------------------- 102 | 103 | bool 104 | pngWriteImageRGBA16( 105 | const IMAGE_T *image, 106 | png_structp pngPtr, 107 | png_infop infoPtr) 108 | { 109 | int32_t rowLength = 4 * image->width; 110 | uint8_t *imageRow = malloc(rowLength); 111 | 112 | if (imageRow == NULL) 113 | { 114 | fprintf(stderr, "savepng: unable to allocated row buffer\n"); 115 | return false; 116 | } 117 | 118 | int32_t y = 0; 119 | for (y = 0; y < image->height; y++) 120 | { 121 | int32_t x = 0; 122 | for (x = 0; x < image->width; x++) 123 | { 124 | uint16_t pixels = *(uint16_t*)(image->buffer + 125 | (y * image->pitch) + 126 | ((x * image->bitsPerPixel) / 8)); 127 | int32_t index = x * 4; 128 | 129 | uint8_t r4 = (pixels >> 12) & 0xF; 130 | uint8_t g4 = (pixels >> 8) & 0xF; 131 | uint8_t b4 = (pixels >> 4) & 0xF; 132 | uint8_t a4 = pixels & 0xF; 133 | 134 | imageRow[index] = (r4 << 4) | r4; 135 | imageRow[index + 1] = (g4 << 4) | g4; 136 | imageRow[index + 2] = (b4 << 4) | b4; 137 | imageRow[index + 3] = (a4 << 4) | a4; 138 | } 139 | png_write_row(pngPtr, imageRow); 140 | 141 | } 142 | 143 | free(imageRow); 144 | 145 | return true; 146 | } 147 | 148 | //----------------------------------------------------------------------- 149 | 150 | bool 151 | pngWriteImageRGBA32( 152 | const IMAGE_T *image, 153 | png_structp pngPtr, 154 | png_infop infoPtr) 155 | { 156 | int32_t y = 0; 157 | for (y = 0; y < image->height; y++) 158 | { 159 | png_write_row(pngPtr, image->buffer + (image->pitch * y)); 160 | } 161 | 162 | return true; 163 | } 164 | 165 | //----------------------------------------------------------------------- 166 | 167 | bool savePng(const IMAGE_T* image, const char *file) 168 | { 169 | png_structp pngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 170 | NULL, 171 | NULL, 172 | NULL); 173 | 174 | if (pngPtr == NULL) 175 | { 176 | fprintf(stderr, 177 | "savepng: unable to allocated PNG write structure\n"); 178 | 179 | return false; 180 | } 181 | 182 | png_infop infoPtr = png_create_info_struct(pngPtr); 183 | 184 | if (infoPtr == NULL) 185 | { 186 | fprintf(stderr, 187 | "savepng: unable to allocated PNG info structure\n"); 188 | 189 | return false; 190 | } 191 | 192 | if (setjmp(png_jmpbuf(pngPtr))) 193 | { 194 | fprintf(stderr, "savepng: unable to create PNG\n"); 195 | return false; 196 | } 197 | 198 | FILE *pngfp = fopen(file, "wb"); 199 | 200 | if (pngfp == NULL) 201 | { 202 | fprintf(stderr, 203 | "savepng: unable to create %s - %s\n", 204 | file, 205 | strerror(errno)); 206 | 207 | exit(EXIT_FAILURE); 208 | } 209 | 210 | png_init_io(pngPtr, pngfp); 211 | 212 | int png_color_type = PNG_COLOR_TYPE_RGB; 213 | 214 | if ((image->type == VC_IMAGE_RGBA16) || 215 | (image->type == VC_IMAGE_RGBA32)) 216 | { 217 | png_color_type = PNG_COLOR_TYPE_RGBA; 218 | } 219 | 220 | png_set_IHDR( 221 | pngPtr, 222 | infoPtr, 223 | image->width, 224 | image->height, 225 | 8, 226 | png_color_type, 227 | PNG_INTERLACE_NONE, 228 | PNG_COMPRESSION_TYPE_BASE, 229 | PNG_FILTER_TYPE_BASE); 230 | 231 | png_write_info(pngPtr, infoPtr); 232 | 233 | bool result = false; 234 | 235 | switch(image->type) 236 | { 237 | case VC_IMAGE_RGB565: 238 | 239 | result = pngWriteImageRGB565(image, pngPtr, infoPtr); 240 | break; 241 | 242 | case VC_IMAGE_RGB888: 243 | 244 | result = pngWriteImageRGB888(image, pngPtr, infoPtr); 245 | break; 246 | 247 | case VC_IMAGE_RGBA16: 248 | 249 | result = pngWriteImageRGBA16(image, pngPtr, infoPtr); 250 | break; 251 | 252 | case VC_IMAGE_RGBA32: 253 | 254 | result = pngWriteImageRGBA32(image, pngPtr, infoPtr); 255 | break; 256 | 257 | default: 258 | 259 | break; 260 | } 261 | 262 | png_write_end(pngPtr, NULL); 263 | png_destroy_write_struct(&pngPtr, &infoPtr); 264 | fclose(pngfp); 265 | 266 | return result; 267 | } 268 | -------------------------------------------------------------------------------- /lib/common/savepng.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef SAVEPNG_H 29 | #define SAVEPNG_H 30 | 31 | #include 32 | 33 | #include "image.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | bool savePng(const IMAGE_T* image, const char *file); 38 | 39 | //------------------------------------------------------------------------- 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/common/scrollingLayer.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef SCROLLING_LAYER_H 29 | #define SCROLLING_LAYER_H 30 | 31 | #include 32 | 33 | #include "image.h" 34 | 35 | #include "bcm_host.h" 36 | 37 | //------------------------------------------------------------------------- 38 | 39 | typedef struct 40 | { 41 | IMAGE_T image; 42 | int32_t viewWidth; 43 | int32_t viewHeight; 44 | int32_t xOffsetMax; 45 | int32_t xOffset; 46 | int32_t yOffsetMax; 47 | int32_t yOffset; 48 | int16_t direction; 49 | int16_t directionMax; 50 | int32_t xDirections[8]; 51 | int32_t yDirections[8]; 52 | VC_RECT_T bmpRect; 53 | VC_RECT_T srcRect; 54 | VC_RECT_T dstRect; 55 | int32_t layer; 56 | DISPMANX_RESOURCE_HANDLE_T frontResource; 57 | DISPMANX_RESOURCE_HANDLE_T backResource; 58 | DISPMANX_ELEMENT_HANDLE_T element; 59 | } SCROLLING_LAYER_T; 60 | 61 | //------------------------------------------------------------------------- 62 | 63 | void 64 | initScrollingLayer(SCROLLING_LAYER_T *sl, 65 | const char* file, 66 | int32_t layer); 67 | 68 | void 69 | addElementScrollingLayerCentered( 70 | SCROLLING_LAYER_T *sl, 71 | DISPMANX_MODEINFO_T *info, 72 | DISPMANX_DISPLAY_HANDLE_T display, 73 | DISPMANX_UPDATE_HANDLE_T update); 74 | 75 | void 76 | addElementScrollingLayer( 77 | SCROLLING_LAYER_T *sl, 78 | DISPMANX_DISPLAY_HANDLE_T display, 79 | DISPMANX_UPDATE_HANDLE_T update); 80 | 81 | void setDirectionScrollingLayer(SCROLLING_LAYER_T *sl, char c); 82 | 83 | void 84 | updatePositionScrollingLayer( 85 | SCROLLING_LAYER_T *sl, 86 | DISPMANX_UPDATE_HANDLE_T update); 87 | 88 | void destroyScrollingLayer(SCROLLING_LAYER_T *sl); 89 | 90 | bool 91 | loadScrollingLayerPng( 92 | IMAGE_T* image, 93 | const char *file, 94 | bool extendX, 95 | bool extendY); 96 | 97 | //------------------------------------------------------------------------- 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /lib/common/spriteLayer.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef SPRITE_LAYER_H 29 | #define SPRITE_LAYER_H 30 | 31 | #include "image.h" 32 | 33 | #include "bcm_host.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | typedef struct 38 | { 39 | IMAGE_T image; 40 | int width; 41 | int height; 42 | int columns; 43 | int rows; 44 | int xOffsetMax; 45 | int xOffset; 46 | int yOffsetMax; 47 | int yOffset; 48 | VC_RECT_T bmpRect; 49 | VC_RECT_T srcRect; 50 | VC_RECT_T dstRect; 51 | int32_t layer; 52 | DISPMANX_RESOURCE_HANDLE_T frontResource; 53 | DISPMANX_RESOURCE_HANDLE_T backResource; 54 | DISPMANX_ELEMENT_HANDLE_T element; 55 | } SPRITE_LAYER_T; 56 | 57 | //------------------------------------------------------------------------- 58 | 59 | void 60 | initSpriteLayer( 61 | SPRITE_LAYER_T *s, 62 | int columns, 63 | int rows, 64 | const char *file, 65 | int32_t layer); 66 | 67 | void 68 | addElementSpriteLayerOffset( 69 | SPRITE_LAYER_T *s, 70 | int32_t xOffset, 71 | int32_t yOffset, 72 | DISPMANX_DISPLAY_HANDLE_T display, 73 | DISPMANX_UPDATE_HANDLE_T update); 74 | 75 | void 76 | addElementSpriteLayerCentered( 77 | SPRITE_LAYER_T *s, 78 | DISPMANX_MODEINFO_T *info, 79 | DISPMANX_DISPLAY_HANDLE_T display, 80 | DISPMANX_UPDATE_HANDLE_T update); 81 | 82 | void 83 | addElementSpriteLayer( 84 | SPRITE_LAYER_T *s, 85 | DISPMANX_DISPLAY_HANDLE_T display, 86 | DISPMANX_UPDATE_HANDLE_T update); 87 | 88 | void 89 | updatePositionSpriteLayer( 90 | SPRITE_LAYER_T *s, 91 | DISPMANX_UPDATE_HANDLE_T update); 92 | 93 | void destroySpriteLayer(SPRITE_LAYER_T *s); 94 | 95 | //------------------------------------------------------------------------- 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /lib/debian/changelog: -------------------------------------------------------------------------------- 1 | raspidmx (1.0-4) unstable; urgency=low 2 | 3 | * Added missing assets for game 4 | 5 | -- Albert Casals Wed, 07 Jun 2017 23:03:00 +0100 6 | 7 | raspidmx (1.0-3) unstable; urgency=low 8 | 9 | * Fixed libpng dependency name 10 | 11 | -- Albert Casals Wed, 07 Jun 2017 22:50:00 +0100 12 | 13 | raspidmx (1.0-2) unstable; urgency=low 14 | 15 | * Fixed internal dependency 16 | 17 | -- Albert Casals Wed, 07 Jun 2017 22:43:00 +0100 18 | 19 | raspidmx (1.0-1) unstable; urgency=low 20 | 21 | * Initial package version 22 | 23 | -- Albert Casals Wed, 07 Jun 2017 22:09:00 +0100 24 | -------------------------------------------------------------------------------- /lib/debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /lib/debian/control: -------------------------------------------------------------------------------- 1 | Source: raspidmx 2 | Maintainer: Albert Casals 3 | Section: graphics 4 | Priority: optional 5 | Standards-Version: 3.9.4 6 | Build-Depends: debhelper (>=9.0.0), libpng12-dev, libraspberrypi-dev 7 | Homepage: https://github.com/AndrewFromMelbourne/raspidmx 8 | 9 | Package: raspidmx 10 | Architecture: all 11 | Depends: ${shlibs:Depends}, ${misc:Depends}, libpng12-0, libraspberrypi0 12 | Description: A dispmanX API with some simple games and samples 13 | 14 | Package: raspidmx-dev 15 | Architecture: all 16 | Depends: ${shlibs:Depends}, ${misc:Depends}, raspidmx, libpng12-dev, libraspberrypi-dev 17 | Description: A dispmanX API development package 18 | -------------------------------------------------------------------------------- /lib/debian/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/debian/raspidmx-dev.install: -------------------------------------------------------------------------------- 1 | lib/libraspidmx.a /usr/lib/arm-linux-gnueabihf 2 | common/*h /usr/include/raspidmx 3 | -------------------------------------------------------------------------------- /lib/debian/raspidmx.install: -------------------------------------------------------------------------------- 1 | lib/libraspidmx.so /usr/lib/arm-linux-gnueabihf 2 | lib/libraspidmx.so.1 /usr/lib/arm-linux-gnueabihf 3 | game/game /usr/share/raspidmx/samples 4 | game/*png /usr/share/raspidmx/samples 5 | life/life /usr/share/raspidmx/samples 6 | mandelbrot/mandelbrot /usr/share/raspidmx/samples 7 | offscreen/pngresize /usr/share/raspidmx/samples 8 | pngview/pngview /usr/share/raspidmx/samples 9 | radar_sweep/radar_sweep /usr/share/raspidmx/samples 10 | radar_sweep_alpha/radar_sweep_alpha /usr/share/raspidmx/samples 11 | rgb_triangle/rgb_triangle /usr/share/raspidmx/samples 12 | spriteview/spriteview /usr/share/raspidmx/samples 13 | test_pattern/test_pattern /usr/share/raspidmx/samples 14 | worms/worms /usr/share/raspidmx/samples 15 | -------------------------------------------------------------------------------- /lib/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | %: 4 | dh $@ 5 | -------------------------------------------------------------------------------- /lib/game/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=main.o 2 | BIN=game 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common $(shell libpng-config --cflags) 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm $(shell libpng-config --ldflags) -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/game/README.md: -------------------------------------------------------------------------------- 1 | # game 2 | 3 | Demonstrates a seamless background image that can be scolled in any 4 | direction. As well as animated sprites. Change direction of travel using 5 | ',' and '.' keys. Press 'Esc' to exit. 6 | 7 | -------------------------------------------------------------------------------- /lib/game/main.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #define _GNU_SOURCE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "backgroundLayer.h" 38 | #include "element_change.h" 39 | #include "image.h" 40 | #include "imageLayer.h" 41 | #include "loadpng.h" 42 | #include "key.h" 43 | #include "scrollingLayer.h" 44 | #include "spriteLayer.h" 45 | 46 | #include "bcm_host.h" 47 | 48 | //------------------------------------------------------------------------- 49 | 50 | #define NDEBUG 51 | 52 | //------------------------------------------------------------------------- 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | uint32_t displayNumber = 0; 57 | 58 | //------------------------------------------------------------------- 59 | 60 | int opt; 61 | 62 | while ((opt = getopt(argc, argv, "d:")) != -1) 63 | { 64 | switch (opt) 65 | { 66 | case 'd': 67 | 68 | displayNumber = atoi(optarg); 69 | break; 70 | 71 | default: 72 | 73 | fprintf(stderr, "Usage: %s [-d ]\n", basename(argv[0])); 74 | fprintf(stderr, " -d - Raspberry Pi display number\n"); 75 | exit(EXIT_FAILURE); 76 | break; 77 | } 78 | } 79 | 80 | //------------------------------------------------------------------- 81 | 82 | bcm_host_init(); 83 | 84 | //--------------------------------------------------------------------- 85 | 86 | BACKGROUND_LAYER_T bg; 87 | initBackgroundLayer(&bg, 0x000F, 0); 88 | 89 | SCROLLING_LAYER_T sl; 90 | initScrollingLayer(&sl, "texture.png", 1); 91 | 92 | IMAGE_LAYER_T spotlight; 93 | 94 | if (loadPng(&(spotlight.image), "spotlight.png") == false) 95 | { 96 | fprintf(stderr, "unable to load spotlight\n"); 97 | exit(EXIT_FAILURE); 98 | } 99 | 100 | createResourceImageLayer(&spotlight, 2); 101 | 102 | SPRITE_LAYER_T sprite; 103 | initSpriteLayer(&sprite, 12, 1, "sprite.png", 3); 104 | 105 | //--------------------------------------------------------------------- 106 | 107 | DISPMANX_DISPLAY_HANDLE_T display 108 | = vc_dispmanx_display_open(displayNumber); 109 | assert(display != 0); 110 | 111 | //--------------------------------------------------------------------- 112 | 113 | DISPMANX_MODEINFO_T info; 114 | int result = vc_dispmanx_display_get_info(display, &info); 115 | assert(result == 0); 116 | 117 | //--------------------------------------------------------------------- 118 | 119 | DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0); 120 | assert(update != 0); 121 | 122 | addElementBackgroundLayer(&bg, display, update); 123 | addElementScrollingLayerCentered(&sl, &info, display, update); 124 | addElementImageLayerCentered(&spotlight, &info, display, update); 125 | addElementSpriteLayerCentered(&sprite, &info, display, update); 126 | 127 | result = vc_dispmanx_update_submit_sync(update); 128 | assert(result == 0); 129 | 130 | //--------------------------------------------------------------------- 131 | 132 | int c = 0; 133 | 134 | while (c != 27) 135 | { 136 | if (keyPressed(&c)) 137 | { 138 | c = tolower(c); 139 | setDirectionScrollingLayer(&sl, c); 140 | } 141 | 142 | //----------------------------------------------------------------- 143 | 144 | DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0); 145 | assert(update != 0); 146 | 147 | updatePositionScrollingLayer(&sl, update); 148 | updatePositionSpriteLayer(&sprite, update); 149 | 150 | result = vc_dispmanx_update_submit_sync(update); 151 | assert(result == 0); 152 | } 153 | 154 | //--------------------------------------------------------------------- 155 | 156 | keyboardReset(); 157 | 158 | //--------------------------------------------------------------------- 159 | 160 | destroyBackgroundLayer(&bg); 161 | destroyScrollingLayer(&sl); 162 | destroyImageLayer(&spotlight); 163 | destroySpriteLayer(&sprite); 164 | 165 | //--------------------------------------------------------------------- 166 | 167 | result = vc_dispmanx_display_close(display); 168 | assert(result == 0); 169 | 170 | //--------------------------------------------------------------------- 171 | 172 | return 0; 173 | } 174 | 175 | -------------------------------------------------------------------------------- /lib/game/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/game/spotlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/lib/game/spotlight.png -------------------------------------------------------------------------------- /lib/game/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/lib/game/sprite.png -------------------------------------------------------------------------------- /lib/game/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/lib/game/texture.png -------------------------------------------------------------------------------- /lib/lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Build static and shared libraries for raspidmx 3 | # 4 | 5 | LIB=raspidmx 6 | 7 | OBJS=../common/backgroundLayer.o ../common/imageGraphics.o ../common/key.o ../common/spriteLayer.o \ 8 | ../common/font.o ../common/imageKey.o ../common/loadpng.o \ 9 | ../common/hsv2rgb.o ../common/imageLayer.o ../common/savepng.o \ 10 | ../common/image.o ../common/imagePalette.o ../common/scrollingLayer.o 11 | 12 | CFLAGS+=-Wall -g -O3 -I../common $(shell libpng-config --cflags) 13 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm $(shell libpng-config --ldflags) 14 | 15 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 16 | 17 | all: $(LIB) 18 | 19 | %.o: %.c 20 | @rm -f $@ 21 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 22 | 23 | $(LIB): $(OBJS) 24 | $(AR) rcs lib$(LIB).a $(OBJS) 25 | #$(CC) -shared -Wl,-soname,lib$(LIB).so.1 $(LDFLAGS) -o lib$(LIB).so.1 $(OBJS) 26 | 27 | # TODO: move to debian package 28 | ln -sfv lib$(LIB).so.1 lib$(LIB).so 29 | 30 | clean: 31 | @rm -f $(OBJS) 32 | @rm -f lib$(LIB).so* 33 | @rm -f lib$(LIB).a 34 | -------------------------------------------------------------------------------- /lib/lib/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/life/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=main.o life.o info.o 2 | BIN=life 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -pthread -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/life/README.md: -------------------------------------------------------------------------------- 1 | # life 2 | 3 | A version of Conway's game of life. The code starts with a random image and 4 | continues to iterate. Press 'p' to pause and then press the space bar to 5 | step. Press 'Esc' to exit the game. 6 | 7 | -------------------------------------------------------------------------------- /lib/life/info.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | #include 30 | 31 | #include "font.h" 32 | #include "imageGraphics.h" 33 | #include "imageKey.h" 34 | #include "imageLayer.h" 35 | #include "info.h" 36 | 37 | //------------------------------------------------------------------------- 38 | 39 | #define INFO_LEFT_PADDING 4 40 | #define INFO_TOP_PADDING 4 41 | 42 | //------------------------------------------------------------------------- 43 | 44 | void 45 | lifeInfo( 46 | IMAGE_LAYER_T *imageLayer, 47 | int32_t size, 48 | bool paused, 49 | int32_t threads, 50 | bool framesPerSecondValid, 51 | double framesPerSecond) 52 | { 53 | static RGBA8_T backgroundColour = { 255, 255, 255, 255 }; 54 | static RGBA8_T textColour = { 0, 0, 0, 255 }; 55 | 56 | IMAGE_T *image = &(imageLayer->image); 57 | 58 | clearImageRGB(image, &backgroundColour); 59 | 60 | //--------------------------------------------------------------------- 61 | 62 | int32_t x = INFO_LEFT_PADDING; 63 | int32_t y = 0; 64 | 65 | KEY_DIMENSIONS_T key_dimensions = { 0, 0 }; 66 | 67 | //--------------------------------------------------------------------- 68 | 69 | x = INFO_LEFT_PADDING; 70 | y += key_dimensions.height + INFO_TOP_PADDING; 71 | 72 | key_dimensions = drawKey(imageLayer, x, y, "Esc", "exit"); 73 | 74 | //--------------------------------------------------------------------- 75 | 76 | y += key_dimensions.height + INFO_TOP_PADDING; 77 | 78 | key_dimensions = drawKey(imageLayer, 79 | x, 80 | y, 81 | "P", 82 | paused ? "resume" : "pause"); 83 | 84 | //--------------------------------------------------------------------- 85 | 86 | y += key_dimensions.height + INFO_TOP_PADDING; 87 | 88 | key_dimensions = drawKey(imageLayer, x, y, "space", "step"); 89 | 90 | //--------------------------------------------------------------------- 91 | 92 | char buffer[128]; 93 | 94 | y += key_dimensions.height + INFO_TOP_PADDING; 95 | 96 | snprintf(buffer, sizeof(buffer), "size: %d", size); 97 | drawStringRGB(x, y, buffer, &textColour, image); 98 | 99 | y += FONT_HEIGHT + INFO_TOP_PADDING; 100 | 101 | snprintf(buffer, sizeof(buffer), "threads: %d", threads); 102 | drawStringRGB(x, y, buffer, &textColour, image); 103 | 104 | y += FONT_HEIGHT + INFO_TOP_PADDING; 105 | 106 | if (framesPerSecondValid) 107 | { 108 | snprintf(buffer, sizeof(buffer), "fps: %.f", framesPerSecond); 109 | } 110 | else 111 | { 112 | snprintf(buffer, sizeof(buffer), "fps: --"); 113 | } 114 | 115 | drawStringRGB(x, y, buffer, &textColour, image); 116 | 117 | //--------------------------------------------------------------------- 118 | 119 | changeSourceAndUpdateImageLayer(imageLayer); 120 | } 121 | 122 | -------------------------------------------------------------------------------- /lib/life/info.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef INFO_H 29 | #define INFO_H 30 | 31 | #include 32 | 33 | #include "imageLayer.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | void 38 | lifeInfo( 39 | IMAGE_LAYER_T *imageLayer, 40 | int32_t size, 41 | bool paused, 42 | int32_t threads, 43 | bool framesPerSecondValid, 44 | double framesPerSecond); 45 | 46 | //------------------------------------------------------------------------- 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/life/life.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef LIFE_H 29 | #define LIFE_H 30 | 31 | #include 32 | #include 33 | 34 | #include "bcm_host.h" 35 | 36 | //------------------------------------------------------------------------- 37 | 38 | #define LIFE_MAX_THREADS 4 39 | 40 | //------------------------------------------------------------------------- 41 | 42 | typedef struct 43 | { 44 | int32_t startHeight; 45 | int32_t endHeight; 46 | } LIFE_HEIGHT_RANGE_T; 47 | 48 | //------------------------------------------------------------------------- 49 | 50 | typedef struct 51 | { 52 | int32_t width; 53 | int32_t alignedWidth; 54 | int32_t height; 55 | int32_t alignedHeight; 56 | int32_t pitch; 57 | uint8_t *buffer; 58 | int32_t fieldLength; 59 | uint8_t *field; 60 | uint8_t *fieldNext; 61 | 62 | VC_RECT_T bmpRect; 63 | VC_RECT_T srcRect; 64 | VC_RECT_T dstRect; 65 | DISPMANX_RESOURCE_HANDLE_T frontResource; 66 | DISPMANX_RESOURCE_HANDLE_T backResource; 67 | DISPMANX_ELEMENT_HANDLE_T element; 68 | 69 | int32_t numberOfThreads; 70 | pthread_t threads[LIFE_MAX_THREADS]; 71 | LIFE_HEIGHT_RANGE_T heightRange[LIFE_MAX_THREADS]; 72 | pthread_barrier_t startIterationBarrier; 73 | pthread_barrier_t finishedIterationBarrier; 74 | } LIFE_T; 75 | 76 | //------------------------------------------------------------------------- 77 | 78 | void newLife(LIFE_T *life, int32_t size); 79 | 80 | void 81 | addElementLife( 82 | LIFE_T *life, 83 | int32_t xOffset, 84 | int32_t yOffset, 85 | int32_t dstSize, 86 | DISPMANX_DISPLAY_HANDLE_T display, 87 | DISPMANX_UPDATE_HANDLE_T update); 88 | 89 | void * 90 | workerLife( 91 | void *arg); 92 | 93 | void 94 | iterateLifeKernel( 95 | LIFE_T *life, 96 | int32_t thread); 97 | 98 | void 99 | iterateLife( 100 | LIFE_T *life); 101 | 102 | void 103 | changeSourceLife( 104 | LIFE_T *life, 105 | DISPMANX_UPDATE_HANDLE_T update); 106 | 107 | void destroyLife(LIFE_T *life); 108 | 109 | //------------------------------------------------------------------------- 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /lib/life/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/mandelbrot/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=main.o mandelbrot.o info.o 2 | BIN=mandelbrot 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common $(shell libpng-config --cflags) 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm $(shell libpng-config --ldflags) -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -pthread -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/mandelbrot/README.md: -------------------------------------------------------------------------------- 1 | # mandelbrot 2 | 3 | A program to view and zoom into the Mandelbrot set. Press 's' to save the 4 | current image as a PNG file. Press 'z' (once the current image has been 5 | drawn) to select the area of interest. Use the 'w', 'a', 's' and 'd' keys 6 | to move the area of interest. You can change the amount of pixels the area 7 | of interest moves by using the '[' and ']' keys. Press 'Enter' to generate 8 | an image of the selected area or 'Esc' to go back to the previous image. 9 | 10 | -------------------------------------------------------------------------------- /lib/mandelbrot/info.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | 30 | #include "font.h" 31 | #include "imageGraphics.h" 32 | #include "imageKey.h" 33 | #include "imageLayer.h" 34 | #include "info.h" 35 | 36 | //------------------------------------------------------------------------- 37 | 38 | #define INFO_LEFT_PADDING 4 39 | #define INFO_TOP_PADDING 4 40 | 41 | //------------------------------------------------------------------------- 42 | 43 | void 44 | calculatingInfo( 45 | IMAGE_LAYER_T *imageLayer, 46 | int32_t threads) 47 | { 48 | static RGBA8_T textColour = { 0, 0, 0, 255 }; 49 | static RGBA8_T backgroundColour = { 255, 255, 255, 255 }; 50 | 51 | IMAGE_T *image = &(imageLayer->image); 52 | 53 | clearImageRGB(image, &backgroundColour); 54 | 55 | //--------------------------------------------------------------------- 56 | 57 | drawStringRGB(INFO_LEFT_PADDING, 58 | INFO_TOP_PADDING, 59 | "Calculating ...", 60 | &textColour, 61 | image); 62 | 63 | //--------------------------------------------------------------------- 64 | 65 | char buffer[128]; 66 | 67 | snprintf(buffer, sizeof(buffer), "threads: %d", threads); 68 | 69 | drawStringRGB(INFO_LEFT_PADDING, 70 | (2 * INFO_TOP_PADDING) + FONT_HEIGHT, 71 | buffer, 72 | &textColour, 73 | image); 74 | 75 | changeSourceAndUpdateImageLayer(imageLayer); 76 | } 77 | 78 | //------------------------------------------------------------------------- 79 | 80 | void 81 | mandelbrotInfo( 82 | IMAGE_LAYER_T *imageLayer) 83 | { 84 | static RGBA8_T backgroundColour = { 255, 255, 255, 255 }; 85 | 86 | IMAGE_T *image = &(imageLayer->image); 87 | 88 | clearImageRGB(image, &backgroundColour); 89 | 90 | //--------------------------------------------------------------------- 91 | 92 | KEY_DIMENSIONS_T key_dimensions = { 0, 0 }; 93 | int32_t x = INFO_LEFT_PADDING; 94 | int32_t y = 0; 95 | 96 | //--------------------------------------------------------------------- 97 | 98 | y += key_dimensions.height + INFO_TOP_PADDING; 99 | 100 | key_dimensions = drawKey(imageLayer, x, y, "Esc", "exit"); 101 | 102 | //--------------------------------------------------------------------- 103 | 104 | y += key_dimensions.height + INFO_TOP_PADDING; 105 | 106 | key_dimensions = drawKey(imageLayer, x, y, "Z", "zoom in"); 107 | 108 | //--------------------------------------------------------------------- 109 | 110 | y += key_dimensions.height + INFO_TOP_PADDING; 111 | 112 | key_dimensions = drawKey(imageLayer, x, y, "S", "save PNG file"); 113 | 114 | //--------------------------------------------------------------------- 115 | 116 | changeSourceAndUpdateImageLayer(imageLayer); 117 | } 118 | 119 | //------------------------------------------------------------------------- 120 | 121 | void 122 | zoomInfo( 123 | IMAGE_LAYER_T *imageLayer, 124 | int32_t *steps, 125 | int32_t numberOfSteps, 126 | int32_t stepIndex) 127 | { 128 | static RGBA8_T backgroundColour = { 255, 255, 255, 255 }; 129 | 130 | IMAGE_T *image = &(imageLayer->image); 131 | 132 | clearImageRGB(image, &backgroundColour); 133 | 134 | //--------------------------------------------------------------------- 135 | 136 | int32_t x = INFO_LEFT_PADDING; 137 | int32_t y = 0; 138 | 139 | KEY_DIMENSIONS_T key_dimensions = { 0, 0 }; 140 | 141 | //--------------------------------------------------------------------- 142 | 143 | x = INFO_LEFT_PADDING; 144 | y += key_dimensions.height + INFO_TOP_PADDING; 145 | 146 | key_dimensions = drawKey(imageLayer, x, y, "Enter", "zoom"); 147 | 148 | //--------------------------------------------------------------------- 149 | 150 | y += key_dimensions.height + INFO_TOP_PADDING; 151 | 152 | key_dimensions = drawKey(imageLayer, x, y, "Esc", "cancel zoom"); 153 | 154 | //--------------------------------------------------------------------- 155 | 156 | y += key_dimensions.height + INFO_TOP_PADDING; 157 | 158 | key_dimensions = drawKey(imageLayer, x, y, "W", "move up"); 159 | 160 | //--------------------------------------------------------------------- 161 | 162 | y += key_dimensions.height + INFO_TOP_PADDING; 163 | 164 | key_dimensions = drawKey(imageLayer, x, y, "A", "move left"); 165 | 166 | //--------------------------------------------------------------------- 167 | 168 | y += key_dimensions.height + INFO_TOP_PADDING; 169 | 170 | key_dimensions = drawKey(imageLayer, x, y, "S", "move down"); 171 | 172 | //--------------------------------------------------------------------- 173 | 174 | y += key_dimensions.height + INFO_TOP_PADDING; 175 | 176 | key_dimensions = drawKey(imageLayer, x, y, "D", "mode right"); 177 | 178 | //--------------------------------------------------------------------- 179 | 180 | y += key_dimensions.height + INFO_TOP_PADDING; 181 | 182 | key_dimensions = drawKey(imageLayer, x, y, "[", "decrease step"); 183 | 184 | //--------------------------------------------------------------------- 185 | 186 | y += key_dimensions.height + INFO_TOP_PADDING; 187 | 188 | key_dimensions = drawKey(imageLayer, x, y, "]", "increase step"); 189 | 190 | //--------------------------------------------------------------------- 191 | 192 | static RGBA8_T lowlightColour = { 191, 191, 191, 255 }; 193 | static RGBA8_T highlightColour = { 0, 0, 0, 255 }; 194 | 195 | y += key_dimensions.height + INFO_TOP_PADDING; 196 | 197 | drawStringRGB(x, y, "step:", &highlightColour, image); 198 | 199 | y += FONT_HEIGHT + INFO_TOP_PADDING; 200 | 201 | char buffer[128]; 202 | 203 | int32_t i = 0; 204 | for (i = 0 ; i < numberOfSteps ; i++) 205 | { 206 | RGBA8_T *colour = &lowlightColour; 207 | 208 | if (i == stepIndex) 209 | { 210 | colour = &highlightColour; 211 | } 212 | 213 | snprintf(buffer, sizeof(buffer), "%d ", steps[i]); 214 | 215 | drawStringRGB(x, y, buffer, colour, image); 216 | 217 | x += strlen(buffer) * FONT_WIDTH; 218 | } 219 | 220 | //--------------------------------------------------------------------- 221 | 222 | changeSourceAndUpdateImageLayer(imageLayer); 223 | } 224 | 225 | -------------------------------------------------------------------------------- /lib/mandelbrot/info.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef INFO_H 29 | #define INFO_H 30 | 31 | #include 32 | 33 | #include "imageLayer.h" 34 | 35 | //------------------------------------------------------------------------- 36 | 37 | void 38 | calculatingInfo( 39 | IMAGE_LAYER_T *imageLayer, 40 | int32_t threads); 41 | 42 | void 43 | mandelbrotInfo( 44 | IMAGE_LAYER_T *imageLayer); 45 | 46 | void 47 | zoomInfo( 48 | IMAGE_LAYER_T *imageLayer, 49 | int32_t *steps, 50 | int32_t numberOfSteps, 51 | int32_t stepIndex); 52 | 53 | //------------------------------------------------------------------------- 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/mandelbrot/mandelbrot.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #include 29 | 30 | #include "bcm_host.h" 31 | 32 | #include "hsv2rgb.h" 33 | #include "image.h" 34 | #include "mandelbrot.h" 35 | 36 | //------------------------------------------------------------------------- 37 | 38 | void 39 | newMandelbrot( 40 | MANDELBROT_T *mbrot, 41 | IMAGE_LAYER_T *imageLayer) 42 | { 43 | mbrot->imageLayer = imageLayer; 44 | 45 | //--------------------------------------------------------------------- 46 | 47 | size_t colours = (sizeof(mbrot->colours) / sizeof(mbrot->colours[0])); 48 | size_t colour = 0; 49 | 50 | mbrot->numberOfColours = colours; 51 | 52 | for (colour = 0 ; colour < colours ; colour++) 53 | { 54 | hsv2rgb((colours - 1 - colour) * (2400 / colours), 55 | 1000, 56 | 1000, 57 | &(mbrot->colours[colour])); 58 | } 59 | 60 | //--------------------------------------------------------------------- 61 | 62 | long cores = sysconf(_SC_NPROCESSORS_ONLN); 63 | 64 | if (cores == -1) 65 | { 66 | cores = 1; 67 | } 68 | 69 | if (cores > MANDELBROT_MAX_THREADS) 70 | { 71 | mbrot->numberOfThreads = MANDELBROT_MAX_THREADS; 72 | } 73 | else 74 | { 75 | mbrot->numberOfThreads = cores; 76 | } 77 | 78 | pthread_barrier_init(&(mbrot->startBarrier), 79 | NULL, 80 | mbrot->numberOfThreads + 1); 81 | 82 | pthread_barrier_init(&(mbrot->finishedBarrier), 83 | NULL, 84 | mbrot->numberOfThreads + 1); 85 | 86 | //--------------------------------------------------------------------- 87 | 88 | IMAGE_T *image = &(imageLayer->image); 89 | 90 | //--------------------------------------------------------------------- 91 | 92 | int32_t heightStep = image->height / mbrot->numberOfThreads; 93 | int32_t heightStart = 0; 94 | 95 | int32_t thread; 96 | for (thread = 0 ; thread < mbrot->numberOfThreads ; thread++) 97 | { 98 | mbrot->heightRange[thread].startHeight = heightStart; 99 | mbrot->heightRange[thread].endHeight = heightStart + heightStep; 100 | 101 | heightStart += heightStep; 102 | 103 | pthread_create(&(mbrot->threads[thread]), 104 | NULL, 105 | workerMandelbrot, 106 | mbrot); 107 | } 108 | 109 | thread = mbrot->numberOfThreads - 1; 110 | mbrot->heightRange[thread].endHeight = image->height; 111 | } 112 | 113 | //------------------------------------------------------------------------- 114 | 115 | void 116 | destroyMandelbrot( 117 | MANDELBROT_T *mbrot) 118 | { 119 | int32_t thread; 120 | for (thread = 0 ; thread < mbrot->numberOfThreads ; thread++) 121 | { 122 | pthread_cancel(mbrot->threads[thread]); 123 | } 124 | } 125 | 126 | //------------------------------------------------------------------------- 127 | 128 | void * 129 | workerMandelbrot( 130 | void *arg) 131 | { 132 | MANDELBROT_T *mbrot = arg; 133 | 134 | int32_t thread = -1; 135 | int32_t i; 136 | for (i = 0 ; i < mbrot->numberOfThreads ; i++) 137 | { 138 | if (pthread_equal(pthread_self(), mbrot->threads[i])) 139 | { 140 | thread = i; 141 | break; 142 | } 143 | } 144 | 145 | if (thread == -1) 146 | { 147 | fprintf(stderr, "mandelbrot: cannot find thread index\n"); 148 | return NULL; 149 | } 150 | 151 | while (true) 152 | { 153 | pthread_barrier_wait(&(mbrot->startBarrier)); 154 | mandelbrotImageKernel(mbrot, 155 | mbrot->heightRange[thread].startHeight, 156 | mbrot->heightRange[thread].endHeight); 157 | pthread_barrier_wait(&(mbrot->finishedBarrier)); 158 | } 159 | 160 | return NULL; 161 | } 162 | 163 | //------------------------------------------------------------------------- 164 | 165 | void 166 | mandelbrotImageKernel( 167 | MANDELBROT_T *mbrot, 168 | int32_t startHeight, 169 | int32_t endHeight) 170 | { 171 | IMAGE_T *image = &(mbrot->imageLayer->image); 172 | 173 | double dx = (mbrot->coords.side / (image->width - 1)); 174 | double dy = (mbrot->coords.side / (image->height - 1)); 175 | 176 | int32_t j; 177 | for (j = startHeight ; j < endHeight ; j++) 178 | { 179 | int32_t i; 180 | for (i = 0 ; i < image->width ; i++) 181 | { 182 | double x0 = mbrot->coords.x0 + dx * i; 183 | double y0 = mbrot->coords.y0 + dy * j; 184 | 185 | double x = 0.0; 186 | double y = 0.0; 187 | 188 | double x2 = x * x; 189 | double y2 = y * y; 190 | 191 | size_t n = 0; 192 | 193 | while ((x2 + y2 < 4.0) && (n < mbrot->numberOfColours)) 194 | { 195 | double xtemp = x2 - y2 + x0; 196 | y = 2 * x * y + y0; 197 | x = xtemp; 198 | 199 | x2 = x * x; 200 | y2 = y * y; 201 | 202 | n++; 203 | } 204 | 205 | if (n < mbrot->numberOfColours) 206 | { 207 | setPixelRGB(image, i, j, &(mbrot->colours[n])); 208 | } 209 | } 210 | } 211 | } 212 | 213 | //------------------------------------------------------------------------- 214 | 215 | void 216 | mandelbrotImage( 217 | MANDELBROT_T *mbrot, 218 | MANDELBROT_COORDS_T *coords) 219 | { 220 | memcpy(&(mbrot->coords), coords, sizeof(MANDELBROT_COORDS_T)); 221 | 222 | static RGBA8_T black = {0, 0, 0, 0}; 223 | 224 | IMAGE_T *image = &(mbrot->imageLayer->image); 225 | clearImageRGB(image, &black); 226 | 227 | //--------------------------------------------------------------------- 228 | 229 | pthread_barrier_wait(&(mbrot->startBarrier)); 230 | pthread_barrier_wait(&(mbrot->finishedBarrier)); 231 | 232 | //--------------------------------------------------------------------- 233 | 234 | changeSourceAndUpdateImageLayer(mbrot->imageLayer); 235 | } 236 | 237 | -------------------------------------------------------------------------------- /lib/mandelbrot/mandelbrot.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef MANDELBROT_H 29 | #define MANDELBROT_H 30 | 31 | #include 32 | #include 33 | 34 | #include "imageLayer.h" 35 | 36 | //------------------------------------------------------------------------- 37 | 38 | #define MANDELBROT_MAX_THREADS 4 39 | 40 | //------------------------------------------------------------------------- 41 | 42 | typedef struct 43 | { 44 | double x0; 45 | double y0; 46 | double side; 47 | } MANDELBROT_COORDS_T; 48 | 49 | //------------------------------------------------------------------------- 50 | 51 | typedef struct 52 | { 53 | int32_t startHeight; 54 | int32_t endHeight; 55 | } MANDELBROT_HEIGHT_RANGE_T; 56 | 57 | //------------------------------------------------------------------------- 58 | 59 | typedef struct 60 | { 61 | MANDELBROT_COORDS_T coords; 62 | IMAGE_LAYER_T *imageLayer; 63 | 64 | RGBA8_T colours[256]; 65 | size_t numberOfColours; 66 | 67 | int32_t numberOfThreads; 68 | pthread_t threads[MANDELBROT_MAX_THREADS]; 69 | MANDELBROT_HEIGHT_RANGE_T heightRange[MANDELBROT_MAX_THREADS]; 70 | pthread_barrier_t startBarrier; 71 | pthread_barrier_t finishedBarrier; 72 | } MANDELBROT_T; 73 | 74 | //------------------------------------------------------------------------- 75 | 76 | void 77 | newMandelbrot( 78 | MANDELBROT_T *mbrot, 79 | IMAGE_LAYER_T *imageLayer); 80 | void 81 | destroyMandelbrot( 82 | MANDELBROT_T *mbrot); 83 | 84 | void * 85 | workerMandelbrot( 86 | void *arg); 87 | 88 | void 89 | mandelbrotImageKernel( 90 | MANDELBROT_T *mbrot, 91 | int32_t startHeight, 92 | int32_t endHeight); 93 | 94 | void 95 | mandelbrotImage( 96 | MANDELBROT_T *mbrot, 97 | MANDELBROT_COORDS_T *coords); 98 | 99 | //------------------------------------------------------------------------- 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /lib/mandelbrot/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/offscreen/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=pngresize.o resizeDispmanX.o 2 | BIN=pngresize 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common $(shell libpng-config --cflags) 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm $(shell libpng-config --ldflags) -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/offscreen/README.md: -------------------------------------------------------------------------------- 1 | # pngresize 2 | 3 | Example of using an offscreen display to resize an image. The program reads 4 | a PNG image and resizes it to the specified width and height. 5 | -------------------------------------------------------------------------------- /lib/offscreen/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/offscreen/pngresize.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #define _GNU_SOURCE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "image.h" 38 | #include "loadpng.h" 39 | #include "resizeDispmanX.h" 40 | #include "savepng.h" 41 | 42 | #include "bcm_host.h" 43 | 44 | //------------------------------------------------------------------------- 45 | 46 | #define NDEBUG 47 | 48 | //------------------------------------------------------------------------- 49 | 50 | const char *program = NULL; 51 | 52 | //------------------------------------------------------------------------- 53 | 54 | void usage(void) 55 | { 56 | fprintf(stderr, 57 | "Usage: %s -w -h \n", 58 | program); 59 | fprintf(stderr, " -w - resize to width\n"); 60 | fprintf(stderr, " -h - resize to height\n"); 61 | 62 | exit(EXIT_FAILURE); 63 | } 64 | 65 | //------------------------------------------------------------------------- 66 | 67 | int main(int argc, char *argv[]) 68 | { 69 | program = basename(argv[0]); 70 | 71 | int16_t width = 0; 72 | int16_t height = 0; 73 | 74 | //--------------------------------------------------------------------- 75 | 76 | int opt = 0; 77 | 78 | while ((opt = getopt(argc, argv, "w:h:")) != -1) 79 | { 80 | switch(opt) 81 | { 82 | case 'w': 83 | 84 | width = atoi(optarg); 85 | break; 86 | 87 | case 'h': 88 | 89 | height = atoi(optarg); 90 | break; 91 | 92 | default: 93 | 94 | usage(); 95 | break; 96 | } 97 | } 98 | 99 | //--------------------------------------------------------------------- 100 | 101 | if ((width <= 0) || (height <= 0)) 102 | { 103 | fprintf(stderr, 104 | "%s: must specify both width or height\n", 105 | program); 106 | exit(EXIT_FAILURE); 107 | } 108 | 109 | //--------------------------------------------------------------------- 110 | 111 | if (optind >= argc) 112 | { 113 | usage(); 114 | } 115 | 116 | //--------------------------------------------------------------------- 117 | 118 | bcm_host_init(); 119 | 120 | //--------------------------------------------------------------------- 121 | 122 | IMAGE_T srcImage; 123 | 124 | if (loadPng(&srcImage, argv[optind]) == false) 125 | { 126 | fprintf(stderr, "%s: unable to load %s\n", program, argv[optind]); 127 | exit(EXIT_FAILURE); 128 | } 129 | 130 | //--------------------------------------------------------------------- 131 | 132 | RESIZE_DISPMANX_T resize; 133 | 134 | initResizeDispmanX(&resize, 135 | srcImage.type, 136 | width, 137 | height, 138 | srcImage.width, 139 | srcImage.height, 140 | true); 141 | 142 | //--------------------------------------------------------------------- 143 | 144 | IMAGE_T dstImage; 145 | 146 | initImage(&dstImage, 147 | srcImage.type, 148 | resize.destinationWidth, 149 | resize.destinationHeight, 150 | false); 151 | 152 | //--------------------------------------------------------------------- 153 | 154 | 155 | resizeDispmanX(&resize, &dstImage, &srcImage); 156 | 157 | //--------------------------------------------------------------------- 158 | 159 | if (savePng(&dstImage, argv[optind+1]) == false) 160 | { 161 | fprintf(stderr, "%s: unable to save %s\n", program, argv[optind+1]); 162 | } 163 | 164 | //--------------------------------------------------------------------- 165 | 166 | destroyImage(&srcImage); 167 | destroyImage(&dstImage); 168 | 169 | destroyResizeDispmanX(&resize); 170 | 171 | //--------------------------------------------------------------------- 172 | 173 | return 0; 174 | } 175 | 176 | -------------------------------------------------------------------------------- /lib/offscreen/resizeDispmanX.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #define _GNU_SOURCE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "bcm_host.h" 36 | 37 | #include "resizeDispmanX.h" 38 | 39 | //------------------------------------------------------------------------- 40 | 41 | #ifndef ALIGN_TO_16 42 | #define ALIGN_TO_16(x) ((x + 15) & ~15) 43 | #endif 44 | 45 | //------------------------------------------------------------------------- 46 | 47 | void 48 | initResizeDispmanX( 49 | RESIZE_DISPMANX_T *rd, 50 | VC_IMAGE_TYPE_T type, 51 | int16_t dWidth, 52 | int16_t dHeight, 53 | int16_t sWidth, 54 | int16_t sHeight, 55 | bool keepAspectRatio) 56 | { 57 | int16_t width = dWidth; 58 | int16_t height = dHeight; 59 | 60 | rd->xRatio = (((int32_t)sWidth << 16) / width) + 1; 61 | rd->yRatio = (((int32_t)sHeight << 16) / height) + 1; 62 | 63 | rd->destinationWidth = ALIGN_TO_16(width); 64 | rd->destinationHeight = height; 65 | 66 | if (keepAspectRatio) 67 | { 68 | if (rd->xRatio < rd->yRatio) 69 | { 70 | rd->xRatio = rd->yRatio; 71 | rd->destinationWidth = ALIGN_TO_16((sWidth * rd->destinationHeight) / sHeight); 72 | } 73 | else 74 | { 75 | rd->yRatio = rd->xRatio; 76 | rd->destinationHeight = (rd->destinationWidth * sHeight) / sWidth; 77 | } 78 | 79 | } 80 | 81 | rd->sourceWidth = sWidth; 82 | rd->sourceHeight = sHeight; 83 | 84 | bcm_host_init(); 85 | 86 | rd->type = type; 87 | 88 | uint32_t dstImageHandle; 89 | 90 | rd->dstRes = vc_dispmanx_resource_create(rd->type, 91 | rd->destinationWidth, 92 | rd->destinationHeight, 93 | &dstImageHandle); 94 | 95 | uint32_t srcImageHandle; 96 | 97 | rd->srcRes = vc_dispmanx_resource_create(rd->type, 98 | sWidth, 99 | sHeight, 100 | &srcImageHandle); 101 | 102 | rd->display = vc_dispmanx_display_open_offscreen(rd->dstRes, 103 | DISPMANX_NO_ROTATE); 104 | 105 | vc_dispmanx_rect_set(&(rd->bmpRect), 0, 0, sWidth, sHeight); 106 | vc_dispmanx_rect_set(&(rd->srcRect), 0, 0, sWidth << 16, sHeight << 16); 107 | 108 | vc_dispmanx_rect_set(&(rd->dstRect), 109 | 0, 110 | 0, 111 | rd->destinationWidth, 112 | rd->destinationHeight); 113 | } 114 | 115 | //------------------------------------------------------------------------- 116 | 117 | void 118 | destroyResizeDispmanX( 119 | RESIZE_DISPMANX_T *rd) 120 | { 121 | vc_dispmanx_display_close(rd->display); 122 | vc_dispmanx_resource_delete(rd->srcRes); 123 | vc_dispmanx_resource_delete(rd->dstRes); 124 | } 125 | 126 | //------------------------------------------------------------------------- 127 | 128 | void 129 | resizeDispmanX( 130 | RESIZE_DISPMANX_T *rd, 131 | IMAGE_T *dst, 132 | IMAGE_T *src) 133 | { 134 | vc_dispmanx_resource_write_data(rd->srcRes, 135 | rd->type, 136 | src->pitch, 137 | src->buffer, 138 | &(rd->bmpRect)); 139 | 140 | VC_DISPMANX_ALPHA_T alpha; 141 | 142 | alpha.mask = DISPMANX_NO_HANDLE; 143 | alpha.flags = DISPMANX_FLAGS_ALPHA_FROM_SOURCE 144 | | DISPMANX_FLAGS_ALPHA_MIX; 145 | alpha.opacity = 255; 146 | 147 | DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0); 148 | 149 | DISPMANX_ELEMENT_HANDLE_T element; 150 | element = vc_dispmanx_element_add(update, 151 | rd->display, 152 | 0, 153 | &(rd->dstRect), 154 | rd->srcRes, 155 | &(rd->srcRect), 156 | DISPMANX_PROTECTION_NONE, 157 | &alpha, 158 | NULL, 159 | DISPMANX_NO_ROTATE); 160 | 161 | vc_dispmanx_update_submit_sync(update); 162 | 163 | vc_dispmanx_resource_read_data(rd->dstRes, 164 | &(rd->dstRect), 165 | dst->buffer, 166 | dst->pitch); 167 | 168 | vc_dispmanx_element_remove(update, element); 169 | } 170 | 171 | //------------------------------------------------------------------------- 172 | 173 | -------------------------------------------------------------------------------- /lib/offscreen/resizeDispmanX.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2015 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef RESIZE_DISPMANX_H 29 | #define RESIZE_DISPMANX_H 30 | 31 | //------------------------------------------------------------------------- 32 | 33 | #include 34 | #include 35 | 36 | #include "bcm_host.h" 37 | 38 | #include "image.h" 39 | 40 | //------------------------------------------------------------------------- 41 | 42 | typedef struct 43 | { 44 | int16_t destinationWidth; 45 | int16_t destinationHeight; 46 | int16_t sourceWidth; 47 | int16_t sourceHeight; 48 | int32_t xRatio; 49 | int32_t yRatio; 50 | VC_IMAGE_TYPE_T type; 51 | DISPMANX_RESOURCE_HANDLE_T dstRes; 52 | DISPMANX_RESOURCE_HANDLE_T srcRes; 53 | DISPMANX_DISPLAY_HANDLE_T display; 54 | VC_RECT_T bmpRect; 55 | VC_RECT_T srcRect; 56 | VC_RECT_T dstRect; 57 | } RESIZE_DISPMANX_T; 58 | 59 | //------------------------------------------------------------------------- 60 | 61 | void 62 | initResizeDispmanX( 63 | RESIZE_DISPMANX_T *rd, 64 | VC_IMAGE_TYPE_T type, 65 | int16_t dWidth, 66 | int16_t dHeight, 67 | int16_t sWidth, 68 | int16_t sHeight, 69 | bool keepAspectRatio); 70 | 71 | void 72 | destroyResizeDispmanX( 73 | RESIZE_DISPMANX_T *rd); 74 | 75 | void 76 | resizeDispmanX( 77 | RESIZE_DISPMANX_T *rd, 78 | IMAGE_T *dst, 79 | IMAGE_T *src); 80 | 81 | //------------------------------------------------------------------------- 82 | 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /lib/pngview/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=pngview.o 2 | BIN=pngview 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common $(shell libpng-config --cflags) 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm $(shell libpng-config --ldflags) -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/pngview/README.md: -------------------------------------------------------------------------------- 1 | # pngview 2 | 3 | Utility to display a PNG image on the Raspberry Pi screen using the Dispmanx windowing system. Press Esc key to exit. Use 'w', 's', 'a' and 'd' keys to move the image on screen. Use '+' and '-' keys to change the number of pixels the image moves (default is 1). 4 | 5 | Usage: pngview [-b ] [-d ] [-l ] [-x ] [-y ] 6 | 7 | -b - set background colour 16 bit RGBA 8 | e.g. 0x000F is opaque black 9 | -d - Raspberry Pi display number 10 | -l - DispmanX layer number 11 | -x - offset (pixels from the left) 12 | -y - offset (pixels from the top) 13 | -n - non-interactive mode 14 | 15 | -------------------------------------------------------------------------------- /lib/pngview/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/radar_sweep/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=radar_sweep.o 2 | BIN=radar_sweep 3 | 4 | CFLAGS+=-Wall -O3 -g -I../common 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/radar_sweep/README.md: -------------------------------------------------------------------------------- 1 | # radar_sweep 2 | 3 | Displays a 'radar sweep' animation. The program manipulates the palette to 4 | generate the animation. Press 'Esc' to exit the program. 5 | 6 | -------------------------------------------------------------------------------- /lib/radar_sweep/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/radar_sweep_alpha/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=radar_sweep_alpha.o 2 | BIN=radar_sweep_alpha 3 | 4 | CFLAGS+=-Wall -O3 -g -I../common 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/radar_sweep_alpha/README.md: -------------------------------------------------------------------------------- 1 | # radar_sweep_alpha 2 | 3 | Displays a 'radar sweep' animation. The program manipulates the palettes 4 | transparency (alpha) to generate the animation. Press 'Esc' to exit the 5 | program. 6 | 7 | -------------------------------------------------------------------------------- /lib/radar_sweep_alpha/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/rgb_triangle/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=rgb_triangle.o 2 | BIN=rgb_triangle 3 | 4 | CFLAGS+=-Wall -O3 -g -I../common 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/rgb_triangle/README.md: -------------------------------------------------------------------------------- 1 | # rgb_triangle 2 | 3 | Displays a triangle in a layer with red, green and blue gradients starting 4 | at each corner respectively. Blends to grey in the center. Pressing 'a' 5 | causes the triangle to move across the screen. The size of the triangle can 6 | be changed using '+' and '-'. Press 'Esc' to exit the program. 7 | 8 | -------------------------------------------------------------------------------- /lib/rgb_triangle/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/spriteview/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=spriteview.o 2 | BIN=spriteview 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common $(shell libpng-config --cflags) 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm $(shell libpng-config --ldflags) -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/spriteview/README.md: -------------------------------------------------------------------------------- 1 | # spriteview 2 | 3 | Animated sprite viewer. 4 | 5 | If in interactive mode (default): Press 'Esc' to exit. Press 'p' to pause and 6 | then use space bar to step through animation. 7 | 8 | If in non-interactive mode (-n): Set a timeout=0 "-t 0" to run infinitelly or 9 | different to 0 to run for a certain time, e.g: "-t 3000" to run for 3 seconds. 10 | An interval between animation steps can be set, e.g: "-i 500" (it changes after 0.5 s). 11 | 12 | -------------------------------------------------------------------------------- /lib/spriteview/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/test_pattern/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=test_pattern.o 2 | BIN=test_pattern 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/test_pattern/README.md: -------------------------------------------------------------------------------- 1 | # test_pattern 2 | 3 | This test pattern should be familiar to anyone who has used the Raspberry 4 | Pi. It is the same four colour square displayed when the Raspberry Pi boots. 5 | This is a very simple demonstation of the DispmanX interface. Two layers are 6 | created. The first layer is a black background (used to hide the frame 7 | buffer) consisting of a single pixel that is stretched to the screen 8 | extents. The second layer consists of four pixels (2x2) that are stretched 9 | to the height of the screen. 10 | 11 | -------------------------------------------------------------------------------- /lib/test_pattern/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/worms/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=main.o worms.o 2 | BIN=worms 3 | 4 | CFLAGS+=-Wall -g -O3 -I../common 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm -L../lib -lraspidmx 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic 17 | 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /lib/worms/README.md: -------------------------------------------------------------------------------- 1 | # Worms 2 | 3 | The idea for the worms came from an article in Scientific American 4 | (December 1987) called Computer Recreations: Simple special effects 5 | illustrate the art of converting algorithms into programs written by A. K. 6 | Dewdney 7 | 8 | The worms use a simple algorithm to randomly change direction by a few 9 | degrees each iteration. 10 | 11 | Unlike the other demonstations, a transparent background layer is created by 12 | default. The worms will crawl over the frame buffer. Press 'Esc' to exit. 13 | 14 | -------------------------------------------------------------------------------- /lib/worms/main.c: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #define _GNU_SOURCE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "bcm_host.h" 38 | 39 | #include "backgroundLayer.h" 40 | #include "image.h" 41 | #include "key.h" 42 | #include "worms.h" 43 | 44 | //----------------------------------------------------------------------- 45 | 46 | #define NDEBUG 47 | 48 | //----------------------------------------------------------------------- 49 | 50 | const char *program = NULL; 51 | 52 | //------------------------------------------------------------------------- 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | int opt = 0; 57 | 58 | const char* imageTypeName = "RGBA32"; 59 | VC_IMAGE_TYPE_T imageType = VC_IMAGE_MIN; 60 | uint16_t background = 0x0000; 61 | uint32_t displayNumber = 0; 62 | 63 | program = basename(argv[0]); 64 | 65 | //------------------------------------------------------------------- 66 | 67 | while ((opt = getopt(argc, argv, "b:d:t:")) != -1) 68 | { 69 | switch (opt) 70 | { 71 | case 'b': 72 | 73 | background = strtol(optarg, NULL, 16); 74 | break; 75 | 76 | case 'd': 77 | 78 | displayNumber = strtol(optarg, NULL, 10); 79 | break; 80 | 81 | case 't': 82 | 83 | imageTypeName = optarg; 84 | break; 85 | 86 | default: 87 | 88 | fprintf(stderr, "Usage: %s \n", program); 89 | fprintf(stderr, "[-b ] [-d ] [-t ]\n"); 90 | fprintf(stderr, " -b - set background colour 16 bit RGBA\n"); 91 | fprintf(stderr, " e.g. 0x000F is opaque black\n"); 92 | fprintf(stderr, " -d - Raspberry Pi display number\n"); 93 | fprintf(stderr, " -t - type of image to create\n"); 94 | fprintf(stderr, " can be one of the following:"); 95 | printImageTypes(stderr, 96 | " ", 97 | "", 98 | IMAGE_TYPES_WITH_ALPHA | 99 | IMAGE_TYPES_DIRECT_COLOUR); 100 | fprintf(stderr, "\n"); 101 | 102 | exit(EXIT_FAILURE); 103 | break; 104 | } 105 | } 106 | 107 | //------------------------------------------------------------------- 108 | 109 | IMAGE_TYPE_INFO_T typeInfo; 110 | 111 | if (findImageType(&typeInfo, 112 | imageTypeName, 113 | IMAGE_TYPES_WITH_ALPHA | IMAGE_TYPES_DIRECT_COLOUR)) 114 | { 115 | imageType = typeInfo.type; 116 | } 117 | else 118 | { 119 | fprintf(stderr, 120 | "%s: unknown image type %s\n", 121 | program, 122 | imageTypeName); 123 | 124 | exit(EXIT_FAILURE); 125 | } 126 | 127 | //--------------------------------------------------------------------- 128 | 129 | bcm_host_init(); 130 | 131 | //--------------------------------------------------------------------- 132 | 133 | DISPMANX_DISPLAY_HANDLE_T display 134 | = vc_dispmanx_display_open(displayNumber); 135 | assert(display != 0); 136 | 137 | //--------------------------------------------------------------------- 138 | 139 | DISPMANX_MODEINFO_T info; 140 | int result = vc_dispmanx_display_get_info(display, &info); 141 | assert(result == 0); 142 | 143 | //--------------------------------------------------------------------- 144 | 145 | BACKGROUND_LAYER_T backgroundLayer; 146 | initBackgroundLayer(&backgroundLayer, background, 0); 147 | 148 | //--------------------------------------------------------------------- 149 | 150 | uint16_t number_of_worms = 36; 151 | uint16_t worm_length = 25; 152 | WORMS_T worms; 153 | 154 | initWorms(number_of_worms, worm_length, &worms, imageType, &info); 155 | 156 | //--------------------------------------------------------------------- 157 | 158 | DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0); 159 | assert(update != 0); 160 | 161 | addElementWorms(&worms, display, update); 162 | addElementBackgroundLayer(&backgroundLayer, display, update); 163 | 164 | result = vc_dispmanx_update_submit_sync(update); 165 | assert(result == 0); 166 | 167 | //--------------------------------------------------------------------- 168 | 169 | struct timeval start_time; 170 | gettimeofday(&start_time, NULL); 171 | 172 | //--------------------------------------------------------------------- 173 | 174 | int c = 0; 175 | uint32_t frame = 0; 176 | 177 | while (c != 27) 178 | { 179 | keyPressed(&c); 180 | 181 | //----------------------------------------------------------------- 182 | 183 | undrawWorms(&worms); 184 | updateWorms(&worms); 185 | drawWorms(&worms); 186 | writeDataWorms(&worms); 187 | 188 | //----------------------------------------------------------------- 189 | 190 | update = vc_dispmanx_update_start(0); 191 | assert(update != 0); 192 | 193 | changeSourceWorms(&worms, update); 194 | 195 | result = vc_dispmanx_update_submit_sync(update); 196 | assert(result == 0); 197 | 198 | //----------------------------------------------------------------- 199 | 200 | ++frame; 201 | } 202 | 203 | //--------------------------------------------------------------------- 204 | 205 | struct timeval end_time; 206 | gettimeofday(&end_time, NULL); 207 | 208 | struct timeval diff; 209 | timersub(&end_time, &start_time, &diff); 210 | 211 | int32_t time_taken = (diff.tv_sec * 1000000) + diff.tv_usec; 212 | double frames_per_second = (frame * 1000000.0) / time_taken; 213 | 214 | printf("%0.1f frames per second\n", frames_per_second); 215 | 216 | //--------------------------------------------------------------------- 217 | 218 | keyboardReset(); 219 | 220 | //--------------------------------------------------------------------- 221 | 222 | destroyBackgroundLayer(&backgroundLayer); 223 | destroyWorms(&worms); 224 | 225 | //--------------------------------------------------------------------- 226 | 227 | result = vc_dispmanx_display_close(display); 228 | assert(result == 0); 229 | 230 | //--------------------------------------------------------------------- 231 | 232 | return 0; 233 | } 234 | 235 | -------------------------------------------------------------------------------- /lib/worms/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/worms/worms.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------- 2 | // 3 | // The MIT License (MIT) 4 | // 5 | // Copyright (c) 2013 Andrew Duncan 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a 8 | // copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included 16 | // in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | //------------------------------------------------------------------------- 27 | 28 | #ifndef WORMS_H 29 | #define WORMS_H 30 | 31 | //------------------------------------------------------------------------- 32 | 33 | #include "image.h" 34 | 35 | #include "bcm_host.h" 36 | 37 | //------------------------------------------------------------------------- 38 | 39 | typedef struct 40 | { 41 | double x; 42 | double y; 43 | } COORD_T; 44 | 45 | typedef struct 46 | { 47 | RGBA8_T colour; 48 | double direction; 49 | uint16_t head; 50 | uint16_t size; 51 | COORD_T *body; 52 | } WORM_T; 53 | 54 | typedef struct 55 | { 56 | uint16_t size; 57 | WORM_T *worms; 58 | IMAGE_T image; 59 | DISPMANX_RESOURCE_HANDLE_T frontResource; 60 | DISPMANX_RESOURCE_HANDLE_T backResource; 61 | DISPMANX_ELEMENT_HANDLE_T element; 62 | } WORMS_T; 63 | 64 | //------------------------------------------------------------------------- 65 | 66 | void 67 | initWorms( 68 | uint16_t number, 69 | uint16_t length, 70 | WORMS_T *worms, 71 | VC_IMAGE_TYPE_T imageType, 72 | DISPMANX_MODEINFO_T *info); 73 | 74 | void updateWorms(WORMS_T *worms); 75 | void drawWorms(WORMS_T *worms); 76 | void undrawWorms(WORMS_T *worms); 77 | 78 | void 79 | addElementWorms( 80 | WORMS_T *worms, 81 | DISPMANX_DISPLAY_HANDLE_T display, 82 | DISPMANX_UPDATE_HANDLE_T update); 83 | void writeDataWorms(WORMS_T *worms); 84 | void changeSourceWorms(WORMS_T *worms, DISPMANX_UPDATE_HANDLE_T update); 85 | 86 | void destroyWorms(WORMS_T *worms); 87 | 88 | //------------------------------------------------------------------------- 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /overlays/batteryInfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/batteryInfo.png -------------------------------------------------------------------------------- /overlays/calibration1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/calibration1.png -------------------------------------------------------------------------------- /overlays/calibration2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/calibration2.png -------------------------------------------------------------------------------- /overlays/calibration3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/calibration3.png -------------------------------------------------------------------------------- /overlays/lowbatterywarning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/lowbatterywarning.png -------------------------------------------------------------------------------- /overlays/mainMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/mainMenu.png -------------------------------------------------------------------------------- /overlays/menuDot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/menuDot.png -------------------------------------------------------------------------------- /overlays/settingsMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/overlays/settingsMenu.png -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | OBJS=retrolite.o 2 | BIN=retrolite 3 | 4 | CFLAGS+=-Wall -g -O3 -I./lib/common $(shell libpng-config --cflags) 5 | LDFLAGS+=-L/opt/vc/lib/ -lbcm_host -lm $(shell libpng-config --ldflags) -L./lib/lib -lraspidmx -lwiringPi -lSDL2 6 | 7 | INCLUDES+=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I/usr/include/SDL2 8 | 9 | all: $(BIN) 10 | 11 | %.o: %.c 12 | @rm -f $@ 13 | $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations 14 | 15 | $(BIN): $(OBJS) 16 | $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -pthread -Wl,--no-whole-archive -rdynamic 17 | chmod +x $@ 18 | clean: 19 | @rm -f $(OBJS) 20 | @rm -f $(BIN) 21 | -------------------------------------------------------------------------------- /src/config: -------------------------------------------------------------------------------- 1 | 4000 3.099998 60 0 10 1 2 | -------------------------------------------------------------------------------- /src/hdmi_switch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ### BEGIN INIT INFO 3 | # Provides: startup.sh 4 | # Required-Start: $remote_fs $syslog 5 | # Required-Stop: $remote_fs $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: Start daemon at boot time 9 | # Description: Enable service provided by daemon. 10 | ### END INIT INFO 11 | 12 | #. /lib/lsb/init-functions 13 | 14 | # HDMI Switcher - Retro Lite CM4 Handheld 15 | # Purpose: To switch between the internal HDMI0 driven screen and the external HDMI1 monitor. Switch off internal screen when hotplug detected. 16 | # Created by: Benjamin Todd 17 | # Date: 2021/12/17 18 | 19 | # Variables 20 | REBOOT_REQUIRED=false 21 | CONFIG=/boot/config.txt 22 | LOADMOD=/etc/modules 23 | AUDIO=/home/pi/.asoundrc 24 | 25 | screenCheck(){ 26 | # Detects whether external HDMI1 HPD is high and external video should be output. Then, setup config.txt accordingly 27 | DISPLAYS=$(tvservice -v 7 -s) 28 | if [[ "${DISPLAYS}" == *"0xa"* ]]; then 29 | if [ -e $CONFIG || -e $AUDIO ] && grep -q -E "^hdmi_drive:0=1$" $CONFIG; then 30 | # Turn on HDMI 1920 x 1080p video 31 | sudo sed -i "s|^hdmi_group:0=2$|hdmi_group:1=2|" $CONFIG 32 | sudo sed -i "s|^hdmi_mode:0=87$|hdmi_mode:1=82|" $CONFIG 33 | sudo sed -i "s|^hdmi_cvt:0=800 480 60 6 0 0 0$|#hdmi_cvt:0=800 480 60 6 0 0 0|" $CONFIG 34 | sudo sed -i "s|^hdmi_force_hotplug:0=1$|#hdmi_force_hotplug:0=1|" $CONFIG 35 | sudo sed -i "s|^hdmi_drive:0=1$|hdmi_drive:1=2|" $CONFIG 36 | # Turn off i2s audio and turn on HDMI audio 37 | sudo sed -i "s|^dtparam=i2s=on$|#dtparam=i2s=on|" $CONFIG 38 | sudo sed -i "s|^dtoverlay=i2s-mmap$|#dtoverlay=i2s-mmap|" $CONFIG 39 | sudo sed -i "s|^#dtparam=audio=on$|dtparam=audio=on|" $CONFIG 40 | sudo sed -i "s|^slave.pcm "\""dmixed"\""$|slave.pcm "\""output"\""|" $AUDIO 41 | # Turn off backlight 42 | sudo sed -i "s|^gpio=12=pd,dl,op$|gpio=12=pu,dh,op|" $CONFIG 43 | # Turn on overclock 44 | sudo sed -i "s|^#arm_freq=2100$|arm_freq=2100|" $CONFIG 45 | sudo sed -i "s|^#gpu_freq=750$|gpu_freq=750|" $CONFIG 46 | sudo sed -i "s|^#over_voltage=6$|over_voltage=6|" $CONFIG 47 | 48 | sudo cp ~/asound.conf.hdmi /etc/asound.conf 49 | if [ -e $LOADMOD ] && grep -q "^#snd-bcm2835" $LOADMOD; then 50 | #Turn on HDMI audio 51 | sudo sed -i "s|^#snd-bcm2835|snd-bcm2835|" $LOADMOD 52 | fi 53 | REBOOT_REQUIRED=true 54 | fi 55 | else 56 | if [[ "${DISPLAYS}" == *"0x9"* || *"Invalid"* ]]; then 57 | if [ -e $CONFIG ] && grep -q -E "^hdmi_drive:1=2$" $CONFIG; then 58 | # Turn on HDMI 800x480p video 59 | sudo sed -i "s|^hdmi_group:1=2$|hdmi_group:0=2|" $CONFIG 60 | sudo sed -i "s|^hdmi_mode:1=82$|hdmi_mode:0=87|" $CONFIG 61 | sudo sed -i "s|^#hdmi_cvt:0=800 480 60 6 0 0 0$|hdmi_cvt:0=800 480 60 6 0 0 0|" $CONFIG 62 | sudo sed -i "s|^#hdmi_force_hotplug:0=1$|hdmi_force_hotplug:0=1|" $CONFIG 63 | sudo sed -i "s|^hdmi_drive:1=2$|hdmi_drive:0=1|" $CONFIG 64 | # Turn on i2s audio and turn off HDMI audio 65 | sudo sed -i "s|^#dtoverlay=i2s-mmap$|dtoverlay=i2s-mmap|" $CONFIG 66 | sudo sed -i "s|^#dtparam=i2s=on$|dtparam=i2s=on|" $CONFIG 67 | sudo sed -i "s|^dtparam=audio=on$|#dtparam=audio=on|" $CONFIG 68 | sudo sed -i "s|^slave.pcm "\""output"\""$|slave.pcm "\""dmixed"\""|" $AUDIO 69 | # Turn on backlight 70 | sudo sed -i "s|^gpio=12=pu,dh,op$|gpio=12=pd,dl,op|" $CONFIG 71 | # Turn off overclock 72 | sudo sed -i "s|^arm_freq=2100$|#arm_freq=2100|" $CONFIG 73 | sudo sed -i "s|^gpu_freq=750$|#gpu_freq=750|" $CONFIG 74 | sudo sed -i "s|^over_voltage=6$|#over_voltage=6|" $CONFIG 75 | 76 | sudo cp ~/asound.conf.lcd /etc/asound.conf 77 | if [ -e $LOADMOD ] && grep -q "^snd-bcm2835" $LOADMOD; then 78 | sudo sed -i "s|^snd-bcm2835|#snd-bcm2835|" $LOADMOD 79 | fi 80 | REBOOT_REQUIRED=true 81 | fi 82 | fi 83 | fi 84 | } 85 | 86 | start(){ 87 | while true 88 | do 89 | screenCheck 90 | sleep 10 91 | if $REBOOT_REQUIRED; then 92 | reboot 93 | fi 94 | done 95 | } 96 | 97 | start 98 | 99 | exit 0 100 | -------------------------------------------------------------------------------- /src/keycodes.h: -------------------------------------------------------------------------------- 1 | #ifndef KEYCODES_H_ 2 | #define KEYCODES_H_ 3 | 4 | #define esc 27 5 | #define backspace 8 6 | #define enter 13 7 | #define right 14 8 | #define left 15 9 | 10 | 11 | char osKeyboardLowercase[5][10] = { 12 | {esc, left, right, 32, 45, 47, enter, 0, 0, 0}, 13 | {0, 122, 120, 99, 118, 98, 110, 109, 44, backspace}, 14 | {97, 115, 100, 102, 103, 104, 106, 107, 108, 46}, 15 | {113, 119, 101, 114, 116, 121, 117, 105, 111, 112}, 16 | {49, 50, 51, 52, 53, 54, 55, 56, 57, 48} 17 | }; 18 | char osKeyboardUppercase[5][10] = { 19 | {esc, left, right, 32, 95, 63, enter, 0, 0, 0}, 20 | {0, 90, 88, 67, 86, 66, 78, 77, 60, backspace}, 21 | {65, 83, 68, 70, 71, 72, 74, 75, 76, 62}, 22 | {81, 87, 69, 82, 84, 89, 85, 73, 79, 80}, 23 | {33, 64, 35, 36, 37, 94, 38, 42, 40, 41} 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/max17055.h: -------------------------------------------------------------------------------- 1 | float getSOC(); 2 | int getCapacity(); 3 | int getRemainingCapacity(); 4 | float getInstantaneousCurrent(); 5 | float getInstantaneousVoltage(); 6 | float getTimeToEmpty(); 7 | void max17055Init(); 8 | float getTimeToFull(); 9 | 10 | 11 | /* 12 | * This macro converts empty voltage target (VE) and recovery voltage (VR) 13 | * in mV to max17055 0x3a reg value. max17055 declares 0% (empty battery) at 14 | * VE. max17055 reenables empty detection when the cell voltage rises above VR. 15 | * VE ranges from 0 to 5110mV, and VR ranges from 0 to 5080mV. 16 | */ 17 | 18 | #define MAX17055_VEMPTY_REG(ve_mv, vr_mv) \ 19 | (((ve_mv / 10) << 7) | (vr_mv / 40)) 20 | 21 | float getSOC() { 22 | int SOC_raw = wiringPiI2CReadReg16(I2CDevice, RepSOC); 23 | return SOC_raw * percentage_multiplier; 24 | } 25 | 26 | int getCapacity() { 27 | int capacity_raw = wiringPiI2CReadReg16(I2CDevice, DesignCap); 28 | capacity_raw = capacity_raw * capacity_multiplier_mAH; 29 | return (capacity_raw); 30 | } 31 | 32 | int getRemainingCapacity() { 33 | int remainingCapacity_raw = wiringPiI2CReadReg16(I2CDevice, RepCap); 34 | remainingCapacity_raw = remainingCapacity_raw * capacity_multiplier_mAH; 35 | return (remainingCapacity_raw); 36 | } 37 | 38 | float getInstantaneousCurrent() { 39 | int16_t current_raw = wiringPiI2CReadReg16(I2CDevice, Current); 40 | return current_raw * current_multiplier_mV; 41 | } 42 | 43 | float getInstantaneousVoltage() { 44 | int voltage_raw = wiringPiI2CReadReg16(I2CDevice, VCell); 45 | return voltage_raw * voltage_multiplier_V; 46 | } 47 | 48 | float getTimeToEmpty() { 49 | int TTE_raw = wiringPiI2CReadReg16(I2CDevice, TimeToEmpty); 50 | return TTE_raw * time_multiplier_Hours; 51 | } 52 | 53 | float getTimeToFull() { 54 | int TTF_raw = wiringPiI2CReadReg16(I2CDevice, TimeToFull); 55 | return TTF_raw * time_multiplier_Hours; 56 | } 57 | 58 | uint16_t getVEmpty() { 59 | uint16_t VEmpty_raw = wiringPiI2CReadReg16(I2CDevice, 0x3A); 60 | return (((VEmpty_raw >> 7) & 0x1FF) * 10); 61 | } 62 | 63 | void max17055Init() { 64 | int StatusPOR = wiringPiI2CReadReg16(I2CDevice, 0x00) & 0x0002; 65 | int currentCapacity = getCapacity(); 66 | if (currentCapacity != batteryCapacity) { 67 | printf("Updating battery Capacity from %dmah to %dmah\n", currentCapacity, batteryCapacity); 68 | StatusPOR = 1; //Force re-config 69 | } 70 | if (StatusPOR == 0) { //If no re-config neccessary 71 | getCapacity(); 72 | getSOC(); 73 | } else { //Initial Config 74 | while (wiringPiI2CReadReg16(I2CDevice, 0x3D) & 1) { 75 | delay(10); 76 | } 77 | wiringPiI2CWriteReg16(I2CDevice, 0x18, (batteryCapacity / capacity_multiplier_mAH)); //Write DesignCap 78 | wiringPiI2CWriteReg16(I2CDevice, 0x45, (int)(batteryCapacity / capacity_multiplier_mAH) / 32); //Write dQAcc 79 | wiringPiI2CWriteReg16(I2CDevice, 0x1E, 0x666); //256mA); //Write IchgTerm 80 | wiringPiI2CWriteReg16(I2CDevice, 0x3A, MAX17055_VEMPTY_REG((int)lowVoltageThreshold * 1000, 3880)); //3.1V //Write VEmpty, convert to mV 81 | int HibCFG = wiringPiI2CReadReg16(I2CDevice, 0xBA); //Store original HibCFG value 82 | wiringPiI2CWriteReg16(I2CDevice, 0x60, 0x90); //Exit Hibernate Mode Step 1 83 | wiringPiI2CWriteReg16(I2CDevice, 0xBA, 0x0); //Exit Hibernate Mode Step 2 84 | wiringPiI2CWriteReg16(I2CDevice, 0x60, 0x0); //Exit Hibernate Mode Step 3 85 | 86 | if (ChargeVoltage > 4.275) { 87 | wiringPiI2CWriteReg16(I2CDevice, 0x46, (int)((batteryCapacity / capacity_multiplier_mAH) / 32) * 51200 / (batteryCapacity / capacity_multiplier_mAH)); 88 | wiringPiI2CWriteReg16(I2CDevice, 0xDB, 0x8400); 89 | } else { 90 | wiringPiI2CWriteReg16(I2CDevice, 0x46, (int)((batteryCapacity / capacity_multiplier_mAH) / 32) * 44138 / (batteryCapacity / capacity_multiplier_mAH)); 91 | wiringPiI2CWriteReg16(I2CDevice, 0xDB, 0x8000); 92 | } 93 | 94 | while (wiringPiI2CReadReg16(I2CDevice, 0xDB) & 0x8000) { 95 | delay(10); 96 | } 97 | wiringPiI2CWriteReg16(I2CDevice, 0xBA, HibCFG); 98 | 99 | max17055_Status = wiringPiI2CReadReg16(I2CDevice, 0x00); 100 | wiringPiI2CWriteReg16(I2CDevice, 0x00, Status & 0xFFFD); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/retrolite.h: -------------------------------------------------------------------------------- 1 | //#ifndef RETROLITE_H_ 2 | //#define RETROLITE_H_ 3 | 4 | #define esc 27 5 | #define backspace 8 6 | #define enter 13 7 | #define right 14 8 | #define left 15 9 | #define up 17 10 | #define down 18 11 | 12 | #define true 1 13 | #define false 0 14 | 15 | volatile bool run = true; 16 | 17 | //I2C MAX17055 Registers 18 | static int Status = 0x00; 19 | static int VCell = 0x09; 20 | //static int AvgVCell = 0x19; 21 | static int Current = 0x0A; 22 | //static int AvgCurrent = 0x0B; 23 | static int RepSOC = 0x06; 24 | static int RepCap = 0x05; 25 | static int TimeToEmpty = 0x11; 26 | static int TimeToFull = 0x20; 27 | static int DesignCap = 0x18; 28 | 29 | //GPIO Pins 30 | static int volUp_button = 5; //Volume Up Button BCM = 19 wPi = 24 31 | static int volDn_button = 16; //Volume Down Button BCM = 15 wPi = 16 32 | static int pwr_button = 6; //Software Power Button from ATTINY BCM = 25 wPi = 6 33 | static int charge_detect = 7; //Pin goes low when charger is connected. BCM = 4 wPi = 7 34 | static int pwm_Brightness = 26; //BCM = 12 wPi = 26 35 | static int fan_pwm = 23; //BCM = 13, wPi = 23 36 | static int low_voltage_shutdown = 27; // BCM = 16, wPi = 27 37 | static int hpd_detect = 15; //BCM = 14, wPi = 15 38 | 39 | //MAX17055 40 | static int I2CAddress = 0x36; //0x36 Fuel Gauge, 0x48 ADS1115; 41 | int I2CDevice; 42 | int batteryCapacity = 4000; //0x1F40; 43 | 44 | //Display 45 | int displayX = 800; 46 | int displayY = 480; 47 | int displaySelect = 0; //Select HDMI. 0 for internal, 1 for External 48 | static int statusIconSize = 18; //Size of status icon images 49 | static int fontWidth = 8; 50 | static int overlayImageX = 500; //Number of X pixels in overlay image 51 | static int overlayImageY = 250; //Number of Y pixels in overlay image 52 | int brightness = 100; //Default Full brightness 53 | int darkMode = 0; //Default light text/battery mode 54 | //PNGview Variables 55 | uint32_t displayNumber; 56 | VC_IMAGE_TYPE_T type; 57 | DISPMANX_DISPLAY_HANDLE_T display; 58 | DISPMANX_MODEINFO_T info; 59 | static int layer = 30000; 60 | int result; 61 | DISPMANX_UPDATE_HANDLE_T update; 62 | //Layers 63 | IMAGE_LAYER_T infoLayer; 64 | int infoLayerEN = false; 65 | IMAGE_LAYER_T kbdLayer; 66 | int kbdLayerEN = false; 67 | IMAGE_LAYER_T kbdHighlightLayer; 68 | int kbdHighlightLayerEN = false; 69 | IMAGE_LAYER_T batteryIconLayer; 70 | int batteryIconLayerEN = false; 71 | IMAGE_LAYER_T batteryPercentLayer; 72 | int batteryPercentLayerEN = false; 73 | IMAGE_LAYER_T volBrightLayer; 74 | int volBrightLayerEN = false; 75 | IMAGE_LAYER_T menuLayer; 76 | int menuLayerEN = false; 77 | IMAGE_LAYER_T menuTextLayer; 78 | int menuTextLayerEN = false; 79 | IMAGE_LAYER_T menuPointerLayer; 80 | int menuPointerLayerEN = false; 81 | 82 | 83 | //Controller Serial 84 | int controllerSerial = -1; 85 | int calibrationStep = 0; 86 | int calibrationStepChanged = false; 87 | int controllerDisconnected = false; 88 | static int brightnessUp = 0x00; 89 | static int brightnessDn = 0x01; 90 | static int calibrationStepOne = 0x02; 91 | static int calibrationStepTwo = 0x03; 92 | static int calibrationComplete = 0x04; 93 | static int osKeyboardEnabled = 0x05; //No Longer Needed 94 | static int osKeyboardLeft = 0x06; 95 | static int osKeyboardRight = 0x07; 96 | static int osKeyboardUp = 0x08; 97 | static int osKeyboardDn = 0x09; 98 | static int osKeyboardSelect = 0x10; 99 | static int osKeyboardDisabled = 0x11; //No Longer Needed 100 | static int menuOpen = 0x12; 101 | static int menuClose = 0x13; 102 | static int controllerError = 0x127; 103 | int osKeyboard = false; 104 | int menuEnabled = false; 105 | int menuUpdated = false; 106 | int menuSelected = 1; 107 | int menuDisplayed = 100; 108 | int menuActive = 0; // 0 = Main Menu, 1 = Battery Info, 2 = Controller Calibration, 3 = OSK, 4 = Settings 109 | int keyboardChanged = false; 110 | int keyboardDemo = false; //Change to true for a demo of the keyboard 111 | int keyCase = 0; //0 = LOWER CASE, 1 = UPPER CASE 112 | int lastKeyCase = 2; 113 | int keyboardRow = 0; //0-4 : 5 Rows in total 114 | int keyboardCollumn = 0; //0-10 : 10 Collumns in total (except first row only has 7) 115 | 116 | 117 | //Variables 118 | //static int i2c_ch = 1; 119 | //static float resistSensor = 0.01; 120 | static float capacity_multiplier_mAH = (5e-3)/0.01; 121 | static float current_multiplier_mV = 0.00015625; 122 | static float voltage_multiplier_V = 7.8125e-5; 123 | static float time_multiplier_Hours = 5.625/3600.0; 124 | static float percentage_multiplier = 1.0/256.0; 125 | int ioError = false; 126 | float ChargeVoltage = 4.2; 127 | int max17055_Status = 0; 128 | float currentTime = 0; 129 | float currentSOC = 0; 130 | float systemp; 131 | char level_Icon[60];// = "./batteryIcons/battery_full_white_18dp.png"; 132 | char overlayImage[60];// = "./overlays/calibration3.png"; 133 | char bar_Icon[60];// = "./volumeIcons/volume_bar_0.png"; 134 | char last_bar_Icon[60]; 135 | char keyboardHighlight[60];// = "./keyboard/00.png"; 136 | int controllerConnected = 0; 137 | int volume = 100; 138 | int chargeStep = 0; //Used for charging animation 139 | int charging = false; 140 | int cpuFanThreshold = 55; //Temperature fan starts running at. Default 65 141 | int fanSpeed = 0; 142 | float lowVoltageThreshold = 3.1; //If voltage drops below this value, engage auto shut down. 143 | int batteryLevelChanged = false; 144 | int volBrightPressed = false; 145 | //char tempSTR[60]; 146 | char batteryText[5]; 147 | int hpd_change = false; 148 | 149 | //Timers 150 | unsigned int chargeIconTimer; 151 | unsigned int endCalibrationTimer; 152 | unsigned int iconTimer = 0; 153 | int calibrationTimerStarted = false; 154 | int shutdownTimerStarted = false; 155 | unsigned int shutdownTimer; 156 | unsigned int GPIOTimer; 157 | unsigned int demoTimer; 158 | unsigned int testTimer; 159 | int testBool = true; 160 | 161 | //Colours 162 | static RGBA8_T clearColor = {0,0,0,0}; 163 | //static RGBA8_T backgroundColour = { 0, 0, 0, 100 }; 164 | static RGBA8_T whiteColour = { 255, 255, 255, 255 }; 165 | static RGBA8_T blackColour = { 0, 0, 0, 255 }; 166 | //static RGBA8_T greenColour = { 0, 255, 0, 200 }; 167 | //static RGBA8_T redColour = { 255, 0, 0, 200 }; 168 | 169 | 170 | //Functions 171 | void updateInfo(IMAGE_LAYER_T*, char[]); 172 | void getInput(); 173 | void clearLayer(IMAGE_LAYER_T*); 174 | void updateBattery(float, IMAGE_LAYER_T*); 175 | char *getcwd(char *buf, size_t size); 176 | int getControllerData(); 177 | void controllerInterface(); 178 | void loadValues(); 179 | void saveValues(); 180 | void updateBatteryImage(); 181 | void batteryChargingDisplay(); 182 | void checkGPIO(); 183 | void updateBatteryText(); 184 | void fanControl(); 185 | void checkResolution(); 186 | void displayImage(char address[60], int xPos, int yPos, IMAGE_LAYER_T* imgLayer, int layerOffset); 187 | void displayText(char address[60], int xPos, int yPos, IMAGE_LAYER_T* imgLayer, int layerOffset, RGBA8_T colour); 188 | void displaySetup(); 189 | float getSOC(); 190 | int getCapacity(); 191 | int getRemainingCapacity(); 192 | float getInstantaneousCurrent(); 193 | float getInstantaneousVoltage(); 194 | float getTimeToEmpty(); 195 | float getTimeToFull(); 196 | void max17055Init(); 197 | long map(long x, long in_min, long in_max, long out_min, long out_max); 198 | void settingValueChanged(int value); 199 | 200 | 201 | char osKeyboardLowercase[5][10] = { 202 | {esc, left, right, 32, 45, 47, enter, 0, 0, 0}, 203 | {0, 122, 120, 99, 118, 98, 110, 109, 44, backspace}, 204 | {97, 115, 100, 102, 103, 104, 106, 107, 108, 46}, 205 | {113, 119, 101, 114, 116, 121, 117, 105, 111, 112}, 206 | {49, 50, 51, 52, 53, 54, 55, 56, 57, 48} 207 | }; 208 | char osKeyboardUppercase[5][10] = { 209 | {esc, up, down, 32, 95, 63, enter, 0, 0, 0}, 210 | {0, 90, 88, 67, 86, 66, 78, 77, 60, backspace}, 211 | {65, 83, 68, 70, 71, 72, 74, 75, 76, 62}, 212 | {81, 87, 69, 82, 84, 89, 85, 73, 79, 80}, 213 | {33, 64, 35, 36, 37, 94, 38, 42, 40, 41} 214 | }; 215 | 216 | //#endif 217 | -------------------------------------------------------------------------------- /volumeIcons/volume_bar_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_0.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_10.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_100.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_20.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_30.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_40.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_50.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_60.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_70.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_80.png -------------------------------------------------------------------------------- /volumeIcons/volume_bar_90.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StonedEdge/Retro-Lite-CM4/9642a33111b07b18fa1a937bbe148a00fdffcbd6/volumeIcons/volume_bar_90.png --------------------------------------------------------------------------------