Example YUI Image upload with YUI 2.6.0

I wanted to add an example of the yuiImgUploader script working with YUI version 2.6.0. If you haven’t read the original YUI Image Uploader page, start there. After that, you can use this page for an example getting the script to work with the latest YUI.

That changes from the previous 2.5 Image uploader are quite small. If you were using a pre 2.6 version of the editor, simply change the location of a couple scripts and add your editor name to the yuiImgUploader function parameters.

Here is the new yui-image-uploader26.js file.

Continue reading

Posted in Programming | Tagged , , , , , | 39 Comments

A few open source tips for the Cypress FX2LP (EZ-USB Cy7c68013A)

I’ve had the enjoyable experience of playing around with the Cy7c68013a chip on the Ez-Usb development board for the past few weeks. I thought I’d post a few tips for developing in this type of environment with open source software.

  1. Convert to Linux

    The tools that Cypress provides with the development kit are Windows based. You can download a number of their items directly from their website, but i didn’t find a way to unpack their source code examples without running their installer in a Windows session. The installer creates a new directory: C:\Cypress\ You can ignore the bin directory. Copy the docs directory (You’ll need the TRM) and the examples directory to your Linux machine. The examples won’t compile on Linux (The c51 compiler provided by Keil is Windows based) but they provide good insight into how to do a few things when it isn’t immediately clear by reading the TRM. You may also be interested in their util sources but I’ve found only minor uses for these since there are open source alternatives to a lot of what they do.

  2. Convert to SDCC

    On Linux, you’ll compile programs for the 8051 chip with SDCC. You can install it from their sources or from a package provided by your Linux distribution. SDCC works very similar to gcc but provides output that can be loaded onto embedded devices.

    A couple important switches for compiling:

    • -mmcs51 Tells the compiler to produce output for the 8051 chip
    • -xram-loc Tells the compiler where to start putting xdata variables
      (If a program suddenly doesn’t work after you add an xdata variable, try playing with this 1st.)
  3. Convert the fx2regs.h file

    The fx2regs.h file provided with cypress won’t compile with SDCC (It’s Keil specific). There are a few things you can do.

    • Just use the 8051.h (or 8052.h) file provided by sdcc. (Works if you don’t need lots of the extended registers. Also works for getting started with basic examples.
    • Rewrite it in non compiler specific macros. SDCC comes with a compiler.h file that has macros for SFR, SBIT, etc. You can use these and generate a header file that can be compiled on more than one platform.
    • Use a convert utility. There is a perl script on SDCCs contrib folder that can convert Keil to SDCC headers.
      (For clarification, this script is included in the source tarball.)
    • Rewrite it yourself by hand. Well, if you don’t trust the conversion script anyway.
  4. Learn how to run programs

    The Cy7c68013a chip handles some basic USB commands for you. 1st of all, it will enumerate itself. 2nd, it will allow you to upload and download firmware to the 8051. This 2nd tidbit is vital. You can 1st upload a byte to the reset bit location in firmware (putting the chip in reset), then upload a new firmware, and then upload a byte that puts it back out of reset, thus running your program.

    This fairly straight forward process is documented in the TRM. Even cooler though, someone already implemented it for you so you don’t have to. I use the cycfx2prog utility. It’s GPLed and the source is available to download.

    After compiling a simple program (which produces an ihx-intel hex file), you can upload it like this:

     > cycfx2prog prg:program.ihx run
    
  5. Port a couple example programs to SDCC.

    I started by rewriting a few of the examples and libraries for testing. I recommend 1st getting serial io working so you can debug easier. After that, play around with the i2c board and lights. Finally, test writing to eeprom. (For eeprom images, the hex2bix program that comes with the development kit can easily be ported to run on Linux by using linux time libraries instead of the windows files.)

    Perhaps this section deserves it’s own blog post later on.

Anyway, I haven’t yet found anything that can’t be done on Linux with the Ez-USB kit.

UPDATE 12/5/08: Added Open Source FX2 Library.

Posted in Hardware, Programming | Tagged , , , , , , | 42 Comments

A few reasons braid is better than 40 lines of Rake.

I’ve been doing a lot of looking at the git subtree merge strategy for tracking remote projects. Ideally, our remote projects would be tracked with submodules. The issue is, we are developing our own libraries for use in our own internal projects. We commonly do major development on the libraries and the submodules at the same time. While submodules work, we find the overhead of having to repeatedly commit in each submodule and then in the parent project somewhat prohibitive to being productive. A good source code management system should help, not get in your way of being productive. While git helps and is out of the way for the most part, we found this not to be the case when developing our own submodules. (They are much better suited when you’re tracking a 3rd party library.)

That being said, the subtree merge strategy lets you use your repository more naturally. When you commit, everything is committed and when you pull, you don’t have to worry about updating the submodules to the correct state, switching to the master branch, or spending time worrying about whether or not you just broke the state of your working directory. On the other hand, subtree merges have a little bit more overhead to deal with when you set them up and when you want to push back to the library you’ve made changes to. Referring to the link above, it takes a number of commands to pull in the library and you need to understand what is happening.

The braid project has been set up to make managing subtree merges a little easier. It has been criticized for being too complex and able to be replaced with subtrees by themselves (see the 40 lines of Rake post.)

Here are a few reasons I think braid is not too complex.

  • It does diff’s correctly.

    In order to find the diff of your merged in subtree against the library, you can use git diff-tree. This is quite daunting to do correctly in a shell. In order to get a patch that really represents what the diff is, you have to do a diff against just the subtree, not the project root or path. You get this by using git rev-parse to find the pulled in tree:

    # you need the base revision of the last time you pulled the library in (via fetch) 
    # and did the merge.  The revision is not what you see in gitk or by browsing the parent
    # of the merge, you find it with rev-parse.
    $ git rev-parse :
    # next, you need the sha1 of just the subtree directory of the commit that you want to 
    # get the diff for (HEAD or a previous commit will work too)
    # this can be retrieved with ls-tree
    $ git ls-tree HEAD path/to/lib
    # after parsing out those two sha1 ids, you can use diff-tree to get the correct diff
    $ git diff-tree   --src-prefix=path/to/lib --dst-prefix=path/to/lib
    

    Part of the problem with a shell script is finding the sha1 ids. When was the last time you imported the library? What if there are multiple parents? Braid takes care of these things by storing some meta information about the subtrees it manages in a .braids file. It will save you a lot of time later.

  • Braid stores the merge strategy for you.

    When you shell script your solution, there is no meta information about your merge strategy. You can manually add additional scripts to merge with a squash or full type merge, but you’ll have to remember to use the correct script when you update your library. Braid takes care of this with it’s meta data again.

  • Braid caches for you.

    There is a problem with fetching huge remote repositories in git. The creator of braid pointed this thread out to me that outlines the problem. Braid can maintain a cache of the remote repository for you which allows you to use the subtree merge strategy effectively without worrying about git’s fetch problem.

Posted in Software | Tagged , , , , | 3 Comments

Terminal Spelling

There are a miriad of dictionary tools on the Internet and for desktops. If you want, you can even pull out the dusty dictionary on your shelf. I find myself often wanting to use the dictionary not for a word definition, but to find out if I’m spelling a word correctly. Finding an online or desktop tool, loading it, and doing the search is bothersome at best.

Since most of the time I already have my terminal open, here is a shortcut I use to finding the correct spelling of a word. Just use aspell (installed on most Linux distributions by default.)

$ echo "aword" | aspell -a

Easy enough isn’t it. Now I put a simple script in my bin directory. Call it whatever you want.

~/bin/spell

#!/bin/bash
echo "$1" | aspell -a

You may even be able to pull this off with an alias or something. In the mean time, just use your terminal to find the correct spelling of that hard to spell word and skip all the GUI utilities.

Posted in Miscellaneous | Tagged , , | Comments Off on Terminal Spelling

Internet on the go

I’m not very transient in my Internet usage, meaning that I use the Internet at home and at work, but not a lot while I’m traveling. On occasion however, I really wish I had a way to connect my laptop to the Internet somewhere where I don’t have a wireless connection. These days, getting on the 3G network is all the talk. 3G is the 3rd generation of wireless Internet. Japan was the 1st to provide it in 2001 and in October of 2003, Verizon became the 1st carrier. By June of 2007, the 200 millionth customer of 3G networks had signed up. In 2008, it’s growth continues. [1] I find it amazing the number of devices that come enabled with Internet access these days.

So what about my laptop? If you live in or around the UK, you might check these mobile broadband deals from Broadband Expert. In addition to providing mobile internet, the broadband expert site allows you to compare mobile broadband.

Clearly, Broadband Expert is on your side when it comes to providing mobile Internet. Instead of touting a solution and hiding the competition, they present you with as many carriers and prices as they have access to. You can sort by price, contract terms, etc to find which option best suites you. Then, whichever carrier you choose, you get a cool USB stick that plugs in to your machine and presto, 3G Internet speeds on your computer. As cool as the USB Internet access stick is, I’m also intrigued by the price. The T-Mobile solution is only £10/month (about $17.91/month) and the other solutions are listed at around £15/month (about $26.87/month). That really isn’t that bad for the data transfer rate offered.

Clearly T-Mobile operates beyond the borders of the UK. That being my current provider for cell-phone and VOIP, I thought I’d look directly at their offerings for Internet service. After browsing their site for available packages, I only found a reference to data cards with Internet access. They don’t appear to offer, as an accessory, a cool USB stick. In addition, their data plans were about $50/month. I may be wrong about this, but in the mean time, it appears you need to go to a 3rd party site like Broadband Expert in order to get the Internet plan for your laptop/computer.

[1] http://en.wikipedia.org/wiki/3G

Posted in Web | 1 Comment

Sharing git branches

I’ve been learning git lately. Here are a few tips for sharing branches I’ve collected during the past few weeks.

Create a branch

In git, branches are stored on your local machine. Even the commonly named “master”, is just a branch on your local machine. Master is simply set up to track a branch on a remote machine by default. To create a new local branch, you can do one of two things. Create the branch and then check it out, or do a checkout with a branch switch.

# using the branch tag
$ git branch newbranch
$ git checkout newbranch
# or just do it with checkout first
$ git checkout -b newbranch
# you can look at your local branches
$ git branch

Pushing a branch to the server

This is only applicable for using git with a central server to track changes. You can of course, use the same method to push a branch to another machine that isn’t being used as a central server (like another development machine) but I haven’t done that as much.

$ git push origin newbranch
# You can look at the new branch on the server
$ git branch -r

Checkout a remote branch

If someone else has pushed a branch to the server, you can check it out on your machine.

$ git checkout -b newbranch origin/newbranch

NOTE There is a –track switch on the checkout command you might need to add. For me, it has been doing that by default though.

NOTE After you push a branch to a server, your local branch isn’t set up to track changes on that branch. There may be another way to accomplish getting that set up, but I just check out the branch again.

$ git push origin newbranch
$ git checkout -b newbranch_renamed origin/newbranch

You could of course, delete “newbranch” and then re-checkout the branch to the same name. It’s important to realize that the names don’t matter really. Newbranch can be named differently on the local and remote machine.

Deleting branches

To delete a branch, just use the -d switch on branch.

$ git checkout master # or another branch
# do your merging before you do the delete 
$ git branch -d newbranch
# you can delete the remote branch after you have deleted the local one like this:
# the syntax is slightly confusing, but it works
$ git push origin :newbranch 
Posted in Programming | Tagged , , , | 4 Comments