Sunday, July 8, 2012

Enabling Composite Video on the Mele A1000 Set Top Box (AllWinner A10)

Just a quick program to enable the composite video interface on the Mele A1000 Set Top Box.
 /***  
  * Small program to enable composite video (NTSC) on Mele A1000  
  *  
  * Based on information from   
  * http://www.cnx-software.com/2012/04/28/how-to-create-your-own-debian-ubuntu-image-for-mele-a1000-allwinner-a10-based-stb/  
  * which shows how to enable the VGA interface  
  *  
  * Copyright (C) 2012 Lawrence Yu  
  *  
  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated   
  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation   
  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,   
  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  
  *  
  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of   
  * the Software.  
  *  
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO   
  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE   
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE   
  * SOFTWARE.  
 ***/   
   
 // --------------------------------------------------  
 // Includes  
 // --------------------------------------------------  
   #include <stdio.h>  
   #include <fcntl.h>  
   
 // --------------------------------------------------  
 // Constants  
 // --------------------------------------------------  
   #define DISP_CMD_TV_ON       0x180  
   #define DISP_CMD_TV_OFF      0x181  
   #define DISP_CMD_TV_SET_MODE    0x182  
   #define DISP_CMD_HDMI_OFF     0x1c1  
     
   #define NOARG 0x00  
   
 // --------------------------------------------------  
 // Global Variables  
 // --------------------------------------------------  
   int g_display;  
   
 // --------------------------------------------------  
 // Functions  
 // --------------------------------------------------  
   void cmd(unsigned long cmd, unsigned long argval) {  
     // Variables  
       unsigned long args[4];  
       int      ret;  
         
     // Send the command  
       args[0] = 0x00;  
       args[1] = argval;  
       args[2] = 0x00;  
       args[3] = 0x00;  
       ret = ioctl(g_display, cmd, (unsigned long)args);  
       printf("Sent Command %02X(%02X) = %02X\n", cmd, argval, ret);  
   }      
   
 // --------------------------------------------------  
 // Main Functions  
 // --------------------------------------------------  
   int main(int argc, char const *argv[]) {  
     // Initialize the display  
       g_display = open("/dev/disp", O_RDWR, 0);  
   
     // Turn off the HDMI  
       cmd(DISP_CMD_HDMI_OFF, NOARG);  
   
     // Turn off the TV  
       cmd(DISP_CMD_TV_OFF, NOARG);  
     
       // Set the TV Mode  
       cmd(DISP_CMD_TV_SET_MODE, 0x0e);  
   
     // Turn on the TV  
       cmd(DISP_CMD_TV_ON, NOARG);  
   }