Difference between revisions of "Project:USB Disco Dance Floor/v1/firmware"

From London Hackspace Wiki
Jump to navigation Jump to search
(Added docs for "set pixel" command)
(Fixed code)
 
(5 intermediate revisions by 3 users not shown)
Line 14: Line 14:
  
 
Examples:
 
Examples:
* 4 bpc (bits per channel) and 4 colours would lead to a bit pattern of: <tt>RRRRGGGG BBBBUUUU</tt>.
+
* 4 <abbr title="bits per channel">bpc</abbr> and 4 colours would lead to a bit pattern of: <tt style="font-weight: bold"><span style="color: #c00">RRRR</span><span style="color: #090">GGGG</span> <span style="color: #00c">BBBB</span>UUUU</tt>.
* 4 bpc and 3 colours would have a bit pattern of: <tt>RRRRGGGG BBBB0000</tt>
+
* 4 bpc and 3 colours would have a bit pattern of: <tt style="font-weight: bold"><span style="color: #c00">RRRR</span><span style="color: #090">GGGG</span> <span style="color: #00c">BBBB</span><span style="color: #666; font-weight: normal">0000</span></tt>
* 12bps and 3 colours would have a bit pattern of: <tt>RRRRRRRR RRRRGGGG GGGGGGGG BBBBBBBB BBBB0000</tt>
+
* 12 bpc and 3 colours would have a bit pattern of: <tt style="font-weight: bold"><span style="color: #c00">RRRRRRRR RRRR</span><span style="color: #090">GGGG GGGGGGGG</span> <span style="color: #00c">BBBBBBBB BBBB</span><span style="color: #666; font-weight: normal">0000</span></tt>
* 3bps and 3 colours would have a bit pattern of: <tt>RRRGGGBB B0000000</tt>
+
* 3 bpc and 3 colours would have a bit pattern of: <tt style="font-weight: bold"><span style="color: #c00">RRR</span><span style="color: #090">GGG</span><span style="color: #00c">BB B</span><span style="color: #666; font-weight: normal">0000000</span></tt>
  
 
=== Co-ordinate ===
 
=== Co-ordinate ===
Line 26: Line 26:
  
 
A scroll spec consists of two two-bit values and two one-bit values packed into a single byte, with the bit pattern: <tt>xxyy0w0h</tt>. The number of pixels to scroll along the X and Y axes is specified by <tt>xx</tt> and <tt>yy</tt>, and the direction is negative along the X/Y axis if <tt>w</tt> or <tt>h</tt> are set, respectively.
 
A scroll spec consists of two two-bit values and two one-bit values packed into a single byte, with the bit pattern: <tt>xxyy0w0h</tt>. The number of pixels to scroll along the X and Y axes is specified by <tt>xx</tt> and <tt>yy</tt>, and the direction is negative along the X/Y axis if <tt>w</tt> or <tt>h</tt> are set, respectively.
 +
 +
=== Ordering ===
 +
 +
When commands refer to regions of the floor and some ordering of the data is needed it will be sorted in a fixed format, with the X co-ordinate increasing until it would fall outside the region. The X co-ordinate is then reset and the Y co-ordinate increased by 1, until the region is defined.
 +
 +
For example, the region: (1, 0) to (2, 2) would be ordered as follows: (1, 0), (2, 0), (1, 1), (2, 1), (1, 2), (2, 2). The code for this algorithm might look something like:
 +
 +
for j in range(y, h+1):
 +
  for i in range(x, w+1):
 +
    output(pixel[x][y])
 +
 +
and going back the other way:
 +
 +
pos=0
 +
while (col = read()):
 +
  i = x + (pos % (1+w-x))
 +
  j = y + (pos / (1+w-x))
 +
  pixel[x][y] = col
 +
  ++pos
  
 
== Commands ==
 
== Commands ==
  
Commands start with a one-byte identifier, followed by zero or more data bytes. The number of data bytes is command-specific. The device should not output any data unless specified below.
+
Commands start with a one-byte identifier, followed by zero or more data bytes. The number of data bytes is command-specific. The device should not output any data unless specified below. Note that "data in" and "data out" are from the point of view of the device.
  
 
=== Status/Diagnostic Commands ===
 
=== Status/Diagnostic Commands ===
Line 35: Line 54:
 
{| class="wikitable" width="100%"
 
{| class="wikitable" width="100%"
 
!width="80"|Command
 
!width="80"|Command
!Action
+
!colspan="2"|Details
 
!width="100"|Min version
 
!width="100"|Min version
 
|-
 
|-
!rowspan="2"|00
+
!rowspan="3"|00
|'''Reset'''
+
|colspan="2"|'''Reset'''
|1.0
+
|rowspan="2"|1.0
 +
|-
 +
|width="42%"|'''Data in:''' ''None''
 +
|width="42%"|'''Data out:''' 6 bytes: hardware version (2), firmware version (2), capabilities (2)
 
|-
 
|-
|colspan="2"|Resets the board to an initial state, with all pixels off. The board sends four bytes representing its hardware and firmware versions (2 bytes each), followed by 2 bytes for hardware details. This command also resets the board ID to 0xFFFF (i.e. unset).
+
|colspan="3"|Resets the board to an initial state, with all pixels off. The board sends four bytes representing its hardware and firmware versions (2 bytes each), followed by 2 bytes for hardware details. This command also resets the board ID to 0xFFFF (i.e. unset).
  
 
The high nybble of the first hardware info byte is the number of different colours supported (0x1, 0x3, or 0x4) and the low nybble is whether sensors are supported (0x1 for yes). The high nybble of the second byete specifies the number of bits needed to specify LED brightness. If this is different for different colours, the firmware will handle scaling. The low nybble does the same for sensor resolution. Note that, for the time being, resolutions should be a power of 2 (0x1, 0x2, 0x4, 0x8).
 
The high nybble of the first hardware info byte is the number of different colours supported (0x1, 0x3, or 0x4) and the low nybble is whether sensors are supported (0x1 for yes). The high nybble of the second byete specifies the number of bits needed to specify LED brightness. If this is different for different colours, the firmware will handle scaling. The low nybble does the same for sensor resolution. Note that, for the time being, resolutions should be a power of 2 (0x1, 0x2, 0x4, 0x8).
 
|-
 
|-
!rowspan="2"|01
+
!rowspan="3"|01
|'''Identify'''
+
|colspan="2"|'''Identify'''
|1.0
+
|rowspan="2"|1.0
 +
|-
 +
|'''Data in:''' 2 bytes: board ID
 +
|'''Data out:''' 1 byte: 0x00
 
|-
 
|-
|colspan="2"|Informs the board of its two-byte board ID for this session. Note that board IDs 0x0000 and 0xFFFF are reserved. The board will respond with 0x00 (success).
+
|colspan="3"|Informs the board of its two-byte board ID for this session. Note that board IDs 0x0000 and 0xFFFF are reserved. The board will respond with 0x00 (success).
 
|-
 
|-
!rowspan="2"|02
+
!rowspan="3"|02
|'''Ping'''
+
|colspan="2"|'''Ping'''
|1.0
+
|rowspan="2"|1.0
 
|-
 
|-
|colspan="2"|Checks connectivity with the board. The board will respond with 0x00 (success) followed by its two-byte board ID.
+
|'''Data in:''' ''None''
 +
|'''Data out:''' 3 bytes: 0x00, board ID (2)
 
|-
 
|-
!rowspan="2"|03
+
|colspan="3"|Checks connectivity with the board. The board will respond with 0x00 (success) followed by its two-byte board ID.
|'''Query neighbours'''
 
|1.2?
 
 
|-
 
|-
|colspan="2"|Asks the board to search for its immediate neighbours. The board will respond with 8 bytes representing the two-byte IDs of its neighbours, starting with its "top" connection and proceeding clockwise. If no neighbour is found in a given position, 0x0000 is returned. If a neighbour is found but it has not been given an identifier for this session, it will return 0xFFFF.
+
!rowspan="3"|03
 +
|colspan="2"|'''Query neighbours'''
 +
|rowspan="2"|1.2?
 +
|-
 +
|'''Data in:''' ''None''
 +
|'''Data out:''' 8 bytes: top neighbour ID, right ID, bottom ID, left ID
 +
|-
 +
|colspan="3"|Asks the board to search for its immediate neighbours. The board will respond with 8 bytes representing the two-byte IDs of its neighbours, starting with its "top" connection and proceeding clockwise. If no neighbour is found in a given position, 0x0000 is returned. If a neighbour is found but it has not been given an identifier for this session, it will return 0xFFFF.
  
 
This should allow the controller software to automatically detect the layout of the floor.
 
This should allow the controller software to automatically detect the layout of the floor.
 
|-
 
|-
!rowspan="2"|0E
+
!rowspan="3"|0E
|'''Display static test pattern'''
+
|colspan="2"|'''Display static test pattern'''
|1.0
+
|rowspan="2"|1.0
 +
|-
 +
|'''Data in:''' 1 byte: pattern to display
 +
|'''Data out:''' 1 byte: 0x00
 
|-
 
|-
|colspan="2"|A static test pattern will be displayed, as selected by the one-byte argument. A list of patterns is given below:
+
|colspan="3"|A static test pattern will be displayed, as selected by the one-byte argument. A list of patterns is given below:
 
*00 - All white
 
*00 - All white
 
*01 - All red
 
*01 - All red
Line 89: Line 123:
 
*10 - RGB fade, (0,0) = red; (3,0) = green; (0,3) = blue; (3,3) = magenta
 
*10 - RGB fade, (0,0) = red; (3,0) = green; (0,3) = blue; (3,3) = magenta
 
|-
 
|-
!rowspan="2"|0F
+
!rowspan="3"|0F
|'''Display animated test pattern'''
+
|colspan="2"|'''Display animated test pattern'''
|1.0
+
|rowspan="2"|1.0
 +
|-
 +
|'''Data in:''' 1 byte: pattern to display
 +
|'''Data out:''' 1 byte: 0x00
 
|-
 
|-
|colspan="2"|An animated test pattern will be displayed, as selected by the one-byte argument. A list of patterns is given below:
+
|colspan="3"|An animated test pattern will be displayed, as selected by the one-byte argument. A list of patterns is given below:
 
*00 - clockwise spiral chase (white), starting at (0,0)
 
*00 - clockwise spiral chase (white), starting at (0,0)
 
*01 - clockwise spiral (white), starting at (0,0); then black spiral once complete
 
*01 - clockwise spiral (white), starting at (0,0); then black spiral once complete
Line 102: Line 139:
 
{| class="wikitable" width="100%"
 
{| class="wikitable" width="100%"
 
!width="80"|Command
 
!width="80"|Command
!Action
+
!colspan="2"|Details
 
!width="100"|Min version
 
!width="100"|Min version
 
|-
 
|-
!rowspan="2"|10
+
!rowspan="3"|10
|'''Clear floor'''
+
|colspan="2"|'''Clear module'''
|1.0
+
|rowspan="2"|1.0
 +
|-
 +
|width="42%"|'''Data in:''' ''None''
 +
|width="42%"|'''Data out:''' ''None''
 +
|-
 +
|colspan="3"|Clears the entire module, resetting all pixels to black.
 +
|-
 +
!rowspan="3"|11
 +
|colspan="2"|'''Write module'''
 +
|rowspan="2"|1.0
 +
|-
 +
|'''Data in:''' 16 colour specs
 +
|'''Data out:''' ''None''
 
|-
 
|-
|colspan="2"|???
+
|colspan="3"|Set the intensities of all pixels on the module. Note: if colour specs contain zero-padding, this should '''not''' be removed in the data for this command.
 
|-
 
|-
!rowspan="2"|11
+
!rowspan="3"|18
|'''Write floor'''
+
|colspan="2"|'''Clear row'''
|1.0
+
|rowspan="2"|1.0
 
|-
 
|-
|colspan="2"|???
+
|'''Data in:''' 1 byte: row number
 +
|'''Data out:''' ''None''
 
|-
 
|-
!rowspan="2"|18
+
|colspan="3"|Clears the given row, resetting all pixels to black.
|'''Clear row'''
 
|1.0
 
 
|-
 
|-
|colspan="2"|???
+
!rowspan="3"|19
 +
|colspan="2"|'''Write row'''
 +
|rowspan="2"|1.0
 
|-
 
|-
!rowspan="2"|19
+
|'''Data in:''' 1 byte: row number, 4 colour specs
|'''Write row'''
+
|'''Data out:''' ''None''
|1.0
 
 
|-
 
|-
|colspan="2"|???
+
|colspan="3"|Set the intensities of all pixels in the given row. The data is ordered with increasing X. Note: if colour specs contain zero-padding, this should '''not''' be removed in the data for this command.
 
|}
 
|}
  
Line 134: Line 183:
 
{| class="wikitable" width="100%"
 
{| class="wikitable" width="100%"
 
!width="80"|Command
 
!width="80"|Command
!Action
+
!colspan="2"|Details
 
!width="100"|Min version
 
!width="100"|Min version
 
|-
 
|-
!rowspan="2"|50
+
!rowspan="3"|50
|'''Set pixel'''
+
|colspan="2"|'''Set pixel'''
|1.1
+
|rowspan="2"|1.1
 
|-
 
|-
|colspan="2"|''Should only be used very rarely, as it's data-inefficient.'' Sends a one-byte co-ordinate followed by a colour spec. The low nybble of the co-ordinate is ignored.
+
|width="42%"|'''Data in:''' 1 byte: co-ordinate, 1 colour spec
 +
|width="42%"|'''Data out:''' ''None''
 
|-
 
|-
!rowspan="2"|51
+
|colspan="3"|''Should only be used very rarely, as it's data-inefficient.'' Sets the pixel at (x, y) to the given colour. The low nybble of the co-ordinate is ignored.
|'''Draw line'''
 
|1.1
 
 
|-
 
|-
|colspan="2"|???
+
!rowspan="3"|51
 +
|colspan="2"|'''Draw line'''
 +
|rowspan="2"|1.1
 
|-
 
|-
!rowspan="2"|52
+
|'''Data in:''' 1 byte: co-ordinate, 1 colour spec
|'''Draw hollow rectangle'''
+
|'''Data out:''' ''None''
|1.1
 
 
|-
 
|-
|colspan="2"|???
+
|colspan="3"|Draws a 1-pixel-width line in the given colour from absolute co-ordinates (x, y) to absolute co-ordinates (w, h) using Bresenham's algorithm.
 
|-
 
|-
!rowspan="2"|53
+
!rowspan="3"|52
|'''Draw filled rectangle'''
+
|colspan="2"|'''Draw hollow rectangle'''
|1.1
+
|rowspan="2"|1.1
 
|-
 
|-
|colspan="2"|???
+
|'''Data in:''' 1 byte: co-ordinate, 1 colour spec
 +
|'''Data out:''' ''None''
 
|-
 
|-
!rowspan="2"|54
+
|colspan="3"|Draws a hollow rectangle in the given colour, with top-left corner at (x, y) and bottom right corner at (w, h).
|'''Scroll floor'''
 
|1.1
 
 
|-
 
|-
|colspan="2"|???
+
!rowspan="3"|53
 +
|colspan="2"|'''Draw filled rectangle'''
 +
|rowspan="2"|1.1
 
|-
 
|-
!rowspan="2"|55
+
|'''Data in:''' 1 byte: co-ordinate, 1 colour spec
|'''Scroll rectangle'''
+
|'''Data out:''' ''None''
|1.1
 
 
|-
 
|-
|colspan="2"|???
+
|colspan="3"|Draws a filled rectangle in the given colour, with top-left corner at (x, y) and bottom right corner at (w, h).
 
|-
 
|-
!rowspan="2"|5E
+
!rowspan="3"|54
|'''Draw single-colour pattern'''
+
|colspan="2"|'''Scroll module'''
|1.1
+
|rowspan="2"|1.1
 
|-
 
|-
|colspan="2"|???
+
|'''Data in:''' 1 byte: scroll spec
 +
|'''Data out:''' ''None''
 
|-
 
|-
!rowspan="2"|5F
+
|colspan="3"|Scrolls the image on the module according to the given spec. Pixels scrolled off the edge do not wrap, and new pixels will be black.
|'''Draw pattern rect'''
 
|1.1
 
 
|-
 
|-
|colspan="2"|???
+
!rowspan="3"|55
 +
|colspan="2"|'''Scroll rectangle'''
 +
|rowspan="2"|1.1
 +
|-
 +
|'''Data in:''' 2 bytes: co-ordinate (1), scroll spec (1)
 +
|'''Data out:''' ''None''
 +
|-
 +
|colspan="3"|Scrolls the image within the rectangle from (x, y) to (w, h) according to the given spec. Pixels scrolled off the edge do not wrap, and new pixels will be black.
 +
|-
 +
!rowspan="3"|56
 +
|colspan="2"|'''Scroll module with data'''
 +
|rowspan="2"|1.2
 +
|-
 +
|'''Data in:''' 1 byte: scroll spec, 4-16 colour specs
 +
|'''Data out:''' 4-16 colour specs
 +
|-
 +
|colspan="3"|Scrolls the image on the module according to the given spec. Pixels scrolled off the edge do not wrap but will be returned in increasing X/Y co-ordinates, and new pixels will be taken from the colour specs given, in increasing X/Y co-ordinates.
 +
|-
 +
!rowspan="3"|57
 +
|colspan="2"|'''Scroll rectangle with data'''
 +
|rowspan="2"|1.2
 +
|-
 +
|'''Data in:''' 2 bytes: co-ordinate (1), scroll spec (1); 1-16 colour specs
 +
|'''Data out:''' 1-16 colour specs
 +
|-
 +
|colspan="3"|Scrolls the image within the rectangle from (x, y) to (w, h) according to the given spec. Pixels scrolled off the edge do not wrap but will be returned in increasing X/Y co-ordinates, and new pixels will be taken from the colour specs given, in increasing X/Y co-ordinates.
 +
|-
 +
!rowspan="3"|5E
 +
|colspan="2"|'''Draw single-colour pattern'''
 +
|rowspan="2"|1.1
 +
|-
 +
|'''Data in:''' 2 bytes: pattern, 1 colour spec
 +
|'''Data out:''' ''None''
 +
|-
 +
|colspan="3"|The first two bytes define the pattern to be drawn, with the set bits corresponding to a pixel being set to the given colour. The bits are ordered in the usual way, so the highest bit of the pair is (0,0), the highest of the second byte is (0,2), and the lowest of the pair is (3, 3).
 +
|-
 +
!rowspan="3"|5F
 +
|colspan="2"|'''Draw pattern rect'''
 +
|rowspan="2"|1.1
 +
|-
 +
|'''Data in:''' 1 byte: co-ordinate, 1-16 colour specs
 +
|'''Data out:''' ''None''
 +
|-
 +
|colspan="3"|The co-ordinate byte defines a rectangle from (x, y) to (w, h), which is filled with the colour specs in the usual ordering.
 
|}
 
|}
 
<!--
 
 
Code | Action
 
=====+========================================================================
 
                          STATUS/DIAGNOSTIC COMMANDS
 
-----+------------------------------------------------------------------------
 
00  | Reset                                                            v1.0
 
    | Resets the board to an initial state, with all pixels off. The board
 
    | sends four bytes representing its hardware and firmware version (2
 
    | each), followed by 2 bytes for hardware details. The high nybble of
 
    | the first hardware info byte is the number of different colours
 
    | supported (0x1, 0x3 or 0x4) and the low nibble is whether sensors are
 
    | supported (0x1 for yes). The high nybble of the second byte specifies
 
    | the number of bits needed to specify LED brightness (if different for
 
    | different colours, the firmware will scale as necessary) and the low
 
    | nybble does the same for sensor resolution. Note that, for the time
 
    | being, resolutions should be a power of 2 (0x1, 0x2, 0x4, 0x8). This
 
    | comand also resets the stored board ID to 0xFFFF (unset).
 
-----+------------------------------------------------------------------------
 
01  | Identify                                                          v1.0
 
    | Informs the board of its board ID for this session (two bytes). Note
 
    | that board IDs 0x0000 and 0xFFFF are reserved. The board responds with
 
    | 0x00 (success).
 
-----+------------------------------------------------------------------------
 
02  | Ping                                                              v1.0
 
    | Checks connectivity. The board will respond with 0x00 (success).
 
-----+------------------------------------------------------------------------
 
03  | Neighbours                                                        v1.2?
 
    | Asks the board to search for its immediate neighbours. The board will
 
    | respond with 8 bytes representing the two-byte IDs of its neighbours,
 
    | starting with its "top" connection and proceeding clockwise. If no
 
    | neighbour is found in a given position, 0x0000 is returned. If a
 
    | neighbour is found but it has not been given an identifier for this
 
    | session, it will return 0xFFFF.
 
    | This should allow the controller software to automatically detect the
 
    | layout of the floor.
 
-----+------------------------------------------------------------------------
 
0E  | Display static test pattern                                      v1.0
 
    | A static test pattern will be displayed, as selected by the one-byte
 
    | argument. A list of patterns is given below:
 
    |  00 - All white
 
    |  01 - All red
 
    |  02 - All green
 
    |  03 - All yellow
 
    |  04 - All blue
 
    |  05 - All magenta
 
    |  06 - All cyan
 
    |  07 - All 50% white
 
    |  08 - Checkerboard: (0,0)=red; (0,1)=cyan
 
    |  09 - Checkerboard: (0,0)=cyan; (0,1)=red
 
    |  0A - Checkerboard: (0,0)=green; (0,1)=magenta
 
    |  0B - Checkerboard: (0,0)=magenta; (0,1)=green
 
    |  0C - Checkerboard: (0,0)=blue; (0,1)=yellow
 
    |  0D - Checkerboard: (0,0)=yellow; (0,1)=blue
 
    |  0E - Checkerboard: (0,0)=white; (0,1)=black
 
    |  0F - Checkerboard: (0,0)=black; (0,1)=white
 
    |  10 - RGB fade, (0,0) = red; (3,0) = green; (0,3) = blue; (3,3) = ?
 
-----+------------------------------------------------------------------------
 
0F  | Display animated test pattern                                    v1.0
 
    | An animated test pattern will be displayed, as selected by the one-byte
 
    | argument. A list of patterns is given below:
 
    |  00 - clockwise spiral chase (white), starting at (0,0)
 
    |  01 - clockwise spiral (white), starting at (0,0); then black spiral
 
    |      once complete
 
==============================================================================
 
                          SIMPLE DISPLAY COMMANDS
 
-----+------------------------------------------------------------------------
 
10  | Clear floor                                                      v1.0
 
-----+------------------------------------------------------------------------
 
11  | Write floor                                                      v1.0
 
-----+------------------------------------------------------------------------
 
18  | Clear row                                                        v1.0
 
-----+------------------------------------------------------------------------
 
19  | Write row                                                        v1.0
 
==============================================================================
 
                          COMPLEX DISPLAY COMMANDS
 
-----+------------------------------------------------------------------------
 
50  | Set pixel                                                        v1.1
 
    | Should only be used very rarely, as it's highly data-inefficient.
 
    | Sends a one-byte co-ordinate followed by a color specification. The low
 
    | nybble of the co-ordinate is ignored.
 
-----+------------------------------------------------------------------------
 
51  | Draw line                                                        v1.1
 
    | Sends a one-byte co-ordinate followed by a color specification. A
 
    | 1-pixel line is drawn from absolute co-ordinates (x,y) to absolute
 
    | co-ordinates (w,h) using ???'s algorithm.
 
-----+------------------------------------------------------------------------
 
52  | Draw hollow rectangle                                            v1.1
 
    | Sends a one-byte co-ordinate followed by a color specification. A
 
    | hollow rectangle will be drawn of width w and height h, with top-left
 
    | at (x, y).
 
-----+------------------------------------------------------------------------
 
53  | Draw filled rectangle                                            v1.1
 
    | Sends a one-byte co-ordinate followed by a color specification. A
 
    | filled rectangle will be drawn of width w and height h, with top-left
 
    | at (x, y).
 
-----+------------------------------------------------------------------------
 
54  | Scroll floor                                                      v1.1
 
    | Sends a one-byte co-ordinate. Scrolls the entire image by (x, y)
 
    | pixels. If w or h is non-zero then the scroll direction is reversed.
 
-----+------------------------------------------------------------------------
 
55  | Scroll rectangle                                                  v1.1
 
    | Sends two co-ordinate bytes. The first defines the rectangle to scroll,
 
    | the second is a scroll spec (as above).
 
-----+------------------------------------------------------------------------
 
5E  | Draw single-colour pattern                                        v1.1
 
    | Sends two bytes followed by a colour spec. The first two bytes define
 
    | the pattern to be drawn on the module as a whole, with set bits
 
    | indicating that the given pixel should be set to the given colour.
 
-----+------------------------------------------------------------------------
 
5F  | Draw pattern rect                                                v1.1
 
    | Sends a co-ordinate byte to define the rectangle, followed by a list of
 
    | colour specs to be used when filling that rectangle. The specs are
 
    | given in order of increasing X then increasing Y (e.g. (0,0), (1,0),
 
    | (0,1), (1,0))
 
 
-->
 

Latest revision as of 09:40, 7 April 2011

USB Disco Dance Floor v1 Firmware
Created 2011-03-31
Members DMI
Project Status Prototyping


Introduction

The firmware will be responsible for listening for serial commands, and then acting upon them. This will primarily involve changing the display.

Data types

Colour spec

The board reports the number of colours it supports at reset time. The colour(s) in a one-colour board will be referred to as R, in a three-colour board as RGB, and in a four-colour board as RGBU. This is because of the suggested LED choices of Red, Green, Blue, and Ultraviolet. The board also reports the number of bits (n) that it can use for setting the brightness of each colour LED.

A colour spec consists of n bits of R, followed by n bits of G, B, and U (as appropriate). If the total number of bits is not a multiple of 8, it will be right-padded with zeroes.

Examples:

  • 4 bpc and 4 colours would lead to a bit pattern of: RRRRGGGG BBBBUUUU.
  • 4 bpc and 3 colours would have a bit pattern of: RRRRGGGG BBBB0000
  • 12 bpc and 3 colours would have a bit pattern of: RRRRRRRR RRRRGGGG GGGGGGGG BBBBBBBB BBBB0000
  • 3 bpc and 3 colours would have a bit pattern of: RRRGGGBB B0000000

Co-ordinate

A co-ordinate consists of four two-bit values packed into a single byte, with the bit pattern: xxyywwhh. Co-ordinates of (0,0) are at the top-left of the module, and increase downwards and rightwards. Note that the ww and hh bits may be ignored.

Scroll spec

A scroll spec consists of two two-bit values and two one-bit values packed into a single byte, with the bit pattern: xxyy0w0h. The number of pixels to scroll along the X and Y axes is specified by xx and yy, and the direction is negative along the X/Y axis if w or h are set, respectively.

Ordering

When commands refer to regions of the floor and some ordering of the data is needed it will be sorted in a fixed format, with the X co-ordinate increasing until it would fall outside the region. The X co-ordinate is then reset and the Y co-ordinate increased by 1, until the region is defined.

For example, the region: (1, 0) to (2, 2) would be ordered as follows: (1, 0), (2, 0), (1, 1), (2, 1), (1, 2), (2, 2). The code for this algorithm might look something like:

for j in range(y, h+1):
  for i in range(x, w+1):
    output(pixel[x][y])

and going back the other way:

pos=0
while (col = read()):
  i = x + (pos % (1+w-x))
  j = y + (pos / (1+w-x))
  pixel[x][y] = col
  ++pos

Commands

Commands start with a one-byte identifier, followed by zero or more data bytes. The number of data bytes is command-specific. The device should not output any data unless specified below. Note that "data in" and "data out" are from the point of view of the device.

Status/Diagnostic Commands

Command Details Min version
00 Reset 1.0
Data in: None Data out: 6 bytes: hardware version (2), firmware version (2), capabilities (2)
Resets the board to an initial state, with all pixels off. The board sends four bytes representing its hardware and firmware versions (2 bytes each), followed by 2 bytes for hardware details. This command also resets the board ID to 0xFFFF (i.e. unset).

The high nybble of the first hardware info byte is the number of different colours supported (0x1, 0x3, or 0x4) and the low nybble is whether sensors are supported (0x1 for yes). The high nybble of the second byete specifies the number of bits needed to specify LED brightness. If this is different for different colours, the firmware will handle scaling. The low nybble does the same for sensor resolution. Note that, for the time being, resolutions should be a power of 2 (0x1, 0x2, 0x4, 0x8).

01 Identify 1.0
Data in: 2 bytes: board ID Data out: 1 byte: 0x00
Informs the board of its two-byte board ID for this session. Note that board IDs 0x0000 and 0xFFFF are reserved. The board will respond with 0x00 (success).
02 Ping 1.0
Data in: None Data out: 3 bytes: 0x00, board ID (2)
Checks connectivity with the board. The board will respond with 0x00 (success) followed by its two-byte board ID.
03 Query neighbours 1.2?
Data in: None Data out: 8 bytes: top neighbour ID, right ID, bottom ID, left ID
Asks the board to search for its immediate neighbours. The board will respond with 8 bytes representing the two-byte IDs of its neighbours, starting with its "top" connection and proceeding clockwise. If no neighbour is found in a given position, 0x0000 is returned. If a neighbour is found but it has not been given an identifier for this session, it will return 0xFFFF.

This should allow the controller software to automatically detect the layout of the floor.

0E Display static test pattern 1.0
Data in: 1 byte: pattern to display Data out: 1 byte: 0x00
A static test pattern will be displayed, as selected by the one-byte argument. A list of patterns is given below:
  • 00 - All white
  • 01 - All red
  • 02 - All green
  • 03 - All yellow
  • 04 - All blue
  • 05 - All magenta
  • 06 - All cyan
  • 07 - All 50% white
  • 08 - Checkerboard: (0,0)=red; (0,1)=cyan
  • 09 - Checkerboard: (0,0)=cyan; (0,1)=red
  • 0A - Checkerboard: (0,0)=green; (0,1)=magenta
  • 0B - Checkerboard: (0,0)=magenta; (0,1)=green
  • 0C - Checkerboard: (0,0)=blue; (0,1)=yellow
  • 0D - Checkerboard: (0,0)=yellow; (0,1)=blue
  • 0E - Checkerboard: (0,0)=white; (0,1)=black
  • 0F - Checkerboard: (0,0)=black; (0,1)=white
  • 10 - RGB fade, (0,0) = red; (3,0) = green; (0,3) = blue; (3,3) = magenta
0F Display animated test pattern 1.0
Data in: 1 byte: pattern to display Data out: 1 byte: 0x00
An animated test pattern will be displayed, as selected by the one-byte argument. A list of patterns is given below:
  • 00 - clockwise spiral chase (white), starting at (0,0)
  • 01 - clockwise spiral (white), starting at (0,0); then black spiral once complete

Simple Display Commands

Command Details Min version
10 Clear module 1.0
Data in: None Data out: None
Clears the entire module, resetting all pixels to black.
11 Write module 1.0
Data in: 16 colour specs Data out: None
Set the intensities of all pixels on the module. Note: if colour specs contain zero-padding, this should not be removed in the data for this command.
18 Clear row 1.0
Data in: 1 byte: row number Data out: None
Clears the given row, resetting all pixels to black.
19 Write row 1.0
Data in: 1 byte: row number, 4 colour specs Data out: None
Set the intensities of all pixels in the given row. The data is ordered with increasing X. Note: if colour specs contain zero-padding, this should not be removed in the data for this command.

Complex Display Commands

Command Details Min version
50 Set pixel 1.1
Data in: 1 byte: co-ordinate, 1 colour spec Data out: None
Should only be used very rarely, as it's data-inefficient. Sets the pixel at (x, y) to the given colour. The low nybble of the co-ordinate is ignored.
51 Draw line 1.1
Data in: 1 byte: co-ordinate, 1 colour spec Data out: None
Draws a 1-pixel-width line in the given colour from absolute co-ordinates (x, y) to absolute co-ordinates (w, h) using Bresenham's algorithm.
52 Draw hollow rectangle 1.1
Data in: 1 byte: co-ordinate, 1 colour spec Data out: None
Draws a hollow rectangle in the given colour, with top-left corner at (x, y) and bottom right corner at (w, h).
53 Draw filled rectangle 1.1
Data in: 1 byte: co-ordinate, 1 colour spec Data out: None
Draws a filled rectangle in the given colour, with top-left corner at (x, y) and bottom right corner at (w, h).
54 Scroll module 1.1
Data in: 1 byte: scroll spec Data out: None
Scrolls the image on the module according to the given spec. Pixels scrolled off the edge do not wrap, and new pixels will be black.
55 Scroll rectangle 1.1
Data in: 2 bytes: co-ordinate (1), scroll spec (1) Data out: None
Scrolls the image within the rectangle from (x, y) to (w, h) according to the given spec. Pixels scrolled off the edge do not wrap, and new pixels will be black.
56 Scroll module with data 1.2
Data in: 1 byte: scroll spec, 4-16 colour specs Data out: 4-16 colour specs
Scrolls the image on the module according to the given spec. Pixels scrolled off the edge do not wrap but will be returned in increasing X/Y co-ordinates, and new pixels will be taken from the colour specs given, in increasing X/Y co-ordinates.
57 Scroll rectangle with data 1.2
Data in: 2 bytes: co-ordinate (1), scroll spec (1); 1-16 colour specs Data out: 1-16 colour specs
Scrolls the image within the rectangle from (x, y) to (w, h) according to the given spec. Pixels scrolled off the edge do not wrap but will be returned in increasing X/Y co-ordinates, and new pixels will be taken from the colour specs given, in increasing X/Y co-ordinates.
5E Draw single-colour pattern 1.1
Data in: 2 bytes: pattern, 1 colour spec Data out: None
The first two bytes define the pattern to be drawn, with the set bits corresponding to a pixel being set to the given colour. The bits are ordered in the usual way, so the highest bit of the pair is (0,0), the highest of the second byte is (0,2), and the lowest of the pair is (3, 3).
5F Draw pattern rect 1.1
Data in: 1 byte: co-ordinate, 1-16 colour specs Data out: None
The co-ordinate byte defines a rectangle from (x, y) to (w, h), which is filled with the colour specs in the usual ordering.