embedded linux qt 支援 jpeg (static)

[尚未編譯]
1.準備QT source
2.準備libjpeg (http://www.ijg.org)
3.編譯libjpeg
4.configure QT 將 -qt-libjpeg 、 -I (include)和 -L(library)額外設定好
5.make install

[編譯完成]
1.尋找你install資料夾下plugins/imageformats是否有libqjpeg.so
2.將imageformats整個複製到embedded下的/lib/plugins
3.將libjpeg的so檔複製到複製到embedded下的/lib
4.設定環境變數 export QT_PLUGIN_PATH=/lib
5.將成試放入執行即可

[偵錯]
1.設定環境變數export QT_DEBUG_PLUGINS=1
2.執行程式
3.執行到jpeg的地方就會顯示有沒有載入成功

編譯出來的hex燒入後無反應

編譯出來的hex燒入後無反應
需要將底下的
C:\Texas Instruments\ZStack-CC2530-2.4.0\Projects\zstack\Tools\CC2530DB\f8w2530.xcl
修改到hex生成模式
找到下列這幾行
// Include these two lines when generating a .hex file for banked code model:
//-M(CODE)[(_CODEBANK_START+_FIRST_BANK_ADDR)-(_CODEBANK_END+_FIRST_BANK_ADDR)]*\
//_NR_OF_BANKS+_FIRST_BANK_ADDR=0x8000
將前面的註解去掉
// Include these two lines when generating a .hex file for banked code model:
-M(CODE)[(_CODEBANK_START+_FIRST_BANK_ADDR)-(_CODEBANK_END+_FIRST_BANK_ADDR)]*\
_NR_OF_BANKS+_FIRST_BANK_ADDR=0x8000
在重新編譯所生成的檔案就可以燒入並且會動
但是要是編成可以直接燒入執行的模式
會出現一個warring就是開啟這個所出現的
但不會有問題

z-stack cc2530 SPI code

z-stack cc2530 SPI code:
/*******************************************************
 *                 INCLUDES
 *******************************************************/
#include "hal_types.h"
#include "hal_spi.h"
#include "OSAL.h"
#include "OnBoard.h"
#include "hal_assert.h"

/******************************************************
 *                     CONSTANTS
 ******************************************************/
/*
  //control軟體控制
  P1.4 - CS
  //spi硬體控制
  P1.5 - CLK
  P1.6 - MOSI
  P1.7 - MISO
*/

#define HAL_SPI_CS_PORT 1
#define HAL_SPI_CS_PIN  4
#define HAL_SPI_CLK_PORT 1
#define HAL_SPI_CLK_PIN  5
#define HAL_SPI_MOSI_PORT 1
#define HAL_SPI_MOSI_PIN  6
#define HAL_SPI_MISO_PORT 1
#define HAL_SPI_MISO_PIN  7

/**************************************************

 *                       MACROS

 **************************************************/
#define HAL_IO_SET(port, pin, val)        HAL_IO_SET_PREP(port, pin, val)
#define HAL_IO_SET_PREP(port, pin, val)   st( P##port##_##pin## = val; )
#define HAL_CONFIG_IO_OUTPUT(port, pin, val)      HAL_CONFIG_IO_OUTPUT_PREP(port, pin, val)
#define HAL_CONFIG_IO_OUTPUT_PREP(port, pin, val) st( P##port##SEL &= ~BV(pin); \
                                                      P##port##_##pin## = val; \
                                                      P##port##DIR |= BV(pin); )
#define HAL_CONFIG_IO_PERIPHERAL(port, pin)      HAL_CONFIG_IO_PERIPHERAL_PREP(port, pin)
#define HAL_CONFIG_IO_PERIPHERAL_PREP(port, pin) st( P##port##SEL |= BV(pin); )
/*******************************************************
 *                   FUNCTIONS - API
 *******************************************************/

void HalSpi_HW_Init(void);

void HalSpiInit(void)
{
  HalSpi_HW_Init();
}

static void halSpi_ConfigSPI(void)
{
   uint8 baud_exponent;
   uint8 baud_mantissa;

  PERCFG |= 0x02;
  //設定硬體控制腳位
  HAL_CONFIG_IO_PERIPHERAL(HAL_SPI_CLK_PORT,  HAL_SPI_CLK_PIN);
  HAL_CONFIG_IO_PERIPHERAL(HAL_SPI_MOSI_PORT, HAL_SPI_MOSI_PIN);
  HAL_CONFIG_IO_PERIPHERAL(HAL_SPI_MISO_PORT, HAL_SPI_MISO_PIN);
  //設定傳輸速度
  baud_exponent = 10;
  baud_mantissa =  0;

  /* Configure SPI */
  U1UCR  = 0x80;
  U1CSR  = 0x00;
  //U1GCR  = HAL_SPI_TRANSFER_MSB_FIRST | HAL_SPI_CLOCK_PHA_0 | HAL_SPI_CLOCK_POL_LO | baud_exponent;//正緣觸發,正緣接收資料
  U1GCR  = HAL_SPI_TRANSFER_MSB_FIRST | 0x40 | HAL_SPI_CLOCK_POL_LO | baud_exponent;//正緣觸發,負緣接收資料
  U1BAUD = baud_mantissa;
}

void HalSpi_HW_Init(void)
{
  //設定基本output模式
  HAL_CONFIG_IO_OUTPUT(HAL_SPI_CS_PORT,    HAL_SPI_CS_PIN,    1);
  halSpi_ConfigSPI();
}

static void spi_tx(uint8 x)
{
  U1CSR &= ~((1<<2) | (1<<1));
  U1DBUF = x;
  while( !(U1CSR & (1<<1)) );
}

void HalSpi_Ad7763_Read(uint8 addr, uint8 *recv_data)
{
    //將CS腳位到LOW
    HAL_IO_SET(HAL_SPI_CS_PORT, HAL_SPI_CS_PIN, 0);  //begin
    addr &= 0x3f;//ADE7765讀取 8bit→0 7bit→0
    spi_tx(addr);//傳送
    spi_tx(0);
    *recv_data = U1DBUF;//接收
    spi_tx(0);
    *(recv_data+1) = U1DBUF;
    spi_tx(0);
    *(recv_data+2) = U1DBUF;
    asm("NOP");
    asm("NOP");
    asm("NOP");
    asm("NOP");
    //將CS腳位到HIGH
    HAL_IO_SET(HAL_SPI_CS_PORT, HAL_SPI_CS_PIN, 1);  //end
}

void HalSpi_Ad7763_Write(uint8 addr, uint16 send_data)
{
    //將CS腳位到LOW
    HAL_IO_SET(HAL_SPI_CS_PORT, HAL_SPI_CS_PIN, 0);  //begin
    addr |= 0x80;//ADE7765寫入 8bit→1 7bit→0
    spi_tx(addr);
    spi_tx((send_data&0xff00)>>8);
    spi_tx(send_data&0x00ff);
    asm("NOP");
    asm("NOP");
    asm("NOP");
    asm("NOP");
    //將CS腳位到HIGH
    HAL_IO_SET(HAL_SPI_CS_PORT, HAL_SPI_CS_PIN, 1);  //end
}

使用z-stack內部function且return處理

使用z-stack內部function
例如:
ZDP_NwkAddrReq()
ZDP_IEEEAddrReq()
等等....
使用方法請查看Z-Stack API.pdf
發送端送出指令給各個device
假設有device回應會在以下函數做處理並且return (並非所有函數都會預設啟動)
ZDP_NWKAddrRsp() 
ZDP_IEEEAddrRsp()
等等....

這時候發送端會接收到return的值
這時候就要做register
在你的
void SampleApp_Init( uint8 task_id )
裡面加上
ZDO_RegisterForZDOMsg(SampleApp_TaskID, NWK_addr_rsp);
NWK_addr_rsp在Z-Stack API.pdf裡面的文件有寫到對應的function
例如:
ZDP_NWKAddrRsp()→NWK_addr_rsp
ZDP_IEEEAddrRsp()→IEEE_addr_rsp 
接下來就要處理接收後的值
也就是在
uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
加上而外的判斷事件
在
switch ( MSGpkt->hdr.event )
裡面額外加上
case ZDO_CB_MSG:
例如:
if ( events & SYS_EVENT_MSG ) {
  MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
  while ( MSGpkt ) {
    switch ( MSGpkt->hdr.event ) {  
    case AF_INCOMING_MSG_CMD:
      SampleApp_MessageMSGCB( MSGpkt );
      break;
    case ZDO_CB_MSG:
      zdoapp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
      break; 
    default:
      break;
    }
    osal_msg_deallocate( (uint8 *)MSGpkt );
    MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
  }  
  return (events ^ SYS_EVENT_MSG);
}

接下來就在副程式
zdoapp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt )
去解析收到的值
例如:解析NWK_addr_rsp
void zdoapp_ProcessZDOMsgs(zdoIncomingMsg_t *inMsg )
{
  ZDO_NwkIEEEAddrResp_t *pAddrRsp;
  switch ( inMsg->clusterID ) {
  case NWK_addr_rsp:
    pAddrRsp = ZDO_ParseAddrRsp( inMsg );
    if ( pAddrRsp ) {
      if ( pAddrRsp->status == ZSuccess ) {
        pAddrRsp->nwkAddr;//short address
        pAddrRsp->extAddr;//MAC address
      }
      osal_mem_free( pAddrRsp );
    }
    break;
  }
}
要看如何解析的話請到
ZDProfile.c
因為要看他如何編譯就可以解析

Lattice Diamond PLL create

1.Tools→Ipexpress→PLL

2.
  • 輸入
    • file name:名子
    • module output:模組語言
  • cutomize
3.



  • 設定
    • CLKOP desired frequency(用來計算用)
  • actual frequency有值
  • calculate
  • generate

4.
沒有Error就算成功


5.
載入模組範例在"檔名_tmpl.v"下

imagecreatefrombmp用PHP讀取BMP

<?php
    function imagecreatefrombmp($p_sFile)
    {
        //    Load the image into a string
        $file    =    fopen($p_sFile,"rb");
        $read    =    fread($file,10);
        while(!feof($file)&&($read<>""))
            $read    .=    fread($file,1024);
       
        $temp    =    unpack("H*",$read);
        $hex    =    $temp[1];
        $header    =    substr($hex,0,108);
        //    Process the header
        //    Structure: http://www.fastgraph.com/help/bmp_header_format.html
        if (substr($header,0,4)=="424d")
        {
            //    Cut it in parts of 2 bytes
            $header_parts    =    str_split($header,2);
            //    Get the width        4 bytes
            $width            =    hexdec($header_parts[19].$header_parts[18]);
            //    Get the height        4 bytes
            $height            =    hexdec($header_parts[23].$header_parts[22]);
            //    Unset the header params
            unset($header_parts);
        }
        //    Define starting X and Y
        $x                =    0;
        $y                =    1;
        //    Create newimage
        $image            =    imagecreatetruecolor($width,$height);
        //    Grab the body from the image
        $body            =    substr($hex,108);
        //    Calculate if padding at the end-line is needed
        //    Divided by two to keep overview.
        //    1 byte = 2 HEX-chars
        $body_size        =    (strlen($body)/2);
        $header_size    =    ($width*$height);
        //    Use end-line padding? Only when needed
        $usePadding        =    ($body_size>($header_size*3)+4);
        //    Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
        //    Calculate the next DWORD-position in the body
        for ($i=0;$i<$body_size;$i+=3)
        {
            //    Calculate line-ending and padding
            if ($x>=$width) {
                //    If padding needed, ignore image-padding
                //    Shift i to the ending of the current 32-bit-block
                if ($usePadding)
                    $i    +=    $width%4;
                //    Reset horizontal position
                $x    =    0;
                //    Raise the height-position (bottom-up)
                $y++;
                //    Reached the image-height? Break the for-loop
                if ($y>$height)
                    break;
            }
            //    Calculation of the RGB-pixel (defined as BGR in image-data)
            //    Define $i_pos as absolute position in the body
            $i_pos    =    $i*2;
            $r        =    hexdec($body[$i_pos+4].$body[$i_pos+5]);
            $g        =    hexdec($body[$i_pos+2].$body[$i_pos+3]);
            $b        =    hexdec($body[$i_pos].$body[$i_pos+1]);
            $gray     =    (int)($r + $g + $b)/3;
            //    Calculate and draw the pixel
            $color    =    imagecolorallocate($image,$gray,$gray,$gray);
            imagesetpixel($image,$x,$height-$y,$color);
            //    Raise the horizontal position
            $x++;
        }
        //    Unset the body / free the memory
        unset($body);
        //    Return image-object
        return $image;
    }
    
    

Minimum spanning tree用PHP寫

<?php
    class Edge
    {
        public $v1;
        public $v2;
        public $weight;
       
        function Edge($v1, $v2, $weight)
        {
            $this->v1 = $v1;
            $this->v2 = $v2;
            $this->weight = $weight;
        }
    }
   
    class Vertex
    {
        public $nRank;
        public $vRoot;
        public $name;

        function Vertex($name)
        {
            $this->name = $name;
            $this->nRank = 0;
            $this->vRoot = $this;
        }

        function GetRoot()
        {
            if ($this->vRoot != $this)
                $this->vRoot = $this->vRoot->GetRoot();
            return $this->vRoot;
        }
    }
   
    class Kruskal
    {
        var $all_vertex = array();
        var $all_edge = array();
       
        function create()
        {
               //create
        }

        function edge_sort()
        {
            function cmp($a, $b)
            {
                if ($a->weight == $b->weight)
                    return 0;
                return ($a->weight < $b->weight) ? -1 : 1;
            }
            usort($this->all_edge, "cmp");
        }
       
        function Join(Vertex $vRoot1, Vertex $vRoot2)
        {
            if ($vRoot2->nRank < $vRoot1->nRank)
                $vRoot2->vRoot = $vRoot1;
            else {
                $vRoot1->vRoot = $vRoot2;
                if ($vRoot1->nRank == $vRoot2->nRank)
                    $vRoot1->nRank++;
            }
        }
       
        function mst_create()
        {
            $mst_vertex = array();

            $this->edge_sort();

            for ($i=0;$i<count($this->all_edge);$i++) {
                $v1 = $this->all_edge[$i]->v1->GetRoot();
                $v2 = $this->all_edge[$i]->v2->GetRoot();

                if($v1->name==$v2->name)
                    continue;
               
                $this->Join($v1, $v2);
               
                array_push($mst_vertex, $this->all_edge[$i]);
            }
            return $mst_vertex;
        }
    }