Fork me on GitHub

12/31/2011

Blog Decoration CSS

This post records the decoration in this blog for backup. Using markdown with these decoration to write blog is awesome!

1. Code Block

pre {
    border:1px dashed #E1E1E1;
    color:#333344;
    background:#FAFAFA;
    overflow:auto;
    padding:0.5em;
}
code {
    font:$(body.code);
    line-height:28px;
}

2. Blcokquote

blockquote {
    background  : #f9f9f9;
    border-left : 10px solid #ccc;
    margin      : 1.5em 10px;
    padding     : .5em 10px;
    quotes      : "\201C""\201D""\2018""\2019";
}

3. Github Ribbon

.ribbon {
    background-color          : #a00;
    overflow                  : hidden;
    z-index                   : 1;
    position                  : absolute;
    right                     : -3em;
    top                       : 2.5em;
    -moz-transform            : rotate(45deg);
    -webkit-transform         : rotate(45deg);
    -moz-box-shadow           : 0 0 1em #888;
    -webkit-box-shadow        : 0 0 1em #888;
}
.ribbon a {
    border          : 1px solid #faa;
    color           : #fff;
    display         : block;
    font            : bold 81.25% 'Helvetiva Neue', Helvetica, Arial, sans-serif;
    margin          : 0.05em 0 0.075em 0;
    padding         : 0.5em 3.5em;
    text-align      : center;
    text-decoration : none;
    text-shadow     : 0 0 0.5em #444;
}

-- EOF --

12/30/2011

Using Git In Non Merging Way

Here is the flow I used in the past few months development wit Git

  1. First, create a branch 'base' to track the remote collaborating branch

    $ git checkout -b base -t origin/trunk
        // create a local branch 'base' to track a remote branch 'origin/trunk'
    $ git branch -a
        // show the detail info about local/remote branches
    $ git remote show origin
        // to know which local branch tracks which remote branch, see the bottom of output
    
  2. Any feature/hotfix are checkout to a separate feature branch from base branch, and develop on it

    $ git checkout -b 1201-fea
        // create a local branch for development
    
  3. After completing and verifying your changes, patch your changes

    $ git diff > p1225_refactor
        // output your changes to a patch file names 'p1201_fea'
    
  4. When ready to sync changes to server, update your base branch, checkout to it, then apply your patch

    $ git checkout base
    $ git pull --rebase
        // make sure the branch in the updated condition
    $ git apply p1225_refactor
        // apply your changes on top of it
    
  5. The habits which prevent you from the regular loop of conflict and merge

    Often update your 'base' branch, don't let it lag too much behind the remote trunk

    If your changes are not urgent, keep checking out a daily experiment branch from 'base' and try to apply your patch and verify it. If any conflict, you can fix it as early as posiible

    Naming your branches and patches clearly, give them some identifiable prefix or suffix

-- EOF --

12/27/2011

open drain & push pull

IC 的輸出腳位通常可以透過設定 register 來改變其輸出的 mode (Open Drain 或 Push-Pull),以下網路上找到的解釋蠻清楚的,紀錄一下。

The push-pull output actually uses two transistors. Each will be on to drive the output to the appropriate level: the top transistor will be on when the output has to be driven high and the bottom transistor will turn on when the output has to go low.

The open-drain output lacks the top transistor. When the output has to go high you simply turn off the bottom transistor, but the line is now pulled high only by the pullup resistor.

Your micro allows you to select between the two types, which means that by setting some bits in some register you actually enable/ disable the top transistor and enable/disable the pullup (if internal, otherwise you just disable the top transistor and have to use an external pullup)

The advantage of the push-pull output is the higher speed, because the line is driven both ways. With the pullup the line can only rise as fast as the RC time constant allows. The R is the pullup, the C is the parasitic capacitance, including the pin capacitance and the board capacitance. The push-pull can typically source more current. With the open-drain the current is limited by the R and R cannot be made very small, because the lower transistor has to sink that current when the output is low; that means higher power consumption.

However, the open-drain allows you to cshort several outputs together, with a common pullup. This is called an wired-OR connection. Now you can drive the output low with any of the IO pins. To drive it high all ouputs have to be high. This is advantageous in some situations, because it eliminates the external gates that would otherwise be required.

12/23/2011

[C] Error “initializer element is not constant” and static

嘗試著要在  static 的 struct 成員指向其他 struct 的時候 (也就是巢狀 struct),必須注意成員必須是 const,而 C 和 C++ 的 const 語意有所出入,需注意之!

It has to do with C language. In C language objects with static storage duration has to be initialized with constant expressions or with aggregate initializers containing constant expressions.
A "large" object is never a constant expression in C, even if the object is declared as const.
Moreover, in C language the term "constant" refers to literal constants (like 1,'a', 0xFF and so on). Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects with static storage duration, regardless of their type.
For example, this is NOT a constant
const int C = 5; /* not a constant in C */
It would be a constant in C++, but it is not a constant in C. So, if you try doing
static int j = C; /* ERROR */
you will get the same error: an attempt to initialize a static object with a non-constant.
-- EOF --

12/18/2011

Use CMake to setup OpenCV environment, and use CMake variable to link installed OpenCV lib

OpenCV 是一個好用的 computer vision open source library,自從 2.0 版本之後就開始採用 CMake 的建構系統,讓整個安裝和跨平台的使用上變得相當容易!

Ubuntu 的安裝方式:
    基本上可以直接參考 Installing OpenCV 2.2 in Ubuntu 11.04 這篇文章,安裝好一些基本的 dependent lib 之後,就是到官網抓最新的 source code 下來編譯然後安裝,比較需要注意的是不要忘記 sudo gedit /etc/ld.so.conf.d/opencv.conf 然後要加入 /usr/local/lib (這樣系統才知道要去哪裡找安裝好的 library)。

Mac 的安裝方式:
    基本上和 Ubuntu 大同小異,不過要先安裝好 Xcode,安裝完不用自行加入 library path。



如何讓別人使用你寫好的 OpeCV application:
    其實安裝好 OpenCV 以後,系統就會有一些現成的 CMake 變數可以使用,如果你利用 OpenCV 開發了一些專案想要利用 CMake 建構的方式,分享給別人的話,那麼可以透過插入下面這兩行,搞定 library linking 的問題:

FIND_PACKAGE(OpenCV REQUIRED)
TARGET_LINK_LIBRARIES(main ${OpenCV_LIBS})

如果有興趣的話,在你安裝完以後,也可以 clone 一些我之前寫的 project 玩玩!例如:一個追蹤手部移動的程式,詳細運行方式請參考 README 檔案,也歡迎留言指教 :)


--- EOF ---


11/19/2011

[DISP] pixel clock, hsync, vsync 觀念

接觸 display driver 開發一陣子,經常遇到一些似懂非懂得名詞,假日的時候 google 一下,解決心中的疑惑

主要參考幾篇網路文章:
1. http://www.linuxjournal.com/article/1089
2. http://www.epanorama.net/documents/pc/vga_timing.html
3. http://kezeodsnx.pixnet.net/blog/post/24116781-display-%E7%9B%B8%E9%97%9C%E5%8E%9F%E7%90%86 (有關 pixel clock)

以下是擷取第一個網路資料的內容,簡單介紹 display 顯示畫面的原理:

TVs and monitors display the picture by scanning lines across the screen. As in a book, the first line starts at the top left of the screen and goes to the top right. Each successive line starts slightly below the previous line. This continues until the screen is full. The lines don't have to be full; the picture is formed by altering the intensity of the electron beam as it scans the lines.

To perform this scan, the TV has two deflection units: one scans from left to right, and the other scans (much more slowly) from top to bottom. Not unexpectedly, these units are called thehorizontal and vertical deflection units. You may also encounter the terms line and frame deflection. (可以把畫面形成想像成一個傳統的打字機,每打完一行,就要從尾端在移動到起始位置)

The electron beam can move at only a finite speed. When the electron beam reaches the right hand side of the screen, it needs to be deflected back again. This part of the scan is called thehorizontal retrace, and it is not used for displaying picture data. The actual time that the hardware requires for the retrace varies, but it is in the order of 5% to 10% of the total line scan time. Similarly, when the vertical deflection reaches the bottom of the screen, it performs a vertical retrace, which is also not used for display.

It's not enough to just deflect, of course; somehow you need to ensure that the scanning is synchronized with the incoming signal, so that the scan is at the top of the screen when the picture information for the top of the screen arrives. You've all seen what happens when this doesn't happen; the picture runs up and down the screen (incorrect vertical synchronization) or tears away from the left of the screen (incorrect horizontal synchronization). Synchronization is achieved by including synchronization pulses in the horizontal and vertical retrace periods. To ensure that they are recognized as synchronization pulses, they have different voltage levels from the picture data. (sync 訊號是為了確保 signal source 跟顯示出來的東西可以保持同步,否則可能會有跳frame或是tearing的現象發生)

As if that wasn't enough, the video amplifier, the part of the TV which alters the intensity of the spot as it travels across the screen, needs time to ensure that the retrace is invisible, so there are brief pauses between the end of the line and the start of the sync pulse, and again between the end of the sync pulse and the beginning of the data. This process is called blanking, and the delays are called the front porch (before the sync pulse) and theback porch (after the sync pulse). (porch 的概念就是,當顯示在做 retrace 的時候並不會 show pixel,就像採煞車一樣把 intensity 降低,這需要時間 "back porch",等到移動到定位了,要開始催油門到一定的 intensity,這也需要時間 "front porch"。

用第二篇資料的圖示會更清楚:

Horizonal Timing

Horizonal Dots         640     640     640        
Vertical Scan Lines    350     400     480
Horiz. Sync Polarity   POS     NEG     NEG
A (us)                 31.77   31.77   31.77     Scanline time
B (us)                 3.77    3.77    3.77      Sync pulse lenght 
C (us)                 1.89    1.89    1.89      Back porch
D (us)                 25.17   25.17   25.17     Active video time
E (us)                 0.94    0.94    0.94      Front porch
         ______________________          ________
________|        VIDEO         |________| VIDEO (next line)
    |-C-|----------D-----------|-E-|
__   ______________________________   ___________
  |_|                              |_|
  |B|
  |---------------A----------------|

Vertical Timing

Horizonal Dots         640     640     640
Vertical Scan Lines    350     400     480
Vert. Sync Polarity    NEG     POS     NEG      
Vertical Frequency     70Hz    70Hz    60Hz
O (ms)                 14.27   14.27   16.68     Total frame time
P (ms)                 0.06    0.06    0.06      Sync length
Q (ms)                 1.88    1.08    1.02      Back porch
R (ms)                 11.13   12.72   15.25     Active video time
S (ms)                 1.2     0.41    0.35      Front porch
         ______________________          ________
________|        VIDEO         |________|  VIDEO (next frame)
    |-Q-|----------R-----------|-S-|
__   ______________________________   ___________
  |_|                              |_|
  |P|
  |---------------O----------------|


...